ANDROID: scs: fix recursive spinlock in scs_check_usage
Use cmpxchg instead of a spinlock in scs_check_usage() to avoid
deadlocks.
Bug: 157781894
Change-Id: I1701ccaf25fdbd34ce4798c6f93e220b1565fb34
Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Git-commit: e467b8c7db
Git-repo: https://android.googlesource.com/kernel/common
[jshriram@codeaurora.org: cherry-pick]
Signed-off-by: Jeevan Shriram <jshriram@codeaurora.org>
This commit is contained in:
parent
f5090438b6
commit
42dd9451e6
41
kernel/scs.c
41
kernel/scs.c
@ -185,36 +185,31 @@ int scs_prepare(struct task_struct *tsk, int node)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CONFIG_DEBUG_STACK_USAGE
|
#ifdef CONFIG_DEBUG_STACK_USAGE
|
||||||
static inline unsigned long scs_used(struct task_struct *tsk)
|
|
||||||
{
|
|
||||||
unsigned long *p = __scs_base(tsk);
|
|
||||||
unsigned long *end = scs_magic(p);
|
|
||||||
unsigned long s = (unsigned long)p;
|
|
||||||
|
|
||||||
while (p < end && READ_ONCE_NOCHECK(*p))
|
|
||||||
p++;
|
|
||||||
|
|
||||||
return (unsigned long)p - s;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void scs_check_usage(struct task_struct *tsk)
|
static void scs_check_usage(struct task_struct *tsk)
|
||||||
{
|
{
|
||||||
static DEFINE_SPINLOCK(lock);
|
|
||||||
static unsigned long highest;
|
static unsigned long highest;
|
||||||
unsigned long used = scs_used(tsk);
|
|
||||||
|
|
||||||
if (used <= highest)
|
unsigned long *p = __scs_base(tsk);
|
||||||
return;
|
unsigned long *end = scs_magic(p);
|
||||||
|
unsigned long prev, curr = highest, used = 0;
|
||||||
|
|
||||||
spin_lock(&lock);
|
for (; p < end; ++p) {
|
||||||
|
if (!READ_ONCE_NOCHECK(*p))
|
||||||
if (used > highest) {
|
break;
|
||||||
pr_info("%s (%d): highest shadow stack usage: %lu bytes\n",
|
used += sizeof(*p);
|
||||||
tsk->comm, task_pid_nr(tsk), used);
|
|
||||||
highest = used;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_unlock(&lock);
|
while (used > curr) {
|
||||||
|
prev = cmpxchg_relaxed(&highest, curr, used);
|
||||||
|
|
||||||
|
if (prev == curr) {
|
||||||
|
pr_info("%s (%d): highest shadow stack usage: %lu bytes\n",
|
||||||
|
tsk->comm, task_pid_nr(tsk), used);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
curr = prev;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static inline void scs_check_usage(struct task_struct *tsk)
|
static inline void scs_check_usage(struct task_struct *tsk)
|
||||||
|
Loading…
Reference in New Issue
Block a user