From: Tom Lendacky <thomas.lendacky@amd.com>
To: Dave Hansen <dave.hansen@intel.com>,
Borislav Petkov <bp@alien8.de>,
"Shutemov, Kirill" <kirill.shutemov@intel.com>,
Ashish Kalra <ashish.kalra@amd.com>,
Kai Huang <kai.huang@intel.com>
Cc: LKML <linux-kernel@vger.kernel.org>,
the arch/x86 maintainers <x86@kernel.org>
Subject: Re: AMD Memory encryption vs. kexec
Date: Tue, 28 Nov 2023 08:03:02 -0600 [thread overview]
Message-ID: <29e235f7-add2-47ae-b06e-a717202c4faf@amd.com> (raw)
In-Reply-To: <82b2e0d5-edcc-44f3-b759-d6b8c8788ea6@intel.com>
On 11/27/23 18:00, Dave Hansen wrote:
> ... actually cc'd the mailing lists and x86@ exploder on this one.
> Please reply here.
>
> ---
>
> There are two kexec-related wbinvd's:
>
> One for the kexec boot CPU in relocate_kernel() which is driven by
> CC_ATTR_HOST_MEM_ENCRYPT:
>
>> image->start = relocate_kernel((unsigned long)image->head,
>> (unsigned long)page_list,
>> image->start,
>> image->preserve_context,
>> cc_platform_has(CC_ATTR_HOST_MEM_ENCRYPT));
>
> the other is for non-boot CPUs in stop_this_cpu():
>
>> if (c->extended_cpuid_level >= 0x8000001f && (cpuid_eax(0x8000001f) & BIT(0)))
>> native_wbinvd();
>
> By my reading, the CC_ATTR_HOST_MEM_ENCRYPT is basically a check for
> whether the current kernel has enabled SME but not SEV while the
> stop_this_cpu() site is driven purely by whether the hardware *supports*
> SME.
>
> The whole supposed reason stop_this_cpu() checks CPUID directly is that
> the current kernel SME/SEV enabling might not match the _next_ kernel's
> enabling choices.
Correct.
>
> So, why is a _current_ kernel check OK for relocate_kernel(), but not OK
> for stop_this_cpu()?
The relocate_kernel() check provides an indication of whether SME is
actually active. The kexec kernel is placed in unencrypted memory to match
how the system was booted - where the kernel is loaded into unencrypted
memory and then encrypted in-place if SME is desired (mem_encrypt=on).
Since the kexec kernel will be unencrypted, the cc_platform_has() call is
used to indicate whether to perform a wbinvd to remove encrypted cache
line entries. If SME is not active, then there is no need to flush caches
prior to booting the kexec kernel.
With SEV, the kernel is loaded encrypted from the start and so the kexec
kernel can remain in encrypted memory and no wbinvd is required.
Thanks,
Tom
>
> It seems to me like both sites might need to use the
> stop_this_cpu()-style "raw" hardware support checks.
>
> Why do I care? TDX potentially needs wbinvd at the same two spots. It
> would be nice to have a common cc_attr for both sites, but I need to
> reconcile the apparently disparate AMD uses first.
next prev parent reply other threads:[~2023-11-28 14:03 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-28 0:00 Dave Hansen
2023-11-28 14:03 ` Tom Lendacky [this message]
2023-11-29 20:01 ` Dave Hansen
2023-11-29 20:54 ` Tom Lendacky
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=29e235f7-add2-47ae-b06e-a717202c4faf@amd.com \
--to=thomas.lendacky@amd.com \
--cc=ashish.kalra@amd.com \
--cc=bp@alien8.de \
--cc=dave.hansen@intel.com \
--cc=kai.huang@intel.com \
--cc=kirill.shutemov@intel.com \
--cc=linux-kernel@vger.kernel.org \
--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®