From patchwork Mon Apr 3 17:43:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 13198514 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6AEDCC761AF for ; Mon, 3 Apr 2023 17:44:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231932AbjDCRoS (ORCPT ); Mon, 3 Apr 2023 13:44:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231937AbjDCRoN (ORCPT ); Mon, 3 Apr 2023 13:44:13 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 113ECD9; Mon, 3 Apr 2023 10:44:12 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id c18so28790448ple.11; Mon, 03 Apr 2023 10:44:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680543851; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9a3JR7vmGcwJg3yramprshnzRS7TRETQfUc7rKzyISs=; b=o77BycsmUJd3tgRAtHCFRAgRLG5KI4CHgVSXZE1lz0jnsV5+iyfvhBWMLmiy+FrcKs qylR+OMJf8zJPwIwsC0y/Q8K9v5qugJyNhKVkfG37nUw7/SZieZ5rNftr9viE8H0Xaxs lynxk4lwNKytUxxDDcAp7JqUyOF1FQIm7FP2yMTT6nxcazpaJsGJ4ivLknVzOzdY10sz RKM1wk1QLr9qH4dmoLVxnmzj3dnvQcfDmB3u2Dw3cRNdFHJ0HuSfrd/73boG8ncea53C TRYiTrU7fIhYLoPkkNgebisPM81mjywnSDSV/c6gPc252T106k0sH4oQPQ/qs12JJNTe 02JQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680543851; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9a3JR7vmGcwJg3yramprshnzRS7TRETQfUc7rKzyISs=; b=Bn0Uak5+8LtxuYtQ3bCcbBd/0Fnyd9zvVk+tm5ko3fGti5Sol2QIHtcYxTQSAEj/F9 xvdN/YLhwzkQDiFROLFjRUXSlk42bm0sfDg12w9U684Pqi9mZlEgXxwqrypz2sYe9uqq c8jrz5yccPkVQamJ/swwiYrlf5AzZSKyc91cvn2EaITpc0cwDI9VoLsg5e0OV7sWNkVU RJJ52+BqOZYJ+XiML5yrnZ6T2Qnzgm5l/TdDSD6iMdwm3eQ8GWaRmqcu/XodKO0hBb9y S2HbDDnY0HbcJG4mmUu4xQp107hizS5pTadDz/2zo62YEgPbpggt7h6EhzRqDin/SBNI JG/A== X-Gm-Message-State: AAQBX9fRFxCzoBhauhRSNL3oC/BxP9qld71EbgYi4Yvwng9OE6l96C0Y fUHD/bc+n3/unHvkQyNOaZU= X-Google-Smtp-Source: AKy350aLHm4XZfaVrgKgPOZiQa6sMJpGyjAQVQHZ+r7zN0g4xwqJx45lr17zX1a/YHYi26pbECPktg== X-Received: by 2002:a17:902:f691:b0:1a2:8940:6dae with SMTP id l17-20020a170902f69100b001a289406daemr19939898plg.34.1680543851406; Mon, 03 Apr 2023 10:44:11 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:2:8635:6e96:35c1:c560]) by smtp.gmail.com with ESMTPSA id jj21-20020a170903049500b001a19196af48sm6883803plb.64.2023.04.03.10.44.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 10:44:11 -0700 (PDT) From: Tianyu Lan To: luto@kernel.org, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, seanjc@google.com, pbonzini@redhat.com, jgross@suse.com, tiala@microsoft.com, kirill@shutemov.name, jiangshan.ljs@antgroup.com, peterz@infradead.org, ashish.kalra@amd.com, srutherford@google.com, akpm@linux-foundation.org, anshuman.khandual@arm.com, pawan.kumar.gupta@linux.intel.com, adrian.hunter@intel.com, daniel.sneddon@linux.intel.com, alexander.shishkin@linux.intel.com, sandipan.das@amd.com, ray.huang@amd.com, brijesh.singh@amd.com, michael.roth@amd.com, thomas.lendacky@amd.com, venu.busireddy@oracle.com, sterritt@google.com, tony.luck@intel.com, samitolvanen@google.com, fenghua.yu@intel.com Cc: pangupta@amd.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-arch@vger.kernel.org Subject: [RFC PATCH V4 01/17] x86/hyperv: Add sev-snp enlightened guest static key Date: Mon, 3 Apr 2023 13:43:49 -0400 Message-Id: <20230403174406.4180472-2-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230403174406.4180472-1-ltykernel@gmail.com> References: <20230403174406.4180472-1-ltykernel@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Tianyu Lan Introduce static key isolation_type_en_snp for enlightened sev-snp guest check. Signed-off-by: Tianyu Lan --- Change since RFC v3: * Remove some Hyper-V specific config setting --- arch/x86/hyperv/ivm.c | 11 +++++++++++ arch/x86/include/asm/mshyperv.h | 3 +++ arch/x86/kernel/cpu/mshyperv.c | 9 +++++++-- drivers/hv/hv_common.c | 6 ++++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 127d5b7b63de..368b2731950e 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -409,3 +409,14 @@ bool hv_isolation_type_snp(void) { return static_branch_unlikely(&isolation_type_snp); } + +DEFINE_STATIC_KEY_FALSE(isolation_type_en_snp); +/* + * hv_isolation_type_en_snp - Check system runs in the AMD SEV-SNP based + * isolation enlightened VM. + */ +bool hv_isolation_type_en_snp(void) +{ + return static_branch_unlikely(&isolation_type_en_snp); +} + diff --git a/arch/x86/include/asm/mshyperv.h b/arch/x86/include/asm/mshyperv.h index e3cef98a0142..2fa40c6ca99f 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -22,6 +22,7 @@ union hv_ghcb; DECLARE_STATIC_KEY_FALSE(isolation_type_snp); +DECLARE_STATIC_KEY_FALSE(isolation_type_en_snp); typedef int (*hyperv_fill_flush_list_func)( struct hv_guest_mapping_flush_list *flush, @@ -36,6 +37,8 @@ extern void *hv_hypercall_pg; extern u64 hv_current_partition_id; +extern bool hv_isolation_type_en_snp(void); + extern union hv_ghcb * __percpu *hv_ghcb_pg; int hv_call_deposit_pages(int node, u64 partition_id, u32 num_pages); diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index ff348ebb6ae2..2f2dcb2370b6 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -403,8 +403,12 @@ static void __init ms_hyperv_init_platform(void) pr_info("Hyper-V: Isolation Config: Group A 0x%x, Group B 0x%x\n", ms_hyperv.isolation_config_a, ms_hyperv.isolation_config_b); - if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) + + if (cc_platform_has(CC_ATTR_GUEST_SEV_SNP)) { + static_branch_enable(&isolation_type_en_snp); + } else if (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP) { static_branch_enable(&isolation_type_snp); + } } if (hv_max_functions_eax >= HYPERV_CPUID_NESTED_FEATURES) { @@ -474,7 +478,8 @@ static void __init ms_hyperv_init_platform(void) #if IS_ENABLED(CONFIG_HYPERV) if ((hv_get_isolation_type() == HV_ISOLATION_TYPE_VBS) || - (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP)) + (hv_get_isolation_type() == HV_ISOLATION_TYPE_SNP + && !cc_platform_has(CC_ATTR_GUEST_SEV_SNP))) hv_vtom_init(); /* * Setup the hook to get control post apic initialization. diff --git a/drivers/hv/hv_common.c b/drivers/hv/hv_common.c index 6d40b6c7b23b..e3b04e978932 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -271,6 +271,12 @@ bool __weak hv_isolation_type_snp(void) } EXPORT_SYMBOL_GPL(hv_isolation_type_snp); +bool __weak hv_isolation_type_en_snp(void) +{ + return false; +} +EXPORT_SYMBOL_GPL(hv_isolation_type_en_snp); + void __weak hv_setup_vmbus_handler(void (*handler)(void)) { }