On Thu, Apr 16, 2020 at 12:53:46PM +0100, Will Deacon wrote: > On Thu, Apr 16, 2020 at 10:31:06AM +0100, Mark Rutland wrote: > > FWIW, for the arm64 unwind code we could add a helper to snapshot the > > frame record, and mark that as __no_sanitize_address, e.g. [...] > > ... we'd need to do likewied in a few bits of unwind code: [...] > Indeed. For now, I'm going to keep this simple with the change below, but > I'll revisit this later on because I have another series removing > smp_read_barrier_depends() which makes this a lot simpler. > > Will The below looks good to me; thanks for putting that together! Mark. > > --->8 > > diff --git a/include/linux/compiler.h b/include/linux/compiler.h > index 00a68063d9d5..c363d8debc43 100644 > --- a/include/linux/compiler.h > +++ b/include/linux/compiler.h > @@ -212,18 +212,12 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val, > (typeof(x))__x; \ > }) > > -/* > - * Use READ_ONCE_NOCHECK() instead of READ_ONCE() if you need > - * to hide memory access from KASAN. > - */ > -#define READ_ONCE_NOCHECK(x) \ > +#define READ_ONCE(x) \ > ({ \ > compiletime_assert_rwonce_type(x); \ > __READ_ONCE_SCALAR(x); \ > }) > > -#define READ_ONCE(x) READ_ONCE_NOCHECK(x) > - > #define __WRITE_ONCE(x, val) \ > do { \ > *(volatile typeof(x) *)&(x) = (val); \ > @@ -247,6 +241,24 @@ do { \ > # define __no_kasan_or_inline __always_inline > #endif > > +static __no_kasan_or_inline > +unsigned long __read_once_word_nocheck(const void *addr) > +{ > + return __READ_ONCE(*(unsigned long *)addr); > +} > + > +/* > + * Use READ_ONCE_NOCHECK() instead of READ_ONCE() if you need to load a > + * word from memory atomically but without telling KASAN. This is usually > + * used by unwinding code when walking the stack of a running process. > + */ > +#define READ_ONCE_NOCHECK(x) \ > +({ \ > + unsigned long __x = __read_once_word_nocheck(&(x)); \ > + smp_read_barrier_depends(); \ > + __x; \ > +}) > + > static __no_kasan_or_inline > unsigned long read_word_at_a_time(const void *addr) > {