Looks like the configuration generator needs updating as well.

Sent from a phone

-----Original Message-----
From: Jan Kiszka [[email protected]]
Received: Sonntag, 22 Okt. 2017, 14:36
To: Jailhouse [[email protected]]
Subject: [PATCH 2/2] x86, configs: Make CPU reset address configurable

From: Jan Kiszka <[email protected]>

Analogously to ARM, this makes the reset address of x86 CPUs definable
via jailhouse_cell_desc.cpu_reset_address. In order to keep the existing
demo inmates alive, all related config files define cpu_reset_address to
0xffff0 which was hard-coded into the hypervisor so far.

Signed-off-by: Jan Kiszka <[email protected]>
---
 configs/apic-demo.c       |  2 ++
 configs/e1000-demo.c      |  2 ++
 configs/ioapic-demo.c     |  2 ++
 configs/ivshmem-demo.c    |  2 ++
 configs/linux-x86-demo.c  |  2 ++
 configs/pci-demo.c        |  2 ++
 configs/smp-demo.c        |  2 ++
 configs/tiny-demo.c       |  2 ++
 hypervisor/arch/x86/svm.c | 21 +++++++++++++--------
 hypervisor/arch/x86/vmx.c | 22 ++++++++++++++--------
 10 files changed, 43 insertions(+), 16 deletions(-)

