From patchwork Tue Feb 6 20:30:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10204131 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 9851860247 for ; Tue, 6 Feb 2018 21:18:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BCF0289EE for ; Tue, 6 Feb 2018 21:18:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7ECAA28A70; Tue, 6 Feb 2018 21:18:13 +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 A8DCA289EE for ; Tue, 6 Feb 2018 21:18:12 +0000 (UTC) Received: from localhost ([::1]:35221 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejAd1-0005bL-DY for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Feb 2018 16:18:11 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44736) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej9tu-0000qw-8p for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ej9tr-00038x-Gx for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:34 -0500 Received: from mail-eopbgr00096.outbound.protection.outlook.com ([40.107.0.96]:29741 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 1ej9tr-00037n-4A for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31: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=b/nGWI46PYRXW9WpjdHnEyPBvE3ovz5On+nlIyh+Nt4=; b=Ekvd5wvyIdGBBhU6NdkbI/oMY+PrUM2c9M1TTWwKfYkvu27bQpzFBPKlcwS00j3zTPTzHKjIbpDZx6vbrFfEk0FJEzov+tNEfk+I1GXopczqgXNSboLiRjul80Gop35WuicNa4hlH7dZq9Phv2NYQSi/J//9T+Trk1GzauOmSsE= 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:27 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Tue, 6 Feb 2018 23:30:27 +0300 Message-Id: <20180206203048.11096-14-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: b55302f5-2d19-4f89-6167-08d56da09a05 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:Ekbeez63ENOUkZOV3KZEwrigR/0bjtUc0e8gx0JPbCEEolhc+dS8+Sn74VCGIs/vpNB9Lvt5+b3rnbavOvFja+5KZpGzJtvSkAx7w3vYhY40+mW249EneJFwUVS1DukZFA9pEx7bHvmL4A3rvUsoCurHb9WhtSd35w1D9TgYIOuIv/8KmsNXOlWS7Zq7Ge81YFlenVLtv6RLO97puFpMVkfMg559aukccmwS1+BOKmRq1kaBVRxeIvmKn7R2lUL+; 25:DFCzmXLthMgeR5ghYTbokjFj3Zrt4VK6XoBfSEURRcotcLdYctIUfXs/plVNm68bmwdjW+a/klvuRXrjQ7UJkBq3wPGM0g/rqpJTLZ7GMZ8yCLlSP8NUF2Wd+GQB/jfIXRsC5U1aIc7a95uCZD/vv0A3FikYVjS4icZ1sFSjo1GQQzJcUQKUoYntztJpCKENKVnMig40WTM4e2s9dTrtbbmkb5h+x7HdfEdAZIddDOYHJHF3EnhmVdUGdn5UjSv9+PZ6G97kmmkxbsWKhH7PyJredeHnewYxPbsGIk1+TtUJSYTlSvUOgqUyPnJYe81KAEPcnYrhKYqaK3Gb3TEjFQ==; 31:bD4L8x5XdJkcOLmN1uUm86bxCAvCbb2o87S7VcoUeKS7/2Or97Wl5XDmM1bBWpcjIkvssFle8q3YBPEERWoNP6zoirtdo8GNggsuLOg9bV+TpnWIQDzcbexnNPlVEpuvSoKi6spo6+f7LSc0kvVfs6raZe7Gil0Z0qN53NNafLZqApC0ICxnAiNH+rnMR9BjnkMN2bFc/JZWKXM/gT3rayUB/ql0t9jbCU8e04uCKVo= X-MS-TrafficTypeDiagnostic: VI1PR0801MB1983: X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 20:kbBXyM4RQlSYE0GSrbFaJj6FDI4s9ps7p+xi5OJnogIFFwt741mA6IeoykayXccrpO8/GK9pFFVITaiXO2pcdUhZkHuR2Vr3M4G0PjIm7D+R5hlZSPxxKn4orFBSYV+y41G4+M2YjDdcIaz6aSySweWMJYrJvW8qXhVdSMZCem6bw4dysHQbEd4GSZMg0pllE4SEpYKbAIm7LO0xphhV+K9FUrN0+hmVZX2Lb7gmnQei6SYAboJpUrkOLCi2FAfqAke9H1YI0eyzSg8ZY/E1ab+yL5bIWry2GG59hssfju5C6x8FuPKU3ved8NVYqf14Qele6r1cgHhGprtGx4a6kEEwkHsuoRjgynbwZ73S+2JLG5ogsweXv3IbhxiX69Su6YHCnNOSAkNTVEwjA+DYJjooaNxs2qvGJouggYaa/uY=; 4:sNrsAtxaBBjlmML/WOsSRwL+3ZZE1G1Pb+Ojt5GI9ShQMfjbR4ISNzdnjUNGd10lQLlXjA6uZghRm/hMoFXYMt/fXIIUC12KSWUJ9sq0HoT+1BrGoVusxtx1CaQjWJAW9iBzH03ODB7C81jITSfsBxyGZLSb0ewKJ4mhBIBmtMLKQFT1SAUdEfHilaZRnjgRe7ohcDw5z+sQxVJTYOd9jNJAObsgL+d9+n6DhJXmFby8CteeE1nIoIOnPYCfkeeMTcKhM5FBxVYXDt/stpLCCQ== 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:SAzIJFDMqCgIxIdQ9aEV/TLZQH5AZbEeBd9yFPU?= =?us-ascii?Q?sanQZUIF5/3YN98n9u5urzGaFn4PvWAZWRn8/rJjYNFDRXYxOyGREA8ShduI?= =?us-ascii?Q?tWUSu5YZOk17SyWuQq7chDAJEJNUJUE/3hseIVgjVkM6/DtfHGplRQJkxCt1?= =?us-ascii?Q?7kVVvT15zh2bxWtkIb+QjLHgIjLFRijOJYmqy9nNgFZbuhLZ9TJSRpwlIMqX?= =?us-ascii?Q?9j41BV9+vPtWD9pzxDpdRuKK7iVCA9J4aiIvvR+Lexw+9BMvbcBGt0xH25px?= =?us-ascii?Q?UqrxU3j7y9qBeOzUQLo5h+ceqdxh1nhXu2WFuEQE6hbcsYyTKe4J5zVnVLo+?= =?us-ascii?Q?j37ioAkXoLiZNtXC6Yp4wlE172RViOlim42VOxiJS8Sj9CKUbHsctksMJUVn?= =?us-ascii?Q?Z7DyGOojZDsaj9LrHswwUjNLRTsBhqlyKyEkKY9eCS5HOOTeCyZfie3Am7YW?= =?us-ascii?Q?3g9a39tW9Pg0Iv+z6MgfjLELNDHApcbicEJhrGxP6EWDvIxmxdsNPJlCgeRJ?= =?us-ascii?Q?l8YeCnL4uOeknISUR6qsxwWQRS8JyRugCai9/OrNVgmU1lmVQ100bdrcO2My?= =?us-ascii?Q?IPwj1iUohIHoAQbBVBx+dr35moW05lVryBI9FZGvGcos9MoQqg4tibpkjWRy?= =?us-ascii?Q?Wwdy37J4yqkXxPCNzefLJjkCMOyobK4v4JS2pqQGOeR2Jvca+2p2JgBMVvGX?= =?us-ascii?Q?bFawO/pDqPk+0SHwend1R5wv54VI3nlhZL5TqXZbqSDZesYiIz+F8Q8BMmUo?= =?us-ascii?Q?xYxP+oVlLCYtApS3L76CEGt2Ptftp1HhLEUL4SmLJcBirZ2F7xA9uG4tlJlO?= =?us-ascii?Q?Bp7CAVt+f9Jy/TameSS6cx/MhHuZqC9Zc3SpNec2lUcGx+llab8BAno//WJm?= =?us-ascii?Q?kJt5iDKDGfPN+UPPLx0VT6T6EJi6yy1PwPfzFA8V7/yAUpcXB2iXLc3kNK+c?= =?us-ascii?Q?6LqIkWrT9yjetIccGv06P/8lmzHQKVvM3g2Ut2o8Ylfw3syV2jBSlmeSs6bu?= =?us-ascii?Q?N2FHhDt8EVKN2sqI9QqJNAKi7olSwduC4VfFx/WqWeo9jlMX+Ud4yr2i4l6p?= =?us-ascii?Q?v/B5+eZoJpljQfhdx3WWlpAN2izfHRL5eWYf9xleH8P36NsT+9qSSJOdvXU7?= =?us-ascii?Q?NnbKjEeyNWNg9/RWUP03T79ppRKPujPmnqFSR/cYT8+935XbsmYf73mslocA?= =?us-ascii?Q?d4bJb1t9ExBFetjGekr893dm/+HynXPJfpO2maqIT1x5dt6UuFglYa7KtyGJ?= =?us-ascii?Q?C6AEgVtehnR8cJpsJ9HcmmNd5tEMVBGxKZa3e03qT+9Q6SuB10lqzhBsWpj+?= =?us-ascii?Q?A3g=3D=3D?= X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 6:46C9Noyd7IvI03EismJ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/u/SSVfYVIeEvYJK9WcoNUw/L4F0DW0aaSlFdHnGmyUquN2DMUKvhIsops5c3q2JI= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2018 20:31:27.4031 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b55302f5-2d19-4f89-6167-08d56da09a05 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.96 Subject: [Qemu-devel] [RFC PATCH 13/34] hyperv: process SIGNAL_EVENT hypercall 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 Add handling of SIGNAL_EVENT hypercall. For that, provide an interface to associate an EventNotifier with an event connection number, so that it's signaled when the SIGNAL_EVENT hypercall with the matching parameters is called by the guest. TODO: we should be able to move this to KVM and avoid expensive user exit just to look up an eventfd by connection number and signal it. Signed-off-by: Roman Kagan --- target/i386/hyperv.h | 2 + target/i386/hyperv.c | 113 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 111 insertions(+), 4 deletions(-) diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h index 3d942e5524..4ce41fe314 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -43,4 +43,6 @@ int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *msg); int hyperv_set_evt_flag(HvSintRoute *sint_route, unsigned evtno); +int hyperv_set_evt_notifier(uint32_t conn_id, EventNotifier *notifier); + #endif diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index b557cd5d5d..9cf1225385 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -19,6 +19,9 @@ #include "exec/address-spaces.h" #include "sysemu/cpus.h" #include "qemu/bitops.h" +#include "qemu/queue.h" +#include "qemu/rcu.h" +#include "qemu/rcu_queue.h" #include "migration/vmstate.h" #include "hyperv.h" #include "hyperv-proto.h" @@ -249,6 +252,106 @@ static void async_synic_update(CPUState *cs, run_on_cpu_data data) qemu_mutex_unlock_iothread(); } +typedef struct EvtHandler { + struct rcu_head rcu; + QLIST_ENTRY(EvtHandler) le; + uint32_t conn_id; + EventNotifier *notifier; +} EvtHandler; + +static QLIST_HEAD(, EvtHandler) evt_handlers; +static QemuMutex handlers_mutex; + +static void __attribute__((constructor)) hv_init(void) +{ + QLIST_INIT(&evt_handlers); + qemu_mutex_init(&handlers_mutex); +} + +int hyperv_set_evt_notifier(uint32_t conn_id, EventNotifier *notifier) +{ + int ret; + EvtHandler *eh; + + qemu_mutex_lock(&handlers_mutex); + QLIST_FOREACH(eh, &evt_handlers, le) { + if (eh->conn_id == conn_id) { + if (notifier) { + ret = -EEXIST; + } else { + QLIST_REMOVE_RCU(eh, le); + g_free_rcu(eh, rcu); + ret = 0; + } + goto unlock; + } + } + + if (notifier) { + eh = g_new(EvtHandler, 1); + eh->conn_id = conn_id; + eh->notifier = notifier; + QLIST_INSERT_HEAD_RCU(&evt_handlers, eh, le); + ret = 0; + } else { + ret = -ENOENT; + } +unlock: + qemu_mutex_unlock(&handlers_mutex); + return ret; +} + +static uint64_t sigevent_params(hwaddr addr, uint32_t *conn_id) +{ + uint64_t ret; + hwaddr len; + struct hyperv_signal_event_input *msg; + + if (addr & (__alignof__(*msg) - 1)) { + return HV_STATUS_INVALID_ALIGNMENT; + } + + len = sizeof(*msg); + msg = cpu_physical_memory_map(addr, &len, 0); + if (len < sizeof(*msg)) { + ret = HV_STATUS_INSUFFICIENT_MEMORY; + } else { + *conn_id = (msg->connection_id & HV_CONNECTION_ID_MASK) + + msg->flag_number; + ret = 0; + } + cpu_physical_memory_unmap(msg, len, 0, 0); + return ret; +} + +static uint64_t hvcall_signal_event(uint64_t param, bool fast) +{ + uint64_t ret; + uint32_t conn_id; + EvtHandler *eh; + + if (likely(fast)) { + conn_id = (param & 0xffffffff) + ((param >> 32) & 0xffff); + } else { + ret = sigevent_params(param, &conn_id); + if (ret) { + return ret; + } + } + + ret = HV_STATUS_INVALID_CONNECTION_ID; + rcu_read_lock(); + QLIST_FOREACH_RCU(eh, &evt_handlers, le) { + if (eh->conn_id == conn_id) { + event_notifier_set(eh->notifier); + ret = 0; + break; + } + } + rcu_read_unlock(); + return ret; +} + int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) { CPUX86State *env = &cpu->env; @@ -281,16 +384,18 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) RUN_ON_CPU_HOST_PTR(get_synic(cpu))); return 0; case KVM_EXIT_HYPERV_HCALL: { - uint16_t code; + uint16_t code = exit->u.hcall.input & 0xffff; + bool fast = exit->u.hcall.input & HV_HYPERCALL_FAST; + uint64_t param = exit->u.hcall.params[0]; - code = exit->u.hcall.input & 0xffff; switch (code) { - case HV_POST_MESSAGE: case HV_SIGNAL_EVENT: + exit->u.hcall.result = hvcall_signal_event(param, fast); + break; default: exit->u.hcall.result = HV_STATUS_INVALID_HYPERCALL_CODE; - return 0; } + return 0; } default: return -1;