From patchwork Tue Feb 6 20:30:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10204087 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 2F56E601A1 for ; Tue, 6 Feb 2018 21:00:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2729A28CD0 for ; Tue, 6 Feb 2018 21:00:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B9D628D1A; Tue, 6 Feb 2018 21:00:37 +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 55A9128CD0 for ; Tue, 6 Feb 2018 21:00:36 +0000 (UTC) Received: from localhost ([::1]:33600 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ejALz-0005O1-DT for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Feb 2018 16:00:35 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44772) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ej9tx-0000uK-1k for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ej9tt-00039n-Ly for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:37 -0500 Received: from mail-eopbgr00092.outbound.protection.outlook.com ([40.107.0.92]:23240 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 1ej9tt-00039J-Bf for qemu-devel@nongnu.org; Tue, 06 Feb 2018 15:31:33 -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=VxUZBSjLTiUsgL5mvmFLLYKdnauB0r6p23zuys97A+8=; b=Gxh1CsBFeSWkBBWmsN36UjyQ8+Xom6G8gVMR9obvBXDsJRjBPswa8cE+hKBhUEOxpVah/hlJeZ2HHyJLA++bRvfLCJbTEtBCI25LmD7FLfGfOXW+X6mABvIGj0enTayJ+I/KOuwyRW4D6kzgcocyr3OxZn241Vldu69vvIoQwI4= 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:29 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Tue, 6 Feb 2018 23:30:28 +0300 Message-Id: <20180206203048.11096-15-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: a16fb1cb-e0a3-4c39-7c93-08d56da09b23 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:SxViIqLAY83+V2/S6q934YXDBPpv+uvPmlZZv5w0YVIEsyqW57lkmQkDdTBvZvuZMCxh9Ajpy9K+NAUj+8lUhV84Lv5YHbixSVli/MrVFAG2hy5Ah5RMLVeswRhvWIRd7RngfrLT90JIFby3uPFTTkEM8iI9sOePdwV/8sX0aTL/yY6E+T436nYS8xn8sb9J6MB/ruJ/JDG5j14U6b6IshAeMIIfYn3pxPCiRGAtIkDDkcRTCu4EnTFHqGx0uijT; 25:JFiHS8AoZlqrlLNbLnRG8TP9WkXMD8t14tCC1uBu9Tr11HkPHTMmXhHww+tzwlTyBoXPEAsUZ9p1aW7D159w8rfXYrol9Zrz0l3Cn6YalwngpUSg/sTtoNuE4K/Ot1iqJn78+IqAjULLoKI/fOAR5kOQ0kpyv6r6gUtd/uv436KondF6Hii2sIiv9cvKkKBuBJL9zJ3RrhZSnWbPjmGml5GVfp3XjPDjB/ZLJqtEizzjyt5foqS5hWudSyUl1H5wIrUsef5tIfSatP5mQSRxLtkv8F/y6PDc5OB16ld0qh/WXbJIy6b99/xbJkUBQJIF5Bqd6HyMIrmTl4bs0x+Cpw==; 31:2T4CCrX/4Ha4Qh+xx/iSf6C+SBB9OVQMf/48U+4bBxQPMNsFnGjkOHa4V6L+Nf6on9ihJ6+GyiGEiYl80KXOHplR7Ro8M384yhoj1Y4B8lgCiVI38dg5tcnqdgEwmOpNr2lnQsWOgHlZmZCUGImJe4NgfrxJXAkPMWsa7oWbNgNL3Wkg0Tt8OE5hCvcYBwEJ3Fy0SiLHqigbzxp7GXPjsKRl9acip6rmgFkVh+VXkm4= X-MS-TrafficTypeDiagnostic: VI1PR0801MB1983: X-Microsoft-Exchange-Diagnostics: 1; VI1PR0801MB1983; 20:IpyNqbjYB6TcAOjVgRQxy3Dh73BtkQQLWQ7VHq/aNLoW1QWr7oV6jPVu587j7IUv/E1MUHGBjE8KWa8w2qfAQg7cbnLTGCX7pcFjBOhNW8Czvu0rdQ5/7yr/AiTFGFDk1jJcugV5KnOJdy54izNMxTonCfKnYV6p0sBkJdotkw+645czCkmFJxMIFYNii0+rBqiuahahISzEVJ5IdQbdNDl1bup9tXSNP0UWKbv1y/+Ls3p5NGkVjp6D2im+j8z0zyg9XQHEh7l8VwZkKxbne8kEEekKpbp/N3IBGWAuEaojfjDZwba96wSuQl37nfSNO6MEKLiCah9ZMOI05A0tVQf/QVMXAcEYWipI+4Fda3ilmeHgA1Ya5L0D1lghqR3/7uSHW8bxZvET5XtU2XgnKeJQPdEGeypzQj1jZ8Qu2Zo=; 4:aLcJ55513RGAVAUbx78DvS64Fvvm+TiViZsPLckRzoMuWvQH+G4oE1WTTH5q5y5IDNttI46iRXQS7Xs69OCo6sg4xEn6fhR2JrIDySGxfihHCO4p2etXq8tpkdu6yzURaMWCZPQjitzxAyTX/ugQckmReKAiDT5G0wpfCcxvWjkXAD65zxwPraoapGwDuV0l9DF/TEtDuq4Kz9Q813+pAi4hJLQZMcwHRWdAiYadB1uUt9a998j0gcJHF1NqHXVSVa/1GoAnZu3i5gEU7xCiGg== 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:ptrAJhyTYxJ4QhizDugx4Fk81SJlEPLt+deYe5Q?= =?us-ascii?Q?yImBMW2JhZHkhg4kOyvoHlkaKDKactH/LRwzh5hAhvpFp/IToFiMlsLYXqxx?= =?us-ascii?Q?FYSfjMMTX23XIiQZgh2NDBN/AX65VV7jU7ZYX0MRodH7EhtcH1/ly5/93M0S?= =?us-ascii?Q?W+3+a2kixQiZygsL9JhooD5/s9RXeckpKEqe6aQceIgOoViXDojtGeDhP6bW?= =?us-ascii?Q?j4xhazpWZlMIbGKRvoFUX/DRajwGYmFbuCJXtOnLG3MEwZnh5n2x0eN5LSsl?= =?us-ascii?Q?5C2xRPY6L3NTub0aGBCJ9u4sw6XZKNCLqGBVYzYPTdGPPThfhURrPOQYkPSJ?= =?us-ascii?Q?uMSCcErniMHV5FRZcTuJgjT9Le45I0J0e/Y/EO1IIBO/C09u5YVzMNIJ70qh?= =?us-ascii?Q?Il/FaJx8re+r7MD/xITfhrhdy+9saVV9GP6IOXZNHgM7Yt1x7uKlSy+u3K9i?= =?us-ascii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+KAtBwlJThMS7SzVqhH5T6s3sAhbVjruXWSYiWMNdXyo0zkPPRyD8eqjr/ksCuuNuZfgsMk0G6ODi5qnhzZMZP9FFPvm+7nvgseUwgXQ= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Feb 2018 20:31:29.5594 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a16fb1cb-e0a3-4c39-7c93-08d56da09b23 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.92 Subject: [Qemu-devel] [RFC PATCH 14/34] hyperv: process POST_MESSAGE 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 POST_MESSAGE hypercall. For that, add an interface to regsiter a handler for the messages arrived from the guest on a particular connection id (IOW set up a message connection in Hyper-V speak). Signed-off-by: Roman Kagan --- target/i386/hyperv.h | 5 +++ target/i386/hyperv.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 92 insertions(+) diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h index 4ce41fe314..fcc41caf1f 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -43,6 +43,11 @@ int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *msg); int hyperv_set_evt_flag(HvSintRoute *sint_route, unsigned evtno); +struct hyperv_post_message_input; +typedef uint64_t (*HvMsgHandler)(const struct hyperv_post_message_input *msg, + void *data); +int hyperv_set_msg_handler(uint32_t conn_id, HvMsgHandler handler, void *data); + 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 9cf1225385..3dc8a7acb0 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -252,6 +252,14 @@ static void async_synic_update(CPUState *cs, run_on_cpu_data data) qemu_mutex_unlock_iothread(); } +typedef struct MsgHandler { + struct rcu_head rcu; + QLIST_ENTRY(MsgHandler) le; + uint32_t conn_id; + HvMsgHandler handler; + void *data; +} MsgHandler; + typedef struct EvtHandler { struct rcu_head rcu; QLIST_ENTRY(EvtHandler) le; @@ -259,15 +267,51 @@ typedef struct EvtHandler { EventNotifier *notifier; } EvtHandler; +static QLIST_HEAD(, MsgHandler) msg_handlers; static QLIST_HEAD(, EvtHandler) evt_handlers; static QemuMutex handlers_mutex; static void __attribute__((constructor)) hv_init(void) { + QLIST_INIT(&msg_handlers); QLIST_INIT(&evt_handlers); qemu_mutex_init(&handlers_mutex); } +int hyperv_set_msg_handler(uint32_t conn_id, HvMsgHandler handler, void *data) +{ + int ret; + MsgHandler *mh; + + qemu_mutex_lock(&handlers_mutex); + QLIST_FOREACH(mh, &msg_handlers, le) { + if (mh->conn_id == conn_id) { + if (handler) { + ret = -EEXIST; + } else { + QLIST_REMOVE_RCU(mh, le); + g_free_rcu(mh, rcu); + ret = 0; + } + goto unlock; + } + } + + if (handler) { + mh = g_new(MsgHandler, 1); + mh->conn_id = conn_id; + mh->handler = handler; + mh->data = data; + QLIST_INSERT_HEAD_RCU(&msg_handlers, mh, le); + ret = 0; + } else { + ret = -ENOENT; + } +unlock: + qemu_mutex_unlock(&handlers_mutex); + return ret; +} + int hyperv_set_evt_notifier(uint32_t conn_id, EventNotifier *notifier) { int ret; @@ -301,6 +345,46 @@ unlock: return ret; } +static uint64_t hvcall_post_message(uint64_t param, bool fast) +{ + uint64_t ret; + hwaddr len; + struct hyperv_post_message_input *msg; + MsgHandler *mh; + + if (fast) { + return HV_STATUS_INVALID_HYPERCALL_CODE; + } + if (param & (__alignof__(*msg) - 1)) { + return HV_STATUS_INVALID_ALIGNMENT; + } + + len = sizeof(*msg); + msg = cpu_physical_memory_map(param, &len, 0); + if (len < sizeof(*msg)) { + ret = HV_STATUS_INSUFFICIENT_MEMORY; + goto unmap; + } + if (msg->payload_size > sizeof(msg->payload)) { + ret = HV_STATUS_INVALID_HYPERCALL_INPUT; + goto unmap; + } + + ret = HV_STATUS_INVALID_CONNECTION_ID; + rcu_read_lock(); + QLIST_FOREACH_RCU(mh, &msg_handlers, le) { + if (mh->conn_id == (msg->connection_id & HV_CONNECTION_ID_MASK)) { + ret = mh->handler(msg, mh->data); + break; + } + } + rcu_read_unlock(); + +unmap: + cpu_physical_memory_unmap(msg, len, 0, 0); + return ret; +} + static uint64_t sigevent_params(hwaddr addr, uint32_t *conn_id) { uint64_t ret; @@ -389,6 +473,9 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) uint64_t param = exit->u.hcall.params[0]; switch (code) { + case HV_POST_MESSAGE: + exit->u.hcall.result = hvcall_post_message(param, fast); + break; case HV_SIGNAL_EVENT: exit->u.hcall.result = hvcall_signal_event(param, fast); break;