Skip to content

Commit

Permalink
powerpc/nohash: Refactor checking of no-change in pte_update()
Browse files Browse the repository at this point in the history
On nohash/64, a few callers of pte_update() check if there is
really a change in order to avoid an unnecessary write.

Refactor that inside pte_update().

Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://msgid.link/076563e611c2b51036686a8d378bfd5ef1726341.1695659959.git.christophe.leroy@csgroup.eu
  • Loading branch information
chleroy authored and mpe committed Oct 19, 2023
1 parent 42a2722 commit 7c929ad
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 9 deletions.
9 changes: 0 additions & 9 deletions arch/powerpc/include/asm/nohash/64/pgtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,6 @@ static inline int __ptep_test_and_clear_young(struct mm_struct *mm,
{
unsigned long old;

if (!pte_young(*ptep))
return 0;
old = pte_update(mm, addr, ptep, _PAGE_ACCESSED, 0, 0);
return (old & _PAGE_ACCESSED) != 0;
}
Expand All @@ -198,20 +196,13 @@ static inline int __ptep_test_and_clear_young(struct mm_struct *mm,
static inline void ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr,
pte_t *ptep)
{

if ((pte_val(*ptep) & _PAGE_RW) == 0)
return;

pte_update(mm, addr, ptep, _PAGE_RW, 0, 0);
}

#define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT
static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
unsigned long addr, pte_t *ptep)
{
if ((pte_val(*ptep) & _PAGE_RW) == 0)
return;

pte_update(mm, addr, ptep, _PAGE_RW, 0, 1);
}

Expand Down
3 changes: 3 additions & 0 deletions arch/powerpc/include/asm/nohash/pgtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ static inline pte_basic_t pte_update(struct mm_struct *mm, unsigned long addr, p
pte_basic_t old = pte_val(*p);
pte_basic_t new = (old & ~(pte_basic_t)clr) | set;

if (new == old)
return old;

*p = __pte(new);

if (IS_ENABLED(CONFIG_44x) && (old & _PAGE_USER) && (old & _PAGE_EXEC))
Expand Down

0 comments on commit 7c929ad

Please sign in to comment.