From patchwork Thu Jan 23 22:00:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Pratik R. Sampat" X-Patchwork-Id: 13948670 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2089.outbound.protection.outlook.com [40.107.96.89]) (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 2C8951CDFB9; Thu, 23 Jan 2025 22:01:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.89 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737669708; cv=fail; b=s5YrF6S2gI51jrUrQK2woI1xfgq1aQOq2ffrnvjrF6xPSakkmmYcjeMCbtM+Tk651YYbcak17TNym2NL9enZX1WYCOxxGBQCS63DZATvXoK1uQyojH0wJmQ+r9zja98qkUSyHXMC5z8Zhcu6R+6AaATUH/E4n/IFY8GHd0E6dQI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1737669708; c=relaxed/simple; bh=3LvNXHDGSKJYnI3Y15fb8Fx1X1WqrVf4TxbHOSbrPV8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=TCshAGIzc1wV2GJk1cldqIImbxl9Ta1aO3+1g93NMVeD4dW+2c/ieVZMxhKAIFmME+mcjNKBjeBSKQMxegYZKs9UJ/Pm4bpXGCzIj47eDFk1VqzcuiAPOFf+StNLM2vniL3FJ9OQhyMA2cPC3unVZseXXcAoaSzBKrL1tma7sb0= 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=ym7h/uDh; arc=fail smtp.client-ip=40.107.96.89 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="ym7h/uDh" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CAsJk6Sm426dcMCr1bOBXHzlF/2YGde+1WnoFf9KUSOcPFOFP4KKhGbAqbrsQc6iwN0Ua626RnmhP41XLdVoKiwUCZ0yTfTe86OXZp8eHZ0njRK2QMoUCKA5diZOqa29HUVGZeUWRZENIz2wePhHQcF5ZR/P7ZUcporugul3FXqTnxqghXBNEqfTctZqAbJkH/NJ0dEwI3tfBKrGXoLz0ChwuhF46cME3XwOX43fxjoQTcIztd5fZ+hEaPooc8Moh0FZ7fGFLR7CIIqT6BdDi2DYL2xxX5OY50/rNqQllO+jBEwuhdXXuTo592lidKhu7FMDXlsHmT9f7hWphRfhYg== 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=qqFz9y8T+D9y9DwlJUeY2mHF1w0bWZrXG4FpTuLg/hw=; b=kFzFhbBGnoZrEMSe3i/nzw+k7BNCmThHkGI4NytGIRKeds8Z3JNkd5ll4RmT1M47PCtw+s/ZXtFdFMmn0ifRD1Dw5nrPvSSuavOinQhYiyfTuJMxuUnmi+74kSqLx/sbqhvw7kHnYVQlKjvZ+6RBlfLRRV9uEwJYreDgJaOCqiiuuY3bpUcPy/KL/K7Ld0EmUY3j7G89Ca/inrOQI5z973cvwQ1UP4V8EQWpgfsVLhEEJOPdT7++OIu/fqOeR2oEN8bs5QdwNvR2gI5s6hbBjYZFkJzz0RmHdl8QgMCTm253IDfbOVV06Z0ovtO5HP1GDkYgCirQrhZuahD2RofVpQ== 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=qqFz9y8T+D9y9DwlJUeY2mHF1w0bWZrXG4FpTuLg/hw=; b=ym7h/uDhO67YRJB1TOYAf1ZFYQBYEmAxPE1Tb69BVcwIUoXEshtmyFEJPpYygWEjqp696TveG7iNp8s0gX/2WiFH257y2cbHfn04TBU9xduTy0FbIOPQgnfHuIqagXrbuMEMNg1ninK8lOSbTjBbZym9N/JdwNs649RW+cmj/vQ= Received: from SJ0PR03CA0090.namprd03.prod.outlook.com (2603:10b6:a03:331::35) by BY1PR12MB8446.namprd12.prod.outlook.com (2603:10b6:a03:52d::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8377.19; Thu, 23 Jan 2025 22:01:43 +0000 Received: from CO1PEPF000042A9.namprd03.prod.outlook.com (2603:10b6:a03:331:cafe::5f) by SJ0PR03CA0090.outlook.office365.com (2603:10b6:a03:331::35) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8356.22 via Frontend Transport; Thu, 23 Jan 2025 22:01:42 +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 CO1PEPF000042A9.mail.protection.outlook.com (10.167.243.38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8377.8 via Frontend Transport; Thu, 23 Jan 2025 22:01:42 +0000 Received: from sampat-dell.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; Thu, 23 Jan 2025 16:01:40 -0600 From: "Pratik R. Sampat" To: , , , , CC: , , , , , , , , , , , , , Subject: [PATCH v5 3/9] KVM: selftests: SEV-SNP test for KVM_SEV_INIT2 Date: Thu, 23 Jan 2025 16:00:54 -0600 Message-ID: <20250123220100.339867-4-prsampat@amd.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250123220100.339867-1-prsampat@amd.com> References: <20250123220100.339867-1-prsampat@amd.com> Precedence: bulk X-Mailing-List: linux-kselftest@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: CO1PEPF000042A9:EE_|BY1PR12MB8446:EE_ X-MS-Office365-Filtering-Correlation-Id: ca8bf5da-0ea1-4bf8-3b87-08dd3bf98543 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|36860700013|1800799024|82310400026; X-Microsoft-Antispam-Message-Info: s9JlLh+TWZ3sEJEAnCszzw4HaFTQSLZZ75rYTlTasBnV81IP7TqmSVywVwa2sFilZIfTVzHHoxJ3TCKKZ7GUh48wanJoi2dMoQkbZoxrtXWXpMTUw/OaMcIObNNTkIKXCXkITmbwqL3/U0z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4XMA2yHmQO5sTtFWvmFQyuw/SYBQtPbvxJxu4WWdY0RD4WnkNysHdP5gi4ewPSlGkb0YcmZcW8sVs7oTL27zyyeeuUhtZOJcdgC/kZHk52h4V+IpeAZ7X2Nmbclw5h7KnMKCNMq5/f8JFZr6ElyXrZ/buuzblLRELdjPXzSNu0Bkc+DrtigNcQ3us+m8wEceNouZfe7SVa8VaMMZkzGBtrFXCeK/oFOJRHO2F+FMKEY8O6L3kcXxvXioHbgWT1OgKgZBsAU8v8u8ok2bRro/z3H1qKMONu/Ps= 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)(7416014)(376014)(36860700013)(1800799024)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Jan 2025 22:01:42.3587 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ca8bf5da-0ea1-4bf8-3b87-08dd3bf98543 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: CO1PEPF000042A9.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY1PR12MB8446 Add the X86_FEATURE_SNP CPU feature to the architectural definition for the SEV-SNP VM type to exercise the KVM_SEV_INIT2 call. Ensure that the SNP test is skipped in scenarios where CPUID supports it but KVM does not, preventing reporting of failure in such cases. Signed-off-by: Pratik R. Sampat --- tools/testing/selftests/kvm/include/x86/processor.h | 1 + tools/testing/selftests/kvm/x86/sev_init2_tests.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/tools/testing/selftests/kvm/include/x86/processor.h b/tools/testing/selftests/kvm/include/x86/processor.h index d60da8966772..1e05e610bb06 100644 --- a/tools/testing/selftests/kvm/include/x86/processor.h +++ b/tools/testing/selftests/kvm/include/x86/processor.h @@ -199,6 +199,7 @@ struct kvm_x86_cpu_feature { #define X86_FEATURE_VGIF KVM_X86_CPU_FEATURE(0x8000000A, 0, EDX, 16) #define X86_FEATURE_SEV KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 1) #define X86_FEATURE_SEV_ES KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 3) +#define X86_FEATURE_SNP KVM_X86_CPU_FEATURE(0x8000001F, 0, EAX, 4) /* * KVM defined paravirt features. diff --git a/tools/testing/selftests/kvm/x86/sev_init2_tests.c b/tools/testing/selftests/kvm/x86/sev_init2_tests.c index 3fb967f40c6a..3f8fb2cc3431 100644 --- a/tools/testing/selftests/kvm/x86/sev_init2_tests.c +++ b/tools/testing/selftests/kvm/x86/sev_init2_tests.c @@ -28,6 +28,7 @@ int kvm_fd; u64 supported_vmsa_features; bool have_sev_es; +bool have_snp; static int __sev_ioctl(int vm_fd, int cmd_id, void *data) { @@ -83,6 +84,9 @@ void test_vm_types(void) if (have_sev_es) test_init2(KVM_X86_SEV_ES_VM, &(struct kvm_sev_init){}); + if (have_snp) + test_init2(KVM_X86_SNP_VM, &(struct kvm_sev_init){}); + test_init2_invalid(0, &(struct kvm_sev_init){}, "VM type is KVM_X86_DEFAULT_VM"); if (kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SW_PROTECTED_VM)) @@ -138,15 +142,24 @@ int main(int argc, char *argv[]) "sev-es: KVM_CAP_VM_TYPES (%x) does not match cpuid (checking %x)", kvm_check_cap(KVM_CAP_VM_TYPES), 1 << KVM_X86_SEV_ES_VM); + have_snp = kvm_check_cap(KVM_CAP_VM_TYPES) & BIT(KVM_X86_SNP_VM); + TEST_ASSERT(!have_snp || kvm_cpu_has(X86_FEATURE_SNP), + "sev-snp: KVM_CAP_VM_TYPES (%x) indicates SNP support (bit %d), but CPUID does not", + kvm_check_cap(KVM_CAP_VM_TYPES), KVM_X86_SNP_VM); + test_vm_types(); test_flags(KVM_X86_SEV_VM); if (have_sev_es) test_flags(KVM_X86_SEV_ES_VM); + if (have_snp) + test_flags(KVM_X86_SNP_VM); test_features(KVM_X86_SEV_VM, 0); if (have_sev_es) test_features(KVM_X86_SEV_ES_VM, supported_vmsa_features); + if (have_snp) + test_features(KVM_X86_SNP_VM, supported_vmsa_features); return 0; }