Message ID | bd3edffaee9ecdccfbf35f70bf502a1fa00f36de.1742465624.git.Sergiy_Kibrik@epam.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | make nested virtualization support optional | expand |
On 20.03.2025 11:38, Sergiy Kibrik wrote: > Check whether nested HVM is enabled for domain before calling nestedhvm_vcpu_*() > and other not already guarded nestedhvm functions. > > Signed-off-by: Sergiy Kibrik <Sergiy_Kibrik@epam.com> > --- > xen/arch/x86/hvm/hvm.c | 6 ++++-- > xen/arch/x86/hvm/svm/asid.c | 2 +- > xen/arch/x86/hvm/svm/svm.c | 6 +++--- > 3 files changed, 8 insertions(+), 6 deletions(-) Afaics common and VMX code have quite a few more references to nestedhvm_vcpu_in_guestmode(), without nestedhvm_enabled(). Are they all fine to keep as is, while the respective adjustments here are strictly necessary? In fact I wonder whether (a) nestedhvm_vcpu_in_guestmode() couldn't be made constant-false when nested is build-time disabled, which ought to eliminate the need for those changes below. Or whether (b) nestedhvm_vcpu_in_guestmode() wouldn't better include a nestedhvm_enabled() check. > --- a/xen/arch/x86/hvm/svm/asid.c > +++ b/xen/arch/x86/hvm/svm/asid.c > @@ -30,7 +30,7 @@ void svm_asid_handle_vmrun(void) > struct vcpu *curr = current; > struct vmcb_struct *vmcb = curr->arch.hvm.svm.vmcb; > struct hvm_vcpu_asid *p_asid = > - nestedhvm_vcpu_in_guestmode(curr) > + ( nestedhvm_enabled(curr->domain) && nestedhvm_vcpu_in_guestmode(curr) ) Nit: No blanks inside parentheses like these. (There's no real need for parentheses here in the first place.) Jan
diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c index 2f31180b6f..5abbf7029d 100644 --- a/xen/arch/x86/hvm/hvm.c +++ b/xen/arch/x86/hvm/hvm.c @@ -1658,7 +1658,8 @@ int hvm_vcpu_initialise(struct vcpu *v) return 0; fail6: - nestedhvm_vcpu_destroy(v); + if ( nestedhvm_enabled(d) ) + nestedhvm_vcpu_destroy(v); fail5: free_compat_arg_xlat(v); fail4: @@ -1682,7 +1683,8 @@ void hvm_vcpu_destroy(struct vcpu *v) if ( hvm_altp2m_supported() ) altp2m_vcpu_destroy(v); - nestedhvm_vcpu_destroy(v); + if ( nestedhvm_enabled(v->domain) ) + nestedhvm_vcpu_destroy(v); free_compat_arg_xlat(v); diff --git a/xen/arch/x86/hvm/svm/asid.c b/xen/arch/x86/hvm/svm/asid.c index 7977a8e86b..05c8971714 100644 --- a/xen/arch/x86/hvm/svm/asid.c +++ b/xen/arch/x86/hvm/svm/asid.c @@ -30,7 +30,7 @@ void svm_asid_handle_vmrun(void) struct vcpu *curr = current; struct vmcb_struct *vmcb = curr->arch.hvm.svm.vmcb; struct hvm_vcpu_asid *p_asid = - nestedhvm_vcpu_in_guestmode(curr) + ( nestedhvm_enabled(curr->domain) && nestedhvm_vcpu_in_guestmode(curr) ) ? &vcpu_nestedhvm(curr).nv_n2asid : &curr->arch.hvm.n1asid; bool need_flush = hvm_asid_handle_vmenter(p_asid); diff --git a/xen/arch/x86/hvm/svm/svm.c b/xen/arch/x86/hvm/svm/svm.c index 09ac138691..d7d91427fd 100644 --- a/xen/arch/x86/hvm/svm/svm.c +++ b/xen/arch/x86/hvm/svm/svm.c @@ -795,7 +795,7 @@ static void cf_check svm_set_tsc_offset(struct vcpu *v, u64 offset, u64 at_tsc) n1vmcb = vcpu_nestedhvm(v).nv_n1vmcx; n2vmcb = vcpu_nestedhvm(v).nv_n2vmcx; - if ( nestedhvm_vcpu_in_guestmode(v) ) + if ( nestedhvm_enabled(d) && nestedhvm_vcpu_in_guestmode(v) ) { n2_tsc_offset = vmcb_get_tsc_offset(n2vmcb) - vmcb_get_tsc_offset(n1vmcb); @@ -2172,7 +2172,7 @@ svm_vmexit_do_vmrun(struct cpu_user_regs *regs, return; } - if ( !nestedsvm_vmcb_map(v, vmcbaddr) ) + if ( nestedhvm_enabled(v->domain) && !nestedsvm_vmcb_map(v, vmcbaddr) ) { gdprintk(XENLOG_ERR, "VMRUN: mapping vmcb failed, injecting #GP\n"); hvm_inject_hw_exception(X86_EXC_GP, 0); @@ -2190,7 +2190,7 @@ nsvm_get_nvmcb_page(struct vcpu *v, uint64_t vmcbaddr) struct page_info *page; struct nestedvcpu *nv = &vcpu_nestedhvm(v); - if ( !nestedsvm_vmcb_map(v, vmcbaddr) ) + if ( nestedhvm_enabled(v->domain) && !nestedsvm_vmcb_map(v, vmcbaddr) ) return NULL; /* Need to translate L1-GPA to MPA */
Check whether nested HVM is enabled for domain before calling nestedhvm_vcpu_*() and other not already guarded nestedhvm functions. Signed-off-by: Sergiy Kibrik <Sergiy_Kibrik@epam.com> --- xen/arch/x86/hvm/hvm.c | 6 ++++-- xen/arch/x86/hvm/svm/asid.c | 2 +- xen/arch/x86/hvm/svm/svm.c | 6 +++--- 3 files changed, 8 insertions(+), 6 deletions(-)