Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2924931rwb; Fri, 20 Jan 2023 09:00:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXvmyZBs2g+b90O1+6blhuSSsWdvLPp4Ng4JqoOqAlA9u4nuITWsAaJSAxeRkEU/b5kkSHuA X-Received: by 2002:aa7:8493:0:b0:58d:98e0:79a9 with SMTP id u19-20020aa78493000000b0058d98e079a9mr14687503pfn.34.1674234029315; Fri, 20 Jan 2023 09:00:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1674234029; cv=pass; d=google.com; s=arc-20160816; b=mPlNyDnzsPUCPX9XisQfcJwEN/simST8F3Z5UtB7Xo+9unF6x8nSD0YGqGcScR4H/Y 05Bif7l9GEYww6zFXwweaDke8E3HXrifYSELvLS9dPq6YtVxMBA4WnfW+CA36FBzNPVu hgw9mI8sQdrsek4SlyLayfE7wzvrYzA1WtbiggqK+Ux9OQ3KFQ1YkmIykP7Lmc4Q8d8O 5d3X554zKMEeXt42y18TkzUbi8lcqDD6BXSxoznx5qWYiEfacQAs7e4zCRZirJmPInqj U1cGeeQO0B4ktf9mS7COWcvKOS0OQAz8MPRL5frbSdth/bp93WdFUNyTAuPU3b8dCEcT SYdg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:references:cc:to:from:content-language:subject :user-agent:date:message-id:dkim-signature; bh=jboexqpozZGmsq4ZnZS+tOYzzrbrLJjcLb97dtHdwC8=; b=N9EFnGr1C46qXPLAky4983PsHx/VtEb0I0sA7LH8/wm21SMRCQvlx1zllNBddv3koh kkR3lj7fkayI98Yur/Q4xgbxduFURwJ07g3775ovxm3GJAFUjxio4v8UK+dYuxqbmA43 Znm0KkcH1U7VmMWQd6p2FN0lrzfVFhh0O16dKDknm5HpIMUX/+CnhenN4cJRtd7+TrtM Gc1acJIkylO1Us8G154EJWFhHUBVBvfoGgjXVS4eF2JHlI8fGaG+7nJzmTJgCLO9ITmX 1+Es6AAVKTcTS1vuyp8psYeLHmZmV6qZezc55I0GRQ9qmbRf+YpzIrx4tBZ5PR3NTKrl Ebsg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@amd.com header.s=selector1 header.b=Mh7Bd9oF; 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 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k6-20020aa790c6000000b0056c37608f45si38733858pfk.348.2023.01.20.09.00.07; Fri, 20 Jan 2023 09:00:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto-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=@amd.com header.s=selector1 header.b=Mh7Bd9oF; 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 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-crypto-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=amd.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229974AbjATQvW (ORCPT + 99 others); Fri, 20 Jan 2023 11:51:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229520AbjATQvV (ORCPT ); Fri, 20 Jan 2023 11:51:21 -0500 Received: from NAM10-DM6-obe.outbound.protection.outlook.com (mail-dm6nam10on2086.outbound.protection.outlook.com [40.107.93.86]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 54296C13ED; Fri, 20 Jan 2023 08:51:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FXKmT2P0ke59c2/wAqWXg8dkj1WhDckZ/2qqWodseh3d43uIq8Dfvz1Pqnt6gOuZy0FkI+NVAPDpoTpjYy92XTTvA5sEQps5jw4UAaiHkfyBIR2NKDBK/QomTGfg9PsWojtWV+LzfESMbOao2Gk9he96+YffBwD2K0w8GAAv9DY1rzKoqFZn43PWDOV4arUWXNt44TERCr1xE7Fid45IMiOfmXTiLiUpQmMvCXW0AVuLRHsSBdyaTsXb4tRkituNfhQqgwRZxWAVti16wI44BWE2jkHAFdOGBmJR18QqSk7UWn4WHU5Du27j6/hMfcn4ot2ZnfTjAuW4chM+NRhWCA== 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=jboexqpozZGmsq4ZnZS+tOYzzrbrLJjcLb97dtHdwC8=; b=URvzImj0eY7HZnyzCDkTKfOvniOtDJD18Ft4PSzdJoL4Oq6Df748MaR4L9scUayo/yTuMGYUjRBkypw6PL+WD3fuKQsNvcyiXlpWwHFrKs+jDK8+kBRLP7tcWhXMZrYZiuM9SXHB/InJSP5L+X+TzPe9pdJey55yEr4zGJJ7284lFowmclGtfr6Ahw9L017jeikr3EqR8dx+Jq6w+BKKmVKVTsaTxRA20vNiLLGFGM8sC4OFEnpHcJJfSGBAdOfYxKNF97ggmjheq5h7GzwKPcrwpxNvsyUwGPrA8FAlCCANdlFKPpkVxkySZG6pL0ZPldUKGnTLWG8c7wRe3XJqHA== 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=jboexqpozZGmsq4ZnZS+tOYzzrbrLJjcLb97dtHdwC8=; b=Mh7Bd9oF8UjdHpAZnxXTLjeH2PyyXQAiqbD3JGIrsAbtSSzqZ2jo4L01LeyHKOi0XtGQlkMLmAmVPHOGpXWuTdZBEfwNlMHkzT++r4xI6sxh0TlWFjBoB9eh0q3bp/CtshDnoiyPuw4krIJ7rR4s9lJQ+KB9S1qMRGo5tBP3DaA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; Received: from SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) by DM4PR12MB5215.namprd12.prod.outlook.com (2603:10b6:5:397::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.27; Fri, 20 Jan 2023 16:51:08 +0000 Received: from SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::5317:fa3f:5cbe:45e9]) by SN6PR12MB2767.namprd12.prod.outlook.com ([fe80::5317:fa3f:5cbe:45e9%3]) with mapi id 15.20.5986.023; Fri, 20 Jan 2023 16:51:08 +0000 Message-ID: Date: Fri, 20 Jan 2023 10:51:04 -0600 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Subject: Re: [PATCH RFC v7 14/64] x86/sev: Add the host SEV-SNP initialization support Content-Language: en-US From: "Kalra, Ashish" To: Jeremi Piotrowski , Michael Roth Cc: kvm@vger.kernel.org, linux-coco@lists.linux.dev, linux-mm@kvack.org, linux-crypto@vger.kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de, mingo@redhat.com, jroedel@suse.de, thomas.lendacky@amd.com, hpa@zytor.com, ardb@kernel.org, pbonzini@redhat.com, seanjc@google.com, vkuznets@redhat.com, wanpengli@tencent.com, jmattson@google.com, luto@kernel.org, dave.hansen@linux.intel.com, slp@redhat.com, pgonda@google.com, peterz@infradead.org, srinivas.pandruvada@linux.intel.com, rientjes@google.com, dovmurik@linux.ibm.com, tobin@ibm.com, bp@alien8.de, vbabka@suse.cz, kirill@shutemov.name, ak@linux.intel.com, tony.luck@intel.com, marcorr@google.com, sathyanarayanan.kuppuswamy@linux.intel.com, alpergun@google.com, dgilbert@redhat.com, jarkko@kernel.org, harald@profian.com, Brijesh Singh References: <20221214194056.161492-1-michael.roth@amd.com> <20221214194056.161492-15-michael.roth@amd.com> <20230118155502.GB24742@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <2f786856-982a-1012-f680-9a6c5faee6ea@amd.com> In-Reply-To: <2f786856-982a-1012-f680-9a6c5faee6ea@amd.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-ClientProxiedBy: CH2PR18CA0053.namprd18.prod.outlook.com (2603:10b6:610:55::33) To SN6PR12MB2767.namprd12.prod.outlook.com (2603:10b6:805:75::23) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN6PR12MB2767:EE_|DM4PR12MB5215:EE_ X-MS-Office365-Filtering-Correlation-Id: aa98496b-3c33-47a4-e5d7-08dafb0686de X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: b0a3x0aCxltOBO2PwDb3lr+bCnOTlj0aYzRh8zIkVYlSA63kXihv8DXB7r2YfUqxcy+o1IO1oFyoas0yO9prGcj4Kj+m1CZDfeISi6/ZGlw7i9cX6KQ+FIBJNTQ5YZx3Q+HfYF682PF7nup03CeztJ3Q3UzjGSb7yUnx93c3h1aA5kQbGllUtwKM+Z+Wole6v1fqFTd6ls9peQMsSfxfSJoiC00z9GCIFXL4Ms7u+rSBTde3ANVwxkgKPlS1OKgW+u8O17VybweXfK7oRnErHv6tp5FOynXg/HM6zXC4CvEiKTRk794P8BqiybC4BC63cUpLjrBnfjHMaxR2UtfEbTJyNT/st9BCt+uImgQLrtO/UtDbxxB/uZRMTM1wkrNqj+fmMPLVqWYcWuiYZoPKIXzIoe7JvAQe28dvLa47avT8hxawudMJq/+d233JLz2qmRj/W5ipXkMcKcNIfQoy/FAeoLhIiDiwk1McVJU7x/1QkvSrdP1KuKhkRJcre5PCvJfLEr/3snv8gxIdpz5B+l4MLPQUE/naZJ0SbsyuP/oDrzOGSThwgbkGBTnvxDW8tl88Diwa0QEGYQeS+dQBVw2xLwX0htkYpsf2HXisAgHzxwy+mAhSXq5mCRJdv79a8kBWeN2UL75DV/TYrXvJ/P545fCrljIYI6jSCDd2x0o+UIQiinxyarUEyeflrTx9vVibgFN9ABIyohi8o/bhgYn9UaUr/KHZQnfoMW6QiSM= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SN6PR12MB2767.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(136003)(39860400002)(366004)(346002)(396003)(451199015)(6506007)(478600001)(6636002)(53546011)(31686004)(110136005)(6666004)(6486002)(66476007)(66556008)(66946007)(186003)(316002)(26005)(6512007)(4326008)(7406005)(36756003)(8936002)(2616005)(7416002)(41300700001)(5660300002)(2906002)(83380400001)(86362001)(38100700002)(8676002)(31696002)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?OGtjTWpmd3Avcjh0ZldwSlNzTzl5ZUJWWkpyZXdmVkFYcFhKZ3l1OVE0R0x2?= =?utf-8?B?Tzl2aU1xMGJTcDZTdjZOUzF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GZTOTd5VmFSZk1JYkpvVldwZVdtSzBsNWZMb1FtcFh4SC9FTDJK?= =?utf-8?B?V3FhUXE0aXZUaDljaWtsM2dhQkpBd2cwY2xNcW5EMVZnd083aTM4WEdrN2RI?= =?utf-8?B?ZVVwWGNlbFBOOGFNL0ozbWJMdDdsZDhhUnZpUjhGRm5tZGloSEQyN2taSnZ4?= =?utf-8?B?b1VRU3M0UG5wMnJIdWo5Y2FEL2Z2N0tQMzhyREpOSXdZeXF1WktRNWg0YlJK?= =?utf-8?Q?7zW5Q2QEfzlh2LudkCUBqXFIh?= X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-Network-Message-Id: aa98496b-3c33-47a4-e5d7-08dafb0686de X-MS-Exchange-CrossTenant-AuthSource: SN6PR12MB2767.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Jan 2023 16:51:08.1539 (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: 8iF0Xbjc+89VeGCRewZIwhBzYBoQmQN+02+EktyR3s8M+maabsBA4S+96854xJMzsZU0OMacuyj8gBTV81NPEw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5215 X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS 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-crypto@vger.kernel.org On 1/19/2023 5:59 PM, Kalra, Ashish wrote: > Hello Jeremi, > > On 1/18/2023 9:55 AM, Jeremi Piotrowski wrote: >> On Wed, Dec 14, 2022 at 01:40:06PM -0600, Michael Roth wrote: >>> From: Brijesh Singh >>> >>> The memory integrity guarantees of SEV-SNP are enforced through a new >>> structure called the Reverse Map Table (RMP). The RMP is a single data >>> structure shared across the system that contains one entry for every 4K >>> page of DRAM that may be used by SEV-SNP VMs. The goal of RMP is to >>> track the owner of each page of memory. Pages of memory can be owned by >>> the hypervisor, owned by a specific VM or owned by the AMD-SP. See APM2 >>> section 15.36.3 for more detail on RMP. >>> >>> The RMP table is used to enforce access control to memory. The table >>> itself >>> is not directly writable by the software. New CPU instructions >>> (RMPUPDATE, >>> PVALIDATE, RMPADJUST) are used to manipulate the RMP entries. >>> >>> Based on the platform configuration, the BIOS reserves the memory used >>> for the RMP table. The start and end address of the RMP table must be >>> queried by reading the RMP_BASE and RMP_END MSRs. If the RMP_BASE and >>> RMP_END are not set then disable the SEV-SNP feature. >>> >>> The SEV-SNP feature is enabled only after the RMP table is successfully >>> initialized. >>> >>> Also set SYSCFG.MFMD when enabling SNP as SEV-SNP FW >= 1.51 requires >>> that SYSCFG.MFMD must be se >>> >>> RMP table entry format is non-architectural and it can vary by processor >>> and is defined by the PPR. Restrict SNP support on the known CPU model >>> and family for which the RMP table entry format is currently defined >>> for. >>> >>> Signed-off-by: Brijesh Singh >>> Signed-off-b: Ashish Kalra >>> Signed-off-by: Michael Roth >>> --- >>>   arch/x86/include/asm/disabled-features.h |   8 +- >>>   arch/x86/include/asm/msr-index.h         |  11 +- >>>   arch/x86/kernel/sev.c                    | 180 +++++++++++++++++++++++ >>>   3 files changed, 197 insertions(+), 2 deletions(-) >>> >>> diff --git a/arch/x86/include/asm/disabled-features.h >>> b/arch/x86/include/asm/disabled-features.h >>> index 33d2cd04d254..9b5a2cc8064a 100644 >>> --- a/arch/x86/include/asm/disabled-features.h >>> +++ b/arch/x86/include/asm/disabled-features.h >>> @@ -87,6 +87,12 @@ >>>   # define DISABLE_TDX_GUEST    (1 << (X86_FEATURE_TDX_GUEST & 31)) >>>   #endif >>> +#ifdef CONFIG_AMD_MEM_ENCRYPT >>> +# define DISABLE_SEV_SNP    0 >>> +#else >>> +# define DISABLE_SEV_SNP    (1 << (X86_FEATURE_SEV_SNP & 31)) >>> +#endif >>> + >>>   /* >>>    * Make sure to add features to the correct mask >>>    */ >>> @@ -110,7 +116,7 @@ >>>                DISABLE_ENQCMD) >>>   #define DISABLED_MASK17    0 >>>   #define DISABLED_MASK18    0 >>> -#define DISABLED_MASK19    0 >>> +#define DISABLED_MASK19    (DISABLE_SEV_SNP) >>>   #define DISABLED_MASK_CHECK BUILD_BUG_ON_ZERO(NCAPINTS != 20) >>>   #endif /* _ASM_X86_DISABLED_FEATURES_H */ >>> diff --git a/arch/x86/include/asm/msr-index.h >>> b/arch/x86/include/asm/msr-index.h >>> index 10ac52705892..35100c630617 100644 >>> --- a/arch/x86/include/asm/msr-index.h >>> +++ b/arch/x86/include/asm/msr-index.h >>> @@ -565,6 +565,8 @@ >>>   #define MSR_AMD64_SEV_ENABLED >>> BIT_ULL(MSR_AMD64_SEV_ENABLED_BIT) >>>   #define MSR_AMD64_SEV_ES_ENABLED >>> BIT_ULL(MSR_AMD64_SEV_ES_ENABLED_BIT) >>>   #define MSR_AMD64_SEV_SNP_ENABLED >>> BIT_ULL(MSR_AMD64_SEV_SNP_ENABLED_BIT) >>> +#define MSR_AMD64_RMP_BASE        0xc0010132 >>> +#define MSR_AMD64_RMP_END        0xc0010133 >>>   #define MSR_AMD64_VIRT_SPEC_CTRL    0xc001011f >>> @@ -649,7 +651,14 @@ >>>   #define MSR_K8_TOP_MEM2            0xc001001d >>>   #define MSR_AMD64_SYSCFG        0xc0010010 >>>   #define MSR_AMD64_SYSCFG_MEM_ENCRYPT_BIT    23 >>> -#define MSR_AMD64_SYSCFG_MEM_ENCRYPT >>> BIT_ULL(MSR_AMD64_SYSCFG_MEM_ENCRYPT_BIT) >>> +#define MSR_AMD64_SYSCFG_MEM_ENCRYPT >>> BIT_ULL(MSR_AMD64_SYSCFG_MEM_ENCRYPT_BIT) >>> +#define MSR_AMD64_SYSCFG_SNP_EN_BIT        24 >>> +#define MSR_AMD64_SYSCFG_SNP_EN >>> BIT_ULL(MSR_AMD64_SYSCFG_SNP_EN_BIT) >>> +#define MSR_AMD64_SYSCFG_SNP_VMPL_EN_BIT    25 >>> +#define MSR_AMD64_SYSCFG_SNP_VMPL_EN >>> BIT_ULL(MSR_AMD64_SYSCFG_SNP_VMPL_EN_BIT) >>> +#define MSR_AMD64_SYSCFG_MFDM_BIT        19 >>> +#define MSR_AMD64_SYSCFG_MFDM >>> BIT_ULL(MSR_AMD64_SYSCFG_MFDM_BIT) >>> + >>>   #define MSR_K8_INT_PENDING_MSG        0xc0010055 >>>   /* C1E active bits in int pending message */ >>>   #define K8_INTP_C1E_ACTIVE_MASK        0x18000000 >>> diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c >>> index a428c62330d3..687a91284506 100644 >>> --- a/arch/x86/kernel/sev.c >>> +++ b/arch/x86/kernel/sev.c >>> @@ -22,6 +22,9 @@ >>>   #include >>>   #include >>>   #include >>> +#include >>> +#include >>> +#include >>>   #include >>>   #include >>> @@ -38,6 +41,7 @@ >>>   #include >>>   #include >>>   #include >>> +#include >>>   #define DR7_RESET_VALUE        0x400 >>> @@ -57,6 +61,12 @@ >>>   #define AP_INIT_CR0_DEFAULT        0x60000010 >>>   #define AP_INIT_MXCSR_DEFAULT        0x1f80 >>> +/* >>> + * The first 16KB from the RMP_BASE is used by the processor for the >>> + * bookkeeping, the range needs to be added during the RMP entry >>> lookup. >>> + */ >>> +#define RMPTABLE_CPU_BOOKKEEPING_SZ    0x4000 >>> + >>>   /* For early boot hypervisor communication in SEV-ES enabled guests */ >>>   static struct ghcb boot_ghcb_page __bss_decrypted >>> __aligned(PAGE_SIZE); >>> @@ -69,6 +79,9 @@ static struct ghcb *boot_ghcb __section(".data"); >>>   /* Bitmap of SEV features supported by the hypervisor */ >>>   static u64 sev_hv_features __ro_after_init; >>> +static unsigned long rmptable_start __ro_after_init; >>> +static unsigned long rmptable_end __ro_after_init; >>> + >>>   /* #VC handler runtime per-CPU data */ >>>   struct sev_es_runtime_data { >>>       struct ghcb ghcb_page; >>> @@ -2260,3 +2273,170 @@ static int __init snp_init_platform_device(void) >>>       return 0; >>>   } >>>   device_initcall(snp_init_platform_device); >>> + >>> +#undef pr_fmt >>> +#define pr_fmt(fmt)    "SEV-SNP: " fmt >>> + >>> +static int __mfd_enable(unsigned int cpu) >>> +{ >>> +    u64 val; >>> + >>> +    if (!cpu_feature_enabled(X86_FEATURE_SEV_SNP)) >>> +        return 0; >>> + >>> +    rdmsrl(MSR_AMD64_SYSCFG, val); >>> + >>> +    val |= MSR_AMD64_SYSCFG_MFDM; >>> + >>> +    wrmsrl(MSR_AMD64_SYSCFG, val); >>> + >>> +    return 0; >>> +} >>> + >>> +static __init void mfd_enable(void *arg) >>> +{ >>> +    __mfd_enable(smp_processor_id()); >>> +} >>> + >>> +static int __snp_enable(unsigned int cpu) >>> +{ >>> +    u64 val; >>> + >>> +    if (!cpu_feature_enabled(X86_FEATURE_SEV_SNP)) >>> +        return 0; >>> + >>> +    rdmsrl(MSR_AMD64_SYSCFG, val); >>> + >>> +    val |= MSR_AMD64_SYSCFG_SNP_EN; >>> +    val |= MSR_AMD64_SYSCFG_SNP_VMPL_EN; >>> + >>> +    wrmsrl(MSR_AMD64_SYSCFG, val); >>> + >>> +    return 0; >>> +} >>> + >>> +static __init void snp_enable(void *arg) >>> +{ >>> +    __snp_enable(smp_processor_id()); >>> +} >>> + >>> +static bool get_rmptable_info(u64 *start, u64 *len) >>> +{ >>> +    u64 calc_rmp_sz, rmp_sz, rmp_base, rmp_end; >>> + >>> +    rdmsrl(MSR_AMD64_RMP_BASE, rmp_base); >>> +    rdmsrl(MSR_AMD64_RMP_END, rmp_end); >>> + >>> +    if (!rmp_base || !rmp_end) { >>> +        pr_err("Memory for the RMP table has not been reserved by >>> BIOS\n"); >>> +        return false; >>> +    } >>> + >>> +    rmp_sz = rmp_end - rmp_base + 1; >>> + >>> +    /* >>> +     * Calculate the amount the memory that must be reserved by the >>> BIOS to >>> +     * address the whole RAM. The reserved memory should also cover the >>> +     * RMP table itself. >>> +     */ >>> +    calc_rmp_sz = (((rmp_sz >> PAGE_SHIFT) + totalram_pages()) << 4) >>> + RMPTABLE_CPU_BOOKKEEPING_SZ; >> >> Since the rmptable is indexed by page number, I believe this check >> should be >> using max_pfn: >> >>      calc_rmp_sz = (max_pfn << 4) + RMPTABLE_CPU_BOOKKEEPING_SZ; >> >> This accounts for holes/offsets in the memory map which lead to the >> top of >> memory having pfn > totalram_pages(). >> > > I agree that this check should use max. addressable pfn to account for > holes in the physical address map. The BIOS will probably also be > computing RMP table size to cover the entire physical memory, which > should be max. addressable PFN. > > But, then we primarly need to check that all available RAM pages are > covered by the RMP table, so the above check is sufficient for that, > right ? > > Also, i assume that max_pfn will take into account any hotplugged memory > as i do know that totalram_pages() handles hotplugged memory. > But essentially you are correct, as RMP table is indexed by PFN, we have to take into account these physical memory holes so that we can have entries for the max DRAM SPA, so i will fix this to use the max. addressable PFN, i.e., max_pfn. Thanks, Ashish > >>> + >>> +    if (calc_rmp_sz > rmp_sz) { >>> +        pr_err("Memory reserved for the RMP table does not cover >>> full system RAM (expected 0x%llx got 0x%llx)\n", >>> +               calc_rmp_sz, rmp_sz); >>> +        return false; >>> +    } >>> + >>> +    *start = rmp_base; >>> +    *len = rmp_sz; >>> + >>> +    pr_info("RMP table physical address [0x%016llx - 0x%016llx]\n", >>> rmp_base, rmp_end); >>> + >>> +    return true; >>> +} >>> +