From patchwork Tue Jul 9 17:51:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13728398 Received: from NAM02-DM3-obe.outbound.protection.outlook.com (mail-dm3nam02on2061.outbound.protection.outlook.com [40.107.95.61]) (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 A581B12C549; Tue, 9 Jul 2024 17:52:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.95.61 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720547536; cv=fail; b=G+19rP1QDJBeJiNfR1w/HnqE/1V02sLlDOqknoPY23bnr+4I9F+356QFeqvijDk2T9iTwkKlGA3G/NEV9QVKsgXGOt5Dh4xPllLjJmHipgCeYFN7DLgMUCInfUF2hwIsfbX+aybX+CGnH0wXvca5/AhugMYzKoEsiYkFB7BzD84= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720547536; c=relaxed/simple; bh=RYFeQXDq5a4SpSU18g8zrw7GB9/95GsOUebeeNtSDds=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=CnrJaWr8t+NlUEoIKX8uwOUI+ld7vszbwjE3D/Om5IFq2Ra9+mM3cV5BXfp9AhUBnv4pvwEbnLU1JNDkcpP0Oaq3SAZhGxLAgbt1JosPNKa6rl4X4ePVyUbZjHQF8jhBgjN4B25BllaGmkeQi6X+W3wvkA2olknIrLBn2jVhDcI= 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=PG1nXvjp; arc=fail smtp.client-ip=40.107.95.61 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="PG1nXvjp" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PZciqU8uxkprvFHUYVogxxMYSFb2W6e2Zbj8qrU0QwvFtws3w74I0zujn/ccd1XYMJ7/wZEgq8ETnEm/ycQJjzgBbHYEm2bxFdZSGtp1H7rfXIsEMhZ3OFbnoOq3haEXnUvFqapgs6J138Qfts1HCBdAN1MKYyOg06erqppR/KrxpKiGCYKk+r82jzSRB1TIqEU6uv7t9EMopo23JG7MAU/42aAv3y9coc4JPLzcPwv7tKameNLhdpVIVsd9wq+R0tmJ8r8+GU40SLbiaeL42pUMqfmx1Fj90Krcy7soKktRXNQ6DdZr+Wf3kSsCWRfSao5ocuagDsXP2p2QPR8HBw== 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=pJ3rU7EZMDgqEVm9Zq5kmPmAJI1fRrZ+n7OniIGLPoA=; b=e4lHtBv9bKM+rdx0+Sy3IPXJvdjrC+KHm686IaqBLy+WDVWzd3Vc5xE4Mgv1J+RtiOP2MwirxL5oq0SlaeOaylLELlZQpGgvHr9PYuAQhAuSQ+1aH+hNpNL/9v1CNQoqQlYVHQitsJP8l1r1TsFZoe0aNNSeQWAL2bQIsfP0VgFG3OwG6MeiOVT1XVoKGuLyK+vD9vZE2oS4GNC0bILydFncooz5mpi1WcFR0uMbbbEtZvp8U+Dry/JWHmXzEINe44DOANQFaOSX5oW5UnUTnEkIOy4ZT1t7yo7QgVihgEanMZdid4FeRkM9kUrYZia5s6XdaWeUuoRR1LOaLwHUqw== 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=pJ3rU7EZMDgqEVm9Zq5kmPmAJI1fRrZ+n7OniIGLPoA=; b=PG1nXvjpQWLlUW1ERDYd3aj1xiQwyU4AIHSH0sraKoP2dDoWc4hp6SsUkmQu36uTdywhmax2OOoSugWlGZzcFf0Gr7Tcwrxjp+4UgQFhHLce1e+UYx1VRJ5iwKqo94q7bvUZoNPM3aLZl0hCKo2ZGLMFZVjnKVIpGmBs6UsSW24= Received: from DM6PR10CA0008.namprd10.prod.outlook.com (2603:10b6:5:60::21) by IA1PR12MB6020.namprd12.prod.outlook.com (2603:10b6:208:3d4::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.35; Tue, 9 Jul 2024 17:52:11 +0000 Received: from DS3PEPF000099DD.namprd04.prod.outlook.com (2603:10b6:5:60:cafe::1e) by DM6PR10CA0008.outlook.office365.com (2603:10b6:5:60::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.19 via Frontend Transport; Tue, 9 Jul 2024 17:52: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 DS3PEPF000099DD.mail.protection.outlook.com (10.167.17.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7762.17 via Frontend Transport; Tue, 9 Jul 2024 17:52: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.39; Tue, 9 Jul 2024 12:52:08 -0500 From: Manali Shukla To: , CC: , , , , , , , , Subject: [RFC PATCH v1 1/4] x86/cpufeatures: Add CPUID feature bit for the Bus Lock Threshold Date: Tue, 9 Jul 2024 17:51:42 +0000 Message-ID: <20240709175145.9986-2-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240709175145.9986-1-manali.shukla@amd.com> References: <20240709175145.9986-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DD:EE_|IA1PR12MB6020:EE_ X-MS-Office365-Filtering-Correlation-Id: 18c5ddb7-e852-43ea-9998-08dca03fdbf9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|376014|36860700013; X-Microsoft-Antispam-Message-Info: vRFnvnChW07UAq6SSStoGe3qEgsy0HiqJsS7TUX9bbfz/gphUzH0Ds+XKqtC3wcd2kh9V6YXLdBFWcXY9xELVk1lP3yVT9yOEJbbse9SmcAtVZRPzSS9mBMbV17rkM59N2TBomTPb7L1SJJCKmCXlkVzEFuKD43ctQCBCyROyCimxDUMCWQAm+AFXvr/mamgWOfte4QnlXo9uK3OfLzCV4azInKyZhfH1g3giGZ9jx0B15P26DOIPHZ7n2VOtwZxc0VLHuwA4SEVguBWeoZxvtshz0znSNmKvHQgvvR+zx+BoXCaI5DvU8jN/FG2XvURVIazoZB5SoOJLCtu+Q0EATgpYnKgr/qNPv+xmPGTbzRrZ7G2gIZ0rVJoZiFSdYowxn2jZgNkBlUqGA4BgFY0NUKhXqiAZrVg/Qbgdo83S1kJkBgdOLjyJA5+vbjKqPXlWDmDjM2aElQ/lNVTa6C69ueslfCxt36dd8RZ8Pp97v2JB3j07iprXxWiuRe0pqycYKR5WH8zGrpz6J9Lg8y//HzDW99891YblvitsYDoO8lj6Pdnvw6BkMOdDWG7dVhBZ4inKcJDd7DifQV37GgNgT2g/E3Bp9i+Fg22+ym1qKc0ng0hYyR/QHA9ji8fR0F9eVmit5FmfUC298KG4zkem9MWzJ9D0WXw6lJye9RbCjPMN6w6fPYWCeglzyjlKZYZi0BGfSJpLedPVzYv+HGhTqaH89Stoz4p9RX8wW2Kod/TG/i6aopgnWUTk89mH78WEa8EaAQ387utjXfV6F0wUA5Nq4eY4LDitSBQMN6dYW2LN9Yzndm7ziOVAkMhGnm28+1zOHyWh5NcGD9f0AXa5WSLWRndEwyu82PaghaUlaEtA2ALT0opC4jZhQhGX6R38ziPH3ig7r7rXaA7XfIH1qE4ZsE2BPUdps7ySnDljlLTUyVW0mMcat5s94wX044U8+PYpNZxHRQvRRXAp8q9ECDfpKEMB1BwQVl9eaE0vGZY1AUwyxiRalOffo0Ha1YZHZnpnoQEK4wYCNiIEA5kaWYrpHdi3P1ix70VdOrT9UdhramcEeDgGrw/UkOqFBzKmbj2h/dWqjU83Clf+iHVyTIlqQVaRybjsTFkRoTExngTHdeoXCEN3hVsK/IMAq3KVAkwd9hOP8AlkUKw+NoCC7vrR18ay2qVN8QciVA67HbkIvSgNmW+rdUCxMe2n5mX0oze5uUHcgc6HZ5q2WV+pnXlTjG/A5A5xjarlySw80BR2Xe5eN+Yy06n04BwmAdFLjlV4wnS/1nQMkICuT2jhOrQsEWU3av+xtqWf1iI6oBq4aCixkv8SJYmutS44RWAUETrm4WTrUnu/WxacsOURbjU/jRTwGuh3hBAWdD2ObmA40LZPsSfkkeUk5X++RRBk2iQ0On/vdZSSHn0+eA8YBh9dlUY7Lc6mtAqYHZ9lmn69RZrzyDNAiEZHMeHkd+9 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:(13230040)(1800799024)(82310400026)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jul 2024 17:52:11.0907 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 18c5ddb7-e852-43ea-9998-08dca03fdbf9 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: DS3PEPF000099DD.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB6020 Malicious guests can cause bus locks to degrade the performance of a system. Non-WB(write-back) and misaligned locked RMW(read-modify-write) instructions are referred to as "bus locks" and require system wide synchronization among all processors to guarantee atomicity. The bus locks may incur significant performance penalties for all processors in the system. The Bus Lock Threshold feature proves beneficial for hypervisors seeking to restrict guests' ability to initiate numerous bus locks, thereby preventing system slowdowns that affect all tenants. Presence of the Bus Lock threshold feature is indicated via CPUID function 0x8000000A_EDX[29] Signed-off-by: Manali Shukla --- arch/x86/include/asm/cpufeatures.h | 1 + 1 file changed, 1 insertion(+) base-commit: 704ec48fc2fbd4e41ec982662ad5bf1eee33eeb2 diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index 3c7434329661..10f397873790 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -381,6 +381,7 @@ #define X86_FEATURE_V_SPEC_CTRL (15*32+20) /* Virtual SPEC_CTRL */ #define X86_FEATURE_VNMI (15*32+25) /* Virtual NMI */ #define X86_FEATURE_SVME_ADDR_CHK (15*32+28) /* "" SVME addr check */ +#define X86_FEATURE_BUS_LOCK_THRESHOLD (15*32+29) /* "" Bus lock threshold */ /* Intel-defined CPU features, CPUID level 0x00000007:0 (ECX), word 16 */ #define X86_FEATURE_AVX512VBMI (16*32+ 1) /* AVX512 Vector Bit Manipulation instructions*/ From patchwork Tue Jul 9 17:51:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13728400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2069.outbound.protection.outlook.com [40.107.220.69]) (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 E89831494C8; Tue, 9 Jul 2024 17:52:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.220.69 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720547536; cv=fail; b=YODIhFl/dMOCGW9kmGlfYcpK7GGFivrTFffEuTo1pnVK9CZuQDhuQCBgw7KqwWqePa1BzihrJ+Xp6hpMvKqh8AR0TCKaeq9wBuSn/daZyIOI11bi6/XwXM8yrVXAlkZcTAOia/6U3ooFSIFY9uFaQ4BYN0luU8D/L1Pz7Fb/hNk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720547536; c=relaxed/simple; bh=0bzjK2P1gQMuTkCSglANTx19JtGZrdZ0HZcnmCrwGMc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VsYC8EZnyyKF2guhOJCaZierjY6tZOigOCmoU8JABZ+H49sg5s7aEZdEHJGqD7P5Dt6/GjhioaRp5hn9HUwKWo4K1bOTpBHzWgDjVYAzUf7iieKfCAW56l1unLvmrQ7t0ZXPIsKxi7Bi0VdQNyv2GV9CoefeLywBiQ35petVhlI= 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=1wIx0q49; arc=fail smtp.client-ip=40.107.220.69 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="1wIx0q49" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hRIMaFpeXdlVBHvs00UsmJ1hQl8i1+yCKLwNPvwZto8IGzZom5otF+iKfCILovGWicsown+U58FPcqjoASRIKHcbDc/0ddlFbNQX2ZifaufV/naXck5QUeIJlalHd1picBKwcJg8az1Cr2fbyvHo8puXBQKAGS/7P+nnjGt88SmLR4pIkO9Ly6a4Sx7tu7LcUG4HaUCGM/zxpNaSsB4jewzFwvnYRXlkk3t2KtOjK5oLhPKyadSQLknDvEYvymrJM4rD9lz0V/ay6+rp/h8CV/7pfJFc2Y9uFExbp0p9h0pVZD7Mr10bW95fc58fr3tF/ucwW+nZ6An7EP/K396TLA== 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=qAJMtIZjyaMxoDQn8SckoHelyBuWTZrvkaF80D7mDLE=; b=PBo7Lm2rUBHCunoJWNFHJ4m+TQB3jLrePuRcJh+dfdfSzDZ+6Sn51Eefi6yPZzENRalqIvFFcbq37IHg2D2U2gyi9UIZVG3mejEs9uWzHjok6csuuItDGwL8St1EpC3EVzWPZCr2tFnwkug5WtGvWfRErfQv0Na1BD/46JdJ6Sy10LgqvPvdYNkuLLGgba6GwZkax0ZvAuh4QsU6yYH/JZzrxarOUStY1EfyTQatmAt+5yV/WCRKHhJKOpdzmblrtWkoRn+vJmMxAM2skwz7oZuB2oYYezvx/pwEJ9wiG4B0uGG16qhXLGzVpvtiAzYBwm/WCrf5GMQIJngeqiTpAA== 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=qAJMtIZjyaMxoDQn8SckoHelyBuWTZrvkaF80D7mDLE=; b=1wIx0q49dBxmOAyZF7Y7QYHqPHO1unTW1Q5VxtWvWvqJxbwCKP2jwLHtYCmiPjUf0ETsDxyHzu1F65V4dNSi4rnddpipsN8dU6rM1kGND/7XI0LAqgHq5Ld3oHHhR14PfJ7gythNRqJ5G5S48LUP4NtGmrFsY7eyw5rM0VxMXmg= Received: from DM6PR10CA0026.namprd10.prod.outlook.com (2603:10b6:5:60::39) by CYYPR12MB8939.namprd12.prod.outlook.com (2603:10b6:930:b8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.36; Tue, 9 Jul 2024 17:52:12 +0000 Received: from DS3PEPF000099DD.namprd04.prod.outlook.com (2603:10b6:5:60:cafe::93) by DM6PR10CA0026.outlook.office365.com (2603:10b6:5:60::39) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.19 via Frontend Transport; Tue, 9 Jul 2024 17:52: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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by DS3PEPF000099DD.mail.protection.outlook.com (10.167.17.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7762.17 via Frontend Transport; Tue, 9 Jul 2024 17:52: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.39; Tue, 9 Jul 2024 12:52:09 -0500 From: Manali Shukla To: , CC: , , , , , , , , Subject: [RFC PATCH v1 2/4] KVM: SVM: Enable Bus lock threshold exit Date: Tue, 9 Jul 2024 17:51:43 +0000 Message-ID: <20240709175145.9986-3-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240709175145.9986-1-manali.shukla@amd.com> References: <20240709175145.9986-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DD:EE_|CYYPR12MB8939:EE_ X-MS-Office365-Filtering-Correlation-Id: 6c0822d4-84cf-46ce-6d05-08dca03fdc6e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|82310400026|36860700013|376014; X-Microsoft-Antispam-Message-Info: 8rSrg4kTi7Ar3yfCdOz7GLS8RqkTPBAqo8sZZyLkhMVxyv++egj4Nz0lnHQqpUgjAgGntXi5257xBvvZtC5KDc7pi8PG7izjrLO2E7q9tDyphzCFkTJR2W9GDIIcReWEEvkcN52dUyoOvESV4wgKfGpicinKTSchLM3EJI/LXhtNM21Mvhv8Cg3FqHou9V+ne9iDrJhjLtVU1sKbZaEu9Fe260pw43UFrerTzudm74SQ5+wU3L/q2h77OSczy3GwPhOPiYO4fXLvYUzx14ob+Gj7NBolHMNl30i9Ev5FzqkZ0HOfRqziaI8xI+Nt58XG4UeS9hnKhPy9hlYKR50yod+sjbDy6KZdjDJicN4VEg/wxOIdHHQj9fv/2Nejg1c95mc9awEglNjNtuOHUHXUKxDF6axBt/8mIZzwgQZ6iVETgduBKQiY8gSKh4laBz1kYAickduTX86rv0vjfGdXSc7xKsDSYhXARkmqF/Ib44IVGnuQJo3uLQktEbWE05MihKFiKIrR/Yb9hnmOuXpabZbQL9FczSaHuBzA8lkc8V1NPHqK5GtHH7+ffKpwrzayVKF0kXxSUEQ/vClPQceMbcsejaV8aWRI7pA0sJmngf9ldU1uZnwTmaSyfy3Sh1VQ4UZeA28rxV/bCQ1H2Y/KSPIVVSobO5JIH+tfH5uStkuf9QewLolhiUSLhwnIxRMbZgd2GZBtOiC7Hds4brXlP1c330b/LCQwpDN1RRQViKLxnkDbjw1T6kCGTaRObyQEwuetHGAm75obY2JIbvIAFXo6EYp218rAr44uR7B5GPOmvOM9wERBOtc416V+tVlkm+Y2Zr6oxpNqAZEXQPhbEe3k1/MgXBx5OKcpnWnri4qBytpwKcYqdIJX3r404njOGUQsSBgo2go6AASHRs4jO+ojb6H3bRcoGi8li0XxhvwTPhGYx81/VSYpvvL3NIacmkWAP6lOBLhUfJYNVqJfrG9YC9n0UY510E9JkJVxP4d6HwX1ytQ+YG7+i/RydqrJchLK2dkHpgOUC2YNhvB4/CNWMuxOUG8y9Fgju8dWiFdrWviwdYlKJayhckbuP2KNz0+/jYqb8BnxUj3EGqFK5yLwJBHuHBLUp5HWOu7F064chquZ4vH+ymx5hf+LYlgxGkPSqw3+3cOzkDhQRn1M7K3wCjY7bQwSZfHtz6tS1vCCM9ehnvS6Y581chVoq6JM6UZGp87km11gX25mSn67W4QjSpw+zEOAwBljX3S3jF5mV628aG8wDVriXLPoLcPL4rGfHlaXDN4APaxXQBX2UUH/VpmBHjCm7O2tDuXYUe4VrMf1f6NMNGpgLjy72XSqEKZPW9zcja6gcTfBjXaF2/4q0+QMGEj9ITlPGnDyi6ByY1RSVUVJMqC3uYfBNG59 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:(13230040)(1800799024)(82310400026)(36860700013)(376014);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jul 2024 17:52:11.8407 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6c0822d4-84cf-46ce-6d05-08dca03fdc6e 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: DS3PEPF000099DD.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR12MB8939 From: Nikunj A Dadhania Malicious guests can cause bus locks to degrade the performance of system. Non-WB(write-back) and misaligned locked RMW(read-modify-write) instructions are referred to as "bus locks" and require system wide synchronization among all processors to guarantee atomicity. Bus locks may incur significant performance penalties for all processors in the system. The Bus Lock Threshold feature proves beneficial for hypervisors seeking to restrict guests' ability to initiate numerous bus locks, thereby preventing system slowdowns that affect all tenants. Support for the buslock threshold is indicated via CPUID function 0x8000000A_EDX[29]. VMCB intercept bit VMCB Offset Bits Function 14h 5 Intercept bus lock operations (occurs after guest instruction finishes) Bus lock threshold VMCB Offset Bits Function 120h 15:0 Bus lock counter Use the KVM capability KVM_CAP_X86_BUS_LOCK_EXIT to enable the feature. When the bus lock threshold counter reaches to zero, KVM will exit to user space by setting KVM_RUN_BUS_LOCK in vcpu->run->flags in bus_lock_exit handler, indicating that a bus lock has been detected in the guest. More details about the Bus Lock Threshold feature can be found in AMD APM [1]. [1]: AMD64 Architecture Programmer's Manual Pub. 24593, April 2024, Vol 2, 15.14.5 Bus Lock Threshold. https://bugzilla.kernel.org/attachment.cgi?id=306250 [Manali: - Added exit reason string for SVM_EXIT_BUS_LOCK. - Moved enablement and disablement of bus lock intercept support. to svm_vcpu_after_set_cpuid(). - Massage commit message. - misc cleanups. ] Signed-off-by: Nikunj A Dadhania Co-developed-by: Manali Shukla Signed-off-by: Manali Shukla --- arch/x86/include/asm/svm.h | 5 +++- arch/x86/include/uapi/asm/svm.h | 2 ++ arch/x86/kvm/svm/svm.c | 43 +++++++++++++++++++++++++++++++++ arch/x86/kvm/x86.h | 1 + 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index 728c98175b9c..538b7d60b05c 100644 --- a/arch/x86/include/asm/svm.h +++ b/arch/x86/include/asm/svm.h @@ -116,6 +116,7 @@ enum { INTERCEPT_INVPCID, INTERCEPT_MCOMMIT, INTERCEPT_TLBSYNC, + INTERCEPT_BUSLOCK, }; @@ -158,7 +159,9 @@ struct __attribute__ ((__packed__)) vmcb_control_area { u64 avic_physical_id; /* Offset 0xf8 */ u8 reserved_7[8]; u64 vmsa_pa; /* Used for an SEV-ES guest */ - u8 reserved_8[720]; + u8 reserved_8[16]; + u16 bus_lock_counter; /* Offset 0x120 */ + u8 reserved_9[702]; /* * Offset 0x3e0, 32 bytes reserved * for use by hypervisor/software. diff --git a/arch/x86/include/uapi/asm/svm.h b/arch/x86/include/uapi/asm/svm.h index 80e1df482337..dcce3ca367e9 100644 --- a/arch/x86/include/uapi/asm/svm.h +++ b/arch/x86/include/uapi/asm/svm.h @@ -95,6 +95,7 @@ #define SVM_EXIT_CR14_WRITE_TRAP 0x09e #define SVM_EXIT_CR15_WRITE_TRAP 0x09f #define SVM_EXIT_INVPCID 0x0a2 +#define SVM_EXIT_BUS_LOCK 0x0a5 #define SVM_EXIT_NPF 0x400 #define SVM_EXIT_AVIC_INCOMPLETE_IPI 0x401 #define SVM_EXIT_AVIC_UNACCELERATED_ACCESS 0x402 @@ -223,6 +224,7 @@ { SVM_EXIT_CR4_WRITE_TRAP, "write_cr4_trap" }, \ { SVM_EXIT_CR8_WRITE_TRAP, "write_cr8_trap" }, \ { SVM_EXIT_INVPCID, "invpcid" }, \ + { SVM_EXIT_BUS_LOCK, "buslock" }, \ { SVM_EXIT_NPF, "npf" }, \ { SVM_EXIT_AVIC_INCOMPLETE_IPI, "avic_incomplete_ipi" }, \ { SVM_EXIT_AVIC_UNACCELERATED_ACCESS, "avic_unaccelerated_access" }, \ diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 7d396f5fa010..9f1d51384eac 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -191,6 +191,9 @@ module_param(pause_filter_count_shrink, ushort, 0444); static unsigned short pause_filter_count_max = KVM_SVM_DEFAULT_PLE_WINDOW_MAX; module_param(pause_filter_count_max, ushort, 0444); +static unsigned short bus_lock_counter = KVM_SVM_DEFAULT_BUS_LOCK_COUNTER; +module_param(bus_lock_counter, ushort, 0644); + /* * Use nested page tables by default. Note, NPT may get forced off by * svm_hardware_setup() if it's unsupported by hardware or the host kernel. @@ -3231,6 +3234,19 @@ static int invpcid_interception(struct kvm_vcpu *vcpu) return kvm_handle_invpcid(vcpu, type, gva); } +static int bus_lock_exit(struct kvm_vcpu *vcpu) +{ + struct vcpu_svm *svm = to_svm(vcpu); + + vcpu->run->exit_reason = KVM_EXIT_X86_BUS_LOCK; + vcpu->run->flags |= KVM_RUN_X86_BUS_LOCK; + + /* Reload the counter again */ + svm->vmcb->control.bus_lock_counter = bus_lock_counter; + + return 0; +} + static int (*const svm_exit_handlers[])(struct kvm_vcpu *vcpu) = { [SVM_EXIT_READ_CR0] = cr_interception, [SVM_EXIT_READ_CR3] = cr_interception, @@ -3298,6 +3314,7 @@ static int (*const svm_exit_handlers[])(struct kvm_vcpu *vcpu) = { [SVM_EXIT_CR4_WRITE_TRAP] = cr_trap, [SVM_EXIT_CR8_WRITE_TRAP] = cr_trap, [SVM_EXIT_INVPCID] = invpcid_interception, + [SVM_EXIT_BUS_LOCK] = bus_lock_exit, [SVM_EXIT_NPF] = npf_interception, [SVM_EXIT_RSM] = rsm_interception, [SVM_EXIT_AVIC_INCOMPLETE_IPI] = avic_incomplete_ipi_interception, @@ -4356,6 +4373,27 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) set_msr_interception(vcpu, svm->msrpm, MSR_IA32_FLUSH_CMD, 0, !!guest_cpuid_has(vcpu, X86_FEATURE_FLUSH_L1D)); + if (cpu_feature_enabled(X86_FEATURE_BUS_LOCK_THRESHOLD) && + vcpu->kvm->arch.bus_lock_detection_enabled) { + svm_set_intercept(svm, INTERCEPT_BUSLOCK); + + /* + * The CPU decrements the bus lock counter every time a bus lock + * is detected. Once the counter reaches zero a VMEXIT_BUSLOCK + * is generated. A value of zero for bus lock counter means a + * VMEXIT_BUSLOCK at every bus lock detection. + * + * Currently, default value for bus_lock_counter is set to 10. + * So, the VMEXIT_BUSLOCK is generated after every 10 bus locks + * detected. + */ + svm->vmcb->control.bus_lock_counter = bus_lock_counter; + pr_debug("Setting buslock counter to %u\n", bus_lock_counter); + } else { + svm_clr_intercept(svm, INTERCEPT_BUSLOCK); + svm->vmcb->control.bus_lock_counter = 0; + } + if (sev_guest(vcpu->kvm)) sev_vcpu_after_set_cpuid(svm); @@ -5149,6 +5187,11 @@ static __init void svm_set_cpu_caps(void) kvm_cpu_cap_set(X86_FEATURE_SVME_ADDR_CHK); } + if (cpu_feature_enabled(X86_FEATURE_BUS_LOCK_THRESHOLD)) { + pr_info("Bus Lock Threashold supported\n"); + kvm_caps.has_bus_lock_exit = true; + } + /* CPUID 0x80000008 */ if (boot_cpu_has(X86_FEATURE_LS_CFG_SSBD) || boot_cpu_has(X86_FEATURE_AMD_SSBD)) diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h index d80a4c6b5a38..2a77232105da 100644 --- a/arch/x86/kvm/x86.h +++ b/arch/x86/kvm/x86.h @@ -58,6 +58,7 @@ void kvm_spurious_fault(void); #define KVM_VMX_DEFAULT_PLE_WINDOW_MAX UINT_MAX #define KVM_SVM_DEFAULT_PLE_WINDOW_MAX USHRT_MAX #define KVM_SVM_DEFAULT_PLE_WINDOW 3000 +#define KVM_SVM_DEFAULT_BUS_LOCK_COUNTER 10 static inline unsigned int __grow_ple_window(unsigned int val, unsigned int base, unsigned int modifier, unsigned int max) From patchwork Tue Jul 9 17:51:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13728401 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2075.outbound.protection.outlook.com [40.107.223.75]) (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 CCB9012C549; Tue, 9 Jul 2024 17:52:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720547539; cv=fail; b=LV7S+pHp5YEainR2PY1mOGSDi8mxu7Of2WEAknbdXvbY1ojnO171RuKl2dq4jFeNgmCrBco0tD4GKiO26VhBPv4p+qHtmFbCwAZD/Q+Nls4fgW8oLl/TkGJeXPWi3+o5VIvZ6jVDOKviqiBPXio3J4+JxuaBNNtxGwy1jmM6lBk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720547539; c=relaxed/simple; bh=W27sKtaZhUoGHPO1V2va5NFW6HIOaLCOTGHYuAqh+Yg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fkrp06BTySqR6wmuum3QA+wqcSv/gV5G0miNKmzUsQtBsT4lQpyXPm6xvGK43VUBuoYmvFVHUWDZbFUbaab4hm8iBlDevhfhgGZcNDf+l81UYb5LLTdo/nrhM2Qu422Boyn3WIwV+CaFfqeIf0YE2hHH0rF6fXETF3Z25hlpx8U= 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=vi9Yjz8h; arc=fail smtp.client-ip=40.107.223.75 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="vi9Yjz8h" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XJqTZ1gW5uc5+ee95daVzVx6B+vqds5kIh/mFVZ99eTe0CDja+f12Bv6Sbt1nTF5U59MlKEkvX0UD9ySG0vOGwqhS4u1qHVXhzu4M5F7SVLpyVkGu1diLHkOJcHL8va+gGZZBEfcbQt5CUj2uhVWsn4w6zPBie9E3agpOSTS+veA2GX6wrwN7eqED4+2BUYj+CwgvVAwSOoGuEKZLeq76SNZMns1dtTkcLvnI+QJuJSvbigO3ldFkEV7yC38WaBuwn1+suU7g+y2+9Jze1VeiIHCauI0GdZgZTJB/MTV4s+zPW1UkZyYR3TD7ZxsgDGosHExDtF7Rabf5xnyXkiviA== 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=BhR0e6Kbl3PNTEsNI5Yopn+uKUvHQaGRBI+INUyF9lA=; b=lNBexLI+JTt5/vbQTBczH9mKy6zW1px3Z3XydyXazr5GK5d6KN54mfXOzr2f6LPy93MdV1ttT1Ws43fstx57aliZnHNpvZ9zMKyrMWSXa7opAyEfubnPTXbDv6rSQoZb7CWxDaQ1Lj2DIQjsPWRlD4JAtUWwG/p2CdVaNqOsXRAOcAAZS9jrDKtVceWJXIb+vf/q6byvkCNoMSRGZfNlXU4P73ehHwhR+ZSSjQb60uh7pFGVN9vl/QoTYZLJWeTttJE3G4W7iIqUlUyDMeYlpAQbZoKZS7dTf73ohlzL9aopoq5pfzfu8lH8oWHZlsjaI7Fxmn0we9Ik7LuiyIWTYA== 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=BhR0e6Kbl3PNTEsNI5Yopn+uKUvHQaGRBI+INUyF9lA=; b=vi9Yjz8hP227b7F++r1dMZFdyB9wQPckPhYRv4Ee+XyoMKTtfiQ+BvRPrcKZuObBVHEcgwpBu9eVN54aMLIhu+Cl64P724PiLtmkiEqwAPGzsquOmgZTUnsgYgnZbniK58WcFXOMccb7w51n0MuUd+g2Hpcz+hA7FcuJLafdris= Received: from DM6PR10CA0003.namprd10.prod.outlook.com (2603:10b6:5:60::16) by PH8PR12MB7374.namprd12.prod.outlook.com (2603:10b6:510:216::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.36; Tue, 9 Jul 2024 17:52:14 +0000 Received: from DS3PEPF000099DD.namprd04.prod.outlook.com (2603:10b6:5:60:cafe::7b) by DM6PR10CA0003.outlook.office365.com (2603:10b6:5:60::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.36 via Frontend Transport; Tue, 9 Jul 2024 17:52:14 +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 DS3PEPF000099DD.mail.protection.outlook.com (10.167.17.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7762.17 via Frontend Transport; Tue, 9 Jul 2024 17:52:14 +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.39; Tue, 9 Jul 2024 12:52:11 -0500 From: Manali Shukla To: , CC: , , , , , , , , Subject: [RFC PATCH v1 3/4] KVM: x86: nSVM: Implement support for nested Bus Lock Threshold Date: Tue, 9 Jul 2024 17:51:44 +0000 Message-ID: <20240709175145.9986-4-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240709175145.9986-1-manali.shukla@amd.com> References: <20240709175145.9986-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DD:EE_|PH8PR12MB7374:EE_ X-MS-Office365-Filtering-Correlation-Id: a0307e64-050e-4671-fa05-08dca03fdddf X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|36860700013|82310400026; X-Microsoft-Antispam-Message-Info: Q4uDOYVeyzpNx3XsBiXhGrFfv0sskfQFsuMpAiv+GjK72L0VmsIwmQ4x6dQj2lcs6/ewHSvH/vD+ooKW5tBNlXTFZXJDwz5BJxri2A8xqXjwXFAl5yFACrdfnJqESy1SH5S8PmpXgj9q29i2AjI/ph8PrpO9cgqQbU03YgYunTlQ6sMmeXFZKo2wlIFB6ctqrcLKMvUbTlaO9rqVdQiByw+YsG0PL8EqgvFCB9urL7c0e+itTh9x1u4LJ8BlkDGPlZSCLEcFtx2kfD9Q5OeEv+pGgC7nKTHajw/pHqFqDrh7NM5XOZAbCs1lotqD/Js6O6av4O68Ao2SLxghEUzm+5v8qk7ETw6lX5gV3MI6QjwBnzE1vXl58ZlFoa56edhvPXbn8ZtSqAt2BN8GPkZiijM4P2i9H/0Od2MuDOF0E5sAdhBTw5FnW7ap2pvV4VdfX4iqgXqa0zcG6j7aYoggKGR62fJsY6apcEEedyzwD5hVIpNd8WzuqZaGhN2mjPX20l3cL+Lsbb5u/xH07LY1kt25xYiTXli6iV5ztnhNizIc9JNH3yduLxiW5mKDZvCZF/8mC5JOkhEHUXlkOyfYt8jcHY81VcQnL5sTT5/neRxMn0SpGT2XcEVXBayP6Cuxd+zq8g536pojH3ApzzmTrSHfBWbsr8oP9vSxZqw88yh8shLgkJ9jZuiC1PeyLSdFFift9dZUVHUvxiNvl1Ie/HgYiioKz5oDAmymE1uX2qclgmP5hAe4WDL9bljGCND0fT8LXRMNT0VA2j3yYeIzi9YT6twerM/wmZAtakQExpimEVKwJsKlMxpXlXXsR5BTmYKwboMPZXYHqp2hvnPwNDk207aIeeKmHpUsgyfrwmZco+jKglhlQM5jdstCfTZFvob7wvSnmsfnZam60WwHqhxZgpl+sC+9GoEN+kJKobyN2s0SXIGlpcCAle5ChucnHPcTWdcFxswYZLGYrz5MTcwYtCbO6wFxk+1yYS2C1mzakktakjFlaE3cZGV5PGrdeliJiWfo2cjPRrffdx7iL6aqjrpQbZu2IO9h5uy1Jpoqdp9LrMok4kcfxJ/GpfSvcS/nPesek87RMY3WkRhABNWbrkX0W7TKWB1kZiIU+5fV5pWw1E5dWvgpLsjiHJy44qXvuZP36syksd1VRQHcrcJr2IlOnfye7argxujiUuFk1jKPQq6C1qPhLVTv0BMjPqlUfs31atNK6M1Oqep0bLgDBAcn+2qf1LQ6zxVntQAMuenAeVF300eiscbO7U8X3Jy9GnWqyJtu+XWCx3UyvP/wUvGoyMl6phMIiiiZAC2BJqU/isL2DQDXMBm/ISjJNmgVLD66N1HBnbrIt1TVtFOzpp18EwIjmkloCt1P32zyqwRgR6ayO2cjXKldKGAWf70Jc5i+ON7EBlFoz9xamvjawG803/95I08nGOYAxu8m3NBuD673qNHhDnDgOYqI 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:(13230040)(1800799024)(376014)(36860700013)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jul 2024 17:52:14.2469 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a0307e64-050e-4671-fa05-08dca03fdddf 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: DS3PEPF000099DD.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR12MB7374 Expose the Bus Lock Threshold in the guest CPUID and support its functionality in nested guest. Ensure proper restoration and saving of the bus_lock_counter at VM Entry and VM Exit respectively in nested guest scenarios. Case 1: L0 supports buslock exit and L1 does not: use buslock counter from L0 and exits happen to L0 VMM. Case 2: Both L0 and L1 supports buslock exit: use L1 buslock counter value and exits happen to L1 VMM. Signed-off-by: Manali Shukla --- arch/x86/kvm/governed_features.h | 1 + arch/x86/kvm/svm/nested.c | 25 +++++++++++++++++++++++++ arch/x86/kvm/svm/svm.c | 5 +++++ arch/x86/kvm/svm/svm.h | 1 + 4 files changed, 32 insertions(+) diff --git a/arch/x86/kvm/governed_features.h b/arch/x86/kvm/governed_features.h index ad463b1ed4e4..0982eb107f0b 100644 --- a/arch/x86/kvm/governed_features.h +++ b/arch/x86/kvm/governed_features.h @@ -17,6 +17,7 @@ KVM_GOVERNED_X86_FEATURE(PFTHRESHOLD) KVM_GOVERNED_X86_FEATURE(VGIF) KVM_GOVERNED_X86_FEATURE(VNMI) KVM_GOVERNED_X86_FEATURE(LAM) +KVM_GOVERNED_X86_FEATURE(BUS_LOCK_THRESHOLD) #undef KVM_GOVERNED_X86_FEATURE #undef KVM_GOVERNED_FEATURE diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c index 6f704c1037e5..d09434225e4d 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -363,6 +363,7 @@ void __nested_copy_vmcb_control_to_cache(struct kvm_vcpu *vcpu, to->virt_ext = from->virt_ext; to->pause_filter_count = from->pause_filter_count; to->pause_filter_thresh = from->pause_filter_thresh; + to->bus_lock_counter = from->bus_lock_counter; /* Copy asid here because nested_vmcb_check_controls will check it. */ to->asid = from->asid; @@ -758,6 +759,16 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm, } } + /* + * If guest intercepts BUSLOCK, use guest's bus_lock_counter value, + * otherwise use host bus_lock_counter value. + */ + if (guest_can_use(vcpu, X86_FEATURE_BUS_LOCK_THRESHOLD) && + vmcb12_is_intercept(&svm->nested.ctl, INTERCEPT_BUSLOCK)) + vmcb02->control.bus_lock_counter = svm->nested.ctl.bus_lock_counter; + else + vmcb02->control.bus_lock_counter = vmcb01->control.bus_lock_counter; + nested_svm_transition_tlb_flush(vcpu); /* Enter Guest-Mode */ @@ -1035,6 +1046,12 @@ int nested_svm_vmexit(struct vcpu_svm *svm) } + if (guest_can_use(vcpu, X86_FEATURE_BUS_LOCK_THRESHOLD) && + vmcb12_is_intercept(&svm->nested.ctl, INTERCEPT_BUSLOCK)) + vmcb12->control.bus_lock_counter = vmcb02->control.bus_lock_counter; + else + vmcb01->control.bus_lock_counter = vmcb02->control.bus_lock_counter; + nested_svm_copy_common_state(svm->nested.vmcb02.ptr, svm->vmcb01.ptr); svm_switch_vmcb(svm, &svm->vmcb01); @@ -1333,6 +1350,13 @@ static int nested_svm_intercept(struct vcpu_svm *svm) vmexit = NESTED_EXIT_DONE; break; } + case SVM_EXIT_BUS_LOCK: { + if (!(vmcb12_is_intercept(&svm->nested.ctl, INTERCEPT_BUSLOCK))) + vmexit = NESTED_EXIT_HOST; + else + vmexit = NESTED_EXIT_DONE; + break; + } default: { if (vmcb12_is_intercept(&svm->nested.ctl, exit_code)) vmexit = NESTED_EXIT_DONE; @@ -1572,6 +1596,7 @@ static void nested_copy_vmcb_cache_to_control(struct vmcb_control_area *dst, dst->virt_ext = from->virt_ext; dst->pause_filter_count = from->pause_filter_count; dst->pause_filter_thresh = from->pause_filter_thresh; + dst->bus_lock_counter = from->bus_lock_counter; /* 'clean' and 'hv_enlightenments' are not changed by KVM */ } diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 9f1d51384eac..bb2437a7694c 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -4373,6 +4373,8 @@ static void svm_vcpu_after_set_cpuid(struct kvm_vcpu *vcpu) set_msr_interception(vcpu, svm->msrpm, MSR_IA32_FLUSH_CMD, 0, !!guest_cpuid_has(vcpu, X86_FEATURE_FLUSH_L1D)); + kvm_governed_feature_check_and_set(vcpu, X86_FEATURE_BUS_LOCK_THRESHOLD); + if (cpu_feature_enabled(X86_FEATURE_BUS_LOCK_THRESHOLD) && vcpu->kvm->arch.bus_lock_detection_enabled) { svm_set_intercept(svm, INTERCEPT_BUSLOCK); @@ -5183,6 +5185,9 @@ static __init void svm_set_cpu_caps(void) if (vnmi) kvm_cpu_cap_set(X86_FEATURE_VNMI); + if (cpu_feature_enabled(X86_FEATURE_BUS_LOCK_THRESHOLD)) + kvm_cpu_cap_set(X86_FEATURE_BUS_LOCK_THRESHOLD); + /* Nested VM can receive #VMEXIT instead of triggering #GP */ kvm_cpu_cap_set(X86_FEATURE_SVME_ADDR_CHK); } diff --git a/arch/x86/kvm/svm/svm.h b/arch/x86/kvm/svm/svm.h index 8983eabf8f84..f49ea38187ba 100644 --- a/arch/x86/kvm/svm/svm.h +++ b/arch/x86/kvm/svm/svm.h @@ -150,6 +150,7 @@ struct vmcb_ctrl_area_cached { u64 nested_cr3; u64 virt_ext; u32 clean; + u16 bus_lock_counter; union { #if IS_ENABLED(CONFIG_HYPERV) || IS_ENABLED(CONFIG_KVM_HYPERV) struct hv_vmcb_enlightenments hv_enlightenments; From patchwork Tue Jul 9 17:51:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13728402 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2075.outbound.protection.outlook.com [40.107.237.75]) (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 887721494C8; Tue, 9 Jul 2024 17:52:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.75 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720547541; cv=fail; b=IwYbIRCKqGo2LtxSmvnzp61SBcwujz+/4uowo7nxmvNVOzBhbhEcvn+tyM2AomN0be966wJE52Rlq81wGcQ9Nw9GCdXqbsZtZgAcXiLxSuPy2MhU8AQGQC06Hm82ALhWOw4pvXQK+abcZOgtzKtx7qjCXFbChsRvz5BspGi66vg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720547541; c=relaxed/simple; bh=oZ4EpGhqlgAcr2qrzuWKOWT5AkS3NQHCeJOyTV1V8PM=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KgDHtaaBivTMqlV2WmCnuhRTuxjtzjZcXnHrlZbCAG39sH/+o8YSOlljOrf/oktr4Fc5UdggnnAiTNyZAUlI1Zb557KqamFcU/TvH1oj1d64tcpbbRrARXmaUw2GLuzqMuVnEXYyRxpNKzmDD7TrZWcu0ipp0TOC/CypHBA9o8I= 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=oNbvnaMb; arc=fail smtp.client-ip=40.107.237.75 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="oNbvnaMb" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G61JK3H7/LBLR/tKvCWYclIr3pw0KIOkETtG71jB47FGMIdMB/FNNL5USdkS3IE8hNaCy1/NTr3mXnxmAtEaY4VreG20IXsZL27/e6TAM4/sRTRUWKHEMenH704k6Jvoap/FkUhvCC/t1H0jI3h1zf2ySPc1waMMmfRKnnB+tujT8bUErP5w9WeKPBd1TSMWklv5RjQx4vFdUsFSSPh7BK2bn8u09d1T+ozZN2+bcO8ArVbJ3AzAPczYd82DkWtM4EWu/bm0MecZx/xkW4G+mYgpC6jKJUBkZgoq/jjstJIbwtk44gyQ+PCUE9DxZw3lJFyjkfflP+EhA7vRzRkF/w== 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=olyTE//IDtXz7FOr/hFWWjoJ2E4C81hgOzAvsB1G12A=; b=eAqdS4tvC2Z2OHrdbyQHl3JvbSoKE14oiONt7OMhH8nLtbmqy/NWQdZ9lih9+XLNrB3TNmiaYc7yAFk3f2kATWWT0Y2XTTo/bhcq/qXANBF9oPu/i/h9xWMwUg8vKP4cKRYP5QiayROhlKUlC1wCyCp3RCe8HpBzeHs8Eeyf19bbqEhZl1siJKJckm0wS7h9d1H9t/qPh0jQa2BfS9PlAoJmSNC8OZR5u4ukCWLKuSg9ZzYeIBA0TInXBEwpXDoRkYy95CoszLf1dbwjJtOHzNnLOSsDA/UzguJtG6FDgfxuqlWbgJvowfav5fQ3T9eh+uxWdB3D4fYf8oJSE2HqVA== 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=olyTE//IDtXz7FOr/hFWWjoJ2E4C81hgOzAvsB1G12A=; b=oNbvnaMbKh7LADQffc9by/PINohGAAcWgjhOPv0mGxPB3GkvJ2Ru9yJU+t+iUNsYiUAUkRw8DLVYJitkHOrJO0syUqHaPvpgef69hcE+p6Kv0t1WrFjAeSLeXOno+6vGZGTbZWzWtK7n8V6ZqFwzUFhfYjWBxA31iJjmvwyD5dU= Received: from DM6PR10CA0014.namprd10.prod.outlook.com (2603:10b6:5:60::27) by PH7PR12MB8779.namprd12.prod.outlook.com (2603:10b6:510:26b::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.36; Tue, 9 Jul 2024 17:52:15 +0000 Received: from DS3PEPF000099DD.namprd04.prod.outlook.com (2603:10b6:5:60:cafe::35) by DM6PR10CA0014.outlook.office365.com (2603:10b6:5:60::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7741.36 via Frontend Transport; Tue, 9 Jul 2024 17:52:15 +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 DS3PEPF000099DD.mail.protection.outlook.com (10.167.17.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7762.17 via Frontend Transport; Tue, 9 Jul 2024 17:52:15 +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.39; Tue, 9 Jul 2024 12:52:12 -0500 From: Manali Shukla To: , CC: , , , , , , , , Subject: [RFC PATCH v1 4/4] KVM: selftests: Add bus lock exit test Date: Tue, 9 Jul 2024 17:51:45 +0000 Message-ID: <20240709175145.9986-5-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240709175145.9986-1-manali.shukla@amd.com> References: <20240709175145.9986-1-manali.shukla@amd.com> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS3PEPF000099DD:EE_|PH7PR12MB8779:EE_ X-MS-Office365-Filtering-Correlation-Id: 4b6f54ab-cc22-4f72-e01b-08dca03fde67 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|82310400026|36860700013; X-Microsoft-Antispam-Message-Info: +H5S6O+bX5BSvoPbIISw+VizqdiDQmpt/GqlWrhb9thG049YlRA4wfRYloTTRTElneQdeYTpGjLCVg1uv2Y81Dj6GpG7J9vPynKByXsicSZDGRaBE33LxHG0HqubgGAqe5mNDOTvG98wHMu6/XuKU/0GhSrvGgeT97D1V0ilj/RcNhHFOyl/BKtMF6D5iiqfXODLJD0yWvVG6hJIZV8Grd52E41wq7H/mfwK+JxnUkI12le2e79gzMY31M0btRarRiORMN8O8qYCcsJDJ8UoSek2bdsZjEIkHzCke51QiBEnSfufL41qGYxoTUvD/cHUD0IT+uB8NyXn7Y7nWX9Ncua6Cu75bjAABiYfXYw7bZ16hibV6S3MJcP+vz6d2erCPWsqelrBbWp/qTkaLHkocUlxHnBaslvIgm6eApaqa1UAVPRo202nPUHxNA0k96t0qa7+YygSi1ls8Ik2HR7GNme0Yq3szt/TT0GMx2STlwWbwO7ryoWRb93G977vMRGATwyRbDyg4GpIZ2EJrwomlw8f42niIGOSqe702X+Yet8eIneoXycxSdYFntmTcN+vVGsNAqRAo6dahX2bGSt20BUNr7PIWcHAElKeXtHSrLov9/482Pw+dn0aL0XiS3SIIqmR9pQKQ+VMIuQLgKZeqVu8R5iodyzIdSKZleyL9fWkyKqs9e2yxUFLjwO+PXeHYO2P7BFJ4xNFrF+HF3LopBnNGlA3+TJ6j5H9sgZcgfFm7VtD7lI/dKGkqaa30eYyU+vfGbPDZu+tPZxzdnChIhw5NxB9YQ0pN8apTQ32Qjbg5RNb6YdAFDT79+N9gppa5unTXgxF/kKdEQwOzpFzhiH13Xp2jSG2jConv8qRIK6t9THu+Tv/sTLQ4rbwioj6kjqjZxAiyolUpJggz3QZRQrHHweWh5x30MswUw75nwVgvMK1Xax1aLAiebWYyQyNhdEKvs73pWG07PSVTPBfCajuH4PcgmfW5VRsL0uhAo2+Uk/39v2UK13YJmG8j4bIruVY2bHIPOMm1wbVtTnGimlMF0D6tlL2SldPoMYV8+beuqgX7Vj6q5qT1FpoepdAINMTM0WRxIQ/QDx5z6iN7G7lixvRScsURN1VvL/1T9Ztf13/EFb+KalWZD9YCwQ9idl4iQItdiSpxFc6F7+tuPOqgbNMCrlOxyPP65pkFnOD2EFOY5272Wr0gaymTmxXi1wQP7vUsQGk99VSMRSeGqaxlsQsgdpPX5e/h4wSUvzLzMrVnUdN9nscxWml3FErYZYQxQ8PsnGDzMYjsoHbD8Y0wf6TEbAsLeSDUVlGVNvTV6mtLmU51Y9VAfGFErldy5fgYVJNWkLuVId5wXM7vwV6Km9Zoqvpm1BURYOS/n/t3kfJdLPmG0DZd5Fu6ZvC+Sdtc5rAsdzuxh511ilWyvnNQ8hmegs03QJxGfdpNIEY09YppLF1bl5rFWKHpMFP 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:(13230040)(1800799024)(376014)(82310400026)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Jul 2024 17:52:15.1688 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4b6f54ab-cc22-4f72-e01b-08dca03fde67 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: DS3PEPF000099DD.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB8779 From: Nikunj A Dadhania Malicious guests can cause bus locks to degrade the performance of a system. The Bus Lock Threshold feature is beneficial for hypervisors aiming to restrict the ability of the guests to perform excessive bus locks and slow down the system for all the tenants. Add a test case to verify the Bus Lock Threshold feature for SVM. [Manali: - The KVM_CAP_X86_BUS_LOCK_EXIT capability is not enabled while vcpus are created, changed the VM and vCPU creation logic to resolve the mentioned issue. - Added nested guest test case for bus lock exit. - massage commit message. - misc cleanups. ] Signed-off-by: Nikunj A Dadhania Co-developed-by: Manali Shukla Signed-off-by: Manali Shukla --- tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/x86_64/svm_buslock_test.c | 114 ++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86_64/svm_buslock_test.c diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index ce8ff8e8ce3a..711ec195e386 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -94,6 +94,7 @@ 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/vmx_preemption_timer_test +TEST_GEN_PROGS_x86_64 += x86_64/svm_buslock_test TEST_GEN_PROGS_x86_64 += x86_64/svm_vmcall_test TEST_GEN_PROGS_x86_64 += x86_64/svm_int_ctl_test TEST_GEN_PROGS_x86_64 += x86_64/svm_nested_shutdown_test diff --git a/tools/testing/selftests/kvm/x86_64/svm_buslock_test.c b/tools/testing/selftests/kvm/x86_64/svm_buslock_test.c new file mode 100644 index 000000000000..dcb595999046 --- /dev/null +++ b/tools/testing/selftests/kvm/x86_64/svm_buslock_test.c @@ -0,0 +1,114 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * svm_buslock_test + * + * Copyright (C) 2024 Advanced Micro Devices, Inc. + * + * SVM testing: Buslock exit + */ + +#include "test_util.h" +#include "kvm_util.h" +#include "processor.h" +#include "svm_util.h" + +#define NO_ITERATIONS 100 +#define __cacheline_aligned __aligned(128) + +struct buslock_test { + unsigned char pad[126]; + atomic_long_t val; +} __packed; + +struct buslock_test test __cacheline_aligned; + +static __always_inline void buslock_atomic_add(int i, atomic_long_t *v) +{ + asm volatile(LOCK_PREFIX "addl %1,%0" + : "+m" (v->counter) + : "ir" (i) : "memory"); +} + +static void buslock_add(void) +{ + /* + * Increment a cache unaligned variable atomically. + * This should generate a bus lock exit. + */ + for (int i = 0; i < NO_ITERATIONS; i++) + buslock_atomic_add(2, &test.val); +} + +static void l2_guest_code(void) +{ + buslock_add(); + GUEST_DONE(); +} + +static void l1_guest_code(struct svm_test_data *svm) +{ + #define L2_GUEST_STACK_SIZE 64 + unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE]; + struct vmcb *vmcb = svm->vmcb; + + generic_svm_setup(svm, l2_guest_code, + &l2_guest_stack[L2_GUEST_STACK_SIZE]); + run_guest(vmcb, svm->vmcb_gpa); + GUEST_ASSERT(vmcb->control.exit_code == SVM_EXIT_VMMCALL); + GUEST_DONE(); +} + +static void guest_code(struct svm_test_data *svm) +{ + buslock_add(); + + if (this_cpu_has(X86_FEATURE_SVM)) + l1_guest_code(svm); +} + +int main(int argc, char *argv[]) +{ + struct kvm_vcpu *vcpu; + struct kvm_run *run; + struct kvm_vm *vm; + vm_vaddr_t svm_gva; + + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM)); + TEST_REQUIRE(kvm_has_cap(KVM_CAP_X86_BUS_LOCK_EXIT)); + + vm = vm_create(1); + vm_enable_cap(vm, KVM_CAP_X86_BUS_LOCK_EXIT, KVM_BUS_LOCK_DETECTION_EXIT); + vcpu = vm_vcpu_add(vm, 0, guest_code); + + vcpu_alloc_svm(vm, &svm_gva); + vcpu_args_set(vcpu, 1, svm_gva); + + run = vcpu->run; + + for (;;) { + struct ucall uc; + + vcpu_run(vcpu); + + if (run->exit_reason == KVM_EXIT_X86_BUS_LOCK) { + run->flags &= ~KVM_RUN_X86_BUS_LOCK; + run->exit_reason = 0; + continue; + } + + switch (get_ucall(vcpu, &uc)) { + case UCALL_ABORT: + REPORT_GUEST_ASSERT(uc); + /* NOT REACHED */ + case UCALL_SYNC: + break; + case UCALL_DONE: + goto done; + default: + TEST_FAIL("Unknown ucall 0x%lx.", uc.cmd); + } + } +done: + kvm_vm_free(vm); + return 0; +}