From: "Kalra, Ashish" <ashish.kalra@amd.com>
To: Tom Lendacky <thomas.lendacky@amd.com>,
linux-kernel@vger.kernel.org, x86@kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
Michael Roth <michael.roth@amd.com>,
Nikunj A Dadhania <nikunj@amd.com>,
Neeraj Upadhyay <Neeraj.Upadhyay@amd.com>
Subject: Re: [PATCH v4 5/8] x86/sev: Map only the RMP table entries instead of the full RMP range
Date: Fri, 25 Oct 2024 06:03:45 -0500 [thread overview]
Message-ID: <5cd8e74d-b41b-4280-92d8-0a0c2d834ed8@amd.com> (raw)
In-Reply-To: <915e7d6b2de0c71d8cd9f8902b1ba3ef6ae563cb.1729708922.git.thomas.lendacky@amd.com>
On 10/23/2024 1:41 PM, Tom Lendacky wrote:
> In preparation for support of a segmented RMP table, map only the RMP
> table entries. The RMP bookkeeping area is only ever accessed when
> first enabling SNP and does not need to remain mapped. To accomplish
> this, split the initialization of the RMP bookkeeping area and the
> initialization of the RMP entry area. The RMP bookkeeping area will be
> mapped only while it is being initialized.
>
> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
> ---
> arch/x86/virt/svm/sev.c | 36 +++++++++++++++++++++++++++++++-----
> 1 file changed, 31 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/virt/svm/sev.c b/arch/x86/virt/svm/sev.c
> index d0fca9bb2e12..dd256e76e443 100644
> --- a/arch/x86/virt/svm/sev.c
> +++ b/arch/x86/virt/svm/sev.c
> @@ -168,6 +168,23 @@ void __init snp_fixup_e820_tables(void)
> __snp_fixup_e820_tables(probed_rmp_base + probed_rmp_size);
> }
>
> +static bool __init init_rmptable_bookkeeping(void)
> +{
> + void *bk;
> +
> + bk = memremap(probed_rmp_base, RMPTABLE_CPU_BOOKKEEPING_SZ, MEMREMAP_WB);
> + if (!bk) {
> + pr_err("Failed to map RMP bookkeeping area\n");
> + return false;
> + }
> +
> + memset(bk, 0, RMPTABLE_CPU_BOOKKEEPING_SZ);
> +
> + memunmap(bk);
> +
> + return true;
> +}
> +
> /*
> * Do the necessary preparations which are verified by the firmware as
> * described in the SNP_INIT_EX firmware command description in the SNP
> @@ -205,12 +222,17 @@ static int __init snp_rmptable_init(void)
> goto nosnp;
> }
>
> - rmptable_start = memremap(probed_rmp_base, probed_rmp_size, MEMREMAP_WB);
> + /* Map only the RMP entries */
> + rmptable_start = memremap(probed_rmp_base + RMPTABLE_CPU_BOOKKEEPING_SZ,
> + probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ,
> + MEMREMAP_WB);
> if (!rmptable_start) {
> pr_err("Failed to map RMP table\n");
> goto nosnp;
> }
>
> + rmptable_size = probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ;
> +
> /*
> * Check if SEV-SNP is already enabled, this can happen in case of
> * kexec boot.
> @@ -219,7 +241,14 @@ static int __init snp_rmptable_init(void)
> if (val & MSR_AMD64_SYSCFG_SNP_EN)
> goto skip_enable;
>
> - memset(rmptable_start, 0, probed_rmp_size);
> + /* Zero out the RMP bookkeeping area */
> + if (!init_rmptable_bookkeeping()) {
> + memunmap(rmptable_start);
> + goto nosnp;
> + }
> +
> + /* Zero out the RMP entries */
> + memset(rmptable_start, 0, rmptable_size);
>
> /* Flush the caches to ensure that data is written before SNP is enabled. */
> wbinvd_on_all_cpus();
> @@ -230,9 +259,6 @@ static int __init snp_rmptable_init(void)
> on_each_cpu(snp_enable, NULL, 1);
>
> skip_enable:
> - rmptable_start += RMPTABLE_CPU_BOOKKEEPING_SZ;
> - rmptable_size = probed_rmp_size - RMPTABLE_CPU_BOOKKEEPING_SZ;
> -
> rmptable = (struct rmpentry *)rmptable_start;
> rmptable_max_pfn = rmptable_size / sizeof(struct rmpentry) - 1;
>
Reviewed-by: Ashish Kalra <ashish.kalra@amd.com>
Thanks,
Ashish
next prev parent reply other threads:[~2024-10-25 11:04 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-23 18:41 [PATCH v4 0/8] Provide support for RMPREAD and a segmented RMP Tom Lendacky
2024-10-23 18:41 ` [PATCH v4 1/8] x86/sev: Prepare for using the RMPREAD instruction to access the RMP Tom Lendacky
2024-10-25 9:00 ` Kalra, Ashish
2024-10-25 13:39 ` Tom Lendacky
2024-10-25 12:09 ` Borislav Petkov
2024-10-25 13:47 ` Tom Lendacky
2024-10-25 13:55 ` Borislav Petkov
2024-10-25 13:56 ` Tom Lendacky
2024-10-25 14:03 ` Borislav Petkov
2024-10-23 18:41 ` [PATCH v4 2/8] x86/sev: Add support for the RMPREAD instruction Tom Lendacky
2024-10-25 9:25 ` Kalra, Ashish
2024-10-23 18:41 ` [PATCH v4 3/8] x86/sev: Require the RMPREAD instruction after Zen4 Tom Lendacky
2024-10-25 10:47 ` Kalra, Ashish
2024-10-23 18:41 ` [PATCH v4 4/8] x86/sev: Move the SNP probe routine out of the way Tom Lendacky
2024-10-23 18:41 ` [PATCH v4 5/8] x86/sev: Map only the RMP table entries instead of the full RMP range Tom Lendacky
2024-10-25 11:03 ` Kalra, Ashish [this message]
2024-10-23 18:42 ` [PATCH v4 6/8] x86/sev: Treat the contiguous RMP table as a single RMP segment Tom Lendacky
2024-10-25 11:51 ` Kalra, Ashish
2024-10-25 13:43 ` Tom Lendacky
2024-10-23 18:42 ` [PATCH v4 7/8] x86/sev: Add full support for a segmented RMP table Tom Lendacky
2024-10-23 18:42 ` [PATCH v4 8/8] x86/sev/docs: Document the SNP Reverse Map Table (RMP) Tom Lendacky
2024-10-25 7:18 ` Kalra, Ashish
2024-10-25 6:11 ` [PATCH v4 0/8] Provide support for RMPREAD and a segmented RMP Neeraj Upadhyay
2024-10-25 6:38 ` Nikunj A. Dadhania
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=5cd8e74d-b41b-4280-92d8-0a0c2d834ed8@amd.com \
--to=ashish.kalra@amd.com \
--cc=Neeraj.Upadhyay@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=michael.roth@amd.com \
--cc=mingo@redhat.com \
--cc=nikunj@amd.com \
--cc=tglx@linutronix.de \
--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
all inboxes | Powered by JetHome®