From: I Hsin Cheng Date: Sun, 26 May 2024 14:01:39 +0000 (+0800) Subject: lib/plist.c: enforce memory ordering in plist_check_list X-Git-Tag: v6.11-rc1~84^2~61 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7abcb84f953df037d40fad66f2109db318dd155b;p=thirdparty%2Fkernel%2Flinux.git 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 Signed-off-by: Andrew Morton --- diff --git a/lib/plist.c b/lib/plist.c index 0d86ed7a76ac6..2e51829d3db9d 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -47,8 +47,8 @@ static void plist_check_list(struct list_head *top) plist_check_prev_next(top, prev, next); while (next != top) { - prev = next; - next = prev->next; + WRITE_ONCE(prev, next); + WRITE_ONCE(next, prev->next); plist_check_prev_next(top, prev, next); } }