Skip to contentSkip to conversation

mm/mempolicy: Move VMA address bound checks inside mpol_misplaced()

PATCH In review Anshuman Khandual 2 participants 6 messages Sep 1, 2017

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

PATCH 1/1 mm/mempolicy: Move VMA address bound checks inside mpol_misplaced()

The VMA address bound checks are applicable to all memory policy modes, not just MPOL_INTERLEAVE. Hence move it to the front and make it common.

---
 mm/mempolicy.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/mempolicy.c +2 -3
index 618ab12..7ec6694 100644
@@ -2173,6 +2173,8 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned long
 	int ret = -1;
 
 	BUG_ON(!vma);
+	BUG_ON(addr >= vma->vm_end);
+	BUG_ON(addr < vma->vm_start);
 
 	pol = get_vma_policy(vma, addr);
 	if (!(pol->flags & MPOL_F_MOF))
@@ -2180,9 +2182,6 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned long
 
 	switch (pol->mode) {
 	case MPOL_INTERLEAVE:
-		BUG_ON(addr >= vma->vm_end);
-		BUG_ON(addr < vma->vm_start);
-
 		pgoff = vma->vm_pgoff;
 		pgoff += (addr - vma->vm_start) >> PAGE_SHIFT;
 		polnid = offset_il_node(pol, vma, pgoff);
Signature · 7 lines
1.8.5.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw
Quoted 2 lines · Anshuman Khandual

The VMA address bound checks are applicable to all memory policy modes, not just MPOL_INTERLEAVE.

But only MPOL_INTERLEAVE actually uses addr and vma->vm_start.

Quoted 3 lines

Hence move it to the front and make it common.

I would just remove them instead. Together with the BUG_ON(!vma). Looks like just leftover from development.

Quoted 19 lines
---
 mm/mempolicy.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
mm/mempolicy.c +2 -0
index 618ab12..7ec6694 100644
@@ -2173,6 +2173,8 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned long
 	int ret = -1;
 
 	BUG_ON(!vma);
+	BUG_ON(addr >= vma->vm_end);
+	BUG_ON(addr < vma->vm_start);
 
 	pol = get_vma_policy(vma, addr);
 	if (!(pol->flags & MPOL_F_MOF))

mm/mempolicy.c int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned long · line 2187

Quoted 9 lines
mm/mempolicy.c +0 -3
@@ -2180,9 +2182,6 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned long
 
 	switch (pol->mode) {
 	case MPOL_INTERLEAVE:
-		BUG_ON(addr >= vma->vm_end);
-		BUG_ON(addr < vma->vm_start);
-
 		pgoff = vma->vm_pgoff;
 		pgoff += (addr - vma->vm_start) >> PAGE_SHIFT;
 		polnid = offset_il_node(pol, vma, pgoff);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 5 lines · Vlastimil Babka
Quoted 2 lines · Anshuman Khandual

The VMA address bound checks are applicable to all memory policy modes, not just MPOL_INTERLEAVE.

But only MPOL_INTERLEAVE actually uses addr and vma->vm_start.

I thought them to be just general sanity checks.

Quoted 7 lines
Quoted 4 lines

Hence move it to the front and make it common.

I would just remove them instead. Together with the BUG_ON(!vma). Looks like just leftover from development.

sure, resend with suggested changes.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#3 lore raw
Quoted 10 lines · Anshuman Khandual
Quoted 5 lines · Vlastimil Babka
Quoted 2 lines · Anshuman Khandual

The VMA address bound checks are applicable to all memory policy modes, not just MPOL_INTERLEAVE.

But only MPOL_INTERLEAVE actually uses addr and vma->vm_start.

I thought them to be just general sanity checks.

Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

Hence move it to the front and make it common.

I would just remove them instead. Together with the BUG_ON(!vma). Looks like just leftover from development.

sure, resend with suggested changes.

I meant, I will resend the patch with suggested changes.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw

PATCH 1/1 mm/mempolicy: Remove BUG_ON() checks for VMA inside mpol_misplaced()

VMA and its address bounds checks are too late in this function. They must have been verified earlier in the page fault sequence. Hence just remove them.

---
 mm/mempolicy.c | 5 -----
 1 file changed, 5 deletions(-)
mm/mempolicy.c +0 -5
index 618ab12..3509b84 100644
@@ -2172,17 +2172,12 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned long
 	int polnid = -1;
 	int ret = -1;
 
-	BUG_ON(!vma);
-
 	pol = get_vma_policy(vma, addr);
 	if (!(pol->flags & MPOL_F_MOF))
 		goto out;
 
 	switch (pol->mode) {
 	case MPOL_INTERLEAVE:
-		BUG_ON(addr >= vma->vm_end);
-		BUG_ON(addr < vma->vm_start);
-
 		pgoff = vma->vm_pgoff;
 		pgoff += (addr - vma->vm_start) >> PAGE_SHIFT;
 		polnid = offset_il_node(pol, vma, pgoff);
Signature · 7 lines
1.8.5.2

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Acked-by on v1 1/1
#5 lore raw

Re: [PATCH] mm/mempolicy: Remove BUG_ON() checks for VMA inside mpol_misplaced()

Quoted 6 lines · Anshuman Khandual

VMA and its address bounds checks are too late in this function. They must have been verified earlier in the page fault sequence. Hence just remove them.

Quoted 17 lines
---
 mm/mempolicy.c | 5 -----
 1 file changed, 5 deletions(-)
mm/mempolicy.c +0 -2
index 618ab12..3509b84 100644
@@ -2172,17 +2172,12 @@ int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned long
 	int polnid = -1;
 	int ret = -1;
 
-	BUG_ON(!vma);
-
 	pol = get_vma_policy(vma, addr);
 	if (!(pol->flags & MPOL_F_MOF))

mm/mempolicy.c int mpol_misplaced(struct page *page, struct vm_area_struct *vma, unsigned long · line 2183

Quoted 10 lines
mm/mempolicy.c +0 -3
 		goto out;
 
 	switch (pol->mode) {
 	case MPOL_INTERLEAVE:
-		BUG_ON(addr >= vma->vm_end);
-		BUG_ON(addr < vma->vm_start);
-
 		pgoff = vma->vm_pgoff;
 		pgoff += (addr - vma->vm_start) >> PAGE_SHIFT;
 		polnid = offset_il_node(pol, vma, pgoff);

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>