All of lore.kernel.org
 help / color / mirror / Atom feed
From: Claudio Imbrenda <imbrenda@linux.ibm.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, david@redhat.com, thuth@redhat.com,
	frankja@linux.ibm.com, cohuck@redhat.com, lvivier@redhat.com,
	nadav.amit@gmail.com, krish.sadhukhan@oracle.com,
	dmatlack@google.com, seanjc@google.com
Subject: [kvm-unit-tests PATCH v1 2/2] x86: pku: fix the test to work with new allocator
Date: Thu, 21 Jan 2021 12:18:08 +0100	[thread overview]
Message-ID: <20210121111808.619347-3-imbrenda@linux.ibm.com> (raw)
In-Reply-To: <20210121111808.619347-1-imbrenda@linux.ibm.com>

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


  parent reply	other threads:[~2021-01-21 12:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210121111808.619347-3-imbrenda@linux.ibm.com \
    --to=imbrenda@linux.ibm.com \
    --cc=cohuck@redhat.com \
    --cc=david@redhat.com \
    --cc=dmatlack@google.com \
    --cc=frankja@linux.ibm.com \
    --cc=krish.sadhukhan@oracle.com \
    --cc=kvm@vger.kernel.org \
    --cc=lvivier@redhat.com \
    --cc=nadav.amit@gmail.com \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=thuth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.