Skip to contentSkip to conversation

could you clarify mm/mempolicy: fix !vma in new_vma_page()

DISCUSSION Michal Hocko 3 participants 16 messages Jan 6, 2014 – Jan 8, 2014

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

Hi Wanpeng Li,
I have just noticed 11c731e81bb0 (mm/mempolicy: fix !vma in new_vma_page()) and I am not sure I understand it. Your changelog claims "
page_address_in_vma() may still return -EFAULT because of many other conditions in it. As a result the while loop in new_vma_page() may end with vma=NULL.
"

And the patch handles hugetlb case only. I was wondering what are those "other conditions" that failed in the BUG_ON mentioned in the changelog? Could you be more specific please?

Thanks!

Signature · 8 lines
Michal Hocko
SUSE Labs

--
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

Hi Michal,

Quoted 9 lines · Michal Hocko

Hi Wanpeng Li,
I have just noticed 11c731e81bb0 (mm/mempolicy: fix !vma in new_vma_page()) and I am not sure I understand it. Your changelog claims "
page_address_in_vma() may still return -EFAULT because of many other conditions in it. As a result the while loop in new_vma_page() may end with vma=NULL.
"

Quoted 4 lines

And the patch handles hugetlb case only. I was wondering what are those "other conditions" that failed in the BUG_ON mentioned in the changelog? Could you be more specific please?

Sorry for the confusion caused.
The code of new_vma_page() used to like this:
1193 while (vma) {
1194 address = page_address_in_vma(page, vma);
1195 if (address != -EFAULT)
1196 break;
1197 vma = vma->vm_next;
1198 }
1199 /*

1200          * queue_pages_range() confirms that @page belongs to some vma,
1201          * so vma shouldn't be NULL.
1202          */

1203 BUG_ON(!vma);
1204
1205 if (PageHuge(page))
1206 return alloc_huge_page_noerr(vma, address, 1);
1207 return alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, address);

The BUG_ON() was triggered and my idea was that even queue_pages_range() confirms @page belongs to some vma, page_address_in_vma() may still return -EFAULT because of below checks in page_address_in_vma().

544 if (PageAnon(page)) {
545 struct anon_vma *page__anon_vma = page_anon_vma(page);
546 /*
547 * Note: swapoff's unuse_vma() is more efficient with this
548 * check, and needs it to match anon_vma when KSM
is active.
549 */
550 if (!vma->anon_vma || !page__anon_vma ||
551 vma->anon_vma->root != page__anon_vma->root)
552 return -EFAULT;
553 } else if (page->mapping && !(vma->vm_flags & VM_NONLINEAR)) {
554 if (!vma->vm_file ||
555 vma->vm_file->f_mapping != page->mapping)
556 return -EFAULT;
557 } else
558 return -EFAULT;

That's the "other conditions" and the reason why we can't use BUG_ON(!vma) in new_vma_page().

Signature · 8 lines
Regards,
--Bob

--
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

On Mon 06-01-14 20:45:54, Bob Liu wrote:
[...]

Quoted 16 lines

544 if (PageAnon(page)) {
545 struct anon_vma *page__anon_vma = page_anon_vma(page);
546 /*

 547                  * Note: swapoff's unuse_vma() is more efficient with this
 548                  * check, and needs it to match anon_vma when KSM is active.
 549                  */

550 if (!vma->anon_vma || !page__anon_vma ||
551 vma->anon_vma->root != page__anon_vma->root)
552 return -EFAULT;
553 } else if (page->mapping && !(vma->vm_flags & VM_NONLINEAR)) {
554 if (!vma->vm_file ||
555 vma->vm_file->f_mapping != page->mapping)
556 return -EFAULT;
557 } else
558 return -EFAULT;

Quoted 2 lines

That's the "other conditions" and the reason why we can't use BUG_ON(!vma) in new_vma_page().

Sorry, I wasn't clear with my question. I was interested in which of these triggered and why only for hugetlb pages?

Signature · 8 lines
Michal Hocko
SUSE Labs

--
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

Hi Michal,

