Skip to contentSkip to conversation

KVM: nVMX: Remove outdated comments in nested_vmx_setup_ctls_msrs().

PATCH Superseded Yu Zhang 2 participants 5 messages Dec 15, 2022 – Dec 19, 2022

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yu Zhang

author
#0 lore raw

PATCH 1/1 KVM: nVMX: Remove outdated comments in nested_vmx_setup_ctls_msrs().

nested_vmx_setup_ctls_msrs() initializes the vmcs_conf.nested, which stores the global VMX MSR configurations when nested is supported, regardless of any particular CPUID settings for one VM.

Commit 6defc591846d ("KVM: nVMX: include conditional controls in /dev/kvm KVM_GET_MSRS") added the some feature flags for secondary proc-based controls, so that those features can be available in KVM_GET_MSRS. Yet this commit did not remove the obsolete comments in nested_vmx_setup_ctls_msrs().

Just fix the comments, and no functional change intended.

Fixes 6defc591846d ("KVM: nVMX: include conditional controls in /dev/kvm KVM_GET_MSRS")
---
 arch/x86/kvm/vmx/nested.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
arch/x86/kvm/vmx/nested.c +1 -5
index b6f4411b613e..76cca5d5aa6b 100644
@@ -6854,11 +6854,7 @@ void nested_vmx_setup_ctls_msrs(struct vmcs_config *vmcs_conf, u32 ept_caps)
 	msrs->procbased_ctls_low &=
 		~(CPU_BASED_CR3_LOAD_EXITING | CPU_BASED_CR3_STORE_EXITING);
 
-	/*
-	 * secondary cpu-based controls.  Do not include those that
-	 * depend on CPUID bits, they are added later by
-	 * vmx_vcpu_after_set_cpuid.
-	 */
+	/* secondary cpu-based controls */
 	msrs->secondary_ctls_low = 0;
 
 	msrs->secondary_ctls_high = vmcs_conf->cpu_based_2nd_exec_ctrl;
Signature · 1 line
2.17.1
#1 lore raw
Quoted 11 lines · Yu Zhang

nested_vmx_setup_ctls_msrs() initializes the vmcs_conf.nested, which stores the global VMX MSR configurations when nested is supported, regardless of any particular CPUID settings for one VM.

Commit 6defc591846d ("KVM: nVMX: include conditional controls in /dev/kvm KVM_GET_MSRS") added the some feature flags for secondary proc-based controls, so that those features can be available in KVM_GET_MSRS. Yet this commit did not remove the obsolete comments in nested_vmx_setup_ctls_msrs().

Quoted 4 lines

Just fix the comments, and no functional change intended.

Fixes 6defc591846d ("KVM: nVMX: include conditional controls in /dev/kvm KVM_GET_MSRS")

I appreciate the nod, but you found this, not me :-)

Quoted 10 lines
---
 arch/x86/kvm/vmx/nested.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
arch/x86/kvm/vmx/nested.c +0 -0
index b6f4411b613e..76cca5d5aa6b 100644

arch/x86/kvm/vmx/nested.c void nested_vmx_setup_ctls_msrs(struct vmcs_config *vmcs_conf, u32 ept_caps) · line 6857

Quoted 9 lines
arch/x86/kvm/vmx/nested.c +1 -5
@@ -6854,11 +6854,7 @@ void nested_vmx_setup_ctls_msrs(struct vmcs_config *vmcs_conf, u32 ept_caps)
 	msrs->procbased_ctls_low &=
 		~(CPU_BASED_CR3_LOAD_EXITING | CPU_BASED_CR3_STORE_EXITING);
 
-	/*
-	 * secondary cpu-based controls.  Do not include those that
-	 * depend on CPUID bits, they are added later by
-	 * vmx_vcpu_after_set_cpuid.
-	 */
+	/* secondary cpu-based controls */

Eh, just drop the comment. Pretty obvious this is for secondary execution controls.

Quoted 6 lines
arch/x86/kvm/vmx/nested.c +0 -0
 	msrs->secondary_ctls_low = 0;
 
 	msrs->secondary_ctls_high = vmcs_conf->cpu_based_2nd_exec_ctrl;
Signature · 1 line
2.17.1
author
#2 lore raw
Quoted 2 lines

