Skip to contentSkip to conversation

mm/page_vma_mapped_walk: Use ptep_get_lockless() for lockless access

PATCH In review Alexander Gordeev 5 participants 9 messages May 28 – Jun 1

Subsystems (3)
lore
Share & tools
lore

Alexander Gordeev

author maintainer
#0 lore raw

PATCH v3 1/1 mm/page_vma_mapped_walk: Use ptep_get_lockless() for lockless access

Switch from ptep_get() to ptep_get_lockless() accessor for PTE reads when no lock is taken.

---
 mm/page_vma_mapped.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
mm/page_vma_mapped.c +7 -2
index a4d52fdb3056..2ccbabfb2cc1 100644
@@ -41,7 +41,7 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw, pmd_t *pmdvalp,
 	if (!pvmw->pte)
 		return false;
 
-	ptent = ptep_get(pvmw->pte);
+	ptent = ptep_get_lockless(pvmw->pte);
 
 	if (pte_none(ptent)) {
 		return false;
@@ -183,6 +183,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
 	struct mm_struct *mm = vma->vm_mm;
 	unsigned long end;
 	spinlock_t *ptl;
+	pte_t pteval;
 	pgd_t *pgd;
 	p4d_t *p4d;
 	pud_t *pud;
@@ -310,7 +311,11 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
 				goto restart;
 			}
 			pvmw->pte++;
-		} while (pte_none(ptep_get(pvmw->pte)));
+			if (!pvmw->ptl)
+				pteval = ptep_get_lockless(pvmw->pte);
+			else
+				pteval = ptep_get(pvmw->pte);
+		} while (pte_none(pteval));
 
 		if (!pvmw->ptl) {
 			spin_lock(ptl);
Signature · 1 line
2.51.0
Reviewed-by on v3 1/1
#1 lore raw
Quoted 30 lines · Alexander Gordeev

Switch from ptep_get() to ptep_get_lockless() accessor for PTE reads when no lock is taken.

---
mm/page_vma_mapped.c | 9 +++++++--

1 file changed, 7 insertions(+), 2 deletions(-)
mm/page_vma_mapped.c +2 -1
index a4d52fdb3056..2ccbabfb2cc1 100644
@@ -41,7 +41,7 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw, pmd_t *pmdvalp,
 	if (!pvmw->pte)
 		return false;
 
-	ptent = ptep_get(pvmw->pte);
+	ptent = ptep_get_lockless(pvmw->pte);
 
 	if (pte_none(ptent)) {
 		return false;
@@ -183,6 +183,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
 	struct mm_struct *mm = vma->vm_mm;
 	unsigned long end;
 	spinlock_t *ptl;
+	pte_t pteval;
 	pgd_t *pgd;
 	p4d_t *p4d;
 	pud_t *pud;

mm/page_vma_mapped.c bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw) · line 318

Quoted 9 lines
mm/page_vma_mapped.c +5 -1
@@ -310,7 +311,11 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
 				goto restart;
 			}
 			pvmw->pte++;
-		} while (pte_none(ptep_get(pvmw->pte)));
+			if (!pvmw->ptl)
+				pteval = ptep_get_lockless(pvmw->pte);
+			else
+				pteval = ptep_get(pvmw->pte);
+		} while (pte_none(pteval));

Use ptep_get_lockless() when lock is not taken.

LGTM, thanks

