Skip to contentSkip to conversation

x86: vmx_tests: pml: Skip PML test if it's not enabled in underlying

PATCH In review Robert Hoo 2 participants 3 messages Jul 25, 2021 – Jul 27, 2021 KVM

lore
Share & tools
lore

Robert Hoo

author
#0 lore raw

PATCH 1/1 x86: vmx_tests: pml: Skip PML test if it's not enabled in underlying

PML in VM depends on "enable PML" in VM-execution control, check this before vmwrite to PMLADDR, because this field doesn't exist if PML is disabled in VM-execution control.

---
 x86/vmx_tests.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
x86/vmx_tests.c +6 -3
index 4f712eb..8663112 100644
@@ -1502,13 +1502,16 @@ static int pml_init(struct vmcs *vmcs)
 		return VMX_TEST_EXIT;
 	}
 
+	ctrl_cpu = vmcs_read(CPU_EXEC_CTRL1) & CPU_PML;
+	if (!ctrl_cpu) {
+		printf("\tPML is not enabled\n");
+		return VMX_TEST_EXIT;
+	}
+
 	pml_log = alloc_page();
 	vmcs_write(PMLADDR, (u64)pml_log);
 	vmcs_write(GUEST_PML_INDEX, PML_INDEX - 1);
 
-	ctrl_cpu = vmcs_read(CPU_EXEC_CTRL1) | CPU_PML;
-	vmcs_write(CPU_EXEC_CTRL1, ctrl_cpu);
-
 	return VMX_TEST_START;
 }
 
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 3 lines · Robert Hoo

PML in VM depends on "enable PML" in VM-execution control, check this before vmwrite to PMLADDR, because this field doesn't exist if PML is disabled in VM-execution control.

No, the field doesn't exist if the CPU doesn't support PML. Whether or not PML is enabled in the execution controls is irrelevant. pml_init() checks for both secondary execution controls and PML support (with bad indentation).

	if (!(ctrl_cpu_rev[0].clr & CPU_SECONDARY) ||
		!(ctrl_cpu_rev[1].clr & CPU_PML)) {
		printf("\tPML is not supported");
		return VMX_TEST_EXIT;
	}

	pml_log = alloc_page();
	vmcs_write(PMLADDR, (u64)pml_log);
	vmcs_write(GUEST_PML_INDEX, PML_INDEX - 1);
Quoted 32 lines
---
 x86/vmx_tests.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
x86/vmx_tests.c +6 -3
index 4f712eb..8663112 100644
@@ -1502,13 +1502,16 @@ static int pml_init(struct vmcs *vmcs)
 		return VMX_TEST_EXIT;
 	}
 
+	ctrl_cpu = vmcs_read(CPU_EXEC_CTRL1) & CPU_PML;
+	if (!ctrl_cpu) {
+		printf("\tPML is not enabled\n");
+		return VMX_TEST_EXIT;
+	}
+
 	pml_log = alloc_page();
 	vmcs_write(PMLADDR, (u64)pml_log);
 	vmcs_write(GUEST_PML_INDEX, PML_INDEX - 1);
 
-	ctrl_cpu = vmcs_read(CPU_EXEC_CTRL1) | CPU_PML;
-	vmcs_write(CPU_EXEC_CTRL1, ctrl_cpu);
-
 	return VMX_TEST_START;
 }
 
Signature · 1 line
1.8.3.1
author
#2 lore raw
Quoted 10 lines · Sean Christopherson
Quoted 5 lines · Robert Hoo

PML in VM depends on "enable PML" in VM-execution control, check this
before vmwrite to PMLADDR, because this field doesn't exist if PML is
disabled in VM-execution control.

No, the field doesn't exist if the CPU doesn't support PML. Whether or not PML
is enabled in the execution controls is irrelevant.

Right, Thanks Sean.

Quoted 45 lines

pml_init() checks for both
secondary execution controls and PML support (with bad indentation).

	if (!(ctrl_cpu_rev[0].clr & CPU_SECONDARY) ||
		!(ctrl_cpu_rev[1].clr & CPU_PML)) {
		printf("\tPML is not supported");
		return VMX_TEST_EXIT;
	}

	pml_log = alloc_page();
	vmcs_write(PMLADDR, (u64)pml_log);
	vmcs_write(GUEST_PML_INDEX, PML_INDEX - 1);
Quoted 32 lines
---
 x86/vmx_tests.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
x86/vmx_tests.c +6 -3
index 4f712eb..8663112 100644
@@ -1502,13 +1502,16 @@ static int pml_init(struct vmcs *vmcs)
 		return VMX_TEST_EXIT;
 	}
 
+	ctrl_cpu = vmcs_read(CPU_EXEC_CTRL1) & CPU_PML;
+	if (!ctrl_cpu) {
+		printf("\tPML is not enabled\n");
+		return VMX_TEST_EXIT;
+	}
+
 	pml_log = alloc_page();
 	vmcs_write(PMLADDR, (u64)pml_log);
 	vmcs_write(GUEST_PML_INDEX, PML_INDEX - 1);
 
-	ctrl_cpu = vmcs_read(CPU_EXEC_CTRL1) | CPU_PML;
-	vmcs_write(CPU_EXEC_CTRL1, ctrl_cpu);
-
 	return VMX_TEST_START;
 }
 
Signature · 1 line
1.8.3.1