Quoted 18 lines · Michal Hocko

On Mon 06-01-14 20:45:54, Bob Liu wrote:
[...]

Quoted 16 lines

544 if (PageAnon(page)) {
545 struct anon_vma *page__anon_vma = page_anon_vma(page);
546 /*

 547                  * Note: swapoff's unuse_vma() is more efficient with this
 548                  * check, and needs it to match anon_vma when KSM is active.
 549                  */

550 if (!vma->anon_vma || !page__anon_vma ||
551 vma->anon_vma->root != page__anon_vma->root)
552 return -EFAULT;
553 } else if (page->mapping && !(vma->vm_flags & VM_NONLINEAR)) {
554 if (!vma->vm_file ||
555 vma->vm_file->f_mapping != page->mapping)
556 return -EFAULT;
557 } else
558 return -EFAULT;

Quoted 5 lines
Quoted 2 lines

That's the "other conditions" and the reason why we can't use BUG_ON(!vma) in new_vma_page().

Sorry, I wasn't clear with my question. I was interested in which of these triggered and why only for hugetlb pages?

Not just for hugetlb pages, sorry for do two things in one patch. The change for hugetlb pages is to fix the potential dereference NULL pointer reported by Dan. http://marc.info/?l=linux-mm&m=137689530323257&w=2

If we should ask Sasha to add more debug information to dump which condition is failed in page_address_in_vma() for you?

Regards,
Wanpeng Li

Quoted 4 lines
Signature · 3 lines
-- 
Michal Hocko
SUSE Labs

--
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

Cced Sasha,

Quoted 42 lines · Wanpeng Li

Hi Michal,

Quoted 18 lines · Michal Hocko

On Mon 06-01-14 20:45:54, Bob Liu wrote:
[...]

Quoted 16 lines

544 if (PageAnon(page)) {
545 struct anon_vma *page__anon_vma = page_anon_vma(page);
546 /*

 547                  * Note: swapoff's unuse_vma() is more efficient with this
 548                  * check, and needs it to match anon_vma when KSM is active.
 549                  */

550 if (!vma->anon_vma || !page__anon_vma ||
551 vma->anon_vma->root != page__anon_vma->root)
552 return -EFAULT;
553 } else if (page->mapping && !(vma->vm_flags & VM_NONLINEAR)) {
554 if (!vma->vm_file ||
555 vma->vm_file->f_mapping != page->mapping)
556 return -EFAULT;
557 } else
558 return -EFAULT;

Quoted 5 lines
Quoted 2 lines

That's the "other conditions" and the reason why we can't use BUG_ON(!vma) in new_vma_page().

Sorry, I wasn't clear with my question. I was interested in which of these triggered and why only for hugetlb pages?

Not just for hugetlb pages, sorry for do two things in one patch. The change for hugetlb pages is to fix the potential dereference NULL pointer reported by Dan. http://marc.info/?l=linux-mm&m=137689530323257&w=2

If we should ask Sasha to add more debug information to dump which condition is failed in page_address_in_vma() for you?

Regards,
Wanpeng Li

Quoted 4 lines
Signature · 3 lines
-- 
Michal Hocko
SUSE Labs
Quoted 5 lines

--
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>

--
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>

#5 lore raw
Quoted 34 lines · Wanpeng Li

Cced Sasha,

Quoted 32 lines · Wanpeng Li

Hi Michal,

Quoted 18 lines · Michal Hocko

On Mon 06-01-14 20:45:54, Bob Liu wrote:
[...]

Quoted 16 lines

544 if (PageAnon(page)) {
545 struct anon_vma *page__anon_vma = page_anon_vma(page);
546 /*

 547                  * Note: swapoff's unuse_vma() is more efficient with this
 548                  * check, and needs it to match anon_vma when KSM is active.
 549                  */

550 if (!vma->anon_vma || !page__anon_vma ||
551 vma->anon_vma->root != page__anon_vma->root)
552 return -EFAULT;
553 } else if (page->mapping && !(vma->vm_flags & VM_NONLINEAR)) {
554 if (!vma->vm_file ||
555 vma->vm_file->f_mapping != page->mapping)
556 return -EFAULT;
557 } else
558 return -EFAULT;

