Skip to contentSkip to conversation

Add ability to drop pages through testdev

PATCH In review Gleb Natapov 2 participants 6 messages Dec 22, 2010 – Dec 29, 2010 KVM

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add ability to drop pages through testdev

hw/testdev.c +12 -0
index d1abf59..29df385 100644
@@ -1,3 +1,4 @@
+#include <sys/mman.h>
 #include "hw.h"
 #include "qdev.h"
 #include "isa.h"
@@ -46,6 +47,16 @@ static uint32_t test_device_ioport_read(void *opaque, uint32_t addr)
     return test_device_ioport_data;
 }
 
+static void test_device_flush_page(void *opaque, uint32_t addr, uint32_t data)
+{
+    target_phys_addr_t len = 4096;
+    void *a = cpu_physical_memory_map(data & ~0xffful, &len, 0);
+
+    mprotect(a, 4096, PROT_NONE);
+    mprotect(a, 4096, PROT_READ|PROT_WRITE);
+    cpu_physical_memory_unmap(a, len, 0, 0);
+}
+
 static char *iomem_buf;
 
 static uint32_t test_iomem_readb(void *opaque, target_phys_addr_t addr)
@@ -104,6 +115,7 @@ static int init_test_device(ISADevice *isa)
     register_ioport_write(0xe0, 1, 2, test_device_ioport_write, dev);
     register_ioport_read(0xe0, 1, 4, test_device_ioport_read, dev);
     register_ioport_write(0xe0, 1, 4, test_device_ioport_write, dev);
+    register_ioport_write(0xe4, 1, 4, test_device_flush_page, dev);
     register_ioport_write(0x2000, 24, 1, test_device_irq_line, NULL);
     iomem_buf = qemu_mallocz(0x10000);
     iomem = cpu_register_io_memory(test_iomem_read, test_iomem_write, NULL);

--
Gleb.

#1 lore raw
Quoted 14 lines · Gleb Natapov
hw/testdev.c +1 -0
index d1abf59..29df385 100644
@@ -1,3 +1,4 @@
+#include<sys/mman.h>
  #include "hw.h"
  #include "qdev.h"
  #include "isa.h"
@@ -46,6 +47,16 @@ static uint32_t test_device_ioport_read(void *opaque, uint32_t addr)
      return test_device_ioport_data;
  }
 

hw/testdev.c static uint32_t test_device_ioport_read(void *opaque, uint32_t addr) · line 59

Quoted 10 lines
hw/testdev.c +10 -0
+static void test_device_flush_page(void *opaque, uint32_t addr, uint32_t data)
+{
+    target_phys_addr_t len = 4096;
+    void *a = cpu_physical_memory_map(data&  ~0xffful,&len, 0);
+
+    mprotect(a, 4096, PROT_NONE);
+    mprotect(a, 4096, PROT_READ|PROT_WRITE);
+    cpu_physical_memory_unmap(a, len, 0, 0);
+}
+

Icky. This is much better done through the api tests. Applied it so as not to spoil all the effort.

Signature · 1 line
error compiling committee.c: too many arguments to function
#2 lore raw
Quoted 15 lines · Avi Kivity
Quoted 14 lines · Gleb Natapov
hw/testdev.c +1 -0
index d1abf59..29df385 100644
@@ -1,3 +1,4 @@
+#include<sys/mman.h>
 #include "hw.h"
 #include "qdev.h"
 #include "isa.h"
@@ -46,6 +47,16 @@ static uint32_t test_device_ioport_read(void *opaque, uint32_t addr)
     return test_device_ioport_data;
 }
 
Quoted 14 lines

hw/testdev.c static uint32_t test_device_ioport_read(void *opaque, uint32_t addr) · line 59

