Thread (96 messages) 96 messages, 7 authors, 2021-11-11

Re: [PATCH v6 11/42] x86/sev: Check the vmpl level

From: Borislav Petkov <bp@alien8.de>
Date: 2021-10-28 15:07:11
Also in: kvm, linux-efi, linux-mm, lkml, platform-driver-x86

On Fri, Oct 08, 2021 at 01:04:22PM -0500, Brijesh Singh wrote:
quoted hunk ↗ jump to hunk
+static bool is_vmpl0(void)
+{
+	u64 attrs, va;
That local variable va is not needed.
quoted hunk ↗ jump to hunk
+	int err;
+
+	/*
+	 * There is no straightforward way to query the current VMPL level. The
+	 * simplest method is to use the RMPADJUST instruction to change a page
+	 * permission to a VMPL level-1, and if the guest kernel is launched at
+	 * a level <= 1, then RMPADJUST instruction will return an error.
+	 */
+	attrs = 1;
+
+	/*
+	 * Any page aligned virtual address is sufficent to test the VMPL level.
"page-aligned" ... 				"sufficient"
quoted hunk ↗ jump to hunk
+	 * The boot_ghcb_page is page aligned memory, so lets use for the test.
+	 */
+	va = (u64)&boot_ghcb_page;
+
+	/* Instruction mnemonic supported in binutils versions v2.36 and later */
+	asm volatile (".byte 0xf3,0x0f,0x01,0xfe\n\t"
+		      : "=a" (err)
+		      : "a" (va), "c" (RMP_PG_SIZE_4K), "d" (attrs)
+		      : "memory", "cc");
You're adding a separate rmpadjust() primitive function in patch 24.
In order to avoid duplication, define that primitive first, just like
you've done for PVALIDATE in the previous patch and use said primitive
at both call sites.

-- 
Regards/Gruss,
    Boris.

https://people.kernel.org/tglx/notes-about-netiquette
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help