lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230531221042.GH1234772@ls.amr.corp.intel.com>
Date:   Wed, 31 May 2023 15:10:42 -0700
From:   Isaku Yamahata <isaku.yamahata@...il.com>
To:     Zhi Wang <zhi.wang.linux@...il.com>
Cc:     isaku.yamahata@...el.com, kvm@...r.kernel.org,
        linux-kernel@...r.kernel.org, isaku.yamahata@...il.com,
        Paolo Bonzini <pbonzini@...hat.com>, erdemaktas@...gle.com,
        Sean Christopherson <seanjc@...gle.com>,
        Sagi Shahar <sagis@...gle.com>,
        David Matlack <dmatlack@...gle.com>,
        Kai Huang <kai.huang@...el.com>, chen.bo@...el.com
Subject: Re: [PATCH v14 003/113] KVM: x86/vmx: Refactor KVM VMX module
 init/exit functions

On Wed, May 31, 2023 at 01:30:12PM -0700,
Isaku Yamahata <isaku.yamahata@...il.com> wrote:

> On Wed, May 31, 2023 at 09:57:18AM +0800,
> Zhi Wang <zhi.wang.linux@...il.com> wrote:
> 
> > > +static int __init vt_init(void)
> > > +{
> > > +	unsigned int vcpu_size, vcpu_align;
> > > +	int r;
> > > +
> > > +	if (!kvm_is_vmx_supported())
> > > +		return -EOPNOTSUPP;
> > > +
> > > +	/*
> > > +	 * Note, hv_init_evmcs() touches only VMX knobs, i.e. there's nothing
> > > +	 * to unwind if a later step fails.
> > > +	 */
> > > +	hv_init_evmcs();
> > > +
> > > +	r = kvm_x86_vendor_init(&vt_init_ops);
> > > +	if (r)
> > > +		return r;
> > > +
> > > +	r = vmx_init();
> > > +	if (r)
> > > +		goto err_vmx_init;
> > > +
> > > +	/*
> > > +	 * Common KVM initialization _must_ come last, after this, /dev/kvm is
> > > +	 * exposed to userspace!
> > > +	 */
> > > +	vcpu_size = sizeof(struct vcpu_vmx);
> > > +	vcpu_align = __alignof__(struct vcpu_vmx);
> > > +	r = kvm_init(vcpu_size, vcpu_align, THIS_MODULE);
> > > +	if (r)
> > > +		goto err_kvm_init;
> > > +
> > > +	return 0;
> > > +
> > ---------------------------------
> > > +err_kvm_init:
> > > +	vmx_exit();
> > > +err_vmx_init:
> > > +	kvm_x86_vendor_exit();
> > > +	return r;
> > > +}
> > > +module_init(vt_init);
> > > +
> > ----------------------------------
> > > +static void vt_exit(void)
> > > +{
> > > +	kvm_exit();
> > > +	kvm_x86_vendor_exit();
> > > +	vmx_exit();
> > ----------------------------------
> > 
> > It seems the exiting sequences above are a little bit different with
> > each other (PS: It is not a prob introduced in this patch):
> > 
> > vmx_exit()
> > kvm_x86_vendor_exit()
> > ....
> > 
> > and
> > 
> > ...
> > kvm_x86_vnedor_exit()
> > vmx_exit()
> > 
> > I was wondering which one should be correct. Literally, the exiting
> > sequence would be in reversing order of the initialization sequence.
> 
> In theory, I think kvm_x86_vendor_exit() => vmx_exit() and
> vmx_init() => kvm_x86_vendor_exit() should be the right order.
> But in practice, it doesn't matter and I didn't want to touch the order with
> this patch series.

Here is the patch for it. But I'd like to hold the patch after this patch
series. 

>From 02c425cb96c252eecbeaf8e57dd6afd7576931b1 Mon Sep 17 00:00:00 2001
Message-Id: <02c425cb96c252eecbeaf8e57dd6afd7576931b1.1685566207.git.isaku.yamahata@...el.com>
From: Isaku Yamahata <isaku.yamahata@...el.com>
Date: Wed, 31 May 2023 13:36:10 -0700
Subject: [PATCH] KVM: VMX: Reorder vmx initialization with kvm vendor
 initialization

To match vmx_exit cleanup.

Signed-off-by: Isaku Yamahata <isaku.yamahata@...el.com>
---
 arch/x86/kvm/vmx/main.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kvm/vmx/main.c b/arch/x86/kvm/vmx/main.c
index 2e4667307458..a0586da86d81 100644
--- a/arch/x86/kvm/vmx/main.c
+++ b/arch/x86/kvm/vmx/main.c
@@ -1251,11 +1251,11 @@ static int __init vt_init(void)
 				   __alignof__(struct vcpu_tdx));
 	}
 
-	r = kvm_x86_vendor_init(&vt_init_ops);
+	r = vmx_init();
 	if (r)
-		return r;
+		goto err_vmx_init;
 
-	r = vmx_init();
+	r = kvm_x86_vendor_init(&vt_init_ops);
 	if (r)
 		goto err_vmx_init;
 
@@ -1270,9 +1270,9 @@ static int __init vt_init(void)
 	return 0;
 
 err_kvm_init:
-	vmx_exit();
-err_vmx_init:
 	kvm_x86_vendor_exit();
+err_vmx_init:
+	vmx_exit();
 	return r;
 }
 module_init(vt_init);
-- 
2.25.1




-- 
Isaku Yamahata <isaku.yamahata@...il.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