mm: include VM_MIXEDMAP flag in the VM_SPECIAL list to avoid m(un)locking
A message that is not in the archive (sent off-list or not yet received): [email protected]
Hannes Frederic Sowa
Tested-byQuoted 73 lines · Daniel Borkmann
From: Vlastimil Babka <[email protected]>
[ 4366.519657] ------------[ cut here ]------------ [ 4366.519709] kernel BUG at mm/mlock.c:528! [ 4366.519742] invalid opcode: 0000 [#1] SMP [ 4366.519782] Modules linked in: ccm arc4 iwldvm [...] [ 4366.520488] video [ 4366.520501] CPU: 3 PID: 2266 Comm: netsniff-ng Not tainted 3.14.0-rc2+ #8 [ 4366.520551] Hardware name: LENOVO 2429BP3/2429BP3, BIOS G4ET37WW (1.12 ) 05/29/2012 [ 4366.520608] task: ffff8801f87f9820 ti: ffff88002cb44000 task.ti: ffff88002cb44000 [ 4366.520662] RIP: 0010:[<ffffffff81171ad0>] [<ffffffff81171ad0>] munlock_vma_pages_range+0x2e0/0x2f0 [ 4366.520738] RSP: 0018:ffff88002cb45e00 EFLAGS: 00010206 [ 4366.520777] RAX: 00000000000001ff RBX: ffff8801f5e75d10 RCX: 000000000000107d [ 4366.520829] RDX: 00000007f133345f RSI: ffffea0007d76000 RDI: ffffea0007d76000 [ 4366.520881] RBP: ffff88002cb45ed8 R08: 0000000000000000 R09: a8001f5d80000000 [ 4366.520932] R10: 57ffcaa287d76000 R11: 0000000000000246 R12: ffffea0007d76000 [ 4366.520983] R13: 00007f133745f000 R14: 00007f133345f000 R15: ffff8801f5e75a50 [ 4366.521036] FS: 00007f133745f740(0000) GS:ffff88021e2c0000(0000) knlGS:0000000000000000 [ 4366.521094] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 4366.521137] CR2: 000000000062ead0 CR3: 00000000c688d000 CR4: 00000000001407e0 [ 4366.521188] Stack: [ 4366.521205] ffffffff8116b085 00007f133745efff 00007f133327d000 00007f133745f000 [ 4366.521269] 000001ff81172793 ffff8800c6baa6e0 0000000000000000 0000000000000000 [ 4366.521333] 00007f1333336000 ffffea0004a7ab40 ffff88002cb45e58 0000000000000000 [ 4366.521397] Call Trace: [ 4366.521422] [<ffffffff8116b085>] ? tlb_finish_mmu+0x35/0x60 [ 4366.521468] [<ffffffff8117486f>] do_munmap+0x18f/0x3b0 [ 4366.521511] [<ffffffff8163e84b>] ? packet_getsockopt+0xfb/0x310 [ 4366.521558] [<ffffffff81174ad1>] vm_munmap+0x41/0x60 [ 4366.521598] [<ffffffff811759b2>] SyS_munmap+0x22/0x30 [ 4366.521639] [<ffffffff81666616>] system_call_fastpath+0x1a/0x1f [ 4366.521683] Code: ff ff e8 c4 07 fe ff 84 c0 48 8b 95 28 ff ff ff 0f 85 52 ff ff ff e9 3e ff ff ff 48 89 d7 e8 bf 32 4e 00 4c 89 e7 e8 aa 32 4e 00 <0f> 0b 66 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 [ 4366.522004] RIP [<ffffffff81171ad0>] munlock_vma_pages_range+0x2e0/0x2f0 [ 4366.522059] RSP <ffff88002cb45e00> [ 4366.539269] ---[ end trace a0088dcf07ae10f2 ]---Daniel Borkmann reported a bug (stack trace above) with
VM_BUG_ONassertions failing wheremunlock_vma_pages_range()thinks it's unexpectedly in the middle of a THP page. This can be reproduced with default config since 3.11 kernels. A reproducer can be found in the kernel's selftest directory for networking by running ./psock_tpacket.The problem is that an order=2 compound page (allocated by
alloc_one_pg_vec_page()is part of the munlockedVM_MIXEDMAPvma (mapped bypacket_mmap()) and mistaken for a THP page and assumed to be order=9.The checks for THP in munlock came with commit
ff6a6da60b89("mm:
acceleratemunlock()treatment of THP pages"), i.e. since 3.9, but did not trigger a bug. It just makesmunlock_vma_pages_range()skip such compound pages until the next 512-pages-aligned page, when it encounters a head page. This is however not a problem for vma's where mlocking has no effect anyway, but it can distort the accounting.Since commit
7225522bb("mm: munlock: batch non-THP page isolation and munlock+putback using pagevec") this can trigger aVM_BUG_ONinPageTransHuge()check.This patch fixes the issue by adding
VM_MIXEDMAPflag toVM_SPECIAL, a list of flags that make vma's non-mlockable and non-mergeable. The reasoning is thatVM_MIXEDMAPvma's are similar toVM_PFNMAP, which is already on theVM_SPECIALlist, and both are intended for non-LRU pages where mlocking makes no sense anyway. Related Lkml discussion can be found in [2].[1]
tools/testing/selftests/net/psock_tpacket
[2] https://lkml.org/lkml/2014/1/10/427
Quoted 13 lines
Signed-off-by Vlastimil Babka <[email protected]>Reported-by Daniel Borkmann <[email protected]>Tested-by Daniel Borkmann <[email protected]>Cc Thomas Hellstrom <[email protected]>Cc John David Anglin <[email protected]>Cc HATAYAMA Daisuke <[email protected]>Cc Konstantin Khlebnikov <[email protected]>Cc Carsten Otte <[email protected]>Cc Jared Hulbert <[email protected]>Cc Hannes Frederic Sowa <[email protected]>Cc Kirill A. Shutemov <[email protected]>Cc Rik van Riel <[email protected]>Cc <[email protected]> [3.11.x+]
Thanks Daniel!
Rik van Riel
Acked-byQuoted 12 lines · Daniel Borkmann
From: Vlastimil Babka <[email protected]>
This patch fixes the issue by adding
VM_MIXEDMAPflag toVM_SPECIAL, a list of flags that make vma's non-mlockable and non-mergeable. The reasoning is thatVM_MIXEDMAPvma's are similar toVM_PFNMAP, which is already on theVM_SPECIALlist, and both are intended for non-LRU pages where mlocking makes no sense anyway. Related Lkml discussion can be found in [2].[1]
tools/testing/selftests/net/psock_tpacket
[2] https://lkml.org/lkml/2014/1/10/427
Quoted 13 lines
Signed-off-by Vlastimil Babka <[email protected]>Reported-by Daniel Borkmann <[email protected]>Tested-by Daniel Borkmann <[email protected]>Cc Thomas Hellstrom <[email protected]>Cc John David Anglin <[email protected]>Cc HATAYAMA Daisuke <[email protected]>Cc Konstantin Khlebnikov <[email protected]>Cc Carsten Otte <[email protected]>Cc Jared Hulbert <[email protected]>Cc Hannes Frederic Sowa <[email protected]>Cc Kirill A. Shutemov <[email protected]>Cc Rik van Riel <[email protected]>Cc <[email protected]> [3.11.x+]
Signature · 1 line
All rights reversed
Quoted 31 lines · On Sun, 16 Feb 2014 15:59:45 +0100 Daniel Borkmann <[email protected]> wrote:
Daniel Borkmann reported a bug (stack trace above) with
VM_BUG_ONassertions failing wheremunlock_vma_pages_range()thinks it's unexpectedly in the middle of a THP page. This can be reproduced with default config since 3.11 kernels. A reproducer can be found in the kernel's selftest directory for networking by running ./psock_tpacket.The problem is that an order=2 compound page (allocated by
alloc_one_pg_vec_page()is part of the munlockedVM_MIXEDMAPvma (mapped bypacket_mmap()) and mistaken for a THP page and assumed to be order=9.The checks for THP in munlock came with commit
ff6a6da60b89("mm:
acceleratemunlock()treatment of THP pages"), i.e. since 3.9, but did not trigger a bug. It just makesmunlock_vma_pages_range()skip such compound pages until the next 512-pages-aligned page, when it encounters a head page. This is however not a problem for vma's where mlocking has no effect anyway, but it can distort the accounting.Since commit
7225522bb("mm: munlock: batch non-THP page isolation and munlock+putback using pagevec") this can trigger aVM_BUG_ONinPageTransHuge()check.This patch fixes the issue by adding
VM_MIXEDMAPflag toVM_SPECIAL, a list of flags that make vma's non-mlockable and non-mergeable. The reasoning is thatVM_MIXEDMAPvma's are similar toVM_PFNMAP, which is already on theVM_SPECIALlist, and both are intended for non-LRU pages where mlocking makes no sense anyway. Related Lkml discussion can be found in [2].
Quoted 3 lines
Signed-off-by Vlastimil Babka <[email protected]>Reported-by Daniel Borkmann <[email protected]>Tested-by Daniel Borkmann <[email protected]>
I'll add your signed-of-by: here. As perDocumentation/SubmittingPatches 12) (c) ;)
Quoted 2 lines
Took the liberty to resubmit it, as people hit that on distribution kernels; tested and it looks to fix the issue.
hm, I wonder why I missed this.
Quoted 86 lines · Daniel Borkmann
From: Vlastimil Babka <[email protected]>
[ 4366.519657] ------------[ cut here ]------------ [ 4366.519709] kernel BUG at mm/mlock.c:528! [ 4366.519742] invalid opcode: 0000 [#1] SMP [ 4366.519782] Modules linked in: ccm arc4 iwldvm [...] [ 4366.520488] video [ 4366.520501] CPU: 3 PID: 2266 Comm: netsniff-ng Not tainted 3.14.0-rc2+ #8 [ 4366.520551] Hardware name: LENOVO 2429BP3/2429BP3, BIOS G4ET37WW (1.12 ) 05/29/2012 [ 4366.520608] task: ffff8801f87f9820 ti: ffff88002cb44000 task.ti: ffff88002cb44000 [ 4366.520662] RIP: 0010:[<ffffffff81171ad0>] [<ffffffff81171ad0>] munlock_vma_pages_range+0x2e0/0x2f0 [ 4366.520738] RSP: 0018:ffff88002cb45e00 EFLAGS: 00010206 [ 4366.520777] RAX: 00000000000001ff RBX: ffff8801f5e75d10 RCX: 000000000000107d [ 4366.520829] RDX: 00000007f133345f RSI: ffffea0007d76000 RDI: ffffea0007d76000 [ 4366.520881] RBP: ffff88002cb45ed8 R08: 0000000000000000 R09: a8001f5d80000000 [ 4366.520932] R10: 57ffcaa287d76000 R11: 0000000000000246 R12: ffffea0007d76000 [ 4366.520983] R13: 00007f133745f000 R14: 00007f133345f000 R15: ffff8801f5e75a50 [ 4366.521036] FS: 00007f133745f740(0000) GS:ffff88021e2c0000(0000) knlGS:0000000000000000 [ 4366.521094] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 4366.521137] CR2: 000000000062ead0 CR3: 00000000c688d000 CR4: 00000000001407e0 [ 4366.521188] Stack: [ 4366.521205] ffffffff8116b085 00007f133745efff 00007f133327d000 00007f133745f000 [ 4366.521269] 000001ff81172793 ffff8800c6baa6e0 0000000000000000 0000000000000000 [ 4366.521333] 00007f1333336000 ffffea0004a7ab40 ffff88002cb45e58 0000000000000000 [ 4366.521397] Call Trace: [ 4366.521422] [<ffffffff8116b085>] ? tlb_finish_mmu+0x35/0x60 [ 4366.521468] [<ffffffff8117486f>] do_munmap+0x18f/0x3b0 [ 4366.521511] [<ffffffff8163e84b>] ? packet_getsockopt+0xfb/0x310 [ 4366.521558] [<ffffffff81174ad1>] vm_munmap+0x41/0x60 [ 4366.521598] [<ffffffff811759b2>] SyS_munmap+0x22/0x30 [ 4366.521639] [<ffffffff81666616>] system_call_fastpath+0x1a/0x1f [ 4366.521683] Code: ff ff e8 c4 07 fe ff 84 c0 48 8b 95 28 ff ff ff 0f 85 52 ff ff ff e9 3e ff ff ff 48 89 d7 e8 bf 32 4e 00 4c 89 e7 e8 aa 32 4e 00 <0f> 0b 66 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 44 00 00 [ 4366.522004] RIP [<ffffffff81171ad0>] munlock_vma_pages_range+0x2e0/0x2f0 [ 4366.522059] RSP <ffff88002cb45e00> [ 4366.539269] ---[ end trace a0088dcf07ae10f2 ]---Daniel Borkmann reported a bug (stack trace above) with
VM_BUG_ONassertions failing wheremunlock_vma_pages_range()thinks it's unexpectedly in the middle of a THP page. This can be reproduced with default config since 3.11 kernels. A reproducer can be found in the kernel's selftest directory for networking by running ./psock_tpacket.The problem is that an order=2 compound page (allocated by
alloc_one_pg_vec_page()is part of the munlockedVM_MIXEDMAPvma (mapped bypacket_mmap()) and mistaken for a THP page and assumed to be order=9.The checks for THP in munlock came with commit
ff6a6da60b89("mm:
acceleratemunlock()treatment of THP pages"), i.e. since 3.9, but did not trigger a bug. It just makesmunlock_vma_pages_range()skip such compound pages until the next 512-pages-aligned page, when it encounters a head page. This is however not a problem for vma's where mlocking has no effect anyway, but it can distort the accounting.Since commit
7225522bb("mm: munlock: batch non-THP page isolation and munlock+putback using pagevec") this can trigger aVM_BUG_ONinPageTransHuge()check.This patch fixes the issue by adding
VM_MIXEDMAPflag toVM_SPECIAL, a list of flags that make vma's non-mlockable and non-mergeable. The reasoning is thatVM_MIXEDMAPvma's are similar toVM_PFNMAP, which is already on theVM_SPECIALlist, and both are intended for non-LRU pages where mlocking makes no sense anyway. Related Lkml discussion can be found in [2].[1]
tools/testing/selftests/net/psock_tpacket
[2] https://lkml.org/lkml/2014/1/10/427Signed-off-by Vlastimil Babka <[email protected]>Reported-by Daniel Borkmann <[email protected]>Tested-by Daniel Borkmann <[email protected]>Cc Thomas Hellstrom <[email protected]>Cc John David Anglin <[email protected]>Cc HATAYAMA Daisuke <[email protected]>Cc Konstantin Khlebnikov <[email protected]>Cc Carsten Otte <[email protected]>Cc Jared Hulbert <[email protected]>Cc Hannes Frederic Sowa <[email protected]>Cc Kirill A. Shutemov <[email protected]>Cc Rik van Riel <[email protected]>Cc <[email protected]> [3.11.x+]
Quoted 3 lines
---
Took the liberty to resubmit it, as people hit that on distribution kernels; tested and it looks to fix the issue.
Thanks for resubmitting and improving the changelog. I've been away last week.
Vlastimil
Quoted 31 lines
include/linux/mm.h | 2 +- mm/huge_memory.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)include/linux/mm.h +1
-1@@ -175,7 +175,7 @@ extern unsigned int kobjsize(const void *objp);* Special vmas that are non-mergable, non-mlock()able. * Note: mm/huge_memory.c VM_NO_THP depends on this definition. */ -#define VM_SPECIAL (VM_IO | VM_DONTEXPAND | VM_PFNMAP) +#define VM_SPECIAL (VM_IO | VM_DONTEXPAND | VM_PFNMAP | VM_MIXEDMAP)/* * mapping from the currently active vm_flags protection bits (the mm/huge_memory.c +1
-1@@ -1963,7 +1963,7 @@ out:return ret; } -#define VM_NO_THP (VM_SPECIAL|VM_MIXEDMAP|VM_HUGETLB|VM_SHARED|VM_MAYSHARE) +#define VM_NO_THP (VM_SPECIAL | VM_HUGETLB | VM_SHARED | VM_MAYSHARE)int hugepage_madvise (struct vm_area_struct *vma,unsigned long *vm_flags,int advice)