From patchwork Tue Jun 6 18:19:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 9769523 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 CD07160364 for ; Tue, 6 Jun 2017 18:21:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C92E6223C7 for ; Tue, 6 Jun 2017 18:21:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDD7C27FB8; Tue, 6 Jun 2017 18:21: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 38880223C7 for ; Tue, 6 Jun 2017 18:21:27 +0000 (UTC) Received: from localhost ([::1]:39624 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIJ6c-0005lb-6j for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Jun 2017 14:21:26 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47316) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIJ5G-0005fc-Mq for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIJ5E-0007DN-LR for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:02 -0400 Received: from mail-eopbgr30133.outbound.protection.outlook.com ([40.107.3.133]:4192 helo=EUR03-AM5-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 1dIJ5E-00075V-Ay for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:00 -0400 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=lMLQr+eh6UhLOov1y1sj7MOkULMct09dX9Bd1Re0Uxk=; b=CJkIt17KoQNLqVR9Qh3boTh0RZ+Gv+yRJquBBPEm2SoOW9C5B4YtCKzjwJDc8bylaJqgDXK4kpeNSlFvpwNeqA5ZIQz0YId7CiSr4+jaQicsHMNq8TmytWL8nhonjtBgKafvqEK/IYT6aZ0uhis4ysXUh81Cro9cpLNcfJOf6BM= Authentication-Results: nongnu.org; dkim=none (message not signed) header.d=none; nongnu.org; dmarc=none action=none header.from=virtuozzo.com; Received: from rkaganb.sw.ru (195.214.232.6) by VI1PR08MB0847.eurprd08.prod.outlook.com (2a01:111:e400:5a05::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1143.10; Tue, 6 Jun 2017 18:19:58 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Tue, 6 Jun 2017 21:19:30 +0300 Message-Id: <20170606181948.16238-6-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170606181948.16238-1-rkagan@virtuozzo.com> References: <20170606181948.16238-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: DB6PR1001CA0042.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:4:55::28) To VI1PR08MB0847.eurprd08.prod.outlook.com (2a01:111:e400:5a05::17) X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR08MB0847: X-MS-Office365-Filtering-Correlation-Id: 3dff6aa4-e16d-48e2-5fd1-08d4ad08a401 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:VI1PR08MB0847; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 3:igBLeoCO1f3jLgQBRIICcB3YFCsjbVqDy5xgDL0RYBSU933wfS0JPtEQcC5nQE7aCiATS+kJ9lcmEbf6b5bSaNWMnMiRw5eDp0t7NpXL68JSVtuDnfZDIbpbfZH7CLNGOyZ1nTa7CRdiFb0YrWcDpDVtvcpRP+fK1J/MYht0buq51OUPZ4IIdVCn4LtdLjX/sh4gpVPXI0HFFCXFMMSnI4QzD/ev3zyATgzlDf3XVZgeE3inVOhtZFLg33g//Iz71v09qfO0ToxRGDdmuRJ52uS3f/FVUdq1x1s9WzOjsw6soQIECtUfl1YhLXH8AiDVt66XZsK+JDHPQVVuVDQHLw==; 25:XYnblNXO0QK84SLcNX0K72eBT88iP6Vmf7obya81bviRONfem/gAEZNeISvkMiVjuIxd/UaQMJh9MSd2qydzlK7NQK6yqjIAUca/o4r7dEBJP9+iixqcAunMCntWQo25PjLyE+4IBD4Av8PhMTJuxEdSi2hu4v2C51gfyPg7VvCyowhdfZPSoOFsawE99kEN8s2y43Fn+gXa+hV3drKvdlHsmRWK0/ckf6pByaaNMJBnqlnkgHmL0OtNZXu8BS06IjPllyITfeyPRTgTJyQIvXtmTVNTNetPePPNaREuINR3JdffarcPR0kCMZdDBeYt9VFrtsAz5RqxfvWMzQ5UbjzJBFG5i0uRBxuqfZ9GvK4bONa2I29ySHB38tbqMCllYl0tBDdjFbNCRSjNazQW//auZ+7vdKVHfpAC1Lj3HJAe9lHR4cimoFGok1WwQDefq+95h4LCZ+HOe3JwazbdaSQsCUuODumJegWfxEzyI1o= X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 31:DAKJyTI6eaOPgrK+xHuUod2uqrYa72RWJSqsyFOpr18PuBZEWObFaS7T7Vk1qtip8gEJGoq04lwgQeZlicatV9/MkefI6PTocuW67t+d+opfhDpA/dFprKd4dhqycvpaEUSVXs/enOE6cPdV5n3ja82j9zvX1Uq5FFXzCtZhviDDfYUCaDq0nsx6sqMKV558Lu6Y+Ijne1ICVG6oF8VyQjwvHb7W8kMuF1ponYP6qsU=; 20:DBzcV1puN0sz4zYcqJs3HAOkQCztaNeAxKfN65AsGiaPUhFfjpUIaCWSJz9c/5aEgZPBcGT2xR1Hpf5pmhzR2UktO+sZ7D7/zitgHDfmuwv3kYml6QmVbtzgW/qTrG5vdz1JnusKIbO0euttPAWvROcWEtWOjNdl0kvuBhcJ5gxOyUn6JzRAbG3XloG2syheL8BG+8xXe1rEVo5/cFX4Dtn4injOaZCyqhTMOZuiiMwQm9Df18g7CLDNhDrXOS5mBqUxRI2dVzaUAFp7tLwyJOGFjBT5rna5Jgvt+a2j9nxLdfuICKtx3OLtjZBFGFEy7R6r/B8GXLL4xXOdRCd3OxTDJmrRXN7KMvYKXVQFXzRQf9Lucynsu913Ijbkqc480pz4cR3t0tMwXFal46qUWMVcfPKg50BCAiKzUgcpIig= 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)(601004)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(10201501046)(100000703101)(100105400095)(6041248)(20161123560025)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(20161123558100)(20161123564025)(20161123555025)(20161123562025)(6072148)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:VI1PR08MB0847; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:VI1P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PkWogsZjU9z7FtMN3VPrc5jYO2w9WArkcTVkVRLkUB9OqrBV019YCU6ZX1U?= =?us-ascii?Q?V9OT+4fgTVDOk7UGlEwwB4Qjgtx2H7Tn2BumGULAOpBWAPW5A2MxcXQveYbw?= =?us-ascii?Q?qC6F4J9iyFmxfIYD5orBJEOs1A6MpB02YJFUTuVT8PVkdv9vMDzf0WRdr5ZX?= =?us-ascii?Q?lxIGC6qte9oAFyol6pYfXUzYVf030QQ2hR/slfhnaqwFdvZh7qkFHYicmj6y?= =?us-ascii?Q?S+1Iv28NG81NX3bWKrHfwnyH0rEKgGi7spu4RMNDQTXYPWjaQNtSEghRp1he?= =?us-ascii?Q?X8CSK7d1O9nuZoWsMiQPEwHbATEyv9?= X-Forefront-PRVS: 033054F29A X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(4630300001)(6009001)(39410400002)(39400400002)(39840400002)(39450400003)(48376002)(33646002)(36756003)(47776003)(6486002)(478600001)(66066001)(5003940100001)(2361001)(2906002)(5660300001)(2351001)(50226002)(81166006)(8676002)(25786009)(1076002)(6512007)(6916009)(53416004)(76176999)(42186005)(189998001)(38730400002)(53936002)(4326008)(50986999)(107886003)(7736002)(110136004)(6666003)(6116002)(3846002)(54906002)(2950100002)(86362001)(6506006)(575784001)(305945005); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR08MB0847; H:rkaganb.sw.ru; FPR:; SPF:None; MLV:sfv; LANG:en; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR08MB0847; 23:mX7frQBbEhAfvzvtpjEDH2hUJ6ekedOOpMHk2Y6Yx?= =?us-ascii?Q?OBU+7cc83/hJ8UciJx0+QKgfzHhPIUxnLQg9i38ZrU8Mgi+rXe2PpKKP5VHk?= =?us-ascii?Q?K0/C0Pv6E+LtYsnmqxBgIgb0xh9VHCrndJ1YaK3XUpa4ITb9XZvm6RCeHQtc?= =?us-ascii?Q?FL1KvkETpTrkYElg5qwqFs2q0tiYyAK+h57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7e1C3UEpdEZQ5eLg43Lim89UR/d53BMB0ZQ7OzVm6/YstTydLpKom4ljA/Ji6nb36x9IB9VbvWIh+hDaQ51IBIpzIuO98EkhwDeinYxNZNMuEvWyV3dilbSN52; 24:LcwgGCjAOS5UBD+3pbzfRGSO1hdfTCgZpa8jHpBPtzm+o30DuEAgPP5/N3VafNlV35fis+V3BfdQyjabjEUMxXIJ57UqY7Ytthex93u139s= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 7:X9VyOEfEbFHO4ehFVuYOeMmCdoJA9D53NN/1JvFoHzLgw4NveeZmOpEk7K4HtM5wOVHKjXYrjWG4nBiXO0IcTLooQ+ww7EStiLAOYvm8w7AI3EHdzZE3QAgw6unmdpb0oyPMRXaHlR7quWDai36R8hmjBDTOhcpC/beKTkkxDV6BhonFQnTrk6SzI7R7To3qNc64dRboQlaUR666WfIMNpM63HX01TyR4unagvBvKkzzhT9YG1+j8PyOPNII/UiDkIt6N9eLmLTC6GdkDoWFDM+rrqJUZyShn9I/s00tw4kiFPen8sQNyFTls+zlc/xGeSxMuKg1QNcSYazmYtWbpw==; 20:jRf24HYaya0xyxbhkU+DUgNIGRKWIatEdJ8ib3JJcrEu6RmSzUQUWZEcgqFlaELg9tVilhFxMAAp/JxZ14d7rHFi6J0Prru5tk1qYXGsslN8vbUMs4bHb9E2HG0qJvgtByzhq5T0jj3aI4Y3zkcjbDooTBEsobqLCXO9o4UCqyc= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2017 18:19:58.1791 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR08MB0847 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.3.133 Subject: [Qemu-devel] [PATCH 05/23] hyperv: ensure VP index equal to QEMU cpu_index 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: Paolo Bonzini , Evgeny Yakovlev , Eduardo Habkost , "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 Hyper-V identifies vcpus by the virtual processor (VP) index which is normally queried by the guest via HV_X64_MSR_VP_INDEX msr. It has to be owned by QEMU in order to preserve it across migration. However, the current implementation in KVM doesn't allow to set this msr, and KVM uses its own notion of VP index. Fortunately, the way vcpus are created in QEMU/KVM basically guarantees that the KVM value is equal to QEMU cpu_index. So, for back and forward compatibility, attempt to set the msr at vcpu init time to cpu_index, but ignore the errors; then query the msr value from KVM and assert that it's equal to cpu_index. On current kernels this will work by luck; future ones will accept the value from userspace. Signed-off-by: Roman Kagan --- target/i386/hyperv.h | 2 ++ target/i386/hyperv.c | 5 +++++ target/i386/kvm.c | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h index 0c3b562..35da0b1 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -39,4 +39,6 @@ void kvm_hv_sint_route_destroy(HvSintRoute *sint_route); int kvm_hv_sint_route_set_sint(HvSintRoute *sint_route); +uint32_t hyperv_vp_index(X86CPU *cpu); + #endif diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 227185c..27de5bc 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -16,6 +16,11 @@ #include "hyperv.h" #include "hyperv_proto.h" +uint32_t hyperv_vp_index(X86CPU *cpu) +{ + return CPU(cpu)->cpu_index; +} + int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) { CPUX86State *env = &cpu->env; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 251aa95..eb9cde4 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -610,11 +610,37 @@ static int kvm_arch_set_tsc_khz(CPUState *cs) return 0; } +static void hyperv_set_vp_index(CPUState *cs) +{ + struct { + struct kvm_msrs info; + struct kvm_msr_entry entries[1]; + } msr_data; + int ret; + + msr_data.info.nmsrs = 1; + msr_data.entries[0].index = HV_X64_MSR_VP_INDEX; + + /* + * Some kernels don't support setting HV_X64_MSR_VP_INDEX. However, + * they use VP_INDEX equal to cpu_index due to the way vcpus are created. + * So ignore the errors from SET_MSRS, but verify that GET_MSRS returns the + * expected value. + */ + msr_data.entries[0].data = cs->cpu_index; + kvm_vcpu_ioctl(cs, KVM_SET_MSRS, &msr_data); + ret = kvm_vcpu_ioctl(cs, KVM_GET_MSRS, &msr_data); + assert(ret == 1); + assert(msr_data.entries[0].data == cs->cpu_index); +} + static int hyperv_handle_properties(CPUState *cs) { X86CPU *cpu = X86_CPU(cs); CPUX86State *env = &cpu->env; + hyperv_set_vp_index(cs); + if (cpu->hyperv_time && kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_TIME) <= 0) { cpu->hyperv_time = false;