Re: [PATCH v2 07/17] virt: acrn: Introduce an ioctl to set vCPU registers state

From: Liu, Shuo A
Date: Fri Sep 04 2020 - 00:40:09 EST


Hi Greg,

On 9/3/2020 21:03, Greg Kroah-Hartman wrote:
> On Thu, Sep 03, 2020 at 08:41:51PM +0800, shuo.a.liu@xxxxxxxxx wrote:
>> From: Shuo Liu <shuo.a.liu@xxxxxxxxx>
>>
>> A virtual CPU of User VM has different context due to the different
>> registers state. ACRN userspace needs to set the virtual CPU
>> registers state (e.g. giving a initial registers state to a virtual
>> BSP of a User VM).
>>
>> HSM provides an ioctl ACRN_IOCTL_SET_VCPU_REGS to do the virtual CPU
>> registers state setting. The ioctl passes the registers state from ACRN
>> userspace to the hypervisor directly.
>>
>> Signed-off-by: Shuo Liu <shuo.a.liu@xxxxxxxxx>
>> Reviewed-by: Zhi Wang <zhi.a.wang@xxxxxxxxx>
>> Reviewed-by: Reinette Chatre <reinette.chatre@xxxxxxxxx>
>> Cc: Zhi Wang <zhi.a.wang@xxxxxxxxx>
>> Cc: Zhenyu Wang <zhenyuw@xxxxxxxxxxxxxxx>
>> Cc: Yu Wang <yu1.wang@xxxxxxxxx>
>> Cc: Reinette Chatre <reinette.chatre@xxxxxxxxx>
>> Cc: Greg Kroah-Hartman <gregkh@xxxxxxxxxxxxxxxxxxx>
>> ---
>> drivers/virt/acrn/hsm.c | 14 +++++++
>> drivers/virt/acrn/hypercall.h | 13 +++++++
>> include/uapi/linux/acrn.h | 71 +++++++++++++++++++++++++++++++++++
>> 3 files changed, 98 insertions(+)
>>
>> diff --git a/drivers/virt/acrn/hsm.c b/drivers/virt/acrn/hsm.c
>> index 6ec6aa9053d3..13df76d0206e 100644
>> --- a/drivers/virt/acrn/hsm.c
>> +++ b/drivers/virt/acrn/hsm.c
>> @@ -12,6 +12,7 @@
>> #define pr_fmt(fmt) "acrn: " fmt
>> #define dev_fmt(fmt) "acrn: " fmt
>>
>> +#include <linux/io.h>
>> #include <linux/miscdevice.h>
>> #include <linux/mm.h>
>> #include <linux/module.h>
>> @@ -49,6 +50,7 @@ static long acrn_dev_ioctl(struct file *filp, unsigned int cmd,
>> {
>> struct acrn_vm *vm = filp->private_data;
>> struct acrn_vm_creation *vm_param;
>> + struct acrn_vcpu_regs *cpu_regs;
>> int ret = 0;
>>
>> if (vm->vmid == ACRN_INVALID_VMID && cmd != ACRN_IOCTL_CREATE_VM) {
>> @@ -96,6 +98,18 @@ static long acrn_dev_ioctl(struct file *filp, unsigned int cmd,
>> case ACRN_IOCTL_DESTROY_VM:
>> ret = acrn_vm_destroy(vm);
>> break;
>> + case ACRN_IOCTL_SET_VCPU_REGS:
>> + cpu_regs = memdup_user((void __user *)ioctl_param,
>> + sizeof(struct acrn_vcpu_regs));
>> + if (IS_ERR(cpu_regs))
>> + return PTR_ERR(cpu_regs);
>> +
>> + ret = hcall_set_vcpu_regs(vm->vmid, virt_to_phys(cpu_regs));
>
> No sanity checking of any arguments?

The HSM driver has limited VM status maintenance so it doesn't have full
ability to do the sanity checking.

>
> Wow, fuzzers are going to have a fun time with your hypervisor, good
> luck! :)

The hypervisor has some sanity checking. :)

Thanks
shuo