Why do we need READ_ONCE() in list_empty()?

2022-04-30 Thread Karim Manaouil
Hi,

list_empty() uses READ_ONCE() to read head->next [1]. AFAIK, READ_ONCE() is
a compile-time memory
barrier to prevent the compiler from reordering the read with the previous
or the following memory accesses.

I checked commit id 1658d35ead5d8dd from its committer Paul E. McKenney
when such a thing was added
to the kernel, to seek for an explanation, but the commit description is
not very insightful. It only says that this
macro might be accessed without the protection of a lock and thus the need
for READ_ONCE.

I still don't understand why READ_ONCE() is needed in list_empty(). Is
there a concrete example where not
wrapping it inside READ_ONCE() could lead to inconsistency/incorrectness?

[1]
https://elixir.bootlin.com/linux/v5.14.11/source/include/linux/list.h#L282

Cheers
Karim
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Linux kernel environment setup in VSCode

2022-04-30 Thread Kwanghoon Son
On Mon, Apr 04, 2022 at 09:31:46PM +0300, Jasper Surmont wrote:
> Hey,
> 
> I'm new to the Linux kernel development, and I wanted to set up a VSCode
> environment for navigating the code (I know, even though people tell me Vim
> is better but currently I'm really not comfortable with it yet).
> My main goal is just navigating and understanding. I've been able to make a
> lot work, and using the C/C++ extension from Microsoft I have good
> IntelliSense.
> 
> However, some things are getting flagged by the extension as errors (which
> of course shouldn't, since I've been able to compile the kernel).
> These are things like: identifiers being undefined (for example, in
> kernel/sched/cpudeadline.c u64 is undefined) and errors like: function
> returning array is not allowed (for example, in drivers/md/dm-zero.c on the
> bottom).
vscode use clang and needs clangd.
you can generate from ./scripts/clang-tools/gen_compile_commands.py
which makes you navigate source code!
> I'm wondering if I'm forgetting things such that all these things get
> resolved. Any tips are appreciated.
> 
> 
> Thanks!
> 
> 
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies