]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
lib/plist.c: enforce memory ordering in plist_check_list
authorI Hsin Cheng <richard120310@gmail.com>
Sun, 26 May 2024 14:01:39 +0000 (22:01 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 25 Jun 2024 05:25:04 +0000 (22:25 -0700)
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>
lib/plist.c

index 0d86ed7a76ac62535ef59c568b67e55d4d0d9191..2e51829d3db9dfccba62e8fdb476c3dde867aed8 100644 (file)
@@ -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);
        }
 }