Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp606630pxj; Wed, 2 Jun 2021 07:09:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAUpl3j92TItuOFdpRJXSo/loPFigQ/Px2kMTL2KQxNy7LwsdnLWTdgvFo6crHeJUeuxNZ X-Received: by 2002:aa7:dd98:: with SMTP id g24mr20069594edv.88.1622642962925; Wed, 02 Jun 2021 07:09:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1622642962; cv=pass; d=google.com; s=arc-20160816; b=vMvxmo4yEvHQTcyNZ9e3jA0bNY52HuMqELsQfqHyz8gZjFKsFx1QAT9zp9ka/b4jej Nhvqy6Po3cFbkpQ1n2EAgo63OjKaCfLXHxAVT/NnD+QHQ0A8/vdbP6JxF/dypAuEQE0P 0m6WDljJIZznOfv40KNWrTW8pc4928/K8XD4jUEuT0CRCBzTtG9IAaLmHmLeNf7YbVHr p2wt3gxLdysANGYfA5rNxfy7E8iNApPd5p1FVMnWBcmZWtzFDnUxXX3XG42q7KOxdgvr vdZqHo3IYI6ejSbYPt2/C9PFV0hJnmFhoeRmLat8kISI+IWRzdUelUn4rNqElINxcRTZ qIUA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Wkm+wd0FGqja+GedI6rO+BZXARHGCW6YTHtk4DGiXTs=; b=ZvQ1ERbFO18k6Wns9Q84yReS9jhABaE4vi+WROBT80pveyh5blMwLaJd9QUwwqdJTX 1XLdMrJqv0EIcYcPTRJqZwnRXStEOM5c01FucCZI72i0e0IapZ3wG/EVSYl9MOg2UAkn 3Nqk6Y8VX0jkrVJPOHG1akIFcCS3/SmxSCzIzn8biNhbwamlGbGALxNZhg42jB31R2MS mjahBs0Besc4tElL1dFdOksmiGuULh/S0w5BfhKDtKEkINZR+jbujY+oI59yc+SzFie5 FcA7qhFDiNhV8QxvPG/jEICkldHzBxeF4aKlQ0IQ0uJGo8tz1elU71/o69OdeZqL2Mfa fShQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=4fjUT8YM; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=amd.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z16si8512564ejx.706.2021.06.02.07.08.57; Wed, 02 Jun 2021 07:09:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=4fjUT8YM; arc=pass (i=1 spf=pass spfdomain=amd.com dkim=pass dkdomain=amd.com dmarc=pass fromdomain=amd.com); spf=pass (google.com: domain of linux-crypto-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230037AbhFBOJb (ORCPT + 99 others); Wed, 2 Jun 2021 10:09:31 -0400 Received: from mail-dm6nam11on2061.outbound.protection.outlook.com ([40.107.223.61]:8225 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230458AbhFBOH4 (ORCPT ); Wed, 2 Jun 2021 10:07:56 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T27ptREqty8Wiplqbn4NUNMw6ZcxiGHOsmfHLDbhNuCLywtnsZoAfyQIsytP2DlB1h0r5Wa1GDxCsP/X4Ct1hKxaq7sEPTuKyfDvhM9yAzz8q93IIOj4sH4u7dNeS8FOvrd+66KStColNBnC5BHvQ5nTNOIW2B4ccDmclNksEna+7mRub1PwZPUr5c9OjnKbmEqmcL4di9iekz/epF5/8rkRIhqcw6leWENXSXKw94lUzQ1BYizomQf61isBXk86pYVKbYMCCDQT/6uEr+Ej7elBpULQlxF5uyuUA08591i9MZBh0ry1jH8Km2IfLn6lMPWQ8W+rr64s+72a1V3Arw== 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-SenderADCheck; bh=Wkm+wd0FGqja+GedI6rO+BZXARHGCW6YTHtk4DGiXTs=; b=C/vklcuaMeFs4Fp2TWVsx8u6I/L4SuiThYr5JUog+yAmVN/du1QyzmCC75lR7c0S9q3Stmk/VDkPxX5wfuje5DTh18duEtu0ERCgkctu+sulvnOmbp5h2eotDKjt2ju7utcxCc3f/fbL4wn8PZMMkb8jkvGS0OrcBAWPaPsNY193Eq9PCJvNf43OE2WSiyRVXjNMku//lceYzGBaF0B7zDUQZ6xjlhEAzB7v5tAHgGGleVqmCUrftI50Kf5wFNSQbSjhB26irQezC2FZeE0VkbIRTDhnV43FkcxHKx8AdJWo067N2hO3NSWqTF8N4UprnfxrHLr56voJEOu2PqUCDg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; 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=Wkm+wd0FGqja+GedI6rO+BZXARHGCW6YTHtk4DGiXTs=; b=4fjUT8YM2jfyyQumuz88ZNbhTA3k8i5DLc40KPGvspiPWZ0Da+Rc5CMU15dbji5lTVXaIMTnBcaDREEphdOcJn5MtyoA+OqZF5/IOkGvqHBE2R8nCNHrR5JNzYuSMWjkhPNUKekhoCcbS6S6I0LxW8yIGWrUaFZUQmtPpx57F8M= Authentication-Results: kernel.org; dkim=none (message not signed) header.d=none;kernel.org; dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) by SA0PR12MB4512.namprd12.prod.outlook.com (2603:10b6:806:71::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.21; Wed, 2 Jun 2021 14:04:53 +0000 Received: from SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94]) by SN6PR12MB2718.namprd12.prod.outlook.com ([fe80::9898:5b48:a062:db94%6]) with mapi id 15.20.4173.030; Wed, 2 Jun 2021 14:04:53 +0000 From: Brijesh Singh To: x86@kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-efi@vger.kernel.org, platform-driver-x86@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org Cc: Thomas Gleixner , Ingo Molnar , Joerg Roedel , Tom Lendacky , "H. Peter Anvin" , Ard Biesheuvel , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Andy Lutomirski , Dave Hansen , Sergio Lopez , Peter Gonda , Peter Zijlstra , Srinivas Pandruvada , David Rientjes , tony.luck@intel.com, npmccallum@redhat.com, Brijesh Singh Subject: [PATCH Part1 RFC v3 09/22] x86/compressed: Register GHCB memory when SEV-SNP is active Date: Wed, 2 Jun 2021 09:04:03 -0500 Message-Id: <20210602140416.23573-10-brijesh.singh@amd.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210602140416.23573-1-brijesh.singh@amd.com> References: <20210602140416.23573-1-brijesh.singh@amd.com> Content-Type: text/plain X-Originating-IP: [165.204.77.1] X-ClientProxiedBy: SN6PR05CA0010.namprd05.prod.outlook.com (2603:10b6:805:de::23) To SN6PR12MB2718.namprd12.prod.outlook.com (2603:10b6:805:6f::22) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sbrijesh-desktop.amd.com (165.204.77.1) by SN6PR05CA0010.namprd05.prod.outlook.com (2603:10b6:805:de::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.9 via Frontend Transport; Wed, 2 Jun 2021 14:04:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e162c06a-b768-48a7-0d1e-08d925cf64ab X-MS-TrafficTypeDiagnostic: SA0PR12MB4512: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 53LdoIBVatvIqBpZpkPWHqRAhhtnsZjeU8wMC3hfxm9gXU80nPxJmyvLjWpDr6e5keIxG88VQ7nG3w1ewmp9gjhJ1BgtM32Jy/1wite37OoX34r7ZCOuFu4Xua2Hw2BTUChBF78jpeHXkKFAafsFS5TMIt6l6cXArCVexhqNzVlq0eKu18kX8PT/ArrhV2L/WwdECAPf1HfzjVRE52u5H+5Xz8izpe+Hv6mCzHETW6nlg9PJhn29CTx/+Qa9E4mBjJnVWrA/MswMIbTHLRxrvENGIki31dg1aqQNCLGbMB8PFA8WfEFZAXiITAdSE4UMmgi0sPcl5+2fgXXM6MKOcIb93329jGrlfw5PJMB/1VKS99Ir2202+Nli8Pil6LQyRby0u+tQZXW1CAmxnVCWqBd4fJQMPvuWQ6k4s0hLjZXx4sYz5A815GO9jqwQ7qXYtSH+z3uMMCfz1rhIZk5cTMpSR7mIlXr2L5korkw3KcV5tOaVfA1mK2Jgjv2vbOnKbvpx9FVlCHrdLUCDz9ryVDQzA1GeJTCgVyyjSZSiDG2X2ncmRjYtcjNEvkdxNocMbZczuoGfW7iWVXykmf2VGWDKkHQymu8uW+O8jbVZr/2/kMhBwkVKpWNlQaRX1M50dy2Y5hWZ5Ly5m0P7e7h51Q== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2718.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(376002)(366004)(346002)(396003)(39860400002)(136003)(6666004)(44832011)(7416002)(26005)(2906002)(8676002)(6486002)(7696005)(52116002)(38100700002)(478600001)(956004)(66556008)(186003)(1076003)(36756003)(8936002)(16526019)(66946007)(38350700002)(5660300002)(2616005)(54906003)(4326008)(86362001)(66476007)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?GyhB7dMrnoJv+W3ZiAMKrRPUzYcFP1uvEnc6EB/cA24K7hHgl7dmtXOgnUtf?= =?us-ascii?Q?A1CTyzQVf9PROi5V6zaZ37e4aXfVYg+mbpjD80pwM4IkOZOVKaOnWEoor/nO?= =?us-ascii?Q?DTra0+LUCqXu/i4qH51v2svqqDJVRGJEVtcNjlH/ss7VR0UlYxKnc199QGK9?= =?us-ascii?Q?Vi1xUwJs3Vj3N2flGWjaSIWNl7kpk77w65gvrpe+5JZwYMIsBt4uqZciA4Uo?= =?us-ascii?Q?pAz6POg+5GEYetCEUSGnCuhffXnx6uaZk1Ntoyu7YAkB1hmbd9v5M1pSarj1?= =?us-ascii?Q?Ah4zG9ENCwlbmiR6nDL2ww5eIXsgHERsvbO/Cbyspl1f4RA9ElKMUQn/dkHa?= =?us-ascii?Q?8Exh0neBdEPTigiOGTyZ4NCB4z5m4xVp//m6cWSgnghu6DkONg7KZmAbXO2f?= =?us-ascii?Q?CNxTIbouOPPLCws242Aya9smNcoylUn9DPVuQq8q2p8aPIJ9CCwR5Dp3wMfT?= =?us-ascii?Q?iA4tnSFFtO2xpJWR8/Muw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network-Message-Id: e162c06a-b768-48a7-0d1e-08d925cf64ab X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2718.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 14:04:52.8674 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 7RMZMdqDJ4t/ckVhG0fYH5vmeC9TldAMhVxpJwU/8GPlPAEv9SH1Kj6LkCcuxjPGh5pvWwPRXSGRJUvjcsz7zQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA0PR12MB4512 Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org The SEV-SNP guest is required to perform GHCB GPA registration. This is because the hypervisor may prefer that a guest use a consistent and/or specific GPA for the GHCB associated with a vCPU. For more information, see the GHCB specification. If hypervisor can not work with the guest provided GPA then terminate the guest boot. Signed-off-by: Brijesh Singh --- arch/x86/boot/compressed/sev.c | 4 ++++ arch/x86/include/asm/sev-common.h | 11 +++++++++++ arch/x86/kernel/sev-shared.c | 16 ++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 808fe1f6b170..4acade02267b 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -203,6 +203,10 @@ static bool early_setup_sev_es(void) /* Initialize lookup tables for the instruction decoder */ inat_init_tables(); + /* SEV-SNP guest requires the GHCB GPA must be registered */ + if (sev_snp_enabled()) + snp_register_ghcb_early(__pa(&boot_ghcb_page)); + return true; } diff --git a/arch/x86/include/asm/sev-common.h b/arch/x86/include/asm/sev-common.h index 1424b8ffde0b..ae99a8a756fe 100644 --- a/arch/x86/include/asm/sev-common.h +++ b/arch/x86/include/asm/sev-common.h @@ -75,6 +75,17 @@ #define GHCB_MSR_PSC_ERROR_POS 32 #define GHCB_MSR_PSC_RESP_VAL(val) ((val) >> GHCB_MSR_PSC_ERROR_POS) +/* GHCB GPA Register */ +#define GHCB_MSR_GPA_REG_REQ 0x012 +#define GHCB_MSR_GPA_REG_VALUE_POS 12 +#define GHCB_MSR_GPA_REG_GFN_MASK GENMASK_ULL(51, 0) +#define GHCB_MSR_GPA_REQ_GFN_VAL(v) \ + (((unsigned long)((v) & GHCB_MSR_GPA_REG_GFN_MASK) << GHCB_MSR_GPA_REG_VALUE_POS)| \ + GHCB_MSR_GPA_REG_REQ) + +#define GHCB_MSR_GPA_REG_RESP 0x013 +#define GHCB_MSR_GPA_REG_RESP_VAL(v) ((v) >> GHCB_MSR_GPA_REG_VALUE_POS) + #define GHCB_MSR_TERM_REQ 0x100 #define GHCB_MSR_TERM_REASON_SET_POS 12 #define GHCB_MSR_TERM_REASON_SET_MASK 0xf diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index b8312ad66120..b62226bf51b9 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -77,6 +77,22 @@ static bool get_hv_features(void) return true; } +static void snp_register_ghcb_early(unsigned long paddr) +{ + unsigned long pfn = paddr >> PAGE_SHIFT; + u64 val; + + sev_es_wr_ghcb_msr(GHCB_MSR_GPA_REQ_GFN_VAL(pfn)); + VMGEXIT(); + + val = sev_es_rd_ghcb_msr(); + + /* If the response GPA is not ours then abort the guest */ + if ((GHCB_RESP_CODE(val) != GHCB_MSR_GPA_REG_RESP) || + (GHCB_MSR_GPA_REG_RESP_VAL(val) != pfn)) + sev_es_terminate(1, GHCB_TERM_REGISTER); +} + static bool sev_es_negotiate_protocol(void) { u64 val; -- 2.17.1