Quoted 5 lines
Quoted 2 lines

That's the "other conditions" and the reason why we can't use BUG_ON(!vma) in new_vma_page().

Sorry, I wasn't clear with my question. I was interested in which of these triggered and why only for hugetlb pages?

Not just for hugetlb pages, sorry for do two things in one patch. The change for hugetlb pages is to fix the potential dereference NULL pointer reported by Dan. http://marc.info/?l=linux-mm&m=137689530323257&w=2

If we should ask Sasha to add more debug information to dump which condition is failed in page_address_in_vma() for you?

I am always more calm when the removed BUG_ON is properly understood and justified.

Signature · 8 lines
Michal Hocko
SUSE Labs

--
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>
#6 lore raw
In reply to Michal Hocko
Quoted 18 lines · Michal Hocko

On Mon 06-01-14 20:45:54, Bob Liu wrote:
[...]

Quoted 16 lines

544 if (PageAnon(page)) {
545 struct anon_vma *page__anon_vma = page_anon_vma(page);
546 /*

 547                  * Note: swapoff's unuse_vma() is more efficient with this
 548                  * check, and needs it to match anon_vma when KSM is active.
 549                  */

550 if (!vma->anon_vma || !page__anon_vma ||
551 vma->anon_vma->root != page__anon_vma->root)
552 return -EFAULT;
553 } else if (page->mapping && !(vma->vm_flags & VM_NONLINEAR)) {
554 if (!vma->vm_file ||
555 vma->vm_file->f_mapping != page->mapping)
556 return -EFAULT;
557 } else
558 return -EFAULT;

Quoted 6 lines
Quoted 2 lines

That's the "other conditions" and the reason why we can't use BUG_ON(!vma) in new_vma_page().

Sorry, I wasn't clear with my question. I was interested in which of these triggered and why only for hugetlb pages?

Sorry I didn't analyse the root cause. They are several checks in page_address_in_vma() so I think it might be not difficult to hit one of them. For example, if the page was mapped to vma by nonlinear mapping?
Anyway, some debug code is needed to verify what really happened here.

alloc_page_vma() can handle the vma=NULL case while alloc_huge_page_noerr() can't, so we return NULL instead of call down to alloc_huge_page().

Signature · 8 lines
Regards,
--Bob

--
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>
#7 lore raw
Quoted 22 lines · Bob Liu
Quoted 21 lines · Michal Hocko

On Mon 06-01-14 20:45:54, Bob Liu wrote:
[...]

Quoted 18 lines

544 if (PageAnon(page)) {
545 struct anon_vma *page__anon_vma = page_anon_vma(page);
546 /*

 547                  * Note: swapoff's unuse_vma() is more efficient with this
 548                  * check, and needs it to match anon_vma when KSM is active.
 549                  */

550 if (!vma->anon_vma || !page__anon_vma ||
551 vma->anon_vma->root != page__anon_vma->root)
552 return -EFAULT;
553 } else if (page->mapping && !(vma->vm_flags & VM_NONLINEAR)) {
554 if (!vma->vm_file ||
555 vma->vm_file->f_mapping != page->mapping)
556 return -EFAULT;
557 } else
558 return -EFAULT;

That's the "other conditions" and the reason why we can't use BUG_ON(!vma) in new_vma_page().

Quoted 7 lines
Quoted 3 lines

Sorry, I wasn't clear with my question. I was interested in which of these triggered and why only for hugetlb pages?

Sorry I didn't analyse the root cause. They are several checks in page_address_in_vma() so I think it might be not difficult to hit one of them.

I would be really curious when anon_vma or f_mapping would be out of sync, that's why I've asked in the first place.

Quoted 2 lines

For example, if the page was mapped to vma by nonlinear mapping?

Hmm, ok !private shmem/hugetlbfs might be remapped as non-linear. For some reason I thought that migration for non-linear mappings is not allowed. This is not the case and it would explain why the BUG_ON triggered.

