From patchwork Wed Nov 22 18:14:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10070725 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 3BAF0601D5 for ; Wed, 22 Nov 2017 18:15:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37EC629DF3 for ; Wed, 22 Nov 2017 18:15:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C88029E4E; Wed, 22 Nov 2017 18:15:44 +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 ACCED29DF3 for ; Wed, 22 Nov 2017 18:15:43 +0000 (UTC) Received: from localhost ([::1]:40783 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHZYk-0000h8-Qj for patchwork-qemu-devel@patchwork.kernel.org; Wed, 22 Nov 2017 13:15:42 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eHZXd-0000g1-Ly for qemu-devel@nongnu.org; Wed, 22 Nov 2017 13:14:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eHZXb-0007bB-Eg for qemu-devel@nongnu.org; Wed, 22 Nov 2017 13:14:33 -0500 Received: from mail-eopbgr20115.outbound.protection.outlook.com ([40.107.2.115]:44320 helo=EUR02-VE1-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 1eHZXb-0007aQ-7B for qemu-devel@nongnu.org; Wed, 22 Nov 2017 13:14:31 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=virtuozzo.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=ak1frGbmeY08hJ3WshHss+aH+Nz4j2AtmI37M7QHq+M=; b=MAz+ex4KuiQQJdDoIQrzvRnL9cd/3s/8E4J90f31Zm71SkfT5R/oB2PObRwqGYgdxKnZe102DoTulZro/0UNTwfPempamUbc4QV7vvY7CGbjAw1noodKxHjXn+Hnh2UikEeuktNS8Sa1G6n2d7t1a8rjgK74+F3KKSqWj/+Sa74= Received: from rkaganb.sw.ru (195.214.232.6) by VI1PR08MB0846.eurprd08.prod.outlook.com (2a01:111:e400:5a05::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.239.5; Wed, 22 Nov 2017 18:14:27 +0000 From: Roman Kagan To: qemu-devel@nongnu.org, Paolo Bonzini , Eduardo Habkost Date: Wed, 22 Nov 2017 21:14:16 +0300 Message-Id: <20171122181418.14180-2-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20171122181418.14180-1-rkagan@virtuozzo.com> References: <20171122181418.14180-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1P18901CA0021.EURP189.PROD.OUTLOOK.COM (2603:10a6:3:8b::31) To VI1PR08MB0846.eurprd08.prod.outlook.com (2a01:111:e400:5a05::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a01d1772-b0d0-4199-dc19-08d531d4de64 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(7168020)(4627115)(201703031133081)(201702281549075)(5600022)(4604075)(2017052603258); SRVR:VI1PR08MB0846; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0846; 3:S1ln2ygklBpJkIVDR5YIHq0HzAHMgmDhmcxh5zZ3vPXfKx2nq0Mp364rKiYlRfgD1pTAq9ka1vDe3dNeGaII1a+0yvQ5Gkp/PiYQ2WDlqHQ1NfPIhbhobWnXimMSvOF4m2LjHoG8XeZsKf7aIbLjxMCsdyqCJWjUHjqdeMe9Oq7hIbG2NWjHVfCRVTQJLK8pUgr6EFISmFJ8kruH3AwmBTg+/zsb3JYNRrP3X5Y3QmW7W6z9jBG0TYOD+C3Yr+fZ; 25:HzjmU2hkYaTwJKfAolAMF9uwR1pFSfQ26MfR5Ke9bSLakcDQCtLHRKZmftpJ8xn8UetdC4eQDS6RZFQehjehixH8tsuT7gdkq9UUiz15iICmS1wpBLCgsxoG1yL/h1N8bBbKQKsdecAJveohWb08X56+XxWGLNRALVSgs8Vx2sqsJkVrwhThV0NQW8/RlQe5Ba/gij51RUx5AI6Y1Puei9akT9PllYzTuH7mrvLvu8jOEhICwDKKV7YtAtCwqK9ZoQo8VWe9qTxjckO9K91GA5XopvisxuS2f7WYXhs9hEeGjv0RiBSsl1mIUi2o/PGu+XAPT2SO07fTME2LGudX3Q==; 31:kAIG+cyP7fSqFVwuwu4X4OSa/cSxBuyrDTRp6XFG0gTV5eE6pEPXbuA7KSBnfPQfY7ICFvSEHB7mhlNErFzKE0ixUxLR67zeice/XIlxOQLT6UdB0cqHnRK/Y2JBuIv2PlGkiR9euRa1hJG4UNbFc6nHCKEjJCEMZ7v5EGFelLepfgf8Fewd3nwlgvOeAVGNH1aOL/gmVvLPpWk/57liVb55T7VrfTJ3x0tttLDfV/A= X-MS-TrafficTypeDiagnostic: VI1PR08MB0846: X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0846; 20:jlaBO3G8bCglOVXJV/JHU4L9jeHZ6B7b1O3qGah3Kq//JvF2n7NH8LvSOgSGD2o3ksSWdEoA3R1CY6Ml63J3120SolesAmCFG9wodAuFp9zysZ03U+XIOidpJyIjuSW+hvI2pxM6f7IX0boYE+dX6KeEjy++8iYof7zEXlxBpoFYopiIrIB5QT6pnkLnfO5wCBkO2j09faxqUVzaz+i7+WO1cfmEJFUMlULcLQF7nxsYrmwXKLuDxsukZzK5gF0xsDV0UwhQTNcAeRPXMXo8RwsWap51oGIqxZQwBe+4VhppzucGx+c95J8/EWQ1LdQCXrKi3v/XDAX5tRWyIs7op2FXPxBsZSTr7yKVJ/6sExTzxwYNqSimf4ffpuCe6la+rn1a3X8UvTyTB7iV+6GzPiKbxBDr36IqvvY8YFErStw=; 4:WqVREuIkyqKipCowd7nFwURmThJWuDbbAuoMK8hSIbjgbKY76dOmylxuAhLv07qentvDfI7FA50PItboO6lgYZt+y/fQxzxDEHH7XVSWPDhcs/4eWEOGmpKNovtgZrFcIBwZEy8WD9m6+zmElJkA1y596ohtY7m4qZvqMRTwPHZou3015E2pBdId6i/MEKsrvu4HkL8Nudo6x8eNc0P/Dly/VHUmv20XGGdjE/GsSpROc1Poji9cY2FhttShgBUy/nykFFJl73MzvqrRP1O2/w== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(2401047)(5005006)(8121501046)(10201501046)(100000703101)(100105400095)(93006095)(93001095)(3231022)(3002001)(6041248)(20161123562025)(20161123564025)(20161123555025)(20161123558100)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:VI1PR08MB0846; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:VI1PR08MB0846; X-Forefront-PRVS: 0499DAF22A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6009001)(346002)(39830400002)(376002)(199003)(189002)(110136005)(50226002)(16586007)(66066001)(316002)(47776003)(8936002)(5003940100001)(2906002)(55236003)(53936002)(97736004)(86362001)(16526018)(2950100002)(76176999)(101416001)(6512007)(107886003)(50986999)(4326008)(6666003)(6486002)(5660300001)(1076002)(6506006)(305945005)(81156014)(81166006)(7736002)(53416004)(25786009)(48376002)(3846002)(6116002)(189998001)(68736007)(33646002)(69596002)(478600001)(105586002)(106356001)(8676002)(36756003)(50466002); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR08MB0846; H:rkaganb.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR08MB0846; 23:7L0NvJw5skPI5zR8LdtiaTlEG+/zQOb7Sanca2i93?= =?us-ascii?Q?1sjJsOrZq7wOH6Y+ue465C8xOIw8zFcAML/FfCFVVefvXEZRqTBFAyBu9B8t?= =?us-ascii?Q?JoCDdaQd+aV6G4qxwOSFcO07csAHrvbqkZBOA7MtNSJXi0KnMKAlG0vedkbR?= =?us-ascii?Q?NQUbpbXo9rMG5d+vnWL7Ur3wNEN4IG/DfcfoSCdk06LVuL9m7gicUS1gY4yo?= =?us-ascii?Q?PReJY+jluZh2Nmp/1Ha4JA9LzROtZI2ZZmy8KuztaSXgDAajTAEYr23X6DSN?= =?us-ascii?Q?b7GYx3Z/Lgu6skLrphVsGc9j0zfY4d174dXZNgEdwVeU3zJ4MHyiB9ZasOv+?= =?us-ascii?Q?kBywK3q8Ow+pL8gAcilfAio9QBmx1FxS+wauAwR15a5sMWO9Fey0chA+eOqp?= =?us-ascii?Q?rMYzw+nkItxbBsBWXYhxA8Lg8EzUEZQP0DduN3kADlWTnt7vnL+l1X0OSi9V?= =?us-ascii?Q?N80r2cY0YceIRgt7fmt2RDs+oSOKcduPVcl9uz85qZSiqL5CLlVf/zSZG+zD?= =?us-ascii?Q?9HiRqUHN/4JC3nS2msw24Z5fQ2Oq26H2Q9pHN9ENsfyqMNa1TuRGJJlS4l1F?= =?us-ascii?Q?BtEz5uvba3PKOYAkjDjixKcZlur0VkGVDkxtDcNAYMp5AaasETlZesl01fdd?= =?us-ascii?Q?FHM0DIuFX7H/IkCkDsGKeFckOBLAlZsoqJ6RMKdpn2zHXkIaAY1tmMrm1052?= =?us-ascii?Q?C5bTKvH0ItE+KO/Z54G08LhkL3zIH25qUmMry/xioxlPZz0lhypsm9b2B4vR?= =?us-ascii?Q?D+zrV8719HORi51zdzPlcDsTrQprO9eDD+89r5NsBxo9AoDd/s2LjIuGokpi?= =?us-ascii?Q?qmg2eoe5nFNbzB8UhoZaH/cbSVTv0kzbMhplPy4wZSl2+24+GR9sUP4RrBT+?= =?us-ascii?Q?rQ9vMRi9sXSjs1Tmr8D0YVVlZcplXfZJtnVMlvOmJkHqqCVWoizrcKI7FLl7?= =?us-ascii?Q?oWRg7T4W/Z7r13EoNqE56dDzVISkQGY1aal4uhJEuOLZdEnJhWSg8UTYi6Sw?= =?us-ascii?Q?6sQIPuPlGxyaZpEqgbAqZAC6DY+6EChxmhX50KgT1xf6XcORjrdYZLDEPy3f?= =?us-ascii?Q?Y8gjrxZZaHy7HUPUSSOVDMcnETJC109Uotymg0pO5zFbjowavsR2Y51VbRy9?= =?us-ascii?Q?HiayCerDwGrD6CJIZQAhJnDeSBns8UsWTME2+3DN+ENdWPBhTXyMnx7EN80w?= =?us-ascii?Q?1U50ThHZ69IV/AxKCCvS2TWbARsVZFQImvs?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0846; 6:8LHnT7RaKHPSS+k9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7mEyBLshLjZDSfHO8RWEPtuxhpQHICSDyHGdecGEnbQ1ztUYg7HZsYIm1eg= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 22 Nov 2017 18:14:27.2554 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a01d1772-b0d0-4199-dc19-08d531d4de64 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB0846 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.2.115 Subject: [Qemu-devel] [PATCH 1/3] hyperv: set partition-wide MSRs only on first vcpu 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: "Denis V. Lunev" Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Evgeny Yakovlev Hyper-V has a notion of partition-wide MSRs. Those MSRs are read and written as usual on each VCPU, however the hypervisor maintains a single global value for all VCPUs. Thus writing such an MSR from any single VCPU affects the global value that is read by all other VCPUs. This leads to an issue during VCPU hotplug: the zero-initialzied values of those MSRs get synced into KVM and override the global values as has already been set by the guest. This change makes the partition-wide MSRs only be synchronized on the first vcpu. Signed-off-by: Evgeny Yakovlev Signed-off-by: Roman Kagan --- target/i386/cpu.h | 5 ++++- target/i386/kvm.c | 23 +++++++++++++++-------- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/target/i386/cpu.h b/target/i386/cpu.h index b086b1528b..ea9db80de5 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1091,10 +1091,13 @@ typedef struct CPUX86State { uint64_t async_pf_en_msr; uint64_t pv_eoi_en_msr; + /* Partition-wide HV MSRs, will be updated only on the first vcpu */ uint64_t msr_hv_hypercall; uint64_t msr_hv_guest_os_id; - uint64_t msr_hv_vapic; uint64_t msr_hv_tsc; + + /* Per-VCPU HV MSRs */ + uint64_t msr_hv_vapic; uint64_t msr_hv_crash_params[HV_CRASH_PARAMS]; uint64_t msr_hv_runtime; uint64_t msr_hv_synic_control; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index b1e32e95d3..563967241b 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -1678,19 +1678,26 @@ static int kvm_put_msrs(X86CPU *cpu, int level) kvm_msr_entry_add(cpu, MSR_CORE_PERF_GLOBAL_CTRL, env->msr_global_ctrl); } - if (has_msr_hv_hypercall) { - kvm_msr_entry_add(cpu, HV_X64_MSR_GUEST_OS_ID, - env->msr_hv_guest_os_id); - kvm_msr_entry_add(cpu, HV_X64_MSR_HYPERCALL, - env->msr_hv_hypercall); + /* + * Hyper-V partition-wide MSRs: to avoid clearing them on cpu hot-add, + * only sync them to KVM on the first cpu + */ + if (current_cpu == first_cpu) { + if (has_msr_hv_hypercall) { + kvm_msr_entry_add(cpu, HV_X64_MSR_GUEST_OS_ID, + env->msr_hv_guest_os_id); + kvm_msr_entry_add(cpu, HV_X64_MSR_HYPERCALL, + env->msr_hv_hypercall); + } + if (cpu->hyperv_time) { + kvm_msr_entry_add(cpu, HV_X64_MSR_REFERENCE_TSC, + env->msr_hv_tsc); + } } if (cpu->hyperv_vapic) { kvm_msr_entry_add(cpu, HV_X64_MSR_APIC_ASSIST_PAGE, env->msr_hv_vapic); } - if (cpu->hyperv_time) { - kvm_msr_entry_add(cpu, HV_X64_MSR_REFERENCE_TSC, env->msr_hv_tsc); - } if (has_msr_hv_crash) { int j;