Fix smap and pku tests for new allocator
cover Fix smap and pku tests for new allocator
The recent fixes to the page allocator broke the SMAP test.
The reason is that the test blindly took a chunk of memory and used it, hoping that the page allocator would not touch it.
Unfortunately the memory area affected is exactly where the new allocator puts the metadata information for the 16M-4G memory area.
This causes the SMAP test to fail.
The solution is to reserve the memory properly using the reserve_pages function. To make things simpler, the memory area reserved is now 8M-16M instead of 16M-32M.
This issue was not found immediately, because the SMAP test needs non-default qemu parameters in order not to be skipped.
I tested the patch and it seems to work.
While fixing the SMAP test, I also noticed that the PKU test was doing the same thing, so I went ahead and fixed that test too in the same way. Unfortunately I do not have the right hardware and therefore I cannot test it.
I would really appreciate if someone who has the right hardware could test the PKU test and see if it works.
Claudio Imbrenda (2):
x86: smap: fix the test to work with new allocator
x86: pku: fix the test to work with new allocator
x86/pku.c | 5 ++++- x86/smap.c | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-)
Signature · 1 line
2.26.2
PATCH 1/2 x86: smap: fix the test to work with new allocator
The test used to simply take a chunk of memory and use it, hoping the memory allocator would never touch it. The memory area used was exactly at the beginning of the 16M boundary.
The new allocator stores metadata information there, and causes the test to fail.
This patch uses the new features of the allocator to properly reserve a memory block. To make things easier and cleaner, the memory area used is now smaller and starts at 8M.
--- x86/smap.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
x86/smap.c +6 -3
@@ -1,4 +1,5 @@#include "libcflat.h" +#include <alloc_page.h> #include "x86/desc.h" #include "x86/processor.h" #include "x86/vm.h"
@@ -44,7 +45,7 @@ asm ("pf_tss:\n" "jmp pf_tss\n\t"); -#define USER_BASE (1 << 24) +#define USER_BASE (1 << 23)#define USER_VAR (v) (*((__typeof__(&(v))) (((unsigned long)&v) + USER_BASE)))#define USER_ADDR (v) ((void *)((unsigned long)(&v) + USER_BASE))
@@ -101,13 +102,15 @@ int main(int ac, char **av)setup_alt_stack ();set_intr_alt_stack (14 , pf_tss); -// Map first 16MB as supervisor pages +if (reserve_pages (USER_BASE ,USER_BASE >>12 )) +report_abort ("Could not reserve memory" ); +// Map first 8MB as supervisor pages for (i =0 ; i <USER_BASE ; i +=PAGE_SIZE ) { *get_pte (phys_to_virt (read_cr3 ()),phys_to_virt (i)) &= ~PT_USER_MASK ;invlpg ((void *)i); } -// Present the same 16MB as user pages in the 16MB-32MB range +// Present the same 8MB as user pages in the 8MB-16MB range for (i =USER_BASE ; i <2 *USER_BASE ; i +=PAGE_SIZE ) { *get_pte (phys_to_virt (read_cr3 ()),phys_to_virt (i)) &= ~USER_BASE ;invlpg ((void *)i);
Signature · 1 line
2.26.2
PATCH 2/2 x86: pku: fix the test to work with new allocator
In reply to Claudio ImbrendaThe test used to simply take a chunk of memory and use it, hoping the memory allocator would never touch it. The memory area used was exactly at the beginning of the 16M boundary.
The new allocator stores metadata information there, and could cause the test to fail.
This patch uses the new features of the allocator to properly reserve a memory block. To make things easier and cleaner, the memory area used is now smaller and starts at 8M.
--- x86/pku.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
x86/pku.c +4 -1
@@ -1,4 +1,5 @@#include "libcflat.h" +#include <alloc_page.h> #include "x86/desc.h" #include "x86/processor.h" #include "x86/vm.h"
@@ -6,7 +7,7 @@#define CR0_WP_MASK (1UL << 16)#define PTE_PKEY_BIT 59 -#define USER_BASE (1 << 24) +#define USER_BASE (1 << 23)#define USER_VAR (v) (*((__typeof__(&(v))) (((unsigned long)&v) + USER_BASE)))volatile int pf_count =0 ;
@@ -77,6 +78,8 @@ int main(int ac, char **av)set_intr_alt_stack (14 , pf_tss);wrmsr (MSR_EFER ,rdmsr (MSR_EFER ) |EFER_LMA ); +if (reserve_pages (USER_BASE ,USER_BASE >>12 )) +report_abort ("Could not reserve memory" );for (i =0 ; i <USER_BASE ; i +=PAGE_SIZE ) { *get_pte (phys_to_virt (read_cr3 ()),phys_to_virt (i)) &= ~PT_USER_MASK ; *get_pte (phys_to_virt (read_cr3 ()),phys_to_virt (i)) |= ((unsigned long )pkey <<PTE_PKEY_BIT );
Signature · 1 line
2.26.2
Quoted 27 lines · Claudio Imbrenda
The recent fixes to the page allocator broke the SMAP test.
The reason is that the test blindly took a chunk of memory and used it, hoping that the page allocator would not touch it.
Unfortunately the memory area affected is exactly where the new allocator puts the metadata information for the 16M-4G memory area.
This causes the SMAP test to fail.
The solution is to reserve the memory properly using the
reserve_pagesfunction. To make things simpler, the memory area reserved is now 8M-16M instead of 16M-32M.This issue was not found immediately, because the SMAP test needs non-default qemu parameters in order not to be skipped.
I tested the patch and it seems to work.
While fixing the SMAP test, I also noticed that the PKU test was doing the same thing, so I went ahead and fixed that test too in the same way. Unfortunately I do not have the right hardware and therefore I cannot test it.
Quoted 2 lines
I would really appreciate if someone who has the right hardware could test the PKU test and see if it works.
Thanks for identifying the PKU test as well. I can confirm it is also failing.
I tested out your patches on supported hardware and both the smap and pku tests passed.
[email protected]: FYI your in-progress PKS test looks like it will need the same fix.
Quoted 15 lines
Claudio Imbrenda (2):
x86: smap: fix the test to work with new allocator
x86: pku: fix the test to work with new allocatorx86/pku.c | 5 ++++- x86/smap.c | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-)--
2.26.2
Quoted 31 lines · David Matlack
Quoted 27 lines · Claudio Imbrenda
The recent fixes to the page allocator broke the SMAP test.
The reason is that the test blindly took a chunk of memory and used it, hoping that the page allocator would not touch it.
Unfortunately the memory area affected is exactly where the new allocator puts the metadata information for the 16M-4G memory area.
This causes the SMAP test to fail.
The solution is to reserve the memory properly using the
reserve_pagesfunction. To make things simpler, the memory area reserved is now 8M-16M instead of 16M-32M.This issue was not found immediately, because the SMAP test needs non-default qemu parameters in order not to be skipped.
I tested the patch and it seems to work.
While fixing the SMAP test, I also noticed that the PKU test was doing the same thing, so I went ahead and fixed that test too in the same way. Unfortunately I do not have the right hardware and therefore I cannot test it.
Quoted 2 lines
I would really appreciate if someone who has the right hardware could test the PKU test and see if it works.
Quoted 9 lines
Thanks for identifying the PKU test as well. I can confirm it is also failing.
I tested out your patches on supported hardware and both the smap and pku tests passed.
[email protected]: FYI your in-progress PKS test looks like it will need the same fix.
Yeah, thank you for your reminder!
Quoted 16 lines
Quoted 16 lines
Claudio Imbrenda (2):
x86: smap: fix the test to work with new allocator
x86: pku: fix the test to work with new allocatorx86/pku.c | 5 ++++- x86/smap.c | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-)--
2.26.2
Quoted 32 lines · Claudio Imbrenda
The recent fixes to the page allocator broke the SMAP test.
The reason is that the test blindly took a chunk of memory and used it, hoping that the page allocator would not touch it.
Unfortunately the memory area affected is exactly where the new allocator puts the metadata information for the 16M-4G memory area.
This causes the SMAP test to fail.
The solution is to reserve the memory properly using the
reserve_pagesfunction. To make things simpler, the memory area reserved is now 8M-16M instead of 16M-32M.This issue was not found immediately, because the SMAP test needs non-default qemu parameters in order not to be skipped.
I tested the patch and it seems to work.
While fixing the SMAP test, I also noticed that the PKU test was doing the same thing, so I went ahead and fixed that test too in the same way. Unfortunately I do not have the right hardware and therefore I cannot test it.
I would really appreciate if someone who has the right hardware could test the PKU test and see if it works.
Quoted 8 lines
Claudio Imbrenda (2):
x86: smap: fix the test to work with new allocator
x86: pku: fix the test to work with new allocatorx86/pku.c | 5 ++++- x86/smap.c | 9 ++++++--- 2 files changed, 10 insertions(+), 4 deletions(-)
Queued, thanks.
Paolo