From patchwork Tue Feb 6 20:30:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10204111 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 3243E60327 for ; Tue, 6 Feb 2018 21:04:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2659E28D33 for ; Tue, 6 Feb 2018 21:04:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 11B0728D22; Tue, 6 Feb 2018 21:04:08 +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 4D38728D2C for ; Tue, 6 Feb 2018 21:04:05 +0000 (UTC) Received: from localhost ([::1]:33793 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejAPM-0008OR-EQ for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Feb 2018 16:04:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44847) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej9u5-00011K-Gi for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ej9u2-0003Ed-5p for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:45 -0500 Received: from mail-eopbgr00120.outbound.protection.outlook.com ([40.107.0.120]:37069 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 1ej9u1-0003E0-Rq for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:42 -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=KLZaHQnE++7UzaipdpN652CN9oB043tbHoW05nDRHAs=; b=GKJG0ufk82Nug2Cp0z6zpVik9Xz+3KnLAi2r25S53HPjRi0nZvgfvhHCI3lkeC5k9ralc10qfsz8S4ErgThcN1pMtKnmesEFLtLdRvMt/KDa4CIDZPqpooirzs4tcqbAyiTA0cNNIlhL8ioezJgyOhpIRcxnJKNqKjAGOGvcW9g= 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:36 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Tue, 6 Feb 2018 23:30:32 +0300 Message-Id: <20180206203048.11096-19-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: 74ddbd17-7263-4bb3-f5a3-08d56da0a049 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:stMqXEpQCin9VElbwSpJBg4o4/aS16sWBFDuaN4+Ljwst2Nku21xsRpD0u8gqAgQ1s4v+q166ZUXC9YVV3sduQizgQHyiQBmBCxabISMIpHyWh3AcOOt0iAgKDZjfIdsv+BscZmcK71qHeWfgDLDQlt4eKb0GddOAvfxU+5pXe8SKM2S8CuQ7ChP/zxzd1Jl/Mr7ejggov99BcpAti1rc+/l1Lsv8SddSP2ZUQ8SNDXu6/XPjfmk2Eko2KKHQb3Y; 25:/esRkhjAsOyDnzWu1I0LQQDM//7suwQfXqFr7yaBjj0PDM1PIzwaZazs+clge5ETXh2Ym/voUvVvDaGiLXrt6wcH3ovlAcdfQQzA4UdaGl9ztDCrBXldA5GjR7DZFAN2IpJwZcmJknrKvtGO9GIGqQfUC0Ct5nn9D6/DhoP3eacBWdrPtITtK91I0Z4f/jaIdPnsZeEkbhvlPtD1/eewNeL08/HknFZUG5ukWi9dNkBZkbaZdGd2rUjtUG3UUoUKVQuO/EJ2DjnlgjjsDnjJuC6tQrmqOnTxc6QuZbXRjATcSjsxPJLdpzoO21C0q59Qu9hshcU5tbVj0in3FR667w==; 31:kPW7xzKBgip+g1asj+xMOQlagq+h8Rzu3RJKkFmXkaAL5nnv/TCo2/hmyek86T7cbJTpEKvACf9NO+Kh396Imw0vFHlO0xTHEgVkvEPDt3LfYiPl+URRd9jdh5gBB4vQGgOGXRX2BvygtNfTU2NQaHf6GJ2PRz/i/OrNpWeT8Q8W49J8oJX8eviI7lEKyrW6n2HfTBi+QfDERaz9GqCbqAt9yjeYA5xRdIUinBEMo+A= X-MS-TrafficTypeDiagnostic: VI1PR0801MB1983: X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 20:NuIGvN7ZwUJUrrYUsK+0dej2J4DoQ8tKpJ82OtbDrb5iIoEHvxSK9JCtMPwHV8bNhMBjuwmP7GFt3Z4Pxfwes8TKroZN8mdn7+Y50XFbSVHVGmcys44GsrNekTGf7RXJuZ5adI3JnIMfIYcXWT4cvvlL+Hq0qWh5CczDf5wDosUxPc3B64yfym512neI9c7SeEdhuvCJo47BQFpmOmCNPL05Ubi5DOQ728SOdeL3HGBCIaWkP1ytKEPlUEp/v6Re24b4JKZLid8OzfnaX23VIgcVc6+7hVgXKb/SRcOj16JS6dHqF4Csgr7NIakeU4pliRhb/yTDPsYYYCaFl1ntu6kpVZJUzmMtIKHXphVOT8nrNv5Biq0H/O0hn/3WkLxO1fJH0EasGnFsFFPyAYDdSWvxD2ApKa9laUKhByJVnT8=; 4:qXxCtke1lWFTHk69r3+haYOfECAKrtCeu5SSwddH11TlzxZLfjYfCEF5bCgd2xta2QxYL1zu5NMN700SxxOfFrw+14V+1AbBlcFHmHA1AUZXLHtIyzaKKd1Z4zZnu5Ydktq4Cl7pAaV8CfhVxRlMw4X8ms2SVaBOWSE7eDfzdhwkAAmiF1YQ+MPWjI88HqI1HFwqWzgWLj5DPIRfwgH4ZTe8p+ydOFJa9LDj5/rF/CviUOvNIBE1WHWEdVcdpoyI1SOwBymoOTO+wPSV/j216g== 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)(6666003)(6916009)(76176011)(575784001)(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:PXS8OOnAzhiwXe0OL2fGmZOKL+2vRw6v8azIhOf?= =?us-ascii?Q?y/vJGsmUcYwGejEPLux5e5Al4UiQwMZGexwfju3NO7Hl3O6rAV8H2ZxWBIec?= =?us-ascii?Q?bpz9iAJ+9ch+ohYS0bw4NvMT+n1hk9AQ31Y16yd0Owr8bHIcNsmt1TDirXkn?= =?us-ascii?Q?rXJhCnGUzW540j/u11pjGwQvYrzf++LUPpLxVTc3OYOy6zPhHgAaf5t6v5jx?= =?us-ascii?Q?vVkwbANPRC94S+ZmeAAh+79BxdLejF4CWgEJNcT1TtI1yx7Viehi2AR5T/s6?= =?us-ascii?Q?Zbhxed638+IA4/pYZy7eweCfMWhwyh/HICV0DmSscZCH8fiRCXwORd1u6JL+?= =?us-ascii?Q?Z7EnOCF9/gllCtp8FEx/agYFyjR1KAZtG6lVy3rWkrDt+I051x25kL1hI0BS?= =?us-ascii?Q?jcdojYYvBp4ZQh4HaU59Icz8bHu3gEKqC14XUqe/Ia25QYpsBn5Z6a8QcYaK?= =?us-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?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 6:PslBzXjTfKZmHLSqVHMkO9nT9Pjo0H8IQhD7PUimAuFDl8QVFOn6Gw6VYmfPygM3o7QbdJu0LxuIV4XP+aFtYaoxg+S8qDkha9vFJSAcZsan1Sag2CEq1zI2tNhRxuQvpbFD4LX8YiOPEJgpqyL3TCBkxudnOFFAx6I+4ww9nSw0ELwKlgnrEmDYFta1SiFGs9OGEw4wcarg6Y7+eZMhHGB2pq+4t4gtJMQNuQA1jEsGXfYaiPjKZhGcYmq+s7KwVWn9piw40e+2Ye20D/YPcDf5CnWa41y9h46upRlNDbZY4sYbHfJ26JofiJMp0tR/Chv38sMDvnierAyAMROGgvpfYa9T5QdwTMkkFD3DCvE=; 5://M0w8AQN1zOWT2LRBQED+bhiObYY6X22aIl5CmpnYNCG46LWrN3+LkSfZZp4CveNx9zH3cCOL9NScq2noZZgPCwnKhQk+TqgJX6Y44XQInvgvroEKwMplfA6jplsHg/LEsDmawZbgb3Tj5XUECq95df25TGyzcK3djWxpWkddw=; 24:c2mg92A09s1z0jPYuW4kaBCXHQ9+z/K5ZWA8UOBimVKLKnPgBkB8T5oDMolD7aRPpDStoGQMuXbg3LF5qffWqiPmE1kAHZknEd45t4F1Dvg=; 7:590QxvAbYc6dI3mQwxJB9KMcoO4CVcO6gGxHONc+uPihj9PeAdyxX1nTEPxvMxVk78FiRMh7nRVcbb0X66xKxDgowTXflTRwUYztv+hXZwRzfBhgm/9wMJQzNmhMfjyz1pmjFXdN6nxwcWWHsNW24xAkeRKEeV/bpYm6SSLm9Hhof++H3W6ul+zowQfL4OV6bd2ctNJrU4L6MwUJJ3Y6uVcBw3PbuQYRCOm3z56YFYJclsE9o41R70m5HZHb8TLb SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 20:bPZN0z7RMgdWuN8VOJbFlXB99ZWMFN41xP8ntJfIlCu5usuiZB89ghGTjWPgwuuwXfzHw+nEr9V7vhLL+DzhzC41cOLHAv9qRa1ud+v+HUjhhoCZ+Om3Jgl501Zaf/okc8kn4zx9ZzAW3JT2WnITzq/hzTM0jR4tnp+rybiw/Hw= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2018 20:31:36.7158 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 74ddbd17-7263-4bb3-f5a3-08d56da0a049 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.120 Subject: [Qemu-devel] [RFC PATCH 18/34] hyperv: add support for KVM_HYPERV_EVENTFD 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 When setting up a notifier for Hyper-V event connection, attempt to use the KVM-assisted one first, and fall back to userspace handling of the hypercall if the kernel doesn't provide the requested feature. Signed-off-by: Roman Kagan --- include/sysemu/kvm.h | 1 + accel/kvm/kvm-all.c | 15 +++++++++++++++ target/i386/hyperv.c | 21 ++++++++++++++++++++- 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/include/sysemu/kvm.h b/include/sysemu/kvm.h index bbf12a1723..70ad0a54b7 100644 --- a/include/sysemu/kvm.h +++ b/include/sysemu/kvm.h @@ -496,6 +496,7 @@ void kvm_irqchip_set_qemuirq_gsi(KVMState *s, qemu_irq irq, int gsi); void kvm_pc_gsi_handler(void *opaque, int n, int level); void kvm_pc_setup_irq_routing(bool pci_enabled); void kvm_init_irq_routing(KVMState *s); +int kvm_set_hv_event_notifier(KVMState *s, uint32_t conn_id, EventNotifier *n); /** * kvm_arch_irqchip_create: diff --git a/accel/kvm/kvm-all.c b/accel/kvm/kvm-all.c index f290f487a5..c3ba87b701 100644 --- a/accel/kvm/kvm-all.c +++ b/accel/kvm/kvm-all.c @@ -1423,6 +1423,21 @@ static void kvm_irqchip_create(MachineState *machine, KVMState *s) s->gsimap = g_hash_table_new(g_direct_hash, g_direct_equal); } +int kvm_set_hv_event_notifier(KVMState *s, uint32_t conn_id, EventNotifier *n) +{ + struct kvm_hyperv_eventfd hvevfd = { + .conn_id = conn_id, + .fd = n ? event_notifier_get_fd(n) : -1, + .flags = n ? 0 : KVM_HYPERV_EVENTFD_DEASSIGN, + }; + + if (!kvm_check_extension(s, KVM_CAP_HYPERV_EVENTFD)) { + return -ENOSYS; + } + + return kvm_vm_ioctl(s, KVM_HYPERV_EVENTFD, &hvevfd); +} + /* Find number of supported CPUs using the recommended * procedure from the kernel API documentation to cope with * older kernels that may be missing capabilities. diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index e43cbb9322..63dcb23fa8 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -313,7 +313,8 @@ unlock: return ret; } -int hyperv_set_evt_notifier(uint32_t conn_id, EventNotifier *notifier) +static int hyperv_set_evt_notifier_userspace(uint32_t conn_id, + EventNotifier *notifier) { int ret; EvtHandler *eh; @@ -346,6 +347,24 @@ unlock: return ret; } +static bool hv_evt_notifier_userspace; + +int hyperv_set_evt_notifier(uint32_t conn_id, EventNotifier *notifier) +{ + if (!hv_evt_notifier_userspace) { + int ret = kvm_set_hv_event_notifier(kvm_state, conn_id, notifier); + if (ret != -ENOSYS) { + return ret; + } + + hv_evt_notifier_userspace = true; + warn_report("Hyper-V event signaling in KVM not supported; " + "using slower userspace hypercall processing"); + } + + return hyperv_set_evt_notifier_userspace(conn_id, notifier); +} + static uint64_t hvcall_post_message(uint64_t param, bool fast) { uint64_t ret;