From patchwork Tue Oct 1 06:34:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13817516 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (mail-mw2nam12on2084.outbound.protection.outlook.com [40.107.244.84]) (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 0A7D929CFE; Tue, 1 Oct 2024 06:34:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.244.84 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764477; cv=fail; b=XyNqty9lhSTdGD23CNtW65s3MtpoLxMffahahq6MVOh6N2qg9U+v0/7ggSRa7efDVnT/PbX09CShM6fx+maHMPZMKoEMu1iH+rw5Jd7XyToJ5kVCWsKE78GkOwNtouFo5I2XNGP5ZcUH8lebwFFhoeONzm4iZmgssPg2eosSlq0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764477; c=relaxed/simple; bh=W7rWJQnNG/rsS6Q0gW46trLmZg+EAZunfhxSdK16mMU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=gs17wMsUHwcQXmp1/OBON5mEBDNFq8tA8mjiz41Wjgjck0LU2in4mih/EjGntQpCwwPTcap2JJRifyRuJVJBBpr0M5ZRutiaPy1+51HMX+sPo8K6+ACJAIpatjz0CwT27KuBGTcSD7fdjJEHEihFq0wJ/0zPAy4HbSkjAVXhUKo= 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=i5HOa8gh; arc=fail smtp.client-ip=40.107.244.84 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="i5HOa8gh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gkdROzfNriUGwea2ybZ8zLJY1l5l50lgDvYtsl0RmfkuOJXFtqjEW03j+0PnzT6W/vDbH1qvE5Cw7clndkZlJNu2CvENi4qZdqKe7+49vyNRw8o5DuXpBCT05CDt8wyDQJH4Dp1CUxF6OhgteXu9jZ7MEhNJFm2rE8UXC6GlGWrJTUkLNIM5nw0Lex3mooAsfn/MihPXnImCW4j9wc8cQMH3akZ4tLDJi1b8MA0QbBPuzAtYLL/OQvbW3gCcZZMNHcxm7hqAYwNWcLrNauxeHqIH3Uat3xLi3pUcS+bXsDSsQSy5+jsdeNbO5dUpelSKq/2haA/X+oJQcQUVvkSV+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=LqUjXN6tSicSc+0iHOqozmpfKWr1l09tGvQZPfzw0Dg=; b=Kd0atH0enefAozUMt4V1/U5lZ3WDzuGjJtEACN5J6Wu7HR/VCqFRuahdfhcubMY/6PBmDWzDlxS/33kYLI+z932paah44AGwkQ3swHIvwYru7X/p4KGlHsiIwRawJMompu2buLrR2C+tS8jW20L1onf7F3twY/yat6QVhr0f/IIvhFCwmJiVtWfLKdOUoYttV4Q1FYB2/g23XYz0ZBe9Qyk/lQbiAIQBCt+gVZ4aWbT5eiZojI8yitd5einMuqXiWwi7dg9NgMLJ+LZ5S/0eWX17BN95qAkQpX/2FiekhLvT/fHrpR/pCySugCW6SvyFbGa10Iauj0ObYSYLvyouJg== 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=LqUjXN6tSicSc+0iHOqozmpfKWr1l09tGvQZPfzw0Dg=; b=i5HOa8ghilDhYJBXSsDhUX/QfVmAmZ8iMr7S3mc8kWtrhkUAB26fEWsHIbkXeH9C+7bKdXX5o01AlyJO+dlirSwMaB/wPRXIgPqX4Iyl+OzuunB8y9gADjTL4JkEP/BltZgGZkTBtT0M9O2DowXa6ucDzuh+k/5iDx/ATyCinZM= Received: from PH7PR03CA0026.namprd03.prod.outlook.com (2603:10b6:510:339::11) by IA1PR12MB8465.namprd12.prod.outlook.com (2603:10b6:208:457::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27; Tue, 1 Oct 2024 06:34:32 +0000 Received: from SN1PEPF000397B5.namprd05.prod.outlook.com (2603:10b6:510:339:cafe::21) by PH7PR03CA0026.outlook.office365.com (2603:10b6:510:339::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27 via Frontend Transport; Tue, 1 Oct 2024 06:34:32 +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 SN1PEPF000397B5.mail.protection.outlook.com (10.167.248.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Tue, 1 Oct 2024 06:34:31 +0000 Received: from chalupa-d178host.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, 1 Oct 2024 01:34:30 -0500 From: Manali Shukla To: , CC: , , , , , , , , Subject: [RFC PATCH v2 1/5] x86/cpu: Add virt tag in /proc/cpuinfo Date: Tue, 1 Oct 2024 06:34:09 +0000 Message-ID: <20241001063413.687787-2-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241001063413.687787-1-manali.shukla@amd.com> References: <20241001063413.687787-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: SN1PEPF000397B5:EE_|IA1PR12MB8465:EE_ X-MS-Office365-Filtering-Correlation-Id: 3461547f-6a6b-4e6b-3ca8-08dce1e31bd3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|36860700013|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: g1ieJUrhKaBfzcQrJER+Wns/XFQpd3LsB0fJ+3llI+jOvs9vN8GWAfzgSwCxlCKlxUiKNoJa4uhRUF5FAWoNpgJDIBSMMu8rF+J2eA2lQqx8uY5A8N88unTrg24foWbusiqYCrEEf134XGQZRRLWLe6koOeCYjecjT+Fj113zc4jQlqSIiltCW/4AmX+3GlP4LFo+9yGbAJwgvr1MBk1LqQZd9EjKaP4pEnbdHKIhAvDT0LloF3qARitdiPmbln8qVvzeE8t4A+REWQFiGFoUb8J1GeN5vR43GsJ16i1JiKYf5Watap4GWLKtDrKKhmQaX6gofxm/CxK68KKT8DcxNmjXT/vPv3zRezSULlNKqYuLmURNkI/C2I5hlHr+pC5miD41bq1K2uZM7Fq6zCCEvzBKoB1Da8N3w0spglVUfe3NVUD3Dc2Y4NqYqZsw7jLLw0Le09GrO8sWylDlufS9TqmVwzx2IyFoWkNKvXA9p1IyoEAWOtVt+R/ODeDgvFKsKvN1MB/hKUBiidO/yS9fiKUE3ahsKHiKZx9qnVYdwW65H5zibu9U50YfHN0YF/X5GuP3u6a53tJE1QjOFiP4dp4Eevsopg730p2yWKFX6Dos2EPykbIxda2sGfLPXAG/EltTvJl/7gs4PrHljOeOVho0nmYuGA4UPJj5AYIkaPgFGx7hfQ7YI6VhfbjOqdopEbdBcSftK3v0BfFKM0wKWIllX3MsjQOCCRtGTZHC6zOVJp3R4KApqHKDMOU2lKcJ4vWLIN0+z+Wg4oovOqofbulkWcUBno3VlFChHa7Jx3YNMBUlyAM/Sy6Z/JURZtlU3Z0aMQT840v1McIWo1po+L/mwnykaYgzjirJEGP2b9O7ApxTVuus086LeiDYbJVHWkQtMBj4blvPQ6cDGWQy5iFTFLj6yvjgkUAQaa/JwMfO6om75nXQDQWeOXDucLHONWlTPJH9DvBW+OL+qX7JqONJYK/PJN3mWrg3MwW8yEE+rsj+D3+NMIh+kauRyV1nA8FuQLRPF4sRJP7pLToPRnJN2785T+tkCMzC58TqBqo5v/pX5GIp3CFARuNQvOsJJN790/XrsWrRufrQEbDFHbwACuhdEH0/Wbu7x/ltU8Ets4s/El6YR9Jm8d1ny5zHxyJsVDRCV9Oef4OnCraFAE0ji8/x1rPCdYa7aKSSG1I9Xmz21TFbNQEzWCKE1ASy71JvCWOZPJnK8P48rHyF6sXAwnIM1imiIQVbkfXTdNraYsiLIF0oiu7cal9TzSAI+5MTdne5qmm7ObtQa18pmHYBMOZcTpn0gIpBhWituGTU5GFx79iTK0j6qaHMz0ckXf/5XgjtTh/ry0E8nHDqgBaAKxWVQuEbLw/EBEaVGFFypYjyODgx5IJtKjC+X4M 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)(376014)(36860700013)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 06:34:31.9484 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3461547f-6a6b-4e6b-3ca8-08dce1e31bd3 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: SN1PEPF000397B5.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA1PR12MB8465 Add support for generating Virtualization feature names in capflags.c and use the resulting x86_virt_flags to print the virt flags in /proc/cpuinfo. Currently, it is difficult to check if a feature is supported in _KVM_. Manually querying cpuid to know whether the feature is supported or not can be quite tedious at times. Print the features supported in KVM hypervisor in a dedicated "virt" line instead of adding them to the common "flags". To do so, define flags which are needed to be added in a dedicated virt line in /proc/cpuinfo with prefix X86_VIRT_FEATURE_. Signed-off-by: Manali Shukla --- arch/x86/include/asm/cpufeature.h | 1 + arch/x86/kernel/cpu/mkcapflags.sh | 3 +++ arch/x86/kernel/cpu/proc.c | 5 +++++ 3 files changed, 9 insertions(+) diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h index 0b9611da6c53..74c52bfd8cf2 100644 --- a/arch/x86/include/asm/cpufeature.h +++ b/arch/x86/include/asm/cpufeature.h @@ -41,6 +41,7 @@ enum cpuid_leafs #define x86_cap_flag_num(flag) ((flag) >> 5), ((flag) & 31) extern const char * const x86_cap_flags[NCAPINTS*32]; +extern const char * const x86_virt_flags[NCAPINTS*32]; extern const char * const x86_power_flags[32]; #define X86_CAP_FMT "%s" #define x86_cap_flag(flag) x86_cap_flags[flag] diff --git a/arch/x86/kernel/cpu/mkcapflags.sh b/arch/x86/kernel/cpu/mkcapflags.sh index 68f537347466..3671c7892c56 100644 --- a/arch/x86/kernel/cpu/mkcapflags.sh +++ b/arch/x86/kernel/cpu/mkcapflags.sh @@ -62,6 +62,9 @@ trap 'rm "$OUT"' EXIT dump_array "x86_bug_flags" "NBUGINTS*32" "X86_BUG_" "NCAPINTS*32" $2 echo "" + dump_array "x86_virt_flags" "NCAPINTS*32" "X86_VIRT_FEATURE_" "" $2 + echo "" + echo "#ifdef CONFIG_X86_VMX_FEATURE_NAMES" echo "#ifndef _ASM_X86_VMXFEATURES_H" echo "#include " diff --git a/arch/x86/kernel/cpu/proc.c b/arch/x86/kernel/cpu/proc.c index e65fae63660e..3068b0a110e4 100644 --- a/arch/x86/kernel/cpu/proc.c +++ b/arch/x86/kernel/cpu/proc.c @@ -103,6 +103,11 @@ static int show_cpuinfo(struct seq_file *m, void *v) if (cpu_has(c, i) && x86_cap_flags[i] != NULL) seq_printf(m, " %s", x86_cap_flags[i]); + seq_puts(m, "\nvirt\t\t:"); + for (i = 0; i < 32*NCAPINTS; i++) + if (cpu_has(c, i) && x86_virt_flags[i] != NULL) + seq_printf(m, " %s", x86_virt_flags[i]); + #ifdef CONFIG_X86_VMX_FEATURE_NAMES if (cpu_has(c, X86_FEATURE_VMX) && c->vmx_capability[0]) { seq_puts(m, "\nvmx flags\t:"); From patchwork Tue Oct 1 06:34:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13817517 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2046.outbound.protection.outlook.com [40.107.237.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 81DCC191F8D; Tue, 1 Oct 2024 06:34:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764479; cv=fail; b=t72Vvh6YhWa/KvGVuOY6oeJKdMxFZLEJiTasYSXIBrLXGpoe+wOOQdPXm3hPUNxIAee1XoKD3+QNSAlWl3TOyvRA02c74hRduTZyfZZhCHMgD8IdhRKCPGO2mQmnL+cQ1Rsf6Ry88c0zQGLU8i3d8Bwyr6JM/LB8MTx3UYf5vaE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764479; c=relaxed/simple; bh=2cLSKYtsJqDsTiaCoSnL0iBpF4qf49xcBWyCMhG6EZA=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=So2mcHG/MDzONhz+nANnIssUSSboYE12hSHX4OO6qJy1rdrCmlK8TkAnJ3KQs4hlqRFeMEbrN9dkEkzdthAteLTEnD0QdL8bO4bFwymYLWrgd2TaRFhmz3DgDVvsB0Pc2KByjliYw0gXi4A6Foltobl/bFVyi23JNubjWc3YTDg= 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=Isb4fkXf; arc=fail smtp.client-ip=40.107.237.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="Isb4fkXf" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=c1z8Y00oVx3wf2U5TThOzj4dxLhJZws+i0KlFYkuOzIxjx02dgBXNZbcosDclFdd3QsVOgvTpslMMeklUG90Rcq5Lbg8dQH90GHY9MFW7lZ14/TtJvPO1/u/mZn/Z6IdRaU/VeKBlz56ZlFELM/y7tQS85r5bM2MoW7C7+avQ07PzHNU+CY61xtljjZJRK66nt5iPTbOc9w2YxTAIffoaCyUges835oWOKJsatNYMmq7yivGqxdSzedBwngZJxnd+aF44SgSlvwcBgB5GZe+cqIV4Kl+MhFPZuOM82Xy/l0Otg+2Gv9VnO0SQrVRnVzplMCHPbMCyMx6OJKSXX/qPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=XyraQc5xYEIcZtxALqC+LJI71Na9wW1pEYFQJt2zxRI=; b=ExFyjhdCwtbBQZ70qHiSAVbxSBbXx/u69HT+r4IYZtBb8LaZ9oh4TmJJFfBuVqk8F/njcqHhFEOCoqmJ5eex53WzEwVNfhn5ZF6XXP2ZCDgqTBC0X3FMJXOQXDZTI6CCRl9f0nRBbT3JZ3/CrzmMfzhBAxmxY5Ph90S42QimdgH1daxLMzNWPX1jsPVmjiFBABPU8U3qaCN2VII76GSBqPW63RBNLwHPes79bnW6gfJLFuRsQJOm8wUC2SV93J675h9B3+vtX888SilIOBsOn+T3ZJo5VizK4jDa0beMv5JJf0FjnK+ZSS6gLkx5dVVsgfxdz1EUWWi7WChMjdPFsg== 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=XyraQc5xYEIcZtxALqC+LJI71Na9wW1pEYFQJt2zxRI=; b=Isb4fkXf/ZtDgUmkaPKAtb2kB4frgfzMXWiJalVObvIoP/6uGn0lpo+n7f6BpX+QmBdQD8ef2Wi4QIC+UJShsEVyyrEYOcIGVkEmTa44IwD/BQIMRpHq+KmKDGkjOQCvxqqapfJvQlEtxX5COYrcJKjEWmysx8luQT2/15Kjsuw= Received: from PH7PR03CA0009.namprd03.prod.outlook.com (2603:10b6:510:339::33) by PH7PR12MB5712.namprd12.prod.outlook.com (2603:10b6:510:1e3::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.26; Tue, 1 Oct 2024 06:34:33 +0000 Received: from SN1PEPF000397B5.namprd05.prod.outlook.com (2603:10b6:510:339:cafe::4) by PH7PR03CA0009.outlook.office365.com (2603:10b6:510:339::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.15 via Frontend Transport; Tue, 1 Oct 2024 06:34:33 +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 SN1PEPF000397B5.mail.protection.outlook.com (10.167.248.59) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Tue, 1 Oct 2024 06:34:33 +0000 Received: from chalupa-d178host.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, 1 Oct 2024 01:34:31 -0500 From: Manali Shukla To: , CC: , , , , , , , , Subject: [RFC PATCH v2 2/5] x86/cpufeatures: Add CPUID feature bit for the Bus Lock Threshold Date: Tue, 1 Oct 2024 06:34:10 +0000 Message-ID: <20241001063413.687787-3-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241001063413.687787-1-manali.shukla@amd.com> References: <20241001063413.687787-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: SN1PEPF000397B5:EE_|PH7PR12MB5712:EE_ X-MS-Office365-Filtering-Correlation-Id: 82fb2aac-6ef1-418b-e5be-08dce1e31c7e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|82310400026|1800799024|376014|36860700013; X-Microsoft-Antispam-Message-Info: qXVJLuk3N79PiHt37FqqDF3ENf/f/fZYb1DyUbUuVBq3QstE+4qhIaFAcSTD8LkMq+nI9Gaay/opH7+zROfhHbXV4f+3QyuZKPzBs/ruF6tI3Ch7uNGb6vTZznjjDWQE9amX3yB6iwY6BD/OeR0TAylP9ROe4Y1czjDbjcgNju3cVKoc3bXUnywfiVMu3BUIwh8C+IRvalROoHs8+ub+ajgWzWkZ6KXoVeJ+c8frCkU9U+u6+11cGwg3tcf/uGnkk860UHXSYJU8GzJSJOQuswXf3X5Xa09Qn3tFziQmTiCWwBzL3fkWHBYjlx8GUJz0YJ3kwoqnBYxOc+eEg944eBMUwxWtcJXHoerQZ7D6B3d9DwHu5z8ejtZHV5XfzKg4ss0lNOUqaXhmZIcu/CzIGDrAQw6GZMcD8PAlOtDuTKBWC+E9pTubxCLHrkEUPwu5QbivSG+j2OULogVYasYYLw+3mF5FPrsKbEhCCTz+QuKTUbcQ/ODUsdTbTjsNSu3kUKWTAFUVS0l+nCp5tYcP4VSWScHP8ahaOhnzug2qc5+5wZYo6YBuBurNHcl+4Pn19MNXYMp/wS4bRapVrMGojWD6cDJAa5aTMPkKVp4F4aNxEN3Rz8tYwusIc7bb1dGvq64DG3v9tiGtoe/zcaS16RRRCS99g4TGiUjLN2amfb1z9bspv6zD0ylglrhOKIBi40cENnZ08Eph65dhTPPnA6oJno+P/Bp+ebXAaSCWbQFjMP29AmJ/fqvMRdtGKV/OTdVmQ8gd530+t2kpehZgZcjKfb5WOZd72g+Hp0fCwh5D0SE0YrQAl0g8l9BuD4YJhRaJljbuxGM3/tn3V+idN0cHojlq8F+eTMR941VD17sQz9xlxst3muyLqREBv9AYopUfPThM1yKmyBrPUOtg1Yxcvslor6J9XlGuR6HOT6leGMDMA3NDu0pGNGfs+Slf7j/5NOKwpLkHoIIrXo7xkWh07eYqXDbfXa35pRJsJZ87pY0Hc3Mbl7E0Ce4GDaPQSfXMkrIyEt4HTwkdwX+ORO54k8krGuTTb0Lmbioxf1NQfA7hNpr4eYRUOiau/GR2Cm4XpN48iG+Uz9Hi+CRxEBB0ympXPZlTr7Cyb9PLChUyiysAnezSARcddfFvT9KyolQxcH6iAVaU81ISK9TWewJDVq9BxzbaRLEydwMN8faTgibBzWkX3s3m1BrUeIqAigep24qiXlQdJlLr6B8RXGJRxXfyGEk2sLEMHJCfVCZtI0FLvSc/VRBjZvgToZh4VCUqWR+ZsMOVntIZrve6vrBXjCahHHxeg5oFA36HhzK7LERSeCMy85qTLPAnEUITheH7o/p+5m5xgyQ0IkIAbpnKiPsLATzCqmMK6qA7UQh2RlS8rsVGdGBSCkPZTzyvLtWJxyZgb5APtvfp1GgRjkG+lloaL5HSPT3BjoZOCCgkUHmGOpiB+9bGOzoE5Ftd 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)(82310400026)(1800799024)(376014)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 06:34:33.0890 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 82fb2aac-6ef1-418b-e5be-08dce1e31c7e 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: SN1PEPF000397B5.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5712 Misbehaving guests can cause bus locks to degrade the performance of the system. The Bus Lock Threshold feature can be used to address this issue by providing capability to the hypervisor to limit guest's ability to generate bus lock, thereby preventing system slowdown due to performance penalities. When the Bus Lock Threshold feature is enabled, the processor checks the bus lock threshold count before executing the buslock and decides whether to trigger bus lock exit or not. The value of the bus lock threshold count '0' generates bus lock exits, and if the value is greater than '0', the bus lock is executed successfully and the bus lock threshold count is decremented. 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(+) diff --git a/arch/x86/include/asm/cpufeatures.h b/arch/x86/include/asm/cpufeatures.h index dd4682857c12..20f389ee0079 100644 --- a/arch/x86/include/asm/cpufeatures.h +++ b/arch/x86/include/asm/cpufeatures.h @@ -382,6 +382,7 @@ #define X86_FEATURE_V_SPEC_CTRL (15*32+20) /* "v_spec_ctrl" Virtual SPEC_CTRL */ #define X86_FEATURE_VNMI (15*32+25) /* "vnmi" Virtual NMI */ #define X86_FEATURE_SVME_ADDR_CHK (15*32+28) /* SVME addr check */ +#define X86_VIRT_FEATURE_BUS_LOCK_THRESHOLD (15*32+29) /* "buslock" Bus lock threshold */ /* Intel-defined CPU features, CPUID level 0x00000007:0 (ECX), word 16 */ #define X86_FEATURE_AVX512VBMI (16*32+ 1) /* "avx512vbmi" AVX512 Vector Bit Manipulation instructions*/ From patchwork Tue Oct 1 06:34:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13817518 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2080.outbound.protection.outlook.com [40.107.223.80]) (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 BAB8E1BC062; Tue, 1 Oct 2024 06:34:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.80 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764480; cv=fail; b=uFC/S8KsTS6T6ASewKkl9vGQm4Cle5tuVfm9rfTCl6pz6jc5Oq5jxEkeBGnEt55xzDFyRqGyfGWh3+4SwE3AE+Utuor9bXkWvxB56hRP2HiNZqgZ9GS5Vx5s1h3DEv6Te/eFDwTUMnq/SKY8Gljc9+wqyJ7OA3CuWoCII9vdkmU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764480; c=relaxed/simple; bh=51eVIjZ6U4T8+hdsbo3YZ86O0EeOyqK1kEvscyKllac=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=KDP80wWUEZXUrD//uGilyziX5VqEb+d7+qrqMBYCfUIbgmKbySzsSyPn0avdldWIX8uBJPO5j/mmqhk10+b4IJrlGyFbiF+V7XOeTy0fZlDdQDIjHoYkEb500ZrJiFk7TLKBKrB6NnfeoOC2GfT5HdJciTVDGBBUV5mxochXdzY= 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=o9m437G6; arc=fail smtp.client-ip=40.107.223.80 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="o9m437G6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=S1kv1cdkaxMvJT0/KchDYEoI1tiETbnG+5NCZsZFkbZvAUN7t6GJum7XKtPpLa+OOS1BA4dp630I9wpHhF4nOFAu9pjcgcQUBLA+gIEvM3wtJaf6coIezVOpgqyINeYa4x1cROLzQDZ9FFxMhFKGewibAnjiJqTt8OWFdms0BrxugSoRCnYr3k0gCmxKarBynRBJtSR1JbZD/YPDILlQMUceQbQftTqVZQXD7QvVakVjzCVLwtjsB+v/qH+f+PPeeFDiA+qk1kBu2m+sRrYfBdfknTToHn8ILQfm36ddtYrFfcsaK+g06HnzWRxefXotp3jw2w1ByKDbyzRjyeAINQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=zopjtBaXTboCoPoC/xMJCWHVyuSxfna49JW/FOUPmtU=; b=Mbq+Zt0FhNuGMn2DxtjF28w67VG1lUnUS/h9cvvERkLKl3ciAPS0ouNNuQRWnrCSJiO9pKwmNTfOuE/bWAKpt0pqDECr0oXR7Kn3+eYNenkkqJkhEFaB3dqVteDBlmjLrFI8njauZ6/DG/Bs2KYR7fBnNZwx0T0xH6FJAMjOOFu7MFujTYD2Ulcjf12bFU9MtbuvMbv72oTZs9cXEVtnuFB2GbWKhS2DbWUYLdsIhuwHkQAKrb4axBbkTCFMDwHmI6HyzHraOjHP826SJLjbGmhpQx7DhGU3nSn+btEBEkFlHjoBPjRNRFEicjOaipir9Ry28oncc9Y+kayiCKj3Tw== 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=zopjtBaXTboCoPoC/xMJCWHVyuSxfna49JW/FOUPmtU=; b=o9m437G6U7kQVFD6TJSPGKHKvlfWlX/eST6169e6IqFo+BzR/GFAEUhsGXxhffXw9UMcYo/d+wfooJqXeSU+Ge822FjVlw8f+9qqoWxb6Ek8KZfGHJMwr/PWXtQXuPNwsGBEH7Bfn3+RNu2EyVlzc7/ZQV1pO5Fd714mdnAINpI= Received: from SN6PR04CA0101.namprd04.prod.outlook.com (2603:10b6:805:f2::42) by DM4PR12MB7646.namprd12.prod.outlook.com (2603:10b6:8:106::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.15; Tue, 1 Oct 2024 06:34:34 +0000 Received: from SN1PEPF000397AE.namprd05.prod.outlook.com (2603:10b6:805:f2:cafe::88) by SN6PR04CA0101.outlook.office365.com (2603:10b6:805:f2::42) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27 via Frontend Transport; Tue, 1 Oct 2024 06:34: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=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by SN1PEPF000397AE.mail.protection.outlook.com (10.167.248.52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Tue, 1 Oct 2024 06:34:33 +0000 Received: from chalupa-d178host.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, 1 Oct 2024 01:34:32 -0500 From: Manali Shukla To: , CC: , , , , , , , , Subject: [RFC PATCH v2 3/5] KVM: SVM: Enable Bus lock threshold exit Date: Tue, 1 Oct 2024 06:34:11 +0000 Message-ID: <20241001063413.687787-4-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241001063413.687787-1-manali.shukla@amd.com> References: <20241001063413.687787-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: SN1PEPF000397AE:EE_|DM4PR12MB7646:EE_ X-MS-Office365-Filtering-Correlation-Id: 3415e48e-4b55-4d06-7a28-08dce1e31d02 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|36860700013|1800799024|376014|82310400026; X-Microsoft-Antispam-Message-Info: Z7HlOGQQesLDr5YW6fOFv4otVk6o1Op9Gvl1u8k/vSHLXlsz3K0SevSUVyfb/xkzlDnVCHT9bcHLLbYDp+BzcF+Y2WRVn3NImoaCuVHE5iU5+B8HeQFYnxX1fmpQ4TW/GB/I6kxM5Sm1hbegx7bACIDjOL90VWDXTzW3sf0PEx+tXSIn3Nl7Sy65cx8pC9F+pfMzhXNLdCzfIJ5okJjcZ4U2G1qVjfwKDop2hdjlTYaLbFrQ53guwHQKGC8mkxR2F0fSU8uGvq/xeDxhbpV/p1+7dwy20zrg4vqDIISJJkgcbPBgZnNe4mfbh/SIXpuurwYGspAvuXukQdpueqBb1e0g1tzV6CYUexy/E3d8XHT100I/ys7WuowuuvIHjimXTkd57/+yZCcaYG/urdTdMf0K5o2t0cSziW98fKPIUaNtiYt+4fPEaO7f/9aKOydd0gfNS+Mx4BxAQ30XlQNS6gIudCJZhyv39ientT/q2NM+zs467mwQ6vRCVEMFkiZ90qmoTQyguv0xRhF5+ebiTDqAOVK9RJ/pMAEL5DjpDPjIyGrlsSiw2iXHPCaIE6Kg/7brB1o61uIWnDnEJBNht0Pvh/ys/KAEJ8jElJ+xeGD9AKSi0XEjQQT2Eet1TlHK4khIdE5kHSMnRt8lC0bV4TE3HYjEAFKGGCyhDspjZyr831USmJMVTlNVsx1I4bFGNLpp+IADB3O/Z1DLkZ9zgIh/Jvk8Czw14mqSqHeaiYirXYYLjJln6XRUjLOnqzD4HjOMqqwk3iq2Jq4lKgeuq8jWKuw4iBu5luDtWh8uS+dB3qPpEIThqx/VWhyUhIha5t3/DQmG16KHFf82HNcNWRPM9zAo8fLr/uKixxf7nlD1v1pIAu0IpnM+tFH55UBPEGyymcUfmQOZGmRS3UCkhpLx8fq+izvdlUPbcF5KsPFqgWbB5Q+9DnDPyKefDg8LspWTw9ioL+esqNfLutv82SXr+G0ZGu3eLg4Gwfk7aY1uK/ZffrwUUanjuZY0u9QxsH8hT6jU1mQ0TYzaJLAsdxjBF7MoKu8vOpmf4xnxtPkl8y3UD0UNh06/lFocmd8dOYdqJOKpuCMaQTgdC9MGh/E4bWt5ohTnxb2RAKEhxrDHSzFW2/cCW0wQ4Wx+iOP7qIjWJ7JzepuRPDF0Onqhc61PPECXX88MZaEOwSP1qZqzBhXeCFNpkfbdqVp63kxjr8Q4slxQlhQxNKurhj8rDcJyNw76+ZKbWnrVxpTIdxQGlsNdUHLTV9aJVLOr6TA8uK1yydo75mDyAUhoLnSMiJSb8EGlF9DxyNm38Y6vgWRORgtAg6xpNlah4liWgfOoPBdjdiMzWtjycLswmXkYey4127wNZsgNfhmhDGU3qzNsVENE2A19XpMwvXjMlJjAfoQg9cVqBN2EpVYKCMukUU0LRSh6NwSHZ7aaRCmTHwAxskXOUQqEQI2bAI3S0PPl 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)(36860700013)(1800799024)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 06:34:33.9357 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3415e48e-4b55-4d06-7a28-08dce1e31d02 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: SN1PEPF000397AE.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB7646 From: Nikunj A Dadhania Virtual machines can exploit bus locks to degrade the performance of the system. Bus locks can be caused by Non-WB(Write back) and misaligned locked RMW (Read-modify-Write) instructions and require systemwide synchronization among all processors which can result into significant performance penalties. To address this issue, the Bus Lock Threshold feature is introduced to provide ability to hypervisor to restrict guests' capability of initiating mulitple buslocks, thereby preventing system slowdowns. Support for the buslock threshold is indicated via CPUID function 0x8000000A_EDX[29]. On the processors that support the Bus Lock Threshold feature, the VMCB provides a Bus Lock Threshold enable bit and an unsigned 16-bit Bus Lock threshold count. VMCB intercept bit VMCB Offset Bits Function 14h 5 Intercept bus lock operations (occurs after guest instruction finishes) Bus lock threshold count VMCB Offset Bits Function 120h 15:0 Bus lock counter When a VMRUN instruction is executed, the bus lock threshold count is loaded into an internal count register. Before the processor executes a bus lock in the guest, it checks the value of this register: - If the value is greater than '0', the processor successfully executes the bus lock and decrements the count. - If the value is '0', the bus lock is not executed, and a #VMEXIT to the VMM is taken. The bus lock threshold #VMEXIT is reported to the VMM with the VMEXIT code A5h, SVM_EXIT_BUS_LOCK. When SVM_EXIT_BUS_LOCK occurs, the value of the current Bus Lock Threshold counter, which is '0', is loaded into the VMCB. This value must be reset to a default greater than '0' in bus_lock_exit handler in hypervisor, because the behavior of SVM_EXIT_BUS_LOCK is fault like, so the bus lock exit to userspace happens with the RIP pointing to the offending instruction (which generates buslocks). So, if the value of the Bus Lock Threshold counter remains '0', the guest continuously exits with SVM_EXIT_BUS_LOCK. The generated SVM_EXIT_BUS_LOCK in kvm will exit to user space by setting the KVM_RUN_BUS_LOCK flag in vcpu->run->flags, indicating to the user space that a bus lock has been detected in the guest. Use the already available KVM capability KVM_CAP_X86_BUS_LOCK_EXIT to enable the feature. This feature is disabled by default, it can be enabled explicitly from user space. 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 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/nested.c | 12 ++++++++++++ arch/x86/kvm/svm/svm.c | 29 +++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/svm.h b/arch/x86/include/asm/svm.h index f0dea3750ca9..bad9723f40e1 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 1814b413fd57..abf6aed88cee 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 @@ -224,6 +225,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/nested.c b/arch/x86/kvm/svm/nested.c index 6f704c1037e5..670092d31f77 100644 --- a/arch/x86/kvm/svm/nested.c +++ b/arch/x86/kvm/svm/nested.c @@ -669,6 +669,12 @@ static void nested_vmcb02_prepare_control(struct vcpu_svm *svm, vmcb02->control.iopm_base_pa = vmcb01->control.iopm_base_pa; vmcb02->control.msrpm_base_pa = vmcb01->control.msrpm_base_pa; + /* + * The bus lock threshold count should keep running across nested + * transitions. + * Copied the buslock threshold count from vmcb01 to vmcb02. + */ + vmcb02->control.bus_lock_counter = vmcb01->control.bus_lock_counter; /* Done at vmrun: asid. */ /* Also overwritten later if necessary. */ @@ -1035,6 +1041,12 @@ int nested_svm_vmexit(struct vcpu_svm *svm) } + /* + * The bus lock threshold count should keep running across nested + * transitions. + * Copied the buslock threshold count from vmcb02 to vmcb01. + */ + 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); diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c index 5ab2c92c7331..41c773a40f99 100644 --- a/arch/x86/kvm/svm/svm.c +++ b/arch/x86/kvm/svm/svm.c @@ -1372,6 +1372,11 @@ static void init_vmcb(struct kvm_vcpu *vcpu) svm->vmcb->control.int_ctl |= V_GIF_ENABLE_MASK; } + if (vcpu->kvm->arch.bus_lock_detection_enabled) + svm_set_intercept(svm, INTERCEPT_BUSLOCK); + else + svm_clr_intercept(svm, INTERCEPT_BUSLOCK); + if (sev_guest(vcpu->kvm)) sev_init_vmcb(svm); @@ -3283,6 +3288,24 @@ 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 with value greater than '0'. + * The bus lock exit on SVM happens with RIP pointing to the guilty + * instruction. So, reloading the value of bus_lock_counter to '0' + * results into generating continuous bus lock exits. + */ + svm->vmcb->control.bus_lock_counter = 1; + + return 0; +} + static int (*const svm_exit_handlers[])(struct kvm_vcpu *vcpu) = { [SVM_EXIT_READ_CR0] = cr_interception, [SVM_EXIT_READ_CR3] = cr_interception, @@ -3350,6 +3373,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, @@ -5212,6 +5236,11 @@ static __init void svm_set_cpu_caps(void) kvm_cpu_cap_set(X86_FEATURE_SVME_ADDR_CHK); } + if (cpu_feature_enabled(X86_VIRT_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)) From patchwork Tue Oct 1 06:34:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13817520 Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2045.outbound.protection.outlook.com [40.107.243.45]) (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 09C0F1BC9ED; Tue, 1 Oct 2024 06:34:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.45 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764481; cv=fail; b=TcBNUmLgpS+zjS0wWMM1yF4u/TOYZHUl6AgYPjg/ul5U3zWAWn5MyDC4kXoXEkzX3m+pT4HLsr74q51xVsu7pDnSm9GEb0kZ2JLowPqj584KPZpUwcev1FiMLi6bEFqUG8wkrYuUcLjDpOm49nqwgogUB0gFXYwsvCxaEVaeDCY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764481; c=relaxed/simple; bh=LHv6DngdlFAm2g5UCreA7fLqwd3lcbclWDeiI3qVX68=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=JKLBfEvy2OevWnW7PgE5sVYfatEGgsJLXyxL+Ij8o8gYJcZXCcUwjKP+SpVFmbkbDvz24XeE8zR31UR13APuzHBFX8SVtvCpflI/m1Lv4U46f+BT5mx/WTov8PkErteusKEglM+uVQWybG9NNpwUNVy2fVcXH2NJFVnDJSS+3jw= 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=3fifdbLO; arc=fail smtp.client-ip=40.107.243.45 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="3fifdbLO" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wSPPAsVGjmaEH/t0cBWMBznQMIT0nfUsroX5OoA1MfmZhBdnkMSY+9yqFJEuDrPXzRJ6rQ/RtVUnlu2+ELngVxZwDTth0tljXnka8xBR2CKSM5opdKqYgwwhavpvWmGhSiEs0XheAqePY1v/daic54FVZvVyubjilLgrKdzUhYB+TmHbTy+VpE4SSs17646+fJvxRxTcUF1X3xaaPS+p9ewVOCvI85JpJyMj233tZdfJ+L1Wy0pjCocxfbXlaUr9Q8U9/HwDTAAN7QXBXQ19Xgg/BD5J9MdWSDFVH8QEUcjFyO3CzmtRkopLb/wa5jNNiMYYkkruw64UxOLrGWPduQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=dqzw9XKzch5uPZWKVULBHcAN/idajHGyVUzFJki0+SM=; b=LxKMGFY4rv7frmK6OghJ/oOnNGneYYSots1MKwwA5Ab2p9HqScaytUyegblnW3ObwfEon5Xhpwp0of0tN6XCKFUx6c+RPK5EAkmsgeWgWNS3n9Xcf7CCHB6SkedDmJXgGwiBcDKTKfRBGKc3Nq07yu/AvOiNEDUP2WTU/q+rPmkX8Iw5DcRkydw0Pd+bjsQqtIrIccaujxr71LC86HI1Zk20IbLyRNPkjMD9Hn0RJa+n05EnJl1IZH3Ca9ZCgEWSxGvBozXXvNXjn6Lxd60H1UlAbOleWA/BADNv3rN/4TwGsg6F47L5Gd+RPXOajAbLXHiPdY9YzeNHNnZ8NThAdQ== 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=dqzw9XKzch5uPZWKVULBHcAN/idajHGyVUzFJki0+SM=; b=3fifdbLO/nvo2hDBXVm/4gjQlR+9UpFZuIqP/uFpcxuS8knmG22e2igw8iaaOx90DbbsDX321DRQqftgVmVQ0ijRWFVzizYoesrEiNAG+pl9TTdCG3b9EKD8lcytPXqHap/UdhvYjwGWnxrWGCfjklS6kAE8dcC/QGrOdrkYayk= Received: from PH8PR07CA0028.namprd07.prod.outlook.com (2603:10b6:510:2cf::23) by SA1PR12MB8164.namprd12.prod.outlook.com (2603:10b6:806:338::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.26; Tue, 1 Oct 2024 06:34:37 +0000 Received: from SN1PEPF000397B2.namprd05.prod.outlook.com (2603:10b6:510:2cf:cafe::d3) by PH8PR07CA0028.outlook.office365.com (2603:10b6:510:2cf::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27 via Frontend Transport; Tue, 1 Oct 2024 06:34:36 +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 SN1PEPF000397B2.mail.protection.outlook.com (10.167.248.56) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Tue, 1 Oct 2024 06:34:36 +0000 Received: from chalupa-d178host.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, 1 Oct 2024 01:34:33 -0500 From: Manali Shukla To: , CC: , , , , , , , , Subject: [RFC PATCH v2 4/5] KVM: X86: Add documentation about behavioral difference for KVM_EXIT_BUS_LOCK Date: Tue, 1 Oct 2024 06:34:12 +0000 Message-ID: <20241001063413.687787-5-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241001063413.687787-1-manali.shukla@amd.com> References: <20241001063413.687787-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: SN1PEPF000397B2:EE_|SA1PR12MB8164:EE_ X-MS-Office365-Filtering-Correlation-Id: b4a6bac9-57c8-4edd-d031-08dce1e31e90 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|30052699003|82310400026|376014|1800799024|36860700013; X-Microsoft-Antispam-Message-Info: gHB0i0ohA6p9ZieP/PUfWtQZM49z0br6aLO8sUhjlMLHAcYe78gfaSCKmun2gRqO6jTlOYcMtJLwbRj9iHyM/RHt3UgLaRoDYRxogQ9fed2VHHJiVYyIFtmhXUM5unc2lLMhG6JdJe6NkWAUdZfpv75yLUxPeCT7USPgNLMVUInHXXJmo7ejg/qKNtPqBCBow4UU6r+CQA0Mp9l3W+KLU3WQsQnD0S4RfvhAr9tgolVaxCFr6XS1uOrWlptkfxd+F8ZQJGxWKN1DZmH7nIdRGFa1VQhai9SnH0y0ebLiLzPPBOKe6Bxv9rXDfDYizsfikIJWnRV+lOxs1Sbzw3ubJIGzZnV/a0ZaVrqs5FpznosoxDoXojyzu2M56/51zVppj2S0BgMV7S/dR3fRoLoh9J5r0GfOamKf/ARSFs82X905dQR6wQyNs8OATY+EDnKbH5Nsyn/TmXX4eYIe0Q39SqRwHtIsq7dt66tNJCM78fEwDf8k65ZWiYC1DKzCHURpnmjNupsQIbbgYlR4rlf5hx9djVw/ALi3sY8a/Ejj60xEJlU4pUIzRjA8SyBGEVlcX7zTh7envmYaxFC0iEDzBc9zNsO++tNSKCfdA273hxxAn65HxtUyPgV/9lcrjcMwjbDleNiOklT08J0PDvdsSevawZT8c9HOktwAa7HzCeF0Avj55TTjClTVRM9AZq/+rC0fifdhy5qM+foK7bLgIMRncdyidrPQ41pzTCKMoYxabCFiZ4D0IOBLCrHE0CHwFh4XJSd03yPeewzvzD6OcFKFdVEU7s86qt099lXtXUaQJiYfRzKKQk0cigCPYy32Tm4gePHzVUVfWSQgJ0vjBQ4VTwqOv/DB+UPOwdwqyIjhhfTfY490LB1BaA6lYORMKTOkx6rfcMVnPD6k+AgVmMQGePiZqdvMSjxQ1w/0tNE3hoqrr8h23S4wwi2V3FSx0l6n6wMEvI5VYvIUiXN1TFNm65ZUo3SBESEeSNrbsfCdMQ/NLMuU1MFXjcgKchE5JJ+EaEqLyjAj2cSvhR2aBmP8c9841xG/yo0FQYk7CC8rfWUCQbPSEnYn6SMprtHGKmsk+JO0T1fL5vLZb6GXmc0UfZ/6dhKzgTsPgbsonOZnmX9u1QsYe5Vur/c9cIP0GT7cLVs2eoniVtKN1sQvXvLlKw7dz2vajK9D+iXppX0RvvFn9BU3ug0bjX5ID5EpjS6QLSkEhCYpeKq2lUxPPJmMqtf3oMPp4/Gi5RcO1QglnpQo2ZG0iABCYpVFeYLux4PPF6Jdnn40mVaUEGViznvXeatGARu0T5hHSUx3w1K6TL3jp5C0DqqROMeLSt9OklUh/F5ehXKCfAgWB4uS99TrTzBUDhbAF5dJvPFb75LxFfeK3owHY96irZOQrrvBQgVVwdmmCaJgh1D3j5yIAsFaOUEnFlzzTbthYtLWRaqP9FfUWsgcKNaBbQScz0fs 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)(30052699003)(82310400026)(376014)(1800799024)(36860700013);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 06:34:36.5463 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b4a6bac9-57c8-4edd-d031-08dce1e31e90 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: SN1PEPF000397B2.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8164 Add a note about behavioral difference for KVM_EXIT_X86_BUS_LOCK between AMD CPUs and Intel CPUs in KVM_CAP_X86_BUS_LOCK_EXIT capability documentation. Signed-off-by: Manali Shukla --- Documentation/virt/kvm/api.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index b3be87489108..536010e1df1d 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -7869,6 +7869,11 @@ Note! Detected bus locks may be coincident with other exits to userspace, i.e. KVM_RUN_X86_BUS_LOCK should be checked regardless of the primary exit reason if userspace wants to take action on all detected bus locks. +Note! In KVM on AMD CPUs, the bus lock exit to user space occurs with RIP +pointing at the offending instruction. In contrast, in KVM on Intel CPUs, the +RIP points to the instruction right after the guilty one after the bus lock +exit to user space. + 7.23 KVM_CAP_PPC_DAWR1 ---------------------- From patchwork Tue Oct 1 06:34:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manali Shukla X-Patchwork-Id: 13817521 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2085.outbound.protection.outlook.com [40.107.237.85]) (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 E14C21BD504; Tue, 1 Oct 2024 06:34:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.237.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764484; cv=fail; b=laZffNukiqFyH4oSpPc4gK8oZuMJzS14TfbShJRdWTE/BZVRg1BvfuS98x/3hhhTOqEQhEA+rgNOHN35iKoEp/gtLAsfq4GMRNGwHGAxD2G6gh8pm7nO0RhATXddksRvrMVDJufVssKmcQauKT48ttIJ27LCkMyEF4fsPjgpAKg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727764484; c=relaxed/simple; bh=bGCIAq0XNODp4VvlaTSFyrtLZRV4LehTY8Dagx8n8pE=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DVkZJKs4zMtLPZ2tJmRgromXbJ8Lc90S/uH4w60GLIH5ZXSQqjJfTJDCYAVvrZ2zi2gJ3+gRI0pjK5Q2tIebz8JCeF6SFl+F47E0ajFl++orYIePb/Mc+077Ieru0s5f68Lh/knqdbecBmPOdQgjsJlemoqhBVHyAaVoWHXxzuM= 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=S0NNkrrS; arc=fail smtp.client-ip=40.107.237.85 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="S0NNkrrS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ZmXyEBXaHoW1fRRY52HAXBpXIds5S9ty/riHvW1vmrWo+ZwV51CaK8bzW2bMl4ER73d827/wAzPeFjEzem4o8Q+5j0PcpMWm3a4v01Cbl2RJpalFJp+iSLUWsju8q/kF9WFZZh9tlNd8lfFa72rLR/x69pr/RxKR2qSKXdqk+XNMejiQv5Qr+DD9rmykXMg915iHaMGHer1aC3hnpLKLvYjBpUufzGWFw+/iYEb7J7bypS8FWZoWaWxxdEUZUaOYRpTtA0j9nYAbB/nV1p2yifv1jqTBv9fgVU+O5R5w4eoU984oi7nvNvuYS6IQWBVPKgSYrL45nFC4dcCQ0eb2Pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=4bneuj8dJUYnpYJ/crtKf1QdMoIS+NDfkqTcIZ4q7js=; b=wtXJDj06YAjv+E5T1kjFxmxti5FKhmoh5q8vKCU/7/YZ5hel/vOhDSYRl9YrfAxO45IMmre6n8bwJLnjze86y1Edg+lwLW4VRcXYn4404EKeHC3McOm6KSbniSHSrY11hPMGgx3gOWILeYpa/9tAZBVRjGrcLGbdtQxH6wZGcX1OB6VsL1FySE68xW85AL2RoufCDGw/BIcvbNHh6evKFCfpob6sfyoKE0DHT4p93c+lwT+dcwx68nGPFKshE5SSFh1Azu3+hJme9+APlwI1O3XiwBCr+1mvxQiWTZsmINL0INoOgTGsw71E5RywB9kBkiOg8yt+4DaJrJlHoUXFIg== 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=4bneuj8dJUYnpYJ/crtKf1QdMoIS+NDfkqTcIZ4q7js=; b=S0NNkrrSdcXnY7uLPBgjnigj6Sfs5Oz/HbJiJts7Tc+OE+fIzh/NG2fS57j/DONXJPplRNIh4ytaJZYXGDclQeXFtmvTdm/Ozn0OYB4RUeYvdJ/Lnp7Lnmp+xY77P2SrIfkwpXMmI3qie8I10BGv+zHzendjUnMHrIZtY9XkYLk= Received: from PH8PR07CA0045.namprd07.prod.outlook.com (2603:10b6:510:2cf::14) by DS7PR12MB5912.namprd12.prod.outlook.com (2603:10b6:8:7d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.15; Tue, 1 Oct 2024 06:34:38 +0000 Received: from SN1PEPF000397B2.namprd05.prod.outlook.com (2603:10b6:510:2cf:cafe::ad) by PH8PR07CA0045.outlook.office365.com (2603:10b6:510:2cf::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.27 via Frontend Transport; Tue, 1 Oct 2024 06:34:37 +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 SN1PEPF000397B2.mail.protection.outlook.com (10.167.248.56) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8026.11 via Frontend Transport; Tue, 1 Oct 2024 06:34:37 +0000 Received: from chalupa-d178host.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, 1 Oct 2024 01:34:34 -0500 From: Manali Shukla To: , CC: , , , , , , , , Subject: [RFC PATCH v2 5/5] KVM: selftests: Add bus lock exit test Date: Tue, 1 Oct 2024 06:34:13 +0000 Message-ID: <20241001063413.687787-6-manali.shukla@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241001063413.687787-1-manali.shukla@amd.com> References: <20241001063413.687787-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: SN1PEPF000397B2:EE_|DS7PR12MB5912:EE_ X-MS-Office365-Filtering-Correlation-Id: d909b733-701e-492b-1853-08dce1e31f1b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: DmJHrqq6jOZHIcLHj7VAcKQEPVaUWOs9i3WSi60RDcIaToAMI966tljg12yMY01uPphqsK4AqFgFyGk3CoFj6EHWmT0+MfbZJh+MPY5/hvVjuzhzVjgTSkrABfKTY9EiSZohKxQfNKzUK5q3h3oE5GvmHuHMYTGfJECCop/B1Ibb/uLh12VjHchGD90fY491PNxhHg/q8cT9j74f5s0C6ENp20l5EdUrfmIKC47c0zF4eRJ6hTWRzyPDGGf9bzod0CyjAjVOu4eG3+fC6Y5vH14ba1SLL7fu+rS3MVXbAokRyT3vhn/ufr69O/ZFMsj5+sgxvlM5HLgM/ANEyWbaQv3rtj00jVUEvYH3QwAysvDPIwJrMDhrgP5QgAerCL4BI6EI02ue4bxzmbWbAWQzMYrShJd15PNd1hdyXlNeIgSvfj6jCMCoXPe+FNtrHLoKfCumqH6hi4zua76qzmX5g8CfWcomNfI1KQpXXd7yQir6XhGnYutDWleVuyUTj5i0OXtnKLqskwg1UxHyIQNcUYlYw40XD8n+Q8nd4J1bnMJMqot0Y6zilrIFS/aEOIASDOCrIvhWE2hyvMkbe489shnNpNy5nnE8EgD5Y1yE76oTlU1Bg/039IO4NMUthBkXOuSFKnZJEs5UjRBsPXgsfWiM52JkD0feXL1hwe711BTS2vPw1DQBm9StvmMk/3bwj90yAboby6uA92OeucSt9mHC+WC+Cfdi3xwd9e1gj+0Gij/qUnHXzSIc9rvE5o4bwEM5f181vEoAXBpCs1hRD6PblHvaR3Rai5Cpa2bmNW2jE7nDIf8IYG+RUjX7eGdHx85Mnb0lPv7/aRNc3q4sAvpv7ZKc0rYm+pNnzFCQjTvhUqRp1FmzEjcA1Fo9ud5JKbQFv5kATVvHeeqr+dld4u+TZOevmxP+txzTB65f0h0Jdgrpj8SPIQL5saqW7uTDEwHgKJVE66h2MRK3vEM4q9xOX789RARhS4+DChGfrT6Qgf1WC9gOTHjYKpewjiMa/X/IJwYUh5waWaW2CyoxsmMJ8t1JdqyAtV0E978HC91n7VN46ytU50adBq524Y930HaTmEmAybVvQOKzJS8ZccIC445O5u78BTBywRJcLPPaMxiUPSY8Kxb6JTSfoi9J7HLjU6Kda7PxaqeG/D8EkDwqV0ySqpC33Noeoz/3l5avX6xt1YYpBMtwyvoR2VuE1CHOEfZFPNjbA9ggOI8nDyuci5DVOYYC1tUz4JPlAoddzg987uwsz87SsCA3BXyBZ6lz2gJHOsDsFZX50qDGO00/Of1W6MO3aS/caF/4TDEQsjVLkd1bHt4MpMAvleN39ci5vLejuAzDeaRGjpg7cIafZqjvOz/DM/vs6eZ/c/NKzrH5OqnaKjZkLJdids2DSDjRiY9UggR7zCC87X4mdArJ5ysTG90KQ/xHoo4Ti7HcebJTUi0y3dA0XT3G21sP 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)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Oct 2024 06:34:37.4525 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d909b733-701e-492b-1853-08dce1e31f1b 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: SN1PEPF000397B2.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB5912 From: Nikunj A Dadhania Add a test case to verify the Bus Lock exit feature The main thing that the selftest verifies is that when a Buslock is generated in the guest context, the KVM_EXIT_X86_BUS_LOCK is triggered for SVM or VMX when the KVM capability KVM_CAP_X86_BUS_LOCK_EXIT is enabled. This test case also verifies the Bus Lock exit in nested scenario. 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/kvm_buslock_test.c | 130 ++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86_64/kvm_buslock_test.c diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index 0c4b254ab56b..fd7b43fd2a8b 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -81,6 +81,7 @@ TEST_GEN_PROGS_x86_64 += x86_64/hyperv_svm_test TEST_GEN_PROGS_x86_64 += x86_64/hyperv_tlb_flush TEST_GEN_PROGS_x86_64 += x86_64/kvm_clock_test TEST_GEN_PROGS_x86_64 += x86_64/kvm_pv_test +TEST_GEN_PROGS_x86_64 += x86_64/kvm_buslock_test TEST_GEN_PROGS_x86_64 += x86_64/monitor_mwait_test TEST_GEN_PROGS_x86_64 += x86_64/nested_exceptions_test TEST_GEN_PROGS_x86_64 += x86_64/platform_info_test diff --git a/tools/testing/selftests/kvm/x86_64/kvm_buslock_test.c b/tools/testing/selftests/kvm/x86_64/kvm_buslock_test.c new file mode 100644 index 000000000000..82693520485c --- /dev/null +++ b/tools/testing/selftests/kvm/x86_64/kvm_buslock_test.c @@ -0,0 +1,130 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2024 Advanced Micro Devices, Inc. + */ + +#include "test_util.h" +#include "kvm_util.h" +#include "processor.h" +#include "svm_util.h" +#include "vmx.h" + +#define NR_ITERATIONS 100 +#define L2_GUEST_STACK_SIZE 64 + +struct buslock_test { + unsigned char pad[PAGE_SIZE - 2]; + atomic_long_t val; +} __packed; + +struct buslock_test test __aligned(PAGE_SIZE); + +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 page unaligned variable atomically. + * This should generate a bus lock exit. + */ + for (int i = 0; i < NR_ITERATIONS; i++) + buslock_atomic_add(2, &test.val); +} + +static void l2_guest_code(void) +{ + buslock_add(); + GUEST_DONE(); +} + +static void l1_svm_code(struct svm_test_data *svm) +{ + 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 l1_vmx_code(struct vmx_pages *vmx) +{ + unsigned long l2_guest_stack[L2_GUEST_STACK_SIZE]; + + GUEST_ASSERT_EQ(prepare_for_vmx_operation(vmx), true); + GUEST_ASSERT_EQ(load_vmcs(vmx), true); + + prepare_vmcs(vmx, NULL, &l2_guest_stack[L2_GUEST_STACK_SIZE]); + + GUEST_ASSERT(!vmwrite(GUEST_RIP, (u64)l2_guest_code)); + GUEST_ASSERT(!vmlaunch()); + + GUEST_ASSERT_EQ(vmreadz(VM_EXIT_REASON), EXIT_REASON_VMCALL); + GUEST_DONE(); +} + +static void guest_code(void *test_data) +{ + buslock_add(); + + if (this_cpu_has(X86_FEATURE_SVM)) + l1_svm_code(test_data); + else + l1_vmx_code(test_data); +} + +int main(int argc, char *argv[]) +{ + struct kvm_vcpu *vcpu; + struct kvm_run *run; + struct kvm_vm *vm; + vm_vaddr_t nested_test_data_gva; + + TEST_REQUIRE(kvm_cpu_has(X86_FEATURE_SVM) || kvm_cpu_has(X86_FEATURE_VMX)); + 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); + + if (kvm_cpu_has(X86_FEATURE_SVM)) + vcpu_alloc_svm(vm, &nested_test_data_gva); + else + vcpu_alloc_vmx(vm, &nested_test_data_gva); + + vcpu_args_set(vcpu, 1, nested_test_data_gva); + + run = vcpu->run; + + for (;;) { + struct ucall uc; + + vcpu_run(vcpu); + + if (run->exit_reason == KVM_EXIT_IO) { + switch (get_ucall(vcpu, &uc)) { + case UCALL_ABORT: + REPORT_GUEST_ASSERT(uc); + /* NOT REACHED */ + case UCALL_SYNC: + continue; + case UCALL_DONE: + goto done; + default: + TEST_FAIL("Unknown ucall 0x%lx.", uc.cmd); + } + } + + TEST_ASSERT_KVM_EXIT_REASON(vcpu, KVM_EXIT_X86_BUS_LOCK); + } +done: + kvm_vm_free(vm); + return 0; +}