diff --git a/configs/apic-demo.c b/configs/apic-demo.c
index 7f2de60a..9c8fed23 100644
--- a/configs/apic-demo.c
+++ b/configs/apic-demo.c
@@ -35,6 +35,8 @@ struct {
                 .num_irqchips = 0,
                 .pio_bitmap_size = ARRAY_SIZE(config.pio_bitmap),
                 .num_pci_devices = 0,
+
+               .cpu_reset_address = 0xffff0,
         },

         .cpus = {
diff --git a/configs/e1000-demo.c b/configs/e1000-demo.c
index 59a350ff..05696ab2 100644
--- a/configs/e1000-demo.c
+++ b/configs/e1000-demo.c
@@ -38,6 +38,8 @@ struct {
                 .pio_bitmap_size = ARRAY_SIZE(config.pio_bitmap),
                 .num_pci_devices = ARRAY_SIZE(config.pci_devices),
                 .num_pci_caps = ARRAY_SIZE(config.pci_caps),
+
+               .cpu_reset_address = 0xffff0,
         },

         .cpus = {
diff --git a/configs/ioapic-demo.c b/configs/ioapic-demo.c
index 4f12d12a..2a95a7d8 100644
--- a/configs/ioapic-demo.c
+++ b/configs/ioapic-demo.c
@@ -36,6 +36,8 @@ struct {
                 .num_irqchips = ARRAY_SIZE(config.irqchips),
                 .pio_bitmap_size = ARRAY_SIZE(config.pio_bitmap),
                 .num_pci_devices = 0,
+
+               .cpu_reset_address = 0xffff0,
         },

         .cpus = {
diff --git a/configs/ivshmem-demo.c b/configs/ivshmem-demo.c
index 8fa991fe..745c24db 100644
--- a/configs/ivshmem-demo.c
+++ b/configs/ivshmem-demo.c
@@ -35,6 +35,8 @@ struct {
                 .pio_bitmap_size = ARRAY_SIZE(config.pio_bitmap),
                 .num_pci_devices = ARRAY_SIZE(config.pci_devices),
                 .num_pci_caps = ARRAY_SIZE(config.pci_caps),
+
+               .cpu_reset_address = 0xffff0,
         },

         .cpus = {
diff --git a/configs/linux-x86-demo.c b/configs/linux-x86-demo.c
index 27c972df..e094ada5 100644
--- a/configs/linux-x86-demo.c
+++ b/configs/linux-x86-demo.c
@@ -47,6 +47,8 @@ struct {
                 .pio_bitmap_size = ARRAY_SIZE(config.pio_bitmap),
                 .num_pci_devices = ARRAY_SIZE(config.pci_devices),
                 .num_pci_caps = ARRAY_SIZE(config.pci_caps),
+
+               .cpu_reset_address = 0xffff0,
         },

         .cpus = {
diff --git a/configs/pci-demo.c b/configs/pci-demo.c
index b15d4e0a..3bd9eb32 100644
--- a/configs/pci-demo.c
+++ b/configs/pci-demo.c
@@ -38,6 +38,8 @@ struct {
                 .pio_bitmap_size = ARRAY_SIZE(config.pio_bitmap),
                 .num_pci_devices = ARRAY_SIZE(config.pci_devices),
                 .num_pci_caps = ARRAY_SIZE(config.pci_caps),
+
+               .cpu_reset_address = 0xffff0,
         },

         .cpus = {
diff --git a/configs/smp-demo.c b/configs/smp-demo.c
index f05f029f..f4b8db1f 100644
--- a/configs/smp-demo.c
+++ b/configs/smp-demo.c
@@ -34,6 +34,8 @@ struct {
                 .num_irqchips = 0,
                 .pio_bitmap_size = ARRAY_SIZE(config.pio_bitmap),
                 .num_pci_devices = 0,
+
+               .cpu_reset_address = 0xffff0,
         },

         .cpus = {
diff --git a/configs/tiny-demo.c b/configs/tiny-demo.c
index f31ac96b..69ce7393 100644
--- a/configs/tiny-demo.c
+++ b/configs/tiny-demo.c
@@ -36,6 +36,8 @@ struct {
                 .num_irqchips = 0,
                 .pio_bitmap_size = ARRAY_SIZE(config.pio_bitmap),
                 .num_pci_devices = 0,
+
+               .cpu_reset_address = 0xffff0,
         },

         .cpus = {
diff --git a/hypervisor/arch/x86/svm.c b/hypervisor/arch/x86/svm.c
index d830f8bc..c125c0da 100644
--- a/hypervisor/arch/x86/svm.c
+++ b/hypervisor/arch/x86/svm.c
@@ -559,24 +559,29 @@ void vcpu_vendor_reset(unsigned int sipi_vector)
         };
         struct per_cpu *cpu_data = this_cpu_data();
         struct vmcb *vmcb = &cpu_data->vmcb;
-       unsigned long val;
+       unsigned long reset_addr;

         vmcb->cr0 = X86_CR0_NW | X86_CR0_CD | X86_CR0_ET;
         vmcb->cr3 = 0;
         vmcb->cr4 = 0;

         vmcb->rflags = 0x02;
+       vmcb->rsp = 0;

-       val = 0;
         if (sipi_vector == APIC_BSP_PSEUDO_SIPI) {
-               val = 0xfff0;
-               sipi_vector = 0xf0;
+               reset_addr = this_cell()->config->cpu_reset_address;
+
+               vmcb->rip = reset_addr & 0xffff;
+
+               vmcb->cs.selector = (reset_addr >> 4) & 0xf000;
+               vmcb->cs.base = reset_addr & ~0xffffL;
+       } else {
+               vmcb->rip = 0;
+
+               vmcb->cs.selector = sipi_vector << 8;
+               vmcb->cs.base = sipi_vector << 12;
         }
-       vmcb->rip = val;
-       vmcb->rsp = 0;

-       vmcb->cs.selector = sipi_vector << 8;
-       vmcb->cs.base = sipi_vector << 12;
         vmcb->cs.limit = 0xffff;
         vmcb->cs.access_rights = 0x009b;

diff --git a/hypervisor/arch/x86/vmx.c b/hypervisor/arch/x86/vmx.c
index 0ee944ff..a549f899 100644
--- a/hypervisor/arch/x86/vmx.c
+++ b/hypervisor/arch/x86/vmx.c
@@ -792,7 +792,7 @@ void __attribute__((noreturn)) vcpu_deactivate_vmm(void)

 void vcpu_vendor_reset(unsigned int sipi_vector)
 {
-       unsigned long val;
+       unsigned long reset_addr, val;
         bool ok = true;

         ok &= vmx_set_guest_cr(CR0_IDX, X86_CR0_NW | X86_CR0_CD | X86_CR0_ET);
@@ -803,18 +803,24 @@ void vcpu_vendor_reset(unsigned int sipi_vector)
         ok &= vmcs_write64(GUEST_RFLAGS, 0x02);
         ok &= vmcs_write64(GUEST_RSP, 0);

-       val = 0;
         if (sipi_vector == APIC_BSP_PSEUDO_SIPI) {
-               val = 0xfff0;
-               sipi_vector = 0xf0;
-
                 /* only cleared on hard reset */
                 ok &= vmcs_write64(GUEST_IA32_DEBUGCTL, 0);
+
+               reset_addr = this_cell()->config->cpu_reset_address;
+
+               ok &= vmcs_write64(GUEST_RIP, reset_addr & 0xffff);
+
+               ok &= vmcs_write16(GUEST_CS_SELECTOR,
+                                  (reset_addr >> 4) & 0xf000);
+               ok &= vmcs_write64(GUEST_CS_BASE, reset_addr & ~0xffffL);
+       } else {
+               ok &= vmcs_write64(GUEST_RIP, 0);
+
+               ok &= vmcs_write16(GUEST_CS_SELECTOR, sipi_vector << 8);
+               ok &= vmcs_write64(GUEST_CS_BASE, sipi_vector << 12);
         }
-       ok &= vmcs_write64(GUEST_RIP, val);

-       ok &= vmcs_write16(GUEST_CS_SELECTOR, sipi_vector << 8);
-       ok &= vmcs_write64(GUEST_CS_BASE, sipi_vector << 12);
         ok &= vmcs_write32(GUEST_CS_LIMIT, 0xffff);
         ok &= vmcs_write32(GUEST_CS_AR_BYTES, 0x0009b);

--
2.12.3

--
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to