public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
To: Avi Kivity <avi@redhat.com>
Cc: Marcelo Tosatti <mtosatti@redhat.com>, KVM list <kvm@vger.kernel.org>
Subject: [PATCH 2/3] KVM test: separate pool from ac_test_t struct
Date: Fri, 23 Jul 2010 13:03:57 +0800	[thread overview]
Message-ID: <4C4922BD.6090502@cn.fujitsu.com> (raw)
In-Reply-To: <4C4921C5.4090809@cn.fujitsu.com>

Separate pool from the ac_test_t struct, later we will use multiple ac_test_t
units, those units should allocate pte from the same pool to avoid mapping to
the same pte

Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
---
 kvm/test/x86/access.c |   71 ++++++++++++++++++++++++++++--------------------
 1 files changed, 41 insertions(+), 30 deletions(-)

diff --git a/kvm/test/x86/access.c b/kvm/test/x86/access.c
index ebadae9..be51a55 100644
--- a/kvm/test/x86/access.c
+++ b/kvm/test/x86/access.c
@@ -127,12 +127,15 @@ typedef struct {
 } idt_entry_t;
 
 typedef struct {
-    unsigned flags[NR_AC_FLAGS];
-    void *virt;
-    pt_element_t phys;
     pt_element_t pt_pool;
     unsigned pt_pool_size;
     unsigned pt_pool_current;
+} ac_pool_t;
+
+typedef struct {
+    unsigned flags[NR_AC_FLAGS];
+    void *virt;
+    pt_element_t phys;
     pt_element_t *ptep;
     pt_element_t expected_pte;
     pt_element_t *pdep;
@@ -225,23 +228,29 @@ void set_efer_nx(int nx)
     wrmsr(MSR_EFER, efer);
 }
 
+static void ac_env_int(ac_pool_t *pool)
+{
+    static idt_entry_t idt[256];
+
+    memset(idt, 0, sizeof(idt));
+    lidt(idt, 256);
+    extern char page_fault, kernel_entry;
+    set_idt_entry(&idt[14], &page_fault, 0);
+    set_idt_entry(&idt[0x20], &kernel_entry, 3);
 
-void ac_test_init(ac_test_t *at)
+    pool->pt_pool = 33 * 1024 * 1024;
+    pool->pt_pool_size = 120 * 1024 * 1024 - pool->pt_pool;
+    pool->pt_pool_current = 0;
+}
+
+void ac_test_init(ac_test_t *at, void *virt)
 {
     wrmsr(MSR_EFER, rdmsr(MSR_EFER) | EFER_NX_MASK);
     set_cr0_wp(1);
     for (int i = 0; i < NR_AC_FLAGS; ++i)
 	at->flags[i] = 0;
-    at->virt = (void *)(0x123400000000 + 16 * smp_id());
+    at->virt = virt;
     at->phys = 32 * 1024 * 1024;
-    at->pt_pool = 33 * 1024 * 1024;
-    at->pt_pool_size = 120 * 1024 * 1024 - at->pt_pool;
-    at->pt_pool_current = 0;
-    memset(at->idt, 0, sizeof at->idt);
-    lidt(at->idt, 256);
-    extern char page_fault, kernel_entry;
-    set_idt_entry(&at->idt[14], &page_fault, 0);
-    set_idt_entry(&at->idt[0x20], &kernel_entry, 3);
 }
 
 int ac_test_bump_one(ac_test_t *at)
@@ -285,21 +294,21 @@ void invlpg(void *addr)
     asm volatile ("invlpg (%0)" : : "r"(addr));
 }
 
-pt_element_t ac_test_alloc_pt(ac_test_t *at)
+pt_element_t ac_test_alloc_pt(ac_pool_t *pool)
 {
-    pt_element_t ret = at->pt_pool + at->pt_pool_current;
-    at->pt_pool_current += PAGE_SIZE;
+    pt_element_t ret = pool->pt_pool + pool->pt_pool_current;
+    pool->pt_pool_current += PAGE_SIZE;
     return ret;
 }
 
