|
Message-ID: <20200420222428.GB77284@google.com> Date: Mon, 20 Apr 2020 15:24:28 -0700 From: Sami Tolvanen <samitolvanen@...gle.com> To: Will Deacon <will@...nel.org> Cc: Catalin Marinas <catalin.marinas@....com>, James Morse <james.morse@....com>, Steven Rostedt <rostedt@...dmis.org>, Ard Biesheuvel <ard.biesheuvel@...aro.org>, Mark Rutland <mark.rutland@....com>, Masahiro Yamada <masahiroy@...nel.org>, Michal Marek <michal.lkml@...kovi.net>, Ingo Molnar <mingo@...hat.com>, Peter Zijlstra <peterz@...radead.org>, Juri Lelli <juri.lelli@...hat.com>, Vincent Guittot <vincent.guittot@...aro.org>, Dave Martin <Dave.Martin@....com>, Kees Cook <keescook@...omium.org>, Laura Abbott <labbott@...hat.com>, Marc Zyngier <maz@...nel.org>, Masami Hiramatsu <mhiramat@...nel.org>, Nick Desaulniers <ndesaulniers@...gle.com>, Jann Horn <jannh@...gle.com>, Miguel Ojeda <miguel.ojeda.sandonis@...il.com>, clang-built-linux@...glegroups.com, kernel-hardening@...ts.openwall.com, linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org Subject: Re: [PATCH v11 03/12] scs: add support for stack usage debugging On Mon, Apr 20, 2020 at 06:17:42PM +0100, Will Deacon wrote: > > +#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++; > > I think the expectation is that the caller has already checked that the > stack is not corrupted, so I'd probably throw a couple of underscores > in front of the function name, along with a comment. Correct. I'll do that. > Also, is tsk ever != current? This is only called from scs_release(), so tsk is never current. > > +static void scs_check_usage(struct task_struct *tsk) > > +{ > > + static DEFINE_SPINLOCK(lock); > > + static unsigned long highest; > > + unsigned long used = scs_used(tsk); > > + > > + if (used <= highest) > > + return; > > + > > + spin_lock(&lock); > > + > > + if (used > highest) { > > + pr_info("%s (%d): highest shadow stack usage: %lu bytes\n", > > + tsk->comm, task_pid_nr(tsk), used); > > + highest = used; > > + } > > + > > + spin_unlock(&lock); > > Do you really need this lock? I'd have thought you could cmpxchg() > highest instead. This is similar to check_stack_usage in kernel/exit.c, but yes, I can change this to a cmpxchg() loop instead. Sami
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.