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: Thu, 14 Mar 2024 16:32:20 +0800
From: Chao Gao <chao.gao@...el.com>
To: <isaku.yamahata@...el.com>
CC: <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>, Kai Huang <kai.huang@...el.com>, <chen.bo@...el.com>,
	<hang.yuan@...el.com>, <tina.zhang@...el.com>
Subject: Re: [PATCH v19 019/130] KVM: x86: Add is_vm_type_supported callback

>-static bool kvm_is_vm_type_supported(unsigned long type)
>+bool __kvm_is_vm_type_supported(unsigned long type)
> {
> 	return type == KVM_X86_DEFAULT_VM ||
> 	       (type == KVM_X86_SW_PROTECTED_VM &&
> 		IS_ENABLED(CONFIG_KVM_SW_PROTECTED_VM) && tdp_enabled);

maybe just do:
	switch (type) {
	case KVM_X86_DEFAULT_VM:
		return true;
	case KVM_X86_SW_PROTECTED_VM:
		return IS_ENABLED(CONFIG_KVM_SW_PROTECTED_VM) && tdp_enabled;
	default:
		return static_call(kvm_x86_is_vm_type_supported)(type);
	}

There are two benefits
1) switch/case improves readability a little.
2) no need to expose __kvm_is_vm_type_supported()


> }
>+EXPORT_SYMBOL_GPL(__kvm_is_vm_type_supported);

>+
>+static bool kvm_is_vm_type_supported(unsigned long type)
>+{
>+	return static_call(kvm_x86_is_vm_type_supported)(type);
>+}
> 
> int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
> {
>@@ -4784,6 +4790,10 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
> 		r = BIT(KVM_X86_DEFAULT_VM);
> 		if (kvm_is_vm_type_supported(KVM_X86_SW_PROTECTED_VM))
> 			r |= BIT(KVM_X86_SW_PROTECTED_VM);
>+		if (kvm_is_vm_type_supported(KVM_X86_TDX_VM))
>+			r |= BIT(KVM_X86_TDX_VM);
>+		if (kvm_is_vm_type_supported(KVM_X86_SNP_VM))
>+			r |= BIT(KVM_X86_SNP_VM);

maybe use a for-loop?

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