* [PATCH] x86/sev: Guard sev_evict_cache() with CONFIG_AMD_MEM_ENCRYPT
@ 2025-09-12 20:29 Tom Lendacky
2025-09-12 20:39 ` Michael Roth
2025-09-12 20:42 ` Borislav Petkov
0 siblings, 2 replies; 7+ messages in thread
From: Tom Lendacky @ 2025-09-12 20:29 UTC (permalink / raw)
To: linux-kernel, x86
Cc: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen,
Michael Roth, Sean Christopherson, stable
The sev_evict_cache() is guest-related code and should be guarded by
CONFIG_AMD_MEM_ENCRYPT, not CONFIG_KVM_AMD_SEV. Move the function
declarations under the appropriate #ifdef.
Fixes: 7b306dfa326f ("x86/sev: Evict cache lines during SNP memory validation")
Cc: <stable@kernel.org>
Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
---
arch/x86/include/asm/sev.h | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)
diff --git a/arch/x86/include/asm/sev.h b/arch/x86/include/asm/sev.h
index 00475b814ac4..e5a7e0ebdc73 100644
--- a/arch/x86/include/asm/sev.h
+++ b/arch/x86/include/asm/sev.h
@@ -579,6 +579,24 @@ struct psc_desc {
u64 caa_pa;
};
+static inline void sev_evict_cache(void *va, int npages)
+{
+ volatile u8 val __always_unused;
+ u8 *bytes = va;
+ int page_idx;
+
+ /*
+ * For SEV guests, a read from the first/last cache-lines of a 4K page
+ * using the guest key is sufficient to cause a flush of all cache-lines
+ * associated with that 4K page without incurring all the overhead of a
+ * full CLFLUSH sequence.
+ */
+ for (page_idx = 0; page_idx < npages; page_idx++) {
+ val = bytes[page_idx * PAGE_SIZE];
+ val = bytes[page_idx * PAGE_SIZE + PAGE_SIZE - 1];
+ }
+}
+
#else /* !CONFIG_AMD_MEM_ENCRYPT */
#define snp_vmpl 0
@@ -624,6 +642,7 @@ static inline enum es_result savic_register_gpa(u64 gpa) { return ES_UNSUPPORTED
static inline enum es_result savic_unregister_gpa(u64 *gpa) { return ES_UNSUPPORTED; }
static inline void savic_ghcb_msr_write(u32 reg, u64 value) { }
static inline u64 savic_ghcb_msr_read(u32 reg) { return 0; }
+static inline void sev_evict_cache(void *va, int npages) {}
#endif /* CONFIG_AMD_MEM_ENCRYPT */
@@ -638,24 +657,6 @@ int rmp_make_shared(u64 pfn, enum pg_level level);
void snp_leak_pages(u64 pfn, unsigned int npages);
void kdump_sev_callback(void);
void snp_fixup_e820_tables(void);
-
-static inline void sev_evict_cache(void *va, int npages)
-{
- volatile u8 val __always_unused;
- u8 *bytes = va;
- int page_idx;
-
- /*
- * For SEV guests, a read from the first/last cache-lines of a 4K page
- * using the guest key is sufficient to cause a flush of all cache-lines
- * associated with that 4K page without incurring all the overhead of a
- * full CLFLUSH sequence.
- */
- for (page_idx = 0; page_idx < npages; page_idx++) {
- val = bytes[page_idx * PAGE_SIZE];
- val = bytes[page_idx * PAGE_SIZE + PAGE_SIZE - 1];
- }
-}
#else
static inline bool snp_probe_rmptable_info(void) { return false; }
static inline int snp_rmptable_init(void) { return -ENOSYS; }
@@ -671,7 +672,6 @@ static inline int rmp_make_shared(u64 pfn, enum pg_level level) { return -ENODEV
static inline void snp_leak_pages(u64 pfn, unsigned int npages) {}
static inline void kdump_sev_callback(void) { }
static inline void snp_fixup_e820_tables(void) {}
-static inline void sev_evict_cache(void *va, int npages) {}
#endif
#endif
base-commit: fc1ded58808520a1ced0c4e2e5fb0dbd33b33612
--
2.46.2
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] x86/sev: Guard sev_evict_cache() with CONFIG_AMD_MEM_ENCRYPT
2025-09-12 20:29 [PATCH] x86/sev: Guard sev_evict_cache() with CONFIG_AMD_MEM_ENCRYPT Tom Lendacky
@ 2025-09-12 20:39 ` Michael Roth
2025-09-12 20:42 ` Borislav Petkov
1 sibling, 0 replies; 7+ messages in thread
From: Michael Roth @ 2025-09-12 20:39 UTC (permalink / raw)
To: Tom Lendacky
Cc: linux-kernel, x86, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
Dave Hansen, Sean Christopherson, stable
On Fri, Sep 12, 2025 at 03:29:19PM -0500, Tom Lendacky wrote:
> The sev_evict_cache() is guest-related code and should be guarded by
> CONFIG_AMD_MEM_ENCRYPT, not CONFIG_KVM_AMD_SEV. Move the function
> declarations under the appropriate #ifdef.
>
> Fixes: 7b306dfa326f ("x86/sev: Evict cache lines during SNP memory validation")
> Cc: <stable@kernel.org>
> Signed-off-by: Tom Lendacky <thomas.lendacky@amd.com>
Reviewed-by: Michael Roth <michael.roth@amd.com>
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] x86/sev: Guard sev_evict_cache() with CONFIG_AMD_MEM_ENCRYPT
2025-09-12 20:29 [PATCH] x86/sev: Guard sev_evict_cache() with CONFIG_AMD_MEM_ENCRYPT Tom Lendacky
2025-09-12 20:39 ` Michael Roth
@ 2025-09-12 20:42 ` Borislav Petkov
2025-09-12 20:49 ` Michael Roth
1 sibling, 1 reply; 7+ messages in thread
From: Borislav Petkov @ 2025-09-12 20:42 UTC (permalink / raw)
To: Tom Lendacky
Cc: linux-kernel, x86, Thomas Gleixner, Ingo Molnar, Dave Hansen,
Michael Roth, Sean Christopherson, stable
On Fri, Sep 12, 2025 at 03:29:19PM -0500, Tom Lendacky wrote:
> The sev_evict_cache() is guest-related code and should be guarded by
> CONFIG_AMD_MEM_ENCRYPT, not CONFIG_KVM_AMD_SEV. Move the function
> declarations under the appropriate #ifdef.
>
> Fixes: 7b306dfa326f ("x86/sev: Evict cache lines during SNP memory validation")
> Cc: <stable@kernel.org>
Do we really want this in stable?
I haven't seen any breakages from it...
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] x86/sev: Guard sev_evict_cache() with CONFIG_AMD_MEM_ENCRYPT
2025-09-12 20:42 ` Borislav Petkov
@ 2025-09-12 20:49 ` Michael Roth
2025-09-12 21:02 ` Borislav Petkov
0 siblings, 1 reply; 7+ messages in thread
From: Michael Roth @ 2025-09-12 20:49 UTC (permalink / raw)
To: Borislav Petkov
Cc: Tom Lendacky, linux-kernel, x86, Thomas Gleixner, Ingo Molnar,
Dave Hansen, Sean Christopherson, stable
On Fri, Sep 12, 2025 at 10:42:03PM +0200, Borislav Petkov wrote:
> On Fri, Sep 12, 2025 at 03:29:19PM -0500, Tom Lendacky wrote:
> > The sev_evict_cache() is guest-related code and should be guarded by
> > CONFIG_AMD_MEM_ENCRYPT, not CONFIG_KVM_AMD_SEV. Move the function
> > declarations under the appropriate #ifdef.
> >
> > Fixes: 7b306dfa326f ("x86/sev: Evict cache lines during SNP memory validation")
> > Cc: <stable@kernel.org>
>
> Do we really want this in stable?
>
> I haven't seen any breakages from it...
I think that's actually the concerning thing. If someone built a guest
kernel with CONFIG_KVM_AMD_SEV=y they might be under the impression that
this is performing evictions when it's actually just a stub function.
-Mike
>
> --
> Regards/Gruss,
> Boris.
>
> https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] x86/sev: Guard sev_evict_cache() with CONFIG_AMD_MEM_ENCRYPT
2025-09-12 20:49 ` Michael Roth
@ 2025-09-12 21:02 ` Borislav Petkov
2025-09-13 14:29 ` Tom Lendacky
0 siblings, 1 reply; 7+ messages in thread
From: Borislav Petkov @ 2025-09-12 21:02 UTC (permalink / raw)
To: Michael Roth
Cc: Tom Lendacky, linux-kernel, x86, Thomas Gleixner, Ingo Molnar,
Dave Hansen, Sean Christopherson, stable
On Fri, Sep 12, 2025 at 03:49:29PM -0500, Michael Roth wrote:
> I think that's actually the concerning thing. If someone built a guest
> kernel with CONFIG_KVM_AMD_SEV=y they might be under the impression that
> this is performing evictions when it's actually just a stub function.
That sooo needs to be in the commit message...
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH] x86/sev: Guard sev_evict_cache() with CONFIG_AMD_MEM_ENCRYPT
2025-09-12 21:02 ` Borislav Petkov
@ 2025-09-13 14:29 ` Tom Lendacky
2025-09-13 15:38 ` Borislav Petkov
0 siblings, 1 reply; 7+ messages in thread
From: Tom Lendacky @ 2025-09-13 14:29 UTC (permalink / raw)
To: Borislav Petkov, Michael Roth
Cc: linux-kernel, x86, Thomas Gleixner, Ingo Molnar, Dave Hansen,
Sean Christopherson, stable
On 9/12/25 16:02, Borislav Petkov wrote:
> On Fri, Sep 12, 2025 at 03:49:29PM -0500, Michael Roth wrote:
>> I think that's actually the concerning thing. If someone built a guest
>> kernel with CONFIG_KVM_AMD_SEV=y they might be under the impression that
>> this is performing evictions when it's actually just a stub function.
>
> That sooo needs to be in the commit message...
I can send a v2 or if you want to modify the commit message with the
following:
The sev_evict_cache() is guest-related code and should be guarded by
CONFIG_AMD_MEM_ENCRYPT, not CONFIG_KVM_AMD_SEV.
CONFIG_AMD_MEM_ENCRYPT=y is required for a guest to run properly as an
SEV-SNP guest, but a guest kernel built with CONFIG_KVM_AMD_SEV=n would
get the stub function of sev_evict_cache() instead of the version that
performs the actual eviction. Move the function declarations under the
appropriate #ifdef.
Let me know.
Thanks,
Tom
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] x86/sev: Guard sev_evict_cache() with CONFIG_AMD_MEM_ENCRYPT
2025-09-13 14:29 ` Tom Lendacky
@ 2025-09-13 15:38 ` Borislav Petkov
0 siblings, 0 replies; 7+ messages in thread
From: Borislav Petkov @ 2025-09-13 15:38 UTC (permalink / raw)
To: Tom Lendacky
Cc: Michael Roth, linux-kernel, x86, Thomas Gleixner, Ingo Molnar,
Dave Hansen, Sean Christopherson, stable
On Sat, Sep 13, 2025 at 09:29:47AM -0500, Tom Lendacky wrote:
> On 9/12/25 16:02, Borislav Petkov wrote:
> > On Fri, Sep 12, 2025 at 03:49:29PM -0500, Michael Roth wrote:
> >> I think that's actually the concerning thing. If someone built a guest
> >> kernel with CONFIG_KVM_AMD_SEV=y they might be under the impression that
> >> this is performing evictions when it's actually just a stub function.
> >
> > That sooo needs to be in the commit message...
>
> I can send a v2 or if you want to modify the commit message with the
> following:
>
> The sev_evict_cache() is guest-related code and should be guarded by
> CONFIG_AMD_MEM_ENCRYPT, not CONFIG_KVM_AMD_SEV.
>
> CONFIG_AMD_MEM_ENCRYPT=y is required for a guest to run properly as an
> SEV-SNP guest, but a guest kernel built with CONFIG_KVM_AMD_SEV=n would
> get the stub function of sev_evict_cache() instead of the version that
> performs the actual eviction. Move the function declarations under the
> appropriate #ifdef.
>
> Let me know.
Right, I had fixed it up locally already like this:
The sev_evict_cache() is guest-related code and should be guarded by
CONFIG_AMD_MEM_ENCRYPT, not CONFIG_KVM_AMD_SEV. Move the function
declarations under the appropriate #ifdef otherwise a guest kernel built
with CONFIG_KVM_AMD_SEV=n won't be doing proper evicting.
but you can send me your version on Monday.
When you do, can you pls rebase it ontop of -rc6 which Linus would have
released by then because this one needs to go up now and doesn't need to be
based ontop of tip/master and be against the x86/sev changes there.
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-09-13 15:38 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-12 20:29 [PATCH] x86/sev: Guard sev_evict_cache() with CONFIG_AMD_MEM_ENCRYPT Tom Lendacky
2025-09-12 20:39 ` Michael Roth
2025-09-12 20:42 ` Borislav Petkov
2025-09-12 20:49 ` Michael Roth
2025-09-12 21:02 ` Borislav Petkov
2025-09-13 14:29 ` Tom Lendacky
2025-09-13 15:38 ` Borislav Petkov
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®