Received: by 2002:a05:6358:51dd:b0:131:369:b2a3 with SMTP id 29csp1330360rwl; Thu, 10 Aug 2023 09:33:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGN+XOotT2WARWzPBzO/uDWySbPIwYiwR9ImAEtiFqimyM8P5/iBIBi2e7RjtzLtFZEzZjp X-Received: by 2002:a05:6a20:d426:b0:127:76ab:a707 with SMTP id il38-20020a056a20d42600b0012776aba707mr2329216pzb.30.1691685184810; Thu, 10 Aug 2023 09:33:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691685184; cv=none; d=google.com; s=arc-20160816; b=g/AdHweYKPefhwi9WtSu8CP5XcnswsWipVBBoceD8l2CLqE9XpbgWlj13zvy1fkwRb AWdDnFGC/+opOcyjCXiINbWA7wG7vKKTkrAlPn4eTq0Wd41/9CQCfp1sPQrznxKr5WeF flk/m2NCCMpjGlBWywFyo/IzLMkiHauzvwphCy1sqlZW3SYXtGfSHGn3s+ghFHSkKyQ4 jXPvzhAvj8/aEGFg3YkqYHR7HBOoVaYJ8ySkNPaXEhTop0IqBP/cH2F92R7adarDnRpN FBPovw1CvNIcBh0tSi4t7e9dDSNrmkMtnw2zplJHhLBSgQhodOpDrriGg33oH5fuDa8d Sk/A== 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=5OiDRKOFgpns5hcMj/5h29PmrGKgZp4X/9SUFpx9MBE=; fh=TxLVtSsj0Yk+bstPG6ly04YaPbvjOFEmGNSQ8sZkNQc=; b=LS+bTdEyzqDAPTK7EvihckPiwLkP2iPmIuIiQpz7ytnOrLf5hUbLqLZK6vfw/dRH8e wE09BG8yROiE0gxrAtBd0JRQRNNCT3klvMcBUHzD9Se2eggKCPfHxMHTL8ZB/WRCG/+A hc4aZpTpabIoKXcEJWWXvF5FNj/qiNn/557EMRDRfF1A7iA9LgOhFeh5RiXEooaBfRpl M91wuHjP19fi6+hbS9R/BzCp8+Cs/ueWbXCxs/D7nhy7tztzcv8+T5uS7ewWuc0Ke+ND loLQSLyEICma7K2a2ktSo5piSrtxJltnQdso4Ls2+DvLRXEXq+4rB1CrI6s+8diV4w0W YAMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=KtC5cKAX; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a20-20020a63e854000000b0056514d0595fsi1776504pgk.296.2023.08.10.09.32.51; Thu, 10 Aug 2023 09:33:04 -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=KtC5cKAX; 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 S236490AbjHJQFj (ORCPT + 99 others); Thu, 10 Aug 2023 12:05:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236595AbjHJQFJ (ORCPT ); Thu, 10 Aug 2023 12:05:09 -0400 Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9CE322D44; Thu, 10 Aug 2023 09:04:21 -0700 (PDT) Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1bc7b25c699so8059915ad.1; Thu, 10 Aug 2023 09:04:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691683461; x=1692288261; 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=5OiDRKOFgpns5hcMj/5h29PmrGKgZp4X/9SUFpx9MBE=; b=KtC5cKAXcmBERk/Z9CHPmAbWVvGMwCr6T583pLHy83J0Npk3tkqIPtcYm+kHz9y1B6 hQcxNkROpA29Ip++JCtIoRVtn7nDkjbJFTNI2eVMPp4zjtRL5XMQhSfY63ds3+gyuA/d /l54aeF9yTYaFptfRPsfzQ3JmJczEQsf+W0HFFcuAhVShqcu81sAunZ4GHfDay0puzuC LxWw1G669/WkIsbrU1rgGxjqrqxaZHaiplwpbe8mfYeC7kswD7kIYkWGvyUvBk+VgyEt IpVIEiy5Zk1HllXHMpIeC0ai+tNiiA4EldN8B3dpGhJMPq+y7DycvMFKffW/p3jzDnOY DfYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691683461; x=1692288261; 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=5OiDRKOFgpns5hcMj/5h29PmrGKgZp4X/9SUFpx9MBE=; b=EFW8QkStkh9u0SgZ7Y/4kZhSk2tJwJZX02TkyZJdC9NDO167zZJFUkdkk2Xob1v4Ab eH3qI7OdekQjrJHsVqi020w4mDGf9jws8c1aaURIVx0OjB5XcOEc+Zg3wjV+mOZ3TqEF ZLvV4Uq6ug0Knst8maIW3YqDIlqGt1k/h+TSQAdLKMtYNm1veZjD9YxkK5+3opPzlwBX YDLW8karepD81/EweI+0WMUtBkCSULW6JWs4rrlMChM/p6/5t+N+z9kM/OCJgu+Nly6R QXIsXE4Nz/dHyDNvh4yl/4VIAwnp1LlvOguAnTHnzXtikmE1XAquWr9Le+1uion6Ptgz 6yFA== X-Gm-Message-State: AOJu0YwBV7GNdjwnbvUB0CwZC0WWAcxvLLIWwXRQaviv6lT1Be2sIjhd prkZXLMjr0i/5nJvgyZruTU= X-Received: by 2002:a17:902:cec4:b0:1bc:844:5831 with SMTP id d4-20020a170902cec400b001bc08445831mr3218659plg.57.1691683460928; Thu, 10 Aug 2023 09:04:20 -0700 (PDT) Received: from ubuntu-Virtual-Machine.corp.microsoft.com ([2001:4898:80e8:0:c620:2003:6c97:8057]) by smtp.gmail.com with ESMTPSA id r4-20020a1709028bc400b001b895a17429sm1948821plo.280.2023.08.10.09.04.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 09:04:19 -0700 (PDT) From: Tianyu Lan To: kys@microsoft.com, haiyangz@microsoft.com, wei.liu@kernel.org, decui@microsoft.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, dave.hansen@linux.intel.com, x86@kernel.org, hpa@zytor.com, daniel.lezcano@linaro.org, arnd@arndb.de, michael.h.kelley@microsoft.com Cc: Tianyu Lan , linux-arch@vger.kernel.org, linux-hyperv@vger.kernel.org, linux-kernel@vger.kernel.org, vkuznets@redhat.com, Michael Kelley Subject: [PATCH V5 1/8] x86/hyperv: Add sev-snp enlightened guest static key Date: Thu, 10 Aug 2023 12:04:04 -0400 Message-Id: <20230810160412.820246-2-ltykernel@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230810160412.820246-1-ltykernel@gmail.com> References: <20230810160412.820246-1-ltykernel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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_BLOCKED,SPF_HELO_NONE,SPF_PASS 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 From: Tianyu Lan Introduce static key isolation_type_en_snp for enlightened sev-snp guest check. Reviewed-by: Michael Kelley Signed-off-by: Tianyu Lan --- arch/x86/hyperv/ivm.c | 11 +++++++++++ arch/x86/include/asm/mshyperv.h | 2 ++ arch/x86/kernel/cpu/mshyperv.c | 9 +++++++-- drivers/hv/hv_common.c | 6 ++++++ include/asm-generic/mshyperv.h | 13 ++++++++++--- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/arch/x86/hyperv/ivm.c b/arch/x86/hyperv/ivm.c index 14f46ad2ca64..b2b5cb19fac9 100644 --- a/arch/x86/hyperv/ivm.c +++ b/arch/x86/hyperv/ivm.c @@ -413,3 +413,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 88d9ef98e087..9f11f0495950 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, @@ -239,6 +240,7 @@ static inline void hv_vtom_init(void) {} #endif extern bool hv_isolation_type_snp(void); +extern bool hv_isolation_type_en_snp(void); static inline bool hv_is_synic_reg(unsigned int reg) { diff --git a/arch/x86/kernel/cpu/mshyperv.c b/arch/x86/kernel/cpu/mshyperv.c index c7969e806c64..5398fb2f4d39 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) && + ms_hyperv.paravisor_present)) 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 542a1d53b303..4b4aa53c34c2 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)) { } diff --git a/include/asm-generic/mshyperv.h b/include/asm-generic/mshyperv.h index 402a8c1c202d..580c766958de 100644 --- a/include/asm-generic/mshyperv.h +++ b/include/asm-generic/mshyperv.h @@ -36,15 +36,21 @@ struct ms_hyperv_info { u32 nested_features; u32 max_vp_index; u32 max_lp_index; - u32 isolation_config_a; + union { + u32 isolation_config_a; + struct { + u32 paravisor_present : 1; + u32 reserved_a1 : 31; + }; + }; union { u32 isolation_config_b; struct { u32 cvm_type : 4; - u32 reserved1 : 1; + u32 reserved_b1 : 1; u32 shared_gpa_boundary_active : 1; u32 shared_gpa_boundary_bits : 6; - u32 reserved2 : 20; + u32 reserved_b2 : 20; }; }; u64 shared_gpa_boundary; @@ -58,6 +64,7 @@ extern void * __percpu *hyperv_pcpu_output_arg; extern u64 hv_do_hypercall(u64 control, void *inputaddr, void *outputaddr); extern u64 hv_do_fast_hypercall8(u16 control, u64 input8); extern bool hv_isolation_type_snp(void); +extern bool hv_isolation_type_en_snp(void); /* Helper functions that provide a consistent pattern for checking Hyper-V hypercall status. */ static inline int hv_result(u64 status) -- 2.25.1