Quoted 5 lines
mm/page_vma_mapped.c +0 -0
 		if (!pvmw->ptl) {
 			spin_lock(ptl);
Signature · 1 line
2.51.0
Signature · 2 lines
Wei Yang
Help you, Help me
maintainer
#2 lore raw
In reply to Alexander Gordeev
Quoted 2 lines · Alexander Gordeev

Switch from ptep_get() to ptep_get_lockless() accessor for PTE reads when no lock is taken.

This is an insufficient commit message that's just saying what you're doing, which isn't very useful.

Please explain why you're doing this and what the benefit is please.

Thanks, Lorenzo

Quoted 43 lines
---
 mm/page_vma_mapped.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
mm/page_vma_mapped.c +7 -3
index a4d52fdb3056..2ccbabfb2cc1 100644
@@ -41,7 +41,7 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw, pmd_t *pmdvalp,
 	if (!pvmw->pte)
 		return false;
 
-	ptent = ptep_get(pvmw->pte);
+	ptent = ptep_get_lockless(pvmw->pte);
 
 	if (pte_none(ptent)) {
 		return false;
@@ -183,6 +183,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
 	struct mm_struct *mm = vma->vm_mm;
 	unsigned long end;
 	spinlock_t *ptl;
+	pte_t pteval;
 	pgd_t *pgd;
 	p4d_t *p4d;
 	pud_t *pud;
@@ -310,7 +311,11 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
 				goto restart;
 			}
 			pvmw->pte++;
-		} while (pte_none(ptep_get(pvmw->pte)));
+			if (!pvmw->ptl)
+				pteval = ptep_get_lockless(pvmw->pte);
+			else
+				pteval = ptep_get(pvmw->pte);
+		} while (pte_none(pteval));
 
 		if (!pvmw->ptl) {
 			spin_lock(ptl);
--

2.51.0

#3 lore raw
Quoted 8 lines · Lorenzo Stoakes
Quoted 2 lines · Alexander Gordeev

Switch from ptep_get() to ptep_get_lockless() accessor for PTE reads when no lock is taken.

This is an insufficient commit message that's just saying what you're doing, which isn't very useful.

Please explain why you're doing this and what the benefit is please.

Maybe something like

"When not holding the lock, there is a chance that the pte gets modified
under our feet, so we need to use the lockless API to make sure that the entries remain consistent during the read."

Only arm64 makes use of it though, due to the contpte stuff and being unable to do it atomically.

Signature · 2 lines
Oscar Salvador
SUSE Labs
author maintainer
#4 lore raw
Quoted 8 lines · Oscar Salvador (SUSE)
Quoted 7 lines · Lorenzo Stoakes
Quoted 2 lines · Alexander Gordeev

Switch from ptep_get() to ptep_get_lockless() accessor for PTE reads when no lock is taken.

This is an insufficient commit message that's just saying what you're doing, which isn't very useful.

Quoted 7 lines
Quoted 1 line

Please explain why you're doing this and what the benefit is please.

Maybe something like

"When not holding the lock, there is a chance that the pte gets modified
under our feet, so we need to use the lockless API to make sure that the entries remain consistent during the read."

I would gladly use this, if it makes sense for everyone.

@Lorenzo?

Quoted 2 lines

Only arm64 makes use of it though, due to the contpte stuff and being unable to do it atomically.

Thanks!

Quoted 3 lines
Signature · 2 lines
Oscar Salvador
SUSE Labs
maintainer
#5 lore raw
Quoted 13 lines · Alexander Gordeev
Quoted 12 lines · Oscar Salvador (SUSE)
Quoted 8 lines · Lorenzo Stoakes
Quoted 2 lines · Alexander Gordeev

Switch from ptep_get() to ptep_get_lockless() accessor for PTE reads when no lock is taken.

This is an insufficient commit message that's just saying what you're doing, which isn't very useful.

Please explain why you're doing this and what the benefit is please.

Maybe something like

Quoted 7 lines
Quoted 3 lines

"When not holding the lock, there is a chance that the pte gets modified
under our feet, so we need to use the lockless API to make sure that the entries remain consistent during the read."

I would gladly use this, if it makes sense for everyone.

@Lorenzo?

Sounds good to me! Thanks

Quoted 9 lines
Quoted 3 lines

Only arm64 makes use of it though, due to the contpte stuff and being unable to do it atomically.

Thanks!

Quoted 3 lines

--
Oscar Salvador
SUSE Labs

Cheers, Lorenzo

Reviewed-by on v3 1/1
#6 lore raw
In reply to Alexander Gordeev
Quoted 4 lines · Alexander Gordeev

Switch from ptep_get() to ptep_get_lockless() accessor for PTE reads when no lock is taken.

I see Andrew has picked up the patch with the amended changelog, so with that:

Quoted 41 lines
---
 mm/page_vma_mapped.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
mm/page_vma_mapped.c +7 -2
index a4d52fdb3056..2ccbabfb2cc1 100644
@@ -41,7 +41,7 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw, pmd_t *pmdvalp,
 	if (!pvmw->pte)
 		return false;
 
-	ptent = ptep_get(pvmw->pte);
+	ptent = ptep_get_lockless(pvmw->pte);
 
 	if (pte_none(ptent)) {
 		return false;
@@ -183,6 +183,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
 	struct mm_struct *mm = vma->vm_mm;
 	unsigned long end;
 	spinlock_t *ptl;
+	pte_t pteval;
 	pgd_t *pgd;
 	p4d_t *p4d;
 	pud_t *pud;
@@ -310,7 +311,11 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
 				goto restart;
 			}
 			pvmw->pte++;
-		} while (pte_none(ptep_get(pvmw->pte)));
+			if (!pvmw->ptl)
+				pteval = ptep_get_lockless(pvmw->pte);
+			else
+				pteval = ptep_get(pvmw->pte);
+		} while (pte_none(pteval));
 
 		if (!pvmw->ptl) {
 			spin_lock(ptl);
Signature · 1 line
2.51.0
Signature · 2 lines
Oscar Salvador
SUSE Labs
maintainer Reviewed-by on v3 1/1
#8 lore raw
In reply to Alexander Gordeev
Quoted 4 lines · Alexander Gordeev

Switch from ptep_get() to ptep_get_lockless() accessor for PTE reads when no lock is taken.

Oh and the logic looks good so with the commit message updated, feel free to add:

Quoted 41 lines
---
 mm/page_vma_mapped.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
mm/page_vma_mapped.c +7 -3
index a4d52fdb3056..2ccbabfb2cc1 100644
@@ -41,7 +41,7 @@ static bool map_pte(struct page_vma_mapped_walk *pvmw, pmd_t *pmdvalp,
 	if (!pvmw->pte)
 		return false;
 
-	ptent = ptep_get(pvmw->pte);
+	ptent = ptep_get_lockless(pvmw->pte);
 
 	if (pte_none(ptent)) {
 		return false;
@@ -183,6 +183,7 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
 	struct mm_struct *mm = vma->vm_mm;
 	unsigned long end;
 	spinlock_t *ptl;
+	pte_t pteval;
 	pgd_t *pgd;
 	p4d_t *p4d;
 	pud_t *pud;
@@ -310,7 +311,11 @@ bool page_vma_mapped_walk(struct page_vma_mapped_walk *pvmw)
 				goto restart;
 			}
 			pvmw->pte++;
-		} while (pte_none(ptep_get(pvmw->pte)));
+			if (!pvmw->ptl)
+				pteval = ptep_get_lockless(pvmw->pte);
+			else
+				pteval = ptep_get(pvmw->pte);
+		} while (pte_none(pteval));
 
 		if (!pvmw->ptl) {
 			spin_lock(ptl);
--

2.51.0