Re: [PATCH v1 1/2] x86/sev: Use per-CPU PSC structure in prep for unaccepted memory support

From: Tom Lendacky
Date: Fri Jul 29 2022 - 10:25:32 EST




On 7/29/22 09:18, Dave Hansen wrote:
On 7/29/22 07:01, Tom Lendacky wrote:
diff --git a/arch/x86/kernel/sev.c b/arch/x86/kernel/sev.c
index c05f0124c410..1f7f6205c4f6 100644
--- a/arch/x86/kernel/sev.c
+++ b/arch/x86/kernel/sev.c
@@ -104,6 +104,15 @@ struct sev_es_runtime_data {
* is currently unsupported in SEV-ES guests.
*/
unsigned long dr7;
+
+ /*
+ * Page State Change structure for use when accepting memory or when
+ * changing page state. Interrupts are disabled when using the structure
+ * but an NMI could still be raised, so use a flag to indicate when the
+ * structure is in use and use the MSR protocol in these cases.
+ */
+ struct snp_psc_desc psc_desc;
+ bool psc_active;
};

This thing:

struct snp_psc_desc {
struct psc_hdr hdr;
struct psc_entry entries[VMGEXIT_PSC_MAX_ENTRY];
} __packed;

is 16k, right? Being per-cpu, this might eat up a MB or two of memory
on a big server?

It's just under 2K, 2,032 bytes.


Considering that runtime acceptance is already single-threaded[1] *and*
there's a fallback method, why not just have a single copy of this
guarded by a single lock?

This function is called for more than just memory acceptance. It's also called for any changes from or to private or shared, which isn't single-threaded.

Thanks,
Tom


1.
https://lore.kernel.org/all/20220614120231.48165-10-kirill.shutemov@xxxxxxxxxxxxxxx/