qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Justin Terry (VM)" <juterry@microsoft.com>
Subject: [Qemu-devel] [PULL 05/20] target/i386: WHPX: set CPUID_EXT_HYPERVISOR bit
Date: Fri,  6 Apr 2018 19:11:06 +0200	[thread overview]
Message-ID: <1523034681-33787-6-git-send-email-pbonzini@redhat.com> (raw)
In-Reply-To: <1523034681-33787-1-git-send-email-pbonzini@redhat.com>

From: "Justin Terry (VM)" <juterry@microsoft.com>

Implements the CPUID trap for CPUID 1 to include the
CPUID_EXT_HYPERVISOR flag in the ECX results. This was preventing some
older linux kernels from booting when trying to access MSR's that dont
make sense when virtualized.

Signed-off-by: Justin Terry (VM) <juterry@microsoft.com>
Message-Id: <20180326170658.606-1-juterry@microsoft.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 target/i386/whpx-all.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 78 insertions(+), 1 deletion(-)

diff --git a/target/i386/whpx-all.c b/target/i386/whpx-all.c
index bf33d32..5843517 100644
--- a/target/i386/whpx-all.c
+++ b/target/i386/whpx-all.c
@@ -911,12 +911,62 @@ static int whpx_vcpu_run(CPUState *cpu)
             ret = 1;
             break;
 
+        case WHvRunVpExitReasonX64Cpuid: {
+            WHV_REGISTER_VALUE reg_values[5] = {0};
+            WHV_REGISTER_NAME reg_names[5];
+            UINT32 reg_count = 5;
+            UINT64 rip, rax, rcx, rdx, rbx;
+
+            rip = vcpu->exit_ctx.VpContext.Rip +
+                  vcpu->exit_ctx.VpContext.InstructionLength;
+            switch (vcpu->exit_ctx.CpuidAccess.Rax) {
+            case 1:
+                rax = vcpu->exit_ctx.CpuidAccess.DefaultResultRax;
+                /* Advertise that we are running on a hypervisor */
+                rcx =
+                    vcpu->exit_ctx.CpuidAccess.DefaultResultRcx |
+                    CPUID_EXT_HYPERVISOR;
+
+                rdx = vcpu->exit_ctx.CpuidAccess.DefaultResultRdx;
+                rbx = vcpu->exit_ctx.CpuidAccess.DefaultResultRbx;
+                break;
+            default:
+                rax = vcpu->exit_ctx.CpuidAccess.DefaultResultRax;
+                rcx = vcpu->exit_ctx.CpuidAccess.DefaultResultRcx;
+                rdx = vcpu->exit_ctx.CpuidAccess.DefaultResultRdx;
+                rbx = vcpu->exit_ctx.CpuidAccess.DefaultResultRbx;
+            }
+
+            reg_names[0] = WHvX64RegisterRip;
+            reg_names[1] = WHvX64RegisterRax;
+            reg_names[2] = WHvX64RegisterRcx;
+            reg_names[3] = WHvX64RegisterRdx;
+            reg_names[4] = WHvX64RegisterRbx;
+
+            reg_values[0].Reg64 = rip;
+            reg_values[1].Reg64 = rax;
+            reg_values[2].Reg64 = rcx;
+            reg_values[3].Reg64 = rdx;
+            reg_values[4].Reg64 = rbx;
+
+            hr = WHvSetVirtualProcessorRegisters(whpx->partition,
+                                                 cpu->cpu_index,
+                                                 reg_names,
+                                                 reg_count,
+                                                 reg_values);
+
+            if (FAILED(hr)) {
+                error_report("WHPX: Failed to set CpuidAccess state registers,"
+                             " hr=%08lx", hr);
+            }
+            ret = 0;
+            break;
+        }
         case WHvRunVpExitReasonNone:
         case WHvRunVpExitReasonUnrecoverableException:
         case WHvRunVpExitReasonInvalidVpRegisterValue:
         case WHvRunVpExitReasonUnsupportedFeature:
         case WHvRunVpExitReasonX64MsrAccess:
-        case WHvRunVpExitReasonX64Cpuid:
         case WHvRunVpExitReasonException:
         default:
             error_report("WHPX: Unexpected VP exit code %d",
@@ -1272,6 +1322,33 @@ static int whpx_accel_init(MachineState *ms)
         goto error;
     }
 
