From patchwork Thu Feb 24 16:55:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brijesh Singh X-Patchwork-Id: 12758962 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F63EC433EF for ; Thu, 24 Feb 2022 16:59:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231290AbiBXQ7h (ORCPT ); Thu, 24 Feb 2022 11:59:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231458AbiBXQ7Q (ORCPT ); Thu, 24 Feb 2022 11:59:16 -0500 Received: from NAM04-MW2-obe.outbound.protection.outlook.com (mail-mw2nam08on2058.outbound.protection.outlook.com [40.107.101.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 208F96D841; Thu, 24 Feb 2022 08:58:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AWt/2PREPAGG0KMkMcxlf7P4Z3MBzz1SilUhJv2sBXQtVcAbQoCf9yAzc9gz4GQMCL8YLjkNmPm+i8tqUX4SeC0Jduqp71gfge4Qx2SQ0ej3AY/wZFnws88Kf91/gzFFqwH1XpKDAfgSkKC+E0WO6feVvufdWfAAivCIifM7xv2ORlWtCGEqCoCPhEPNFO4XKwV84pTy5DFV5Rdes1K+T6/2dd5cCYIF+kqK9jym2oqOOxa/Iz01iVj4iv4Gq5TSC+1buEQimG8oGXAFs7fokfTD1e/QEvSHtw4B5jN3SXTOX+AXROQPCpu2gRoAJ5S3xiVSVmGyBMSyTVwdtBFSyg== 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=MriIQFjpVo5GQhnMhkhGMZD8LYkmiW1LeAmkrlk5JMAd/Sf/8IpqzfpJ0EFbzGnjCZFLRReMGaNdlIKhKHDuBx7MIFJg2L2+PbjKG3s+Fb0CAtRDv0hB+WxvQGkb8II7k30dviFqXBOML7h4TkB758iCjGduH07b26YjEOA6B8926GWI7HN1N3M0JIeeICw9tKwrIKrLJma8Isuu/p5xQG+hJC6QY42uEaqsAAOCMQWPqdRXjLfYK500K2NJCnF2fcMUWttSBa2uQlCUthm9ACIbfOXzlf5WrBwdwuEFQnQyHRciAlvRFcxm8p7x2RvEu9vEooRkhxV5NC+GvFjnWg== 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=Ocr4QsaeWh3bqcr+TLJ91kdil/cQ4ko4r+wP85c3EiEOrgK4wYpZoKw169Jx+D2/KgciWCUl0mXFqDH1NvBtIhjcp8BXlKYRNAIF8C/uw40tdu7AxUPpXfBsR0V6eS6r8e/NDCJI/CBCvGRDMv8f3lDbyPZSOWmqYZAXH869moM= Received: from DM6PR02CA0136.namprd02.prod.outlook.com (2603:10b6:5:1b4::38) by BN6PR12MB1457.namprd12.prod.outlook.com (2603:10b6:405:10::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.21; Thu, 24 Feb 2022 16:58:23 +0000 Received: from DM6NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:5:1b4:cafe::6) by DM6PR02CA0136.outlook.office365.com (2603:10b6:5:1b4::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 16:58:23 +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 DM6NAM11FT063.mail.protection.outlook.com (10.13.172.219) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.5017.22 via Frontend Transport; Thu, 24 Feb 2022 16:58:23 +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; Thu, 24 Feb 2022 10:58:11 -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 v11 11/45] x86/sev: Save the negotiated GHCB version Date: Thu, 24 Feb 2022 10:55:51 -0600 Message-ID: <20220224165625.2175020-12-brijesh.singh@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220224165625.2175020-1-brijesh.singh@amd.com> References: <20220224165625.2175020-1-brijesh.singh@amd.com> MIME-Version: 1.0 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: 2e2e5a52-2bd2-461e-0074-08d9f7b6de2c X-MS-TrafficTypeDiagnostic: BN6PR12MB1457: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: gtnA7zc0hSXbGZ1dtqDjerU1dL4A/YgYYaiV+qPfp6phvZgLO+GOgEDGAR/C6pHQbnURcptQIC5LbXC+Skky3CGs5sAuL4DeDz4Tk1nwwbRVEYg7sNsbTFaLWrk5BcC6hhE7mcRqxyiKP7rZrxCGVAhvBJ9jcx4rN2RwtZllS9so6B3NrIiOy3qx6rvo7oREPNGNYnGX7OA/nE2v5XoovU2b7MhzpzXetbXl8+LoNpo6jcSoTgtxULKhNqDA9ONwOJjMgFlFp+WqMfJd/swHUQUpHVTh98nXV2UDJaRaK5Bk8p2mSe2EESnVJuybEH40lgcPmipetNOlsh7jvhzdUxlbgjMHi0szdoY6DuMZENW7/R5dpnUp5r97wa2nrQLFUoSikEeoip+6dWdK4tskPfiFUIjvY/q0NOzbhhciWc7g0b9QLcDFTyjlAtbEc2Vg2m6dz6xAiIQrNYXTRie2zOoSUHZKz98UbvKZjKmBoQ2gsGfOp9ChOVdjuUWiEHCHqWYKh8N5ersFkpAtaiTcedI5u/VHfgyhGdsaBd9tVuCNLeXeGCYzMMHCwcOVBLMSZYO4mxw0Yc1U2bFbAPYhM/w/DYSaTWNtrFw71RDP5Q8OMLqWy2zBDptfARvefDdSBeQcjrCchxA6/OAvFFG5NCMERPOQ06BwtNHnR4HgpWFmC6KYFXrf5s67Tslppc+sVBcSguSlrqaU/cR/wCYsMCSEklfASQMYOiGzR0FejNw= 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)(40470700004)(46966006)(186003)(426003)(7696005)(110136005)(54906003)(26005)(316002)(47076005)(83380400001)(6666004)(82310400004)(336012)(36860700001)(86362001)(2616005)(1076003)(508600001)(2906002)(16526019)(40460700003)(8936002)(5660300002)(7416002)(7406005)(70206006)(44832011)(356005)(8676002)(81166007)(4326008)(70586007)(36756003)(2101003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Feb 2022 16:58:23.0670 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2e2e5a52-2bd2-461e-0074-08d9f7b6de2c 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: DM6NAM11FT063.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1457 Precedence: bulk List-ID: X-Mailing-List: kvm@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);