]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
riscv: Fixup race condition on PG_dcache_clean in flush_icache_pte
authorGuo Ren <guoren@linux.alibaba.com>
Fri, 27 Jan 2023 03:53:06 +0000 (22:53 -0500)
committerPalmer Dabbelt <palmer@rivosinc.com>
Thu, 9 Feb 2023 19:40:32 +0000 (11:40 -0800)
In commit 588a513d3425 ("arm64: Fix race condition on PG_dcache_clean
in __sync_icache_dcache()"), we found RISC-V has the same issue as the
previous arm64. The previous implementation didn't guarantee the correct
sequence of operations, which means flush_icache_all() hasn't been
called when the PG_dcache_clean was set. That would cause a risk of page
synchronization.

Fixes: 08f051eda33b ("RISC-V: Flush I$ when making a dirty page executable")
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Reviewed-by: Andrew Jones <ajones@ventanamicro.com>
Reviewed-by: Conor Dooley <conor.dooley@microchip.com>
Link: https://lore.kernel.org/r/20230127035306.1819561-1-guoren@kernel.org
Cc: stable@vger.kernel.org
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/mm/cacheflush.c

index 3cc07ed45aeb3c3e68399c01f046f62856a58b61..fcd6145fbeadce85a3de645e384b73c52146432a 100644 (file)
@@ -90,8 +90,10 @@ void flush_icache_pte(pte_t pte)
        if (PageHuge(page))
                page = compound_head(page);
 
-       if (!test_and_set_bit(PG_dcache_clean, &page->flags))
+       if (!test_bit(PG_dcache_clean, &page->flags)) {
                flush_icache_all();
+               set_bit(PG_dcache_clean, &page->flags);
+       }
 }
 #endif /* CONFIG_MMU */