From patchwork Tue Feb 6 20:30:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10204123 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 6176060327 for ; Tue, 6 Feb 2018 21:13:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55CFB28AE7 for ; Tue, 6 Feb 2018 21:13:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 52FFC28AF2; Tue, 6 Feb 2018 21:13:54 +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 58ADF2900F for ; Tue, 6 Feb 2018 21:11:53 +0000 (UTC) Received: from localhost ([::1]:34492 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejAWu-0007XW-Fp for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Feb 2018 16:11:52 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej9to-0000jj-3H for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ej9tk-00035u-OR for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:28 -0500 Received: from mail-eopbgr00099.outbound.protection.outlook.com ([40.107.0.99]:61504 helo=EUR02-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 1ej9tk-00035N-DU for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:24 -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=Wgy6IrEBZxPUbMQR8q3MrYOLrNpuqv9GWXEprVuItP8=; b=P6NjbK1TAM0iWuQ6WGiIZLR2cGla+KsETpilRr0o4nCy5hrL2YJ8As337eXIvfqns+CKOLZC18RwLhFmE7Y1pNdNj/XVBoO7cK6TgolHv7RVsvI9W+rkaQJ30NFtp+4rczw6NOCfK07bQGzjW/PODk9lQYA9HLqtX4K9LSQ37ME= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (195.214.232.6) by VI1PR0801MB1983.eurprd08.prod.outlook.com (2603:10a6:800:8a::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.464.11; Tue, 6 Feb 2018 20:31:20 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Tue, 6 Feb 2018 23:30:23 +0300 Message-Id: <20180206203048.11096-10-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180206203048.11096-1-rkagan@virtuozzo.com> References: <20180206203048.11096-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [195.214.232.6] X-ClientProxiedBy: HE1PR0301CA0008.eurprd03.prod.outlook.com (2603:10a6:3:76::18) To VI1PR0801MB1983.eurprd08.prod.outlook.com (2603:10a6:800:8a::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 78f8b95d-39a6-4f2c-caf1-08d56da095c3 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(7168020)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:VI1PR0801MB1983; X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 3:/rwqG4jIj/9DSMbnhKx7c3eRbD/5JCkDCBRbFPOhCm00owV9eJ2lAvA1izbnku4tB+V+/cbMYejdL1FzCX44j56Bcb3QC/5TkQq0W4Rk9nlHsiyJXCNhhaVJRs2bkSjwwjYSgH1iBokWS9YPe9W23mAVRFKPIhGQYxZ5PvCl3Fx0bcUn+neRo9M85lfd4rB4m4HNXSt8rMI0kf3NiyG9+8OviPrWqa25atAIYG6dK8cpjgoSmAFqkWirrZZsx+bo; 25:h7Y4l2A5HyNPwjLodaDqZgLiCgsrwge9lGysxglnu/Ogx2M86BcguCvJCtJR3RT7T/klTaNqZXAAcgVfa5kNt5+DrkPnlRQoqm4ZM/Q00kTuSIytinSdpHWSuLMbOCaPU4/TPUVW29xmIXET9Yh6J4YRj+rTp3GEXpMS42l4fmXipnMct48CPzUrr2bgoamkyucf1ooFHJMDf+1vek5uKpw1bPVFVCpY+lBek31YCdbOTsWz5C/QinJ5yScH/fHwAQ8IIi4oUMGMvQp626HiDcHw67t4q2r0LZu9WdjQvWeWYboSDFYY+ToP7eeodHS8LGsVD3PlnPXvynsAGxDDdA==; 31:T4HwBBerUvOk9t4g9L1jNsTz5xFnAQPnYq72b2YCjlB67R047UYzPbqjVp6YcUbXeMayEW/mYcBDF34KpwwMg1c/c3ZuBBLM37kqBKU1QW2OobEnogFai4TARzOuVxMicnDB9o3sXZ6YcMiq5F5mt2osb+PXGkDD3BzD0gGJMWDQOZ8kfgwcXMBRhI7YsRUobhrGOWYT1bLSQQJ2Z6iNy4Kheg1BUr8J+ESlzmc0MzI= X-MS-TrafficTypeDiagnostic: VI1PR0801MB1983: X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 20:/3r2cEYW2Xxu8mbwKfW0WfM1Ay9Dffbm1Zj0P0GMvra3Lj6G7ISBR/iSa+uOMCldey7zAWCo1a7L9NPnn5LH4zxsjhxQYu0uFZLAI8z5NOUZA0f7Gg0qLW8yBnj4XqRywIbusO3QDdy2NL2CLOro547tib3woF7uzs8thXnnD4/mgrHUIov0K+mBE8GLL3DlgXOIwgv+Vczeg5UxVZQZFHxvVjXJSp1TbF0rCAvTurrBWXLtYmo2UzKhchZLXzFnDv8Hutb/xHUnU388MIA4URDa4PM6mt43GWh2AW6LJx4utBeX/m1VHjoN3khzsqlyzaK+Il1GBvKy0wZRgVf0hXtn5LqEyeP3OcAOqJuaacgf+a+LnRz+uqD6xCQSktN94mqbajKJZxMYpQoE6IxjjsRX0oU76cD2xKuckNRjivA=; 4:BJteeU+Oy87daBr9Xluw7drHxdG9jOoxYXwSBlr36C+9Xh0uljZ978lE9wrY3MWqEAgzOLSO6ujvm0WTdiMYYSu/d1HDzPBuU/C/uTl+4cFidYxqiUgQ/4+UAwRgjqgLikNK1CaCeeG32ouOF66358cvnrUOljdUzhbFCkE2bWqBqBLsVRa/JhSHnu2lkdXD3f5UY1BOhTmk8jOuWAcLmVIW/XmqktzM/owVOA+RIs2kA+iMSaDUqwyP+X4BEFMF7G1/Ne/cU46NbizQHCUYdA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(3002001)(93006095)(93001095)(3231101)(2400082)(944501161)(10201501046)(6041288)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123562045)(20161123560045)(6072148)(201708071742011); SRVR:VI1PR0801MB1983; BCL:0; PCL:0; RULEID:; SRVR:VI1PR0801MB1983; X-Forefront-PRVS: 0575F81B58 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(396003)(366004)(376002)(39380400002)(39850400004)(346002)(189003)(199004)(16586007)(53936002)(305945005)(54906003)(7736002)(3846002)(316002)(105586002)(2361001)(106356001)(2351001)(6116002)(1076002)(50226002)(8936002)(81156014)(5660300001)(8676002)(81166006)(7416002)(2950100002)(6916009)(76176011)(86362001)(68736007)(66066001)(16526019)(47776003)(50466002)(4326008)(97736004)(26005)(6512007)(51416003)(2906002)(52116002)(386003)(6506007)(59450400001)(48376002)(55236004)(36756003)(53416004)(69596002)(6486002)(478600001)(186003)(25786009)(217873001); DIR:OUT; SFP:1102; SCL:1; SRVR:VI1PR0801MB1983; H:rkaganb.sw.ru; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR0801MB1983; 23:cCcl37+MWTcD5DfVbV3UhLdUjGKZIE6S0j7XJQe?= =?us-ascii?Q?mQ3LQB+ZL8onu4BSZaYlMES4jQo8KXPtRYGOdXSL0SIOi8Xm1ALt0pA41vlj?= =?us-ascii?Q?KlrVDwuGkPO6Gy+jwmQXiXnJPekzbE2yqbTuPQBuppmFscs2YdnO3lwqvZiO?= =?us-ascii?Q?hsD7ct7qzNekUoPjdfnoU1U77J2lJAL2ArLV0QxeYcCuNZKSszJwxv/+1FGk?= =?us-ascii?Q?/8vsAWNhummmbFQOCi7P0rgQkPhYzkBYKsV6aifdg81u+AbyX6uWW5M50sMu?= =?us-ascii?Q?ApO+JXwOjBGbOCspEfQKDCvmwmh0DaZLZ1D+fQP964paxftN+jT1LAy8XeGp?= =?us-ascii?Q?7VDtreFVWcLEe3aPMjIDOxthLM6HIpBptHtUT+BLVqb78hi8ZkIu3HPWdpZp?= =?us-ascii?Q?6vcNea/XwADvI4Flw8dH56QQ40ipQFeo+E6I0IuCkAHEI0zoyXInEJZJbv3q?= =?us-ascii?Q?OTlOW/yW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A5TEVqlYaSV6i2BVP+Aul6OC+onesdhFjpexzRCGcRPgYn2b/N5NENCQgyKZYQzLBMMA014SJNlqyw= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2018 20:31:20.1999 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 78f8b95d-39a6-4f2c-caf1-08d56da095c3 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0801MB1983 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.0.99 Subject: [Qemu-devel] [RFC PATCH 09/34] hyperv: block SynIC use in QEMU in incompatible configurations 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: Ben Warren , Konrad Rzeszutek Wilk , Krish Sadhukhan , "Marcos E. Matsunaga" , Jan Dakinevich , Vadim Rozenfeld , "Denis V. Lunev" , si-wei liu , Paolo Bonzini , Vitaly Kuznetsov , Cathy Avery Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Certain configurations do not allow SynIC to be used in QEMU. In particular, - when hyperv_vpindex is off, SINT routes can't be used as they refer to the destination vCPU by vp_index - older KVM (which doesn't expose KVM_CAP_HYPERV_SYNIC2) zeroes out SynIC message and event pages on every msr load, breaking migration OTOH in-KVM users of SynIC -- SynIC timers -- do work in those configurations, and we shouldn't stop the guest from using them. To cover both scenarios, introduce a (user-invisible) SynIC property that disallows to use the SynIC within QEMU but not in KVM. The property is clear by default but is set via compat logic for older machine types. As a result, when hv_synic and a modern machine type are specified, QEMU will refuse to run unless vp_index is on and the kernel is recent enough. OTOH with older machine types QEMU will fine run against an older kernel and/or without vp_index enabled but will refuse the in-QEMU uses of SynIC (e.g. VMBus). Also a function is added that allows the devices to query the status of SynIC support across vCPUs. Signed-off-by: Roman Kagan --- include/hw/i386/pc.h | 5 ++++ target/i386/hyperv.h | 4 ++- target/i386/hyperv.c | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++- target/i386/kvm.c | 8 +++--- 4 files changed, 80 insertions(+), 7 deletions(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index bb49165fe0..744f6a20d2 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -352,6 +352,11 @@ bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); .property = "extended-tseg-mbytes",\ .value = stringify(0),\ },\ + {\ + .driver = "hyperv-synic",\ + .property = "in-kvm-only",\ + .value = "on",\ + },\ #define PC_COMPAT_2_8 \ HW_COMPAT_2_8 \ diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h index 20bbd7bb29..249bc15232 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -34,8 +34,10 @@ int kvm_hv_sint_route_set_sint(HvSintRoute *sint_route); uint32_t hyperv_vp_index(X86CPU *cpu); X86CPU *hyperv_find_vcpu(uint32_t vp_index); -void hyperv_synic_add(X86CPU *cpu); +int hyperv_synic_add(X86CPU *cpu); void hyperv_synic_reset(X86CPU *cpu); void hyperv_synic_update(X86CPU *cpu); +bool hyperv_synic_usable(void); + #endif diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index a27d33acb3..933bfe5bcb 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -14,6 +14,7 @@ #include "qemu/osdep.h" #include "qemu/main-loop.h" #include "qapi/error.h" +#include "qemu/error-report.h" #include "hw/qdev-properties.h" #include "hyperv.h" #include "hyperv-proto.h" @@ -23,6 +24,8 @@ typedef struct SynICState { X86CPU *cpu; + bool in_kvm_only; + bool enabled; hwaddr msg_page_addr; hwaddr evt_page_addr; @@ -78,6 +81,10 @@ static void synic_update_evt_page_addr(SynICState *synic) static void synic_update(SynICState *synic) { + if (synic->in_kvm_only) { + return; + } + synic->enabled = synic->cpu->env.msr_hv_synic_control & HV_SYNIC_ENABLE; synic_update_msg_page_addr(synic); synic_update_evt_page_addr(synic); @@ -154,6 +161,7 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, } synic = get_synic(cpu); + assert(!synic->in_kvm_only); sint_route = g_new0(HvSintRoute, 1); r = event_notifier_init(&sint_route->sint_set_notifier, false); @@ -240,17 +248,32 @@ int kvm_hv_sint_route_set_sint(HvSintRoute *sint_route) return event_notifier_set(&sint_route->sint_set_notifier); } +static Property synic_props[] = { + /* user-invisible, only used for compat handling */ + DEFINE_PROP_BOOL("in-kvm-only", SynICState, in_kvm_only, false), + DEFINE_PROP_END_OF_LIST(), +}; + static void synic_realize(DeviceState *dev, Error **errp) { Object *obj = OBJECT(dev); SynICState *synic = SYNIC(dev); + if (synic->in_kvm_only) { + return; + } + synic->cpu = X86_CPU(obj->parent); } static void synic_reset(DeviceState *dev) { SynICState *synic = SYNIC(dev); + + if (synic->in_kvm_only) { + return; + } + synic_update(synic); } @@ -258,19 +281,45 @@ static void synic_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); + dc->props = synic_props; dc->realize = synic_realize; dc->reset = synic_reset; dc->user_creatable = false; } -void hyperv_synic_add(X86CPU *cpu) +int hyperv_synic_add(X86CPU *cpu) { Object *obj; + SynICState *synic; + uint32_t synic_cap; + int ret; obj = object_new(TYPE_SYNIC); object_property_add_child(OBJECT(cpu), "synic", obj, &error_abort); object_unref(obj); + + synic = SYNIC(obj); + + if (!synic->in_kvm_only) { + synic_cap = KVM_CAP_HYPERV_SYNIC2; + if (!cpu->hyperv_vpindex) { + error_report("Hyper-V SynIC requires VP_INDEX support"); + return -ENOSYS; + } + } else { + /* compat mode: only in-KVM SynIC timers supported */ + synic_cap = KVM_CAP_HYPERV_SYNIC; + } + + ret = kvm_vcpu_enable_cap(CPU(cpu), synic_cap, 0); + if (ret) { + error_report("failed to enable Hyper-V SynIC in KVM: %s", + strerror(-ret)); + return ret; + } + object_property_set_bool(obj, true, "realized", &error_abort); + return 0; } void hyperv_synic_reset(X86CPU *cpu) @@ -283,6 +332,25 @@ void hyperv_synic_update(X86CPU *cpu) synic_update(get_synic(cpu)); } +bool hyperv_synic_usable(void) +{ + CPUState *cs; + + CPU_FOREACH(cs) { + X86CPU *cpu = X86_CPU(cs); + + if (!cpu->hyperv_synic) { + return false; + } + + if (get_synic(cpu)->in_kvm_only) { + return false; + } + } + + return true; +} + static const TypeInfo synic_type_info = { .name = TYPE_SYNIC, .parent = TYPE_DEVICE, diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 84c5cc2131..663501355b 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -717,12 +717,10 @@ static int hyperv_init_vcpu(X86CPU *cpu) } if (cpu->hyperv_synic) { - if (kvm_vcpu_enable_cap(CPU(cpu), KVM_CAP_HYPERV_SYNIC, 0)) { - fprintf(stderr, "failed to enable Hyper-V SynIC\n"); - return -ENOSYS; + int ret = hyperv_synic_add(cpu); + if (ret) { + return ret; } - - hyperv_synic_add(cpu); } return 0;