Message ID | 20241021-atomic-read-acquire-v2-1-e5cb03a35b37@linaro.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | [v2] mm: Pair atomic_set_release() with _read_acquire() | expand |
On Mon, Oct 21, 2024 at 1:26 PM Linus Walleij <linus.walleij@linaro.org> wrote: > The code for syncing vmalloc memory PGD pointers is using > atomic_read() in pair with atomic_set_release() but the > proper pairing is atomic_read_acquire() paired with > atomic_set_release(). > > This is done to clearly instruct the compiler to not > reorder the memcpy() or similar calls inside the section > so that we do not observe changes to init_mm. memcpy() > calls should be identified by the compiler as having > unpredictable side effects, but let's try to be on the > safe side. > > Fixes: d31e23aff011 ("ARM: mm: make vmalloc_seq handling SMP safe") > Suggested-by: Mark Rutland <mark.rutland@arm.com> > Signed-off-by: Linus Walleij <linus.walleij@linaro.org> > --- > This patch was done on top of Melon Liu's patch: > https://www.arm.linux.org.uk/developer/patches/viewpatch.php?id=9427/1 It turns out this patch does not build without KASAN enabled, so it will need to be dropped. I incorporated a line of Melon's semantics and included this patch into my recent series and resent. Yours, Linus Walleij
diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c index f952b0b0f8a5..257ed86f3474 100644 --- a/arch/arm/mm/ioremap.c +++ b/arch/arm/mm/ioremap.c @@ -138,7 +138,7 @@ void __check_vmalloc_seq(struct mm_struct *mm) int seq; do { - seq = atomic_read(&init_mm.context.vmalloc_seq); + seq = atomic_read_acquire(&init_mm.context.vmalloc_seq); sync_vmalloc_pgds(mm); /* * Use a store-release so that other CPUs that observe the
The code for syncing vmalloc memory PGD pointers is using atomic_read() in pair with atomic_set_release() but the proper pairing is atomic_read_acquire() paired with atomic_set_release(). This is done to clearly instruct the compiler to not reorder the memcpy() or similar calls inside the section so that we do not observe changes to init_mm. memcpy() calls should be identified by the compiler as having unpredictable side effects, but let's try to be on the safe side. Fixes: d31e23aff011 ("ARM: mm: make vmalloc_seq handling SMP safe") Suggested-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> --- This patch was done on top of Melon Liu's patch: https://www.arm.linux.org.uk/developer/patches/viewpatch.php?id=9427/1 --- Changes in v2: - Fix the terminology from the hopelessly misread function names in v1 :( - Write an extended blurb summing up the discussion around this change wrt init_mm. - Link to v1: https://lore.kernel.org/r/20241021-atomic-read-acquire-v1-1-4dee71191c06@linaro.org --- arch/arm/mm/ioremap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- base-commit: d530f55d9fde0aae4ac90e072b288da13f6aae81 change-id: 20241021-atomic-read-acquire-52a667991cfc Best regards,