From mboxrd@z Thu Jan 1 00:00:00 1970 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 95F6DC43217 for ; Mon, 7 Mar 2022 21:36:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243727AbiCGVgy (ORCPT ); Mon, 7 Mar 2022 16:36:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36360 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245649AbiCGVgY (ORCPT ); Mon, 7 Mar 2022 16:36:24 -0500 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2072.outbound.protection.outlook.com [40.107.92.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB41288784; Mon, 7 Mar 2022 13:34:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dZCelW6G1qxV0ySTFOaEQUvlugKk9MglBBe9A7+rIqSBLi898lneuwoXsyLOgFHxaQplpcZETc+7Xmk0uLlUC1oXUDxXnZxPYny1Xg4HFnqbEOp0RaQT9kjbSQp0opv3MqqJSgLhICt3G4sDhZB+JJgtwroGfUFE7VJAb6g0FpHI41j7mqrO3Gt83hRTpzz5tWJQ6+GLXqYBeIUH4dRmu2HWKY+dgk7MXZnM+yMvYdoIEZV/uRnCLLzHPFwU2W1QEmLQ5fIfbiFh+vitVw5xZUQmu9AawDJOnMOT6W4N7k4NCwV+hPaMUvyhlqm2hYjJvvkAnS8hqaeUkAk6hZNUvw== 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=dQ99cfpt0m7da6oqy/rXr/yW8LVwNmJ3ynuO/U1I9WU=; b=hXsdbKFzn/wj4/7KYVfkPcow3jLUUr0RjUK4/Nss5m185dO+8GLlMy9GzyJ5bTufmfqO8jTrxx8r1V+a7oGvINKKFGUy+GoYQqTCrz/bHhXrTDeRMd8Q4X7nFrHG86w6od4I7MKqYsNNQj38fBpu8MSNsEnN8FrTJovP69PD/u9K9pQpOhCJf34Hx8rxa2iqmFq/k0yH4VPDGW9ws/uL0UCQk5KKC0bl5fUo5Hvqm36816qeIFx0+WkBjyZnMVPBcwaPjH6uozglcIZU7kmkmrt/XImGCiXb/m+FQ2PrfIlH9h29QJSwzSs0KamcdoixOB7NCmVJJgxogrc8O0/NOg== 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=dQ99cfpt0m7da6oqy/rXr/yW8LVwNmJ3ynuO/U1I9WU=; b=O6GMTIQuyNBCgEn/r6dhZNkmV0jEK6eGlxe3YZqW07RytvZJDP7XaOLMal5Jfu3II0NEW6m6mjLviwMu1CaXpOGKdXKGJ0a7xBEQuy0uYucTF984nngpY0yQ8D3FG/W563j4k72KBvDzNkseVgi1PL/XogQUdomq3p/un5YWQ2M= Received: from BN9PR03CA0364.namprd03.prod.outlook.com (2603:10b6:408:f7::9) by BN8PR12MB3170.namprd12.prod.outlook.com (2603:10b6:408:98::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5038.14; Mon, 7 Mar 2022 21:34:56 +0000 Received: from BN8NAM11FT031.eop-nam11.prod.protection.outlook.com (2603:10b6:408:f7:cafe::d3) by BN9PR03CA0364.outlook.office365.com (2603:10b6:408:f7::9) 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:56 +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 BN8NAM11FT031.mail.protection.outlook.com (10.13.177.25) 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:56 +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:45 -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 16/46] x86/compressed: Register GHCB memory when SEV-SNP is active Date: Mon, 7 Mar 2022 15:33:26 -0600 Message-ID: <20220307213356.2797205-17-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: eabeab00-f93a-451b-75ba-08da008252fe X-MS-TrafficTypeDiagnostic: BN8PR12MB3170: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: WuzsaRaaygPxy1PRsxQhQ162xh17LAcxjukcFrh5sRJs1+bMe4G7qqDMthhJOqOHsi5WafrYaGXogOL0hWPAmaG3rb+0q1dF9EHJdFnGknAkX2Q8Y6SD+HbrV3KbQ7ue4G+KowRAZC0sjJIXpbB1erGkg2+tmoy7cYQZ8+dCFVDt/+JczuLRroPovHcBeisd0unmhq4lMRQN32eEG1+AGzkr0xKOdkJcXf0APZSrWde4iQIy23VxDqs2j0jDsd6JBbww+BZZOvu1Lh/9zV6XSqovwHE2nyHUoN4YChuMo0kAIz6QDTGtt+D3AJAG4NTH+PhmkIkfpHnied6wAlyoD5lYDTzXV7rks+WvHYi/XkITKfNF7vp6adb+KZKEcZGcZgf+lc1C2rN4TJdK76au8AUhtteFFgTd/oakljcpb6ygjENqIld7+qx1xUZjyqhoRk7Dk7daw0WEzY8+wByZwFlCiuGddYunztMSJfvgDV/MfNSn6sTzTBIO3GoLkARNPm4nQSkiaHJdBUJTGJOrvb2VibmXVMh1/BMYmVwPiiwsRsHG6bGpUsd5Dx3N5Akm//CLulw4yMiUR4IJc9iHAe2tiMwWilLm6W4o17eXnSSu8rsoV/RhA9TwL4VGfaWC37QRQuoZTkBiaxXslOCUm50VMgzcbfuzh8M4VsJ3TmWQ18CbMJH/6dqjZzSHJrGDZCNgzbehCe8hH5Fa8kQKZx4Oc+7JZ64rtDTQDum3B+g= 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)(46966006)(36840700001)(40470700004)(40460700003)(70206006)(316002)(336012)(54906003)(8676002)(4326008)(86362001)(44832011)(82310400004)(8936002)(356005)(81166007)(2906002)(2616005)(5660300002)(7416002)(7406005)(426003)(508600001)(70586007)(110136005)(26005)(1076003)(16526019)(186003)(7696005)(6666004)(36860700001)(47076005)(36756003)(36900700001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Mar 2022 21:34:56.3878 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: eabeab00-f93a-451b-75ba-08da008252fe 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: BN8NAM11FT031.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3170 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The SEV-SNP guest is required by the GHCB spec to register the GHCB's Guest Physical Address (GPA). 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 section "GHCB GPA Registration". If hypervisor can not work with the guest provided GPA then terminate the guest boot. Reviewed-by: Venu Busireddy Signed-off-by: Brijesh Singh --- arch/x86/boot/compressed/sev.c | 4 ++++ arch/x86/include/asm/sev-common.h | 13 +++++++++++++ arch/x86/kernel/sev-shared.c | 16 ++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c index 23978d858297..485410a182b0 100644 --- a/arch/x86/boot/compressed/sev.c +++ b/arch/x86/boot/compressed/sev.c @@ -175,6 +175,10 @@ static bool early_setup_ghcb(void) /* Initialize lookup tables for the instruction decoder */ inat_init_tables(); + /* 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 fe7fe16e5fd5..f077a6c95e67 100644 --- a/arch/x86/include/asm/sev-common.h +++ b/arch/x86/include/asm/sev-common.h @@ -57,6 +57,19 @@ #define GHCB_MSR_AP_RESET_HOLD_REQ 0x006 #define GHCB_MSR_AP_RESET_HOLD_RESP 0x007 +/* GHCB GPA Register */ +#define GHCB_MSR_REG_GPA_REQ 0x012 +#define GHCB_MSR_REG_GPA_REQ_VAL(v) \ + /* GHCBData[63:12] */ \ + (((u64)((v) & GENMASK_ULL(51, 0)) << 12) | \ + /* GHCBData[11:0] */ \ + GHCB_MSR_REG_GPA_REQ) + +#define GHCB_MSR_REG_GPA_RESP 0x013 +#define GHCB_MSR_REG_GPA_RESP_VAL(v) \ + /* GHCBData[63:12] */ \ + (((u64)(v) & GENMASK_ULL(63, 12)) >> 12) + /* * SNP Page State Change Operation * diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c index 4a876e684f67..e9ff13cd90b0 100644 --- a/arch/x86/kernel/sev-shared.c +++ b/arch/x86/kernel/sev-shared.c @@ -68,6 +68,22 @@ static u64 get_hv_features(void) return GHCB_MSR_HV_FT_RESP_VAL(val); } +static void __maybe_unused snp_register_ghcb_early(unsigned long paddr) +{ + unsigned long pfn = paddr >> PAGE_SHIFT; + u64 val; + + sev_es_wr_ghcb_msr(GHCB_MSR_REG_GPA_REQ_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_REG_GPA_RESP) || + (GHCB_MSR_REG_GPA_RESP_VAL(val) != pfn)) + sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_REGISTER); +} + static bool sev_es_negotiate_protocol(void) { u64 val; -- 2.25.1