Quoted 10 lines
hw/testdev.c +10 -0
+static void test_device_flush_page(void *opaque, uint32_t addr, uint32_t data)
+{
+    target_phys_addr_t len = 4096;
+    void *a = cpu_physical_memory_map(data&  ~0xffful,&len, 0);
+
+    mprotect(a, 4096, PROT_NONE);
+    mprotect(a, 4096, PROT_READ|PROT_WRITE);
+    cpu_physical_memory_unmap(a, len, 0, 0);
+}
+

Icky. This is much better done through the api tests. Applied it so as not to spoil all the effort.

How would you do that there?

--
Gleb.

#3 lore raw
Quoted 27 lines · Gleb Natapov
Quoted 26 lines · Avi Kivity
Quoted 24 lines · Gleb Natapov
hw/testdev.c +11 -0
index d1abf59..29df385 100644
@@ -1,3 +1,4 @@
+#include<sys/mman.h>
  #include "hw.h"
  #include "qdev.h"
  #include "isa.h"
@@ -46,6 +47,16 @@ static uint32_t test_device_ioport_read(void *opaque, uint32_t addr)
      return test_device_ioport_data;
  }
 
+static void test_device_flush_page(void *opaque, uint32_t addr, uint32_t data)
+{
+    target_phys_addr_t len = 4096;
+    void *a = cpu_physical_memory_map(data&   ~0xffful,&len, 0);
+
+    mprotect(a, 4096, PROT_NONE);
+    mprotect(a, 4096, PROT_READ|PROT_WRITE);
+    cpu_physical_memory_unmap(a, len, 0, 0);
+}
+
Quoted 4 lines
Quoted 3 lines

Icky. This is much better done through the api tests. Applied it so as not to spoil all the effort.

How would you do that there?

Set up all the state using the KVM_SET_REGS family, pointing to the instruction you want to test, and KVM_RUN that. You can even queue exceptions and interrupts for complicated cases.

Signature · 1 line
error compiling committee.c: too many arguments to function
#4 lore raw
Quoted 28 lines · Avi Kivity
Quoted 27 lines · Gleb Natapov
Quoted 26 lines · Avi Kivity
Quoted 24 lines · Gleb Natapov
hw/testdev.c +11 -0
index d1abf59..29df385 100644
@@ -1,3 +1,4 @@
+#include<sys/mman.h>
  #include "hw.h"
  #include "qdev.h"
  #include "isa.h"
@@ -46,6 +47,16 @@ static uint32_t test_device_ioport_read(void *opaque, uint32_t addr)
      return test_device_ioport_data;
  }
 
+static void test_device_flush_page(void *opaque, uint32_t addr, uint32_t data)
+{
+    target_phys_addr_t len = 4096;
+    void *a = cpu_physical_memory_map(data&   ~0xffful,&len, 0);
+
+    mprotect(a, 4096, PROT_NONE);
+    mprotect(a, 4096, PROT_READ|PROT_WRITE);
+    cpu_physical_memory_unmap(a, len, 0, 0);
+}
+
Quoted 9 lines
Quoted 4 lines
Quoted 3 lines

Icky. This is much better done through the api tests. Applied it so as not to spoil all the effort.

How would you do that there?

Set up all the state using the KVM_SET_REGS family, pointing to the instruction you want to test, and KVM_RUN that. You can even queue exceptions and interrupts for complicated cases.

I mean how do you drop a page from shadow/ept tables? Wouldn't you have to do the same trick there?

--
Gleb.

#5 lore raw
Quoted 12 lines · Gleb Natapov
Quoted 9 lines
Quoted 4 lines
Quoted 3 lines

Icky. This is much better done through the api tests. Applied it so as not to spoil all the effort.

How would you do that there?

Set up all the state using the KVM_SET_REGS family, pointing to the instruction you want to test, and KVM_RUN that. You can even queue exceptions and interrupts for complicated cases.

I mean how do you drop a page from shadow/ept tables? Wouldn't you have to do the same trick there?

Yes, but you just call munmap(), you don't have to go through testdev.

Signature · 1 line
error compiling committee.c: too many arguments to function