From patchwork Mon Mar 26 17:06:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Denis V. Lunev\" via" X-Patchwork-Id: 10308317 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1CB5A60386 for ; Mon, 26 Mar 2018 17:08:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B20B29142 for ; Mon, 26 Mar 2018 17:08:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3E322916F; Mon, 26 Mar 2018 17:08:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3F30129147 for ; Mon, 26 Mar 2018 17:08:27 +0000 (UTC) Received: from localhost ([::1]:58123 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0Vbe-0001hJ-GK for patchwork-qemu-devel@patchwork.kernel.org; Mon, 26 Mar 2018 13:08:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38313) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0VaU-0000on-PS for qemu-devel@nongnu.org; Mon, 26 Mar 2018 13:07:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f0VaR-0004PZ-I5 for qemu-devel@nongnu.org; Mon, 26 Mar 2018 13:07:14 -0400 Received: from mail-bl2nam02on0099.outbound.protection.outlook.com ([104.47.38.99]:64176 helo=NAM02-BL2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f0VaR-0004P5-CJ for qemu-devel@nongnu.org; Mon, 26 Mar 2018 13:07:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=F3nuPua8E9nWwYUt0uyo0OpH+ZM5K/l/2HwqknnqHfs=; b=im8dSOdD10rb276K5wegiYf6EW+2h8NAeAJry9VpBAO40vesJk55d6dVxFby3/huyTsevMv9XMLsSU0P/JOKYfbglxSjqF1VL6HC8raLHaccSHUquiaIAviIACfZUX9Jt6KIC6gA8WzbWKf1p1YPLm9gmB44r3SWKeDzJq/wSPk= Received: from JUTERRY-DEV2.corp.microsoft.com (2001:4898:80e8:b::2ab) by DM5PR21MB0170.namprd21.prod.outlook.com (2603:10b6:3:a5::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.653.1; Mon, 26 Mar 2018 17:07:08 +0000 To: qemu-devel@nongnu.org Date: Mon, 26 Mar 2018 10:06:58 -0700 Message-Id: <20180326170658.606-1-juterry@microsoft.com> X-Mailer: git-send-email 2.11.0 MIME-Version: 1.0 X-Originating-IP: [2001:4898:80e8:b::2ab] X-ClientProxiedBy: MWHPR0201CA0067.namprd02.prod.outlook.com (2603:10b6:301:73::44) To DM5PR21MB0170.namprd21.prod.outlook.com (2603:10b6:3:a5::21) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 1a482007-88a9-4893-a2ba-08d5933c0251 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020); SRVR:DM5PR21MB0170; X-Microsoft-Exchange-Diagnostics: 1; DM5PR21MB0170; 3:bkvxa/vY4yFNvIwlN8fgPC0cbRbFwrxnUuZdQXVxjqQv5wXx5hx+D0nvlQdNpx7e14BLZoWm4n9iA3SB9c6RjxvVvDOm+ulmnjMskkk2bERsK9gZDow5dDN2Gwxq1/UNcPQQ7SDXG0fdGzj8J11N4ILII+LZdKZvVyBDfWn7S4y7NhHV7ippOK9gseM90rg6C2FbdZIaeKuhb+faifSBfpfopzUqE5WvJr2GoRvzLJmjaAo9EO/c2uEC7XzI1AN2; 25:dQlk13FItO9gMJJRjUTWHUgZN8st0i63clVm7+XpcXx4b/lMJA9UsqAxEa4GjCvtNqeh9HT0enW6G15HQfWt0LmbDrUWp+mtIEuRKhfjF+AREFpD7GZ09qV2Z8w0/bh325or9f3SqdfJmWB8gWt2i+83e6spN+GsXlEAxbx02rnFQaXqDCgMjMAE+bIZA2Beoya1PdMMb3wBplig4ly/4cJPZWswWG+BFixSdIHyYnP+gB4H4NjHctKPwFof6zV76YPRf8gWQtMXUW+P6EL9TRFdcRkiqkcEw8E5230AA25qKfKQg+a7obUu1PvxlDB7Ioguh6x/MjhFgJYy1axh+A==; 31:K+396Gp9qlIenWPcdU3i86GErAX1Aqp81l6i3QZmg3aWjs9dVWf+hqtFApWjzoSQIXC9Vu1NdDWVwsHCXXp1lKxCO4yfDqf8tIHn7PfZrymm81/linWvYvHi1zq8xCnaAu9MULm2cRacXWoUcZ51ZzzKwSZPuqZbBqYz9cvOY9dpS/MIivbf3A4K4iYL/7LagNE4KWtGgkucBJYDehZDGDIo6pf+A889yBSYeNcf61w= X-MS-TrafficTypeDiagnostic: DM5PR21MB0170: X-Microsoft-Exchange-Diagnostics: 1; DM5PR21MB0170; 20:N4ee/m1QMeAUvVUGC0iYsk45zJqa7isutA/bSs3PLGG0JOUxg/LcL0NXsXwEPDKVkw/v9Klw32L3jHNZa+sV2O43GNjwCQ39hHT3xubI3qJS+NNtjw5Fq+f+rNeWLegFWxrXTMdRbiSau5ijLOjCmH7q9OF+8PTSTGjUiZEwHdGhSzxd/fHL262Z6tbPlIXUPbWllKrDRdk/OZblesxZUzxfaUbkNfq3yyahiZsi+na5IqxRk26Xyk1M/+eOIy03RG8vCoRhQYz2j0ECI+PGpBfMTN3Fz4DVWMNCJwshYs2tVYLT6nur64qv8O5ObbGYm8omUmZ3+eGaVPcT9l54BIPHZwQn3pVHcjQNP/qvFztd0vw8tJD8vnQ7WKDZ0+UOXnHPndE9yoqk1lazJMWVBmV38G4zI7ZWtblRmJknshIQq10JhElB/sK9Hnl+vXUUbMiOmsUUCwEtTubtqaePpRWbj87TDSdPAu+RCA1W+v8GetaIEs5m6JPy0vqT5jzO; 4:nuIu+qcSL0Wkfr6O+iS7jlkd0SOrSAKemFKFXfgaNW+YVhBU7cHPU6WxdoEyuSshxJMzlIsZtkV7kxIBPvRCNw/LyXMSggLCxiQpLVBkeFQ0BOe/Hn9zHu7lQe9gp7F8QRRtR5cptfclVoQvX+/4bZpm4iFY8Ao5xWz8JWaYayFSTO+Ltq2opUOvorQSa4naRngpj2Vaz6NXGR3lfsO12lISigaCnRB6BFgbtpmkE/PMpt87NzOT6J4yjI6Ui++HLECDYFbVItIKivAUw9IASJl2XjbE5wZJCJTfKh36z8fNnoC/0qp9xFzK0T78wU6ONqGsH+8t5rCoqALNyOSBhBbGGEIALf9u0R5ejxC/Pu4= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(28532068793085)(89211679590171); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(61425038)(6040522)(2401047)(5005006)(8121501046)(3231221)(944501327)(52105095)(3002001)(93006095)(93001095)(10201501046)(6055026)(61426038)(61427038)(6041310)(20161123564045)(20161123558120)(20161123562045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011); SRVR:DM5PR21MB0170; BCL:0; PCL:0; RULEID:; SRVR:DM5PR21MB0170; X-Forefront-PRVS: 06237E4555 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(39860400002)(376002)(39380400002)(346002)(396003)(366004)(199004)(189003)(6346003)(305945005)(7736002)(25786009)(4326008)(1076002)(6916009)(97736004)(6666003)(2906002)(7696005)(8936002)(386003)(2616005)(1857600001)(316002)(59450400001)(46003)(486005)(486005)(8676002)(52116002)(16526019)(50466002)(48376002)(6116002)(50226002)(10290500003)(105586002)(16586007)(22452003)(86362001)(52396003)(81156014)(51416003)(186003)(478600001)(10090500001)(86612001)(107886003)(68736007)(81166006)(36756003)(5660300001)(2351001)(2361001)(6486002)(53936002)(47776003)(106356001)(476003)(19627235001); DIR:OUT; SFP:1102; SCL:1; SRVR:DM5PR21MB0170; H:JUTERRY-DEV2.corp.microsoft.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=juterry@microsoft.com; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR21MB0170; 23:v/vN95MmI86K42kapJcfFbXtnl044fAeGcZVe+8Kd?= =?us-ascii?Q?xqpNl3R7erZa+wPxMjQVKxeSFR8aUPaydgw3VoZiuZsy8kaHFNNEBBZdcW/M?= =?us-ascii?Q?GTpbKUn9qRG2uw3RnADzFOmicTIsXI627v6/e56paSqoROh248H0BfrwbkYz?= =?us-ascii?Q?nBnsxMbU4Y9rHkWox8TZyivQya66iIE4p/ul0xddwtRfpvYD6vsxJllHWHO5?= =?us-ascii?Q?K+hBJke5maPfXuCSXXneHq40pJyKXITyJi0W6AHFWXY6ohrY7O20wt6Cq3xM?= =?us-ascii?Q?vQ36Ibm39y9Ip219TcHNpUJe02zTNgTswa/j43SAnCHjzeG91UxvMgRpnDAY?= =?us-ascii?Q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d8=; 24:Azw/VmEUY/e/t5Hd3B7daP7Cgn7sO2EKWyXlp7HL7pqvkk2fO/TRu9dx1HCUZAa2HMzl8sEOyOmSUEji8/0/wxOdmePB1pn78IsupSIGL9I= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR21MB0170; 7:1LoMMDKHqh+5gb+8X0v0PSVRpqMhwr9zgId4R06Lu5qmWwAOnNwdJb3BaTSugJ4w327EYqBTbuHtA2xI+ZzuSIutzoBrmnhqMh3cGHh7khpjTLyvaBZMpvCviNQtob/BSSspj7//fkruM2pZu8DqmShMcY0Q2/94IVJy/8zrERYeU2Qk47MkYQ4BT0szErMcIzUH89lv+POBIYhiJAokKKerZDhpDXKQ5rKtsESgvx67cl1P7sMMjVpUxkHh/mgJ; 20:XX2BnNKWyuCQwziksm22KLvAU4CIniAMjGQzbVoNE2DaXzwqSpdRClhMvtMmf9UA8HlBX4r0PaRiojYI/5EOYgHVPAkXv7fehDWwGgVXj4fVzU7wlnVD4AtQ576JHTk6KP/jNwZdiXUL8pW/na/65QdnBuSHjOW8zlzd6IyjcW8= X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Mar 2018 17:07:08.6046 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1a482007-88a9-4893-a2ba-08d5933c0251 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR21MB0170 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.38.99 Subject: [Qemu-devel] [PATCH] WHPX fixes an issue with CPUID 1 not returning CPUID_EXT_HYPERVISOR 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: , X-Patchwork-Original-From: "Justin Terry \(VM\) via Qemu-devel" From: "Denis V. Lunev\" via" Reply-To: "Justin Terry \(VM\)" Cc: pbonzini@redhat.com, "Justin Terry \(VM\)" , ehabkost@redhat.com, rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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) --- 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 bf33d320bf..58435178a4 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);