Quoted 1 line

Anyway, some debug code is needed to verify what really happened here.

That would be prefferable before the patch had been submitted and merged...

Quoted 3 lines

alloc_page_vma() can handle the vma=NULL case while alloc_huge_page_noerr() can't, so we return NULL instead of call down to alloc_huge_page().

OK, I see.

Thanks!

Signature · 8 lines
Michal Hocko
SUSE Labs

--
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>
#8 lore raw
Quoted 31 lines · Michal Hocko
Quoted 22 lines · Bob Liu
Quoted 21 lines · Michal Hocko

On Mon 06-01-14 20:45:54, Bob Liu wrote:
[...]

Quoted 18 lines

544 if (PageAnon(page)) {
545 struct anon_vma *page__anon_vma = page_anon_vma(page);
546 /*

 547                  * Note: swapoff's unuse_vma() is more efficient with this
 548                  * check, and needs it to match anon_vma when KSM is active.
 549                  */

550 if (!vma->anon_vma || !page__anon_vma ||
551 vma->anon_vma->root != page__anon_vma->root)
552 return -EFAULT;
553 } else if (page->mapping && !(vma->vm_flags & VM_NONLINEAR)) {
554 if (!vma->vm_file ||
555 vma->vm_file->f_mapping != page->mapping)
556 return -EFAULT;
557 } else
558 return -EFAULT;

That's the "other conditions" and the reason why we can't use BUG_ON(!vma) in new_vma_page().

Quoted 7 lines
Quoted 3 lines

Sorry, I wasn't clear with my question. I was interested in which of these triggered and why only for hugetlb pages?

Sorry I didn't analyse the root cause. They are several checks in page_address_in_vma() so I think it might be not difficult to hit one of them.

Quoted 7 lines

I would be really curious when anon_vma or f_mapping would be out of sync, that's why I've asked in the first place.

Quoted 2 lines

For example, if the page was mapped to vma by nonlinear mapping?

Hmm, ok !private shmem/hugetlbfs might be remapped as non-linear.

OK, it didn't let go away from my head so I had to check. hugetlbfs cannot be remmaped as non-linear because it is missing its vm_ops is missing remap_pages implementation. So this case is impossible for these pages. So at least the PageHuge part of the patch is bogus AFAICS.

We still have shmem and even then I am curious whether we are doing the right thing. The loop is inteded to handle range spanning multiple VMAs (as per 3ad33b2436b54 (Migration: find correct vma in new_vma_page())) and it doesn't seem to be VM_NONLINEAR aware. It will always fail for shared shmem and so we always fallback to task/system default mempolicy. Whether somebody uses mempolicy on VM_NONLINEAR mappings is hard to tell. I am not familiar with this feature much.

That being said. The BUG_ON(!vma) was bogus for VM_NONLINEAR cases. The changed code could keep it for hugetlbfs path because we shouldn't see NULL vma there AFAICS.

What is the right(tm) thing to do for VM_NONLINEAR is hard to tell and I would leave it to those who are more familiar with the usage.

Signature · 8 lines
Michal Hocko
SUSE Labs

--
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>
#9 lore raw
Quoted 53 lines · Michal Hocko
Quoted 31 lines · Michal Hocko
Quoted 22 lines · Bob Liu
Quoted 21 lines · Michal Hocko

On Mon 06-01-14 20:45:54, Bob Liu wrote:
[...]

Quoted 18 lines

544 if (PageAnon(page)) {
545 struct anon_vma *page__anon_vma = page_anon_vma(page);
546 /*

 547                  * Note: swapoff's unuse_vma() is more efficient with this
 548                  * check, and needs it to match anon_vma when KSM is active.
 549                  */

550 if (!vma->anon_vma || !page__anon_vma ||
551 vma->anon_vma->root != page__anon_vma->root)
552 return -EFAULT;
553 } else if (page->mapping && !(vma->vm_flags & VM_NONLINEAR)) {
554 if (!vma->vm_file ||
555 vma->vm_file->f_mapping != page->mapping)
556 return -EFAULT;
557 } else
558 return -EFAULT;

