From patchwork Mon May 1 08:57:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tianyu Lan X-Patchwork-Id: 89005 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2566339vqo; Mon, 1 May 2023 02:05:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4GVA064tA6ii63CKQW9xCT3kI3FTfODEIQHhWg2IQY6W/OS2We2Rs1W7B/WmFiui/NEIuu X-Received: by 2002:a17:902:e551:b0:1a6:6f3f:bc3 with SMTP id n17-20020a170902e55100b001a66f3f0bc3mr16376182plf.57.1682931958984; Mon, 01 May 2023 02:05:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682931958; cv=none; d=google.com; s=arc-20160816; b=AVMWZqjtzBleDhxyoFyazd5iKXKnamH4tfOqHnZIo7qnhn2xyOt77fUDbws1dUzhYS 7yG0TXDBpLhWXtHusZNLFi2PqJR5liX5NLyBJs/EPT5H/dLhhmb5ceaupUN6q1Nz5YK7 NUcrB+Hv1N8IU3AMExxPCyjcBFKGsoKYEh9Eyl+ovsxprJEM+jnEgmyKJvwVbZB7LSeT RVot0zn/UgonwHl8hiq5NQTnOxAOTr5z3c97mqU/G09cJx5w7grB+EfhDeKwadSwt/r6 YQLy82qKU9ro9emHlDAi84uFOYvOdMFME2K6cJNINi2wkcsUyYcMNLqGG24QyQanQuj1 Nr1w== 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=Udm3eUyVQh3+nWxooTJ9GWCwKBxGdrkWeoFcDQJr1CA=; b=LEPTUr9vrN++QTwOkvqpiMQaMfj6rpFQ2gas6Dqxs1c5lzK4AkRzCAlCR2jeOgEX5k BJVnt0a0hn0sEmfw3QWGPtxH/8Tu96y+2hID+IxqKsSs+SMDJYZKldVUXx4nfByx2GWY e9/LzVRJal4lSpd09CC7WwovySqDJyxbuVbCnY4hLR/qBiFcgWA2G9/42No4t2GQvq1z +nRWrhwxJ56JA6ij6FnaYlC8F9KP4neGGuMObq7fCfUtYu7cy3wUbU534m3EsWWtPcAX M5WU78qbV3xD9BNypLI6dGIYp4lGtm51l9zbTdh83rWX4cgg34WI3AdyB0BQ1XkY5Bpn yPNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=QKSYElK4; 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 k4-20020a170902c40400b001ab039a411csi16695plk.17.2023.05.01.02.05.46; Mon, 01 May 2023 02:05:58 -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=20221208 header.b=QKSYElK4; 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 S232228AbjEAI5h (ORCPT + 99 others); Mon, 1 May 2023 04:57:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232181AbjEAI5d (ORCPT ); Mon, 1 May 2023 04:57:33 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C481FA; Mon, 1 May 2023 01:57:32 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1aaf2ede38fso8715355ad.2; Mon, 01 May 2023 01:57:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682931451; x=1685523451; 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=Udm3eUyVQh3+nWxooTJ9GWCwKBxGdrkWeoFcDQJr1CA=; b=QKSYElK4WHUusngEnOczpAhR7EGv6uM9CCbzcsaLTEr863kXBbKsvFhU0JbIncMqt/ ub5HB/1bcxs4CQHUJIEJl9aMZ3kFmfbmcu0rtvPhLuyw8pH7CK8S5eB/SBorhAexkENg /okTBlcthPspkPR5p3Fz+vrQfbZ6XL3q2pvBci8CKmGsdgMaKKOtX46hFESEeO6aUE1R bLbIKGgS+JUpTftXTjZfO9XmbI3rMM6/WYy0Jk02C2BmuIvkeZ2WLCIcF0M2+W6pDA6u I9ZreZJzKgQcuo7Ik24+1Ps6PkT3JdoikZNpTctGJ10bBCX+OCFna4kPAkYRs8uH9Vnb 9b/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682931451; x=1685523451; 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=Udm3eUyVQh3+nWxooTJ9GWCwKBxGdrkWeoFcDQJr1CA=; b=EY0rmndNqA7DL+Msmkk8q03HUMPD4JniFjjgbG1DQQUvB1vDeSf2G/n+uzcWGJ7T1f 0XWUoOcGg8+CsnS1ixRQPqNS0hC9ooSYoiZZBkbrOTgZBnkJzeGJFUXGfBq+h8Bpla5u 77cbWl//O/0DVApb2zrs5cc8jAxQEwTRnCz7RQ2pinBOX1Us+nXobn3CUg/lwMbUuUU/ KX7vowO/7h9jmDoDBtSCnBFb8Osbhrvt6q16xi3u7IIzV5N6z/QoNwpdqesSEpblN3E7 Bv+XdjekM7ffhA6Tq2bsxzrU/9fRTu7VfgvoNy9la8n2Rb2u2UqDGqR0+pm6yzcL9ONf YsDA== X-Gm-Message-State: AC+VfDyn45i2IPYqQQBBgH34+2sqUNOOIN118t1TbTmgXC9Per7QgC8U j2YGHc4GyERGfAaxlUN6v0g= X-Received: by 2002:a17:902:b48c:b0:1a6:34ea:6bcf with SMTP id y12-20020a170902b48c00b001a634ea6bcfmr12766396plr.45.1682931451363; Mon, 01 May 2023 01:57:31 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:b:e11b:15ea:ad44:bde7]) by smtp.gmail.com with ESMTPSA id t13-20020a1709028c8d00b001a4fe00a8d4sm17407070plo.90.2023.05.01.01.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 01:57:31 -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 V5 01/15] x86/hyperv: Add sev-snp enlightened guest static key Date: Mon, 1 May 2023 04:57:11 -0400 Message-Id: <20230501085726.544209-2-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230501085726.544209-1-ltykernel@gmail.com> References: <20230501085726.544209-1-ltykernel@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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?1764682061761701772?= X-GMAIL-MSGID: =?utf-8?q?1764682061761701772?= 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 b445e252aa83..97d117ec95c4 100644 --- a/arch/x86/include/asm/mshyperv.h +++ b/arch/x86/include/asm/mshyperv.h @@ -26,6 +26,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, @@ -45,6 +46,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 c7969e806c64..63a2bfbfe701 100644 --- a/arch/x86/kernel/cpu/mshyperv.c +++ b/arch/x86/kernel/cpu/mshyperv.c @@ -402,8 +402,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) { @@ -473,7 +477,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 64f9ceca887b..179bc5f5bf52 100644 --- a/drivers/hv/hv_common.c +++ b/drivers/hv/hv_common.c @@ -502,6 +502,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)) { }