[v12,10/31] LoongArch: KVM: Implement vcpu ENABLE_CAP ioctl interface

Message ID 20230530015223.147755-11-zhaotianrui@loongson.cn
State New
Headers
Series Add KVM LoongArch support |

Commit Message

zhaotianrui May 30, 2023, 1:52 a.m. UTC
  Implement LoongArch vcpu KVM_ENABLE_CAP ioctl interface.

Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
---
 arch/loongarch/kvm/vcpu.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
  

Comments

maobibo June 5, 2023, 1:12 p.m. UTC | #1
在 2023/5/30 09:52, Tianrui Zhao 写道:
> Implement LoongArch vcpu KVM_ENABLE_CAP ioctl interface.
> 
> Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
> ---
>  arch/loongarch/kvm/vcpu.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
> 
> diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
> index 278fbafc59b4..5a88f815c412 100644
> --- a/arch/loongarch/kvm/vcpu.c
> +++ b/arch/loongarch/kvm/vcpu.c
> @@ -186,6 +186,23 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
>  	return 0;
>  }
>  
> +static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
> +				     struct kvm_enable_cap *cap)
> +{
> +	int r = 0;
> +
> +	if (!kvm_vm_ioctl_check_extension(vcpu->kvm, cap->cap))
> +		return -EINVAL;
It is a little strange to check extension of the whole vm in enable vcap capability.
can we change to usage like  general architectures?

> +	if (cap->flags)
> +		return -EINVAL;
> +	if (cap->args[0])
> +		return -EINVAL;
> +	if (cap->cap)
> +		return -EINVAL;
Do we need check args[0] and cap here ?

Regards
Bibo, Mao
> +
> +	return r;
> +}
> +
>  long kvm_arch_vcpu_ioctl(struct file *filp,
>  			 unsigned int ioctl, unsigned long arg)
>  {
> @@ -209,6 +226,15 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
>  			r = _kvm_get_reg(vcpu, &reg);
>  		break;
>  	}
> +	case KVM_ENABLE_CAP: {
> +		struct kvm_enable_cap cap;
> +
> +		r = -EFAULT;
> +		if (copy_from_user(&cap, argp, sizeof(cap)))
> +			break;
> +		r = kvm_vcpu_ioctl_enable_cap(vcpu, &cap);
> +		break;
> +	}
>  	default:
>  		r = -ENOIOCTLCMD;
>  		break;
  
zhaotianrui June 6, 2023, 3:20 a.m. UTC | #2
在 2023年06月05日 21:12, bibo, mao 写道:
>
> 在 2023/5/30 09:52, Tianrui Zhao 写道:
>> Implement LoongArch vcpu KVM_ENABLE_CAP ioctl interface.
>>
>> Signed-off-by: Tianrui Zhao <zhaotianrui@loongson.cn>
>> ---
>>   arch/loongarch/kvm/vcpu.c | 26 ++++++++++++++++++++++++++
>>   1 file changed, 26 insertions(+)
>>
>> diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
>> index 278fbafc59b4..5a88f815c412 100644
>> --- a/arch/loongarch/kvm/vcpu.c
>> +++ b/arch/loongarch/kvm/vcpu.c
>> @@ -186,6 +186,23 @@ int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
>>   	return 0;
>>   }
>>   
>> +static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
>> +				     struct kvm_enable_cap *cap)
>> +{
>> +	int r = 0;
>> +
>> +	if (!kvm_vm_ioctl_check_extension(vcpu->kvm, cap->cap))
>> +		return -EINVAL;
> It is a little strange to check extension of the whole vm in enable vcap capability.
> can we change to usage like  general architectures?
Thanks, I look up this interface of other archs and re-consider it, and 
I think it should be removed.

Thanks
Tianrui Zhao
>
>> +	if (cap->flags)
>> +		return -EINVAL;
>> +	if (cap->args[0])
>> +		return -EINVAL;
>> +	if (cap->cap)
>> +		return -EINVAL;
> Do we need check args[0] and cap here ?
>
> Regards
> Bibo, Mao
No need, I will remove the two conditions.

Thanks
Tianrui Zhao
>> +
>> +	return r;
>> +}
>> +
>>   long kvm_arch_vcpu_ioctl(struct file *filp,
>>   			 unsigned int ioctl, unsigned long arg)
>>   {
>> @@ -209,6 +226,15 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
>>   			r = _kvm_get_reg(vcpu, &reg);
>>   		break;
>>   	}
>> +	case KVM_ENABLE_CAP: {
>> +		struct kvm_enable_cap cap;
>> +
>> +		r = -EFAULT;
>> +		if (copy_from_user(&cap, argp, sizeof(cap)))
>> +			break;
>> +		r = kvm_vcpu_ioctl_enable_cap(vcpu, &cap);
>> +		break;
>> +	}
>>   	default:
>>   		r = -ENOIOCTLCMD;
>>   		break;
  

Patch

diff --git a/arch/loongarch/kvm/vcpu.c b/arch/loongarch/kvm/vcpu.c
index 278fbafc59b4..5a88f815c412 100644
--- a/arch/loongarch/kvm/vcpu.c
+++ b/arch/loongarch/kvm/vcpu.c
@@ -186,6 +186,23 @@  int kvm_arch_vcpu_ioctl_set_regs(struct kvm_vcpu *vcpu, struct kvm_regs *regs)
 	return 0;
 }
 
+static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu,
+				     struct kvm_enable_cap *cap)
+{
+	int r = 0;
+
+	if (!kvm_vm_ioctl_check_extension(vcpu->kvm, cap->cap))
+		return -EINVAL;
+	if (cap->flags)
+		return -EINVAL;
+	if (cap->args[0])
+		return -EINVAL;
+	if (cap->cap)
+		return -EINVAL;
+
+	return r;
+}
+
 long kvm_arch_vcpu_ioctl(struct file *filp,
 			 unsigned int ioctl, unsigned long arg)
 {
@@ -209,6 +226,15 @@  long kvm_arch_vcpu_ioctl(struct file *filp,
 			r = _kvm_get_reg(vcpu, &reg);
 		break;
 	}
+	case KVM_ENABLE_CAP: {
+		struct kvm_enable_cap cap;
+
+		r = -EFAULT;
+		if (copy_from_user(&cap, argp, sizeof(cap)))
+			break;
+		r = kvm_vcpu_ioctl_enable_cap(vcpu, &cap);
+		break;
+	}
 	default:
 		r = -ENOIOCTLCMD;
 		break;