Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp3514781pxp; Tue, 8 Mar 2022 16:22:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJzlnZbAzYJuXWEWPQlI2Xb0g8joU8ABAzRuN+bvQCWN6jG5e2uLYax3GtQsADtPyqlChdrS X-Received: by 2002:a17:90a:fb4e:b0:1bc:8227:edd9 with SMTP id iq14-20020a17090afb4e00b001bc8227edd9mr7473745pjb.56.1646785336551; Tue, 08 Mar 2022 16:22:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1646785336; cv=pass; d=google.com; s=arc-20160816; b=CoJPjkKdLD0Qh79GUql3+WxUClOOohSmK/BkEusmCLn9U/zrK7yx/LrMJf53tm/Qbs Vw3CytJCwb7Ywl1dVpgITE8cvmNwHphir9rpHr9HcczHwqDqxq4qtUUCo8Q/zwdRxfEq UOuzlZUj6sn185HUZ2f4p0YnMLE2i/qLzvJl17Tfi0N5RWyXRvi9F5VnuGeoIY+/xotv 3vOE09pYl/0RQJ9DlMdYY1HVG3VYC7LvPo/bbC6iI6P8FerwtReyE8ukRpj67VVAA1IM 0qaz6pRZKIzSoKBRkJfPdfRp9ZE/Flmz1erfPwqCqpbWNk7jzb7zudzk9b2SFQypkNBc WIQQ== ARC-Message-Signature: i=2; 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=NW12IGctCHQ59PAs+7VbIe+Nhdv+NxvQBr3aNl1R/eU=; b=h1BdTM2KtHrbLGveSOXdPjyjK1x/cjF0NStzy15lma8RlgRszxk6Ja6035GtiEaMz0 Lg6d51MFNncAUexWlc3/WaoR7PIyAJn1fFgT6vTtGdcZojtS5G//yzxLgCipsfTyQPbj pAw++ry7l4fqqsQ3HWfvpyQtGIn86XNDNf0qCBtsDX5txy+7/ULsulwW7ZRR8gHHLutX eqvCYA1F6bDxD0Wb6rh73AE9364H3PERz/kxqlj+BAhoq4rIdNSxb8YoIQPpc28Z9Rd0 tmZT4JKtAi/WDtcO9v5t5OF5oBzb7tiPm2Io1YfeqgtMS9EgGPxkfzXK+OLLVQxRZL/f WRxw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=CteKe0Mc; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id my15-20020a17090b4c8f00b001bef41cdf55si581639pjb.47.2022.03.08.16.22.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 16:22:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=CteKe0Mc; arc=pass (i=1 spf=pass spfdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id CA910C0875; Tue, 8 Mar 2022 15:46:24 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245695AbiCGVgI (ORCPT + 99 others); Mon, 7 Mar 2022 16:36:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245600AbiCGVfn (ORCPT ); Mon, 7 Mar 2022 16:35:43 -0500 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2047.outbound.protection.outlook.com [40.107.237.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79F7C70F5F; Mon, 7 Mar 2022 13:34:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=atJ6+Stmb6FxeQsZe1WVsIAMDd+2oakJJtR5/ki+SYHPhsthAwxsdFGO8VDKP+QQOp/tg1d9D0YXWwyClinaBGpKBMJkCXXWoWfe2uo1zMKjYjMx6JjsxmR3Q4JcH3/UJMqBwsf8d0KiVI/T8/I0yKrRHNcGZhHgm/Bdo1SkGKe/eNUw8qsPn/m0CPHPRkpZJeAmZCkI4e/TBQka0JXt6Sap+SA4rYRsRHWJRiPkbHe3i4lyy37YFWpMm95EOuY2N39x92lv9KBPb+N/dglMKGLIn7C6IG/u4Mvi+HSFoLcO4AmFU172amwpjPXsVtA4GStVol9oWstHfu9dKhXM0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NW12IGctCHQ59PAs+7VbIe+Nhdv+NxvQBr3aNl1R/eU=; b=TCBLGAkkqYm9I7FXqxloxO6tgyF0KLU/W7dxGAL1Xz1Tmi672o0eTqm2s9DAuMNc7soy/VvbbXyFo1wF9uG2gKpZmutxSF+tsO2z1+SPEW14EtFYg8l5U1AJvtTmJudNL32nbcAFgo1LBTlAniS0MRUVPTsCWjkUldF0Hx4l4y6TZu2n9BKW6PRANwPErgVayd3jU3XxBgrfK3pRoF0ZD5scfwiFsoJIl8uftRrzrIvWe5Eh/d1Azgc05NDPrwI+WSgG186u9ie1ieJis2CdsY59Qsq4YosxrMAdsCRYgqXixapfseHfb10jiVrERj+7vnLVtdGRlTBp7OJfm5O9MA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NW12IGctCHQ59PAs+7VbIe+Nhdv+NxvQBr3aNl1R/eU=; b=CteKe0Mc23WTbrq/q2IDtd67hLJIJtfx0xSJv/ieOP9PSJWKGpuMg178dgCALCg5rWiVMqBLmq9rxH7n0mhu7v/tn6bPZtEJMlthXHRW6AB14j91bo+4qDzZZxr8ya+mQUYqm9407Pf5184Dc1mtmvSp8o7LUcoFkQ0B6RmafSc= Received: from BN6PR18CA0001.namprd18.prod.outlook.com (2603:10b6:404:121::11) by CY4PR12MB1575.namprd12.prod.outlook.com (2603:10b6:910:f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.26; Mon, 7 Mar 2022 21:34:39 +0000 Received: from BN8NAM11FT029.eop-nam11.prod.protection.outlook.com (2603:10b6:404:121:cafe::31) by BN6PR18CA0001.outlook.office365.com (2603:10b6:404:121::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14 via Frontend Transport; Mon, 7 Mar 2022 21:34:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; Received: from SATLEXMB04.amd.com (165.204.84.17) by BN8NAM11FT029.mail.protection.outlook.com (10.13.177.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5038.14 via Frontend Transport; Mon, 7 Mar 2022 21:34:39 +0000 Received: from sbrijesh-desktop.amd.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.18; Mon, 7 Mar 2022 15:34:36 -0600 From: Brijesh Singh To: , , , , , , CC: Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , "Vitaly Kuznetsov" , Jim Mattson , "Andy Lutomirski" , Dave Hansen , Sergio Lopez , Peter Gonda , "Peter Zijlstra" , Srinivas Pandruvada , David Rientjes , Dov Murik , Tobin Feldman-Fitzthum , Borislav Petkov , Michael Roth , Vlastimil Babka , "Kirill A . Shutemov" , Andi Kleen , "Dr . David Alan Gilbert" , , , , , Brijesh Singh , Venu Busireddy Subject: [PATCH v12 11/46] x86/sev: Save the negotiated GHCB version Date: Mon, 7 Mar 2022 15:33:21 -0600 Message-ID: <20220307213356.2797205-12-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220307213356.2797205-1-brijesh.singh@amd.com> References: <20220307213356.2797205-1-brijesh.singh@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: da8d6c11-80d0-4cb5-4539-08da008248db X-MS-TrafficTypeDiagnostic: CY4PR12MB1575:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uKv3AvFGJjl/eUVLhEnrEoDGIFl5CII3dUDDop+9ZY+WFNaeLl0jjlRZblWcnSA6mJewXDzdq+Q3DIdJ7jcFY1SqNDsmKQTZZvovA0vfJRBYu/R9UF24Ln0oNwkvudwFiP+NQymJjYlI9I0KipzGO7yzxhD+cGJFnaPAgnsgsblbEtKi68VIV+7yUuXsp3nfg38emLgOzyDjEigASn4abZL/wnapL6iP8YYW5928K+i/k6PTB/yjOuFYHcAs985Gz7LmmuTrPZxbM+tkmdDjpZ+lela0jnEUbmGp7A94AOSYEXyAnaaI0YFtvtX6Y0jE46bSc7lgeo/Wu81qOKOBwr6ei5VeJXN1hUp/4jgeFFLVJqfaQ1H6ldE0/0kSiLU9FIO4CfB+hdUyX0dkweyinjXlMb1KQblLRcar27Xy5WXqvDNRdS9cuWDRCwyvD1zNH5FqROggolhGqsKdFxQ+wdS+hKNkWIFizaxetjqWjHkMR9C6nl+4TS34+Ql3EZftrhqAtyznSuMb2bcprktE2zRCcJPPWq+HOTkRjbpsPQzk9IpnXflnMhq+qijdwvzPTo9aKmXLd3ow9NKZVh0VAzheYA5acCm8FUCQvn0OQnzyAZMEgUftD2YnkTJhNUizNBUcGC5COVAy297uU+8VFZpaMLbT9L9O7+9kA3NUNSrlABDhvNHTSxFxAZvJ5GyCWppvxa094dYmKnVywsNduh0W67Abprippy1yz15s10A= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230001)(4636009)(36840700001)(46966006)(40470700004)(82310400004)(426003)(336012)(83380400001)(8936002)(4326008)(7696005)(508600001)(86362001)(6666004)(1076003)(70586007)(2616005)(70206006)(8676002)(26005)(186003)(16526019)(316002)(110136005)(54906003)(36756003)(47076005)(36860700001)(40460700003)(7406005)(356005)(7416002)(5660300002)(81166007)(44832011)(2906002)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2022 21:34:39.3799 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: da8d6c11-80d0-4cb5-4539-08da008248db X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT029.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1575 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 SEV-ES guest calls the 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. Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh --- 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 ec060c433589..9b9c190e8c3b 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 2abf8a7d75e5..91105f5a02a8 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); -- 2.25.1