From: "Aithal, Srikanth" <sraithal@amd.com>
To: Ashish Kalra <Ashish.Kalra@amd.com>, linux-tip-commits@vger.kernel.org
Cc: bp@alien8.de, thomas.lendacky@amd.com, michael.roth@amd.com,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86/sev: Apply RMP table fixups for kexec.
Date: Wed, 13 Mar 2024 16:28:37 +0530 [thread overview]
Message-ID: <f152da91-816e-4791-9afb-51f189acdbd6@amd.com> (raw)
In-Reply-To: <20240312184757.52699-1-Ashish.Kalra@amd.com>
On 3/13/2024 12:17 AM, Ashish Kalra wrote:
> From: Ashish Kalra <ashish.kalra@amd.com>
>
> RMP table start and end physical range may not be aligned to 2MB in
> the e820 tables causing fatal RMP page faults during kexec boot when
> new page allocations are done in the same 2MB page as the RMP table.
> Check if RMP table start and end physical range in e820_table is not
> aligned to 2MB and in that case use e820__range_update() to map this
> range to reserved.
>
> Override e820__memory_setup_default() to check and apply these RMP table
> fixups in e820_table before e820_table is used to setup
> e280_table_firmware and e820_table_kexec.
>
> Fixes: c3b86e61b756 ("x86/cpufeatures: Enable/unmask SEV-SNP CPU feature")
> Signed-off-by: Ashish Kalra <ashish.kalra@amd.com>
> ---
> arch/x86/virt/svm/sev.c | 52 +++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 52 insertions(+)
>
> diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
> index cffe1157a90a..e0d7584df28f 100644
> --- a/arch/x86/virt/svm/sev.c
> +++ b/arch/x86/virt/svm/sev.c
> @@ -65,6 +65,8 @@ static u64 probed_rmp_base, probed_rmp_size;
> static struct rmpentry *rmptable __ro_after_init;
> static u64 rmptable_max_pfn __ro_after_init;
>
> +static char *__init snp_rmptable_e820_fixup(void);
> +
> static LIST_HEAD(snp_leaked_pages_list);
> static DEFINE_SPINLOCK(snp_leaked_pages_list_lock);
>
> @@ -160,9 +162,59 @@ bool snp_probe_rmptable_info(void)
> pr_info("RMP table physical range [0x%016llx - 0x%016llx]\n",
> probed_rmp_base, probed_rmp_base + probed_rmp_size - 1);
>
> + /*
> + * Override e820__memory_setup_default() to do any RMP table fixups
> + * for kexec if required.
> + */
> + x86_init.resources.memory_setup = snp_rmptable_e820_fixup;
> +
> return true;
> }
>
> +/*
> + * Override e820__memory_setup_default() to do any RMP table fixups
> + * in e820_table before e820_table_firmware and e820_table_kexec
> + * are setup.
> + */
> +static char *__init snp_rmptable_e820_fixup(void)
> +{
> + /* Populate e820_table from BIOS-supplied e820 map */
> + char *p = e820__memory_setup_default();
> + u64 pa;
> +
> + /*
> + * RMP table start & end physical range may not be aligned to 2MB in the
> + * e820 tables causing fatal RMP page faults during kexec boot when new
> + * page allocations are done in the same 2MB page as the RMP table.
> + * Check if RMP table start & end physical range in e820_table is not aligned
> + * to 2MB and in that case use e820__range_update() to map this range to reserved,
> + * e820__range_update() nicely handles partial range update and also
> + * merges any consecutive ranges of the same type.
> + * Need to override e820__memory_setup_default() to check and apply
> + * fixups in e820_table before e820_table is used to setup
> + * e280_table_firmware and e820_table_kexec.
> + */
> + pa = probed_rmp_base;
> + if (!IS_ALIGNED(pa, PMD_SIZE)) {
> + pa = ALIGN_DOWN(pa, PMD_SIZE);
> + if (e820__mapped_any(pa, pa + PMD_SIZE, E820_TYPE_RAM)) {
> + pr_info("Reserving start of RMP table on a 2MB boundary [0x%016llx]\n", pa);
> + e820__range_update(pa, PMD_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED);
> + }
> + }
> +
> + pa = probed_rmp_base + probed_rmp_size;
> + if (!IS_ALIGNED(pa, PMD_SIZE)) {
> + pa = ALIGN_DOWN(pa, PMD_SIZE);
> + if (e820__mapped_any(pa, pa + PMD_SIZE, E820_TYPE_RAM)) {
> + pr_info("Reserving end of RMP table on a 2MB boundary [0x%016llx]\n", pa);
> + e820__range_update(pa, PMD_SIZE, E820_TYPE_RAM, E820_TYPE_RESERVED);
> + }
> + }
> +
> + return p;
> +}
> +
> /*
> * Do the necessary preparations which are verified by the firmware as
> * described in the SNP_INIT_EX firmware command description in the SNP
Tested this patch, it fixes the kexec issue reported. Thank you.
Tested-by: Srikanth Aithal <sraithal@amd.com>
next prev parent reply other threads:[~2024-03-13 10:58 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-12 18:47 [PATCH] x86/sev: Apply RMP table fixups for kexec Ashish Kalra
2024-03-13 10:58 ` Aithal, Srikanth [this message]
2024-04-02 14:45 ` bp
2024-04-02 15:54 ` Tom Lendacky
2024-04-02 16:34 ` bp
2024-04-02 17:06 ` Kalra, Ashish
2024-04-02 17:11 ` Kalra, Ashish
2024-04-02 17:45 ` Borislav Petkov
2024-04-02 18:41 ` Kalra, Ashish
2024-04-02 18:50 ` Borislav Petkov
2024-04-02 19:33 ` Kalra, Ashish
2024-04-02 20:21 ` Borislav Petkov
2024-04-02 21:00 ` Kalra, Ashish
2024-04-02 21:17 ` Kalra, Ashish
2024-04-02 21:20 ` Borislav Petkov
2024-04-02 21:31 ` Kalra, Ashish
2024-04-02 21:40 ` Borislav Petkov
2024-04-02 22:09 ` Tom Lendacky
2024-04-02 22:31 ` Kalra, Ashish
2024-04-02 22:42 ` Michael Roth
2024-04-03 21:08 ` Kalra, Ashish
2024-04-04 8:17 ` Jeremi Piotrowski
2024-04-04 18:07 ` Kalra, Ashish
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f152da91-816e-4791-9afb-51f189acdbd6@amd.com \
--to=sraithal@amd.com \
--cc=Ashish.Kalra@amd.com \
--cc=bp@alien8.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=thomas.lendacky@amd.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox