[PATCH] lib/plist.c: Enforce memory ordering in plist_check_list

From: I Hsin Cheng
Date: Sun May 26 2024 - 10:01:56 EST


There exist an iteration over a plist in the function plist_check_list,
and memory dependency exists between variables "prev", "next" and
"prev->next". Consider plist is used scheduling subsystem, we should
guarantee the memory order between multiple processors.

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

Signed-off-by: I Hsin Cheng <richard120310@xxxxxxxxx>
---
lib/plist.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/plist.c b/lib/plist.c
index 0d86ed7a7..2e51829d3 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);
}
}
--
2.34.1