From patchwork Tue Jun 6 18:19:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 9769585 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 99A5460364 for ; Tue, 6 Jun 2017 18:28:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92CD822B1F for ; Tue, 6 Jun 2017 18:28:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8344127C05; Tue, 6 Jun 2017 18:28: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 CA7DE22B1F for ; Tue, 6 Jun 2017 18:28:36 +0000 (UTC) Received: from localhost ([::1]:39656 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIJDX-0004No-Tc for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Jun 2017 14:28:35 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47604) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIJ5c-00064I-7j for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIJ5X-0007Ps-Cf for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:24 -0400 Received: from mail-eopbgr30118.outbound.protection.outlook.com ([40.107.3.118]:59885 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 1dIJ5X-0007Pa-1Q for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:19 -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=C2kZL77sprrbzWzW7sCVlIOGVNuf0fokA9e+Ejk7R8A=; b=Z3fccXwrWvfagbfR61DrS+vUKu7AmNjcW2RFWpOf9fwqdFxwvODQr/FI3tbU3NZ/jZs6oeHm8mJ1QiRu7dgWMYeUM9hf+plnFuGi5El+0o58Tn7zV+qEGkbQRPlDjxsfPNRLG9ZggS4+jdaYMP26vTdDZH0o7BSs2Hx68Rjm76c= 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:15 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Tue, 6 Jun 2017 21:19:45 +0300 Message-Id: <20170606181948.16238-21-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: 4099b603-0862-4dda-3276-08d4ad08ae66 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:VI1PR08MB0847; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 3:we4c2o24HvWDtESRskQH1JUqDH+gsjOCGlb4Wqv34Z6+IKT9xYvqrIvYBw4BlAYPbGoFg5h9R8832GhrcSQph139QwKsqwUslnevoep5v9XoszcPAxPKDPHuLNGnuZa1k/aVpvOGzJD50OYTxrlyv1FBOLiQQF78+ZYg1JOZAauZh7/o5bxWC/vjw/Bmk+M79YKZVNpvvjIr4q4c0YPBO52rTAr2S7lSg4ria5Dbs+8dsKHNxZSbHTaZ3fq/SFYO6tnidHPTJmiP19cmvq3b6CDXHAi7e270VBLpLyg1WjpKn2tbJ4y0mUyBTHW8DAjVImhAe14DbpBhBOVF3KuZjw==; 25:3tKO8t2PbxJidfkfX6Ctv5WfyxIsBzah7MWmiBTazYIaPuygml6K5dlebyoz3vDC7YzJlMrfl+QoHsm0T55HjYPeKC/5q7tk4vf+7AhZpLvnh1Zcd+A2eQ9QIMsnfRzBcDrK35p8RVYpquZ63Kjv6mFhfxU2lXTp3Nojy5qJ2mkuWNPHE3qE/ANPgHEz6lzFURnGyg3mrSoG9xU93wIG00h6cRl7Ax61E+toQmrdmyngq1AaMmrXZ5fowNoqPHhqt5neFI8UB9aWG3vS08PAQIwXbWW4P3fm614/jHf3Uq01iK5m7eBgHq11rh3PIuJLRPMsH+JX7LyK37RZ/+tZVOrrmue4I/f/Q1shuqJVggyk3irMH58r5/6/JCGzxxJnFbkcTi4oQx/tf2N0CwDpJ+/WRxDsN37MTRmBdCrpwvSlWUQyMDRGhawICrijlhYDRhbFG6Qs/s/fq4PuU4N44jHQc12EStYMQc3uEQ321Lw= X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 31:GK3+8qPsuQlawWbwdpDU8Mcyl9FVv5ur96/ovk5etpDsQWLjAPGJmEoRj7XDtGkzisDm+ttQdEaw1U7uJ5N7ViSgEOM0u+0zAAIVc3Owpv1AxPBsq7BUbrBJPvsK10v78jhJDE6IGhShUAafubZoI53tReFZHDXSSccJHRowSJ1u1Qyu5DevVq/XdeEdnkXNUqshs+JIn7vQ9JKdU1F7JKcMvyf3ejm4ApkI3geuPyU=; 20:bYaIkE4gHBmHh3jYJLsKcUtFOY5X/uKf2rPKta+mRQB/PcUztPQhPxxjM1Fmygo7RnTSckJrv/7fbJxYF45sJEleRUr9I2zS39ViuO+iFKaI+qSoAbFHLXuqsWLCG5nMVCe4bC07PzyRgA8z0bfP5vbqUgn6m3HEUzZP1glhl5CBPyA+uACbm0dKVLUy8nqYmhZMs8IY09A7IAyl0Ec9/oHGPYgPcz0KkD0Cebu4jziRoTpDRGkhcpCo8U9GbW2/THOaogNeBMH8rnTWzEccH1GupkONOl4Ezj/iob4W26zWhnBQi8NVY2C9tf8Qv8rmqNPuUvjUvcGisI1zb7E7Suon5k+Ul9l53avJM1BG/uSAyiq9AHclc4/xY/3VAmAXhwAA3ToDfqeJ+r89fHr1c3bsXOlnbovh2ThgVrlSofg= 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:kT8wUcCyKZlgEloqkLJE9xq3+2GSfIc+pyLzT/pgzK?= =?us-ascii?Q?+sJuXRX/ctv5kKnUNaVwEZ0TYB958wuDjpl2vDF2ckwgRc6Yswdf6gdX/kbd?= =?us-ascii?Q?m/q31rtXkWoQAtbHwfnZ0/VKI9OPEb9/QkcjkqOBr9ntOhVf+tQUss/FpvOD?= =?us-ascii?Q?5ya+xCnTG2luuVCz3te9yyoyAWhY+h/7shq/xjub6hivsbABDkrgwrixAq+W?= =?us-ascii?Q?xI03WRWHGZcdlejMlx+PtoetN+zp2cbWNMJxhmRaHSdzTi50IXfTfg2Ve96+?= =?us-ascii?Q?1vnZQPc4dnh5cQW4+9IbYwW+LRlpW/x2XALkdgEQ5T8GAxO68gJk3M4hjh3z?= =?us-ascii?Q?iySYFveEJ5R9NOO2Wsqlurat0jfZsVIwQ8swdKieoyjFHbwdbeEpTRDHTrn0?= =?us-ascii?Q?61FUGlrGZrzkqjyrkdo12KbO57C+jCuEjZ2vqy19bNPuC3pS306WsfuSwgc/?= =?us-ascii?Q?OjN7UH0fMNBbKXZQIPaOtt4QwyAGPHcJ1yVu96eeAvxcwFjb0sbBn3VPE0w5?= =?us-ascii?Q?iRPeo6w1E7JqGatZWOX6rR6I8Lgx2AR9z41R4+I8mPgux5D/5oesV46osGBv?= =?us-ascii?Q?AQPNCUZSuGHa8ZkXfLSPaUN0hoOzkCs7Ksc6+wZMgbpZSPIi75bxnKkwi+zD?= =?us-ascii?Q?s2kGl5E6Oqs6kSGYvAl2r6a94439gx18+nVAkrbgfK3hJQsRuwjoSVTdjYoJ?= =?us-ascii?Q?BinEhBuhAGuyg9nvTFE9ioD7db6oZOsDxkl83P5t+F5Iia6QCuChOLeURMBq?= =?us-ascii?Q?38wz9thT+pkuPWZhc5vt+7WpGM1q+xSONcbPv3KXVCqAA66avIjk9ks6mlMg?= =?us-ascii?Q?SvUi4j+NMkuG1+Id1keYaYiPyTwJ+3/A0ZJiajNaGwaYCjVx0N3E9lsBL8FZ?= =?us-ascii?Q?BGNATft1MrYjL+WtziwaiRXY+/3ShtOwnnGhhElutJ3dDxyQyYHSFyhGwzGY?= =?us-ascii?Q?j4+vMBd9Ro5t1GKkRB+QafIUVWoqBkCYzOJmPbN4yGRmrD+vkdGZDpLrtq3l?= =?us-ascii?Q?YEA2WLW7xKrgQ/Wck+vI+p89pG0L7Mt+hEYpG0c1JPvCndNLo4WUAxgqDH6f?= =?us-ascii?Q?WEpCoPG85DghP+WC4yvLdh99mycwLgTSNs4uJB0QG8UugV29FwGI0lmvy+gi?= =?us-ascii?Q?FB+boOG2uOFviUl0lraqo8mD3CGGoe?= 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:LWiBWR2bp1DSiy/d/wqmP1GHMrwDRlU09Ab8JQYHZ?= =?us-ascii?Q?XKL0I3otpX1Qud9hx/CwUZGNGzH7jGxqtzCXyBJuTmyvSSaaQWEhiPadcXYA?= =?us-ascii?Q?VaDF3+TD3NqExNqnovsMdvGMvUPTu7w2e1Ecovh2GdwKLCqDweMblCmYwk8w?= =?us-ascii?Q?PzNreZRHXH2QADPvZBIXIJcdsLO6d1f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Qu3d1xEhHdchHZed7n7qxfHBIj1SIvvUPQfDoxGUGewRFcdRUwPTV9WHDHX0Gl47ZqlSTT6M2l6drUAs+jL769G2mNoxWCeRFG9ikP4QkcI; 24:rLYjgLCgdKqePE+KflbGzGtoaPKtRwPKxgWEFuY5A+wz2s9+dNqM10APg9gETa1McXH+QcBoRY087U8Uu1fbbdV9jo4wmY8hNrBsIHeCZak= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 7:P8Ba85RjBXBrwm7WqZNpgUanwkquMQ5u3HM6uYn2LASbwyKZ0r8v2NpC+CuHIbZZ7t18BG0kV2qBc0SH/mumzvuf9XwzZPxknKd2NKH3P1wjceKJzY1BSD7VmyHD9PviafTsLbBpDaa0QyARXgqE1AEUvGb2uP3VVSv5vH28WVs+hL67z+km0fwjGSqIrcCdDtdRUKkgTGfqqQoYca174OYaMOqcPVaFl6mRAaHyFrese5TSUx9l0fIuAP/s+4MCALYzVVs2rpdjVKN0wcc39qrhqU0BBDVgtoQqASdPuO4+ecA5lyIjtOwdPvUDKRPWvz5DaV7mhzHaDZthfwqcnQ==; 20:4IH98SVP7XnGnDs725UVhdolE5W8zhl+HUrA/WdwkYEz98knFNxRlVZJKMeXVDK5pIG2y1cGX+dRZRxczrGq2rDrUeb3qRYkCkpHQAdDwIx38hZFeX5VAdZri1+BWDuzACGFptDp4xj1l3WwCz3E+c+DyNzAlUqwWee2h/iBqQo= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2017 18:20:15.6015 (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.118 Subject: [Qemu-devel] [PATCH 20/23] 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: 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 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 | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 95 insertions(+) diff --git a/target/i386/hyperv.h b/target/i386/hyperv.h index d2630ac..f82c770 100644 --- a/target/i386/hyperv.h +++ b/target/i386/hyperv.h @@ -41,6 +41,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 030184e..50386a2 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -232,6 +232,17 @@ 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; + +static QLIST_HEAD(, MsgHandler) msg_handlers; +static QemuMutex msg_handlers_mutex; + typedef struct EvtHandler { struct rcu_head rcu; QLIST_ENTRY(EvtHandler) le; @@ -244,10 +255,46 @@ static QemuMutex evt_handlers_mutex; static void __attribute__((constructor)) hv_init(void) { + QLIST_INIT(&msg_handlers); + qemu_mutex_init(&msg_handlers_mutex); QLIST_INIT(&evt_handlers); qemu_mutex_init(&evt_handlers_mutex); } +int hyperv_set_msg_handler(uint32_t conn_id, HvMsgHandler handler, void *data) +{ + int ret; + MsgHandler *mh; + + qemu_mutex_lock(&msg_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(&msg_handlers_mutex); + return ret; +} + int hyperv_set_evt_notifier(uint32_t conn_id, EventNotifier *notifier) { int ret; @@ -281,6 +328,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; @@ -364,6 +451,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;