Received: by 2002:a05:6a10:144:0:0:0:0 with SMTP id 4csp290714pxw; Fri, 8 Apr 2022 07:41:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiLMK5GYuVEW75wNR/hc6SE6xZdJrEk+KZ7u5YkxxHfbM6KLVhakF3sED+HJwVNa3qPz1n X-Received: by 2002:a17:903:32c5:b0:156:b466:c8ed with SMTP id i5-20020a17090332c500b00156b466c8edmr19396171plr.34.1649428903526; Fri, 08 Apr 2022 07:41:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649428903; cv=none; d=google.com; s=arc-20160816; b=z/r+kKtv/J05akCvUpEmXwzndI2cOVGvD3qsq9EePZvCJIgCxhLP7C5ojdjlXGVBIQ J3HwV1WdeDSwQV4PMWJyUib99VV+zqbCH8MPLUVWxvyHW/bQlli5S/qFjn2aiTNPq0HK jEDF5A3bIGNdCs/djRwf3YgEf24NWmKIX/sHuhwqpcKMRR2NZQeMEEGFQP+CHypbACsq y/JKqPOKe4S2+EDUdyoG7nbLV9THt1GR62X57b6wAgjPp7akGJAgRj08LPygW+omNRP0 H3j0dfslxEqUf5iTQUGypaRfck7Q+yz67XhZ5wETp7iOZmgwAY4aDAD5GtLvTnq/qSi6 N7wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=VL6W8xBiAHENLUziclyBl/sRfCmbPUlf8MEowg+MPJM=; b=UHmgu9L3q9y2KxG9MfXpM0vXigt7vp4qVcHo9MfrIN9ec226iKmKEeIp/PqCws2qGD +DcvvwrJfleDnDJcvvgwm11P4sl7ds2FstuSTtcCJxOTGL9disjkuyXyVCyEC2Ql3cu/ fZygyc84G8nVFfsdAZmPVm3G5yaVQXW5ua3pt/T90kJf9bGNLkD+PyFxICcrQ9BG9d7X KXse15VaT1keuhiNrCzca/FG5gFhdrLUTXs270vAOKDGjb9TllW9u/T1WqMgJ1Js9GKe 6ahGaOnn1JYE+5mgpA77HV57kaC5nXeg8yrEyCx0BRR0IYmEImYPf2dBBI2t36/A8nGd uwZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=nYfny0To; dkim=neutral (no key) header.i=@linutronix.de; 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=linutronix.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i6-20020a633c46000000b003816043ef7csi1629823pgn.369.2022.04.08.07.41.29; Fri, 08 Apr 2022 07:41:43 -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=@linutronix.de header.s=2020 header.b=nYfny0To; dkim=neutral (no key) header.i=@linutronix.de; 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=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233378AbiDHJRA (ORCPT + 99 others); Fri, 8 Apr 2022 05:17:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233099AbiDHJMG (ORCPT ); Fri, 8 Apr 2022 05:12:06 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D47371252B6; Fri, 8 Apr 2022 02:09:12 -0700 (PDT) Date: Fri, 08 Apr 2022 09:09:09 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1649408950; h=from:from:sender:sender:reply-to: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; bh=VL6W8xBiAHENLUziclyBl/sRfCmbPUlf8MEowg+MPJM=; b=nYfny0ToDDymeUnREkvUVKXoHwdXvLiHmnD/fhJT2Vm4rNagYxC32woSrbcq21nSgkFTuR s0rY2SNnw7oeVcHl92QFEyALVdc3tIsJvkizKFB0r55t7nFZdsIUtQ4DoEV3vny46TjGLC RUpA4Y6W3hvipOZ6bbJA83CfUiigsHE5ZEnktuMCjXca+lEVUNC5ubgFSW+PHA9Qdz8gU/ YhPZiE65hRWzRWmGUjqp+EKLCrMJpwhnOKUjNnWvBhDeDu3bIdYGi6vrEwIEDh1l+6j17C xwfVdU9lb6PiiTuEf0iifIV2MbQr1sePLJTIDtvaIBzhFjhBmEdirPYPhJsc5g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1649408950; h=from:from:sender:sender:reply-to: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; bh=VL6W8xBiAHENLUziclyBl/sRfCmbPUlf8MEowg+MPJM=; b=htfL/VAQiV+Lp2+9pX4M264J9X0iIyIAdGY078wpIiMHJ1rELY2qtkWKT+Twybk2F+8e77 j7bHrs81/j5knDDw== From: "tip-bot2 for Brijesh Singh" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: x86/sev] x86/sev: Save the negotiated GHCB version Cc: Brijesh Singh , Borislav Petkov , Venu Busireddy , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20220307213356.2797205-12-brijesh.singh@amd.com> References: <20220307213356.2797205-12-brijesh.singh@amd.com> MIME-Version: 1.0 Message-ID: <164940894981.389.4710155959955476545.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED 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 The following commit has been merged into the x86/sev branch of tip: Commit-ID: 2ea29c5abbc27147c2d9e2ab5e05436aca706b65 Gitweb: https://git.kernel.org/tip/2ea29c5abbc27147c2d9e2ab5e05436aca706b65 Author: Brijesh Singh AuthorDate: Wed, 09 Feb 2022 12:10:05 -06:00 Committer: Borislav Petkov CommitterDate: Wed, 06 Apr 2022 13:10:18 +02:00 x86/sev: Save the negotiated GHCB version The SEV-ES guest calls sev_es_negotiate_protocol() to negotiate the GHCB protocol version before establishing the GHCB. Cache the negotiated GHCB version so that it can be used later. Signed-off-by: Brijesh Singh Signed-off-by: Borislav Petkov Reviewed-by: Venu Busireddy Link: https://lore.kernel.org/r/20220307213356.2797205-12-brijesh.singh@amd.com --- arch/x86/include/asm/sev.h | 2 +- arch/x86/kernel/sev-shared.c | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h index ec060c4..9b9c190 100644 --- a/arch/x86/include/asm/sev.h +++ b/arch/x86/include/asm/sev.h @@ -12,7 +12,7 @@ #include #include -#define GHCB_PROTO_OUR 0x0001UL +#define GHCB_PROTOCOL_MIN 1ULL #define GHCB_PROTOCOL_MAX 1ULL #define GHCB_DEFAULT_USAGE 0ULL diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index 2abf8a7..91105f5 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -14,6 +14,15 @@ #define has_cpuflag(f) boot_cpu_has(f) #endif +/* + * Since feature negotiation related variables are set early in the boot + * process they must reside in the .data section so as not to be zeroed + * out when the .bss section is later cleared. + * + * GHCB protocol version negotiated with the hypervisor. + */ +static u16 ghcb_version __ro_after_init; + static bool __init sev_es_check_cpu_features(void) { if (!has_cpuflag(X86_FEATURE_RDRAND)) { @@ -51,10 +60,12 @@ static bool sev_es_negotiate_protocol(void) if (GHCB_MSR_INFO(val) != GHCB_MSR_SEV_INFO_RESP) return false; - if (GHCB_MSR_PROTO_MAX(val) < GHCB_PROTO_OUR || - GHCB_MSR_PROTO_MIN(val) > GHCB_PROTO_OUR) + if (GHCB_MSR_PROTO_MAX(val) < GHCB_PROTOCOL_MIN || + GHCB_MSR_PROTO_MIN(val) > GHCB_PROTOCOL_MAX) return false; + ghcb_version = min_t(size_t, GHCB_MSR_PROTO_MAX(val), GHCB_PROTOCOL_MAX); + return true; } @@ -127,7 +138,7 @@ enum es_result sev_es_ghcb_hv_call(struct ghcb *ghcb, bool set_ghcb_msr, u64 exit_info_1, u64 exit_info_2) { /* Fill in protocol and format specifiers */ - ghcb->protocol_version = GHCB_PROTOCOL_MAX; + ghcb->protocol_version = ghcb_version; ghcb->ghcb_usage = GHCB_DEFAULT_USAGE; ghcb_set_sw_exit_code(ghcb, exit_code);