From patchwork Fri Sep 21 08:22:08 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10609383 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33FEA14BD for ; Fri, 21 Sep 2018 09:00:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 255882D890 for ; Fri, 21 Sep 2018 09:00:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1954B2D895; Fri, 21 Sep 2018 09:00:19 +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=-7.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,MAILING_LIST_MULTI,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 9F4A82D890 for ; Fri, 21 Sep 2018 09:00:18 +0000 (UTC) Received: from localhost ([::1]:54617 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3HIQ-0002D1-0h for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Sep 2018 05:00:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49018) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3Ghu-0006gu-T5 for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3Ght-0001ox-Tb for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:34 -0400 Received: from mail-eopbgr70117.outbound.protection.outlook.com ([40.107.7.117]:46849 helo=EUR04-HE1-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 1g3Ght-0001gn-Er for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:33 -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:X-MS-Exchange-SenderADCheck; bh=Umm7zqALZepBA3r39fFbRfOAgcpGqt8dAEBvVAI/jo4=; b=JJ4OGoysERCB97Y8iDGJTQLSUKNh3oiuzL+2y2+nmR3X3nx74fSQO6UcnuJUUCTvzrZAycxwpvjaTTQ1RWXcmnhqRxmGN8JiPnGH+2bQxI1dj7/8XLeyRbCBTZqWi8myrcfnQDVzt2w9rTgr+SNkCp1tJIr6g07yLbUzPTmSGAo= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (185.231.240.5) by AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.18; Fri, 21 Sep 2018 08:22:29 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2018 11:22:08 +0300 Message-Id: <20180921082217.29481-2-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921082217.29481-1-rkagan@virtuozzo.com> References: <20180921082217.29481-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: VI1P193CA0003.EURP193.PROD.OUTLOOK.COM (2603:10a6:800:bd::13) To AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 968f7b65-c6e3-4372-9416-08d61f9b5f9b X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB3588; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 3:HcIkK/9II73fi1YeK0YggBfT9/7S2Sp/x5Ues0+ogvrwRg+4HChxiXUOUkAkni/hHozyIjCGzFiiVxhnj1LHDsYm35Z9HAYIzTuDSSTPuDBJRxyjFpx+m3xh3HKw0/MtN6TNsXs0zF+VTFcKbraFuYBGE+eW28Z0E5sEye8MiGcXkNVe7SACL0zs28uYbEyUX/IYu+FFbQhJTwq57g+3A+U+kFyc+nfo00ZTBIkUMqlxGEZdAJlaiHVLCjPVUeIb; 25:9Xgf3RSg3TYSZrm9ryL1mjiBZxG1z92bFOK45HHuIn0TvSfPBF2XxzMmKJF71jQ1WWS1N0wU3Rg9v3BS7gpyRi1ZhzpFXSIEDWmqF3/C1Cv6QMJQwdW1jo0bxQeio5gqXiKmZrbQCC4aL57elYkd2jhU6JV9IKH1QMNLl+VUONlM2TP6I0zdVZkG41YvKE7xbTbSx3IROtbjJb/yxFERR2bkmJk7RjAZjqsmTdl9nlXeanegumhzt/IYIs9kcm9kKivjqagIziI/uzj8ZO3whsaksUfTpZfzZ6+L486sViEKiYtDEL4KXlgonLc9wSO0coQohr3RoH31u9hB18C8iA==; 31:1yN2ooiH3wSXEdTYxuxsQnY92NdBztDP6VQySU3pLro4qwWT81g8oVPV+twWeeAtGa+CdjNgYiegMkMdsADVl8gVu7pC8DHH7bGFkCcUuxw+qAoYb34fSaf3ztLMISA9oaThcBfqNuGU8dqU6sa2PHoBs2IhmCMzX29gC4Gr0MBV8HEiuB7RHaj08edzRHMT4Dw5QfzqK/vfb3CycP45yNy+7lcGhk3IVyTdiaFRSJE= X-MS-TrafficTypeDiagnostic: AM0PR08MB3588: X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 20:EZXOrtDGzw703F5v+1fEgi4b6u9m51wLx9DZHbmvRufj0SC4hrY/pzACW9G83R+i525zsl2Qrr0CN5Yd+AX050GmIAZeKT/eSfThh5LGmCEg/Bh1OjuaDdMpw4o3RFccMwsYBaaEeExldtleSfhSYiYzqg5CCicjKUXWSHpAAxI0xJceU1whOJEWSLZ6d8TseN1IR//SDpxQqrJ6yFiXjLs/WLjW8TEypnlNGv73X12qnqO7vRgR3dsHRyAYuxcvydfn2gFqlIn+vzwibqSAcK0ohqptuLJFwATV5nuOsK4R3B8SX5hyZ6yfzqrsFf+mdFfoi3w9KqlvhH2wKgxElnpC2sJdNCjA3N5gIgaIAMIGXXVRltnUIaUyr7xhaTqTfSMIH9pC0f4n68kuDu1ZGY84TBRfrTN+jz0ouQzb0kyzx3IOB2beT0Ss6UJbr9daDDba9aeYe5oAavc+hVsmjyBOw0UEKpcMfJfddE1WQ+r0ZPAuvCIwcy8M7AZhq0Fk; 4:fTGSmzlO9KH7y1wXGVWYerVeMNeF2OOEZufyh8hzfiClE6Sb1xKyeWeffNloOkQEv4lDBP8CyYfzu7vMCX6K7Z5iv1mbMELfyMJIeTlYv8fJGxKb6ruD+ZDGhFt92mtVyQjhhkH1cw7CkWV911Blw3Z8RnVVfL53qYbaMdFAmQmE7DtHlO88QfDwa2dfKC2+5+5lhSCn0KYESLcFFQ8Awx4kbxLCozvCSUZVAQqtMglMvLDhJmGynWqfIvaKHQ0azJIB5u8xTzZ6vEkBnaNnHQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231355)(944501410)(52105095)(10201501046)(3002001)(149027)(150027)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(201708071742011)(7699051); SRVR:AM0PR08MB3588; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB3588; X-Forefront-PRVS: 0802ADD973 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(346002)(136003)(396003)(39850400004)(366004)(376002)(189003)(199004)(6916009)(16526019)(5660300001)(36756003)(3846002)(54906003)(48376002)(6506007)(476003)(486006)(52116002)(446003)(1076002)(76176011)(386003)(51416003)(186003)(6116002)(16586007)(2906002)(66066001)(6512007)(7416002)(50226002)(53936002)(25786009)(106356001)(53416004)(81166006)(47776003)(316002)(956004)(11346002)(2616005)(7736002)(8936002)(305945005)(8676002)(2351001)(105586002)(97736004)(4326008)(86362001)(6666003)(68736007)(478600001)(6486002)(2361001)(50466002)(26005)(69596002)(81156014); DIR:OUT; SFP:1102; SCL:1; SRVR:AM0PR08MB3588; H:rkaganb.sw.ru; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR08MB3588; 23:epmtZm8tGbvP9QTKgcpOXHv1sic53EHsBXNqIEqpm?= /R4jNji1oFKtHA2oINZMFTppgv2YhSraTBGHwNB3AmLwZSYl21INZTMDDoWzS8AjkInlhPXexUXtvB0EsD1LmO+ROooohymUHkz5Jc8aNNT50DHdF0ghboCQhjcYVQzREruqI45+cbxM+LmECrzDIfOg/pnB7xo/taha1HKXwQZSZcnoAidHKtiH4xeNoBTo5g4cL5vE/3TG/pC7ab+FAu/yv5zr3LWFKr5PcWjaYyDxCroTfEJ0VsMPpcOBQUX75dW4IZ+9MpiSzaJkweCXMuczpn34zPeMK8wy4lnTD2MduUhdW8EcWKdZH6nZ4Gtyi+waUzeL5HN/RG2dIZ7Kdqi4k3ptLGjEJd+AZY2ThB6aaFJft+qa7FG/+byx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WrPErQjmLkqPt4D7ygthJb/Uot9sppVmP0lulAMlYSOZ6PmQEoqpbONboBb9dJHosHxmEMUiX8eDy7HVkZNAQX SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 20:FxkV2i6IvUEVsVDgCdBFbwYJsoYJGf6+XK8mTh6QlJVeHe0iBeLLWNER8KEGzDAxxE5GNS7j4h6TLyaaTv54SavMEav8iHKni2XjegvCPdXLPe5KC6a9SgWD7/974vb+/X+3jhj2IoKCertQye4yQXPPK8YuuWtV83ZDDB6fh/c= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2018 08:22:29.2837 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 968f7b65-c6e3-4372-9416-08d61f9b5f9b X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3588 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.7.117 Subject: [Qemu-devel] [PATCH 01/10] hyperv:synic: split capability testing and setting 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: Vijayabhaskar Balakrishna , Eduardo Habkost , Konrad Rzeszutek Wilk , "Michael S. Tsirkin" , Venu Busireddy , Liran Alon , Paolo Bonzini , Si-Wei Liu , Igor Mammedov , Boris Ostrovsky , Karl Heubaum Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Put a bit more consistency into handling KVM_CAP_HYPERV_SYNIC capability, by checking its availability and determining the feasibility of hv-synic property first, and enabling it later. Signed-off-by: Roman Kagan --- target/i386/kvm.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 892d4f46c1..8d956da5d1 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -734,8 +734,9 @@ static int hyperv_handle_properties(CPUState *cs) } if (cpu->hyperv_synic) { if (!has_msr_hv_synic || - kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_SYNIC, 0)) { - fprintf(stderr, "Hyper-V SynIC is not supported by kernel\n"); + !kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_SYNIC)) { + fprintf(stderr, "Hyper-V SynIC (requested by 'hv-synic' cpu flag) " + "is not supported by kernel\n"); return -ENOSYS; } @@ -753,12 +754,14 @@ static int hyperv_handle_properties(CPUState *cs) static int hyperv_init_vcpu(X86CPU *cpu) { + CPUState *cs = CPU(cpu); + int ret; + if (cpu->hyperv_vpindex && !hv_vpindex_settable) { /* * the kernel doesn't support setting vp_index; assert that its value * is in sync */ - int ret; struct { struct kvm_msrs info; struct kvm_msr_entry entries[1]; @@ -767,7 +770,7 @@ static int hyperv_init_vcpu(X86CPU *cpu) .entries[0].index = HV_X64_MSR_VP_INDEX, }; - ret = kvm_vcpu_ioctl(CPU(cpu), KVM_GET_MSRS, &msr_data); + ret = kvm_vcpu_ioctl(cs, KVM_GET_MSRS, &msr_data); if (ret < 0) { return ret; } @@ -779,6 +782,15 @@ static int hyperv_init_vcpu(X86CPU *cpu) } } + if (cpu->hyperv_synic) { + ret = kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_SYNIC, 0); + if (ret < 0) { + error_report("failed to turn on HyperV SynIC in KVM: %s", + strerror(-ret)); + return ret; + } + } + return 0; } From patchwork Fri Sep 21 08:22:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10609395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8479014BD for ; Fri, 21 Sep 2018 09:05:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 720A129CAF for ; Fri, 21 Sep 2018 09:05:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 62A0F2DBE4; Fri, 21 Sep 2018 09:05:49 +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=-7.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,MAILING_LIST_MULTI,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 EE4A829CAF for ; Fri, 21 Sep 2018 09:05:43 +0000 (UTC) Received: from localhost ([::1]:54658 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3HNf-0007HT-6E for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Sep 2018 05:05:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49085) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3Gi0-0006kn-8q for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3Ghx-00024m-1D for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:40 -0400 Received: from mail-eopbgr70098.outbound.protection.outlook.com ([40.107.7.98]:35648 helo=EUR04-HE1-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 1g3Ghw-0001yN-Kl for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:36 -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:X-MS-Exchange-SenderADCheck; bh=L4lqpj6ihCv/Nzylmh1kczaggMGe7R/yuTUxwM2k0po=; b=djuBxO0G1uRLu3ksvfiXdgpQQ9DZFa2K4yD9TrBXKo7PmqoH6R2HFwddviRpMW+Z+DXm4Nf3M03D6HzHW0Lg14mydshJhDfv5pLodYoTy/lpzVWgbsyLgIe8lBYS457qWL4N/r4qCZ8+KpIzfjobG51hqhu3Cb4DWf1EfAWiq6U= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (185.231.240.5) by AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.18; Fri, 21 Sep 2018 08:22:33 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2018 11:22:10 +0300 Message-Id: <20180921082217.29481-4-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921082217.29481-1-rkagan@virtuozzo.com> References: <20180921082217.29481-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: VI1P193CA0003.EURP193.PROD.OUTLOOK.COM (2603:10a6:800:bd::13) To AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 25bed2db-bde1-421b-4319-08d61f9b61e8 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB3588; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 3:h4iIW3yxoilCiT0BjvLogo8gvwo2vzIAa2j4qYr1n4W3Rj7NXvvagQeVFmytDdICTZm9YLR6YIT9XdvbtIEc1/VMi0IF3pLOghdIZzz4HLMIZs8Nl9NvKd+rTkTmGLw7a5MOidWrcWWTtymQ5HBV9JOItsiI4rirS1VXzFNQoOPw+dikGHKHeI3homMA4dandcJuFT2lNGk/TKgNUpo/QticbHrZu9FPpHTkLRVESWgAZJ7CUS0vEGsDpumH3tBN; 25:gYSsC1t9VpaucJo/6fBy4rKvr/VJgrpzogGWMsFzZ+aSYHFDevokAexA/Y4TizwZTIla1n4fZXm/frhBH6aVOdnvS3csuWCr8aY1r6KWfacKY36HbS0s0E9nWyFdMAArb3Bd7CZIfKDcWZVTv94zcrgFha9NgtFW2Rh+rhdhXpvPfMCjw1L/XC0dq052jw+akhkYMgpQbJ7azk/xmoC7VeEL4nUYXXK9d3mDLXtKH+VFw5BUNN3j52LlvMWsEHIUoRuUrhh+IwKYPvvmYfg/7DGhQXb6JpJCGRPWgQQ/c5LHT+dO1VRinXCv4GryqPyMJ6UCBt2nlAq20lobLW2e7g==; 31:Q1bAxZMMMQcci1FhqGnwoYLaZ+7XcUG1Oo16cESLsF1n1Ku008z8K5+BOqyGNtvWeBMzvKbN1HKz+jWpDWjNNGmfiVzdzB2Vi5GhIVMzoxhLCFq341UoFGxbVm1DxxzgV+VITtrMuf0XzbMB4MgBhEYXqfMvBnGJZYByPF2re+98pSj9z1sLBmDZmeIV+m268AmC5W8bHokEW47r/ICtSW9Pi6xKYR0qz19BQ08NOKY= X-MS-TrafficTypeDiagnostic: AM0PR08MB3588: X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 20:Pz8c1+ZWQ4MwUTUZMgmgmGSHuKclwDve4C0YHMbejB0RH9IGZjtTTBClEcVRZVYZPFggIGSZocbtaGTo1Cu/3dNl+KdMyqwJi5GyOCvrUW+5GoK8OzVwgbkGDXidgD9EaeqzCZtA/iHAigQcV+Jl4kri3eNGAjYlmYpS46bpWWEVwmsyMo9gnAI4h5DeiglNZUt3NIH1HRxcTtPtE+PodAUMLlqOSUwwp3dLBWx0L1v390XzIY787ov4Ud1jUBgLzj7CllqZn/lU9zn/72ZkRTrvWOH6ZjID6D5UqQAjhS3FMv+FqfTiPQnH2LRdVl9w1rVOsMdOp+u16KE0xyRWcbanp91vzFnAfFC0IWSDx6p5zvHMepQSFFQu+VvVq/DPTYwP0SpjEOv0OWYrhybxFsxq8ALwUy9UI+pzmEZDJhA63+lKP6UOP+NxlKJEBxQEq2fFmMke/67VCff28YmrL+mtK9UbQBsFklkYLROenYTNxUS0jtChT1SZhgW2pk2b; 4:Dl6HItRhk+bdYUyXkW5jOb2wQ4hqqxQEE7OsSsoeEOvvHk+9YxWfmtF9/ToMHqZEVTCGBWwmxepfTZd3hheABG2Ij+4/JP13MvRURfOZjbXLbj1d7atsuDVQfgmMrBG/vouZmSY6QUod4oHiMb4ANrInWadN2M+FWNqqE1y86cvcLMY4j/llv1ohUR8yMRhN+NG122+2ZTlfAy5gJz0qCyB+CYxVGSvFMbrrHnvvyVWPBuZUe7WQ4PEHyZoggAP1c006UJleWFPhlSgMJmIC5A== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231355)(944501410)(52105095)(10201501046)(3002001)(149027)(150027)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(201708071742011)(7699051); SRVR:AM0PR08MB3588; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB3588; X-Forefront-PRVS: 0802ADD973 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(346002)(136003)(396003)(39850400004)(366004)(376002)(189003)(199004)(6916009)(16526019)(5660300001)(36756003)(3846002)(54906003)(48376002)(6506007)(476003)(486006)(52116002)(446003)(1076002)(76176011)(386003)(51416003)(186003)(6116002)(16586007)(2906002)(66066001)(6512007)(7416002)(50226002)(53936002)(25786009)(106356001)(53416004)(81166006)(47776003)(316002)(956004)(11346002)(2616005)(7736002)(8936002)(305945005)(8676002)(2351001)(105586002)(97736004)(4326008)(86362001)(6666003)(68736007)(478600001)(6486002)(2361001)(50466002)(26005)(69596002)(81156014); DIR:OUT; SFP:1102; SCL:1; SRVR:AM0PR08MB3588; H:rkaganb.sw.ru; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR08MB3588; 23:IRKaraEUSrmzarih52o6gDbqteaO9N1+pUxFi6/qs?= F87bCGhWmS0XeB1D+aYaEaLIQacz6Wa5BSwr4ZnF1NEUGdd5P8s7u9FRX8Gdz2xbsmLJ68MVHnvsmlXacAHP2ZJ8bG5H3r36n/YGLWucCwOazfWNiAah4FQgVCgepA4hGEI82yy7yIHJnRWpHFpFbV2xgNhIlNSmdCQoxJ0T7Fo48+VHIcxtx23fDLbjoAO/Opnx8FsE8NyXHHff3VYmBP+M4AShsYXm/0J1fyQvuFNvk8XGzd80nngvcyowaIBuHT7BIktiMDQ8mRjQZGbw3mZC4XDioDaUomfWRi1WWpEAjqUp3R0l7I44zOKxmXBYZ8ZnfUDuSXLVzJzrlCE19rG4/M0n4PIlhRlGZdG0Pl9gIxifruP5hd56oSjh9PaaHJ4M50Z+RvglnyygdPtLs8Q3Ckb2+QIreaOJ0rcMWCSXggjXeCXF+sdOxeBhjUTO/xtBAqiDcqqPueKbw/CuUY6bk5OciJPBKgmgVH64V3SwIjjL+5aqF7CRmXgRndyVcyb38wZi76yq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oS8M5YpuI3iaoYwz0ukKDHep2tN++BClbWZppFK3uX2Zr5yKCkpyZxGVnkElOcJF4lHc= X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 6:7jgp2cohjUyzsbTHranoX0jHmlgOph2diOwef2GFnG9jeCX8pBmbJbAKaOYWe6Za4apeAxbawXy/cTtI2Zr0jh223kJGCzp8WyxSnHcmOiXIknTKlj2J/+Rx4jgdWHUOYT/F9CHzULNgR2JPpq673sj9Jgqs+QiAytWEwmOyHorC0rrJjx9iDMiHgKqJ31QwR4fBOFNrbs2UTYvZ0joY64NHnX2kungcys2AIEAX8MK92g0fuDrcjD466M5LSlZYSmg5ROwmcERrwl32ERKLi1aEItxjea6WsAG0+xMjkvabHYso7PQLfEYCZa/6DtIqXyNU1eKgPiVhopZfRxlwLo0RH6PoCqg94tSedIO+alDk0b6chA9zU9nxFTcQxP/FM+wu+VwDuxMPSQSVxQt4G3gRMkmCf5sf6zz95MMZgOblCOWT2xRmxGm7P7izMq132vOrb6MKCCfgscIsCePw2Q==; 5:YbVGuCwLpRHEPRmcorHK6Oif+pV5YuUiZVMVtq6EesB3WqtoX7Ugs5aijKAudGvbb5KRct5Fe2kcVdfFQqm9ZvRi1laCTZp1AspRxpBxp0wYKeZsrcyJKhuLWJ1NkN3Rmf20AfajV4J5udiM4Qbu7G4f35xM8FpqZYHKkBEgIJ4=; 7:q9h5EXGUlrSSIHzADBXwL1FcLld7/0GWANb/Yu3zhC6t9MOv5kx7GNVXcCkZqr4Y8Qh2ef+Hm68rwMyqdfG1ocCapgsZcUdvkqOLaB3Op9FehLGDUHofKdY2zWPwdB78bX35kQt8qotYlRf9DOihyhGO2lWA+OgOFS1UqjyhU1i7deWirhGa6kFfdwP7mWG8JawlvO9qiawhgjYByTJBgzOxOZ8ajx9SjMLY3LwoLUKmoOn3mzEp7tHvLto7cG8Y SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 20:Zk/+D7A6W/I7/KwbHE2WN3Fcjx099FK8U/UNGcxZbOJSurtWoWh302+s2SbHFeQbKmfNsVWKMtZucyPtCgzsPpobJ6uEWzetCwxn2xoTMIPpmdJlYIfyntIik79kv4IpMsq+R+Nl/SNnB3a7v5o1IKRZDEOzFL4CGiYMoz2diUA= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2018 08:22:33.1261 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 25bed2db-bde1-421b-4319-08d61f9b61e8 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3588 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.7.98 Subject: [Qemu-devel] [PATCH 03/10] hyperv: only add SynIC in compatible configurations 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: Vijayabhaskar Balakrishna , Eduardo Habkost , Konrad Rzeszutek Wilk , "Michael S. Tsirkin" , Venu Busireddy , Liran Alon , Paolo Bonzini , Si-Wei Liu , Igor Mammedov , Boris Ostrovsky , Karl Heubaum Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Certain configurations do not allow SynIC to be used in QEMU. In particular, - when hyperv_vpindex is off, SINT routes can't be used as they refer to the destination vCPU by vp_index - older KVM (which doesn't expose KVM_CAP_HYPERV_SYNIC2) zeroes out SynIC message and event pages on every msr load, breaking migration OTOH in-KVM users of SynIC -- SynIC timers -- do work in those configurations, and we shouldn't stop the guest from using them. To cover both scenarios, introduce an X86CPU property that makes CPU init code to skip creation of the SynIC object (and thus disables any SynIC use in QEMU) but keeps the KVM part of the SynIC working. The property is clear by default but is set via compat logic for older machine types. As a result, when hv_synic and a modern machine type are specified, QEMU will refuse to run unless vp_index is on and the kernel is recent enough. OTOH with an older machine type QEMU will run fine with hv_synic=on against an older kernel and/or without vp_index enabled but will disallow the in-QEMU uses of SynIC (in e.g. VMBus). Signed-off-by: Roman Kagan Reported-by: Vitaly Kuznetsov --- include/hw/i386/pc.h | 8 ++++++++ target/i386/cpu.h | 1 + target/i386/cpu.c | 2 ++ target/i386/kvm.c | 30 ++++++++++++++++++++++-------- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/include/hw/i386/pc.h b/include/hw/i386/pc.h index 6894f37df1..dfe6746692 100644 --- a/include/hw/i386/pc.h +++ b/include/hw/i386/pc.h @@ -294,6 +294,14 @@ int e820_add_entry(uint64_t, uint64_t, uint32_t); int e820_get_num_entries(void); bool e820_get_entry(int, uint32_t, uint64_t *, uint64_t *); +#define PC_COMPAT_3_0 \ + HW_COMPAT_3_0 \ + {\ + .driver = TYPE_X86_CPU,\ + .property = "x-hv-synic-kvm-only",\ + .value = "on",\ + } + #define PC_COMPAT_2_12 \ HW_COMPAT_2_12 \ {\ diff --git a/target/i386/cpu.h b/target/i386/cpu.h index b572a8e4aa..e2e87dc13f 100644 --- a/target/i386/cpu.h +++ b/target/i386/cpu.h @@ -1376,6 +1376,7 @@ struct X86CPU { bool hyperv_vpindex; bool hyperv_runtime; bool hyperv_synic; + bool hyperv_synic_kvm_only; bool hyperv_stimer; bool hyperv_frequencies; bool hyperv_reenlightenment; diff --git a/target/i386/cpu.c b/target/i386/cpu.c index f24295e6e4..9c29c5db81 100644 --- a/target/i386/cpu.c +++ b/target/i386/cpu.c @@ -5575,6 +5575,8 @@ static Property x86_cpu_properties[] = { * to the specific Windows version being used." */ DEFINE_PROP_INT32("x-hv-max-vps", X86CPU, hv_max_vps, -1), + DEFINE_PROP_BOOL("x-hv-synic-kvm-only", X86CPU, hyperv_synic_kvm_only, + false), DEFINE_PROP_END_OF_LIST() }; diff --git a/target/i386/kvm.c b/target/i386/kvm.c index 47427d98f8..056a482d3a 100644 --- a/target/i386/kvm.c +++ b/target/i386/kvm.c @@ -733,8 +733,18 @@ static int hyperv_handle_properties(CPUState *cs) env->features[FEAT_HYPERV_EAX] |= HV_VP_RUNTIME_AVAILABLE; } if (cpu->hyperv_synic) { - if (!has_msr_hv_synic || - !kvm_check_extension(cs->kvm_state, KVM_CAP_HYPERV_SYNIC)) { + unsigned int cap = KVM_CAP_HYPERV_SYNIC; + if (!cpu->hyperv_synic_kvm_only) { + if (!cpu->hyperv_vpindex) { + fprintf(stderr, "Hyper-V SynIC " + "(requested by 'hv-synic' cpu flag) " + "requires Hyper-V VP_INDEX ('hv-vpindex')\n"); + return -ENOSYS; + } + cap = KVM_CAP_HYPERV_SYNIC2; + } + + if (!has_msr_hv_synic || !kvm_check_extension(cs->kvm_state, cap)) { fprintf(stderr, "Hyper-V SynIC (requested by 'hv-synic' cpu flag) " "is not supported by kernel\n"); return -ENOSYS; @@ -783,18 +793,22 @@ static int hyperv_init_vcpu(X86CPU *cpu) } if (cpu->hyperv_synic) { - ret = kvm_vcpu_enable_cap(cs, KVM_CAP_HYPERV_SYNIC, 0); + uint32_t synic_cap = cpu->hyperv_synic_kvm_only ? + KVM_CAP_HYPERV_SYNIC : KVM_CAP_HYPERV_SYNIC2; + ret = kvm_vcpu_enable_cap(cs, synic_cap, 0); if (ret < 0) { error_report("failed to turn on HyperV SynIC in KVM: %s", strerror(-ret)); return ret; } - ret = hyperv_x86_synic_add(cpu); - if (ret < 0) { - error_report("failed to create HyperV SynIC: %s", - strerror(-ret)); - return ret; + if (!cpu->hyperv_synic_kvm_only) { + ret = hyperv_x86_synic_add(cpu); + if (ret < 0) { + error_report("failed to create HyperV SynIC: %s", + strerror(-ret)); + return ret; + } } } From patchwork Fri Sep 21 08:22:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10609375 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8B52415A6 for ; Fri, 21 Sep 2018 08:58:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A7A42D873 for ; Fri, 21 Sep 2018 08:58:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E04B2D889; Fri, 21 Sep 2018 08:58: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=-7.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,MAILING_LIST_MULTI,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 C88CD2D874 for ; Fri, 21 Sep 2018 08:58:36 +0000 (UTC) Received: from localhost ([::1]:54601 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3HGm-0008ML-50 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Sep 2018 04:58:36 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49083) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3Gi0-0006kh-8F for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3Ghx-00026d-K6 for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:40 -0400 Received: from mail-eopbgr70098.outbound.protection.outlook.com ([40.107.7.98]:35648 helo=EUR04-HE1-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 1g3Ghx-0001yN-B7 for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:37 -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:X-MS-Exchange-SenderADCheck; bh=QkYzzwr5zzVRqRaCU+tPXUsJiFM3BG57ktO7T6gfu5U=; b=TcvrQCk1jXpE8Bhy5TqhoK0ORkD9+3mjdlptVng/GVN2x3Tydd2tDqws7cUMhMZGFvI+aKtTIz+bsmAU70igKWyZIwtk9jSX9032bsYcB86/N9uVG9SVIlMyW/rprvdhjzE04hh8BqTuSQcj3uIqKfbiglV+7qRVxNzawgRf4fw= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (185.231.240.5) by AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.18; Fri, 21 Sep 2018 08:22:34 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2018 11:22:11 +0300 Message-Id: <20180921082217.29481-5-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921082217.29481-1-rkagan@virtuozzo.com> References: <20180921082217.29481-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: VI1P193CA0003.EURP193.PROD.OUTLOOK.COM (2603:10a6:800:bd::13) To AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ceed3755-a359-4454-9885-08d61f9b62d6 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB3588; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 3:a/aQywTXx/vJhClzkeYHfu6iypR48fJat6/I53j2tbfKgbngut6YbjkgZRNI2z3VxPJEqxjaV6EIxcEL3XI4U9nrgnpC/YJsQ36QBHKoHjs94arWfXhZu+TgkqOqAvptLzzJjiPR9fTsLZPJcu1CKI2uM2r6tXCSLD1HXtC8uVjhr4ZSOnjLNfDQc/k5VF3E86eEZBcLxYkX+ea1O76U/nX/NpIagqwM7YquuCfYZehlr/NGWmj0rVduV3pOh06j; 25:TQWfH0mkUll2e8BKSb659ge7NdBMKX106f5DHiQ7QDXKpiTXTK0IqlGHWBBDxpSDugcn1nVN3wDOhJYrKT3bfRMGLzprgvZuMFq3NbKZT54iRlRewQ6gjx+SLZp8FDLezTKOvbiuytcQiroYM9MRyqc2x6nvr6yy2g49Ln0yaCUDlwej8NBNAyBhDzT0WiqixuaByf7GR0CnHnlWF6/oq8Tg9You8/iigxE3tDECDTob0aGeaU8ONd0DJThWxwyI7mEZhbTEaZdROnGLWPkXRU65ODW8xki7quZZMQE0QbFUofzRFgQP8QnZGX58AYvw+j6PBkn+k8paB37yl1Vt5A==; 31:Md8mZ6mmRTAb0ffPuo9rD6Q0Do3SZVSVXmfHxef/W2iNxzBKSeDBEw82FN9pjVfIqR4TMZkPssP4uhO2IHXmf321DRWWeC/VGdoQFzShJmAjp2ut243RPSLJHhiRs3ogWVAz/LeUy4x+D//7SdNl4mM+nPXyKLznB/vmjZYqi905plUfljxgcdTo5v4zwEoiRYao/G5G6sknz6uKGEcqHnDrNZ8TiaKhM1jEDQ7Iapk= X-MS-TrafficTypeDiagnostic: AM0PR08MB3588: X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 20:VO/L1/MFGCuNZMrYcWp1Y1e9DFILxb+sF5nHhNzhVeYOQjrJt8J2x8pxGl8S19SnXfWsC5/zOYFn/wro0Sfj2OmCOlexhTpaIjpEaZQjeHsSiVDtQUA83SsP6cbf/kf7+nThIGeV1GL45rx2nfHQU8gSI4BWxAdZnnT4XAzNb9um29Sx78sdgNghlQ5jdl+gwIQjt7t//5pI6vhvUWSxrma9yM1e7SmxlJ9m5ic65sOjC99raH5fH/HFv+MofJNRgifsXNYq4WdK+TFaeYppoOAOinoh+FvATd8w68rct0BPmQ6x7wuBnwCjs7OEnl+/T3SZm/inCquE5xKFV0Mc8xRg9J/74DQ3z6kX24LkZvcc5VXj+5SzACRkpoZPnCLGqsoeS8JKOND0Pp7E77YvgpwiRSfh4/VV6yHAGsrsxP5m+kKoeN+ToGGulwYKgnDV6IrpUNiK5+LDuhdjsysE2RK71xPw+NXoNbjJwzffUECdLmz10LOWr+5FSdYRD+Wc; 4:mWHYqdMEA5dSurchnS+gvI9Q39ppVM0kCVe31wWJ8s8JZiGyMWSTM/FnHW2MU3svTO3gnSPEwVIJXjaCN9B/xyre1sVuC3Y3ZJqq5+efNFkazN1OmFapak/53t88yyA4qASukvJDo4BAzPJ8acW5rDlTD4is8oOJJMSm8E/9ZOj+RuIzkiXjzEk0KlzxoZ10BKmm+Rgj0OKuwxpex3a9uxGF9jVx8tvULi4uDW9Mf0nO+LMyZjenazFnrS/K+8xKysFcjMuszudrQKB3vTz2Ew== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231355)(944501410)(52105095)(10201501046)(3002001)(149027)(150027)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(201708071742011)(7699051); SRVR:AM0PR08MB3588; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB3588; X-Forefront-PRVS: 0802ADD973 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(346002)(136003)(396003)(39850400004)(366004)(376002)(189003)(199004)(6916009)(16526019)(5660300001)(36756003)(3846002)(54906003)(48376002)(6506007)(476003)(486006)(14444005)(52116002)(446003)(1076002)(76176011)(386003)(51416003)(186003)(6116002)(16586007)(2906002)(66066001)(6512007)(7416002)(50226002)(53936002)(25786009)(106356001)(53416004)(81166006)(47776003)(316002)(956004)(11346002)(2616005)(7736002)(8936002)(305945005)(8676002)(2351001)(105586002)(97736004)(4326008)(86362001)(6666003)(68736007)(478600001)(6486002)(2361001)(50466002)(26005)(69596002)(81156014); DIR:OUT; SFP:1102; SCL:1; SRVR:AM0PR08MB3588; H:rkaganb.sw.ru; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR08MB3588; 23:FX6AGDI2rr8AHgAoKO12TBNbtHHwX7kZ3ItehRTn8?= FzBosH8aHBoAI9P41LpJ0tfCXoTO9WZ44eIZSpNouwEVgw7D97epRDiwQkpWkmEu9jjAcpu4yzMnbYJTDE6wfHd7XyEMQej4NMieg0LmFbAHOU6u1TdqO4htdAHFxTdis4xBO/QkLNq2Jncf0/fpp3BgBIfaF1cNtXtxIPVlLS7mUFILTnPPpUWYuCxj8Asc2F5fc7e8wrH+h7D+tzHBRo7TXYbtHv+DJeJErdw80hpzoqbmRlBQS7CjPNBsUunqsb4A4zDNHhQQRxPMjjbbDFblmn38p1GK8KJnJS6K6qSe18qtQHZ9QuSVu/XHMIl1vy7dpq1brq2M8LAg1hIF0aJgplHsn8+yEQi+oRBqFZuHq16yD7qfIA+4v6Iy39gojtWr+5E0WcK5V90+KngGtSaJKoVzl5oYtbtwcrHpTfmm7XepGQvtQ3rB7fCPymXLcCEUiTzpJLyfL4UrB10PVtwCS9yJgv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pnaaWxUeujkBLcP9caiCp4pGHwUTLbCu4FEunzAVW1bZXHpSoBbzwovUKELFcotPb8S0evJnrGjopydxyVJ7EqMWCxIuZnnydcEjengA== X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 6:jeOgNhQp1u6g8W9pEjGI5yI0pR8Ecbu8uKUiyYhK0PoDQP4PMSMoDP/cRXyDYvTtZf/XPzbYMYOQ+4DApuci4abkYKCuy0EgxtNbIKFBu6i81TMdWuco9qQmACJjfvOVbTROPlRuGgDj5AJeWSD5J5ljUESu6HfcEQZPHpidIiZbxVSFxujPQjk8w/GbDIQNsxRB5djNc8H0m12CxlbFRsnBIEiKHogaG0353JS1jpit4Odh6Pl4erj6teqv4l/vneB3qQWZN3WAZCppmBpyiwCeRm975/+ArIY60NuYbsf6G4CfcYz2ciR1L0Vt8ulUWfgWn+LsaorAnimrpNzSyCcCClusUoCsISXXU7xqPdopjV47tmGXxn2W1EAsGqqOISzAejPO0KWju+fBGNXve6FPO1FGIpjwkJQgaLROMG325LkzmPRMwIllXzw6e7I9bO21j693Y8owP06MBfwRXQ==; 5:BwXQxTooL7HmV616oVs9xTepQvckJ7l7p+cNoO4hFy1svRIbenFVySP2KosJIlT2Ahb/Yo3pp4LvolttkgThS9/373U36gaJmvXEJ1wqfMFvD22ra0zUZjDn7I1djxrLrkfQNJg2MLz2Nyum3IRb5NSR/bhE/2sXe9QE0wu/EUc=; 7:vytdScTW1QnLO0cCPV7N0TlGzoVU52BQZGHTu7Szvx7OJPm+1IlgHv2VrBFL7NM+wBL/JOwG24ZGPBvJQzcRR8aD6peLwUD45CQA/eRDTD9+MRX37dtr7rcEE59OHBBM18APdE5i0QH+L1SPcihJL5QUR2bVmonkZTHM3FqwwDm2ENsl6mjpDWSeKCMzMfTQXfuk/jXz1dSyqKDKfNI1x3odEWShzQoyAuNWaRsqpNDrnD0GsKVc8b2rkWqBZk5e SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 20:aPUo36Zrt9rCC07knDOZ7w0RaJs2dZOjlWC/XDyfrA+BYhvSA26tQ+paWjELqhBB9haVckCL/rfTnC5QdFmfbunKRE/MosytNsWEMUZzF6hPmVxUKbb91z9QgPWLv71pVFiFb2zXeGmHMhOrQYMeSLSNVpFGd2mCd4UaayIMLBs= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2018 08:22:34.6880 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ceed3755-a359-4454-9885-08d61f9b62d6 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3588 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.7.98 Subject: [Qemu-devel] [PATCH 04/10] 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: Vijayabhaskar Balakrishna , Eduardo Habkost , Konrad Rzeszutek Wilk , "Michael S. Tsirkin" , Venu Busireddy , Liran Alon , Paolo Bonzini , Si-Wei Liu , Igor Mammedov , Boris Ostrovsky , Karl Heubaum 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 happens to (mostly) work because the actual guests seem not to depend on the features listed above. This patch implements those pages as the spec mandates. Since the extra RAM regions, which introduce migration incompatibility, are only added at SynIC object creation which only happens when hyperv_synic_kvm_only == false, no extra compat logic is necessary. Signed-off-by: Roman Kagan --- hw/hyperv/hyperv.c | 51 +++++++++++++++++++++++++++++++++++++++++--- target/i386/hyperv.c | 20 +++++++++++------ 2 files changed, 62 insertions(+), 9 deletions(-) diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index 3d6f044282..70cf129d04 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -10,6 +10,7 @@ #include "qemu/osdep.h" #include "qemu/main-loop.h" #include "qapi/error.h" +#include "exec/address-spaces.h" #include "sysemu/kvm.h" #include "hw/hyperv/hyperv.h" @@ -21,6 +22,10 @@ typedef struct SynICState { bool enabled; hwaddr msg_page_addr; hwaddr event_page_addr; + MemoryRegion msg_page_mr; + MemoryRegion event_page_mr; + struct hyperv_message_page *msg_page; + struct hyperv_event_flags_page *event_page; } SynICState; #define TYPE_SYNIC "hyperv-synic" @@ -36,8 +41,28 @@ static void synic_update(SynICState *synic, bool enable, { synic->enabled = enable; - synic->msg_page_addr = msg_page_addr; - synic->event_page_addr = event_page_addr; + if (synic->msg_page_addr != msg_page_addr) { + if (synic->msg_page_addr) { + memory_region_del_subregion(get_system_memory(), + &synic->msg_page_mr); + } + if (msg_page_addr) { + memory_region_add_subregion(get_system_memory(), msg_page_addr, + &synic->msg_page_mr); + } + synic->msg_page_addr = msg_page_addr; + } + if (synic->event_page_addr != event_page_addr) { + if (synic->event_page_addr) { + memory_region_del_subregion(get_system_memory(), + &synic->event_page_mr); + } + if (event_page_addr) { + memory_region_add_subregion(get_system_memory(), event_page_addr, + &synic->event_page_mr); + } + synic->event_page_addr = event_page_addr; + } } void hyperv_synic_update(CPUState *cs, bool enable, @@ -54,11 +79,31 @@ void hyperv_synic_update(CPUState *cs, bool enable, static void synic_realize(DeviceState *dev, Error **errp) { + Object *obj = OBJECT(dev); + SynICState *synic = SYNIC(dev); + char *msgp_name, *eventp_name; + uint32_t vp_index; + + /* memory region names have to be globally unique */ + vp_index = hyperv_vp_index(synic->cs); + msgp_name = g_strdup_printf("synic-%u-msg-page", vp_index); + eventp_name = g_strdup_printf("synic-%u-event-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->event_page_mr, obj, eventp_name, + sizeof(*synic->event_page), &error_abort); + synic->msg_page = memory_region_get_ram_ptr(&synic->msg_page_mr); + synic->event_page = memory_region_get_ram_ptr(&synic->event_page_mr); + + g_free(msgp_name); + g_free(eventp_name); } - static void synic_reset(DeviceState *dev) { SynICState *synic = SYNIC(dev); + memset(synic->msg_page, 0, sizeof(*synic->msg_page)); + memset(synic->event_page, 0, sizeof(*synic->event_page)); synic_update(synic, false, 0, 0); } diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 0216735d67..3f76c3e266 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -12,6 +12,7 @@ */ #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "hyperv.h" #include "hw/hyperv/hyperv.h" #include "hyperv-proto.h" @@ -38,6 +39,13 @@ void hyperv_x86_synic_update(X86CPU *cpu) hyperv_synic_update(CPU(cpu), enable, msg_page_addr, event_page_addr); } +static void async_synic_update(CPUState *cs, run_on_cpu_data data) +{ + qemu_mutex_lock_iothread(); + hyperv_x86_synic_update(X86_CPU(cs)); + qemu_mutex_unlock_iothread(); +} + int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) { CPUX86State *env = &cpu->env; @@ -48,11 +56,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; @@ -67,7 +70,12 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) return -1; } - hyperv_x86_synic_update(cpu); + /* + * this will run in this cpu thread before it returns to KVM, but in a + * safe environment (i.e. when all cpus are quiescent) -- this is + * necessary because memory hierarchy is being changed + */ + async_safe_run_on_cpu(CPU(cpu), async_synic_update, RUN_ON_CPU_NULL); return 0; case KVM_EXIT_HYPERV_HCALL: { From patchwork Fri Sep 21 08:22:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10609387 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8493015A6 for ; Fri, 21 Sep 2018 09:01:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 728132D890 for ; Fri, 21 Sep 2018 09:01:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6644D2D895; Fri, 21 Sep 2018 09:01:36 +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=-7.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,MAILING_LIST_MULTI,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 5F9CA2D890 for ; Fri, 21 Sep 2018 09:01:35 +0000 (UTC) Received: from localhost ([::1]:54627 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3HJe-0003AW-72 for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Sep 2018 05:01:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49116) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3Gi3-0006rF-ER for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3Gi0-00029l-4B for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:43 -0400 Received: from mail-eopbgr70091.outbound.protection.outlook.com ([40.107.7.91]:35048 helo=EUR04-HE1-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 1g3Ghz-00027r-Je for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:40 -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:X-MS-Exchange-SenderADCheck; bh=h1TF3puJSDhV4pijmNyVfa1Qzqz5IWEO/QCphaTlqic=; b=iQKE+zrDm/fUwuPZXKxYAA++TxJ+9Y3YyJL0eXK5zFeAI0S6tiJMOF99PHNoULB90AY3ehNXf7qpjIuh8ZM3AjRpzuz9YHuN5lIc4cgOLANwwgEY6LnAh48zkZuy5Djlzx03ARvFPMBn0II5zaEOiB03is5vIg1VCWSBeOiWH9U= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (185.231.240.5) by AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.18; Fri, 21 Sep 2018 08:22:36 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2018 11:22:12 +0300 Message-Id: <20180921082217.29481-6-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921082217.29481-1-rkagan@virtuozzo.com> References: <20180921082217.29481-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: VI1P193CA0003.EURP193.PROD.OUTLOOK.COM (2603:10a6:800:bd::13) To AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3a02a6a1-074b-4c23-3f59-08d61f9b63b4 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB3588; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 3:GcISga/XmIBueht9pv3lQhoVfY4sY8CNrFtEe4L0xmTPdWLfPJnu8+xEaK4MIitEZOnfhCKBygftXR+tT+fBTHFk9wCy+VMfZqtLeQaSunmSieqFMMWx/hFmkpEe4bEXc0fm8lrnxDmIvuvNOlTSbVl5mdv9frPp21EmkKYEU6DBJlYbnBzeL+788I3C3MZGKyjrGyFF4R6n8nBVxEzrr4UN5v/7eVjadCFD4lvaxITqLAgfGgdMYnxqsI1pe+gQ; 25:0wFBoz1mX+EIXyEmgw8ZI7vHzsDZcCBU0XhNOxkf7pUdMzXhnppsZe/mJCYqVSLY5Tdp/AqwEH+omLfyy/XmtayQZSMcKFs8bECw1R2SiaxHp//fRNFpYFaFtGQmeFci5mjDglZeBSAZ3HExXl/VdjgVrXnzoyKmI0ym5fCYzF8hibaCwr0xuiSEUJiEqh6MsOumk0qnrLNSo1hmUakeH3mFd9mLpR+Rndscbaf87hyZ6u8bk4V9RdiMijk+N86x4W1MCctISvrwPAGr+zSniiJJnSsHpo+NAbDA/P4+wgi1fa15mH50N+/HaWVPY2WMhsmw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3cPebA9He3UYyFO4YftDhOoOLdXvBR91ou+xqqN6MRxcPpICPSG+FvjJNCN4SxYyun62d9LCfPBJ9blg== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231355)(944501410)(52105095)(10201501046)(3002001)(149027)(150027)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(201708071742011)(7699051); SRVR:AM0PR08MB3588; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB3588; X-Forefront-PRVS: 0802ADD973 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(346002)(136003)(396003)(39850400004)(366004)(376002)(189003)(199004)(6916009)(16526019)(5660300001)(36756003)(3846002)(54906003)(48376002)(6506007)(476003)(486006)(14444005)(52116002)(446003)(1076002)(76176011)(386003)(51416003)(186003)(6116002)(16586007)(15650500001)(2906002)(66066001)(6512007)(7416002)(50226002)(53936002)(25786009)(106356001)(53416004)(81166006)(47776003)(316002)(956004)(11346002)(2616005)(7736002)(8936002)(305945005)(8676002)(2351001)(105586002)(97736004)(4326008)(86362001)(6666003)(68736007)(478600001)(6486002)(2361001)(50466002)(26005)(69596002)(81156014); DIR:OUT; SFP:1102; SCL:1; SRVR:AM0PR08MB3588; H:rkaganb.sw.ru; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR08MB3588; 23:g0nYmrljPNIj88b4QMEMFfBZkSO5FMfhQds5CDTWW?= myWp0Uajfe0BTrfJGDyBmlxwZ9GR7fVpdlLuRLhYRWEil9mcY3jnEebS43UgPOWaujLqBuOFdgA3gOeINUI9+AwRcuL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MfkUzbIzmqdX8RTITKsZraxMmlT3vh7tZzKMP9jwS50BqRjNyDjnztB0pkhskP2hwviCAfHmjtnojjnnmw25QPy0nDz88ZXILCBRqiEPQ6Agi2A+4uWcwKumjAR79+248Hrl23l5eicI5B7PEJuFI3aGBgQP6c=; 7:BqEubzjP2c9YhSJ37mx1mfRP6Hp00C8b+HrtOiwy0dAH+CLizr2rLXGGmlmDUVJ+KqVbYZu5TKtpdQsF0CBkwiRKV6oek5Yi+jb7m9W4waCrX/GwDXVKY89QZIgOaueUDD9/0rGZPSOilu44nfg6gXI00h0j3TjB/V6o/naA6D34SR9Iap38c72D7eeu/DjWt/7MNpQNoLRYwHNyMtin3KaPGSaSdyNr8f7adhvCDsCXAwYDnJ12ldJeCP7UBeVo SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 20:8nSftaQ6AjNqfLEgrU6T+QtVDVNw6xncmLWm57rFVciyCs6DfCCykvqbyeQtwTgA5SdoL8NMABXHthbgDxQ4jZ+MbZe4QUkxc/6RF75QpcghNr1105ioUyL0wyMkHtcOm1eQ3SehPBi3COnWXSBkOGSPlg/CB6vegrcchIMX+Is= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2018 08:22:36.1563 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3a02a6a1-074b-4c23-3f59-08d61f9b63b4 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3588 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.7.91 Subject: [Qemu-devel] [PATCH 05/10] hyperv: add synic message delivery 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: Vijayabhaskar Balakrishna , Eduardo Habkost , Konrad Rzeszutek Wilk , "Michael S. Tsirkin" , Venu Busireddy , Liran Alon , Paolo Bonzini , Si-Wei Liu , Igor Mammedov , Boris Ostrovsky , Karl Heubaum Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add infrastructure to deliver SynIC messages to the SynIC message page. Note that KVM may also want to deliver (SynIC timer) messages to the same message slot. The problem is that the access to a SynIC message slot is controlled by the value of its .msg_type field which indicates if the slot is being owned by the hypervisor (zero) or by the guest (non-zero). This leaves no room for synchronizing multiple concurrent producers. The simplest way to deal with this for both KVM and QEMU is to only deliver messages in the vcpu thread. KVM already does this; this patch makes it for QEMU, too. Specifically, - add a function for posting messages, which only copies the message into the staging buffer if its free, and schedules a work on the corresponding vcpu to actually deliver it to the guest slot; - instead of a sint ack callback, set up the sint route with a message status callback. This function is called in a bh whenever there are updates to the message slot status: either the vcpu made definitive progress delivering the message from the staging buffer (succeeded or failed) or the guest issued EOM; the status is passed as an argument to the callback. Signed-off-by: Roman Kagan --- include/hw/hyperv/hyperv.h | 18 ++++- hw/hyperv/hyperv.c | 162 ++++++++++++++++++++++++++++++++++--- 2 files changed, 166 insertions(+), 14 deletions(-) diff --git a/include/hw/hyperv/hyperv.h b/include/hw/hyperv/hyperv.h index 6fba4762c8..82d561fc88 100644 --- a/include/hw/hyperv/hyperv.h +++ b/include/hw/hyperv/hyperv.h @@ -11,18 +11,30 @@ #define HW_HYPERV_HYPERV_H #include "cpu-qom.h" +#include "hw/hyperv/hyperv-proto.h" typedef struct HvSintRoute HvSintRoute; -typedef void (*HvSintAckClb)(void *data); + +/* + * Callback executed in a bottom-half when the status of posting the message + * becomes known, before unblocking the connection for further messages + */ +typedef void (*HvSintMsgCb)(void *data, int status); HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, - HvSintAckClb sint_ack_clb, - void *sint_ack_clb_data); + HvSintMsgCb cb, void *cb_data); void hyperv_sint_route_ref(HvSintRoute *sint_route); void hyperv_sint_route_unref(HvSintRoute *sint_route); int hyperv_sint_route_set_sint(HvSintRoute *sint_route); +/* + * Submit a message to be posted in vcpu context. If the submission succeeds, + * the status of posting the message is reported via the callback associated + * with the @sint_route; until then no more messages are accepted. + */ +int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *msg); + static inline uint32_t hyperv_vp_index(CPUState *cs) { return cs->cpu_index; diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index 70cf129d04..21217631dc 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -148,14 +148,51 @@ static void synic_register_types(void) type_init(synic_register_types) +/* + * KVM has its own message producers (SynIC timers). To guarantee + * serialization with both KVM vcpu and the guest cpu, the messages are first + * staged in an intermediate area and then posted to the SynIC message page in + * the vcpu thread. + */ +typedef struct HvSintStagedMesage { + /* message content staged by hyperv_post_msg */ + struct hyperv_message msg; + /* callback + data (r/o) to complete the processing in a BH */ + HvSintMsgCb cb; + void *cb_data; + /* message posting status filled by cpu_post_msg */ + int status; + /* passing the buck: */ + enum { + /* initial state */ + HV_STAGED_MSG_FREE, + /* + * hyperv_post_msg (e.g. in main loop) grabs the staged area (FREE -> + * BUSY), copies msg, and schedules cpu_post_msg on the assigned cpu + */ + HV_STAGED_MSG_BUSY, + /* + * cpu_post_msg (vcpu thread) tries to copy staged msg to msg slot, + * notify the guest, records the status, marks the posting done (BUSY + * -> POSTED), and schedules sint_msg_bh BH + */ + HV_STAGED_MSG_POSTED, + /* + * sint_msg_bh (BH) verifies that the posting is done, runs the + * callback, and starts over (POSTED -> FREE) + */ + } state; +} HvSintStagedMesage; + struct HvSintRoute { uint32_t sint; SynICState *synic; int gsi; EventNotifier sint_set_notifier; EventNotifier sint_ack_notifier; - HvSintAckClb sint_ack_clb; - void *sint_ack_clb_data; + + HvSintStagedMesage *staged_msg; + unsigned refcount; }; @@ -166,17 +203,115 @@ static CPUState *hyperv_find_vcpu(uint32_t vp_index) return cs; } -static void kvm_hv_sint_ack_handler(EventNotifier *notifier) +/* + * BH to complete the processing of a staged message. + */ +static void sint_msg_bh(void *opaque) +{ + HvSintRoute *sint_route = opaque; + HvSintStagedMesage *staged_msg = sint_route->staged_msg; + + if (atomic_read(&staged_msg->state) != HV_STAGED_MSG_POSTED) { + /* status nor ready yet (spurious ack from guest?), ignore */ + return; + } + + staged_msg->cb(staged_msg->cb_data, staged_msg->status); + staged_msg->status = 0; + + /* staged message processing finished, ready to start over */ + atomic_set(&staged_msg->state, HV_STAGED_MSG_FREE); + /* drop the reference taken in hyperv_post_msg */ + hyperv_sint_route_unref(sint_route); +} + +/* + * Worker to transfer the message from the staging area into the SynIC message + * page in vcpu context. + */ +static void cpu_post_msg(CPUState *cs, run_on_cpu_data data) +{ + HvSintRoute *sint_route = data.host_ptr; + HvSintStagedMesage *staged_msg = sint_route->staged_msg; + SynICState *synic = sint_route->synic; + struct hyperv_message *dst_msg; + bool wait_for_sint_ack = false; + + assert(staged_msg->state == HV_STAGED_MSG_BUSY); + + if (!synic->enabled || !synic->msg_page_addr) { + staged_msg->status = -ENXIO; + goto posted; + } + + dst_msg = &synic->msg_page->slot[sint_route->sint]; + + if (dst_msg->header.message_type != HV_MESSAGE_NONE) { + dst_msg->header.message_flags |= HV_MESSAGE_FLAG_PENDING; + staged_msg->status = -EAGAIN; + wait_for_sint_ack = true; + } else { + memcpy(dst_msg, &staged_msg->msg, sizeof(*dst_msg)); + staged_msg->status = hyperv_sint_route_set_sint(sint_route); + } + + memory_region_set_dirty(&synic->msg_page_mr, 0, sizeof(*synic->msg_page)); + +posted: + atomic_set(&staged_msg->state, HV_STAGED_MSG_POSTED); + /* + * Notify the msg originator of the progress made; if the slot was busy we + * set msg_pending flag in it so it will be the guest who will do EOM and + * trigger the notification from KVM via sint_ack_notifier + */ + if (!wait_for_sint_ack) { + aio_bh_schedule_oneshot(qemu_get_aio_context(), sint_msg_bh, + sint_route); + } +} + +/* + * Post a Hyper-V message to the staging area, for delivery to guest in the + * vcpu thread. + */ +int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *src_msg) +{ + HvSintStagedMesage *staged_msg = sint_route->staged_msg; + + assert(staged_msg); + + /* grab the staging area */ + if (atomic_cmpxchg(&staged_msg->state, HV_STAGED_MSG_FREE, + HV_STAGED_MSG_BUSY) != HV_STAGED_MSG_FREE) { + return -EAGAIN; + } + + memcpy(&staged_msg->msg, src_msg, sizeof(*src_msg)); + + /* hold a reference on sint_route until the callback is finished */ + hyperv_sint_route_ref(sint_route); + + /* schedule message posting attempt in vcpu thread */ + async_run_on_cpu(sint_route->synic->cs, cpu_post_msg, + RUN_ON_CPU_HOST_PTR(sint_route)); + return 0; +} + +static void sint_ack_handler(EventNotifier *notifier) { HvSintRoute *sint_route = container_of(notifier, HvSintRoute, sint_ack_notifier); event_notifier_test_and_clear(notifier); - sint_route->sint_ack_clb(sint_route->sint_ack_clb_data); + + /* + * the guest consumed the previous message so complete the current one with + * -EAGAIN and let the msg originator retry + */ + aio_bh_schedule_oneshot(qemu_get_aio_context(), sint_msg_bh, sint_route); } HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, - HvSintAckClb sint_ack_clb, - void *sint_ack_clb_data) + HvSintMsgCb cb, void *cb_data) { HvSintRoute *sint_route; EventNotifier *ack_notifier; @@ -200,14 +335,19 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, goto err; } - ack_notifier = sint_ack_clb ? &sint_route->sint_ack_notifier : NULL; + + ack_notifier = cb ? &sint_route->sint_ack_notifier : NULL; if (ack_notifier) { + sint_route->staged_msg = g_new0(HvSintStagedMesage, 1); + sint_route->staged_msg->cb = cb; + sint_route->staged_msg->cb_data = cb_data; + r = event_notifier_init(ack_notifier, false); if (r) { goto err_sint_set_notifier; } - event_notifier_set_handler(ack_notifier, kvm_hv_sint_ack_handler); + event_notifier_set_handler(ack_notifier, sint_ack_handler); } gsi = kvm_irqchip_add_hv_sint_route(kvm_state, vp_index, sint); @@ -222,8 +362,6 @@ HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, goto err_irqfd; } sint_route->gsi = gsi; - sint_route->sint_ack_clb = sint_ack_clb; - sint_route->sint_ack_clb_data = sint_ack_clb_data; sint_route->synic = synic; sint_route->sint = sint; sint_route->refcount = 1; @@ -236,6 +374,7 @@ err_gsi: if (ack_notifier) { event_notifier_set_handler(ack_notifier, NULL); event_notifier_cleanup(ack_notifier); + g_free(sint_route->staged_msg); } err_sint_set_notifier: event_notifier_cleanup(&sint_route->sint_set_notifier); @@ -266,9 +405,10 @@ void hyperv_sint_route_unref(HvSintRoute *sint_route) &sint_route->sint_set_notifier, sint_route->gsi); kvm_irqchip_release_virq(kvm_state, sint_route->gsi); - if (sint_route->sint_ack_clb) { + if (sint_route->staged_msg) { event_notifier_set_handler(&sint_route->sint_ack_notifier, NULL); event_notifier_cleanup(&sint_route->sint_ack_notifier); + g_free(sint_route->staged_msg); } event_notifier_cleanup(&sint_route->sint_set_notifier); g_free(sint_route); From patchwork Fri Sep 21 08:22:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10609389 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3DA9614BD for ; Fri, 21 Sep 2018 09:03:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E29D2DBD5 for ; Fri, 21 Sep 2018 09:03:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 223DD2DBE4; Fri, 21 Sep 2018 09:03:34 +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=-7.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,MAILING_LIST_MULTI,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 9B18F2DBD5 for ; Fri, 21 Sep 2018 09:03:33 +0000 (UTC) Received: from localhost ([::1]:54636 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3HLZ-0005S6-0m for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Sep 2018 05:03:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49113) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3Gi3-0006r7-Dd for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3Gi0-0002Bw-NU for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:43 -0400 Received: from mail-eopbgr70091.outbound.protection.outlook.com ([40.107.7.91]:35048 helo=EUR04-HE1-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 1g3Gi0-00027r-EB for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:40 -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:X-MS-Exchange-SenderADCheck; bh=aIIgiQo5F7kikKwl6Fy7bkKEpILU9naRbFqsfE2gWYM=; b=X6rc1QkuQPnN/dngLZuSz4GNWHssKINcnWVF5KNfbzKhkjSTUw+OSTPNc7w138TAbgpzk3I9k7HPa8W7J+d8x9sLuE006KP5CQx0PptJSbg8XJqsiJFK0RFKWADLTQoVze8jDbcONWk+1jE++fk5ZELZhc96vsaVAFIP8qQlhwg= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (185.231.240.5) by AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.18; Fri, 21 Sep 2018 08:22:37 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2018 11:22:13 +0300 Message-Id: <20180921082217.29481-7-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921082217.29481-1-rkagan@virtuozzo.com> References: <20180921082217.29481-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: VI1P193CA0003.EURP193.PROD.OUTLOOK.COM (2603:10a6:800:bd::13) To AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2a739fd5-ba9c-465e-e640-08d61f9b6491 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB3588; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 3:JHA6Ja41BmT5Zhpwm3GpO83S6LLGJWL38mAagV6/S1IOwx/XCVGD0fxP1dgimh/BMxQKGZ9X2PwdMbN5X5uJGLvqd6cTgpzjQTc3ZUWZz0Uy871XujYVFMmyiELvJVNvpsppk/dAtSZ1PuOmThae6hKWIcfdxVTt3duvuFzEy6tfiGxPd/FiScEhqHSG01nEyN90aeu3mtd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HT6XowTGnwzONkvU7Bs60sB0zdz49JwIUPtvAbBwh/Z+mHri0gLVwsDgh5g6eO68KCPDMh7dZDnQgJx8mNt6aV0LaV/h2mrHVknrBqB96qyJcTQ4zANcUt8LgBMRZgoiFi4yjXL6jpBO; 4:nzwAnxLhQo2bC6OndFUmOGicSesMSfTwL3K98MXMmA3lay86zIRInDCq6lg99ArlZ3D2akNfK5c4utvNbjEAHuY5eTE2AFFoVyxD8F7BWw7JJxdBy1DQk7eXqBSB22a4J8fvy/PyAR2PE1KRyEBtUgDQpDvS7jmiGFEouMijvglMetXAHGl5DWBipTfntXD0/kTpR0/nhufwBWcB0NX81nnqqBJox58iMpzi9l6f7PhZe+Ti4hxHRxEMt7fd76QhtyqiM/SexCtrpcsZYfMxMA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231355)(944501410)(52105095)(10201501046)(3002001)(149027)(150027)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(201708071742011)(7699051); SRVR:AM0PR08MB3588; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB3588; X-Forefront-PRVS: 0802ADD973 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(346002)(136003)(396003)(39850400004)(366004)(376002)(189003)(199004)(6916009)(16526019)(5660300001)(36756003)(3846002)(54906003)(48376002)(6506007)(476003)(486006)(52116002)(446003)(1076002)(76176011)(386003)(51416003)(186003)(6116002)(16586007)(2906002)(66066001)(6512007)(7416002)(50226002)(53936002)(25786009)(106356001)(53416004)(81166006)(47776003)(316002)(956004)(11346002)(2616005)(7736002)(8936002)(305945005)(8676002)(2351001)(105586002)(97736004)(4326008)(86362001)(6666003)(68736007)(478600001)(6486002)(2361001)(50466002)(26005)(69596002)(81156014); DIR:OUT; SFP:1102; SCL:1; SRVR:AM0PR08MB3588; H:rkaganb.sw.ru; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR08MB3588; 23:oQTnBrFAX7v5zKgypIjRlkGotgOpJQvLMZNZpprz0?= gIUNo5keah6A0NDct6YvrEv7CFVqZGrucpuWkC2v+a0m7cks90H8/w5Hwu2ngRqFc4BTWrZNXggq8bUuAe3nBd/zpDhDalth91dy2bVEBAc7LdIwkDnIG7OjAVL0zxwM1ST9a4l3ifzETT8pR9JNm2hmbj5BdrvDGnc6GxKW3wToOj9EeL3OtXNgyzOfcAiMLYCZeRp4BOGfILeisdrs+18Fn7uGh96zOsC2BSJJzjpbcImkZOAOmvJsc8UhjPsw9GHlokGP86ByXRUBtsiAmNWC8fY/EBjEaIGjxltEckLumTJw+GIlmaV+3zDfNdR9R0k6w12Mojt1+1uv/JxwoHGsBukn5ESR7EKwQyTOLEDDbyW/4MDgZnVnLVlar39WltMfjB2QzUp/1fTC0/qSHHr4C4RIzP2NXlN21gwH2MzMF7L0ACtXl2hAWnCj2D8HZ2CA6/bZVUc8WdeOKu0mKnFAqrdxsyfOXDGj3fl4NcSqw5eNC7l7+rZZiFMR6zGjpFAfjSyLRJyjp1zvdntJZgjR4o3VIi8Sr/YE4IICF0rf47u3CyZ8lr3TpTQ0DQwY6j9tGH0XH9uG5Cdw/4g4HV3yLt4VyLalZYZEcIwK7uor6pQbSfWsEZ5tGgn5Fzi8DOvAgqpS1S51ng9Ee3xoKeR8wfDlklmOfIuNxerq4FDXjqO5nQQNg/Ts/DDEHeWI7iKvEG9kEnRoN/TfBWoh6NUCZzobCRcgJ07c0zqSiAbHsP6rMFmJNPUcCnCAxIXdvY5sZBZlrJpFDI+TnT9gAt2v16pWvqC1s9o1/4MZeifNF43eAzMThaGbImqHHK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F9tQdGaTmkrCB/AuMBACgSV+D+AgCOqOtrNqZ3IiKqkIOWxss8QH6GogSUE3xHlxNMCBpQFbWt6DQf75VLelei9b1HTo1vHrOwvs0IWqGA0+FwGiLqSPE6z5HpOXH2NrBWeNFKw4ybT91onPEDqc5wgabVnYDYyBzNjOzUHHW0ZS1wlKnHRI9XEv/r/5zKr0Af6TUBWIYZsx5atN9e3wlgsFEU8NLWQe+Vx+5SZLXg/KuS8kMAcP7TKWr99v43jia4n1agaWAZjYT0D3e8w==; 5:Y5ChrVMuX/hHqNEFQHr7JDHQt5VWOZHWa6DG7IqZEdhUTeEALBkeatJ0N2Lx0oIAJTvutdJdZEvDxB95Fu6SuSu/WhX0CTPVA8ph/lxppEXKkJNnr7rTBpg68+yIICvwbLWXXPm63C9f1Rj1QVO/fp4WwHlFCRAY+aU9StGbVcw=; 7:JCnvin3gDRlSyoEUgwYYGrSYfaV0J0Vw1Db73v0wa/Vzg6xyGubs0XhuKqOP81wpgAKLwG8Wp+KgOFo5d5fyjGaHrPDTwR0AsPltOsXXfyuq0r86XjOMXYQ2lhphRC34kWJ7sQcil2Kvaog18jlcOrsuJV9I/MNGERm6PfprDn+cWp4J35iEBb3EBRaqxAQnYjoa6jz+fB6HvX3hrA665oZv/+Xz3F2Fx4PNFVmd1jt1vetVHaq/5rmlJI6RGpxg SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 20:1fRiDyXHPenkQ7TYOqgC4eYoMB05SpNCHO0in+iQLFrFblOkzNUFVBiiwipeRlsEWj12a4MgIcUqkAh3VTF8UarqOTp9zEafiH+t9Sdas+cNPdrvDj46ga4iqo16e1S+DWjsagHpUC9Rnf9axNX1sVFNPmzEa6BPo/GZ4aqL/bg= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2018 08:22:37.6089 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2a739fd5-ba9c-465e-e640-08d61f9b6491 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3588 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.7.91 Subject: [Qemu-devel] [PATCH 06/10] hyperv: add synic event flag signaling 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: Vijayabhaskar Balakrishna , Eduardo Habkost , Konrad Rzeszutek Wilk , "Michael S. Tsirkin" , Venu Busireddy , Liran Alon , Paolo Bonzini , Si-Wei Liu , Igor Mammedov , Boris Ostrovsky , Karl Heubaum Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add infrastructure to signal SynIC event flags by atomically setting the corresponding bit in the event flags page and firing a SINT if necessary. Signed-off-by: Roman Kagan --- include/hw/hyperv/hyperv.h | 4 ++++ hw/hyperv/hyperv.c | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/hw/hyperv/hyperv.h b/include/hw/hyperv/hyperv.h index 82d561fc88..757c85eb8f 100644 --- a/include/hw/hyperv/hyperv.h +++ b/include/hw/hyperv/hyperv.h @@ -34,6 +34,10 @@ int hyperv_sint_route_set_sint(HvSintRoute *sint_route); * with the @sint_route; until then no more messages are accepted. */ int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *msg); +/* + * Set event flag @eventno, and signal the SINT if the flag has changed. + */ +int hyperv_set_event_flag(HvSintRoute *sint_route, unsigned eventno); static inline uint32_t hyperv_vp_index(CPUState *cs) { diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index 21217631dc..0b28e7922c 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -12,6 +12,7 @@ #include "qapi/error.h" #include "exec/address-spaces.h" #include "sysemu/kvm.h" +#include "qemu/bitops.h" #include "hw/hyperv/hyperv.h" typedef struct SynICState { @@ -310,6 +311,37 @@ static void sint_ack_handler(EventNotifier *notifier) aio_bh_schedule_oneshot(qemu_get_aio_context(), sint_msg_bh, sint_route); } +/* + * Set given event flag for a given sint on a given vcpu, and signal the sint. + */ +int hyperv_set_event_flag(HvSintRoute *sint_route, unsigned eventno) +{ + int ret; + SynICState *synic = sint_route->synic; + unsigned long *flags, set_mask; + unsigned set_idx; + + if (eventno > HV_EVENT_FLAGS_COUNT) { + return -EINVAL; + } + if (!synic->enabled || !synic->event_page_addr) { + return -ENXIO; + } + + set_idx = BIT_WORD(eventno); + set_mask = BIT_MASK(eventno); + flags = synic->event_page->slot[sint_route->sint].flags; + + if ((atomic_fetch_or(&flags[set_idx], set_mask) & set_mask) != set_mask) { + memory_region_set_dirty(&synic->event_page_mr, 0, + sizeof(*synic->event_page)); + ret = hyperv_sint_route_set_sint(sint_route); + } else { + ret = 0; + } + return ret; +} + HvSintRoute *hyperv_sint_route_new(uint32_t vp_index, uint32_t sint, HvSintMsgCb cb, void *cb_data) { From patchwork Fri Sep 21 08:22:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10609401 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5E3F514BD for ; Fri, 21 Sep 2018 09:09:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D25A2D607 for ; Fri, 21 Sep 2018 09:09:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4107B2D60E; Fri, 21 Sep 2018 09:09:15 +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=-7.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,MAILING_LIST_MULTI,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 92E0B2D607 for ; Fri, 21 Sep 2018 09:09:14 +0000 (UTC) Received: from localhost ([::1]:54672 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3HR3-0002FM-HH for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Sep 2018 05:09:13 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49159) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3Gi6-0006xv-Lo for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3Gi3-0002Kl-Bv for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:46 -0400 Received: from mail-eopbgr70119.outbound.protection.outlook.com ([40.107.7.119]:27680 helo=EUR04-HE1-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 1g3Gi2-0002FC-To for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:43 -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:X-MS-Exchange-SenderADCheck; bh=M/ORs6XTTAgnTGUzG+ja1vmx6QNcaXwB/S7aaxRlaxM=; b=RbfBZwZ+NVHb1Abj5ykBMtUvoOx7eTGIagD56ULS1djCqRvtnTJD/ea7OnkOIg6alTC3i7JUSVQn0NkI5x8xMCmoLskp1wiE6UIvnxn3SmtM6CmiYojJ6pnznQF/HWVxIy1welC8NgjTDJOXOBDYYT3KEX/xFzB07MSCsVDLA8E= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (185.231.240.5) by AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.18; Fri, 21 Sep 2018 08:22:39 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2018 11:22:14 +0300 Message-Id: <20180921082217.29481-8-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921082217.29481-1-rkagan@virtuozzo.com> References: <20180921082217.29481-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: VI1P193CA0003.EURP193.PROD.OUTLOOK.COM (2603:10a6:800:bd::13) To AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 46e4ba1b-bfd1-4dd7-d5bb-08d61f9b659c X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB3588; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 3:rNmx+0DYw4Hfw50MtdHi6rUsjwwmLDLUqQ/T75IboljK/ilzx6qli9/GsP0DW2GqcEDYkhKfJQn1ZAyGydsS3bDnlRdGx/1Ik9dVaAc6ZYf2MPVrXmo0iJgiKRE5LnSLD30WK3lwll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uuHfyDz73BFAtwiObDcKU1r34L7vE6+cfgsVgxjEjfNpn69WfOKntSnFvE1T3B4T+wZfBr4HwNbDWIINq5s0e+DQD8jQjLKs5pLOiYD92EcyCP+I1oNrafzMq9oyhhJ3BQJY3JD3+/dFMZJARFKhRtNnOjxRMKlle7lm3psBYGJVNq+ly2ppHUd816BpYMpnppmUAqxaAf32; 4:9aPI8WpacxFfGSLKBrA9Z8et5WAvKR/4YXIrKCuMJwLrK+AkKWHynvrklcIVIZCega0UnHk307upE4ZUK6b4yNLwB2hmCIDlBbFYwtoq7OirODXEtRGH1Ouk+fNbraU9RXEzN+ZUnmNfADxcQsPbx+eIDyJmONWmX10ktKyOhHmRGlhe5MXwK0bKNWKQSLBUAavng8VEnMddcNWn+vLs1LhSd6CPzW7soYuDHADpWrBaBwMumkbZnV75VLmQbSoiB0icikIpYKEoHChvv5yfFw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231355)(944501410)(52105095)(10201501046)(3002001)(149027)(150027)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(201708071742011)(7699051); SRVR:AM0PR08MB3588; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB3588; X-Forefront-PRVS: 0802ADD973 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(346002)(136003)(396003)(39850400004)(366004)(376002)(189003)(199004)(6916009)(16526019)(5660300001)(36756003)(3846002)(54906003)(48376002)(6506007)(476003)(486006)(14444005)(52116002)(446003)(1076002)(76176011)(386003)(51416003)(186003)(6116002)(16586007)(2906002)(66066001)(6512007)(7416002)(50226002)(53936002)(25786009)(106356001)(53416004)(81166006)(47776003)(316002)(956004)(11346002)(2616005)(7736002)(8936002)(305945005)(8676002)(2351001)(105586002)(97736004)(4326008)(86362001)(6666003)(68736007)(478600001)(6486002)(2361001)(50466002)(26005)(69596002)(81156014); DIR:OUT; SFP:1102; SCL:1; SRVR:AM0PR08MB3588; H:rkaganb.sw.ru; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR08MB3588; 23:yL9wgCnSxGF4MDQM3aUOnuSNvw30Pz1uCO9kyWjIB?= JDR+qHWAeTYv4uEFH4FZquJWTB1+XM3YnoLtyLLl1HbBC52gfkhWidKgiKZJZC+12yMqDmg5OakgTidnKedHeans+kmJuPh9H3zpnFZt3BlxUBgBH7LFt/mWtOZ4TBHwWE2TPPXSAH26jViBhVJFQ2E8Veoe8IfbjWXo59PAQRU6d7Qp2tKw/SC8zsfS56mFxAaPnw+iIDZxaz894XFGwzADPMyTWSSAeBxhvzTvGiE41XeHNzfA+gYxaMcmp3JcXg1ox1dIMQYTIKO1+E9uQYhXjqFc4iQSP/FOnfGlXbfPgHOyyf9YHTrkfaF20f42PYoKFqF5XwfdA3rG1PujQogeyn/dEBmLjTqvvXpr/vC77kWbdJ8LlkYkImVlnOstT7lIfdoKsxqjQdUHB9DyClAOB4ZHTraMeAR5JcZsArzWZUtiJCcUhRCQk6mMFUsuT0dsKDrdQVkNU3UQmPuDxuDPAi04N5TCf64HYRc1LKLHMYmgiYRpiWf7pi9HpwVuZJmE8XuCYUd2Y+VywaIoUjnzcBCI9XL/V/LNPBqGZH5RA+MULO4zrMtNW7hDptg3wmD7WqzhDKeUcNC6biW0lhMicNiVSU7fsbWPD1jsYmyoG48CGxu2DWw3hVES9010bDjlQbLwRQFyw+su6x0RLgGuXMfxTxeovRuruo6bJGK3SUt/msBQqJs17L6pcUk66hZ0TDTiNBtTupiToj2sau/hXBGzHRuST0/XuE7Yi4FLy9EZnuiWddKmi8HqOupI23SzhtD7+G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sXPhq0WxNQ/gjKO0NjfPXWd0+u04mw68QEJwmLrqx9yJpZdiVyACkxKsesraN4IlF3YK5mD7b/ongBKVs6sj5E5C6zWjjMqrDmmrBD1VLJiMJw3KEGbDWAzEwlWIjwqJlc0MRIlr5HxnNGLYbVZw1p4OsUarCI7HiZzgdEa1TnZ2oK11n+nN7X2BOMxDRAZDMIJF8UXiMPbKERscWuqiXsFWPFJg0hsjG3b/3oKH3flI/KjJRoI9piEpIfLFlDKKbmnnEEKQg2iDg7ZxE/zTX/6Yqd6lCfIr5Hc4FsACT4wSx4YjTC/TEl8smzXOwzLdgtBWnc9KCCdjg==; 5:cBWq6f3NnsvEWfkHSzmoXXYhzTsdJzfrsDEDAPoVbFdsVv4b6AQaR93Fg+TP50B3hWqxYaW71BsXof5/s8xwzhs5ekASKa2KXexi3Fw2mfxUrICIrSHlw91HGY94IMTqNEw/N73bxXoR+y4AbI2eCrKQXwucstNA7chB6Gk8whw=; 7:D/8IMCD0CeSJx2tmWL2BK5WCoVzGn6kRuN/ngPkCbX6UYlcZRb+OrG5jTGMzdNEXPzcWYhJ0epte3Zt9syR/he+vHzJLw7C+4rWFJY1PrwUtDm3l4m9vHJhXd3hjtijghRcggZ81gSNfQIcIdZXMh6BDthy7GqVBZHGO4hkiTRSbwnGuM2PMWJAo7ngJ3zAoG+J2zw2co5p0FOlS6occtUJffIcbslZ0IwntBnNYKi6YwELA+moG9ZJLY483otzm SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 20:lLumOwYRymxrdzXUNt9mVYIb7jzdvOWosWaUd67j9pZTXhU81lCEoAMHYT9MGG60IGs3xxbNAzWJPNRYSgZcEHFTsaq99gSi+G6t/N2LanAnQ2y0iUOvbI/MPhapsZl7YXxxgSAVwgaWIe186GWITHJH5ZzXWCTKSl0yeppbvyE= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2018 08:22:39.3426 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 46e4ba1b-bfd1-4dd7-d5bb-08d61f9b659c X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3588 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.7.119 Subject: [Qemu-devel] [PATCH 07/10] 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: Vijayabhaskar Balakrishna , Eduardo Habkost , Konrad Rzeszutek Wilk , "Michael S. Tsirkin" , Venu Busireddy , Liran Alon , Paolo Bonzini , Si-Wei Liu , Igor Mammedov , Boris Ostrovsky , Karl Heubaum 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 connection ID is called by the guest. Support for using KVM functionality for this will be added in a followup patch. Signed-off-by: Roman Kagan --- include/hw/hyperv/hyperv-proto.h | 1 + include/hw/hyperv/hyperv.h | 13 +++++ hw/hyperv/hyperv.c | 93 ++++++++++++++++++++++++++++++++ target/i386/hyperv.c | 10 ++-- 4 files changed, 113 insertions(+), 4 deletions(-) diff --git a/include/hw/hyperv/hyperv-proto.h b/include/hw/hyperv/hyperv-proto.h index 2dc78eeafb..21dc28aee9 100644 --- a/include/hw/hyperv/hyperv-proto.h +++ b/include/hw/hyperv/hyperv-proto.h @@ -21,6 +21,7 @@ #define HV_STATUS_INVALID_ALIGNMENT 4 #define HV_STATUS_INVALID_PARAMETER 5 #define HV_STATUS_INSUFFICIENT_MEMORY 11 +#define HV_STATUS_INVALID_PORT_ID 17 #define HV_STATUS_INVALID_CONNECTION_ID 18 #define HV_STATUS_INSUFFICIENT_BUFFERS 19 diff --git a/include/hw/hyperv/hyperv.h b/include/hw/hyperv/hyperv.h index 757c85eb8f..df92ed7e66 100644 --- a/include/hw/hyperv/hyperv.h +++ b/include/hw/hyperv/hyperv.h @@ -39,6 +39,19 @@ int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *msg); */ int hyperv_set_event_flag(HvSintRoute *sint_route, unsigned eventno); +/* + * Associate @notifier with the event connection @conn_id, such that @notifier + * is signaled when the guest executes HV_SIGNAL_EVENT hypercall on @conn_id. + * If @notifier is NULL clear the association. + */ +int hyperv_set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier); + +/* + * Process HV_SIGNAL_EVENT hypercall: signal the EventNotifier associated with + * the connection as specified in @param. + */ +uint16_t hyperv_hcall_signal_event(uint64_t param, bool fast); + static inline uint32_t hyperv_vp_index(CPUState *cs) { return cs->cpu_index; diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index 0b28e7922c..5bb5126393 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -13,6 +13,9 @@ #include "exec/address-spaces.h" #include "sysemu/kvm.h" #include "qemu/bitops.h" +#include "qemu/queue.h" +#include "qemu/rcu.h" +#include "qemu/rcu_queue.h" #include "hw/hyperv/hyperv.h" typedef struct SynICState { @@ -450,3 +453,93 @@ int hyperv_sint_route_set_sint(HvSintRoute *sint_route) { return event_notifier_set(&sint_route->sint_set_notifier); } + +typedef struct EventFlagHandler { + struct rcu_head rcu; + QLIST_ENTRY(EventFlagHandler) link; + uint32_t conn_id; + EventNotifier *notifier; +} EventFlagHandler; + +static QLIST_HEAD(, EventFlagHandler) event_flag_handlers; +static QemuMutex handlers_mutex; + +static void __attribute__((constructor)) hv_init(void) +{ + QLIST_INIT(&event_flag_handlers); + qemu_mutex_init(&handlers_mutex); +} + +int hyperv_set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier) +{ + int ret; + EventFlagHandler *handler; + + qemu_mutex_lock(&handlers_mutex); + QLIST_FOREACH(handler, &event_flag_handlers, link) { + if (handler->conn_id == conn_id) { + if (notifier) { + ret = -EEXIST; + } else { + QLIST_REMOVE_RCU(handler, link); + g_free_rcu(handler, rcu); + ret = 0; + } + goto unlock; + } + } + + if (notifier) { + handler = g_new(EventFlagHandler, 1); + handler->conn_id = conn_id; + handler->notifier = notifier; + QLIST_INSERT_HEAD_RCU(&event_flag_handlers, handler, link); + ret = 0; + } else { + ret = -ENOENT; + } +unlock: + qemu_mutex_unlock(&handlers_mutex); + return ret; +} + +uint16_t hyperv_hcall_signal_event(uint64_t param, bool fast) +{ + uint16_t ret; + EventFlagHandler *handler; + + if (unlikely(!fast)) { + hwaddr addr = param; + + if (addr & (__alignof__(addr) - 1)) { + return HV_STATUS_INVALID_ALIGNMENT; + } + + param = ldq_phys(&address_space_memory, addr); + } + + /* + * Per spec, bits 32-47 contain the extra "flag number". However, we + * have no use for it, and in all known usecases it is zero, so just + * report lookup failure if it isn't. + */ + if (param & 0xffff00000000ULL) { + return HV_STATUS_INVALID_PORT_ID; + } + /* remaining bits are reserved-zero */ + if (param & ~HV_CONNECTION_ID_MASK) { + return HV_STATUS_INVALID_HYPERCALL_INPUT; + } + + ret = HV_STATUS_INVALID_CONNECTION_ID; + rcu_read_lock(); + QLIST_FOREACH_RCU(handler, &event_flag_handlers, link) { + if (handler->conn_id == param) { + event_notifier_set(handler->notifier); + ret = 0; + break; + } + } + rcu_read_unlock(); + return ret; +} diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 3f76c3e266..96b3b5ad7f 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -79,16 +79,18 @@ int kvm_hv_handle_exit(X86CPU *cpu, struct kvm_hyperv_exit *exit) 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 = hyperv_hcall_signal_event(param, fast); + break; default: exit->u.hcall.result = HV_STATUS_INVALID_HYPERCALL_CODE; - return 0; } + return 0; } default: return -1; From patchwork Fri Sep 21 08:22:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10609397 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0C08714BD for ; Fri, 21 Sep 2018 09:06:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF88929CAF for ; Fri, 21 Sep 2018 09:06:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1F212DBE4; Fri, 21 Sep 2018 09:06: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=-7.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,MAILING_LIST_MULTI,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 7568229CAF for ; Fri, 21 Sep 2018 09:06:38 +0000 (UTC) Received: from localhost ([::1]:54660 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3HOX-0007tB-9m for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Sep 2018 05:06:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49157) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3Gi6-0006xs-KW for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3Gi4-0002O3-09 for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:46 -0400 Received: from mail-eopbgr70119.outbound.protection.outlook.com ([40.107.7.119]:27680 helo=EUR04-HE1-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 1g3Gi3-0002FC-Lx for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:43 -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:X-MS-Exchange-SenderADCheck; bh=YDyrDD4lIelGwPlKQgr1Sm+T86tLFFf4SxZxVwg9nYg=; b=PrihhZH03pUu+bnBpuyVKAPj4goRGm3KzfcNTL0BFFxipl7u3jpuYJETs49nHaRrYMdOgRgCZWLY8Nrd/zhLXaw9aH+gQcOyAj8kll75/HzzlYvQp9SVbzpb26/XqrM+JQ2NKsjN+hkag9+CmIk6YRhicfSZZAXia0MjZMLiYMY= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (185.231.240.5) by AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.18; Fri, 21 Sep 2018 08:22:40 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2018 11:22:15 +0300 Message-Id: <20180921082217.29481-9-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921082217.29481-1-rkagan@virtuozzo.com> References: <20180921082217.29481-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: VI1P193CA0003.EURP193.PROD.OUTLOOK.COM (2603:10a6:800:bd::13) To AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5f1ec611-6ac1-43bc-678f-08d61f9b6686 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB3588; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 3:Hhy5H5o/RTEykVJg/buWVjNT6wAjvPvz3dTGpxHw1fPN677kCLoKCvkSm59g++c7LjuvpsRe+eznPSMxV9C/BfXQDY7wNzs6sPkQGprGrYkVeeMv4uala/usf/QaR3cTziMQvrZ19y4HXUqpyKN1T2bTje6MDh78pr20Ij1RDONAn42oCNMfZGvQMDsSHOgsM9/aS0MdN/b0+ba6CSL9c7TCYFXCnIQ6dH3iwvXKrq03pMraMtzVKz+pq0jiYWMt; 25:Wo6Vg7W3f54EB9wApgemwukSMfrDT3rwL8aNGtBdWCyaHQZuNdT5Plt25oT2iKWwo4d2hVjxqWh4sWbAne5qHUW6bkDOQ7JtJ8YWRJtNSbf9gUVkPaJKjQwatIYKBOK9CBzvVK7gBNfro7XljyToLsvSMfd0vtkPmEYGrUDiITS/fc2ZpuZ2lSiO8nyisUu4yP/+jcHXwePSETxrnE87yt+WigusnhCxNMKyC2AiI73uOVxoOwfwjTdnYWkJlwduxUZGng9fnCZqfDFMcrjMIwIJ3V8NRdRz1ABcEl20MWZPQ0ZqahQWsT13bH2aTxVPHIjeW8skno+8vCDeKqpJ/w==; 31:rCjgKXkp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myw+ilpFY8I6joJUsKZaEkQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231355)(944501410)(52105095)(10201501046)(3002001)(149027)(150027)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(201708071742011)(7699051); SRVR:AM0PR08MB3588; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB3588; X-Forefront-PRVS: 0802ADD973 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(346002)(136003)(396003)(39850400004)(366004)(376002)(189003)(199004)(6916009)(16526019)(5660300001)(36756003)(3846002)(54906003)(48376002)(6506007)(476003)(486006)(14444005)(52116002)(446003)(1076002)(76176011)(386003)(51416003)(186003)(6116002)(16586007)(2906002)(66066001)(6512007)(7416002)(50226002)(53936002)(25786009)(106356001)(53416004)(81166006)(47776003)(316002)(956004)(11346002)(2616005)(7736002)(8936002)(305945005)(8676002)(2351001)(105586002)(97736004)(4326008)(86362001)(6666003)(68736007)(478600001)(6486002)(2361001)(50466002)(26005)(69596002)(81156014); DIR:OUT; SFP:1102; SCL:1; SRVR:AM0PR08MB3588; H:rkaganb.sw.ru; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR08MB3588; 23:SyLQ2lzh0RIh2bkshw9raEdN93t4UoFZQbeSLWtM0?= V23lq0HT2VG8aEqeSuNEqxKb2w2EpVYpZ053HNVa2for2K0VItoBBAPU2LDsNk0df5Q6xEJax8v524G5bxZNVkJBJuUpMeEGLyIMuznkEIS1uonicwsHh0B8XTuD5LKWPyh3P+Q3qKst/UyHyBg2qC7HO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Idig3TsIihEubksR0qYVQYNh6o+TeKs0S0bVe92k7GA5/17176nrdrnWHjts=; 7:K7j8p6aN1zMP2KKnwWHiKHZccIg2psK9XQhVB8cyjWeCFYf2XKnPv1Gf+lxcowMt0sf90U24g3DImDpCSvxIymjmQAVCi78wbjmWtPwSD1hjC3EqU/KGz8aLwfrCTdKJfzIPJ9xASQ4EduTIXmXzm9SVEvEUl4/cNCu/DBlU+1TytNwkNppiLV47DOhPBK4tltFkaTydcZa9TBE6yF3laHpPrpZavosT6XzBso0cI7CQGbuHR+V8Vkncg39LXEzP SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 20:nQ68hGKPO0y21Qh3G2Yx1rNpqBXyerkl/YK2YVeOwZVGN84dsLfKsCbdoVphPSiM3bfz6+/u5QipmHxVSaIMHPY9MLmCfPaD3QAn/06bQvtYbsOw2kuZzvZMNa9HVaM5t2lTxKFmhQ4+qiqHvR+FZVfRMoDp8NKFE1x982xZRXg= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2018 08:22:40.8890 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5f1ec611-6ac1-43bc-678f-08d61f9b6686 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3588 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.7.119 Subject: [Qemu-devel] [PATCH 08/10] hyperv: add support for KVM_HYPERV_EVENTFD 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: Vijayabhaskar Balakrishna , Eduardo Habkost , Konrad Rzeszutek Wilk , "Michael S. Tsirkin" , Venu Busireddy , Liran Alon , Paolo Bonzini , Si-Wei Liu , Igor Mammedov , Boris Ostrovsky , Karl Heubaum Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP When setting up a notifier for Hyper-V event connection, try to use the KVM-assisted one first, and fall back to userspace handling of the hypercall if the kernel doesn't provide the requested feature. Signed-off-by: Roman Kagan --- hw/hyperv/hyperv.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index 5bb5126393..bf361de6f6 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -13,6 +13,7 @@ #include "exec/address-spaces.h" #include "sysemu/kvm.h" #include "qemu/bitops.h" +#include "qemu/error-report.h" #include "qemu/queue.h" #include "qemu/rcu.h" #include "qemu/rcu_queue.h" @@ -470,7 +471,7 @@ static void __attribute__((constructor)) hv_init(void) qemu_mutex_init(&handlers_mutex); } -int hyperv_set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier) +static int set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier) { int ret; EventFlagHandler *handler; @@ -503,6 +504,30 @@ unlock: return ret; } +static bool process_event_flags_userspace; + +int hyperv_set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier) +{ + if (!process_event_flags_userspace && + !kvm_check_extension(kvm_state, KVM_CAP_HYPERV_EVENTFD)) { + process_event_flags_userspace = true; + + warn_report("Hyper-V event signaling is not supported by this kernel; " + "using slower userspace hypercall processing"); + } + + if (!process_event_flags_userspace) { + struct kvm_hyperv_eventfd hvevfd = { + .conn_id = conn_id, + .fd = notifier ? event_notifier_get_fd(notifier) : -1, + .flags = notifier ? 0 : KVM_HYPERV_EVENTFD_DEASSIGN, + }; + + return kvm_vm_ioctl(kvm_state, KVM_HYPERV_EVENTFD, &hvevfd); + } + return set_event_flag_handler(conn_id, notifier); +} + uint16_t hyperv_hcall_signal_event(uint64_t param, bool fast) { uint16_t ret; From patchwork Fri Sep 21 08:22:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10609399 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 43D1514BD for ; Fri, 21 Sep 2018 09:09:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 329432D607 for ; Fri, 21 Sep 2018 09:09:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2632C2D60E; Fri, 21 Sep 2018 09:09:05 +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=-7.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,MAILING_LIST_MULTI,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 CE6042D607 for ; Fri, 21 Sep 2018 09:09:03 +0000 (UTC) Received: from localhost ([::1]:54671 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3HQt-00026h-3l for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Sep 2018 05:09:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3Gi9-00071M-VV for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3Gi6-0002WV-PX for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:49 -0400 Received: from mail-eopbgr70095.outbound.protection.outlook.com ([40.107.7.95]:44383 helo=EUR04-HE1-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 1g3Gi6-0002SR-9M for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:46 -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:X-MS-Exchange-SenderADCheck; bh=wN1p1Xr5Kx/LPgFjCj5+vEKWWv+jadY9tsv6qSyIKuE=; b=gF1dBBu0Jc4keWsFJ1MeVoNBxcovxTAXCzTmB/zMaRNfVJt5WPDL1f8TlVDLlOjmue+S0/tOe91W4x+4I8CP5mNJFpZvdBLaSlZZCigV9UdeUEhUMlhV07gPZzZQXwxPqOHksdpYRSL613q0bD9ETb9tNTu8oduHmFwrvwJjads= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (185.231.240.5) by AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.18; Fri, 21 Sep 2018 08:22:42 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2018 11:22:16 +0300 Message-Id: <20180921082217.29481-10-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921082217.29481-1-rkagan@virtuozzo.com> References: <20180921082217.29481-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: VI1P193CA0003.EURP193.PROD.OUTLOOK.COM (2603:10a6:800:bd::13) To AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3099dd71-67c3-4610-e002-08d61f9b679a X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB3588; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 3:fxNOhD4/6VbRVagiDSwNKmPet/UblddNNq2uzvTpXTvzx4L+esTF8/GILW5WDWSEPtW/AbliE/kwbTfhuy8wpUFnXFLkVanroQRaqQFWB4qLk/mp7F5v7PuM3mB4sn7yDHpycCRsPY2fqIv13o3k8Htxz5N0p5+DeT68RvPYDfqkIRatYMdGP/I+nhaaybIjCs5l3hzlXKISc6936sHIZJjKP0tTO6mUMQ0BwArPOdtxN9uowAH7XaptEZpImYO6; 25:3xTvFoD9fJ7aPbLsYR73Snh6kzRUK0ikhRuYABIaizxlmsIdm8aO2crLd7K5AIxBmzhbLJRkVie0kccf9+e8Y4rVO2F26wAICKDckitvkYZhksZ1uTAmGbTJTUd2BwvGDG1QNsGrKmC1mWuUklmB7ak8n1fK8/doA1ROe/OB14aE88R3YEDdTCaRtytxdVuacM6Pb90gqqGv+PcQAC6BS7d7uKMNQA1G/QL1NY9KkvlC5y2X3fMlnf7+p00A0n4Q2Ct46M1/pQ6DMdUmChX/iTp4q/tyN09hpn/2K1iprxvXW/Exzg3+sG9Tj9TmaaXCbvku9jCsA6vHOxdA0l+5iw==; 31:c2rZUleBgsBB4AMVSkQND2hhuYFOPair03xFJKM+BysXdvxDxOfhxKFKFthH326HqLEwn8jlK36P+vF9dNUczArakdZZwZbGTWJsyVPnhuHk/ObqaXTTrIbzpWBSkYIpMN/Ngr4NS+XX3vWhYNzcYceoYZTXoL8wMwJU0fwKjs1pSbPaPcQ0xR9C6DH2s4M3YEkAISkg5Fc72Gh3AsHgdt6SBmtB4rQcmhBBtwELvxk= X-MS-TrafficTypeDiagnostic: AM0PR08MB3588: X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 20:kEeSRZ/LQSPaIGGi1Zf+2LghTjw9/48DA/r3CfMV12rlShXxEG+J5OV5EIvwCzykec0/sajjvCyF5E65iyGUnNuy4GIyqT1AsGpCMCkvBXw5UeQO6jNY/jAPJVgzYivjA8wdmArIRfh4Af2oI3IQy7IggTlKe6Zlxh7QBstlCT660rPnl8OnqHqH1vkv7STPXsZdGCWL0tumrESuVyavRw9JvdR0dYcF1wBjRgEnLkHMKN9HmZ8yBPESbQ98kE7lB4zunQiWlUr8XKcDPtokQPJBtRSu5pomAOH8TCPC2HLXyD6wAK1fMZdmah2nHMRdctjiMYrxQ+bOS551ovjjdeyJ6ibsLzVem/tHRCAmP8q1gpEIJOXRXMO7I7x/3shdpZf9UtuAQ/PhqXB3eUSWJHGoDNBQGPbbh0ZsO6v6JFAJO+XRdUI+xsNu5a3idj5dnraH+zfdypJb/0sEqJSMlhDwklAEZ/rmhhCiLhB+ntNWYFTDphO/OAs8edTww3D0; 4:omDUbcd88KPIOqsnAug+1mB1u5tcnlOK92ojd9kgqR39zOMOplYbnCNgZMWXgAhmoR+oK80rGj/ORLd/PD91ZeNu/F9wKx8H/5Z4+7CvAfW/En3hBNawdtfvU4pZ9dF7/v7fGTyieIQ7JSesnxGsUhJC4E9sxXER8qWTHjbSaX/OvakpsT8pJLPON/P+lyXUQcouyiHZHUXoI7h3hUfN5GuoWvjhHe1Dwf3LKlQoa9CrTATmJdDMvKGdmgzcmagNRSnlJsU8eeyhAzQK/2zlqA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231355)(944501410)(52105095)(10201501046)(3002001)(149027)(150027)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(201708071742011)(7699051); SRVR:AM0PR08MB3588; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB3588; X-Forefront-PRVS: 0802ADD973 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(346002)(136003)(396003)(39850400004)(366004)(376002)(189003)(199004)(6916009)(16526019)(5660300001)(36756003)(3846002)(54906003)(48376002)(6506007)(476003)(486006)(14444005)(52116002)(446003)(1076002)(76176011)(386003)(51416003)(186003)(6116002)(16586007)(2906002)(66066001)(6512007)(7416002)(50226002)(53936002)(25786009)(106356001)(53416004)(81166006)(47776003)(316002)(956004)(11346002)(2616005)(7736002)(8936002)(305945005)(8676002)(2351001)(105586002)(97736004)(4326008)(86362001)(6666003)(68736007)(478600001)(6486002)(2361001)(50466002)(26005)(69596002)(81156014); DIR:OUT; SFP:1102; SCL:1; SRVR:AM0PR08MB3588; H:rkaganb.sw.ru; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.outlook.com: virtuozzo.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; AM0PR08MB3588; 23:bSWJz3pB+y4TkYEYE+F1SNcLpPoPc5h0fnd+UwE+T?= UCugx/P59IOY8hZ2EW8OVi9tC3YYHMRetSKOO+QMNczNsJRf1V/i9ttXm4g2CGPxDjZB/RaKWzTa4qcJ8aaJ3wh3iasKHnOq7WGH4KJ4dUbrGRbnbLzseH93q63M2qxhPBfx/8InOxh+96SbNUpRXDq5lay6QWwI0VEwu1K3gbT+AgUIIFjd8a7VHw4NHQljjbBA8YlW34Y+RTc2WTNamVmhMTX3XdZFUQXZ1M00zAso15WSgs4BGLGMJsPLap47eh+e8D6XJW+D6lvktvS7gPux7SvBQy0+Kf3YZ4g72/aLFbkAPKDT7JXW5yJy37qGyDXrtcTNtnbyPJupPH3u0tngig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3zBA2MZcydH3yUvNJ4mFUC0Ib+LNmZFndmzG0SjCyVC5XVc/a2J2LrLYt6/XmDbsgVzZcXSN4G3H/T4tbLWEByQkqj+qt9ypw4hI53EMNDIKSlX2uU49Fk96/tqDE239 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 20:puB583PLxKGZ6j6sXEGDuqoEIu+kWqI8cC6oeKDzqSKGYjIrCL5ONlHpVN7Vjp8cg+sTSz8pjnZkH/rOnm6vQALULy7/1jvt2+oTkK7jXjnhjcpmbV/ScV7I79KEKtRJ/ledEsUvKm1DItis3Mdq8nKedsy8y+wLIfJf8O1+GAg= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2018 08:22:42.6852 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3099dd71-67c3-4610-e002-08d61f9b679a X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3588 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.7.95 Subject: [Qemu-devel] [PATCH 09/10] 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: Vijayabhaskar Balakrishna , Eduardo Habkost , Konrad Rzeszutek Wilk , "Michael S. Tsirkin" , Venu Busireddy , Liran Alon , Paolo Bonzini , Si-Wei Liu , Igor Mammedov , Boris Ostrovsky , Karl Heubaum 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 --- include/hw/hyperv/hyperv.h | 18 ++++++++ hw/hyperv/hyperv.c | 84 ++++++++++++++++++++++++++++++++++++++ target/i386/hyperv.c | 3 ++ 3 files changed, 105 insertions(+) diff --git a/include/hw/hyperv/hyperv.h b/include/hw/hyperv/hyperv.h index df92ed7e66..597381cb01 100644 --- a/include/hw/hyperv/hyperv.h +++ b/include/hw/hyperv/hyperv.h @@ -39,6 +39,18 @@ int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *msg); */ int hyperv_set_event_flag(HvSintRoute *sint_route, unsigned eventno); +/* + * Handler for messages arriving from the guest via HV_POST_MESSAGE hypercall. + * Executed in vcpu context. + */ +typedef uint16_t (*HvMsgHandler)(const struct hyperv_post_message_input *msg, + void *data); +/* + * Associate @handler with the message connection @conn_id, such that @handler + * is called with @data when the guest executes HV_POST_MESSAGE hypercall on + * @conn_id. If @handler is NULL clear the association. + */ +int hyperv_set_msg_handler(uint32_t conn_id, HvMsgHandler handler, void *data); /* * Associate @notifier with the event connection @conn_id, such that @notifier * is signaled when the guest executes HV_SIGNAL_EVENT hypercall on @conn_id. @@ -46,6 +58,12 @@ int hyperv_set_event_flag(HvSintRoute *sint_route, unsigned eventno); */ int hyperv_set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier); +/* + * Process HV_POST_MESSAGE hypercall: parse the data in the guest memory as + * specified in @param, and call the HvMsgHandler associated with the + * connection on the message contained therein. + */ +uint16_t hyperv_hcall_post_message(uint64_t param, bool fast); /* * Process HV_SIGNAL_EVENT hypercall: signal the EventNotifier associated with * the connection as specified in @param. diff --git a/hw/hyperv/hyperv.c b/hw/hyperv/hyperv.c index bf361de6f6..8d70fe7705 100644 --- a/hw/hyperv/hyperv.c +++ b/hw/hyperv/hyperv.c @@ -455,6 +455,14 @@ int hyperv_sint_route_set_sint(HvSintRoute *sint_route) return event_notifier_set(&sint_route->sint_set_notifier); } +typedef struct MsgHandler { + struct rcu_head rcu; + QLIST_ENTRY(MsgHandler) link; + uint32_t conn_id; + HvMsgHandler handler; + void *data; +} MsgHandler; + typedef struct EventFlagHandler { struct rcu_head rcu; QLIST_ENTRY(EventFlagHandler) link; @@ -462,15 +470,91 @@ typedef struct EventFlagHandler { EventNotifier *notifier; } EventFlagHandler; +static QLIST_HEAD(, MsgHandler) msg_handlers; static QLIST_HEAD(, EventFlagHandler) event_flag_handlers; static QemuMutex handlers_mutex; static void __attribute__((constructor)) hv_init(void) { + QLIST_INIT(&msg_handlers); QLIST_INIT(&event_flag_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, link) { + if (mh->conn_id == conn_id) { + if (handler) { + ret = -EEXIST; + } else { + QLIST_REMOVE_RCU(mh, link); + 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, link); + ret = 0; + } else { + ret = -ENOENT; + } +unlock: + qemu_mutex_unlock(&handlers_mutex); + return ret; +} + +uint16_t hyperv_hcall_post_message(uint64_t param, bool fast) +{ + uint16_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, link) { + 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 int set_event_flag_handler(uint32_t conn_id, EventNotifier *notifier) { int ret; diff --git a/target/i386/hyperv.c b/target/i386/hyperv.c index 96b3b5ad7f..b264a28620 100644 --- a/target/i386/hyperv.c +++ b/target/i386/hyperv.c @@ -84,6 +84,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 = hyperv_hcall_post_message(param, fast); + break; case HV_SIGNAL_EVENT: exit->u.hcall.result = hyperv_hcall_signal_event(param, fast); break; From patchwork Fri Sep 21 08:22:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Roman Kagan X-Patchwork-Id: 10609423 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8CF8D14DA for ; Fri, 21 Sep 2018 09:11:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 792892DDC9 for ; Fri, 21 Sep 2018 09:11:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 641812DD60; Fri, 21 Sep 2018 09:11:29 +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=-7.8 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,MAILING_LIST_MULTI,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 A05E02D64A for ; Fri, 21 Sep 2018 09:11:28 +0000 (UTC) Received: from localhost ([::1]:54691 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3HTD-0003rW-Sy for patchwork-qemu-devel@patchwork.kernel.org; Fri, 21 Sep 2018 05:11:27 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49193) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g3Gi9-00071L-VI for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g3Gi7-0002a7-Eb for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:49 -0400 Received: from mail-eopbgr70095.outbound.protection.outlook.com ([40.107.7.95]:44383 helo=EUR04-HE1-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 1g3Gi7-0002SR-5M for qemu-devel@nongnu.org; Fri, 21 Sep 2018 04:22:47 -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:X-MS-Exchange-SenderADCheck; bh=WYmEmJ0Bmm1uSiVuwPDNY6U5Fpcp44y7Nak2PYkBQHo=; b=BD/lBwOsFPM9VSx9B3baSmZpNQlpsL6MENFx2LO2yXdrVn36nmav4cba4YXqGEfEs/tycgd+lcKaXohzDeKI0ZRc11jgwutwy8ij0L4aeGC4TB54i5c7hMRhxHWIdReHhWQlP1TEn3J39Pe02vZmsvCnFdY7r6YmYFq69l+a83M= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=rkagan@virtuozzo.com; Received: from rkaganb.sw.ru (185.231.240.5) by AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1143.18; Fri, 21 Sep 2018 08:22:44 +0000 From: Roman Kagan To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2018 11:22:17 +0300 Message-Id: <20180921082217.29481-11-rkagan@virtuozzo.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921082217.29481-1-rkagan@virtuozzo.com> References: <20180921082217.29481-1-rkagan@virtuozzo.com> MIME-Version: 1.0 X-Originating-IP: [185.231.240.5] X-ClientProxiedBy: VI1P193CA0003.EURP193.PROD.OUTLOOK.COM (2603:10a6:800:bd::13) To AM0PR08MB3588.eurprd08.prod.outlook.com (2603:10a6:208:e1::30) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5c58cbeb-0aba-451f-5cc8-08d61f9b6890 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989299)(4534165)(4627221)(201703031133081)(201702281549075)(8990200)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:AM0PR08MB3588; X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 3:bJFnrs7rEKh1g6PRbqhir2dwL+/yanrW8eDE3mo5srCYjdnuyHe1phDDG7vF9t9mBBSXedNb1rzKSarQj0YiLEqnIJFw0I+bvbMyKjbcMNyKqpEMnw4hAppoVPTIXmUgfEtb5QozlaaDAYT3WQRf6EXwvXiD0O3RyGCjmzq5h0pwrtB/d2dYqwkMEHv/Zuj57gj5qUzZ8gC/lXKQtZ4Cc/95DD0mOjnafGrTnNexTGSCuqKHKuOzxnQpXj2kf29F; 25:Kr+tlHNVPrexuZnAvUOQcpv6sgmX8HbJQxNfSizn1O16jFjuNM+3bPQaB0hDwXz4gweTMLywD5o1EiaGVBYwtHj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yQG2; 4:ernmu8iJ+afH2OBrZ+qDWUpSQDPEOzovaolh8FLOPsssTfEOBR8KUxBgFn2eDbsKmUAWsLNamkrvg7JTasCF6nmXM3DME9ggMZ2XYsOvs0nyduNV2aog+Vc4ERo+uDZmQcZLnnDXT+Fj14ejsGU9cslaGmRDdOB0x263R0cO+zWu4YCSA+hIqcBLjULcNbGEPThq4d6HcRjI1aIPOs3aDvBYY1oXIpLRPIEoPDvamM9pfOqFSpyRNEFEPT9frIX2OPzMqwoFqV4WSx3ImvKDtA== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231355)(944501410)(52105095)(10201501046)(3002001)(149027)(150027)(6041310)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123560045)(20161123564045)(201708071742011)(7699051); SRVR:AM0PR08MB3588; BCL:0; PCL:0; RULEID:; SRVR:AM0PR08MB3588; X-Forefront-PRVS: 0802ADD973 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(346002)(136003)(396003)(39850400004)(366004)(376002)(189003)(199004)(6916009)(16526019)(5660300001)(36756003)(3846002)(54906003)(48376002)(6506007)(476003)(486006)(14444005)(52116002)(446003)(1076002)(76176011)(386003)(51416003)(186003)(6116002)(16586007)(15650500001)(2906002)(66066001)(6512007)(7416002)(50226002)(53936002)(25786009)(106356001)(53416004)(81166006)(47776003)(316002)(956004)(11346002)(2616005)(7736002)(8936002)(305945005)(8676002)(2351001)(105586002)(97736004)(4326008)(86362001)(6666003)(68736007)(478600001)(6486002)(2361001)(50466002)(26005)(69596002)(81156014); DIR:OUT; SFP:1102; SCL:1; SRVR:AM0PR08MB3588; H:rkaganb.sw.ru; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; Received-SPF: None (protection.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bf0DE1JgFWV0im3y3HSBUY9YZHB1/8QoePKDMgbgWs3M9+souCR7vKdPgjtaCRpNShKyiVwxtEHeoA2OinADbYTpr26ET+ZvueHFiOrz28trKuSDBAUVrxj65NRcFKl81cOxbPFKmG/vMWeaBed7gFJmNelEyCFo9KOwjtoucEptW4twRFBPC4i56ONrYA==; 5:R6FEYcPOdbxbpM88xmZ57Fbu0C3Mb23YfWWJjDTvxb4jFyzL1YgezKhuoTl5kawtcjvn/R14vVp7brtwZjT2TTnCmB5cHmXbllei8XonPMMC/MAXggKEw4FUA6jmnJHOmckjrCc7Qenb+K5ZLMo4IEcaxf7zMHEQuBkvv/rgeH0=; 7:lEzrRXeTP03W3n3m2tUS0t3zHaCh4Vw8h+FHL5Mh9ojOM6r5he3HMjmZ91p8v28Nr1kn8vACF26GY7eJSXWqFXVCfevYNGKYkaUoA3Xf3Xk/9d70sC0mkb5ac5g5ktJzuGUbW71tyfiKpyk/s5bD/6wGwIzbE41zMtNV1HKXNMl+tO0emB0KXH/2tI4rnnOlxSVUmXO7VFACa6LdcuozYAn/NuNuhryWn1jDz31KmSmxHoDTPMB98iyS7OBBMmpk SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; AM0PR08MB3588; 20:B90UYML0GKzDiu3hE6OEY9YTslwUTsDDu2ou4L5kuMNF5m/+UWO9B6xMx4xJ6O3cy8JVs/OU3O3HlA2sy3FA7zzf5I1H37E/Ic8mPe0ZBc7FpFD5/S2YyP2jtJnO7PvYiaUxSg259X0Zvj8yqnpn1rDRhb3J1mctwl5yaTY7d9Y= X-OriginatorOrg: virtuozzo.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2018 08:22:44.3097 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5c58cbeb-0aba-451f-5cc8-08d61f9b6890 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 0bc7f26d-0264-416e-a6fc-8352af79c58f X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR08MB3588 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 40.107.7.95 Subject: [Qemu-devel] [PATCH 10/10] hyperv_testdev: add SynIC message and event testmodes 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: Vijayabhaskar Balakrishna , Eduardo Habkost , Konrad Rzeszutek Wilk , "Michael S. Tsirkin" , Venu Busireddy , Liran Alon , Paolo Bonzini , Si-Wei Liu , Igor Mammedov , Boris Ostrovsky , Karl Heubaum Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add testmodes for SynIC messages and events. The message or event connection setup / teardown is initiated by the guest via new control codes written to the test device port. Then the test connections bounce the respective operations back to the guest, i.e. the incoming messages are posted or the incoming events are signaled on the configured vCPUs. Signed-off-by: Roman Kagan --- hw/misc/hyperv_testdev.c | 165 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 164 insertions(+), 1 deletion(-) diff --git a/hw/misc/hyperv_testdev.c b/hw/misc/hyperv_testdev.c index 02ef606469..ee77bbac8b 100644 --- a/hw/misc/hyperv_testdev.c +++ b/hw/misc/hyperv_testdev.c @@ -12,6 +12,7 @@ */ #include "qemu/osdep.h" +#include "qemu/main-loop.h" #include "qemu/queue.h" #include "hw/qdev.h" #include "hw/isa/isa.h" @@ -24,10 +25,26 @@ typedef struct TestSintRoute { HvSintRoute *sint_route; } TestSintRoute; +typedef struct TestMsgConn { + QLIST_ENTRY(TestMsgConn) le; + uint8_t conn_id; + HvSintRoute *sint_route; + struct hyperv_message msg; +} TestMsgConn; + +typedef struct TestEvtConn { + QLIST_ENTRY(TestEvtConn) le; + uint8_t conn_id; + HvSintRoute *sint_route; + EventNotifier notifier; +} TestEvtConn; + struct HypervTestDev { ISADevice parent_obj; MemoryRegion sint_control; QLIST_HEAD(, TestSintRoute) sint_routes; + QLIST_HEAD(, TestMsgConn) msg_conns; + QLIST_HEAD(, TestEvtConn) evt_conns; }; typedef struct HypervTestDev HypervTestDev; @@ -38,7 +55,11 @@ typedef struct HypervTestDev HypervTestDev; enum { HV_TEST_DEV_SINT_ROUTE_CREATE = 1, HV_TEST_DEV_SINT_ROUTE_DESTROY, - HV_TEST_DEV_SINT_ROUTE_SET_SINT + HV_TEST_DEV_SINT_ROUTE_SET_SINT, + HV_TEST_DEV_MSG_CONN_CREATE, + HV_TEST_DEV_MSG_CONN_DESTROY, + HV_TEST_DEV_EVT_CONN_CREATE, + HV_TEST_DEV_EVT_CONN_DESTROY, }; static void sint_route_create(HypervTestDev *dev, @@ -93,6 +114,133 @@ static void sint_route_set_sint(HypervTestDev *dev, hyperv_sint_route_set_sint(sint_route->sint_route); } +static void msg_retry(void *opaque) +{ + TestMsgConn *conn = opaque; + assert(!hyperv_post_msg(conn->sint_route, &conn->msg)); +} + +static void msg_cb(void *data, int status) +{ + TestMsgConn *conn = data; + + if (!status) { + return; + } + + assert(status == -EAGAIN); + + aio_bh_schedule_oneshot(qemu_get_aio_context(), msg_retry, conn); +} + +static uint16_t msg_handler(const struct hyperv_post_message_input *msg, + void *data) +{ + int ret; + TestMsgConn *conn = data; + + /* post the same message we've got */ + conn->msg.header.message_type = msg->message_type; + assert(msg->payload_size < sizeof(conn->msg.payload)); + conn->msg.header.payload_size = msg->payload_size; + memcpy(&conn->msg.payload, msg->payload, msg->payload_size); + + ret = hyperv_post_msg(conn->sint_route, &conn->msg); + + switch (ret) { + case 0: + return HV_STATUS_SUCCESS; + case -EAGAIN: + return HV_STATUS_INSUFFICIENT_BUFFERS; + default: + return HV_STATUS_INVALID_HYPERCALL_INPUT; + } +} + +static void msg_conn_create(HypervTestDev *dev, uint8_t vp_index, + uint8_t sint, uint8_t conn_id) +{ + TestMsgConn *conn; + + conn = g_new0(TestMsgConn, 1); + assert(conn); + + conn->conn_id = conn_id; + + conn->sint_route = hyperv_sint_route_new(vp_index, sint, msg_cb, conn); + assert(conn->sint_route); + + assert(!hyperv_set_msg_handler(conn->conn_id, msg_handler, conn)); + + QLIST_INSERT_HEAD(&dev->msg_conns, conn, le); +} + +static void msg_conn_destroy(HypervTestDev *dev, uint8_t conn_id) +{ + TestMsgConn *conn; + + QLIST_FOREACH(conn, &dev->msg_conns, le) { + if (conn->conn_id == conn_id) { + QLIST_REMOVE(conn, le); + hyperv_set_msg_handler(conn->conn_id, NULL, NULL); + hyperv_sint_route_unref(conn->sint_route); + g_free(conn); + return; + } + } + assert(false); +} + +static void evt_conn_handler(EventNotifier *notifier) +{ + TestEvtConn *conn = container_of(notifier, TestEvtConn, notifier); + + event_notifier_test_and_clear(notifier); + + /* signal the same event flag we've got */ + assert(!hyperv_set_event_flag(conn->sint_route, conn->conn_id)); +} + +static void evt_conn_create(HypervTestDev *dev, uint8_t vp_index, + uint8_t sint, uint8_t conn_id) +{ + TestEvtConn *conn; + + conn = g_new0(TestEvtConn, 1); + assert(conn); + + conn->conn_id = conn_id; + + conn->sint_route = hyperv_sint_route_new(vp_index, sint, NULL, NULL); + assert(conn->sint_route); + + assert(!event_notifier_init(&conn->notifier, false)); + + event_notifier_set_handler(&conn->notifier, evt_conn_handler); + + assert(!hyperv_set_event_flag_handler(conn_id, &conn->notifier)); + + QLIST_INSERT_HEAD(&dev->evt_conns, conn, le); +} + +static void evt_conn_destroy(HypervTestDev *dev, uint8_t conn_id) +{ + TestEvtConn *conn; + + QLIST_FOREACH(conn, &dev->evt_conns, le) { + if (conn->conn_id == conn_id) { + QLIST_REMOVE(conn, le); + hyperv_set_event_flag_handler(conn->conn_id, NULL); + event_notifier_set_handler(&conn->notifier, NULL); + event_notifier_cleanup(&conn->notifier); + hyperv_sint_route_unref(conn->sint_route); + g_free(conn); + return; + } + } + assert(false); +} + static void hv_test_dev_control(void *opaque, hwaddr addr, uint64_t data, uint32_t len) { @@ -100,6 +248,7 @@ static void hv_test_dev_control(void *opaque, hwaddr addr, uint64_t data, uint8_t sint = data & 0xFF; uint8_t vp_index = (data >> 8ULL) & 0xFF; uint8_t ctl = (data >> 16ULL) & 0xFF; + uint8_t conn_id = (data >> 24ULL) & 0xFF; switch (ctl) { case HV_TEST_DEV_SINT_ROUTE_CREATE: @@ -111,6 +260,18 @@ static void hv_test_dev_control(void *opaque, hwaddr addr, uint64_t data, case HV_TEST_DEV_SINT_ROUTE_SET_SINT: sint_route_set_sint(dev, vp_index, sint); break; + case HV_TEST_DEV_MSG_CONN_CREATE: + msg_conn_create(dev, vp_index, sint, conn_id); + break; + case HV_TEST_DEV_MSG_CONN_DESTROY: + msg_conn_destroy(dev, conn_id); + break; + case HV_TEST_DEV_EVT_CONN_CREATE: + evt_conn_create(dev, vp_index, sint, conn_id); + break; + case HV_TEST_DEV_EVT_CONN_DESTROY: + evt_conn_destroy(dev, conn_id); + break; default: break; } @@ -130,6 +291,8 @@ static void hv_test_dev_realizefn(DeviceState *d, Error **errp) MemoryRegion *io = isa_address_space_io(isa); QLIST_INIT(&dev->sint_routes); + QLIST_INIT(&dev->msg_conns); + QLIST_INIT(&dev->evt_conns); memory_region_init_io(&dev->sint_control, OBJECT(dev), &synic_test_sint_ops, dev, "hyperv-testdev-ctl", 4);