Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/plist.c: enforce memory ordering in plist_check_list

There exists an iteration over a plist in plist_check_list(), and memory
dependency exists between variables "prev", "next" and "prev->next". As
plist is used in the scheduling subsystem, we should guarantee the memory
ordering between multiple processors.

Using macro "WRITE_ONCE()" can help us to ensure the memory ordering as
it was stated in "Documentation/memory-barriers.txt".

Link: https://lkml.kernel.org/r/20240526140139.17220-1-richard120310@gmail.com
Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

I Hsin Cheng and committed by
Andrew Morton
7abcb84f 87beb669

+2 -2
+2 -2
lib/plist.c
··· 47 47 48 48 plist_check_prev_next(top, prev, next); 49 49 while (next != top) { 50 - prev = next; 51 - next = prev->next; 50 + WRITE_ONCE(prev, next); 51 + WRITE_ONCE(next, prev->next); 52 52 plist_check_prev_next(top, prev, next); 53 53 } 54 54 }