From patchwork Wed Dec 29 06:21:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 12700755 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA815C433EF for ; Wed, 29 Dec 2021 06:22:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238911AbhL2GWh (ORCPT ); Wed, 29 Dec 2021 01:22:37 -0500 Received: from mail-co1nam11on2071.outbound.protection.outlook.com ([40.107.220.71]:57217 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S238906AbhL2GWg (ORCPT ); Wed, 29 Dec 2021 01:22:36 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KqRT2MyMshcF9IE6Ho8YuNDXqfoZpvxv5YUPVMHaXjQDJHfq5hd8vbWPcf8yN1smQ9OO2WqydhSjc6cCkEvenoCx7O6lNMNW4+EVdEdwxDtSgscytR0bRlx2aG4O4h45894SzBoqQKzz5r5uITGs3n+tFep87VJsX7jzrhAewO5P68gDsjxtjIYZMJkIx1586050y6e4QcpJG32DgCMGkw2zZGTUUjJMjl7PX7Y3BzU/Dio4pjSW0gzW8SmCy3Jnpbb6iaUx8scsy8bW7i6ppG0AGLIMxMdJZJLM3tuLyM5hjNjnDyDij/VaK1+BTM5j6TtlUDDeqdrbZUMt0VlRlA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=JfK4po0pfFKOqsjGQdvXI9ymDQH41ErxopaRIqphZng=; b=Bs0pLil/0l+ZhFreWqDlNjQX7oi6mde9G2bBY+ocTC+LA5NerKYC2q4bK5I/qqVQBU9G8Gxx9J8EbNwc9qp9r7da2n7YKhiZkGhkyQC+qHArkN5fl1ewUuRb2rKmXtWrEj9F2ilaJCdtP3mck690memqihaoDuSq1fDaky/k/kN3Fn0B5dS361PBSkfwoRAIIX+r4MEq/6zzdyHx6jdNomzX44uHF+o7dcNoS1VHa3+P2OI/Q8tDl3rM0SJo2mC3x1+YNLJeSlI6N7IHE1qtfAuAOM1dRSfZBWimqFa6prsIVH8STOqSIHdnyJjbJKwTlCt3aeathHcOCVIYrVYd7w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=JfK4po0pfFKOqsjGQdvXI9ymDQH41ErxopaRIqphZng=; b=J6zcOYRWNgFr1KcjpY3v3GPy01cwZNqlhD5whfQFnJmNN2xZEaraJwgNLdJMCJDEcCHmP4PanS0UskFsVsmnVXj0W31vfYd3rK2gHvuMlB+rFqLmF3pz54rJDDuSFf+xyuAFEuikDr3HAZeDCPoq36tCaH1aWN7eiFYR6lYc6ME= Received: from DM5PR18CA0057.namprd18.prod.outlook.com (2603:10b6:3:22::19) by PH0PR12MB5420.namprd12.prod.outlook.com (2603:10b6:510:e8::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4823.16; Wed, 29 Dec 2021 06:22:34 +0000 Received: from DM6NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:3:22:cafe::7e) by DM5PR18CA0057.outlook.office365.com (2603:10b6:3:22::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4844.14 via Frontend Transport; Wed, 29 Dec 2021 06:22:34 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; Received: from SATLEXMB03.amd.com (165.204.84.17) by DM6NAM11FT031.mail.protection.outlook.com (10.13.172.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4844.14 via Frontend Transport; Wed, 29 Dec 2021 06:22:34 +0000 Received: from bhadra.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Wed, 29 Dec 2021 00:22:33 -0600 From: Manali Shukla To: Subject: [kvm-unit-tests PATCH 1/3] x86: nSVM: Check #NM exception handling in L2 Date: Wed, 29 Dec 2021 06:21:59 +0000 Message-ID: <20211229062201.26269-2-manali.shukla@amd.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211229062201.26269-1-manali.shukla@amd.com> References: <20211229062201.26269-1-manali.shukla@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f8799452-bd89-4c47-f0de-08d9ca939a4f X-MS-TrafficTypeDiagnostic: PH0PR12MB5420:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2449; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wIApM2nunwrC4ufScLueZGp4UHgieke7H+VkWNRfTW68BLs+FLw2IcCQusZfqCrS3btlEszp2bLppe3RtPYxk/xukRjuZ8qzjA4w8JauSEDj/vjX9/KhAn2YxdALqqjn1/H6nj46nDdp9t/yGpF4sDATclvbPYgaY7SDbmEzlUwnZoxbFNMR9rX34CTvHs2TvIGd+DTjh1c980Ilo5CPZqXhFw/zdiSopKvhOoWvDto3+0ac6X5p9buFwadaayWuCRo4YDydAS+2J0nAsUPGTciPN2s1HmY+M5zMeBDn9wDuW8Zhz5ZFUXBCdvazpz6z9TM3IFYF1jLfMdJFNnEF9ePJSEofhVXw8A185axPIaV+xQCU+Gu0/EZOItWsSEx8Hqdy2zAqNz+7qRqNkojkr1nDvgaqwFhSrq+vWr1QyCwM6VFtEYRGG5DEXG9ylWecVCn8cbwpNtVbief92t5AbXpFR45EkWMFttrsXwSsjJxuNwYARIZ1FQTassAyr1lNdRCL2BcAKOXQymXSjdfARJxIhFPMIUJz+E98TxvBZgoHN31xQKeeXiS3svIgDeZs7f31wtSmNWV0nqZNjpKnxFAUJ4j6wz6M8V7xPM/CboW+OTrpxo3jmFNNl/v0wdy8wnTA3kLzQjhXlq9D5n+H6UsGJJfKY7dWpyqrCfEUzwjqP6zG2KDyF39YmKokJQpnAE7WpL93aLiQaQL3e4Kje8qF+nMovi6J12YgAWw9Y5ksgd4U7WSTzvxO4Qa3WqOjMOVXwLtfv8NjlJZeqyJjsWzixTwpcOmTVY3V1t1W/mQ= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(36840700001)(40470700002)(46966006)(426003)(47076005)(1076003)(26005)(508600001)(36860700001)(8676002)(356005)(6916009)(7696005)(70586007)(70206006)(44832011)(81166007)(82310400004)(6666004)(2906002)(186003)(16526019)(36756003)(316002)(5660300002)(86362001)(2616005)(336012)(40460700001)(8936002)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Dec 2021 06:22:34.6631 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f8799452-bd89-4c47-f0de-08d9ca939a4f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT031.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR12MB5420 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add coverage for NM exception handling in L2 when only L2 NM exception handler is registered Verifies 3 different conditions for which #NM is generated and handled in L2 1) CR0.TS is set - #NM is generated and handled in L2 exception handler 2) CR0.TS is cleared and CR0.EM is set - #NM is generated and handled in L2 exception handler 3) CR0.TS and CR0.EM are cleared - #NM is not generated Signed-off-by: Manali Shukla --- x86/svm_tests.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/x86/svm_tests.c b/x86/svm_tests.c index 8ad6122..681272c 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -2962,6 +2962,50 @@ static bool vgif_check(struct svm_test *test) return get_test_stage(test) == 3; } +static int nm_test_counter; + +static void guest_test_nm_handler(struct ex_regs *r) +{ + nm_test_counter++; + write_cr0(read_cr0() & ~X86_CR0_TS); + write_cr0(read_cr0() & ~X86_CR0_EM); +} + +static void svm_nm_test_guest(struct svm_test *test) +{ + asm volatile("fnop"); +} + +/* This test checks that: + * + * (a) If CR0.TS is set in L2, #NM is handled by L2 when + * just an L2 handler is registered. + * + * (b) If CR0.TS is cleared and CR0.EM is set, #NM is handled + * by L2 when just an l2 handler is registered. + * + * (c) If CR0.TS and CR0.EM are cleared in L2, no exception + * is generated. + */ + +static void svm_nm_test(void) +{ + handle_exception(NM_VECTOR, guest_test_nm_handler); + write_cr0(read_cr0() & ~X86_CR0_TS); + test_set_guest(svm_nm_test_guest); + + vmcb->save.cr0 = vmcb->save.cr0 | X86_CR0_TS; + report(svm_vmrun() == SVM_EXIT_VMMCALL && nm_test_counter == 1, + "fnop with CR0.TS set in L2, #NM is triggered"); + + vmcb->save.cr0 = (vmcb->save.cr0 & ~X86_CR0_TS) | X86_CR0_EM; + report(svm_vmrun() == SVM_EXIT_VMMCALL && nm_test_counter == 2, + "fnop with CR0.EM set in L2, #NM is triggered"); + + vmcb->save.cr0 = vmcb->save.cr0 & ~(X86_CR0_TS | X86_CR0_EM); + report(svm_vmrun() == SVM_EXIT_VMMCALL && nm_test_counter == 2, + "fnop with CR0.TS and CR0.EM unset no #NM excpetion"); +} struct svm_test svm_tests[] = { { "null", default_supported, default_prepare, @@ -3082,5 +3126,6 @@ struct svm_test svm_tests[] = { TEST(svm_vmrun_errata_test), TEST(svm_vmload_vmsave), TEST(svm_test_singlestep), + TEST(svm_nm_test), { NULL, NULL, NULL, NULL, NULL, NULL, NULL } }; From patchwork Wed Dec 29 06:22:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 12700756 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32DF2C433F5 for ; Wed, 29 Dec 2021 06:22:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238917AbhL2GW6 (ORCPT ); Wed, 29 Dec 2021 01:22:58 -0500 Received: from mail-bn8nam08on2071.outbound.protection.outlook.com ([40.107.100.71]:19552 "EHLO NAM04-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S238916AbhL2GW6 (ORCPT ); Wed, 29 Dec 2021 01:22:58 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SeYmzFsu5DQShgr+V0a/5ECNwlSbnk/hh0A6U8qakbQJqJ4zC8X9tsoIps9NVJyAPJBastRkSz7TarA9//RjS4Zd9UlrkLB42J/CefGScCIChsWTq3yxBEPvp/EwipNs20IHRysrSbFYVHLKGr7F2dRI/6aHXxlHBCGLE5yXTIVRI1SI7xZqCYszYOwk8iaHIKRlUrbunaYXlteXtm+P3/THNgBE7qTJp8TUPeevh0dhtF2Yq2e4f5BSU4hwUuuaB+K/Cs0PVb2hXzkaCUfFmb7xYXURTgdTTxcHqzdfQpvpOrL3a9skxjEqd7WTchAkagbmH9jmvPQV0swVuhBcGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dTOwOwKW7UPeQhjFSr+q7fPvs2ELSRaFrsWIFg3Dcf4=; b=QwHm7uT131/Vxgvv44Oeu6RGabidkLUCDUzIvuYnIY526jlMzgbGsH0fk30s5wkB5PbxfJ0HFZ1IhdgUCLGttKuOnRcoZDNs/5jVKbPtZViMBiEsjBo3C6ClDIaopmS0vixVHcE18TDNnCEh6hMHOgw2ZxUYnNtyB9Ar70KkdYEJC1bS3V2lc7dNR/2i3OJ0lrbSQa7ndEH4zI5vtc/1/x5m/VrN6lrVVFJaOhsvYA2/goc2j29Q6PR9fj8FznYHcVdu2K60Pyspvh3cMNd25zUve0GaM0IH/mQq3liP2D5iiOVpBl2pMD0g6SXj83ay1Rmcq5xno7wmdydeI3TWGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=dTOwOwKW7UPeQhjFSr+q7fPvs2ELSRaFrsWIFg3Dcf4=; b=35Wu9+wfcZlr976cDK1i+93l915pvvTPw6979zFtIjLBCfjQsR4e6/UnwCUOs1b6oMfdrMPfNqxuK5m68BnkpPqbMAGuAsB+uUsBKtzV2QkOZRHDtBaqcphA/ZgsG785y4vWCESZ+QcjVUCOjEBKEN3rmwLz9/NSI+bwF1OA2uA= Received: from DM5PR11CA0005.namprd11.prod.outlook.com (2603:10b6:3:115::15) by DM6PR12MB3980.namprd12.prod.outlook.com (2603:10b6:5:1cc::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4823.19; Wed, 29 Dec 2021 06:22:55 +0000 Received: from DM6NAM11FT054.eop-nam11.prod.protection.outlook.com (2603:10b6:3:115:cafe::af) by DM5PR11CA0005.outlook.office365.com (2603:10b6:3:115::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4844.13 via Frontend Transport; Wed, 29 Dec 2021 06:22:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; Received: from SATLEXMB03.amd.com (165.204.84.17) by DM6NAM11FT054.mail.protection.outlook.com (10.13.173.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4844.14 via Frontend Transport; Wed, 29 Dec 2021 06:22:53 +0000 Received: from bhadra.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Wed, 29 Dec 2021 00:22:52 -0600 From: Manali Shukla To: Subject: [kvm-unit-tests PATCH 2/3] x86: nSVM: Check #BP exception handling in L2 Date: Wed, 29 Dec 2021 06:22:00 +0000 Message-ID: <20211229062201.26269-3-manali.shukla@amd.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211229062201.26269-1-manali.shukla@amd.com> References: <20211229062201.26269-1-manali.shukla@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3943b854-7810-493f-d1fa-08d9ca93a58f X-MS-TrafficTypeDiagnostic: DM6PR12MB3980:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2399; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ncpHevovM+m+Nu1XOsUQzXxKBn/hssEo9Qbh3wVMI//N8L1vEgZQrvAFfa4b9X6wea4OTHUBSloqYWdk1CaeQB+otrDKQQjsZVcRmzyTSd391nu7e9GHbrrBw5Hby5Umjvo0DfMZ13fh7fG2hVXzDD+IZP8IARGgSrUizCbtXBiom7An369BjRVwza4LGb1zAwCr4HN52gR67XbNBRSXqghA4/LnWzES7d+Py9+YuKPCH2o1dyhVHTbllH0JKNUPylvHjVd+aNuWcHeTZpdyiAwORcObn8EA55RYkFnhJbT1x0UdGfMZDbbEttZIYHC+uFLExCdLkW47i3tkfxxh2syuVaPM/5wyyttKF/6vtRtTKVBD2UY1zQ4GdN/JSvDEX+R07Oe0zHAo/BYgx/aaC70hKyxCx3aX/f4uy6LD2R/nzcVEtXPGRmCjRFJgOGI1XroEVnQ52zk5KiB/zA4bJrFe9B/V54PZzwLkjZiyzojun8ppCvyPBb9fcnG9nKYTPEfW6oK4t1XVZ2grxwl6fylYEAbUlWwj7f1C9U2KOwD1UQnEppUs0x/h8r0GOLI2mh/Dqz0nEujjOr4Wx66BI+aOa7mxOPpCtJDwk7oZu5OgbCX9A6ijWZ0/8rAq1oWvzOQppZtuESXPiYAq+2nYssN4Tq4Jht/0UzAMVaC051KgobSAgIhyOEOWjXGlyw+M8KG4CsJyQMiUSCwiib7hk16VY+ioTZIFnDuhNEtjR4ipgU4k80E/X/7+gy+H6wyj/1aCRDcn2pvaETuvfAhoHErpzCa2aFIaH4PPavAemqs= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(40470700002)(316002)(8676002)(426003)(2906002)(7696005)(81166007)(5660300002)(8936002)(356005)(6666004)(36860700001)(6916009)(1076003)(40460700001)(26005)(82310400004)(36756003)(336012)(86362001)(508600001)(16526019)(44832011)(186003)(2616005)(47076005)(70206006)(70586007)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Dec 2021 06:22:53.5523 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3943b854-7810-493f-d1fa-08d9ca93a58f X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT054.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3980 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add coverage for BP exception handling in L2 when only L2 BP exception handler is registered BP exception is generated using int3 instruction and it is handled by L2 BP exception handler. Signed-off-by: Manali Shukla --- x86/svm_tests.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/x86/svm_tests.c b/x86/svm_tests.c index 681272c..ed67ae1 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -2962,6 +2962,26 @@ static bool vgif_check(struct svm_test *test) return get_test_stage(test) == 3; } +static int bp_test_counter; + +static void guest_test_bp_handler(struct ex_regs *r) +{ + bp_test_counter++; +} + +static void svm_bp_test_guest(struct svm_test *test) +{ + asm volatile("int3"); +} + +static void svm_int3_test(void) +{ + handle_exception(BP_VECTOR, guest_test_bp_handler); + test_set_guest(svm_bp_test_guest); + report(svm_vmrun() == SVM_EXIT_VMMCALL && bp_test_counter == 1, + "#BP is handled in L2 exception handler"); +} + static int nm_test_counter; static void guest_test_nm_handler(struct ex_regs *r) @@ -3127,5 +3147,6 @@ struct svm_test svm_tests[] = { TEST(svm_vmload_vmsave), TEST(svm_test_singlestep), TEST(svm_nm_test), + TEST(svm_int3_test), { NULL, NULL, NULL, NULL, NULL, NULL, NULL } }; From patchwork Wed Dec 29 06:22:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 12700778 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5589C433EF for ; Wed, 29 Dec 2021 06:23:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238920AbhL2GXQ (ORCPT ); Wed, 29 Dec 2021 01:23:16 -0500 Received: from mail-bn8nam11on2089.outbound.protection.outlook.com ([40.107.236.89]:39393 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S238916AbhL2GXO (ORCPT ); Wed, 29 Dec 2021 01:23:14 -0500 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QUT4Aboid9iNq3yGxaEduuCYjCax2mt/ANrG/K1UhLy5jVqc4PfgWPGt6eAr1JKdI3bpEtDx2u9RqsRTTdGBy42n1xjQtdK29HNdBs6UWY1CnItzekcvGqT+WPGX87/7mp2LekJ5e+QqU0S2V5jn3PVC+SNdvMD6cRlxfHKIB5oIPl5e/XTziU7IrvxoF+/eyZODS9Wdtu17KLwq2Hqzfb8eyF8Jg80Ww0dX9vGNwEH6CpvPZ7iGwCC4YO9WQpiLeofpfXR81c1JceE4i9IU14PZhXXSLap5q+n6QAFrRw2vsRmVKnLGXWD1d6mP44KMIdcz/xBuua210DZu0l2LOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=kmbRg1/gawEgFeJ5aLFeD0hpPmf0OwBIMxMx0n9gJ+g=; b=dd4qxPHivPk2n9jVy/87Bj2cMtX7QB8kQqsJ8o8Ugrh1XVe9/z8qrUyOZqxwXIUadB0nnuMPMDnMjv9DAaMUk/iMFRZpgyOS4LVvsEx0C8/7wGrjGE0siCfiNpgI2H7Q7n7OXFFJcNsHh1pRQCkWDOaisFUzjEDLqlncdUvkT1LJbwpFDkMColzJ2Jj+QXrWgmWkKUq8mGL3KULG9TkrmWZR2vxEBEI4oWUYB9m+AVL8oN7ErD9QwxPNXKbcgt/lDalDvohcyiwL2v2gvh5dgGh4tit6hp9AtpBebE+IudUykc8fgo48f5RWnHLd997rCwjCrOGYqhm8e0HFT31rVA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=kmbRg1/gawEgFeJ5aLFeD0hpPmf0OwBIMxMx0n9gJ+g=; b=AMMuE2K+vkgkP76FbkFMsBc55Cj9a9PNzbKh2BAxoiW4sfyliIJaISvMwpc6vVnWmC031hfmXayKdyoxLy/ovApmPwbjo2SHkntUkO/lq+ndIxwF3h4BhXrXtj8qJWUGiw7ucUQDOCIinofgrVAXgJyYBRPPQa7e2336lw/LSeM= Received: from DM5PR19CA0006.namprd19.prod.outlook.com (2603:10b6:3:151::16) by MN2PR12MB2911.namprd12.prod.outlook.com (2603:10b6:208:a9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4823.19; Wed, 29 Dec 2021 06:23:12 +0000 Received: from DM6NAM11FT023.eop-nam11.prod.protection.outlook.com (2603:10b6:3:151:cafe::79) by DM5PR19CA0006.outlook.office365.com (2603:10b6:3:151::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4844.13 via Frontend Transport; Wed, 29 Dec 2021 06:23:12 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB03.amd.com; Received: from SATLEXMB03.amd.com (165.204.84.17) by DM6NAM11FT023.mail.protection.outlook.com (10.13.173.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4844.14 via Frontend Transport; Wed, 29 Dec 2021 06:23:12 +0000 Received: from bhadra.amd.com (10.180.168.240) by SATLEXMB03.amd.com (10.181.40.144) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.17; Wed, 29 Dec 2021 00:23:11 -0600 From: Manali Shukla To: Subject: [kvm-unit-tests PATCH 3/3] x86: nSVM: Check #OF exception handling in L2 Date: Wed, 29 Dec 2021 06:22:01 +0000 Message-ID: <20211229062201.26269-4-manali.shukla@amd.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20211229062201.26269-1-manali.shukla@amd.com> References: <20211229062201.26269-1-manali.shukla@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB03.amd.com (10.181.40.144) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 05a0d543-8322-4ca3-2372-08d9ca93b0df X-MS-TrafficTypeDiagnostic: MN2PR12MB2911:EE_ X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1227; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lY/1Wk2vuxvV8LGys611fg8Kr5rv6bSuI/IqflO1gaO70qo9sD6nR/wL9a0XrROCArqiZp+gDdfaVSDUo5uAbzjeplRV3qPtKxoJh6dRSFlAddfICY4j6Gs9l30+cSouJMEKZl9mUq1CmBJlU/M0WBpNxAG7gMwkxHHMWhtkGafA2bxaUYotPOkflseu6smMHzvG5lqD9t1e9hsyKpmzMd48e/QYmxiNx/0Ou8/hH/mTMFa4TTNRrlGA2sxTg8eRxMrRpJIV1Vltl2WDoTsXC3XnVnRH79wj48ceeewR9kDsfNcGJ67BooCNLT1YkKpWoNHzAe5mpCCeuL2fJGR/o3MTTZ0GKhVvlBcSPLuB1Idtvp7hBTMUo4hHPv/H4Rmi3DAhH/dATzntfJ6BITvAoB86dyjuyb6DRk0mXzQiIL1UQDE2JHI262aKpzAvn/9m/vkisrNwFUz1HuJxMfAvSsCyVr7gkUwFPiTVHQAgSNNvcevpx0GDH44dFZFhIuNrrrjDwTN24SLmPBLoLqtIqfZnBxb6GiKz2/jf1e3e0IEMR5h2sgz8aDk5KXl15MU0ovZfTcysr7pt+3LBM3cSvittjtguVUT8iwPxSI9BbYVDjWelG7hmsVRbqH+A0dg9QmPiiDIpYHCuWv9Bt9gwcXyRvHqiuaXvBdZtJEnYIP7QJBnThF6prDMCupqp2M8GWcpFBCzd1j1Kf8rSSzO68qnVmHJyKIqdMxnJD1gn33OgAlreD/aOs+HAR0Yl8uUbGtgClMDGnQlKK7/MqLIGvgDT/AWxIZhg5NBp9NZABXU= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB03.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(4636009)(36840700001)(46966006)(40470700002)(336012)(2906002)(316002)(26005)(70206006)(1076003)(8936002)(86362001)(426003)(508600001)(16526019)(5660300002)(82310400004)(40460700001)(186003)(47076005)(8676002)(36756003)(6916009)(7696005)(36860700001)(70586007)(44832011)(81166007)(356005)(6666004)(2616005)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Dec 2021 06:23:12.5115 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 05a0d543-8322-4ca3-2372-08d9ca93b0df X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB03.amd.com] X-MS-Exchange-CrossTenant-AuthSource: DM6NAM11FT023.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB2911 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add coverage for OF exception handling in L2 when only L2 OF exception handler is registered. OF exception generated using instrumented code and it is handled by L2 OF exception handler. Signed-off-by: Manali Shukla --- x86/svm_tests.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/x86/svm_tests.c b/x86/svm_tests.c index ed67ae1..0707786 100644 --- a/x86/svm_tests.c +++ b/x86/svm_tests.c @@ -2962,6 +2962,53 @@ static bool vgif_check(struct svm_test *test) return get_test_stage(test) == 3; } +static int of_test_counter; + +static void guest_test_of_handler(struct ex_regs *r) +{ + of_test_counter++; +} + +static void svm_of_test_guest(struct svm_test *test) +{ + struct far_pointer32 fp = { + .offset = (uintptr_t)&&into, + .selector = KERNEL_CS32, + }; + uintptr_t rsp; + + asm volatile ("mov %%rsp, %0" : "=r"(rsp)); + + if (fp.offset != (uintptr_t)&&into) { + printf("Codee address too high.\n"); + return; + } + + if ((u32)rsp != rsp) { + printf("Stack address too high.\n"); + } + + asm goto("lcall *%0" : : "m" (fp) : "rax" : into); + return; +into: + + asm volatile (".code32;" + "movl $0x7fffffff, %eax;" + "addl %eax, %eax;" + "into;" + "lret;" + ".code64"); + __builtin_unreachable(); +} + +static void svm_into_test(void) +{ + handle_exception(OF_VECTOR, guest_test_of_handler); + test_set_guest(svm_of_test_guest); + report(svm_vmrun() == SVM_EXIT_VMMCALL && of_test_counter == 1, + "#OF is generated in L2 exception handler0"); +} + static int bp_test_counter; static void guest_test_bp_handler(struct ex_regs *r) @@ -3148,5 +3195,6 @@ struct svm_test svm_tests[] = { TEST(svm_test_singlestep), TEST(svm_nm_test), TEST(svm_int3_test), + TEST(svm_into_test), { NULL, NULL, NULL, NULL, NULL, NULL, NULL } };