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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 14 Mar 2023 02:38:06 +0000
From:   "Huang, Kai" <kai.huang@...el.com>
To:     "kvm@...r.kernel.org" <kvm@...r.kernel.org>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "Yamahata, Isaku" <isaku.yamahata@...el.com>
CC:     "zhi.wang.linux@...il.com" <zhi.wang.linux@...il.com>,
        "pbonzini@...hat.com" <pbonzini@...hat.com>,
        "Shahar, Sagi" <sagis@...gle.com>,
        "Aktas, Erdem" <erdemaktas@...gle.com>,
        "isaku.yamahata@...il.com" <isaku.yamahata@...il.com>,
        "dmatlack@...gle.com" <dmatlack@...gle.com>,
        "Christopherson,, Sean" <seanjc@...gle.com>
Subject: Re: [PATCH v13 003/113] KVM: TDX: Initialize the TDX module when
 loading the KVM intel kernel module

On Sun, 2023-03-12 at 10:55 -0700, isaku.yamahata@...el.com wrote:
> +int __init tdx_hardware_setup(struct kvm_x86_ops *x86_ops)
> +{
> +	int r;
> +
> +	if (!enable_ept) {
> +		pr_warn("Cannot enable TDX with EPT disabled\n");
> +		return -EINVAL;
> +	}
> +
> +	/* tdx_enable() in tdx_module_setup() requires cpus lock. */
> +	cpus_read_lock();
> +	/* TDX requires VMX. */
> +	r = vmxon_all();

Why not using hardware_enable_all()?

> +	if (!r) {
> +		int cpu;
> +
> +		/*
> +		 * Because tdx_cpu_enabel() acquire spin locks, on_each_cpu()
> +		 * can't be used.
> +		 */
> +		for_each_online_cpu(cpu) {
> +			if (smp_call_on_cpu(cpu, tdx_cpu_enable_cpu, NULL, false))
> +				r = -EIO;
> +		}
> +		if (!r)
> +			r = tdx_module_setup();
> +	}
> +	vmxoff_all();
> +	cpus_read_unlock();
> +
> +	return r;
> +}

I think you should use hardware_enable_all(), and just do something similar to
below in vmx_hardware_enable():

diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index 7eec0226d56a..b7b3f99c0095 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -2504,6 +2504,15 @@ static int vmx_hardware_enable(void)
                return r;
        }
 
+       if (enable_tdx) {
+               r = tdx_cpu_enable();
+               if (r) {
+                       cpu_vmxoff();
+                       intel_pt_handle_vmx(0);
+                       return r;
+               }
+       }
+
        if (enable_ept)
                ept_sync_global();

It handles two cases automatically:

1) When user wants to use TDX while loading KVM module, if above fails, then
hardware_enable_all() returns error, and you just give up initializing TDX
module and mark enable_tdx as false.

2) When a new cpu becomes online, and when TDX is being used by KVM, then if
above fails, it automatically rejects the CPU which isn't TDX-runnable although
it is VMX-runnable.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