Skip to content

Commit 88247e8

Browse files
kvaneeshozbenh
authored andcommitted
powerpc/mm: Add new "set" flag argument to pte/pmd update function
pte_update() is a powerpc-ism used to change the bits of a PTE when the access permission is being restricted (a flush is potentially needed). It uses atomic operations on when needed and handles the hash synchronization on hash based processors. It is currently only used to clear PTE bits and so the current implementation doesn't provide a way to also set PTE bits. The new _PAGE_NUMA bit, when set, is actually restricting access so it must use that function too, so this change adds the ability for pte_update() to also set bits. We will use this later to set the _PAGE_NUMA bit. Acked-by: Mel Gorman <mgorman@suse.de> Acked-by: Rik van Riel <riel@redhat.com> Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
1 parent 49d9684 commit 88247e8

4 files changed

Lines changed: 24 additions & 18 deletions

File tree

‎arch/powerpc/include/asm/hugetlb.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
127127
unsigned long addr, pte_t *ptep)
128128
{
129129
#ifdef CONFIG_PPC64
130-
return __pte(pte_update(mm, addr, ptep, ~0UL, 1));
130+
return __pte(pte_update(mm, addr, ptep, ~0UL, 0, 1));
131131
#else
132132
return __pte(pte_update(ptep, ~0UL, 0));
133133
#endif

‎arch/powerpc/include/asm/pgtable-ppc64.h‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ extern void hpte_need_flush(struct mm_struct *mm, unsigned long addr,
195195
static inline unsigned long pte_update(struct mm_struct *mm,
196196
unsigned long addr,
197197
pte_t *ptep, unsigned long clr,
198+
unsigned long set,
198199
int huge)
199200
{
200201
#ifdef PTE_ATOMIC_UPDATES
@@ -205,14 +206,15 @@ static inline unsigned long pte_update(struct mm_struct *mm,
205206
andi. %1,%0,%6\n\
206207
bne- 1b \n\
207208
andc %1,%0,%4 \n\
209+
or %1,%1,%7\n\
208210
stdcx. %1,0,%3 \n\
209211
bne- 1b"
210212
: "=&r" (old), "=&r" (tmp), "=m" (*ptep)
211-
: "r" (ptep), "r" (clr), "m" (*ptep), "i" (_PAGE_BUSY)
213+
: "r" (ptep), "r" (clr), "m" (*ptep), "i" (_PAGE_BUSY), "r" (set)
212214
: "cc" );
213215
#else
214216
unsigned long old = pte_val(*ptep);
215-
*ptep = __pte(old & ~clr);
217+
*ptep = __pte((old & ~clr) | set);
216218
#endif
217219
/* huge pages use the old page table lock */
218220
if (!huge)
@@ -231,9 +233,9 @@ static inline int __ptep_test_and_clear_young(struct mm_struct *mm,
231233
{
232234
unsigned long old;
233235

234-
if ((pte_val(*ptep) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) == 0)
236+
if ((pte_val(*ptep) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) == 0)
235237
return 0;
236-
old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0);
238+
old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0, 0);
237239
return (old & _PAGE_ACCESSED) != 0;
238240
}
239241
#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG
@@ -252,7 +254,7 @@ static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
252254
if ((pte_val(*ptep) & _PAGE_RW) == 0)
253255
return;
254256

255-
pte_update(mm, addr, ptep, _PAGE_RW, 0);
257+
pte_update(mm, addr, ptep, _PAGE_RW, 0, 0);
256258
}
257259

258260
static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
@@ -261,7 +263,7 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
261263
if ((pte_val(*ptep) & _PAGE_RW) == 0)
262264
return;
263265

264-
pte_update(mm, addr, ptep, _PAGE_RW, 1);
266+
pte_update(mm, addr, ptep, _PAGE_RW, 0, 1);
265267
}
266268

