From patchwork Wed Mar 27 05:42:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13605576 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2042.outbound.protection.outlook.com [40.107.223.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C03B5D304; Wed, 27 Mar 2024 05:43:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.42 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711518195; cv=fail; b=b1MswBddF42+yYbmpKC1j9jTnDDO+BiAyxVog3ubfu8DzXoRvCASQF1dsE8N8hb7yJ0wv5xTzc0tOHCUz7L1F9Ccd4BwkxoL4URQmKw8KTJpsJBatUnIBz/q1jHppuSzYXGADeP83pl+D6DHDafD81EnSQ17tjfQdK0i22jmwxc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711518195; c=relaxed/simple; bh=ySJgZEUorsCyEp4Jdek9zGeISNzGTW7spH/Em6PGwO0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=sj1uSV0j0y0rAwJ6JSHv1IKg5FfHnIJk/l9vgK7uq2R3EU0OYnIzJ9ywsu8dA/YUW2yMp+NZAL1RxS7BWaIcVsiwZ2GZDNXsTsqi+blVrSdNnSVd8KoGNSbTnaGjsQ1ygay8Z58Oc+aaH9pPppVN8o716SOhSnk0pm/58NNjD08= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=4NJwciGK; arc=fail smtp.client-ip=40.107.223.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="4NJwciGK" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PfzgCY3uZVQLwJSDuKm76KfQBOEmXtgJOCFSZr3Ci5+Ww+f8mWnimqdkkUplWjK5S4VJPpA8dGzqsPehPBnNHYQvA1XQVGdFJvcZ96V06v4GgcBHH+LJBb6uZEkH0mYHitLcDF/QlwLnA1THjMhhhJNZjYG/Ej5TrcWk5T3gEhoZa3ckOa3IbDHF7L30HT2qpQg9YVB8Pg/UR7s4RxJFG793d7RFqL94mC/ljf8F+bEZPidMXpZTlmp90/LtB7RW0rFQ5NdlsIo565GaAGW512KhDve64+EJGC4lNIZ7YqkP1KSPcSKF8g3bxFZ/ZZ2IDfzODWfjL8KzFJgZ3wmMgg== 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=16shPcdruHzE7YytYMcJenoFtLuSK0lr88DixnfrsIM=; b=d+vZEGPeQzV5mrLhfTF5afICPN9HiXVDSVlwFk+tzCV8NpGnI7VbaDNe+Kr/WgOP7B87seFJZC8W9E2mQRXoHMojR3lSbPiMugGxGgk8ASAo7Z+DXspTNuJ8oaLx3UoDvjIR2hHr01OxXtoEcRXJsDrYnn9URK8GFWQ5fywzSDtV1C96iK+n6j7TLmKna7ogQnqU5wxKIwW5JZD8doKHuuyjm6cjRjGJCxHqtx285QfhRQx20gi1b8fqrtyuSjFcAqiVNqyztPz2cPrrz1m+X8k5+QFqDY/qFOV/GcegkHFgKh7lRI+hKch3lh+DBBGEKPsbc/Bi0nFBdtJwICcUGg== 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 (0) 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=16shPcdruHzE7YytYMcJenoFtLuSK0lr88DixnfrsIM=; b=4NJwciGKAp6r+e5S4PqcpkH6zhZCAkdbhRL9QqLULnSqFqFqBo7qTIBcwaFTcbvUTBXCsHSKOkFcR0TstVZonb10uUeBNrFK1pfE933bxAy//nAOk5FUp+4tNte4Pp7pRHLYKzVJQrR4qsOBZf9qZ+Ox7wyBpGUsbw+18O33Zuo= Received: from CH0PR04CA0030.namprd04.prod.outlook.com (2603:10b6:610:76::35) by CH3PR12MB7761.namprd12.prod.outlook.com (2603:10b6:610:153::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.28; Wed, 27 Mar 2024 05:43:11 +0000 Received: from CH1PEPF0000AD75.namprd04.prod.outlook.com (2603:10b6:610:76:cafe::94) by CH0PR04CA0030.outlook.office365.com (2603:10b6:610:76::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Wed, 27 Mar 2024 05:43:11 +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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CH1PEPF0000AD75.mail.protection.outlook.com (10.167.244.54) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Wed, 27 Mar 2024 05:43:11 +0000 Received: from chalupa-4a00host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 27 Mar 2024 00:43:09 -0500 From: Manali Shukla To: , CC: , , , , , Subject: [PATCH v1 1/3] KVM: selftests: Add safe_halt() and cli() helpers to common code Date: Wed, 27 Mar 2024 05:42:53 +0000 Message-ID: <20240327054255.24626-2-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240327054255.24626-1-manali.shukla@amd.com> References: <20240327054255.24626-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD75:EE_|CH3PR12MB7761:EE_ X-MS-Office365-Filtering-Correlation-Id: d4f7ce94-b90c-4404-aad1-08dc4e20ca09 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CjfYFkPcVZp+lD5/B+Fpu/b9gHDP3SfLRUZ3X04aFzNG7pX7dAwve7YpD5D5KMwTAbI9ozde9r+9NgWY98pPGKjKJifi9xRNl1Q14eKEpfzOFaZ3gH3MKN0/3iCN14NbVgDsUddq29e8zIC/ASG8SyKWv/gkwY+7Ql8DEO9V39Sc/01MWqhnlGigtjqqRdOiy5Z37Owh/68uuaFCSwXL2A+lBDLmCU+0c6le7Pfril+QZyF3Abuv0G77hTCG57/MNZSyvrkCf9XnsaIpW0mCmIsx04luilzwugqUUSx/csS/oS8NQlJqvxGxeueogIk8GeN9Xf9E/BVnT3J/V+083tfLAtLJgCMZGco6neZJFuP2H6q9w83N+8Xog8ETxo+EsVunI5+js+JFAH9LoqPA1FvOB0XMglY+HEXgUqgnt5RISEAsMUHUsTr3jEmOoTUZELf446bLimJUN6LFi6l9ZTJkcsYD+A3u7BafDpcAbsa3UQxOykGDhe88ypTSOYOx3QHCdkfdNMBtPnlae5Pi/ImLM3DfCfc5F5X5gDpHtKgjVzBZyAYv1+AlcTSmwq60ircQrLelJLWb6L78yGTKfEJ8pKAByJcIHu1t7BmPJwlKMdpvsrkI5yPWaKz/l1bUgKX1Wj/7hL2qGalbcJc/ZlKellqZ2J3XaUyTq1aAbuHc9nC37C0OAl6v2W97qMfH8ljV0f7SM3n0DotBvIeVCSU+RO5V4mzyj4lhuSmbiVx2H2m48ZgYcJHxOlV6yzI4 X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(36860700004)(82310400014)(376005)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2024 05:43:11.4693 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d4f7ce94-b90c-4404-aad1-08dc4e20ca09 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH1PEPF0000AD75.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB7761 Add safe_halt() and cli() helpers to processor.h to make them broadly available in KVM selftests. Suggested-by: Sean Christopherson Signed-off-by: Manali Shukla --- .../selftests/kvm/include/x86_64/processor.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tools/testing/selftests/kvm/include/x86_64/processor.h b/tools/testing/selftests/kvm/include/x86_64/processor.h index 20c9e3b33b07..6de37f6b8ddc 100644 --- a/tools/testing/selftests/kvm/include/x86_64/processor.h +++ b/tools/testing/selftests/kvm/include/x86_64/processor.h @@ -1217,6 +1217,23 @@ static inline void kvm_hypercall_map_gpa_range(uint64_t gpa, uint64_t size, GUEST_ASSERT(!ret); } +/* + * Execute HLT in an STI interrupt shadow to ensure that a pending IRQ that's + * intended to be a wake event arrives *after* HLT is executed. Modern CPUs, + * except for a few oddballs that KVM is unlikely to run on, block IRQs for one + * instruction after STI, *if* RFLAGS.IF=0 before STI. Note, Intel CPUs may + * block other events beyond regular IRQs, e.g. may block NMIs and SMIs too. + */ +static inline void safe_halt(void) +{ + asm volatile("sti; hlt"); +} + +static inline void cli(void) +{ + asm volatile ("cli"); +} + void __vm_xsave_require_permission(uint64_t xfeature, const char *name); #define vm_xsave_require_permission(xfeature) \ From patchwork Wed Mar 27 05:42:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13605578 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2077.outbound.protection.outlook.com [40.107.96.77]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 813AA12B93; Wed, 27 Mar 2024 05:43:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711518196; cv=fail; b=Sh00xa/LGyIIHVfh0Pa59ICq+PhPwrQAv7t71KINS9WmDPNJhm47v5glvBYrqHVRjfH5QM0JZEvvSIjszsJ3Aa05Ipvw968q108px70YslPYr8O0lgA6yLqKnfCfPi/1Sc5XwQb9nqhFZS9excWMdTDpW3XDDXbszxvBA/noNxw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711518196; c=relaxed/simple; bh=rBEOAhMOr2Mc6g/4ZxVEi2d8HDiDHEUUh/g6HdOt+2c=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=V6wk6LSb+3qXPj2OCfLIUNbwh88UAZkUSX3UtApfDciyxrqR9Aquvm4PJR9/H1hxhyMTgqHRPTTiOBoYAUlGofTyDfpP8ctoeC0TMG0ujmhddOzMV3HL43Wmlat79rqo1fsfn6GixvBG979U5UfOFwCv5vXIfeiddmXlVK8Nwfg= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=Tg/iRoW8; arc=fail smtp.client-ip=40.107.96.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="Tg/iRoW8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UoZBvkDAyUuSKqCo0LGg1K4tSmp6oco7CIC90XaqAduOxP6aNrMdW4FQv2wRC57MVUYVQjjaqR1Jy3YnRv6pytA8KtK1H9kHdK83GWj6re4RJxD9RfyAj5Z3DYPBPL8OHXiIfFxURzEnkT/m2jc79i+brICRCLELDMMqN6i6kefMQpQr8vkEi3lrNZJD72tK2EOqXlXKPLXSyW5axdfLhfPyTq+AXHtcgG08D0Pr0yKdtymIhNH+xfgvWU65jIonQneukAwW0JJB+VeJIn4SHComgvE1EEepkix7EjWnEvWRJyeLxjTQ0+QO6McMMtrO36vlXbDaDTp0fvJJonwq8A== 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=QL+MOT1mtFeALiF8LL04IVbAndrtX+CkHbK57hwB8Z0=; b=DtwbBI42WzQ9h4+1Rb7b5hv9FOv3Ddeq5l2/0n1Rv6E9vSpyS1n84mEAhaqL7/bHRBqzM7RBGHyoYP+YueMfVKxGgMtjGYT4ueXj4jw6+bxZUd6ibjeOn0+qUPUi3xNsgaNlnsDVYTscwu+t6iaA+uMttJlEIBXU+5gUpOyPtG12Gbul5oORKU0N5Hb2RGUkGXixnOordTyJGvY+/lYBAj4ZQwk6IZsfZgqi7iSxZJlIJ7C1FQUgh4aHk/6hW0csYkxULvZ92TXW13ulxhC+5iLUqzrpwp2rqfIdAmajLaXCadIdk2V/YnejFU6GV4muXv0hI2tah5408TSV9Co0tA== 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 (0) 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=QL+MOT1mtFeALiF8LL04IVbAndrtX+CkHbK57hwB8Z0=; b=Tg/iRoW8U4EpyqV0CZU6Gj/gWdZ9cnILftpD1MK5zFsg4Ks/VgaaF2i0yRHt1bsTGcSI7eIOcFVpJoeeg8TvVXC4C8eSAYeKbhd4OG78eWQ3IzBQTqkACDHc+/m9vznkUFJUDOdo3cTQsogiMg0s/jMHfAOr2so+6fVx2ggxv0k= Received: from CH5PR05CA0017.namprd05.prod.outlook.com (2603:10b6:610:1f0::7) by PH7PR12MB7938.namprd12.prod.outlook.com (2603:10b6:510:276::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.24; Wed, 27 Mar 2024 05:43:12 +0000 Received: from CH1PEPF0000AD7A.namprd04.prod.outlook.com (2603:10b6:610:1f0:cafe::63) by CH5PR05CA0017.outlook.office365.com (2603:10b6:610:1f0::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.12 via Frontend Transport; Wed, 27 Mar 2024 05:43:11 +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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CH1PEPF0000AD7A.mail.protection.outlook.com (10.167.244.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Wed, 27 Mar 2024 05:43:11 +0000 Received: from chalupa-4a00host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 27 Mar 2024 00:43:10 -0500 From: Manali Shukla To: , CC: , , , , , Subject: [PATCH v1 2/3] KVM: selftests: Change __vm_create() to create a vm without in-kernel APIC Date: Wed, 27 Mar 2024 05:42:54 +0000 Message-ID: <20240327054255.24626-3-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240327054255.24626-1-manali.shukla@amd.com> References: <20240327054255.24626-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD7A:EE_|PH7PR12MB7938:EE_ X-MS-Office365-Filtering-Correlation-Id: 8db197ee-3856-467b-8756-08dc4e20ca4d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OgF+jvQtedAXvU01p43C/LfcoHUOZhpUVM90yXOfu/UhqNo4keaH7utEyl2aOyM6Fw/9je+jChzY9sHcp3K2afxKiBIi2MwbipSkqn2lvtqt7MCeyDopnQpEEpExFEWV073sGf3Q/4VTc32QbL3w1uM/QFBNeXoMJxkfWL9FwbgunfB145GnResPC9JhTGa0+ntPhE3dbau3BdW5u1XmyBfaPfBi76FJpOlGDkUKjeoAFlFEiMBFEmKngQJWY20sID4AVMaOXX9/u11ebBE1T/kspVo5mt5wTPQwUhWvvOJMOhKHO1Alwub5aj5HZWVysaRuY13qZns2U07LzT8RIjzAN1Hm7ZY0bGLTNw9tn2YzVsIud6gjwwNH08+9gY+gzacNPQkg9izQnirXtjbcktZQWfBuL2aS0hY1Z+4OCyXtG/9rNGHUZrFiCqWpC7ShuQA+J6WxDgjF/cnbrkDFqmD61JUb4Cp6qNVID6UxEEO7UkKuv80lkqTZHOHP4U9v1MiJ1kVYYMzbuQsO3NZkBVl2oYgxJ68+ZgAoPiw9eyRJ4akGgzjryjz5y24yyxlCSobipqgi6OmRVXyYl+pzIQMf5UHuGZ6pKULax+cyWQlN9VFLoDcnrtmPqsLrwB1Hkqxxx/WqZbIHPYUuNvHbAdCoHH0fHXm2yOX9grduvZ1B7McZ28gnZJ7nUkC+9f6/OAA/EpuqmoGQnwCh0fLZixmXKkDPn9hzmnVeysOw/D7BXAcNMYKNLBRKJ5uzz8od X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(36860700004)(82310400014)(1800799015)(376005);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2024 05:43:11.9141 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8db197ee-3856-467b-8756-08dc4e20ca4d 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH1PEPF0000AD7A.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7938 Change __vm_create() to incorporate creation of a vm without in-kernel APIC. Currently, all the vms are created with in-kernel APIC support in KVM selftests because KVM_CREATE_IRQCHIP ioctl is called by default from kvm_arch_vm_post_create(). Add a flag in __vm_create() for a userspace to decide whether to start a vm with in-kernel APIC or without in-kernel APIC. It is a preparatory patch to create a vm without in-kernel APIC support for the KVM_X86_DISABLE_EXITS_HLT test. Signed-off-by: Manali Shukla --- tools/testing/selftests/kvm/dirty_log_test.c | 2 +- tools/testing/selftests/kvm/include/kvm_util_base.h | 4 ++-- tools/testing/selftests/kvm/lib/kvm_util.c | 11 ++++++++--- .../selftests/kvm/x86_64/ucna_injection_test.c | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/tools/testing/selftests/kvm/dirty_log_test.c b/tools/testing/selftests/kvm/dirty_log_test.c index 6cbecf499767..667a83d67bfe 100644 --- a/tools/testing/selftests/kvm/dirty_log_test.c +++ b/tools/testing/selftests/kvm/dirty_log_test.c @@ -699,7 +699,7 @@ static struct kvm_vm *create_vm(enum vm_guest_mode mode, struct kvm_vcpu **vcpu, pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode)); - vm = __vm_create(VM_SHAPE(mode), 1, extra_mem_pages); + vm = __vm_create(VM_SHAPE(mode), 1, extra_mem_pages, true); log_mode_create_vm_done(vm); *vcpu = vm_vcpu_add(vm, 0, guest_code); diff --git a/tools/testing/selftests/kvm/include/kvm_util_base.h b/tools/testing/selftests/kvm/include/kvm_util_base.h index 4a40b332115d..00e37c376cf3 100644 --- a/tools/testing/selftests/kvm/include/kvm_util_base.h +++ b/tools/testing/selftests/kvm/include/kvm_util_base.h @@ -879,7 +879,7 @@ static inline vm_paddr_t vm_phy_pages_alloc(struct kvm_vm *vm, size_t num, */ struct kvm_vm *____vm_create(struct vm_shape shape); struct kvm_vm *__vm_create(struct vm_shape shape, uint32_t nr_runnable_vcpus, - uint64_t nr_extra_pages); + uint64_t nr_extra_pages, bool is_in_kernel_apic); static inline struct kvm_vm *vm_create_barebones(void) { @@ -900,7 +900,7 @@ static inline struct kvm_vm *vm_create_barebones_protected_vm(void) static inline struct kvm_vm *vm_create(uint32_t nr_runnable_vcpus) { - return __vm_create(VM_SHAPE_DEFAULT, nr_runnable_vcpus, 0); + return __vm_create(VM_SHAPE_DEFAULT, nr_runnable_vcpus, 0, true); } struct kvm_vm *__vm_create_with_vcpus(struct vm_shape shape, uint32_t nr_vcpus, diff --git a/tools/testing/selftests/kvm/lib/kvm_util.c b/tools/testing/selftests/kvm/lib/kvm_util.c index adc51b0712ca..9c2a9e216d80 100644 --- a/tools/testing/selftests/kvm/lib/kvm_util.c +++ b/tools/testing/selftests/kvm/lib/kvm_util.c @@ -354,7 +354,7 @@ static uint64_t vm_nr_pages_required(enum vm_guest_mode mode, } struct kvm_vm *__vm_create(struct vm_shape shape, uint32_t nr_runnable_vcpus, - uint64_t nr_extra_pages) + uint64_t nr_extra_pages, bool is_in_kernel_apic) { uint64_t nr_pages = vm_nr_pages_required(shape.mode, nr_runnable_vcpus, nr_extra_pages); @@ -382,7 +382,12 @@ struct kvm_vm *__vm_create(struct vm_shape shape, uint32_t nr_runnable_vcpus, slot0 = memslot2region(vm, 0); ucall_init(vm, slot0->region.guest_phys_addr + slot0->region.memory_size); - kvm_arch_vm_post_create(vm); + if (is_in_kernel_apic) { + kvm_arch_vm_post_create(vm); + } else { + sync_global_to_guest(vm, host_cpu_is_intel); + sync_global_to_guest(vm, host_cpu_is_amd); + } return vm; } @@ -415,7 +420,7 @@ struct kvm_vm *__vm_create_with_vcpus(struct vm_shape shape, uint32_t nr_vcpus, TEST_ASSERT(!nr_vcpus || vcpus, "Must provide vCPU array"); - vm = __vm_create(shape, nr_vcpus, extra_mem_pages); + vm = __vm_create(shape, nr_vcpus, extra_mem_pages, true); for (i = 0; i < nr_vcpus; ++i) vcpus[i] = vm_vcpu_add(vm, i, guest_code); diff --git a/tools/testing/selftests/kvm/x86_64/ucna_injection_test.c b/tools/testing/selftests/kvm/x86_64/ucna_injection_test.c index 0ed32ec903d0..095188562709 100644 --- a/tools/testing/selftests/kvm/x86_64/ucna_injection_test.c +++ b/tools/testing/selftests/kvm/x86_64/ucna_injection_test.c @@ -271,7 +271,7 @@ int main(int argc, char *argv[]) kvm_check_cap(KVM_CAP_MCE); - vm = __vm_create(VM_SHAPE_DEFAULT, 3, 0); + vm = __vm_create(VM_SHAPE_DEFAULT, 3, 0, true); kvm_ioctl(vm->kvm_fd, KVM_X86_GET_MCE_CAP_SUPPORTED, &supported_mcg_caps); From patchwork Wed Mar 27 05:42:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13605579 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2046.outbound.protection.outlook.com [40.107.92.46]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C86E1171CC; Wed, 27 Mar 2024 05:43:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.92.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711518197; cv=fail; b=nD/mcdsS4in6p+bhyjCYhjunR5UkW468zYZNPZOSwvCNvm9DumxGm7KwkuaT1n4E3NAZHlLhYTZwr3xU7tNjv7Lus+v5Z48klUrvbnVUWgDXjiFrSIF+AkgAn2V+qHw4CEJhVigNCSd1HNqT09j6e632qnSPWiLsMN42BeHGFPA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711518197; c=relaxed/simple; bh=dw8dBinq3tE3t53/PPwMenGmaGsRyDZL+du91C9yWnQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LAGCF9dszhErcoM5iRgEV3KcaVKoVWWj54QNcoxEGpV7jDvg2zUtlO2D2BwQLViYPoxn0zKs8mSAKvSn1gi62iFQ2rYq6KJtMUiMO+rYpYwFiZ0GJ3KphAu/Uj9HO9Cct25durcKMvlBus0+b5ZfocgznWsLru4n904Nhk3p2dY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com; spf=fail smtp.mailfrom=amd.com; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b=DIMxxUda; arc=fail smtp.client-ip=40.107.92.46 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=amd.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=amd.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=amd.com header.i=@amd.com header.b="DIMxxUda" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BGGG1mwLvI2a8psol5ueVmfPVxRocquNoAtZoXOgh4q3bHSp2uB6L8BQyPK0c4mnq1aYAM8f9oYksQ5SB2Z7rS6zqOMejGG4lO9ks9mIGujHnhHxpxK9L0KE1xUb+mSf6YY0cEK46BxKX88oBMl/eU27+/oLXN19O4a2jgUUCfB9o/+oZIH3RVDpnrLzkb2VAwoITIVdqbIn9J17BpIj54CWFQEN4oj0PCN8sSTsHXZdnUmczoHdja+IQiRdSb3QsE62zhKPDJrV1G0TfKCTyVom+B5O35gA8ECOkyFM9Ly/bz+BjuYOHzemuVxNJCpdNDep1CP7i03qWzNbwGJ6aw== 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=4Ejoj9ojfpD7FEqtatnIcbZZK+y1kNu1zg+AMRd/T/E=; b=DA4fldq9rkf3/bBeLdXU10U5sCLo3IBwYt6w2RD/JiJ1C0Uqb6bGdj9Qsnq6K412ZlAexe2W5xtBMfVxxYumvqP6xBy1k0zd/SvrFBXMHqvQcDqxblZSDuqdAYj54LX5vqRTd1Swdnz8fKuRl/7Wt/LuJdTsTDO8WcApHsmWMtu5V9C+RKBKxhl0tCp3ZWo3wvFSV/a7oLu2IRx4hF+Pmor+iwZZfC/zcGVSGwediFulwPnMXqxa+LKKKAiwe+5sIdLovNA4Uc+cQHgkVQVYYDZsOT6KSOcqaPl0ndHJXLYEOgd1FDFXCktspq0FZH+tyjdzn6ldAhY0G7jmun677w== 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 (0) 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=4Ejoj9ojfpD7FEqtatnIcbZZK+y1kNu1zg+AMRd/T/E=; b=DIMxxUdaSs0kQcS4MWMnI2zn0ASIqKJma8/vkn3pCsFPSyx8EQbhTwV+GBx0REVM5pqjLEa0lmx4cOO5kFkRBUqDJTCwEMC6PGByeRQ4u6lbh/8szvmeW9alVIrS0rL3vRMOpFm37Rtw+x9uGj1tZKdp45CuQbM3HStd1m2Z1oA= Received: from CH5PR03CA0019.namprd03.prod.outlook.com (2603:10b6:610:1f1::27) by DM4PR12MB5866.namprd12.prod.outlook.com (2603:10b6:8:65::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.32; Wed, 27 Mar 2024 05:43:13 +0000 Received: from CH1PEPF0000AD77.namprd04.prod.outlook.com (2603:10b6:610:1f1:cafe::99) by CH5PR03CA0019.outlook.office365.com (2603:10b6:610:1f1::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.13 via Frontend Transport; Wed, 27 Mar 2024 05:43:13 +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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CH1PEPF0000AD77.mail.protection.outlook.com (10.167.244.55) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7409.10 via Frontend Transport; Wed, 27 Mar 2024 05:43:12 +0000 Received: from chalupa-4a00host.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Wed, 27 Mar 2024 00:43:11 -0500 From: Manali Shukla To: , CC: , , , , , Subject: [PATCH v1 3/3] KVM: selftests: Add a test case for KVM_X86_DISABLE_EXITS_HLT Date: Wed, 27 Mar 2024 05:42:55 +0000 Message-ID: <20240327054255.24626-4-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240327054255.24626-1-manali.shukla@amd.com> References: <20240327054255.24626-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB03.amd.com (10.181.40.144) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH1PEPF0000AD77:EE_|DM4PR12MB5866:EE_ X-MS-Office365-Filtering-Correlation-Id: 527d1de0-10e3-4892-894c-08dc4e20cac9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mxSGyvqr/0OSg7d8IYXr7ZUxEEWW17zdnBkU8Wr6vArJBZjjzKlFGEZgoVLIGAyr4EmoYGfVNWE/5YqDp4lHMab8XAvGSbFT56V6HJJdrbuVbMvJXqw12Gofaewxe1IuefaT6mpA1bIwPLWlEmhNwdFqHol2Pik2fvylHSxzi3rnLMneyi8f08b6j8JGkAzEQ+HgbJ7GBrjFwnkI3atePiToozKTT71wGCsGKSI12F9QQ1Ae0XPBUHTk6/C/uIkwuRdp8PxpMHwbUORJW+b+9LdBs+oX2lQNwzZS+tQtRdjuBeP7JG5zXa7VXZZqDG23BORJ1nQcagEYf14d13V8jjfzJ4sRsofzqEVqGc2eVWuSKovhK8zQypBaHw6zY7LQefQlQd6/9svMl4scC0yCNz+Gh+uuA6VUgw98UwkQKrhZaSVcQIQ6LQkcSZFPBv5j53fcE1E+nH/UlTZKJbuiZGfF5eMjYSgVlX8MTVScHh7WCtfOn9qIz2d6nUu4Q75RorWjwZJYIx8XslzTBQWB65iJFtqUDoso/LDj9rfXfg8kQ9wba0ls/+632zxGrJ2Kj3A5Jwit+TsBnwx9fSF1lTgCeIBvC0aRrxOqSHQuwJ5oZPP5T4OCsmfECG1D87YenoTl7NCQu5uv6iw/6YkWNgKIoc7islohKczA+HFx4KWOE907UCMnL4DP66Gq4TFMSGAbW6dyGD2HftNG8wfi9fsE9EWpYpxvO10mDheRVq28r0SPFaAbdsEjZ3w91YQM X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(376005)(82310400014)(36860700004)(1800799015);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Mar 2024 05:43:12.7268 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 527d1de0-10e3-4892-894c-08dc4e20cac9 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=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CH1PEPF0000AD77.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5866 By default, HLT instruction executed by guest is intercepted by hypervisor. However, KVM_CAP_X86_DISABLE_EXITS capability can be used to not intercept HLT by setting KVM_X86_DISABLE_EXITS_HLT. Add a test case to test KVM_X86_DISABLE_EXITS_HLT functionality. Suggested-by: Sean Christopherson Signed-off-by: Manali Shukla --- tools/testing/selftests/kvm/Makefile | 1 + .../kvm/x86_64/halt_disable_exit_test.c | 113 ++++++++++++++++++ 2 files changed, 114 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86_64/halt_disable_exit_test.c diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index c75251d5c97c..9f72abb95d2e 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -89,6 +89,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/set_sregs_test TEST_GEN_PROGS_x86_64 += x86_64/smaller_maxphyaddr_emulation_test TEST_GEN_PROGS_x86_64 += x86_64/smm_test TEST_GEN_PROGS_x86_64 += x86_64/state_test +TEST_GEN_PROGS_x86_64 += x86_64/halt_disable_exit_test TEST_GEN_PROGS_x86_64 += x86_64/vmx_preemption_timer_test TEST_GEN_PROGS_x86_64 += x86_64/svm_vmcall_test TEST_GEN_PROGS_x86_64 += x86_64/svm_int_ctl_test diff --git a/tools/testing/selftests/kvm/x86_64/halt_disable_exit_test.c b/tools/testing/selftests/kvm/x86_64/halt_disable_exit_test.c new file mode 100644 index 000000000000..b7279dd0eaff --- /dev/null +++ b/tools/testing/selftests/kvm/x86_64/halt_disable_exit_test.c @@ -0,0 +1,113 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * KVM disable halt exit test + * + * Copyright (C) 2024 Advanced Micro Devices, Inc. + */ +#include +#include +#include "kvm_util.h" +#include "svm_util.h" +#include "processor.h" +#include "test_util.h" + +pthread_t task_thread, vcpu_thread; +#define SIG_IPI SIGUSR1 + +static void guest_code(uint8_t is_hlt_exec) +{ + while (!READ_ONCE(is_hlt_exec)) + ; + + safe_halt(); + GUEST_DONE(); +} + +static void *task_worker(void *arg) +{ + uint8_t *is_hlt_exec = (uint8_t *)arg; + + usleep(1000); + WRITE_ONCE(*is_hlt_exec, 1); + pthread_kill(vcpu_thread, SIG_IPI); + return 0; +} + +static void *vcpu_worker(void *arg) +{ + int ret; + int sig = -1; + uint8_t *is_hlt_exec = (uint8_t *)arg; + struct kvm_vm *vm; + struct kvm_run *run; + struct kvm_vcpu *vcpu; + struct kvm_signal_mask *sigmask = alloca(offsetof(struct kvm_signal_mask, sigset) + + sizeof(sigset_t)); + sigset_t *sigset = (sigset_t *) &sigmask->sigset; + + /* Create a VM without in kernel APIC support */ + vm = __vm_create(VM_SHAPE_DEFAULT, 1, 0, false); + vm_enable_cap(vm, KVM_CAP_X86_DISABLE_EXITS, KVM_X86_DISABLE_EXITS_HLT); + vcpu = vm_vcpu_add(vm, 0, guest_code); + vcpu_args_set(vcpu, 1, *is_hlt_exec); + + /* + * SIG_IPI is unblocked atomically while in KVM_RUN. It causes the + * ioctl to return with -EINTR, but it is still pending and we need + * to accept it with the sigwait. + */ + sigmask->len = 8; + pthread_sigmask(0, NULL, sigset); + sigdelset(sigset, SIG_IPI); + vcpu_ioctl(vcpu, KVM_SET_SIGNAL_MASK, sigmask); + sigemptyset(sigset); + sigaddset(sigset, SIG_IPI); + run = vcpu->run; + +again: + ret = __vcpu_run(vcpu); + TEST_ASSERT_EQ(errno, EINTR); + + if (ret == -1 && errno == EINTR) { + sigwait(sigset, &sig); + assert(sig == SIG_IPI); + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_INTR); + goto again; + } + + if (run->exit_reason == KVM_EXIT_HLT) + TEST_FAIL("Expected KVM_EXIT_INTR, got KVM_EXIT_HLT"); + + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_IO); + kvm_vm_free(vm); + return 0; +} + +int main(int argc, char *argv[]) +{ + int ret; + void *retval; + uint8_t is_halt_exec; + sigset_t sigset; + + TEST_REQUIRE(kvm_has_cap(KVM_CAP_X86_DISABLE_EXITS)); + + /* Ensure that vCPU threads start with SIG_IPI blocked. */ + sigemptyset(&sigset); + sigaddset(&sigset, SIG_IPI); + pthread_sigmask(SIG_BLOCK, &sigset, NULL); + + ret = pthread_create(&vcpu_thread, NULL, vcpu_worker, &is_halt_exec); + TEST_ASSERT(ret == 0, "pthread_create vcpu thread failed errno=%d", errno); + + ret = pthread_create(&task_thread, NULL, task_worker, &is_halt_exec); + TEST_ASSERT(ret == 0, "pthread_create task thread failed errno=%d", errno); + + pthread_join(vcpu_thread, &retval); + TEST_ASSERT(ret == 0, "pthread_join on vcpu thread failed with errno=%d", ret); + + pthread_join(task_thread, &retval); + TEST_ASSERT(ret == 0, "pthread_join on task thread failed with errno=%d", ret); + + return 0; +}