That's the "other conditions" and the reason why we can't use BUG_ON(!vma) in new_vma_page().

Quoted 7 lines
Quoted 3 lines

Sorry, I wasn't clear with my question. I was interested in which of these triggered and why only for hugetlb pages?

Sorry I didn't analyse the root cause. They are several checks in page_address_in_vma() so I think it might be not difficult to hit one of them.

Quoted 7 lines

I would be really curious when anon_vma or f_mapping would be out of sync, that's why I've asked in the first place.

Quoted 2 lines

For example, if the page was mapped to vma by nonlinear mapping?

Hmm, ok !private shmem/hugetlbfs might be remapped as non-linear.

OK, it didn't let go away from my head so I had to check. hugetlbfs cannot be remmaped as non-linear because it is missing its vm_ops is missing remap_pages implementation. So this case is impossible for these pages. So at least the PageHuge part of the patch is bogus AFAICS.

We still have shmem and even then I am curious whether we are doing the right thing. The loop is inteded to handle range spanning multiple VMAs (as per 3ad33b2436b54 (Migration: find correct vma in new_vma_page())) and it doesn't seem to be VM_NONLINEAR aware. It will always fail for shared shmem and so we always fallback to task/system default mempolicy. Whether somebody uses mempolicy on VM_NONLINEAR mappings is hard to tell. I am not familiar with this feature much.

Quoted 4 lines

That being said. The BUG_ON(!vma) was bogus for VM_NONLINEAR cases. The changed code could keep it for hugetlbfs path because we shouldn't see NULL vma there AFAICS.

Sounds reasonable, but as your said we'd better find out the root cause before making any changes.
Do you think below debug info is enough? If yes, then we can ask Sasha help us having a test.

