From patchwork Tue Jun 6 18:19:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 9769601 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 3D03D6035D for ; Tue, 6 Jun 2017 18:35:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3544C2846F for ; Tue, 6 Jun 2017 18:35:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 29D7D28497; Tue, 6 Jun 2017 18:35:09 +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 3CD2C2846F for ; Tue, 6 Jun 2017 18:35:08 +0000 (UTC) Received: from localhost ([::1]:39682 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIJJq-0001ia-P2 for patchwork-qemu-devel@patchwork.kernel.org; Tue, 06 Jun 2017 14:35:06 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47510) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dIJ5T-0005wp-W6 for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dIJ5Q-0007Ne-5C for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:15 -0400 Received: from mail-eopbgr30107.outbound.protection.outlook.com ([40.107.3.107]:56200 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 1dIJ5P-0007MD-TJ for qemu-devel@nongnu.org; Tue, 06 Jun 2017 14:20:12 -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=sQzafTvvkRQiWjfobKfPo3CEbON1DXl/Hgtu3BasT6o=; b=CH4d1JafREI98d7ng4LK3ERvP2a4VoYBHZvx9wEs+dAGBFpfdTFxsfUSslaM3vaBeXLETpt4k9vMDN4vC7AjU2JsjQP238Ym+a5iVtnELR0NcPeHyC6WpohIryGWX2p15Ufe19UFBrmdCzUw3BCPFDhkF1lCUp9nWJ4CrBqlxGY= 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:09 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Tue, 6 Jun 2017 21:19:40 +0300 Message-Id: <20170606181948.16238-16-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: 77ec1973-afdf-4b21-8fcb-08d4ad08aafd X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(22001)(201703131423075)(201703031133081); SRVR:VI1PR08MB0847; X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 3:4sN0sDWrlnpbpXRjc5fPkH0vAKXKHG8AjVAnR137NKGxRLVu//PekkSZiNugPWPiEhewm1605xtVFoo/UfK0UaSfmumAB4M85yZDK2sQzxe/tre9nsW7NUQ7+brFOl58KkRiNm/Pw23jUIFn06khG2y8kg4uyxWg2fOZbVhHw15lrunu+acnDdRVkwRo012pA1K6r3n+Rhrp5Zvlum98ke0RvLUFgjrZz6+hQ5AujfJ3e+RYl9IE3GE3gVdqoPVZD/jZJHA1nF6V4ajZP6rPcVJwmOuYIBqqsz05fxxo28PLxLW4kbm6+l0e4J0yW3iMh12kWvCuKohOZ6VARJurOA==; 25:834A7XYTavYn1ozjnJqkM1ajMP5dqIqZ3iWX/X1jtPizHux3DHuYaC4IiFsJXmvld8A14B+g+tDwSEs0RcZp/h8z0YZ1Rl9Ua99WxQ4G+R2lGcSNxprDXKe9lEvsQgGGdLKmjfwyppxZKKE1JfciSr6cLANzV6elSXDvMZY/1kM1qn0B+KKGyNvjhI4/S0Uydvla745iFTHTDZAZ8VBuVqmy7Uee5JSX4rcMglk1RZVP/fJpCqo+OWirJVW2BxxPSKwKj+/7xvYN7O3BEf1WhAH2RbDWQ2pA9YwystWvTLHT7vvioTQthThytb+acqUw0eEDTc9fXKnlGB7ptn2g90QTRxUs28c7uOHDj3GO1UHT+b332hPuIOQExv5ggKQF5t3n540tm0+2WUOC6TCUCH17YwxFkGJOH+ThLs75fnIgmO4beyW92o9Jas3rzv/hGdkSlC+ljm0FeaS+sNFY1yIOf1dB83ODvk0JuHzGeKM= X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 31:OpQGCA+UMTGicbL1UrXWyFyGVw9+siHKpwW8bTO7cJ3fbzqtMJnhmkHmwqwle2OoZ6T4M9iVc9/n7U0cXwI0HWrAjKB6h6PHQVy/kmoXDkv4J0l3CoSvMW8Th4NjgRruziSOqL8H8jJZlqjoKK28Zy2qr/HuvQR/Rz+1o6CatrXSYJOOrjPoSKP1STrxQJo7Hyht7qSKwP/tnKDZNC1udUS3F9gt6KBaBGEzM7t9j/U=; 20:XT4vxJBrMLZvtnYBjPa/DrrVeXzif1gsQ+XhsLLCP3SoOvRfncdn/Opzr5+2QBGU+W4qHAaaycnMi2zCUenJZXBszCO+27BrIi6IKsFHXLAMR8lT4aoJvW74xaMcjP1gXi6LK2iNF/ye4jb+1JEOpyZVF+4jrecR1nbsYmqF0N9w7IZbOmhOfpe1b7c9mGKErbyTaTMhE5kwxiOBGXFlfw8xRxglWk1+YLgDEqFie/Kcxv08V7b0iYU2nK/CrHQIqaKJQmW8HdBXTwvNolG8OPb82L0szVYEgvvFTI4954QagkTb23K+H6lWZhaaljGV7dRK7zWr3P178binG9sO2MJ0+7xtEBHSlQhfLPvDq1BYi95J5D0laxwxH82SHj+f9mzFfvF006AyzQCZnBQPOnygt9xVIZnLpZDinLuk+r8= 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:k0hPa7fPwP9YUdlOk6kCFR5GJXPcfvO1EDZl8NdDfa?= =?us-ascii?Q?nU9/0TD2ivRk67nWatm2r5UvHDbCuxEot87F7FHFJsRo3JgaJ6BBUAiAEpsK?= =?us-ascii?Q?cwzkheEse8a/E2qlwMX1ALPJn2Jg4xEyzNZZS5TaUxZ65hlz6bOIkiHZWsyq?= =?us-ascii?Q?Nx9wmzqG7yZy/CqzKxT4DsVfqvak2WcO8w7SBPz3cYyucv8qMJSK+e0Rb5SO?= =?us-ascii?Q?CuDfZf1OiwRxB9HW79+W6iGMY6/Wr51WyunAwe6thvZqbb2mOnMPBPmjI5Uv?= =?us-ascii?Q?/ZCAJk0AKlevTdqRnq5CH2N7N6HbnXqqIiSRWvafLjnV77J6p9dXxdK8B+Sg?= =?us-ascii?Q?qk4jH3mRlayglx9Wg35Qonr1r01t7nNVB6p3CdYOVANd8fPqgg+pfgHsAT3F?= =?us-ascii?Q?o7qEz2bSECmhCsfJ0gnVV4bF3+sgbJ/NaX67o9Mt9P3DSKHPQXRs9+aRyaca?= =?us-ascii?Q?H9wmqR0gtSSFcOc/mhD2kyLAgAIv5ztkhvYzvvidAKFToC2IXp+R2YBcIBTz?= =?us-ascii?Q?WE7LsvMIQeY2DTppuzV/jp7htp5XYDDktAiAF80dpSmwJNep8L+NKquzLj5s?= =?us-ascii?Q?ucoK+rJ4c0zg/8NQgb77a/9/j234CnACDXbY0WxBrll+rorccTPiVDgFYI8i?= =?us-ascii?Q?Xd6LXtjUZxy7B1gryT/VWUSXrLSqhqJ6bITm1X280fpsRc8L4K29Zl3iKpMP?= =?us-ascii?Q?NaVJPQ96CdvoEG0jFR1bokYqRCOdx831h95c1lmiEXavOUXBG1AF2rrAsfg+?= =?us-ascii?Q?10V/XmegctjUATVpvH9+tjQC5Os9RKt40zxYpNfi2mwCJqIPGkPktP2X0HYm?= =?us-ascii?Q?BSEGNnkVeRD7lAfOp9LmRahI0ni5yZWsX5bvpYO98yR/MvRfPnsoA7stZNAg?= =?us-ascii?Q?Em9A9lHLyxlIcNeAnkl1TU+NRw03Euaq2Pj0rGt9+DJ6RrW8kWjB+TZjCWAR?= =?us-ascii?Q?3iA03XFJFyVS8pFQerB93pjLTiyzzA9jOsQyG0He9Dt5bm6OQaJvLR2sSNAh?= =?us-ascii?Q?HozH7pzAOmzctpcMOzNDvgPprLamQByQ47UO+h3dLWG6Ss6vfv+pdkL+shfz?= =?us-ascii?Q?/Fxaf8BZn8UsMpkxTqVU7JPMIDgUaid/6TCvpBz6bGRBzLNOGwv/xizNclZc?= =?us-ascii?Q?bx8p397DGeZ96vOsB0ydzl8XMqL2p0?= 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:vayTs3YQLS04gTswImaw60kosNQ0RYd2hE3DkmNhL?= =?us-ascii?Q?1tvN50UUOwwegcnSGA1dPuvdu8lZw1y3eR3iR2vEZURYZZzLBNbyPDx8f+ns?= =?us-ascii?Q?PXpDAWba3AOyznExKhbACBj41V6A+9bDfEBxl4DkMKhk2B0YV7QyzgQPyoBK?= =?us-ascii?Q?uNOlKW+iGh2EtD+W/Twi8tZC0icCNX6PYGkKIhF9E2scWzMOEOruut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WL/ym+GJEjnUPgx8Ct2dwrK7oXsXcEs0Pd2DBrG6zl1u+nHT6srv2fsRgSaESo+BTnQve4xGQUut+52fpnT3/vI7SvqCdCtBnUnQdwsauNlUk; 24:Rai98NhXLHicDXamSkJDhUO2ogPMJo6l3j3WkbzxnLRmKiZjCDnzOyZK3UmrCqOxBd6ksjnZIxYlV2a94Z5W6zLgZZC7q0aVAb0j+/9qwkg= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; VI1PR08MB0847; 7:++k5PBcs8XVOJzX7GtD2m5wK85KhW6wd5Ywcm1XJMTCRP0LR0xV58aKK/RsEh67rZSgItp3Y4Ed/w4ceXtSuWRF0l5tn3hxG+P1MDfUdH/l+FKh1wabu+YdgDrSCgxr7jr5Idz/SU77VIpP7vqyxbkquWZw4KeMikPuwceFo6rk0iGyEIIogPQhg7ivVdMZiCb+L50xbCJnHKkpvhGSS5R6B6ursAuaMMdu3Lx0exxEts1NOW8xW5CVMeakakV/d68O0+GLxCo1+xYeWht/2Cnxh3M3w0mRzUe36efrziRXDWZxKfTAnokg7IO6Bg1bymKgDq8TDRqQv5jaK6LWT8g==; 20:w7m3VHh17SxXKZQ4beodh85DfRiBsGkbDxGwFu57nk3ehplMsswyE1pm6sSXd7xpCOcIh3cSXcssJvsO/QxNf8LC8u/tds6iGmqPxsK9PsS20w2/kRLCaI2/LfIGa2cwtAsLierFJSJL/kq6iqH29SS3HDUHadSXQw8agZ931r4= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jun 2017 18:20:09.8982 (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.107 Subject: [Qemu-devel] [PATCH 15/23] hyperv: make overlay pages for SynIC 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 Per Hyper-V spec, SynIC message and event flag pages are to be implemented as so called overlay pages. That is, they are owned by the hypervisor and, when mapped into the guest physical address space, overlay the guest physical pages such that 1) the overlaid guest page becomes invisible to the guest CPUs until the overlay page is turned off 2) the contents of the overlay page is preserved when it's turned off and back on, even at a different address; it's only zeroed at vcpu reset This particular nature of SynIC message and event flag pages is ignored in the current code, and guest physical pages are used directly instead. This (mostly) works because the actual guests seem not to depend on the features listed above. This patch implements those pages as the spec mandates. Besides being more correct, it will help to work around certain lifetime issues with the current code (in a followup patch). Signed-off-by: Roman Kagan --- target/i386/hyperv.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 2d9e9fe..165133a 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -15,6 +15,9 @@ #include "qemu/main-loop.h" #include "qapi/error.h" #include "hw/qdev-properties.h" +#include "exec/address-spaces.h" +#include "sysemu/cpus.h" +#include "migration/vmstate.h" #include "hyperv.h" #include "hyperv_proto.h" @@ -26,6 +29,10 @@ typedef struct SynICState { bool enabled; hwaddr msg_page_addr; hwaddr evt_page_addr; + MemoryRegion msg_page_mr; + MemoryRegion evt_page_mr; + struct hyperv_message_page *msg_page; + struct hyperv_event_flags_page *evt_page; } SynICState; #define TYPE_SYNIC "hyperv-synic" @@ -65,6 +72,17 @@ static void synic_update_msg_page_addr(SynICState *synic) uint64_t msr = synic->cpu->env.msr_hv_synic_msg_page; hwaddr new_addr = (msr & HV_SIMP_ENABLE) ? (msr & TARGET_PAGE_MASK) : 0; + if (new_addr == synic->msg_page_addr) { + return; + } + + if (synic->msg_page_addr) { + memory_region_del_subregion(get_system_memory(), &synic->msg_page_mr); + } + if (new_addr) { + memory_region_add_subregion(get_system_memory(), new_addr, + &synic->msg_page_mr); + } synic->msg_page_addr = new_addr; } @@ -73,6 +91,17 @@ static void synic_update_evt_page_addr(SynICState *synic) uint64_t msr = synic->cpu->env.msr_hv_synic_evt_page; hwaddr new_addr = (msr & HV_SIEFP_ENABLE) ? (msr & TARGET_PAGE_MASK) : 0; + if (new_addr == synic->evt_page_addr) { + return; + } + + if (synic->evt_page_addr) { + memory_region_del_subregion(get_system_memory(), &synic->evt_page_mr); + } + if (new_addr) { + memory_region_add_subregion(get_system_memory(), new_addr, + &synic->evt_page_mr); + } synic->evt_page_addr = new_addr; } @@ -83,6 +112,15 @@ static void synic_update(SynICState *synic) synic_update_evt_page_addr(synic); } + +static void async_synic_update(CPUState *cs, run_on_cpu_data data) +{ + SynICState *synic = data.host_ptr; + qemu_mutex_lock_iothread(); + synic_update(synic); + qemu_mutex_unlock_iothread(); +} + int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) { CPUX86State *env = &cpu->env; @@ -93,11 +131,6 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) return -1; } - /* - * For now just track changes in SynIC control and msg/evt pages msr's. - * When SynIC messaging/events processing will be added in future - * here we will do messages queues flushing and pages remapping. - */ switch (exit->u.synic.msr) { case HV_X64_MSR_SCONTROL: env->msr_hv_synic_control = exit->u.synic.control; @@ -111,7 +144,8 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) default: return -1; } - synic_update(get_synic(cpu)); + async_safe_run_on_cpu(CPU(cpu), async_synic_update, + RUN_ON_CPU_HOST_PTR(get_synic(cpu))); return 0; case KVM_EXIT_HYPERV_HCALL: { uint16_t code; @@ -245,13 +279,34 @@ static void synic_realize(DeviceState *dev, Error **errp) { Object *obj = OBJECT(dev); SynICState *synic = SYNIC(dev); + char *msgp_name, *evtp_name; + uint32_t vp_index; synic->cpu = X86_CPU(obj->parent); + + /* memory region names have to be globally unique */ + vp_index = hyperv_vp_index(synic->cpu); + msgp_name = g_strdup_printf("synic-%u-msg-page", vp_index); + evtp_name = g_strdup_printf("synic-%u-evt-page", vp_index); + + memory_region_init_ram(&synic->msg_page_mr, obj, msgp_name, + sizeof(*synic->msg_page), &error_abort); + memory_region_init_ram(&synic->evt_page_mr, obj, evtp_name, + sizeof(*synic->evt_page), &error_abort); + vmstate_register_ram(&synic->msg_page_mr, dev); + vmstate_register_ram(&synic->evt_page_mr, dev); + synic->msg_page = memory_region_get_ram_ptr(&synic->msg_page_mr); + synic->evt_page = memory_region_get_ram_ptr(&synic->evt_page_mr); + + g_free(msgp_name); + g_free(evtp_name); } static void synic_reset(DeviceState *dev) { SynICState *synic = SYNIC(dev); + memset(synic->msg_page, 0, sizeof(*synic->msg_page)); + memset(synic->evt_page, 0, sizeof(*synic->evt_page)); synic_update(synic); }