-_Bool ac_test_enough_room(ac_test_t *at)
+_Bool ac_test_enough_room(ac_pool_t *pool)
 {
-    return at->pt_pool_current + 4 * PAGE_SIZE <= at->pt_pool_size;
+    return pool->pt_pool_current + 4 * PAGE_SIZE <= pool->pt_pool_size;
 }
 
-void ac_test_reset_pt_pool(ac_test_t *at)
+void ac_test_reset_pt_pool(ac_pool_t *pool)
 {
-    at->pt_pool_current = 0;
+    pool->pt_pool_current = 0;
 }
 
 void ac_set_expected_status(ac_test_t *at)
@@ -407,12 +416,12 @@ fault:
         at->expected_error &= ~PFERR_FETCH_MASK;
 }
 
-void ac_test_setup_pte(ac_test_t *at)
+void ac_test_setup_pte(ac_test_t *at, ac_pool_t *pool)
 {
     unsigned long root = read_cr3();
 
-    if (!ac_test_enough_room(at))
-	ac_test_reset_pt_pool(at);
+    if (!ac_test_enough_room(pool))
+	ac_test_reset_pt_pool(pool);
 
     at->ptep = 0;
     for (int i = 4; i >= 1 && (i >= 2 || !at->flags[AC_PDE_PSE]); --i) {
@@ -423,12 +432,12 @@ void ac_test_setup_pte(ac_test_t *at)
 	case 4:
 	case 3:
 	    pte = vroot[index];
-	    pte = ac_test_alloc_pt(at) | PT_PRESENT_MASK;
+	    pte = ac_test_alloc_pt(pool) | PT_PRESENT_MASK;
 	    pte |= PT_WRITABLE_MASK | PT_USER_MASK;
 	    break;
 	case 2:
 	    if (!at->flags[AC_PDE_PSE])
-		pte = ac_test_alloc_pt(at);
+		pte = ac_test_alloc_pt(pool);
 	    else {
 		pte = at->phys & PT_PSE_BASE_ADDR_MASK;
 		pte |= PT_PSE_MASK;
@@ -620,29 +629,31 @@ static void ac_test_show(ac_test_t *at)
     printf("%s", line);
 }
 
-int ac_test_exec(ac_test_t *at)
+int ac_test_exec(ac_test_t *at, ac_pool_t *pool)
 {
     int r;
 
     if (verbose) {
         ac_test_show(at);
     }
-    ac_test_setup_pte(at);
+    ac_test_setup_pte(at, pool);
     r = ac_test_do_access(at);
     return r;
 }
 
 int ac_test_run(void)
 {
-    static ac_test_t at;
+    ac_test_t at;
+    ac_pool_t pool;
     int tests, successes;
 
     printf("run\n");
     tests = successes = 0;
-    ac_test_init(&at);
+    ac_env_int(&pool);
+    ac_test_init(&at, (void *)(0x123400000000 + 16 * smp_id()));
     do {
 	++tests;
-	successes += ac_test_exec(&at);
+	successes += ac_test_exec(&at, &pool);
     } while (ac_test_bump(&at));
 
     printf("\n%d tests, %d failures\n", tests, tests - successes);
-- 
1.6.1.2



  reply	other threads:[~2010-07-23  5:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-23  4:59 [PATCH 1/3] KVM test: separate expect status updates from ac_test_setup_pte() function Xiao Guangrong
2010-07-23  5:03 ` Xiao Guangrong [this message]
2010-07-23  5:07   ` [PATCH 3/3] KVM test: add test case to trigger the bug which cause hugepage mapping corrupt Xiao Guangrong
2010-07-27 21:14 ` [PATCH 1/3] KVM test: separate expect status updates from ac_test_setup_pte() function Marcelo Tosatti

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=4C4922BD.6090502@cn.fujitsu.com \
    --to=xiaoguangrong@cn.fujitsu.com \
    --cc=avi@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox