Skip to contentSkip to conversation

whpx: i386: small random fixes

PATCH Superseded Mohamed Mediouni 1 participant 10 messages Mar 3 Arm/Amlogic Meson SoC support

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v3 cover whpx: i386: small random fixes

Also has a small arm64 patch for enabling Hyper-V enlightenments if asked for, which depends on another (common code) patch in the series

v3:

- Added HVF build fix from Pierrick Bouvier (oops... forgot to have it copied over from the test machine earlier...)
- Also added a fix for "whpx: make enlightenments configurable" highlighted with an error from GCC. Clang did not catch this...

Mohamed Mediouni (8):
Revert "elf-ops.h: Map into memory the ELF to load"
whpx: i386: apic: bring closer to MSHV code path
whpx: i386: do not enable nested virt when kernel-irqchip=off target/i386: emulate: LA57 fix
whpx: i386: enable some more enlightenments
whpx: make Hyper-V enlightenments configurable
whpx: arm64: enable enlightenments if asked for
whpx: i386: remove SIPI trapping

Pierrick Bouvier (1):
target/i386/hvf/hvf.c: fix compilation

 accel/whpx/whpx-common.c       |  44 +++++
 hw/intc/apic.c                 |   9 ++
 include/hw/elf_ops.h.inc       |  71 +++-----
 include/system/whpx-internal.h |  14 +-
 target/arm/whpx/whpx-all.c     |  37 +++++
 target/i386/cpu-apic.c         |   3 -
 target/i386/emulate/x86_mmu.c  |   2 +-
 target/i386/hvf/hvf.c          |  14 +-
 target/i386/whpx/irq.c         | 153 ++++++++++++++++++
 target/i386/whpx/irq.h         |  10 ++
 target/i386/whpx/meson.build   |   2 +-
 target/i386/whpx/whpx-all.c    | 139 ++--------------
 target/i386/whpx/whpx-apic.c   | 286 ---------------------------------
 13 files changed, 317 insertions(+), 467 deletions(-)
 create mode 100644 target/i386/whpx/irq.c
 create mode 100644 target/i386/whpx/irq.h
 delete mode 100644 target/i386/whpx/whpx-apic.c
Signature · 1 line
2.50.1 (Apple Git-155)
#1 lore raw

PATCH v3 1/9 target/i386/hvf/hvf.c: fix compilation

From: Pierrick Bouvier <[email protected]>

../target/i386/hvf/hvf.c:476:31: error: use of undeclared identifier 'cpu'
476 | X86CPU *x86_cpu = X86_CPU(cpu);
| ^
../target/i386/hvf/hvf.c:479:24: error: use of undeclared identifier 'cpu'
479 | env->cr[0] = rvmcs(cpu->accel->fd, VMCS_GUEST_CR0);
| ^
../target/i386/hvf/hvf.c:480:24: error: use of undeclared identifier 'cpu'
480 | env->cr[3] = rvmcs(cpu->accel->fd, VMCS_GUEST_CR3);
| ^
../target/i386/hvf/hvf.c:481:23: error: use of undeclared identifier 'cpu'
481 | env->cr[2] = rreg(cpu->accel->fd, HV_X86_CR2);
| ^
../target/i386/hvf/hvf.c:486:31: error: use of undeclared identifier 'cpu'
486 | X86CPU *x86_cpu = X86_CPU(cpu);
| ^
../target/i386/hvf/hvf.c:489:11: error: use of undeclared identifier 'cpu'
489 | wvmcs(cpu->accel->fd, VMCS_GUEST_CR0, env->cr[0]);
| ^
../target/i386/hvf/hvf.c:490:11: error: use of undeclared identifier 'cpu'
490 | wvmcs(cpu->accel->fd, VMCS_GUEST_CR3, env->cr[3]);
| ^
7 errors generated.

---
 target/i386/hvf/hvf.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
