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: 78658 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2475855vqo; Mon, 3 Apr 2023 10:45:31 -0700 (PDT) X-Google-Smtp-Source: AK7set9QXqCs/r1FC2te5nm7iCuUBOT0lHpf4bLJZyt1FrbBNBKV3TspHsZyXEc4HvpNqdbj880C X-Received: by 2002:a05:6a20:b191:b0:c2:b6cf:96db with SMTP id ee17-20020a056a20b19100b000c2b6cf96dbmr28563869pzb.39.1680543930959; Mon, 03 Apr 2023 10:45:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680543930; cv=none; d=google.com; s=arc-20160816; b=EmbjfaRsjZjDCzyxYkEGJQa6LV8hpCTIVFiJ3n6nXdAaBm8Ow307LsJV2YY5GZPqCl wppt87tfbXjBYHY8RNHN7wOoZj7osE466QNyCnmygbrEVeTvfdSSLCLS/PUsrnPYAqj5 NQnRT71/UF3sURHaSLXFkuXkBexFbeIFX7rPYwAlyn262H2VDbNGkP2O9SOfDjqsAw1+ O0Yb0HgzH8szHIZwZc5x9jHzIGiIReTBWCRFlxlN/vHo9IsYGoZ1aShJmNo+H13OUiDE +K4H1jh/jamn7iVr6Rf25xoljfdzaaMw0oraM2hh1W/YHIXENWLmDpKHxzy37wopzuWA 6U5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9a3JR7vmGcwJg3yramprshnzRS7TRETQfUc7rKzyISs=; b=xbZCf2jp6Of3xrXda/qjdCc1eRPFHv3ggv7sYaictTGmxqu91fEk6zn9L3/QA2C5Zi UaxPZ54pv2KmKPvisk6w6NVFBQL5vo6+Qu21PrMlGHKyJzNc+gIYbMcSZ3Yua687VefP fbYDXQK6gCl4wI3ApAGNSjhBRVgXDbWwPENPo9JDwOCqynBKiwif7uIh3eMpFP3/pzDM YkzOROCmWNK3pPWgeEc1bkR14rLKPFlcXqJhDQnpjlD0cxjUUw2oFIPHm6yNAt8x7QBy Zf6oD91fZFuuvhiIDvoFcc8yAsLkyKsSc7lsealZU/Z2H9tzUSqGqQdJ8jkl+SfLyoM0 PaTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=o77Bycsm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o8-20020aa79788000000b0062d90384500si8751966pfp.307.2023.04.03.10.45.18; Mon, 03 Apr 2023 10:45:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=o77Bycsm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232111AbjDCRoU (ORCPT + 99 others); Mon, 3 Apr 2023 13:44:20 -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-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 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762178033365269319?= X-GMAIL-MSGID: =?utf-8?q?1762178033365269319?= 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)) { }