+    memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY));
+    prop.ExtendedVmExits.X64CpuidExit = 1;
+    hr = WHvSetPartitionProperty(whpx->partition,
+                                 WHvPartitionPropertyCodeExtendedVmExits,
+                                 &prop,
+                                 sizeof(WHV_PARTITION_PROPERTY));
+
+    if (FAILED(hr)) {
+        error_report("WHPX: Failed to enable partition extended X64CpuidExit"
+                     " hr=%08lx", hr);
+        ret = -EINVAL;
+        goto error;
+    }
+
+    UINT32 cpuidExitList[] = {1};
+    hr = WHvSetPartitionProperty(whpx->partition,
+                                 WHvPartitionPropertyCodeCpuidExitList,
+                                 cpuidExitList,
+                                 RTL_NUMBER_OF(cpuidExitList) * sizeof(UINT32));
+
+    if (FAILED(hr)) {
+        error_report("WHPX: Failed to set partition CpuidExitList hr=%08lx",
+                     hr);
+        ret = -EINVAL;
+        goto error;
+    }
+
     hr = WHvSetupPartition(whpx->partition);
     if (FAILED(hr)) {
         error_report("WHPX: Failed to setup partition, hr=%08lx", hr);
-- 
1.8.3.1

  parent reply	other threads:[~2018-04-06 17:11 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-06 17:11 [Qemu-devel] [PULL 00/20] Miscellaneous patches for QEMU 2.12-rc Paolo Bonzini
2018-04-06 17:11 ` [Qemu-devel] [PULL 01/20] sys_membarrier: fix up include directives Paolo Bonzini
2018-04-06 17:44   ` Eric Blake
2018-04-06 17:11 ` [Qemu-devel] [PULL 02/20] target/i386: Fix andn instruction Paolo Bonzini
2018-04-06 17:11 ` [Qemu-devel] [PULL 03/20] scripts/checkpatch.pl: Bug fix Paolo Bonzini
2018-04-06 17:11 ` [Qemu-devel] [PULL 04/20] memfd: fix vhost-user-test on non-memfd capable host Paolo Bonzini
2018-04-06 17:11 ` Paolo Bonzini [this message]
2018-04-06 17:11 ` [Qemu-devel] [PULL 06/20] i386/hyperv: add hv-frequencies cpu property Paolo Bonzini
2018-04-06 17:11 ` [Qemu-devel] [PULL 07/20] i386/hyperv: error out if features requested but unsupported Paolo Bonzini
2018-04-06 17:11 ` [Qemu-devel] [PULL 08/20] configure: Add missing configure options to help text Paolo Bonzini
2018-04-06 17:11 ` [Qemu-devel] [PULL 09/20] scsi-disk: Don't enlarge min_io_size to max_io_size Paolo Bonzini
2018-04-06 17:11 ` [Qemu-devel] [PULL 10/20] scsi-disk: allow customizing the SCSI version Paolo Bonzini
2018-04-06 17:11 ` [Qemu-devel] [PULL 11/20] hw/scsi: support SCSI-2 passthrough without PI Paolo Bonzini
2018-04-06 17:11 ` [Qemu-devel] [PULL 12/20] hw/dma/i82374: Avoid double creation of the 82374 controller Paolo Bonzini
2018-04-06 17:11 ` [Qemu-devel] [PULL 13/20] kvmclock: fix clock_is_reliable on migration from QEMU < 2.9 Paolo Bonzini
2018-04-06 17:11 ` [Qemu-devel] [PULL 14/20] virtio-serial: fix heapover-flow Paolo Bonzini
2018-04-06 17:11 ` [Qemu-devel] [PULL 15/20] qemu-pr-helper: Daemonize before dropping privileges Paolo Bonzini
2018-04-06 17:11 ` [Qemu-devel] [PULL 16/20] qemu-pr-helper: Write pidfile more often Paolo Bonzini
2018-04-06 17:11 ` [Qemu-devel] [PULL 17/20] device-crash-test: Remove fixed isa-fdc entry Paolo Bonzini
2018-04-06 17:11 ` [Qemu-devel] [PULL 18/20] dump: Fix build with newer gcc Paolo Bonzini
2018-04-06 17:11 ` [Qemu-devel] [PULL 19/20] maint: Add .mailmap entries for patches claiming list authorship Paolo Bonzini
2018-04-06 17:11 ` [Qemu-devel] [PULL 20/20] Add missing bit for SSE instr in VEX decoding Paolo Bonzini
2018-04-09  9:20 ` [Qemu-devel] [PULL 00/20] Miscellaneous patches for QEMU 2.12-rc Peter Maydell
2018-04-09 10:57   ` 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=1523034681-33787-6-git-send-email-pbonzini@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=juterry@microsoft.com \
    --cc=qemu-devel@nongnu.org \
    /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;
as well as URLs for NNTP newsgroup(s).