Skip to contentSkip to conversation

mm/vmalloc: leave lazy MMU mode on PTE mapping error

PATCH Applied Alexander Gordeev 3 participants 6 messages Jun 23, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm/vmalloc: leave lazy MMU mode on PTE mapping error

Function vmap_pages_pte_range() enters the lazy MMU mode, but fails to leave it in case an error is encountered.

Fixes 44562c71e2cf ("mm/vmalloc: Enter lazy mmu mode while manipulating vmalloc ptes")
---
 mm/vmalloc.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
mm/vmalloc.c +15 -7
index ab986dd09b6a..6dbcdceecae1 100644
@@ -514,6 +514,7 @@ static int vmap_pages_pte_range(pmd_t *pmd, unsigned long addr,
 		unsigned long end, pgprot_t prot, struct page **pages, int *nr,
 		pgtbl_mod_mask *mask)
 {
+	int err = 0;
 	pte_t *pte;
 
 	/*
@@ -530,12 +531,18 @@ static int vmap_pages_pte_range(pmd_t *pmd, unsigned long addr,
 	do {
 		struct page *page = pages[*nr];
 
-		if (WARN_ON(!pte_none(ptep_get(pte))))
-			return -EBUSY;
-		if (WARN_ON(!page))
-			return -ENOMEM;
-		if (WARN_ON(!pfn_valid(page_to_pfn(page))))
-			return -EINVAL;
+		if (WARN_ON(!pte_none(ptep_get(pte)))) {
+			err = -EBUSY;
+			break;
+		}
+		if (WARN_ON(!page)) {
+			err = -ENOMEM;
+			break;
+		}
+		if (WARN_ON(!pfn_valid(page_to_pfn(page)))) {
+			err = -EINVAL;
+			break;
+		}
 
 		set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
 		(*nr)++;
@@ -543,7 +550,8 @@ static int vmap_pages_pte_range(pmd_t *pmd, unsigned long addr,
 
 	arch_leave_lazy_mmu_mode();
 	*mask |= PGTBL_PTE_MODIFIED;
-	return 0;
+
+	return err;
 }
 
 static int vmap_pages_pmd_range(pud_t *pud, unsigned long addr,
Signature · 1 line
2.48.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Alexander Gordeev

Function vmap_pages_pte_range() enters the lazy MMU mode, but fails to leave it in case an error is encountered.

Fixes 44562c71e2cf ("mm/vmalloc: Enter lazy mmu mode while manipulating vmalloc ptes")

Ouch, sorry about that! The patch looks good to me so:

I wonder an aditional Fixes: should be added for Commit 2ba3e6947aed ("mm/vmalloc: track which page-table levels were modified") though? That's the one that added the "*mask |= PGTBL_PTE_MODIFIED;" which would have also been skipped if an error occured before this patch.

Thanks,
Ryan

Quoted 51 lines
---
 mm/vmalloc.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
mm/vmalloc.c +15 -7
index ab986dd09b6a..6dbcdceecae1 100644
@@ -514,6 +514,7 @@ static int vmap_pages_pte_range(pmd_t *pmd, unsigned long addr,
 		unsigned long end, pgprot_t prot, struct page **pages, int *nr,
 		pgtbl_mod_mask *mask)
 {
+	int err = 0;
 	pte_t *pte;
 
 	/*
@@ -530,12 +531,18 @@ static int vmap_pages_pte_range(pmd_t *pmd, unsigned long addr,
 	do {
 		struct page *page = pages[*nr];
 
-		if (WARN_ON(!pte_none(ptep_get(pte))))
-			return -EBUSY;
-		if (WARN_ON(!page))
-			return -ENOMEM;
-		if (WARN_ON(!pfn_valid(page_to_pfn(page))))
-			return -EINVAL;
+		if (WARN_ON(!pte_none(ptep_get(pte)))) {
+			err = -EBUSY;
+			break;
+		}
+		if (WARN_ON(!page)) {
+			err = -ENOMEM;
+			break;
+		}
+		if (WARN_ON(!pfn_valid(page_to_pfn(page)))) {
+			err = -EINVAL;
+			break;
+		}
 
 		set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
 		(*nr)++;
@@ -543,7 +550,8 @@ static int vmap_pages_pte_range(pmd_t *pmd, unsigned long addr,
 
 	arch_leave_lazy_mmu_mode();
 	*mask |= PGTBL_PTE_MODIFIED;
-	return 0;
+
+	return err;
 }
 
 static int vmap_pages_pmd_range(pud_t *pud, unsigned long addr,
#2 lore raw
Quoted 10 lines · Ryan Roberts
Quoted 8 lines · Alexander Gordeev

Function vmap_pages_pte_range() enters the lazy MMU mode, but fails to leave it in case an error is encountered.

Fixes 44562c71e2cf ("mm/vmalloc: Enter lazy mmu mode while manipulating vmalloc ptes")
Quoted 8 lines

Ouch, sorry about that! The patch looks good to me so:

I wonder an aditional Fixes: should be added for Commit 2ba3e6947aed ("mm/vmalloc: track which page-table levels were modified") though? That's the one that added the "*mask |= PGTBL_PTE_MODIFIED;" which would have also been skipped if an error occured before this patch.

Good catch! I think it certainly needs to be reported with Fixes and I even doubt whether your commit should be mentioned at all?

Quoted 2 lines

Thanks,
Ryan

Thanks!

#3 lore raw
Quoted 15 lines · Alexander Gordeev
Quoted 14 lines · Ryan Roberts
Quoted 8 lines · Alexander Gordeev

Function vmap_pages_pte_range() enters the lazy MMU mode, but fails to leave it in case an error is encountered.

Fixes 44562c71e2cf ("mm/vmalloc: Enter lazy mmu mode while manipulating vmalloc ptes")

Ouch, sorry about that! The patch looks good to me so:

Quoted 7 lines
Quoted 4 lines

I wonder an aditional Fixes: should be added for Commit 2ba3e6947aed ("mm/vmalloc: track which page-table levels were modified") though? That's the one that added the "*mask |= PGTBL_PTE_MODIFIED;" which would have also been skipped if an error occured before this patch.

Good catch! I think it certainly needs to be reported with Fixes and I even doubt whether your commit should be mentioned at all?

Well I would certainly argue that my patch is broken as is. So happy to have 2
Fixes: tags. But I'm not really sure what the rules are here...

Quoted 5 lines
Quoted 3 lines

Thanks,
Ryan

Thanks!

#4 lore raw
Quoted 21 lines · Ryan Roberts
Quoted 20 lines · Alexander Gordeev
Quoted 18 lines · Ryan Roberts
Quoted 8 lines · Alexander Gordeev

Function vmap_pages_pte_range() enters the lazy MMU mode, but fails to leave it in case an error is encountered.

Fixes 44562c71e2cf ("mm/vmalloc: Enter lazy mmu mode while manipulating vmalloc ptes")

Ouch, sorry about that! The patch looks good to me so:

I wonder an aditional Fixes: should be added for Commit 2ba3e6947aed ("mm/vmalloc: track which page-table levels were modified") though? That's the one that added the "*mask |= PGTBL_PTE_MODIFIED;" which would have also been skipped if an error occured before this patch.

Quoted 5 lines
Quoted 2 lines

Good catch! I think it certainly needs to be reported with Fixes and I even doubt whether your commit should be mentioned at all?

Well I would certainly argue that my patch is broken as is. So happy to have 2
Fixes: tags. But I'm not really sure what the rules are here...

I would only list the older commit 2ba3e6947aed ("mm/vmalloc: track which page-table levels were modified"). The static checker warning came later, but it's not really the important bit. It's just one bug.

We'll have to hand edit the commit if we want to backport it so that's a separate issue.

regards,
dan carpenter

#5 lore raw
Quoted 25 lines · Dan Carpenter
Quoted 24 lines · Ryan Roberts
Quoted 22 lines · Alexander Gordeev
Quoted 10 lines · Ryan Roberts
Quoted 8 lines · Alexander Gordeev

Function vmap_pages_pte_range() enters the lazy MMU mode, but fails to leave it in case an error is encountered.

Fixes 44562c71e2cf ("mm/vmalloc: Enter lazy mmu mode while manipulating vmalloc ptes")
Quoted 8 lines

Ouch, sorry about that! The patch looks good to me so:

I wonder an aditional Fixes: should be added for Commit 2ba3e6947aed ("mm/vmalloc: track which page-table levels were modified") though? That's the one that added the "*mask |= PGTBL_PTE_MODIFIED;" which would have also been skipped if an error occured before this patch.

Good catch! I think it certainly needs to be reported with Fixes and I even doubt whether your commit should be mentioned at all?

Quoted 6 lines
Quoted 2 lines

Well I would certainly argue that my patch is broken as is. So happy to have 2
Fixes: tags. But I'm not really sure what the rules are here...

I would only list the older commit 2ba3e6947aed ("mm/vmalloc: track which page-table levels were modified"). The static checker warning came later, but it's not really the important bit. It's just one bug.

Given smatch caught the locking bug, I wonder if it could be taught to look for lazy_mmu issues? i.e. unbalanced enter/leave, nesting and read hazards. I think Alexander previously found a read hazard so I wouldn't be surprised if there are more.

Quoted 7 lines

We'll have to hand edit the commit if we want to backport it so that's a separate issue.

regards,
dan carpenter