Re: [PATCH] bpf: don't fail kmalloc while releasing raw_tp

From: Steven Rostedt
Date: Tue Nov 17 2020 - 20:09:47 EST


On Tue, 17 Nov 2020 16:42:44 -0800
Matt Mullins <mmullins@xxxxxxx> wrote:


> > Indeed with a stub function, I don't see any need for READ_ONCE/WRITE_ONCE.
>
> I'm not sure if this is a practical issue, but without WRITE_ONCE, can't
> the write be torn? A racing __traceiter_ could potentially see a
> half-modified function pointer, which wouldn't work out too well.

This has been discussed before, and Linus said:

"We add READ_ONCE and WRITE_ONCE annotations when they make sense. Not
because of some theoretical "compiler is free to do garbage"
arguments. If such garbage happens, we need to fix the compiler"

https://lore.kernel.org/lkml/CAHk-=wi_KeD1M-_-_SU_H92vJ-yNkDnAGhAS=RR1yNNGWKW+aA@xxxxxxxxxxxxxx/

>
> This was actually my gut instinct before I wrote the __GFP_NOFAIL
> instead -- currently that whole array's memory ordering is provided by
> RCU and I didn't dive deep enough to evaluate getting too clever with
> atomic modifications to it.

The pointers are always going to be the architecture word size (by
definition), and any compiler that tears a write of a long is broken.

-- Steve