From patchwork Sat Dec 30 17:23:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 13507030 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D3459C46CD2 for ; Sat, 30 Dec 2023 17:36:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 721B76B0178; Sat, 30 Dec 2023 12:36:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6AAF56B0179; Sat, 30 Dec 2023 12:36:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4AFE36B017A; Sat, 30 Dec 2023 12:36:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 359956B0178 for ; Sat, 30 Dec 2023 12:36:20 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 04DA840478 for ; Sat, 30 Dec 2023 17:36:20 +0000 (UTC) X-FDA: 81624188520.19.CD37244 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2047.outbound.protection.outlook.com [40.107.93.47]) by imf02.hostedemail.com (Postfix) with ESMTP id 2EECC8000B for ; Sat, 30 Dec 2023 17:36:16 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=ZelDUwPD; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf02.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.93.47 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1703957777; a=rsa-sha256; cv=pass; b=ndfTduZsLZw+cUgB14lJWJRqlRiioPMhgCgTf3AwDI1+3VKJuj3m4qr1srTqVptFmeWKdM iUbgXsRRW3JP7JvGM7UVrmX/TUE6Ge/yczNPeG/LLQzRpawe4fiVvhY4saTAQhc6qgKCrm V8k9dIlRaoaLRJA7M+p6RAOrE+VTNfQ= ARC-Authentication-Results: i=2; imf02.hostedemail.com; dkim=pass header.d=amd.com header.s=selector1 header.b=ZelDUwPD; arc=pass ("microsoft.com:s=arcselector9901:i=1"); dmarc=pass (policy=quarantine) header.from=amd.com; spf=pass (imf02.hostedemail.com: domain of Michael.Roth@amd.com designates 40.107.93.47 as permitted sender) smtp.mailfrom=Michael.Roth@amd.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703957777; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=suPeQu3ZqbFX6Q/W+f2tBEOWSna7wKJedszjB7wQMIM=; b=j9YrtI9k6zwKGtExS5Xm3b3wRoxmfbs5qXYr2Wnr5NqO1oT5fDoBhEKGFA7WI6dUEjTE9B bWAqRcXHRq+u+3EyqKZaNH4A5FH+5tng590jINYqPxKh7z9KOUKcsi6Pt4svCH/P+kq+bB 6Ov05kfF+X0PdjMBJDY3onPzQEcF1/k= ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VHsySAU6EZzKqL2WLihl9giGtBSmYVZ1xqKJ/COgBcZjRn3IEd78mLzk7K79HHvxVkls3TzlUXKBfacqXc9GzYmBO8jHXIZJFYOl1o4ymdswpI5QXEsyG7Ev9GpGY3AL+6RSOFfJhmFPB58PjoqIuYih/uXeaKheJa9l03URDwMJg+yvh9EU9w2CtFCuQ+FY01cKAbwt1I5YBe1gLgSheTjxqsRlo3ny/Kjx0bhyxTz6BCGe/BGiorrYX/l72MmZ5o/pOxSBmbPvdMR45tGxMfbjZg+oVsJ8mVrnkvsi73BfQrWa2wZiIuU3hFfZm//pBd7UoCBX6FXWHHSgN2+yyA== 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=suPeQu3ZqbFX6Q/W+f2tBEOWSna7wKJedszjB7wQMIM=; b=HwxhfFnJx3bDeGjhRRP8WKXb9AN9NHqp1dRa0K1g2QpeV1wg2D4PbjdpkrqsZw83zxanUYsq5hM1w1ltODsI6br06vGrAqvneigm2mbXRPqq7JYliU4lC5FWp6TMminr/kzZ1FTAi2MujPTQa2/oKcfhugBkEZ5OH8mqjGxXQesmZsN1NB4a3QyyuAcjeGsQ/j0rm4bT7tSsx6GH19aN9boFmZYvIDCtRqSkA/YcIqOlapx08yV6NtQlk2dswp/RzMr0IIzyzXzEwpQljxptyaB3mo8NBrvLuM/AE9nZsLvTPDB3hmeGOYBjxVr4uuETwOQpZ/2t6JE0Ey/magV+Kg== 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=suPeQu3ZqbFX6Q/W+f2tBEOWSna7wKJedszjB7wQMIM=; b=ZelDUwPDRL53ZCNroikc6fGfTpII6hXRvhSZ9wryiN69kQ7KYs/r4P8rfA3UiPm+Jsfsc1UCb0V3kM5GrHxnNemYIFtBP124ILS1du2HoIFlGzCky9dY0PAu+gwqsvWjkxCeHQvWM0xuAdrLU7Jx6iz1mm2yZ4VwwholEiA1fXg= Received: from CY8PR19CA0009.namprd19.prod.outlook.com (2603:10b6:930:44::14) by PH7PR12MB7114.namprd12.prod.outlook.com (2603:10b6:510:1ed::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.23; Sat, 30 Dec 2023 17:36:09 +0000 Received: from CY4PEPF0000FCC1.namprd03.prod.outlook.com (2603:10b6:930:44:cafe::14) by CY8PR19CA0009.outlook.office365.com (2603:10b6:930:44::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7135.23 via Frontend Transport; Sat, 30 Dec 2023 17:36:09 +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 CY4PEPF0000FCC1.mail.protection.outlook.com (10.167.242.103) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.7159.9 via Frontend Transport; Sat, 30 Dec 2023 17:36:09 +0000 Received: from localhost (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.34; Sat, 30 Dec 2023 11:36:09 -0600 From: Michael Roth To: CC: , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , Subject: [PATCH v11 07/35] KVM: x86: Add KVM_X86_SNP_VM vm_type Date: Sat, 30 Dec 2023 11:23:23 -0600 Message-ID: <20231230172351.574091-8-michael.roth@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231230172351.574091-1-michael.roth@amd.com> References: <20231230172351.574091-1-michael.roth@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] 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: CY4PEPF0000FCC1:EE_|PH7PR12MB7114:EE_ X-MS-Office365-Filtering-Correlation-Id: be5358a0-ffd0-4a2c-3c39-08dc095dcf5f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5q2d07QMAIpNskcHBIB+N1EFO1/pfqjPgE5QxvMTYi9vkQb2GIvV+nL8gegomJLGkxkeJGCkZnwg8D7dBDmKb+gVtqlX6vhMJr3ctnXk8wMQ6g++NzkpPwd8rfriu8NIWmUfMiWWFCi0MUTCQd064TaHjBh3ToOObzskMSY9A8DzdaeM0tbW2EmO6lSgqxjBno1j3/ZR9eRRZyIdzpiWB2p3t8xGlftaPkM5gwBioja1a2bHfg2LvnWwUc9Y+4QjJgOiwfV6SF2MH4t4a19etTMXrIsLRfcj6/W5RjVUOxrc4Po6bWR4wlIgo4UeJb3m8PujgNwTaJGH5N7jKwf/TuRTgQFimohFxIKMfjSftb0EoK7YkUV7v9OnoAQS5axGoPC3jyoBPZWdcaN7ve/LGUxHcB46rGk8Y812s5bt00IvQQnKFpfzwVOWmb8tJdd00btgmtzv/xR+Ot5umo9uHht78tExPJOjoTLaigL9ozH0o3U8xGLG0m9fG86Al4iMNaGbtJlBySNvFQmY1PPokL/JubdZNK3+IUyTeYr/V2y3GL3Qgt+V3/+ppxxfHimKB4yAKCKGlz+Yo8yjx3LPowK2d5tlKH1qo9RfSjl2ucQdWnUYCLvjgNMlCLJdBIT16S4y+280VZfEnFnVSBsQrRy+ugcMo94PmmXDipcqY6BuyA0a9EFMfazhIhiq5ZHvZNms9W8RR/dgpWyioXl2IO2WHiQuWvK6TSvwfbXvC3SahxhkE/hLcnnPlLVEpqKv1/c02dEdrSj51l/Z+VO9ew== X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230031)(4636009)(136003)(346002)(376002)(39860400002)(396003)(230922051799003)(1800799012)(451199024)(64100799003)(82310400011)(186009)(40470700004)(36840700001)(46966006)(47076005)(83380400001)(2616005)(26005)(1076003)(336012)(426003)(16526019)(82740400003)(356005)(81166007)(36860700001)(41300700001)(8676002)(8936002)(316002)(54906003)(4326008)(7416002)(5660300002)(7406005)(2906002)(44832011)(6916009)(6666004)(478600001)(70206006)(70586007)(86362001)(36756003)(40480700001)(40460700003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Dec 2023 17:36:09.4407 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: be5358a0-ffd0-4a2c-3c39-08dc095dcf5f 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: CY4PEPF0000FCC1.namprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7114 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: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tO5X4go/BEnJYkG9npZgTxFi0qgFJtH2UbSVVOqq7YA0ktgYakpKOGAoPwLMoI3YRdFhmsBMIZ6SXPXwvpYMilCimZCX3hkhHzlVxUd5TOo+QhtZJV/DdnBYRm5KfqlyOYQw7Lg80KlReEaXQCoZVi6WRDq8lFMu3ooZw3qR78tLI9LQjJDB7xTGbqgD/xfNrXSuID3BKDVAKWZETCRBZ9oG2b6ObyTya76QdHt94lzMow6J4y8LBF/Y4gLosmqTo2aJwxzyfxnS22lmfPtPt4XosPVneLHKe8tfuViwLFM7VWxYiz9FaAcgEY+ZW7WQdSDflhR7hhwGRGmsTIV8hu1J1FnNqr6kZzlCjjSBfWRspt5/WjJdUyYx5byusC5 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In some cases, such as detecting whether a page fault should be handled as a private fault or not, KVM will need to handle things differently versus the existing KVM_X86_PROTECTED_VM type. Add a new KVM_X86_SNP_VM to allow for this, along with a helper to query the vm_type. Signed-off-by: Michael Roth --- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/include/uapi/asm/kvm.h | 1 + arch/x86/kvm/x86.c | 20 +++++++++++++++++--- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h index 63596fe45013..e38cab5dccae 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -2141,6 +2141,8 @@ void kvm_configure_mmu(bool enable_tdp, int tdp_forced_root_level, #define kvm_arch_has_private_mem(kvm) false #endif +bool kvm_is_vm_type(struct kvm *kvm, unsigned long type); + static inline u16 kvm_read_ldt(void) { u16 ldt; diff --git a/arch/x86/include/uapi/asm/kvm.h b/arch/x86/include/uapi/asm/kvm.h index a448d0964fc0..57e4ba484aa2 100644 --- a/arch/x86/include/uapi/asm/kvm.h +++ b/arch/x86/include/uapi/asm/kvm.h @@ -564,5 +564,6 @@ struct kvm_pmu_event_filter { #define KVM_X86_DEFAULT_VM 0 #define KVM_X86_SW_PROTECTED_VM 1 +#define KVM_X86_SNP_VM 3 #endif /* _ASM_X86_KVM_H */ diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index aaf71e5c1d18..87b78d63e81d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -4579,9 +4579,21 @@ static int kvm_ioctl_get_supported_hv_cpuid(struct kvm_vcpu *vcpu, static bool kvm_is_vm_type_supported(unsigned long type) { - return type == KVM_X86_DEFAULT_VM || - (type == KVM_X86_SW_PROTECTED_VM && - IS_ENABLED(CONFIG_KVM_SW_PROTECTED_VM) && tdp_enabled); + if (type == KVM_X86_DEFAULT_VM) + return true; + else if (type == KVM_X86_SW_PROTECTED_VM && + IS_ENABLED(CONFIG_KVM_SW_PROTECTED_VM) && tdp_enabled) + return true; + else if (type == KVM_X86_SNP_VM && + IS_ENABLED(CONFIG_KVM_AMD_SEV) && tdp_enabled) + return true; + + return false; +} + +bool kvm_is_vm_type(struct kvm *kvm, unsigned long type) +{ + return kvm->arch.vm_type == type; } int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) @@ -4784,6 +4796,8 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) r = BIT(KVM_X86_DEFAULT_VM); if (kvm_is_vm_type_supported(KVM_X86_SW_PROTECTED_VM)) r |= BIT(KVM_X86_SW_PROTECTED_VM); + if (kvm_is_vm_type_supported(KVM_X86_SNP_VM)) + r |= BIT(KVM_X86_SNP_VM); break; default: break;