New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
simd: use alloc_pages_node to force alignment #9674
simd: use alloc_pages_node to force alignment #9674
Conversation
|
@bugcommenter @zachariasmaladroit maybe you could keep this a spin once another dev has taken a look? @behlendorf maybe we do want to add a kmem_cache_alloc_node wrapper as well, and force the cache to use SLAB? |
|
forgot to mention - I dumped the addresses, and the alignment was indeed off for KASAN/slub_debug=Z/SLAB_CANARY, and correct for regular kernel configs. with this patch, it was correct across the board - so I am fairly certain this is the culprit.. |
|
@Fabian-Gruenbichler definitely would give it a test once it is deemed safe ! Thanks for the work and quick track-down of the cause I'm running slub via |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This nicely explains things! I agree switching this to the kernel's slab allocator is going to be the best way to handle this. I also don't think we need to give up the numa locality if we directly use the kernel's slab allocator instead of the spl. Here's what I was thinking, 6ced01f, which tweaks your patch a little bit. Additional comments inline.
3275640
to
142eee4
Compare
Codecov Report
@@ Coverage Diff @@
## master #9674 +/- ##
========================================
+ Coverage 79% 79% +<1%
========================================
Files 418 418
Lines 123577 123562 -15
========================================
+ Hits 97951 98048 +97
+ Misses 25626 25514 -112
Continue to review full report at Codecov.
|
142eee4
to
31d2623
Compare
|
I took your v2 and just slightly reworded the commit message, and added '16-/' to the comment, hence left your authorship+final S-O-B. feel free to re-order the S-O-Bs/reset the author, if you think it is more appropriate the other way round. either is fine for me! |
|
also, dropped [WIP] prefix in PR :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, aside from the missing header. Thanks for updating it.
fxsave and xsave require the target address to be 16-/64-byte aligned. kmalloc(_node) does not (yet) offer such fine-grained control over alignement[0,1], even though it does "the right thing" most of the time for power-of-2 sizes. unfortunately, alignment is completely off when using certain debugging or hardening features/configs, such as KASAN, slub_debug=Z or the not-yet-upstream SLAB_CANARY. Use alloc_pages_node() instead which allows us to allocate page-aligned memory. Since fpregs_state is padded to a full page anyway, and this code is only relevant for x86 which has 4k pages, this approach should not allocate any unnecessary memory but still guarantuee the neeeded alignment. Fixes: openzfs#9608 0: https://lwn.net/Articles/787740/ 1: https://lore.kernel.org/linux-block/20190826111627.7505-1-vbabka@suse.cz/ Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>Foo Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
31d2623
to
e943c8e
Compare
fxsave and xsave require the target address to be 16-/64-byte aligned. kmalloc(_node) does not (yet) offer such fine-grained control over alignment[0,1], even though it does "the right thing" most of the time for power-of-2 sizes. unfortunately, alignment is completely off when using certain debugging or hardening features/configs, such as KASAN, slub_debug=Z or the not-yet-upstream SLAB_CANARY. Use alloc_pages_node() instead which allows us to allocate page-aligned memory. Since fpregs_state is padded to a full page anyway, and this code is only relevant for x86 which has 4k pages, this approach should not allocate any unnecessary memory but still guarantee the needed alignment. 0: https://lwn.net/Articles/787740/ 1: https://lore.kernel.org/linux-block/20190826111627.7505-1-vbabka@suse.cz/ Reviewed-by: Tony Hutter <hutter2@llnl.gov> Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes openzfs#9608 Closes openzfs#9674
fxsave and xsave require the target address to be 16-/64-byte aligned. kmalloc(_node) does not (yet) offer such fine-grained control over alignment[0,1], even though it does "the right thing" most of the time for power-of-2 sizes. unfortunately, alignment is completely off when using certain debugging or hardening features/configs, such as KASAN, slub_debug=Z or the not-yet-upstream SLAB_CANARY. Use alloc_pages_node() instead which allows us to allocate page-aligned memory. Since fpregs_state is padded to a full page anyway, and this code is only relevant for x86 which has 4k pages, this approach should not allocate any unnecessary memory but still guarantee the needed alignment. 0: https://lwn.net/Articles/787740/ 1: https://lore.kernel.org/linux-block/20190826111627.7505-1-vbabka@suse.cz/ Reviewed-by: Tony Hutter <hutter2@llnl.gov> Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes openzfs#9608 Closes openzfs#9674
fxsave and xsave require the target address to be 16-/64-byte aligned. kmalloc(_node) does not (yet) offer such fine-grained control over alignment[0,1], even though it does "the right thing" most of the time for power-of-2 sizes. unfortunately, alignment is completely off when using certain debugging or hardening features/configs, such as KASAN, slub_debug=Z or the not-yet-upstream SLAB_CANARY. Use alloc_pages_node() instead which allows us to allocate page-aligned memory. Since fpregs_state is padded to a full page anyway, and this code is only relevant for x86 which has 4k pages, this approach should not allocate any unnecessary memory but still guarantee the needed alignment. 0: https://lwn.net/Articles/787740/ 1: https://lore.kernel.org/linux-block/20190826111627.7505-1-vbabka@suse.cz/ Reviewed-by: Tony Hutter <hutter2@llnl.gov> Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes openzfs#9608 Closes openzfs#9674
fxsave and xsave require the target address to be 16-/64-byte aligned. kmalloc(_node) does not (yet) offer such fine-grained control over alignment[0,1], even though it does "the right thing" most of the time for power-of-2 sizes. unfortunately, alignment is completely off when using certain debugging or hardening features/configs, such as KASAN, slub_debug=Z or the not-yet-upstream SLAB_CANARY. Use alloc_pages_node() instead which allows us to allocate page-aligned memory. Since fpregs_state is padded to a full page anyway, and this code is only relevant for x86 which has 4k pages, this approach should not allocate any unnecessary memory but still guarantee the needed alignment. 0: https://lwn.net/Articles/787740/ 1: https://lore.kernel.org/linux-block/20190826111627.7505-1-vbabka@suse.cz/ Reviewed-by: Tony Hutter <hutter2@llnl.gov> Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes openzfs#9608 Closes openzfs#9674
fxsave and xsave require the target address to be 16-/64-byte aligned. kmalloc(_node) does not (yet) offer such fine-grained control over alignment[0,1], even though it does "the right thing" most of the time for power-of-2 sizes. unfortunately, alignment is completely off when using certain debugging or hardening features/configs, such as KASAN, slub_debug=Z or the not-yet-upstream SLAB_CANARY. Use alloc_pages_node() instead which allows us to allocate page-aligned memory. Since fpregs_state is padded to a full page anyway, and this code is only relevant for x86 which has 4k pages, this approach should not allocate any unnecessary memory but still guarantee the needed alignment. 0: https://lwn.net/Articles/787740/ 1: https://lore.kernel.org/linux-block/20190826111627.7505-1-vbabka@suse.cz/ Reviewed-by: Tony Hutter <hutter2@llnl.gov> Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #9608 Closes #9674
fxsave and xsave require the target address to be 16-/64-byte aligned. kmalloc(_node) does not (yet) offer such fine-grained control over alignment[0,1], even though it does "the right thing" most of the time for power-of-2 sizes. unfortunately, alignment is completely off when using certain debugging or hardening features/configs, such as KASAN, slub_debug=Z or the not-yet-upstream SLAB_CANARY. Use alloc_pages_node() instead which allows us to allocate page-aligned memory. Since fpregs_state is padded to a full page anyway, and this code is only relevant for x86 which has 4k pages, this approach should not allocate any unnecessary memory but still guarantee the needed alignment. 0: https://lwn.net/Articles/787740/ 1: https://lore.kernel.org/linux-block/20190826111627.7505-1-vbabka@suse.cz/ Reviewed-by: Tony Hutter <hutter2@llnl.gov> Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes openzfs#9608 Closes openzfs#9674
…node to force alignment fxsave and xsave require the target address to be 16-/64-byte aligned. kmalloc(_node) does not (yet) offer such fine-grained control over alignment[0,1], even though it does "the right thing" most of the time for power-of-2 sizes. unfortunately, alignment is completely off when using certain debugging or hardening features/configs, such as KASAN, slub_debug=Z or the not-yet-upstream SLAB_CANARY. Use alloc_pages_node() instead which allows us to allocate page-aligned memory. Since fpregs_state is padded to a full page anyway, and this code is only relevant for x86 which has 4k pages, this approach should not allocate any unnecessary memory but still guarantee the needed alignment. 0: https://lwn.net/Articles/787740/ 1: https://lore.kernel.org/linux-block/20190826111627.7505-1-vbabka@suse.cz/ Reviewed-by: Tony Hutter <hutter2@llnl.gov> Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes openzfs#9608 Closes openzfs#9674
fxsave and xsave require the target address to be 16-/64-byte aligned. kmalloc(_node) does not (yet) offer such fine-grained control over alignment[0,1], even though it does "the right thing" most of the time for power-of-2 sizes. unfortunately, alignment is completely off when using certain debugging or hardening features/configs, such as KASAN, slub_debug=Z or the not-yet-upstream SLAB_CANARY. Use alloc_pages_node() instead which allows us to allocate page-aligned memory. Since fpregs_state is padded to a full page anyway, and this code is only relevant for x86 which has 4k pages, this approach should not allocate any unnecessary memory but still guarantee the needed alignment. 0: https://lwn.net/Articles/787740/ 1: https://lore.kernel.org/linux-block/20190826111627.7505-1-vbabka@suse.cz/ Reviewed-by: Tony Hutter <hutter2@llnl.gov> Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes openzfs#9608 Closes openzfs#9674
Motivation and Context / Description
See #9608 - the SIMD/FPU code is currently broken because it relies on (wrong) assumptions about kernel memory allocation.
fxsave and xsave require the target address to be 16-/64-byte aligned.
kmalloc(_node) does not (yet) offer such fine-grained control over
alignement[0,1], even though it does "the right thing" most of the time
for power-of-2 sizes. unfortunately, alignment is completely off when
using certain debugging or hardening features/configs, such as KASAN,
slub_debug=Z or the not-yet-upstream SLAB_CANARY.
resort to (spl_)kmem_cache_alloc, which enables us to specify an
explicit alignment. CPU/NUMA-node locality is lost, since spl_kmem_cache
does not have kmem_cache_alloc_node support.
Fixes: #9608
0: https://lwn.net/Articles/787740/
1: https://lore.kernel.org/linux-block/20190826111627.7505-1-vbabka@suse.cz/
How Has This Been Tested?
smoke-tested in VMs with regular, hardened and slub_debug kernels
Types of changes
Checklist:
Signed-off-by.