Eh, just drop the comment. Pretty obvious this is for secondary execution controls.

Thanks Sean. Well, I agree it is obvious.

This line was kept because there are comments for other groups of control fields(e.g., exit/entry/pin-based/cpu-based controls etc.) in nested_vmx_setup_ctls_msrs(). If we do not keep the one for secondary cpu-based controls, we may just delete other comments as well. But is that really necessary?

B.R.
Yu

#3 lore raw
Quoted 9 lines · Yu Zhang
Quoted 2 lines

Eh, just drop the comment. Pretty obvious this is for secondary execution controls.

Thanks Sean. Well, I agree it is obvious.

This line was kept because there are comments for other groups of control fields(e.g., exit/entry/pin-based/cpu-based controls etc.) in nested_vmx_setup_ctls_msrs(). If we do not keep the one for secondary cpu-based controls, we may just delete other comments as well. But is that really necessary?

Adding a patch to delete the various one-line comments is probably unnecessary churn. The comments are kinda sorta helpful, but only because the function is a giant and thus a bit hard to follow. A better solution than comments would be to add helpers for each collection ("secondary_ctls" is a bit of a lie because it handle VPID, EPT, VMFUNC, etc..., but whatever), e.g.

	nested_vmx_setup_pinbased_ctls(msrs);
	nested_vmx_setup_exit_ctls(msrs);
	nested_vmx_setup_entry_ctls(msrs);
	nested_vmx_setup_cpubased_ctls(msrs);
	nested_vmx_setup_secondary_ctls(msrs);
	nested_vmx_setup_misc_data(msrs);
author
#4 lore raw
Quoted 11 lines · Sean Christopherson
Quoted 9 lines · Yu Zhang
Quoted 2 lines

Eh, just drop the comment. Pretty obvious this is for secondary execution controls.

Thanks Sean. Well, I agree it is obvious.

This line was kept because there are comments for other groups of control fields(e.g., exit/entry/pin-based/cpu-based controls etc.) in nested_vmx_setup_ctls_msrs(). If we do not keep the one for secondary cpu-based controls, we may just delete other comments as well. But is that really necessary?

Quoted 5 lines

Adding a patch to delete the various one-line comments is probably unnecessary churn. The comments are kinda sorta helpful, but only because the function is a giant and thus a bit hard to follow. A better solution than comments would be to add helpers for each collection ("secondary_ctls" is a bit of a lie because it handle VPID, EPT, VMFUNC, etc..., but whatever), e.g.

Good point. The "secondary_ctls" may be inaccurate, but I do not have a better name in mind either...

Quoted 6 lines
	nested_vmx_setup_pinbased_ctls(msrs);
	nested_vmx_setup_exit_ctls(msrs);
	nested_vmx_setup_entry_ctls(msrs);
	nested_vmx_setup_cpubased_ctls(msrs);
	nested_vmx_setup_secondary_ctls(msrs);

Adding nested_vmx_setup_secondary_ctls() will impact
1> your previous patch to expose ENABLE_USR_WAIT_PAUSE control
https://lore.kernel.org/lkml/[email protected]/
2> my previous patch to simplify the setting of secondary proc- based control:
https://www.spinics.net/lists/kernel/msg4582141.html
How about we combine our previous patches and the new ones together in next version?

One more questionable comment for nested_vmx_setup_ctls_msrs() is:

arch/x86/kvm/vmx/nested.c +0 -2
index b6f4411b613e..58b491f13ed7 100644
@@ -6744,8 +6744,6 @@ static u64 nested_vmx_calc_vmcs_enum_msr(void)
 /*
  * nested_vmx_setup_ctls_msrs() sets up variables containing the values to be
  * returned for the various VMX controls MSRs when nested VMX is enabled.
- * The same values should also be used to verify that vmcs12 control fields are
- * valid during nested entry from L1 to L2.
  * Each of these control msrs has a low and high 32-bit half: A low bit is on
  * if the corresponding bit in the (32-bit) control field *must* be on, and a
  * bit in the high half is on if the corresponding bit in the control field
Quoted 1 line
	nested_vmx_setup_misc_data(msrs);

As to the misc data msr, do we really need a seperate function for it? If yes, then what about the vmx basic msr, the ones for fixed bits in CR0/4?

B.R.
Yu