Re: [PATCH v4 04/15] x86/sev: Check for the presence of an SVSM in the SNP Secrets page

From: Tom Lendacky
Date: Wed May 22 2024 - 12:15:47 EST


On 5/22/24 10:27, Borislav Petkov wrote:
On Mon, May 20, 2024 at 08:57:43AM -0500, Tom Lendacky wrote:
So this will be a new shared directory in the top level include directory
(as PAGE_ALIGNED is defined in include/linux/mm.h), not just in the
arch/x86/include directory like the others (io.h, msr.h and tdx.h). Is that
what you want?

You can actually do this - it is a lot easier and still clean:

diff --git a/arch/x86/boot/compressed/sev.c b/arch/x86/boot/compressed/sev.c
index cb771b380a6b..5ee53a7a060e 100644
--- a/arch/x86/boot/compressed/sev.c
+++ b/arch/x86/boot/compressed/sev.c
@@ -12,7 +12,6 @@
*/
#include "misc.h"
-#include <linux/mm.h>
#include <asm/bootparam.h>
#include <asm/pgtable_types.h>
#include <asm/sev.h>
diff --git a/arch/x86/kernel/sev-shared.c b/arch/x86/kernel/sev-shared.c
index 46ea4e5e118a..bd4bbb30ef0c 100644
--- a/arch/x86/kernel/sev-shared.c
+++ b/arch/x86/kernel/sev-shared.c
@@ -1329,7 +1329,12 @@ static void __head setup_svsm_ca(const struct cc_blob_sev_info *cc_info)
vmpl = secrets_page->svsm_guest_vmpl;
caa = secrets_page->svsm_caa;
- if (!PAGE_ALIGNED(caa))
+
+ /*
+ * Open-code PAGE_ALIGNED() to avoid pulling in the world and
+ * more by including linux/mm.h.
+ */
+ if (caa & (PAGE_SIZE - 1))

Or what I originally proposed:

if (!IS_ALIGNED(caa, PAGE_SIZE))

Which also works without including mm.h.

Thanks,
Tom

sev_es_terminate(SEV_TERM_SET_LINUX, GHCB_TERM_SVSM_CAA);
/*