From patchwork Tue Jun 6 18:19:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 9769599 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 8BF666035D for ; Tue, 6 Jun 2017 18:33:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 849C0283BE for ; Tue, 6 Jun 2017 18:33:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7856F28415; Tue, 6 Jun 2017 18:33:38 +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 9F528283BE for ; Tue, 6 Jun 2017 18:33:37 +0000 (UTC) Received: from localhost ([::1]:39678 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIJIO-0000Lv-N9 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Jun 2017 14:33:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47595) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIJ5a-00062o-HK for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:24 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIJ5V-0007PS-SB for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:22 -0400 Received: from mail-eopbgr30121.outbound.protection.outlook.com ([40.107.3.121]:59392 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 1dIJ5V-0007PE-Go for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:17 -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=I2aZE0/gmd9n0bYTFXcZup7bHoEnw4CpWuiRTDDrNlI=; b=BwFA9dJX//20T+/giDt2h5oqDS4y9IRgZhDJWA+Yde9m1+KDKlxcExQIOxiwfs/mlR9Bfmd7wraiMDhxVplEw39Yx7lbeTxrfLoQXbUkhIR+e1t7x+PrrpCZzoq/F0armUcdFUvjYtEPjRcpvYnC3qM0wtSXybOB5ojaharNeAE= 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:20:14 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Tue, 6 Jun 2017 21:19:44 +0300 Message-Id: <20170606181948.16238-20-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: 7f0d432f-36a4-47b3-4cb0-08d4ad08adbf X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:VI1PR08MB0847; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 3:uxx+MmYsCQwnCKbpeZYCUZ1sJGM/DuteYRyZdsgqIOf7XpBrrmgqn+0qZGNksKEiJObYfcqHBRfK7OGMD3vbEQ97PO929FgBs0RsYrMK1y2UxdrNRtMeJhzNOk8RaP+cuFPOpHhXEplJPJvMdpPUrWO3Y/+F+GT4OCiJ2I0GVLX0zl5Kh/FXj30zT+LWsHpcMMAByzkYd0yUPlGRQCp1PpDJyH1+BT6fdDxVQXTu5yBk+fy5GwQd/AxqKaqSnLejYKGFzVn1MmkzAHnxg0i8LyueopziqHaobAmfOp3C+YHpGrFcHLqNKs/IyDfh/81ksivj5sitx+4pgP/PJRGSew==; 25:YBr65k5onTOak4LmVmojItYg+uXUX/DdIMnvmM8rHMXuS9eo76Ge+5/KnRD8uiw1chy4x7Pfy+ZI4IFotDU3uZ5vT73+D5NDmRNh2a1G+YrNGwnaROgV7rQRphEWMR0n8SsfNrooi70tr7ryiCgRq+pXKveMdXS+6msfZrWyKT79kKFKclqETyZh9jB/9L5DhCYtGoDabgN+vK9BfVEAiJ9AFIzLJZRUnZs/iGjo4mm7kxMS7zt6J1Uibm8z4daIMF9RVG30nIRXGE0s5OzoGOgd0/j51SnnkUA6aXMhBs3xg+9xEbSCaAL82QBJGCZbPjBzpLOrAXptVTafxod+A1skf5QPjFukjaV0RfAHzXZUlxPpyi4lJcGJnVy8sCo0bWXP7+Gm3mwZ5kRBzUfw5ow+BUUMuFKA5xd7qyHXXDD3FcKji3nZpPznRIX6suMtEFBhCSc9Vu7Clcr4+tvSY2lOS2QfT0pBnG1PNsRj1ME= X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 31:hyX42vouFbV1xLN5oWoJuSsBm1XX1Gs5GQkseav9lsBlE+otwC2JJcZKuHWdBgPCa/zfvOo4uRmm2JkLHMPVp1OiqAJaVLE+22xZ86J1mLw8/I2xNNuDw+YdY6seFV1ViApvgKxSwzqpnnNUwsqSVZkrmREaUxySelwddzT6PNCzB1/UO+pKWI+4uY9mqqSgtIhWLg/QGe1RJa/5kV60YsaTPGVXYACnbfMXO9u1VXo=; 20:WvDhSXpdMhblW0uNvRIJCbSLGmkk/qJX1LWzyyhKnjnZDlpT4Fv4oHwcws1Wct+z4/bwnu0ZcDdlRlzqSFcM8JcskPJv8p6tDRLAosqpAB4VgH8Iyz4Ef41LOTbUf/hKfRvdQ4JyJkniB4oW7DZZYnLRZXtSsW7ruKPx8H1XYxKcvVJBmMpriBbmZpnjKTxIAICIlS3b9GdCWTMlhVrapY7pyzWARlj+kj7P3IsBCbhFkeWz0tYcqnSM/O9iAw3VrPYAZ1lnYyBwhpXhq2mNF2wujxRlWc9PjxXB98Z+Y2wHzukKOVTUyyl1EnVdj1or3Y8258A8VL8QM2vkUuB30XyUii0hD1Kvb3PaWXvBdu6ALIaTthBVt106ymNVhU6XZbeLjkeMb4vb8ATZtCsaRFOr/pl70/wTUInsg/ZsXxk= 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:VI1PR08MB0847; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; VI1PR08MB0847; 4:JN+2M/20gMEqUvjHuyeguj52GBLabQWcxmd7bTcMjZ?= =?us-ascii?Q?eaqXeIHMjI9K4RyjX1j7rC46IS5EXMvzsP2GL/6tzrYStWpn5aoG0fExS6SX?= =?us-ascii?Q?sP+lT1bkrvhMJuB7N9+naQPuO+AAn3eLaqdAuYpIxeHrMkNRrDcYd73123OV?= =?us-ascii?Q?GZXyNVpThdf5dzJwt4wIJngx52a9hxMGi0IZBuccy4Dup+8y7l0FjxxKaorI?= =?us-ascii?Q?ZkmYfh4QfSgULikd7fSQq7dhyBPWCqEp8J+to9lyDI1QJm0CeCv/byo5TtM6?= =?us-ascii?Q?rY8ux+1RhrkKJoreu1duH8LczoeyYLWYv5B6n7qhEbkN1FAlBvDLG4qchAm6?= =?us-ascii?Q?i7Yl1n2q8D0Q2onjR0nra1/IDIl/9IUz8FMUL5MA1PYp4Pe4n1VXseO3NJ+V?= =?us-ascii?Q?OF/r/JzxMBGGdLp1clgoJFBzJ1F7nwqJgF5DKIkpGgNiDog11p1GgttpfN+U?= =?us-ascii?Q?z15ChVRlfmYBBlI6jx3o5PV13oKPmlWZKJViKICZkKIGaFWkAS+7KDbJoqAJ?= =?us-ascii?Q?1XCdTXhm5dxJAQ+qOGNoRapxV+3mJWfjz2Qwjebj1pNFNplKQtmPY387TYXm?= =?us-ascii?Q?dWTnYiBpZ4OGWSspfbuN/LtK1IXM/eYKNb0Wq0tRs/s9ItqFcKrO+Sg/zcVM?= =?us-ascii?Q?3uBhY6gck32inLc8yfYObnfwFuHV3tuNI5bDK7BbEEf6nZKQ3XlQ7S7DXDBy?= =?us-ascii?Q?suUdfeC4sUhuuqg7+wZxRRfcEair2JRArXDhnXmH1acHectVXqdpwVqfsqX2?= =?us-ascii?Q?6EeAD6ImeZZ0EZlw/GLw6IV2aJ6hSRN290LiwsIoKAJhr5brxH6RjuXjRnVd?= =?us-ascii?Q?rKGDQ3/WS5PMrSN5AKyrRsKW5nY4nM3O8k8SgHpLMRu9NjeC0e9DNJD3b9YL?= =?us-ascii?Q?voOu+lWInTVQE6y3u6XpOlp/bCrxH7ry2vAehd++Jo6iRc7sHM2I9fLUOjjN?= =?us-ascii?Q?S+HSVpNy8ob6Xvm6G1oAPccidINg2xw+45YQGfStfJFkl31OcgJhvWY6fCZG?= =?us-ascii?Q?xYJXtqdy68NSy2UOkFFYTtiUcoFltofFB1ecAgJrRsiJgtxUELiXI8lWYc3m?= =?us-ascii?Q?kMEfp7ArvAEufSPgvzQVxEPQlQTxDtuE4Li2iU5pVPD5ewStD3nwPJNfHU+W?= =?us-ascii?Q?9TnFjTXW5ooK5eQ/9Ue0G5+boHQ8dI?= 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)(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:qIRSBzLW5fv5t43D2Isvsz/ixk2kLTXd1HQfxeWjC?= =?us-ascii?Q?8brKYd9QzEW4LYjqAXi0lk9NJCBz4FYIwzj0EXiR6D+wc7vMXzPhA33J30cJ?= =?us-ascii?Q?DmK9T10GFGLAuK4DBOUFn2jPaJHWOUX/e1cy8ISHxZR64QmDHnNjEnrReAzP?= =?us-ascii?Q?mqNE4OufgV4a/3yiPgJv9t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o3qREk32ziDsX5jBg80PqWn/dJcuj+JEbdAi8mYLpfTVC0puJFdJGZmF0n7g31WRQgKYYod9q4dngqyF4+TcNiyoiNFHyNJIlfSCCWPNPANqXKOK8Hz/oTaY91; 24:tA8KJvJNp7AjvRfR7g83CU9t6Y5JAKh304034D55Pq8i23sqreeiJJ3FdRp56s/MpRu3Msh1Mq6xsYH6UPtTbdUfy4KaUJR9t7HdNIL0uxo= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 7:QXWtNUMlPhqRq1nNwcToXC8Ypi7H3tB8ufj7DPeGnhiWacgH3hEM8JkboNOSCUy49OlhE0P9MKIgQf2hhF1Olq3jkL9a6dviFLSlQ0jG8Os4VvqoA0o+hqgIKSlRyxEFssSnuydaaIyf1y4Bu1SyooIa1EE/TdLWFQWzZ0TORb5ffRoxZXO+DYe17YoZ/g11fFPMzM+s3kvjogIW2s7YGOFLzZfLKK611A/FrpeGkKveRzG1DKLXePoSfAiPPurgumA2PtTg9JYYlxfeTq3vioFMxiSAsSBw1Nuwze/ki8WfWh8m5uSeYwSHJmNojJnfqY/ZfXf+VJQBds8V9lfo6w==; 20:BPTvxXlLXYv0bti49toyIz+xBU4gVbDA2yqSe7g32V5z+GS5XBbGRN96vXCy51RmHH6xKhowI9D5IzDPFt1bKIZ80DtppK0UpKxmXMX1I5p10RPvjBRkuTcv93a5/+Yoiv/JRmzlQYNiJhuCUUExOGXpXjR0x2b+CDSXemVdiTM= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2017 18:20:14.5077 (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.121 Subject: [Qemu-devel] [PATCH 19/23] 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: 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 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 a2d4304..d2630ac 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -41,4 +41,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 dcf49e4..030184e 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -18,6 +18,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" @@ -229,6 +232,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 evt_handlers_mutex; + +static void __attribute__((constructor)) hv_init(void) +{ + QLIST_INIT(&evt_handlers); + qemu_mutex_init(&evt_handlers_mutex); +} + +int hyperv_set_evt_notifier(uint32_t conn_id, EventNotifier *notifier) +{ + int ret; + EvtHandler *eh; + + qemu_mutex_lock(&evt_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(&evt_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; @@ -256,16 +359,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;