mm/mempolicy.c +0 -0
index 12733f5..86c5cc0 100644
@@ -1189,11 +1189,21 @@ static struct page *new_vma_page(struct page

*page, unsigned long private, int *

 {
        struct vm_area_struct *vma = (struct vm_area_struct *)private;
        unsigned long uninitialized_var(address);
mm/mempolicy.c +0 -0
index 12733f5..86c5cc0 100644
@@ -1189,11 +1189,21 @@ static struct page *new_vma_page(struct page

*page, unsigned long private, int *

 {
        struct vm_area_struct *vma = (struct vm_area_struct *)private;
        unsigned long uninitialized_var(address);

+ unsigned long uninitialized_var(address2);

        while (vma) {
                address = page_address_in_vma(page, vma);
                if (address != -EFAULT)
                        break;

+#if 1
+ address2 = vma_address(page, vma);
+ if (address2 >= vma->vm_start && address2 < vma->vm_end) {
+ printk("other condition happened\n");
+ if (vma->vm_flags & VM_NONLINEAR)
+ printk("non linear map\n");
+ dump_page(page);
+ }
+#endif

                vma = vma->vm_next;
        }
        /*
mm/rmap.c +1 -1
index d792e71..4d35d5c 100644
@@ -529,7 +529,7 @@ vma_address(struct page *page, struct vm_area_struct *vma)
        unsigned long address = __vma_address(page, vma);
 
        /* page should be within @vma mapping range */
-       VM_BUG_ON(address < vma->vm_start || address >= vma->vm_end);
+       //VM_BUG_ON(address < vma->vm_start || address >= vma->vm_end);
 
        return address;
 }
Signature · 8 lines
Regards,
--Bob

--
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>
#10 lore raw
Quoted 59 lines · Bob Liu
Quoted 53 lines · Michal Hocko
Quoted 31 lines · Michal Hocko
Quoted 22 lines · Bob Liu
Quoted 21 lines · Michal Hocko

On Mon 06-01-14 20:45:54, Bob Liu wrote:
[...]

Quoted 18 lines

544 if (PageAnon(page)) {
545 struct anon_vma *page__anon_vma = page_anon_vma(page);
546 /*

 547                  * Note: swapoff's unuse_vma() is more efficient with this
 548                  * check, and needs it to match anon_vma when KSM is active.
 549                  */

550 if (!vma->anon_vma || !page__anon_vma ||
551 vma->anon_vma->root != page__anon_vma->root)
552 return -EFAULT;
553 } else if (page->mapping && !(vma->vm_flags & VM_NONLINEAR)) {
554 if (!vma->vm_file ||
555 vma->vm_file->f_mapping != page->mapping)
556 return -EFAULT;
557 } else
558 return -EFAULT;

That's the "other conditions" and the reason why we can't use BUG_ON(!vma) in new_vma_page().

Quoted 7 lines
Quoted 3 lines

Sorry, I wasn't clear with my question. I was interested in which of these triggered and why only for hugetlb pages?

Sorry I didn't analyse the root cause. They are several checks in page_address_in_vma() so I think it might be not difficult to hit one of them.

Quoted 7 lines

I would be really curious when anon_vma or f_mapping would be out of sync, that's why I've asked in the first place.

Quoted 2 lines

For example, if the page was mapped to vma by nonlinear mapping?

Hmm, ok !private shmem/hugetlbfs might be remapped as non-linear.

OK, it didn't let go away from my head so I had to check. hugetlbfs cannot be remmaped as non-linear because it is missing its vm_ops is missing remap_pages implementation. So this case is impossible for these pages. So at least the PageHuge part of the patch is bogus AFAICS.

We still have shmem and even then I am curious whether we are doing the right thing. The loop is inteded to handle range spanning multiple VMAs (as per 3ad33b2436b54 (Migration: find correct vma in new_vma_page())) and it doesn't seem to be VM_NONLINEAR aware. It will always fail for shared shmem and so we always fallback to task/system default mempolicy. Whether somebody uses mempolicy on VM_NONLINEAR mappings is hard to tell. I am not familiar with this feature much.

Quoted 4 lines

That being said. The BUG_ON(!vma) was bogus for VM_NONLINEAR cases. The changed code could keep it for hugetlbfs path because we shouldn't see NULL vma there AFAICS.

Quoted 4 lines

Sounds reasonable, but as your said we'd better find out the root cause before making any changes.
Do you think below debug info is enough? If yes, then we can ask Sasha help us having a test.

If I was debugging this I would simply add printk into page_address_in_vma error paths.

Anyway, I think that at least hugetlbfs part should be reverted because it might paper over real bugs. Although the migration would fail for such hugetlb page we should catch that a weird page was tried to be migrated. What about the patch below?
---

#11 lore raw
Quoted 8 lines · Michal Hocko

If I was debugging this I would simply add printk into page_address_in_vma error paths.

Anyway, I think that at least hugetlbfs part should be reverted because it might paper over real bugs. Although the migration would fail for such hugetlb page we should catch that a weird page was tried to be migrated. What about the patch below?

Looks good to me. But we need to confirm whether our assumption is right. Sasha, could you please have a test with Michal's patch?

Thanks,
-Bob

Quoted 44 lines

---
From 2d61421f26a3b63b4670d71b7adc67e2191b6157 Mon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Wed, 8 Jan 2014 10:57:41 +0100
Subject: [PATCH] mm: new_vma_page cannot see NULL vma for hugetlb pages

11c731e81bb0 (mm/mempolicy: fix !vma in new_vma_page()) has removed BUG_ON(!vma) from new_vma_page which is partially correct because page_address_in_vma will return EFAULT for non-linear mappings and at least shared shmem might be mapped this way.

The patch also tried to prevent NULL ptr for hugetlb pages which is not correct AFAICS because hugetlb pages cannot be mapped as VM_NONLINEAR and other conditions in page_address_in_vma seem to be legit and catch real bugs.

This patch restores BUG_ON for PageHuge to catch potential issues when the to-be-migrated page is not setup properly.

---
 mm/mempolicy.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/mempolicy.c +2 -5
index 9e8d2d86978a..f3f51464a23b 100644
@@ -1199,10 +1199,8 @@ static struct page *new_vma_page(struct page *page, unsigned long private, int *
        }
 
        if (PageHuge(page)) {
-               if (vma)
-                       return alloc_huge_page_noerr(vma, address, 1);
-               else
-                       return NULL;
+               BUG_ON(vma)
+               return alloc_huge_page_noerr(vma, address, 1);
        }
        /*
         * if !vma, alloc_page_vma() will use task or system default policy
--

1.8.5.2

Quoted 3 lines

--
Michal Hocko
SUSE Labs

--
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>

#12 lore raw
Quoted 6 lines · Bob Liu
Quoted 4 lines · Michal Hocko

If I was debugging this I would simply add printk into page_address_in_vma error paths.

Quoted 6 lines
Quoted 4 lines

Anyway, I think that at least hugetlbfs part should be reverted because it might paper over real bugs. Although the migration would fail for such hugetlb page we should catch that a weird page was tried to be migrated. What about the patch below?

Looks good to me. But we need to confirm whether our assumption is right.

Which assumption you have in mind? non-linear mapping or failing on anon_vma or f_mapping checks?

Quoted 1 line

Sasha, could you please have a test with Michal's patch?

I obviously doesn't have anything against testing but we should really focus on the original issue. This patch simply restores hugetlb code path.

Quoted 50 lines

Thanks,
-Bob

Quoted 47 lines

---
From 2d61421f26a3b63b4670d71b7adc67e2191b6157 Mon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Wed, 8 Jan 2014 10:57:41 +0100
Subject: [PATCH] mm: new_vma_page cannot see NULL vma for hugetlb pages

11c731e81bb0 (mm/mempolicy: fix !vma in new_vma_page()) has removed BUG_ON(!vma) from new_vma_page which is partially correct because page_address_in_vma will return EFAULT for non-linear mappings and at least shared shmem might be mapped this way.

The patch also tried to prevent NULL ptr for hugetlb pages which is not correct AFAICS because hugetlb pages cannot be mapped as VM_NONLINEAR and other conditions in page_address_in_vma seem to be legit and catch real bugs.

This patch restores BUG_ON for PageHuge to catch potential issues when the to-be-migrated page is not setup properly.

---
 mm/mempolicy.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/mempolicy.c +2 -5
index 9e8d2d86978a..f3f51464a23b 100644
@@ -1199,10 +1199,8 @@ static struct page *new_vma_page(struct page *page, unsigned long private, int *
        }
 
        if (PageHuge(page)) {
-               if (vma)
-                       return alloc_huge_page_noerr(vma, address, 1);
-               else
-                       return NULL;
+               BUG_ON(vma)
+               return alloc_huge_page_noerr(vma, address, 1);
        }
        /*
         * if !vma, alloc_page_vma() will use task or system default policy
--

1.8.5.2

--
Michal Hocko
SUSE Labs

Signature · 8 lines
Michal Hocko
SUSE Labs

--
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>
Reviewed-by
#13 lore raw
Quoted 12 lines · Michal Hocko
Quoted 11 lines · Bob Liu
Quoted 8 lines · Michal Hocko

If I was debugging this I would simply add printk into page_address_in_vma error paths.

Anyway, I think that at least hugetlbfs part should be reverted because it might paper over real bugs. Although the migration would fail for such hugetlb page we should catch that a weird page was tried to be migrated. What about the patch below?

Quoted 5 lines
Quoted 1 line

Looks good to me. But we need to confirm whether our assumption is right.

Which assumption you have in mind? non-linear mapping or failing on anon_vma or f_mapping checks?

The assumption that the original BUG_ON(!vma) was triggered by non-linear mapping.

Quoted 4 lines
Quoted 1 line

Sasha, could you please have a test with Michal's patch?

I obviously doesn't have anything against testing but we should really focus on the original issue. This patch simply restores hugetlb code

Oh, I see your point.
Yes, I agree that your patch should be merged and if the BUG_ON() is triggered(which is unlikely) again.
We can open another thread and analysis the root cause.

Quoted 16 lines
Quoted 16 lines
Quoted 16 lines

---
From 2d61421f26a3b63b4670d71b7adc67e2191b6157 Mon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Wed, 8 Jan 2014 10:57:41 +0100
Subject: [PATCH] mm: new_vma_page cannot see NULL vma for hugetlb pages

11c731e81bb0 (mm/mempolicy: fix !vma in new_vma_page()) has removed BUG_ON(!vma) from new_vma_page which is partially correct because page_address_in_vma will return EFAULT for non-linear mappings and at least shared shmem might be mapped this way.

The patch also tried to prevent NULL ptr for hugetlb pages which is not correct AFAICS because hugetlb pages cannot be mapped as VM_NONLINEAR and other conditions in page_address_in_vma seem to be legit and catch real bugs.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

This patch restores BUG_ON for PageHuge to catch potential issues when the to-be-migrated page is not setup properly.

Quoted 24 lines
Quoted 24 lines
Quoted 24 lines
---
 mm/mempolicy.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/mempolicy.c +2 -5
index 9e8d2d86978a..f3f51464a23b 100644
@@ -1199,10 +1199,8 @@ static struct page *new_vma_page(struct page *page, unsigned long private, int *
        }
 
        if (PageHuge(page)) {
-               if (vma)
-                       return alloc_huge_page_noerr(vma, address, 1);
-               else
-                       return NULL;
+               BUG_ON(vma)
+               return alloc_huge_page_noerr(vma, address, 1);
        }
        /*
         * if !vma, alloc_page_vma() will use task or system default policy
--

1.8.5.2

Signature · 8 lines
Regards,
--Bob

--
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>
#14 lore raw

On Wed 08-01-14 21:10:29, Bob Liu wrote:
[...]

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

From 2d61421f26a3b63b4670d71b7adc67e2191b6157 Mon Sep 17 00:00:00 2001
From: Michal Hocko <[email protected]>
Date: Wed, 8 Jan 2014 10:57:41 +0100
Subject: [PATCH] mm: new_vma_page cannot see NULL vma for hugetlb pages

11c731e81bb0 (mm/mempolicy: fix !vma in new_vma_page()) has removed BUG_ON(!vma) from new_vma_page which is partially correct because page_address_in_vma will return EFAULT for non-linear mappings and at least shared shmem might be mapped this way.

The patch also tried to prevent NULL ptr for hugetlb pages which is not correct AFAICS because hugetlb pages cannot be mapped as VM_NONLINEAR and other conditions in page_address_in_vma seem to be legit and catch real bugs.

Quoted 6 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines

This patch restores BUG_ON for PageHuge to catch potential issues when the to-be-migrated page is not setup properly.

Thanks!

Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
Quoted 11 lines
---
 mm/mempolicy.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
mm/mempolicy.c +0 -0
index 9e8d2d86978a..f3f51464a23b 100644
@@ -1199,10 +1199,8 @@ static struct page *new_vma_page(struct page *page, unsigned long private, int *
        }
 
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

mm/mempolicy.c static struct page *new_vma_page(struct page *page, unsigned long private, int * · line 1202

Quoted 6 lines
mm/mempolicy.c +1 -4
        if (PageHuge(page)) {
-               if (vma)
-                       return alloc_huge_page_noerr(vma, address, 1);
-               else
-                       return NULL;
+               BUG_ON(vma)

That was meant to say BUG_ON(!vma) of course ;) but I guess your reviewed-by still applies so I will post it to Andrew.

Quoted 11 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
mm/mempolicy.c +1 -1
+               return alloc_huge_page_noerr(vma, address, 1);
        }
        /*
         * if !vma, alloc_page_vma() will use task or system default policy
--

1.8.5.2

Signature · 2 lines
Regards,
--Bob
Signature · 8 lines
Michal Hocko
SUSE Labs

--
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>
author Reviewed-by Bob Liu
#15 lore raw
In reply to Bob Liu

Hi Andrew,
the whole thread started here: http://lkml.org/lkml/2014/1/6/217
I guess it makes sense to revert part of the already merged commit with the following patch. If the BUG_ON triggers again then we should rather find out why page_address_in_vma fails on anon_vma or f_mapping checks and not simply paper over it.
---