lkml.org 
[lkml]   [2017]   [Oct]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH V8 2/2] printk: hash addresses printed with %p
On Thu, 26 Oct 2017 13:58:38 +1100
"Tobin C. Harding" <me@tobin.cc> wrote:

> > +static bool have_filled_random_ptr_key;
> > +static siphash_key_t ptr_key __read_mostly;
> > +
> > +static void fill_random_ptr_key(struct random_ready_callback *unused)
> > +{
> > + get_random_bytes(&ptr_key, sizeof(ptr_key));
> > + WRITE_ONCE(have_filled_random_ptr_key, true);
>
> This usage of WRITE_ONCE was suggested by Jason A. Donenfeld. I read
> include/linux/compiler.h but was not able to grok it. Is this enough to
> stop the compiler re-ordering these two statements?
>
> Or do I need to read Documentation/memory-barriers.txt [again]?

No, the WRITE_ONCE does not stop the compiler from reordering those
statements. If you need that, then you need to do:

get_random_bytes(&ptr_key, sizeof(ptr_key));
barrier();
WRITE_ONCE(have_filled_random_ptr_key, true);

and that only works against interrupts. If you need synchronization
across CPUs, then you need smp_mb().

-- Steve

\
 
 \ /
  Last update: 2017-10-30 22:33    [W:0.162 / U:0.052 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site