target/i386/hvf/hvf.c +7 -7
index a70f8461b0..c0d028b147 100644
@@ -472,21 +472,21 @@ static void hvf_cpu_x86_cpuid(CPUX86State *env, uint32_t index, uint32_t count,
 
 static void hvf_load_crs(CPUState *cs)
 {
-    X86CPU *x86_cpu = X86_CPU(cpu);
+    X86CPU *x86_cpu = X86_CPU(cs);
     CPUX86State *env = &x86_cpu->env;
 
-    env->cr[0] = rvmcs(cpu->accel->fd, VMCS_GUEST_CR0);
-    env->cr[3] = rvmcs(cpu->accel->fd, VMCS_GUEST_CR3);
-    env->cr[2] = rreg(cpu->accel->fd, HV_X86_CR2);
+    env->cr[0] = rvmcs(cs->accel->fd, VMCS_GUEST_CR0);
+    env->cr[3] = rvmcs(cs->accel->fd, VMCS_GUEST_CR3);
+    env->cr[2] = rreg(cs->accel->fd, HV_X86_CR2);
 }
 
 static void hvf_save_crs(CPUState *cs)
 {
-    X86CPU *x86_cpu = X86_CPU(cpu);
+    X86CPU *x86_cpu = X86_CPU(cs);
     CPUX86State *env = &x86_cpu->env;
 
-    wvmcs(cpu->accel->fd, VMCS_GUEST_CR0, env->cr[0]);
-    wvmcs(cpu->accel->fd, VMCS_GUEST_CR3, env->cr[3]);
+    wvmcs(cs->accel->fd, VMCS_GUEST_CR0, env->cr[0]);
+    wvmcs(cs->accel->fd, VMCS_GUEST_CR3, env->cr[3]);
     wreg(cs->accel->fd, HV_X86_CR2, env->cr[2]);
 }
 
Signature · 1 line
2.50.1 (Apple Git-155)
#2 lore raw

PATCH v3 2/9 Revert "elf-ops.h: Map into memory the ELF to load"

In reply to Mohamed Mediouni

This reverts commit 816b9fe450220e19acb91a0ce4a8ade7000648d1.

---
 include/hw/elf_ops.h.inc | 71 +++++++++++++++-------------------------
 1 file changed, 26 insertions(+), 45 deletions(-)
include/hw/elf_ops.h.inc +26 -45
index 9c35d1b9da..bcf484b938 100644
@@ -325,11 +325,9 @@ static ssize_t glue(load_elf, SZ)(const char *name, int fd,
 {
     struct elfhdr ehdr;
     struct elf_phdr *phdr = NULL, *ph;
-    int size, i;
-    ssize_t total_size;
-    elf_word mem_size, file_size, data_offset;
+    int size, i, total_size;
+    elf_word mem_size, file_size;
     uint64_t addr, low = (uint64_t)-1, high = 0;
-    GMappedFile *mapped_file = NULL;
     uint8_t *data = NULL;
     ssize_t ret = ELF_LOAD_FAILED;
 
@@ -409,32 +407,20 @@ static ssize_t glue(load_elf, SZ)(const char *name, int fd,
         }
     }
 
-    /*
-     * Since we want to be able to modify the mapped buffer, we set the
-     * 'writable' parameter to 'true'. Modifications to the buffer are not
-     * written back to the file.
-     */
-    mapped_file = g_mapped_file_new_from_fd(fd, true, NULL);
-    if (!mapped_file) {
-        goto fail;
-    }
-
     total_size = 0;
     for(i = 0; i < ehdr.e_phnum; i++) {
         ph = &phdr[i];
         if (ph->p_type == PT_LOAD) {
             mem_size = ph->p_memsz; /* Size of the ROM */
             file_size = ph->p_filesz; /* Size of the allocated data */
-            data_offset = ph->p_offset; /* Offset where the data is located */
-
-            if (file_size > 0) {
-                if (g_mapped_file_get_length(mapped_file) <
-                    file_size + data_offset) {
+            data = g_malloc0(file_size);
+            if (ph->p_filesz > 0) {
+                if (lseek(fd, ph->p_offset, SEEK_SET) < 0) {
+                    goto fail;
+                }
+                if (read(fd, data, file_size) != file_size) {
                     goto fail;
                 }
-
-                data = (uint8_t *)g_mapped_file_get_contents(mapped_file);
-                data += data_offset;
             }
 
             /* The ELF spec is somewhat vague about the purpose of the
@@ -530,23 +516,22 @@ static ssize_t glue(load_elf, SZ)(const char *name, int fd,
                 *pentry = ehdr.e_entry - ph->p_vaddr + ph->p_paddr;
             }
 
-            /* Some ELF files really do have segments of zero size;
-             * just ignore them rather than trying to create empty
-             * ROM blobs, because the zero-length blob can falsely
-             * trigger the overlapping-ROM-blobs check.
-             */
-            if (mem_size != 0) {
+            if (mem_size == 0) {
+                /* Some ELF files really do have segments of zero size;
+                 * just ignore them rather than trying to create empty
+                 * ROM blobs, because the zero-length blob can falsely
+                 * trigger the overlapping-ROM-blobs check.
+                 */
+                g_free(data);
+            } else {
                 if (load_rom) {
                     g_autofree char *label =
                         g_strdup_printf("%s ELF program header segment %d",
                                         name, i);
 
-                    /*
-                     * rom_add_elf_program() takes its own reference to
-                     * 'mapped_file'.
-                     */
-                    rom_add_elf_program(label, mapped_file, data, file_size,
-                                        mem_size, addr, as);
+                    /* rom_add_elf_program() seize the ownership of 'data' */
+                    rom_add_elf_program(label, NULL, data, file_size, mem_size,
+                                        addr, as);
                 } else {
                     MemTxResult res;
 
@@ -584,16 +569,14 @@ static ssize_t glue(load_elf, SZ)(const char *name, int fd,
             struct elf_note *nhdr = NULL;
 
             file_size = ph->p_filesz; /* Size of the range of ELF notes */
-            data_offset = ph->p_offset; /* Offset where the notes are located */
-
-            if (file_size > 0) {
-                if (g_mapped_file_get_length(mapped_file) <
-                    file_size + data_offset) {
+            data = g_malloc0(file_size);
+            if (ph->p_filesz > 0) {
+                if (lseek(fd, ph->p_offset, SEEK_SET) < 0) {
+                    goto fail;
+                }
+                if (read(fd, data, file_size) != file_size) {
                     goto fail;
                 }
-
-                data = (uint8_t *)g_mapped_file_get_contents(mapped_file);
-                data += data_offset;
             }
 
             /*
@@ -607,6 +590,7 @@ static ssize_t glue(load_elf, SZ)(const char *name, int fd,
             if (nhdr != NULL) {
                 elf_note_fn((void *)nhdr, (void *)&ph->p_align, SZ == 64);
             }
+            g_free(data);
             data = NULL;
         }
     }
@@ -619,9 +603,6 @@ static ssize_t glue(load_elf, SZ)(const char *name, int fd,
     }
     ret = total_size;
  fail:
-    if (mapped_file) {
-        g_mapped_file_unref(mapped_file);
-    }
     g_free(phdr);
     return ret;
 }
Signature · 1 line
2.50.1 (Apple Git-155)
#3 lore raw

PATCH v3 3/9 whpx: i386: apic: bring closer to MSHV code path

In reply to Mohamed Mediouni

MSHV doesn't have a dedicated apic_type and uses the common class. Make WHPX do the same thing.

As VM save/restore isn't currently supported anyway, this doesn't break functionality.

---
 hw/intc/apic.c                 |   9 ++
 include/system/whpx-internal.h |  10 +-
 target/i386/cpu-apic.c         |   3 -
 target/i386/whpx/irq.c         | 153 ++++++++++++++++++
 target/i386/whpx/irq.h         |  10 ++
 target/i386/whpx/meson.build   |   2 +-
 target/i386/whpx/whpx-all.c    |  17 +-
 target/i386/whpx/whpx-apic.c   | 286 ---------------------------------
 8 files changed, 183 insertions(+), 307 deletions(-)
 create mode 100644 target/i386/whpx/irq.c
 create mode 100644 target/i386/whpx/irq.h
 delete mode 100644 target/i386/whpx/whpx-apic.c
hw/intc/apic.c +9 -0
index 8766ed00b9..4920043063 100644
@@ -28,6 +28,8 @@
 #include "qemu/host-utils.h"
 #include "system/kvm.h"
 #include "system/mshv.h"
+#include "system/whpx.h"
+#include "whpx/irq.h"
 #include "trace.h"
 #include "hw/i386/apic-msidef.h"
 #include "exec/cpu-common.h"
@@ -915,6 +917,13 @@ static void apic_send_msi(MSIMessage *msi)
                                dest_mode, trigger_mode);
         return;
     }
+#endif
+#ifdef CONFIG_WHPX
+    if (whpx_enabled() && whpx_irqchip_in_kernel()) {
+        whpx_request_interrupt(delivery, vector, dest,
+                               dest_mode, trigger_mode);
+        return;
+    }
 #endif
     apic_deliver_irq(dest, dest_mode, delivery, vector, trigger_mode);
 }
include/system/whpx-internal.h +8 -2
index 7a1c9871f1..e7b915ccbf 100644
@@ -4,7 +4,6 @@
 
 #include <windows.h>
 #include <winhvplatform.h>
-#include "hw/i386/apic.h"
 #include "exec/vaddr.h"
 
 typedef enum WhpxBreakpointState {
@@ -45,7 +44,6 @@ struct whpx_state {
 };
 
 extern struct whpx_state whpx_global;
-void whpx_apic_get(APICCommonState *s);
 
 #define WHV_E_UNKNOWN_CAPABILITY 0x80370300L
 
@@ -85,6 +83,14 @@ void whpx_apic_get(APICCommonState *s);
          UINT32 StateSize)) \
   X(HRESULT, WHvResetPartition, \
         (WHV_PARTITION_HANDLE Partition)) \
+  X(HRESULT, WHvGetVirtualProcessorState, \
+        (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, \
+        WHV_VIRTUAL_PROCESSOR_STATE_TYPE StateType, PVOID Buffer, \
+        UINT32 BufferSizeInBytes, UINT32 *BytesWritten)) \
+  X(HRESULT, WHvSetVirtualProcessorState, \
+        (WHV_PARTITION_HANDLE Partition, UINT32 VpIndex, \
+        WHV_VIRTUAL_PROCESSOR_STATE_TYPE StateType, PVOID Buffer, \
+        UINT32 BufferSizeInBytes)) \
 
 #define WHP_DEFINE_TYPE(return_type, function_name, signature) \
     typedef return_type (WINAPI *function_name ## _t) signature;
target/i386/cpu-apic.c +0 -3
index eaa10ad2a3..77073ad455 100644
@@ -33,10 +33,7 @@ APICCommonClass *apic_get_class(Error **errp)
         apic_type = "kvm-apic";
     } else if (xen_enabled()) {
         apic_type = "xen-apic";
-    } else if (whpx_irqchip_in_kernel()) {
-        apic_type = "whpx-apic";
     }
-
     return APIC_COMMON_CLASS(object_class_by_name(apic_type));
 }
 
target/i386/whpx/irq.c new file +153 -0

153 lines not on this page · raw message

target/i386/whpx/irq.h new file +10 -0
new file mode 100644
index 0000000000..02debc9e85
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef QEMU_X86_WHPX_H
+#define QEMU_X86_WHPX_H
+
+int whpx_request_interrupt(uint32_t interrupt_type, uint32_t vector,
+                           uint32_t vp_index, bool logical_dest_mode,
+                           bool level_triggered);
+
+int whpx_set_lint(CPUState* cpu);
+#endif /* QEMU_X86_WHPX_H */
target/i386/whpx/meson.build +1 -1
index c3aaaff9fd..5c13274b77 100644
@@ -1,4 +1,4 @@
 i386_system_ss.add(when: 'CONFIG_WHPX', if_true: files(
   'whpx-all.c',
-  'whpx-apic.c',
+  'irq.c'
 ))
target/i386/whpx/whpx-all.c +2 -15
index c172e86886..8dd6f68ff9 100644
@@ -36,6 +36,7 @@
 #include "system/whpx-accel-ops.h"
 #include "system/whpx-all.h"
 #include "system/whpx-common.h"
+#include "whpx/irq.h"
 
 #include "emulate/x86_decode.h"
 #include "emulate/x86_emu.h"
@@ -390,6 +391,7 @@ void whpx_set_registers(CPUState *cpu, WHPXStateLevel level)
      */
     if (level >= WHPX_LEVEL_RESET_STATE) {
         whpx_set_tsc(cpu);
+        whpx_set_lint(cpu);
     }
 
     memset(&vcxt, 0, sizeof(struct whpx_register_set));
@@ -621,17 +623,6 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel level)
                      hr);
     }
 
-    if (level > WHPX_LEVEL_FAST_RUNTIME_STATE && whpx_irqchip_in_kernel()) {
-        /*
-         * Fetch the TPR value from the emulated APIC. It may get overwritten
-         * below with the value from CR8 returned by
-         * WHvGetVirtualProcessorRegisters().
-         */
-        whpx_apic_get(x86_cpu->apic_state);
-        vcpu->tpr = whpx_apic_tpr_to_cr8(
-            cpu_get_apic_tpr(x86_cpu->apic_state));
-    }
-
     idx = 0;
 
     /* Indexes for first 16 registers match between HV and QEMU definitions */
@@ -764,10 +755,6 @@ void whpx_get_registers(CPUState *cpu, WHPXStateLevel level)
 
     assert(idx == RTL_NUMBER_OF(whpx_register_names));
 
-    if (level > WHPX_LEVEL_FAST_RUNTIME_STATE && whpx_irqchip_in_kernel()) {
-        whpx_apic_get(x86_cpu->apic_state);
-    }
-
     x86_update_hflags(env);
 }
 
target/i386/whpx/whpx-apic.c deleted +0 -286

286 lines not on this page · raw message

Signature · 1 line
2.50.1 (Apple Git-155)
#4 lore raw

PATCH v3 4/9 whpx: i386: do not enable nested virt when kernel-irqchip=off

In reply to Mohamed Mediouni

This combination is not allowed as of build 26300.7939 and results in:

qemu-system-x86_64.exe: WHPX: Failed to setup partition, hr=c0350005 qemu-system-x86_64.exe: failed to initialize whpx: Invalid argument

---
 target/i386/whpx/whpx-all.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/whpx/whpx-all.c +1 -1
index 8dd6f68ff9..4afcbbae25 100644
@@ -2147,7 +2147,7 @@ int whpx_accel_init(AccelState *as, MachineState *ms)
         goto error;
     }
 
-    if (processor_features.Bank1.NestedVirtSupport) {
+    if (whpx_irqchip_in_kernel() && processor_features.Bank1.NestedVirtSupport) {
         memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY));
         prop.NestedVirtualization = 1;
         hr = whp_dispatch.WHvSetPartitionProperty(
Signature · 1 line
2.50.1 (Apple Git-155)
#5 lore raw

PATCH v3 5/9 target/i386: emulate: LA57 fix

In reply to Mohamed Mediouni

Seen on a Sapphire Rapids box with LA57.

---
 target/i386/emulate/x86_mmu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/emulate/x86_mmu.c +1 -1
index 8261ca1635..4e39bae025 100644
@@ -56,7 +56,7 @@ static bool is_user(CPUState *cpu)
 struct gpt_translation {
     target_ulong  gva;
     uint64_t gpa;
-    uint64_t pte[5];
+    uint64_t pte[6];
 };
 
 static int gpt_top_level(CPUState *cpu, bool pae)
Signature · 1 line
2.50.1 (Apple Git-155)
#6 lore raw

PATCH v3 6/9 whpx: i386: enable some more enlightenments

In reply to Mohamed Mediouni
---
 target/i386/whpx/whpx-all.c | 3 +++
 1 file changed, 3 insertions(+)
target/i386/whpx/whpx-all.c +3 -0
index 4afcbbae25..915d79152e 100644
@@ -2201,9 +2201,12 @@ int whpx_accel_init(AccelState *as, MachineState *ms)
 
     synthetic_features.Bank0.HypervisorPresent = 1;
     synthetic_features.Bank0.Hv1 = 1;
+    synthetic_features.Bank0.AccessVpRunTimeReg = 1;
     synthetic_features.Bank0.AccessPartitionReferenceCounter = 1;
     synthetic_features.Bank0.AccessPartitionReferenceTsc = 1;
+    synthetic_features.Bank0.AccessHypercallRegs = 1;
     synthetic_features.Bank0.AccessFrequencyRegs = 1;
+    synthetic_features.Bank0.EnableExtendedGvaRangesForFlushVirtualAddressList = 1;
     synthetic_features.Bank0.AccessVpIndex = 1;
     synthetic_features.Bank0.AccessHypercallRegs = 1;
     synthetic_features.Bank0.TbFlushHypercalls = 1;
Signature · 1 line
2.50.1 (Apple Git-155)
#7 lore raw

PATCH v3 7/9 whpx: make Hyper-V enlightenments configurable

In reply to Mohamed Mediouni

Have them be a machine option instead of a CPU one, to have something available, even if not ideal...

The existing Hyper-V enlightenments configuration mechanism is part of per-CPU configuration, which happens too late for this.

---
 accel/whpx/whpx-common.c       | 44 ++++++++++++++++++++++++++++++++++
 include/system/whpx-internal.h |  4 ++++
 target/i386/whpx/whpx-all.c    | 20 +++++++++-------
 3 files changed, 59 insertions(+), 9 deletions(-)
accel/whpx/whpx-common.c +44 -0
index 4863fc8663..dae9ff0800 100644
@@ -25,6 +25,7 @@
 #include "qapi/qapi-visit-common.h"
 #include "migration/blocker.h"
 #include "accel/accel-cpu-target.h"
+#include "qemu/target-info.h"
 #include <winerror.h>
 
 #include "system/whpx-internal.h"
@@ -470,6 +471,41 @@ static void whpx_set_kernel_irqchip(Object *obj, Visitor *v,
     }
 }
 
+static void whpx_set_hyperv(Object *obj, Visitor *v,
+                                   const char *name, void *opaque,
+                                   Error **errp)
+{
+    struct whpx_state *whpx = &whpx_global;
+    OnOffAuto mode;
+
+    if (!visit_type_OnOffAuto(v, name, &mode, errp)) {
+        return;
+    }
+
+    switch (mode) {
+    case ON_OFF_AUTO_ON:
+        whpx->hyperv_enlightenments_allowed = true;
+        whpx->hyperv_enlightenments_required = true;
+        break;
+
+    case ON_OFF_AUTO_OFF:
+        whpx->hyperv_enlightenments_allowed = false;
+        whpx->hyperv_enlightenments_required = false;
+        break;
+
+    case ON_OFF_AUTO_AUTO:
+        whpx->hyperv_enlightenments_allowed = true;
+        whpx->hyperv_enlightenments_required = false;
+        break;
+    default:
+        /*
+         * The value was checked in visit_type_OnOffAuto() above. If
+         * we get here, then something is wrong in QEMU.
+         */
+        abort();
+    }
+}
+
 static void whpx_cpu_accel_class_init(ObjectClass *oc, const void *data)
 {
     AccelCPUClass *acc = ACCEL_CPU_CLASS(oc);
@@ -498,6 +534,11 @@ static void whpx_accel_class_init(ObjectClass *oc, const void *data)
         NULL, NULL);
     object_class_property_set_description(oc, "kernel-irqchip",
         "Configure WHPX in-kernel irqchip");
+    object_class_property_add(oc, "hyperv", "OnOffAuto",
+        NULL, whpx_set_hyperv,
+        NULL, NULL);
+    object_class_property_set_description(oc, "hyperv",
+        "Configure Hyper-V enlightenments");
 }
 
 static void whpx_accel_instance_init(Object *obj)
@@ -507,6 +548,9 @@ static void whpx_accel_instance_init(Object *obj)
     memset(whpx, 0, sizeof(struct whpx_state));
     /* Turn on kernel-irqchip, by default */
     whpx->kernel_irqchip_allowed = true;
+
+    whpx->hyperv_enlightenments_allowed = true;
+    whpx->hyperv_enlightenments_required = false;
 }
 
 static const TypeInfo whpx_accel_type = {
include/system/whpx-internal.h +4 -0
index e7b915ccbf..abea3ddeee 100644
@@ -41,6 +41,10 @@ struct whpx_state {
 
     bool kernel_irqchip_allowed;
     bool kernel_irqchip_required;
+
+    bool hyperv_enlightenments_allowed;
+    bool hyperv_enlightenments_required;
+
 };
 
 extern struct whpx_state whpx_global;
target/i386/whpx/whpx-all.c +11 -9
index 915d79152e..4968a5a3e4 100644
@@ -2219,15 +2219,17 @@ int whpx_accel_init(AccelState *as, MachineState *ms)
         synthetic_features.Bank0.DirectSyntheticTimers = 1;
     }
 
-    hr = whp_dispatch.WHvSetPartitionProperty(
-            whpx->partition,
-            WHvPartitionPropertyCodeSyntheticProcessorFeaturesBanks,
-            &synthetic_features,
-            sizeof(WHV_SYNTHETIC_PROCESSOR_FEATURES_BANKS));
-    if (FAILED(hr)) {
-        error_report("WHPX: Failed to set synthetic features, hr=%08lx", hr);
-        ret = -EINVAL;
-        goto error;
+    if (whpx->hyperv_enlightenments_allowed) {
+        hr = whp_dispatch.WHvSetPartitionProperty(
+                whpx->partition,
+                WHvPartitionPropertyCodeSyntheticProcessorFeaturesBanks,
+                &synthetic_features,
+                sizeof(WHV_SYNTHETIC_PROCESSOR_FEATURES_BANKS));
+        if (FAILED(hr)) {
+            error_report("WHPX: Failed to set synthetic features, hr=%08lx", hr);
+            ret = -EINVAL;
+            goto error;
+        }
     }
 
     /* Register for MSR and CPUID exits */
Signature · 1 line
2.50.1 (Apple Git-155)
#8 lore raw

PATCH v3 8/9 whpx: arm64: enable enlightenments if asked for

In reply to Mohamed Mediouni
---
 target/arm/whpx/whpx-all.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
target/arm/whpx/whpx-all.c +37 -0
index bb94eac7bf..9983d59a38 100644
@@ -947,6 +947,43 @@ int whpx_accel_init(AccelState *as, MachineState *ms)
         goto error;
     }
 
+    /* Enable synthetic processor features */
+    WHV_SYNTHETIC_PROCESSOR_FEATURES_BANKS synthetic_features;
+    memset(&synthetic_features, 0, sizeof(WHV_SYNTHETIC_PROCESSOR_FEATURES_BANKS));
+    synthetic_features.BanksCount = 1;
+
+    synthetic_features.Bank0.HypervisorPresent = 1;
+    synthetic_features.Bank0.Hv1 = 1;
+    synthetic_features.Bank0.AccessVpRunTimeReg = 1;
+    synthetic_features.Bank0.AccessPartitionReferenceCounter = 1;
+    synthetic_features.Bank0.AccessPartitionReferenceTsc = 1;
+    synthetic_features.Bank0.AccessHypercallRegs = 1;
+    synthetic_features.Bank0.AccessVpIndex = 1;
+    synthetic_features.Bank0.AccessHypercallRegs = 1;
+    synthetic_features.Bank0.TbFlushHypercalls = 1;
+    synthetic_features.Bank0.AccessSynicRegs = 1;
+    synthetic_features.Bank0.AccessSyntheticTimerRegs = 1;
+    synthetic_features.Bank0.AccessIntrCtrlRegs = 1;
+    synthetic_features.Bank0.SyntheticClusterIpi = 1;
+    synthetic_features.Bank0.DirectSyntheticTimers = 1;
+
+    /*
+     * On ARM64, have enlightenments off by default 
+     * as they're not needed for performance.
+     */
+    if (whpx->hyperv_enlightenments_required) {
+        hr = whp_dispatch.WHvSetPartitionProperty(
+                whpx->partition,
+                WHvPartitionPropertyCodeSyntheticProcessorFeaturesBanks,
+                &synthetic_features,
+                sizeof(WHV_SYNTHETIC_PROCESSOR_FEATURES_BANKS));
+        if (FAILED(hr)) {
+            error_report("WHPX: Failed to set synthetic features, hr=%08lx", hr);
+            ret = -EINVAL;
+            goto error;
+        }
+    }
+
     hr = whp_dispatch.WHvSetupPartition(whpx->partition);
     if (FAILED(hr)) {
         error_report("WHPX: Failed to setup partition, hr=%08lx", hr);
Signature · 1 line
2.50.1 (Apple Git-155)
#9 lore raw

PATCH v3 9/9 whpx: i386: remove SIPI trapping

In reply to Mohamed Mediouni

The implementation in Hyper-V works fine and the code currently present doesn't handle x2APIC correctly anyway, so remove it and use the implementation in Hyper-V.

---
 target/i386/whpx/whpx-all.c | 97 -------------------------------------
 1 file changed, 97 deletions(-)
target/i386/whpx/whpx-all.c +0 -97
index 4968a5a3e4..fa78218f80 100644
@@ -1679,100 +1679,6 @@ int whpx_vcpu_run(CPUState *cpu)
             ret = whpx_handle_halt(cpu);
             break;
 
-        case WHvRunVpExitReasonX64ApicInitSipiTrap: {
-            WHV_INTERRUPT_CONTROL ipi = {0};
-            uint64_t icr = vcpu->exit_ctx.ApicInitSipi.ApicIcr;
-            uint32_t delivery_mode =
-                (icr & APIC_ICR_DELIV_MOD) >> APIC_ICR_DELIV_MOD_SHIFT;
-            int dest_shorthand =
-                (icr & APIC_ICR_DEST_SHORT) >> APIC_ICR_DEST_SHORT_SHIFT;
-            bool broadcast = false;
-            bool include_self = false;
-            uint32_t i;
-
-            /* We only registered for INIT and SIPI exits. */
-            if ((delivery_mode != APIC_DM_INIT) &&
-                (delivery_mode != APIC_DM_SIPI)) {
-                error_report(
-                    "WHPX: Unexpected APIC exit that is not a INIT or SIPI");
-                break;
-            }
-
-            if (delivery_mode == APIC_DM_INIT) {
-                ipi.Type = WHvX64InterruptTypeInit;
-            } else {
-                ipi.Type = WHvX64InterruptTypeSipi;
-            }
-
-            ipi.DestinationMode =
-                ((icr & APIC_ICR_DEST_MOD) >> APIC_ICR_DEST_MOD_SHIFT) ?
-                    WHvX64InterruptDestinationModeLogical :
-                    WHvX64InterruptDestinationModePhysical;
-
-            ipi.TriggerMode =
-                ((icr & APIC_ICR_TRIGGER_MOD) >> APIC_ICR_TRIGGER_MOD_SHIFT) ?
-                    WHvX64InterruptTriggerModeLevel :
-                    WHvX64InterruptTriggerModeEdge;
-
-            ipi.Vector = icr & APIC_VECTOR_MASK;
-            switch (dest_shorthand) {
-            /* no shorthand. Bits 56-63 contain the destination. */
-            case 0:
-                ipi.Destination = (icr >> 56) & APIC_VECTOR_MASK;
-                hr = whp_dispatch.WHvRequestInterrupt(whpx->partition,
-                        &ipi, sizeof(ipi));
-                if (FAILED(hr)) {
-                    error_report("WHPX: Failed to request interrupt  hr=%08lx",
-                        hr);
-                }
-
-                break;
-
-            /* self */
-            case 1:
-                include_self = true;
-                break;
-
-            /* broadcast, including self */
-            case 2:
-                broadcast = true;
-                include_self = true;
-                break;
-
-            /* broadcast, excluding self */
-            case 3:
-                broadcast = true;
-                break;
-            }
-
-            if (!broadcast && !include_self) {
-                break;
-            }
-
-            for (i = 0; i <= max_vcpu_index; i++) {
-                if (i == cpu->cpu_index && !include_self) {
-                    continue;
-                }
-
-                /*
-                 * Assuming that APIC Ids are identity mapped since
-                 * WHvX64RegisterApicId & WHvX64RegisterInitialApicId registers
-                 * are not handled yet and the hypervisor doesn't allow the
-                 * guest to modify the APIC ID.
-                 */
-                ipi.Destination = i;
-                hr = whp_dispatch.WHvRequestInterrupt(whpx->partition,
-                        &ipi, sizeof(ipi));
-                if (FAILED(hr)) {
-                    error_report(
-                        "WHPX: Failed to request SIPI for %d,  hr=%08lx",
-                        i, hr);
-                }
-            }
-
-            break;
-        }
-
         case WHvRunVpExitReasonCanceled:
             if (exclusive_step_mode != WHPX_STEP_NONE) {
                 /*
@@ -2236,9 +2142,6 @@ int whpx_accel_init(AccelState *as, MachineState *ms)
     memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY));
     prop.ExtendedVmExits.X64MsrExit = 1;
     prop.ExtendedVmExits.ExceptionExit = 1;
-    if (whpx_irqchip_in_kernel()) {
-        prop.ExtendedVmExits.X64ApicInitSipiExitTrap = 1;
-    }
 
     hr = whp_dispatch.WHvSetPartitionProperty(
             whpx->partition,
Signature · 1 line
2.50.1 (Apple Git-155)