267269
/*
@@ -284,14 +286,14 @@ static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
284286
static inline pte_t ptep_get_and_clear(struct mm_struct *mm,
285287
unsigned long addr, pte_t *ptep)
286288
{
287-
unsigned long old = pte_update(mm, addr, ptep, ~0UL, 0);
289+
unsigned long old = pte_update(mm, addr, ptep, ~0UL, 0, 0);
288290
return __pte(old);
289291
}
290292

291293
static inline void pte_clear(struct mm_struct *mm, unsigned long addr,
292294
pte_t * ptep)
293295
{
294-
pte_update(mm, addr, ptep, ~0UL, 0);
296+
pte_update(mm, addr, ptep, ~0UL, 0, 0);
295297
}
296298

297299

@@ -506,7 +508,9 @@ extern int pmdp_set_access_flags(struct vm_area_struct *vma,
506508

507509
extern unsigned long pmd_hugepage_update(struct mm_struct *mm,
508510
unsigned long addr,
509-
pmd_t *pmdp, unsigned long clr);
511+
pmd_t *pmdp,
512+
unsigned long clr,
513+
unsigned long set);
510514

511515
static inline int __pmdp_test_and_clear_young(struct mm_struct *mm,
512516
unsigned long addr, pmd_t *pmdp)
@@ -515,7 +519,7 @@ static inline int __pmdp_test_and_clear_young(struct mm_struct *mm,
515519

516520
if ((pmd_val(*pmdp) & (_PAGE_ACCESSED | _PAGE_HASHPTE)) == 0)
517521
return 0;
518-
old = pmd_hugepage_update(mm, addr, pmdp, _PAGE_ACCESSED);
522+
old = pmd_hugepage_update(mm, addr, pmdp, _PAGE_ACCESSED, 0);
519523
return ((old & _PAGE_ACCESSED) != 0);
520524
}
521525

@@ -542,7 +546,7 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm, unsigned long addr,
542546
if ((pmd_val(*pmdp) & _PAGE_RW) == 0)
543547
return;
544548

545-
pmd_hugepage_update(mm, addr, pmdp, _PAGE_RW);
549+
pmd_hugepage_update(mm, addr, pmdp, _PAGE_RW, 0);
546550
}
547551

548552
#define __HAVE_ARCH_PMDP_SPLITTING_FLUSH

‎arch/powerpc/mm/pgtable_64.c‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,8 @@ int pmdp_set_access_flags(struct vm_area_struct *vma, unsigned long address,
510510
}
511511

512512
unsigned long pmd_hugepage_update(struct mm_struct *mm, unsigned long addr,
513-
pmd_t *pmdp, unsigned long clr)
513+
pmd_t *pmdp, unsigned long clr,
514+
unsigned long set)
514515
{
515516

516517
unsigned long old, tmp;
@@ -526,14 +527,15 @@ unsigned long pmd_hugepage_update(struct mm_struct *mm, unsigned long addr,
526527
andi. %1,%0,%6\n\
527528
bne- 1b \n\
528529
andc %1,%0,%4 \n\
530+
or %1,%1,%7\n\
529531
stdcx. %1,0,%3 \n\
530532
bne- 1b"
531533
: "=&r" (old), "=&r" (tmp), "=m" (*pmdp)
532-
: "r" (pmdp), "r" (clr), "m" (*pmdp), "i" (_PAGE_BUSY)
534+
: "r" (pmdp), "r" (clr), "m" (*pmdp), "i" (_PAGE_BUSY), "r" (set)
533535
: "cc" );
534536
#else
535537
old = pmd_val(*pmdp);
536-
*pmdp = __pmd(old & ~clr);
538+
*pmdp = __pmd((old & ~clr) | set);
537539
#endif
538540
if (old & _PAGE_HASHPTE)
539541
hpte_do_hugepage_flush(mm, addr, pmdp);
@@ -708,7 +710,7 @@ void set_pmd_at(struct mm_struct *mm, unsigned long addr,
708710
void pmdp_invalidate(struct vm_area_struct *vma, unsigned long address,
709711
pmd_t *pmdp)
710712
{
711-
pmd_hugepage_update(vma->vm_mm, address, pmdp, _PAGE_PRESENT);
713+
pmd_hugepage_update(vma->vm_mm, address, pmdp, _PAGE_PRESENT, 0);
712714
}
713715

714716
/*
@@ -835,7 +837,7 @@ pmd_t pmdp_get_and_clear(struct mm_struct *mm,
835837
unsigned long old;
836838
pgtable_t *pgtable_slot;
837839

838-
old = pmd_hugepage_update(mm, addr, pmdp, ~0UL);
840+
old = pmd_hugepage_update(mm, addr, pmdp, ~0UL, 0);
839841
old_pmd = __pmd(old);
840842
/*
841843
* We have pmd == none and we are holding page_table_lock.

‎arch/powerpc/mm/subpage-prot.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ static void hpte_flush_range(struct mm_struct *mm, unsigned long addr,
7878
pte = pte_offset_map_lock(mm, pmd, addr, &ptl);
7979
arch_enter_lazy_mmu_mode();
8080
for (; npages > 0; --npages) {
81-
pte_update(mm, addr, pte, 0, 0);
81+
pte_update(mm, addr, pte, 0, 0, 0);
8282
addr += PAGE_SIZE;
8383
++pte;
8484
}

0 commit comments

Comments
 (0)