kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH v1 0/2] Fix smap and pku tests for new allocator
@ 2021-01-21 11:18 Claudio Imbrenda
  2021-01-21 11:18 ` [kvm-unit-tests PATCH v1 1/2] x86: smap: fix the test to work with " Claudio Imbrenda
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Claudio Imbrenda @ 2021-01-21 11:18 UTC (permalink / raw)
  To: kvm
  Cc: pbonzini, david, thuth, frankja, cohuck, lvivier, nadav.amit,
	krish.sadhukhan, dmatlack, seanjc

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

-- 
2.26.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [kvm-unit-tests PATCH v1 1/2] x86: smap: fix the test to work with new allocator
  2021-01-21 11:18 [kvm-unit-tests PATCH v1 0/2] Fix smap and pku tests for new allocator Claudio Imbrenda
@ 2021-01-21 11:18 ` Claudio Imbrenda
  2021-01-21 11:18 ` [kvm-unit-tests PATCH v1 2/2] x86: pku: " Claudio Imbrenda
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Claudio Imbrenda @ 2021-01-21 11:18 UTC (permalink / raw)
  To: kvm
  Cc: pbonzini, david, thuth, frankja, cohuck, lvivier, nadav.amit,
	krish.sadhukhan, dmatlack, seanjc

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.

Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
Reported-by: David Matlack <dmatlack@google.com>
---
 x86/smap.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/x86/smap.c b/x86/smap.c
index 5782c4a..ac2c8d5 100644
--- a/x86/smap.c
+++ b/x86/smap.c
@@ -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);
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [kvm-unit-tests PATCH v1 2/2] x86: pku: fix the test to work with new allocator
  2021-01-21 11:18 [kvm-unit-tests PATCH v1 0/2] Fix smap and pku tests for new allocator Claudio Imbrenda
  2021-01-21 11:18 ` [kvm-unit-tests PATCH v1 1/2] x86: smap: fix the test to work with " Claudio Imbrenda
@ 2021-01-21 11:18 ` Claudio Imbrenda
  2021-01-21 18:23 ` [kvm-unit-tests PATCH v1 0/2] Fix smap and pku tests for " David Matlack
  2021-01-23 18:16 ` Paolo Bonzini
  3 siblings, 0 replies; 6+ messages in thread
From: Claudio Imbrenda @ 2021-01-21 11:18 UTC (permalink / raw)
  To: kvm
  Cc: pbonzini, david, thuth, frankja, cohuck, lvivier, nadav.amit,
	krish.sadhukhan, dmatlack, seanjc

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

Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
---
 x86/pku.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/x86/pku.c b/x86/pku.c
index 4f6086c..7e8247c 100644
--- a/x86/pku.c
+++ b/x86/pku.c
@@ -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);
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [kvm-unit-tests PATCH v1 0/2] Fix smap and pku tests for new allocator
  2021-01-21 11:18 [kvm-unit-tests PATCH v1 0/2] Fix smap and pku tests for new allocator Claudio Imbrenda
  2021-01-21 11:18 ` [kvm-unit-tests PATCH v1 1/2] x86: smap: fix the test to work with " Claudio Imbrenda
  2021-01-21 11:18 ` [kvm-unit-tests PATCH v1 2/2] x86: pku: " Claudio Imbrenda
@ 2021-01-21 18:23 ` David Matlack
  2021-01-22  0:55   ` Chenyi Qiang
  2021-01-23 18:16 ` Paolo Bonzini
  3 siblings, 1 reply; 6+ messages in thread
From: David Matlack @ 2021-01-21 18:23 UTC (permalink / raw)
  To: Claudio Imbrenda
  Cc: kvm list, Paolo Bonzini, David Hildenbrand, Thomas Huth, frankja,
	cohuck, Laurent Vivier, nadav.amit, krish.sadhukhan, seanjc,
	chenyi.qiang

On Thu, Jan 21, 2021 at 3:18 AM Claudio Imbrenda <imbrenda@linux.ibm.com> wrote:
>
> 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.

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.

chenyi.qiang@intel.com: FYI your in-progress PKS test looks like it
will need the same fix.



>
>
>
>
> 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(-)
>
> --
> 2.26.2
>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [kvm-unit-tests PATCH v1 0/2] Fix smap and pku tests for new allocator
  2021-01-21 18:23 ` [kvm-unit-tests PATCH v1 0/2] Fix smap and pku tests for " David Matlack
@ 2021-01-22  0:55   ` Chenyi Qiang
  0 siblings, 0 replies; 6+ messages in thread
From: Chenyi Qiang @ 2021-01-22  0:55 UTC (permalink / raw)
  To: David Matlack, Claudio Imbrenda
  Cc: kvm list, Paolo Bonzini, David Hildenbrand, Thomas Huth, frankja,
	cohuck, Laurent Vivier, nadav.amit, krish.sadhukhan, seanjc



On 1/22/2021 2:23 AM, David Matlack wrote:
> On Thu, Jan 21, 2021 at 3:18 AM Claudio Imbrenda <imbrenda@linux.ibm.com> wrote:
>>
>> 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.
> 
> 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.
> 
> chenyi.qiang@intel.com: FYI your in-progress PKS test looks like it
> will need the same fix.
> 
> 

Yeah, thank you for your reminder!

> 
>>
>>
>>
>>
>> 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(-)
>>
>> --
>> 2.26.2
>>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [kvm-unit-tests PATCH v1 0/2] Fix smap and pku tests for new allocator
  2021-01-21 11:18 [kvm-unit-tests PATCH v1 0/2] Fix smap and pku tests for new allocator Claudio Imbrenda
                   ` (2 preceding siblings ...)
  2021-01-21 18:23 ` [kvm-unit-tests PATCH v1 0/2] Fix smap and pku tests for " David Matlack
@ 2021-01-23 18:16 ` Paolo Bonzini
  3 siblings, 0 replies; 6+ messages in thread
From: Paolo Bonzini @ 2021-01-23 18:16 UTC (permalink / raw)
  To: Claudio Imbrenda, kvm
  Cc: david, thuth, frankja, cohuck, lvivier, nadav.amit,
	krish.sadhukhan, dmatlack, seanjc

On 21/01/21 12:18, Claudio Imbrenda wrote:
> 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(-)
> 

Queued, thanks.

Paolo


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-01-23 18:18 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-21 11:18 [kvm-unit-tests PATCH v1 0/2] Fix smap and pku tests for new allocator Claudio Imbrenda
2021-01-21 11:18 ` [kvm-unit-tests PATCH v1 1/2] x86: smap: fix the test to work with " Claudio Imbrenda
2021-01-21 11:18 ` [kvm-unit-tests PATCH v1 2/2] x86: pku: " Claudio Imbrenda
2021-01-21 18:23 ` [kvm-unit-tests PATCH v1 0/2] Fix smap and pku tests for " David Matlack
2021-01-22  0:55   ` Chenyi Qiang
2021-01-23 18:16 ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).