Commit c30fa83b authored by Alexandre Ghiti's avatar Alexandre Ghiti Committed by Palmer Dabbelt

riscv: Use WRITE_ONCE() when setting page table entries

To avoid any compiler "weirdness" when accessing page table entries which
are concurrently modified by the HW, let's use WRITE_ONCE() macro
(commit 20a004e7 ("arm64: mm: Use READ_ONCE/WRITE_ONCE when accessing
page tables") gives a great explanation with more details).
Signed-off-by: default avatarAlexandre Ghiti <alexghiti@rivosinc.com>
Link: https://lore.kernel.org/r/20231213203001.179237-2-alexghiti@rivosinc.comSigned-off-by: default avatarPalmer Dabbelt <palmer@rivosinc.com>
parent b85ea95d
...@@ -202,7 +202,7 @@ static inline int pud_user(pud_t pud) ...@@ -202,7 +202,7 @@ static inline int pud_user(pud_t pud)
static inline void set_pud(pud_t *pudp, pud_t pud) static inline void set_pud(pud_t *pudp, pud_t pud)
{ {
*pudp = pud; WRITE_ONCE(*pudp, pud);
} }
static inline void pud_clear(pud_t *pudp) static inline void pud_clear(pud_t *pudp)
...@@ -278,7 +278,7 @@ static inline unsigned long _pmd_pfn(pmd_t pmd) ...@@ -278,7 +278,7 @@ static inline unsigned long _pmd_pfn(pmd_t pmd)
static inline void set_p4d(p4d_t *p4dp, p4d_t p4d) static inline void set_p4d(p4d_t *p4dp, p4d_t p4d)
{ {
if (pgtable_l4_enabled) if (pgtable_l4_enabled)
*p4dp = p4d; WRITE_ONCE(*p4dp, p4d);
else else
set_pud((pud_t *)p4dp, (pud_t){ p4d_val(p4d) }); set_pud((pud_t *)p4dp, (pud_t){ p4d_val(p4d) });
} }
...@@ -351,7 +351,7 @@ static inline pud_t *pud_offset(p4d_t *p4d, unsigned long address) ...@@ -351,7 +351,7 @@ static inline pud_t *pud_offset(p4d_t *p4d, unsigned long address)
static inline void set_pgd(pgd_t *pgdp, pgd_t pgd) static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
{ {
if (pgtable_l5_enabled) if (pgtable_l5_enabled)
*pgdp = pgd; WRITE_ONCE(*pgdp, pgd);
else else
set_p4d((p4d_t *)pgdp, (p4d_t){ pgd_val(pgd) }); set_p4d((p4d_t *)pgdp, (p4d_t){ pgd_val(pgd) });
} }
......
...@@ -248,7 +248,7 @@ static inline int pmd_leaf(pmd_t pmd) ...@@ -248,7 +248,7 @@ static inline int pmd_leaf(pmd_t pmd)
static inline void set_pmd(pmd_t *pmdp, pmd_t pmd) static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
{ {
*pmdp = pmd; WRITE_ONCE(*pmdp, pmd);
} }
static inline void pmd_clear(pmd_t *pmdp) static inline void pmd_clear(pmd_t *pmdp)
...@@ -510,7 +510,7 @@ static inline int pte_same(pte_t pte_a, pte_t pte_b) ...@@ -510,7 +510,7 @@ static inline int pte_same(pte_t pte_a, pte_t pte_b)
*/ */
static inline void set_pte(pte_t *ptep, pte_t pteval) static inline void set_pte(pte_t *ptep, pte_t pteval)
{ {
*ptep = pteval; WRITE_ONCE(*ptep, pteval);
} }
void flush_icache_pte(pte_t pte); void flush_icache_pte(pte_t pte);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment