Skip to content

Commit c30fa83

Browse files
Alexandre Ghitipalmer-dabbelt
authored andcommitted
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 20a004e ("arm64: mm: Use READ_ONCE/WRITE_ONCE when accessing page tables") gives a great explanation with more details). Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com> Link: https://lore.kernel.org/r/20231213203001.179237-2-alexghiti@rivosinc.com Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
1 parent b85ea95 commit c30fa83

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

arch/riscv/include/asm/pgtable-64.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static inline int pud_user(pud_t pud)
202202

203203
static inline void set_pud(pud_t *pudp, pud_t pud)
204204
{
205-
*pudp = pud;
205+
WRITE_ONCE(*pudp, pud);
206206
}
207207

208208
static inline void pud_clear(pud_t *pudp)
@@ -278,7 +278,7 @@ static inline unsigned long _pmd_pfn(pmd_t pmd)
278278
static inline void set_p4d(p4d_t *p4dp, p4d_t p4d)
279279
{
280280
if (pgtable_l4_enabled)
281-
*p4dp = p4d;
281+
WRITE_ONCE(*p4dp, p4d);
282282
else
283283
set_pud((pud_t *)p4dp, (pud_t){ p4d_val(p4d) });
284284
}
@@ -351,7 +351,7 @@ static inline pud_t *pud_offset(p4d_t *p4d, unsigned long address)
351351
static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
352352
{
353353
if (pgtable_l5_enabled)
354-
*pgdp = pgd;
354+
WRITE_ONCE(*pgdp, pgd);
355355
else
356356
set_p4d((p4d_t *)pgdp, (p4d_t){ pgd_val(pgd) });
357357
}

arch/riscv/include/asm/pgtable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ static inline int pmd_leaf(pmd_t pmd)
248248

249249
static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
250250
{
251-
*pmdp = pmd;
251+
WRITE_ONCE(*pmdp, pmd);
252252
}
253253

254254
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)
510510
*/
511511
static inline void set_pte(pte_t *ptep, pte_t pteval)
512512
{
513-
*ptep = pteval;
513+
WRITE_ONCE(*ptep, pteval);
514514
}
515515

516516
void flush_icache_pte(pte_t pte);

0 commit comments

Comments
 (0)