Skip to content

Commit e37c698

Browse files
committed
mm: replace ACCESS_ONCE with READ_ONCE or barriers
ACCESS_ONCE does not work reliably on non-scalar types. For example gcc 4.6 and 4.7 might remove the volatile tag for such accesses during the SRA (scalar replacement of aggregates) step (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58145) Let's change the code to access the page table elements with READ_ONCE that does implicit scalar accesses for the gup code. mm_find_pmd is tricky, because m68k and sparc(32bit) define pmd_t as array of longs. This code requires just that the pmd_present and pmd_trans_huge check are done on the same value, so a barrier is sufficent. A similar case is in handle_pte_fault. On ppc44x the word size is 32 bit, but a pte is 64 bit. A barrier is ok as well. Signed-off-by: Christian Borntraeger <borntraeger@de.ibm.com> Cc: linux-mm@kvack.org Acked-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
1 parent 230fa25 commit e37c698

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

mm/gup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -917,7 +917,7 @@ static int gup_pud_range(pgd_t *pgdp, unsigned long addr, unsigned long end,
917917

918918
pudp = pud_offset(pgdp, addr);
919919
do {
920-
pud_t pud = ACCESS_ONCE(*pudp);
920+
pud_t pud = READ_ONCE(*pudp);
921921

922922
next = pud_addr_end(addr, end);
923923
if (pud_none(pud))

mm/memory.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3202,7 +3202,16 @@ static int handle_pte_fault(struct mm_struct *mm,
32023202
pte_t entry;
32033203
spinlock_t *ptl;
32043204

3205-
entry = ACCESS_ONCE(*pte);
3205+
/*
3206+
* some architectures can have larger ptes than wordsize,
3207+
* e.g.ppc44x-defconfig has CONFIG_PTE_64BIT=y and CONFIG_32BIT=y,
3208+
* so READ_ONCE or ACCESS_ONCE cannot guarantee atomic accesses.
3209+
* The code below just needs a consistent view for the ifs and
3210+
* we later double check anyway with the ptl lock held. So here
3211+
* a barrier will do.
3212+
*/
3213+
entry = *pte;
3214+
barrier();
32063215
if (!pte_present(entry)) {
32073216
if (pte_none(entry)) {
32083217
if (vma->vm_ops) {

mm/rmap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,8 @@ pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address)
581581
* without holding anon_vma lock for write. So when looking for a
582582
* genuine pmde (in which to find pte), test present and !THP together.
583583
*/
584-
pmde = ACCESS_ONCE(*pmd);
584+
pmde = *pmd;
585+
barrier();
585586
if (!pmd_present(pmde) || pmd_trans_huge(pmde))
586587
pmd = NULL;
587588
out:

0 commit comments

Comments
 (0)