From nobody Fri Dec 19 08:11:50 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530218139659386.63781692833004; Thu, 28 Jun 2018 13:35:39 -0700 (PDT) Received: from localhost ([::1]:38437 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYddi-0006jn-TO for importer@patchew.org; Thu, 28 Jun 2018 16:35:38 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38317) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fYdAy-0007ce-7m for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fYdAx-0000y1-7v for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:56 -0400 Received: from mail-wr0-x242.google.com ([2a00:1450:400c:c0c::242]:43835) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fYdAx-0000wu-0S for qemu-devel@nongnu.org; Thu, 28 Jun 2018 16:05:55 -0400 Received: by mail-wr0-x242.google.com with SMTP id c5-v6so6682014wrs.10 for ; Thu, 28 Jun 2018 13:05:54 -0700 (PDT) Received: from 640k.lan ([82.84.124.111]) by smtp.gmail.com with ESMTPSA id 127-v6sm6211110wmd.18.2018.06.28.13.05.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 28 Jun 2018 13:05:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=QF/kNaXicyap5zS8PbToiF8fNXhM2h7AN0o9/gNB3VA=; b=q3NkM6h8Kb8Pjdwcv01zIE2IEQjB/z3WdvGej0k6xe9khpokKnQGPjVKgXNkJLemL5 g/iTBVTsHiP6yRQec/5eMssC3K9mjIZjGyGMSwf5HhL8ARmmfBbvdH4N7wak6FLvIs0E HfIYrR3B9CaiiqmabjGlTodk5shyCOpAUdDGIkNx+nNOOUeEdbarHiZ0ztc8e6w8HctS GNxzN2QCLYkcpeK0CtfXrmpkvJSz9n603JUyQhfERtnW33Hrbd57ndIW0pFOQenzrvgl bvue2kkfl20AH2+Q+2z18wWcLAU+7nC3xpeDCJwOn9nwlng2k2w2VviAGvk5m3oAthyM ETSw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=QF/kNaXicyap5zS8PbToiF8fNXhM2h7AN0o9/gNB3VA=; b=U43krB5VtEuCCjs7ffFtk+FXNJW5ykbQAC1uHrQp0bRmDioSU52RlXPil1t2SuPPH8 e4JkvHJT6FGwfFcamEbnZlX1Xl/hhwZ0gtPX+WXYSAJDEF/55WWLGLR1vbBEjn134vBY yyBwbtDv+CCpI0IbZSd4O/6lKD7BYSnMF8xGAb4sB5vQjQHr5GKVGT6x0Kk9qMyf1976 aJWKsKImJ3k4s2x/0E4pnlU71sjN1fO0x2PlJ4jmekbN1UJDP5Me7zmVa8TvciZk+VVj zw6879xzOrHG73N3TJH6NeA1YKqmsRsiTNoLNXDjDIezB0pscS6TlNk2z91PoK8Z5HFh /GHA== X-Gm-Message-State: APt69E0/LHC/f16tkAsZJvLb3H71CHhszajrt3Drt4tWdVABcAQCFHVk zxWM0SHEHXWsWAsc1kS7biMg0e+C X-Google-Smtp-Source: AAOMgpdcGs7SSnIgYjhvfos6xD255emA+AKfIBcF9qaZpNi2jWJO9YYAcwfEpv+XtDGC1m/JWGr++g== X-Received: by 2002:adf:ed52:: with SMTP id u18-v6mr9494378wro.262.1530216353741; Thu, 28 Jun 2018 13:05:53 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 28 Jun 2018 22:04:51 +0200 Message-Id: <1530216310-52873-42-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1530216310-52873-1-git-send-email-pbonzini@redhat.com> References: <1530216310-52873-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::242 Subject: [Qemu-devel] [PULL 41/60] WHPX: register for unrecognized MSR exits X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Justin Terry \(VM\)" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: "Justin Terry (VM)" Some variations of Linux kernels end up accessing MSR's that the Windows Hypervisor doesn't implement which causes a GP to be returned to the guest. This fix registers QEMU for unimplemented MSR access and globally returns 0= on reads and ignores writes. This behavior is allows the Linux kernel to probe= the MSR with a write/read/check sequence it does often without failing the acce= ss. Signed-off-by: Justin Terry (VM) Message-Id: <20180605221500.21674-2-juterry@microsoft.com> Signed-off-by: Paolo Bonzini --- target/i386/whpx-all.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/target/i386/whpx-all.c b/target/i386/whpx-all.c index 99501ba..57e53e1 100644 --- a/target/i386/whpx-all.c +++ b/target/i386/whpx-all.c @@ -932,6 +932,7 @@ static int whpx_vcpu_run(CPUState *cpu) =20 case WHvRunVpExitReasonX64InterruptWindow: vcpu->window_registered =3D 0; + ret =3D 0; break; =20 case WHvRunVpExitReasonX64Halt: @@ -943,6 +944,40 @@ static int whpx_vcpu_run(CPUState *cpu) ret =3D 1; break; =20 + case WHvRunVpExitReasonX64MsrAccess: { + WHV_REGISTER_VALUE reg_values[3] =3D {0}; + WHV_REGISTER_NAME reg_names[3]; + UINT32 reg_count; + + reg_names[0] =3D WHvX64RegisterRip; + reg_names[1] =3D WHvX64RegisterRax; + reg_names[2] =3D WHvX64RegisterRdx; + + reg_values[0].Reg64 =3D + vcpu->exit_ctx.VpContext.Rip + + vcpu->exit_ctx.VpContext.InstructionLength; + + /* + * For all unsupported MSR access we: + * ignore writes + * return 0 on read. + */ + reg_count =3D vcpu->exit_ctx.MsrAccess.AccessInfo.IsWrite ? + 1 : 3; + + hr =3D whp_dispatch.WHvSetVirtualProcessorRegisters( + whpx->partition, + cpu->cpu_index, + reg_names, reg_count, + reg_values); + + if (FAILED(hr)) { + error_report("WHPX: Failed to set MsrAccess state " + " registers, hr=3D%08lx", hr); + } + ret =3D 0; + break; + } case WHvRunVpExitReasonX64Cpuid: { WHV_REGISTER_VALUE reg_values[5]; WHV_REGISTER_NAME reg_names[5]; @@ -1010,7 +1045,6 @@ static int whpx_vcpu_run(CPUState *cpu) case WHvRunVpExitReasonUnrecoverableException: case WHvRunVpExitReasonInvalidVpRegisterValue: case WHvRunVpExitReasonUnsupportedFeature: - case WHvRunVpExitReasonX64MsrAccess: case WHvRunVpExitReasonException: default: error_report("WHPX: Unexpected VP exit code %d", @@ -1378,6 +1412,7 @@ static int whpx_accel_init(MachineState *ms) } =20 memset(&prop, 0, sizeof(WHV_PARTITION_PROPERTY)); + prop.ExtendedVmExits.X64MsrExit =3D 1; prop.ExtendedVmExits.X64CpuidExit =3D 1; hr =3D whp_dispatch.WHvSetPartitionProperty( whpx->partition, @@ -1386,8 +1421,8 @@ static int whpx_accel_init(MachineState *ms) sizeof(WHV_PARTITION_PROPERTY)); =20 if (FAILED(hr)) { - error_report("WHPX: Failed to enable partition extended X64CpuidEx= it" - " hr=3D%08lx", hr); + error_report("WHPX: Failed to enable partition extended X64MsrExit= and" + " X64CpuidExit hr=3D%08lx", hr); ret =3D -EINVAL; goto error; } --=20 1.8.3.1