hax: Add hax max vcpu IOCTL and support 64 vcpu
PATCH 1/1 hax: Add hax max vcpu IOCTL and support 64 vcpu
This commit tried to obtain max vcpu of haxm driver by calling HAX_IOCTL_CAP_MAX_VCPU before creating the vm so that if using hax as the accelerator and the smp value is larger than the haxm driver supported max value, the program will terminate. Previously, it will create vm and vcpu one by one until haxm reports error. Also, the maximum vcpu value in qemu for haxm is updated from 0x10 to 0x40 in hax-i386.h.
This patch resolves the issue by calling hax device ioctl HAX_IOCTL_CAP_MAX_VCPU in hax_init and store the min(haxm max, qemu max) in hax_state structure. The value will be compared with smp value in vm_create. (ioctl naming credit to KVM)
This commit results in if ioctl doesn't exist or occur error, it will continue running but output warning, if smp value is larger than the min(hax max,qemu max), it will terminate and output error message.
--- target/i386/hax-all.c | 7 +++++-- target/i386/hax-i386.h | 4 +++- target/i386/hax-posix.c | 29 +++++++++++++++++++++++++++++ target/i386/hax-posix.h | 1 + target/i386/hax-windows.c | 32 ++++++++++++++++++++++++++++++++ target/i386/hax-windows.h | 2 ++ 6 files changed, 72 insertions(+), 3 deletions(-)
target/i386/hax-all.c +5 -2
@@ -259,8 +259,9 @@ struct hax_vm *hax_vm_create(struct hax_state *hax, int max_cpus) goto error; } -if (max_cpus >HAX_MAX_VCPU ) { -fprintf (stderr,"Maximum VCPU number QEMU supported is %d\n" ,HAX_MAX_VCPU ); +if (max_cpus > hax->hax_max_vcpu) { +fprintf (stderr,"Maximum VCPU number QEMU and HAXM driver supported is %d\n" , + hax->hax_max_vcpu); goto error; }
@@ -332,6 +333,8 @@ static int hax_init(ram_addr_t ram_size, int max_cpus) goto error; } + hax->hax_max_vcpu =hax_max_vcpus_support (hax); +if (!hax_version_support (hax)) { ret = -EINVAL ; goto error;
target/i386/hax-i386.h +3 -1
@@ -38,9 +38,10 @@ struct hax_state {struct hax_vm *vm;uint64_t mem_quota;bool supports_64bit_ramblock; +int hax_max_vcpu; }; -#define HAX_MAX_VCPU 0x10 +#define HAX_MAX_VCPU 0x40#define MAX_VM_ID 0x40#define MAX_VCPU_ID 0x40
@@ -74,6 +75,7 @@ int hax_notify_qemu_version(hax_fd vm_fd, struct hax_qemu_version *qversion);int hax_set_ram (uint64_t start_pa,uint32_t size,uint64_t host_va,int flags);/* Common host function */ +int hax_max_vcpus_support (struct hax_state *hax);int hax_host_create_vm (struct hax_state *hax,int *vm_id);hax_fd hax_host_open_vm (struct hax_state *hax,int vm_id);int hax_host_create_vcpu (hax_fd vm_fd,int vcpuid);
target/i386/hax-posix.c +29 -0
@@ -163,6 +163,35 @@ int hax_host_create_vm(struct hax_state *hax, int *vmid)return ret; } +int hax_max_vcpus_support (struct hax_state *hax) +{ +int ret; +int vcpu_num =0 ; + +if (hax_invalid_fd (hax->fd)) { +return vcpu_num; + } + + ret =ioctl (hax->fd,HAX_IOCTL_CAP_MAX_VCPU , &vcpu_num); + +if (ret ==0 && vcpu_num >0 ) { +if (vcpu_num !=HAX_MAX_VCPU ) { +fprintf (stderr,"Warning: HAXM driver and QEMU are inconsistent" +" in max vcpu number, HAXM driver: %d, QEMU: %d," +" refers to the smaller one.\n" , vcpu_num,HAX_MAX_VCPU ); +if (vcpu_num >HAX_MAX_VCPU ) { + vcpu_num =HAX_MAX_VCPU ; + } + } + }else { + vcpu_num =HAX_MAX_VCPU ; +fprintf (stderr,"Warning: HAXM driver doesn't support HAX_IOCTL_CAP_MAX_VCPU," +" will refer to max value defined in QEMU\n" ); + } + +return vcpu_num; +} +hax_fd hax_host_open_vm (struct hax_state *hax,int vm_id) {hax_fd fd;
target/i386/hax-posix.h +1 -0
@@ -38,6 +38,7 @@ static inline void hax_close_fd(hax_fd fd)#define HAX_IOCTL_CREATE_VM _IOWR(0, 0x21, uint32_t)#define HAX_IOCTL_DESTROY_VM _IOW(0, 0x22, uint32_t)#define HAX_IOCTL_CAPABILITY _IOR(0, 0x23, struct hax_capabilityinfo) +#define HAX_IOCTL_CAP_MAX_VCPU _IOR(0, 0x25, uint32_t)#define HAX_VM_IOCTL_VCPU_CREATE _IOWR(0, 0x80, uint32_t)#define HAX_VM_IOCTL_ALLOC_RAM _IOWR(0, 0x81, struct hax_alloc_ram_info)
target/i386/hax-windows.c +32 -0
@@ -249,6 +249,38 @@ int hax_host_create_vm(struct hax_state *hax, int *vmid)return 0 ; } +int hax_max_vcpus_support (struct hax_state *hax) +{ +int ret; +int vcpu_num =0 ; +DWORD dSize =0 ; + +if (hax_invalid_fd (hax->fd)) { +return vcpu_num; + } + + ret =DeviceIoControl (hax->fd, +HAX_IOCTL_CAP_MAX_VCPU , +NULL ,0 , &vcpu_num,sizeof (vcpu_num), &dSize, + (LPOVERLAPPED )NULL ); +if (ret && vcpu_num >0 ) { +if (vcpu_num !=HAX_MAX_VCPU ) { +fprintf (stderr,"Warning: HAXM driver and QEMU are inconsistent" +" in max vcpu number, HAXM driver: %d, QEMU: %d," +" refers to the smaller one.\n" , vcpu_num,HAX_MAX_VCPU ); +if (vcpu_num >HAX_MAX_VCPU ) { + vcpu_num =HAX_MAX_VCPU ; + } + } + }else { + vcpu_num =HAX_MAX_VCPU ; +fprintf (stderr,"Warning: HAXM driver doesn't support HAX_IOCTL_CAP_MAX_VCPU," +" will refer to max value defined in QEMU\n" ); + } + +return vcpu_num; +} +hax_fd hax_host_open_vm (struct hax_state *hax,int vm_id) {char *vm_name =NULL ;
target/i386/hax-windows.h +2 -0
@@ -48,6 +48,8 @@ static inline int hax_invalid_fd(hax_fd fd) METHOD_BUFFERED, FILE_ANY_ACCESS)#define HAX_IOCTL_CAPABILITY CTL_CODE(HAX_DEVICE_TYPE, 0x910, \ METHOD_BUFFERED, FILE_ANY_ACCESS) +#define HAX_IOCTL_CAP_MAX_VCPU CTL_CODE(HAX_DEVICE_TYPE, 0x917, \ + METHOD_BUFFERED, FILE_ANY_ACCESS)#define HAX_VM_IOCTL_VCPU_CREATE CTL_CODE(HAX_DEVICE_TYPE, 0x902, \ METHOD_BUFFERED, FILE_ANY_ACCESS)
Signature · 1 line
2.24.1
Looks good to me.
--
Best Regards,
Colin Xu
Quoted 188 lines · WangBowen
This commit tried to obtain max vcpu of haxm driver by calling
HAX_IOCTL_CAP_MAX_VCPUbefore creating the vm so that if using hax as the accelerator and the smp value is larger than the haxm driver supported max value, the program will terminate. Previously, it will create vm and vcpu one by one until haxm reports error. Also, the maximum vcpu value in qemu for haxm is updated from0x10to0x40inhax-i386.h.This patch resolves the issue by calling hax device ioctl
HAX_IOCTL_CAP_MAX_VCPUinhax_initand store themin(haxm max, qemu max)inhax_statestructure. The value will be compared with smp value invm_create. (ioctl naming credit to KVM)This commit results in if ioctl doesn't exist or occur error, it will continue running but output warning, if smp value is larger than the
min(hax max,qemu max), it will terminate and output error message.Signed-off-by WangBowen <[email protected]>---
target/i386/hax-all.c | 7 +++++-- target/i386/hax-i386.h | 4 +++- target/i386/hax-posix.c | 29 +++++++++++++++++++++++++++++ target/i386/hax-posix.h | 1 + target/i386/hax-windows.c | 32 ++++++++++++++++++++++++++++++++ target/i386/hax-windows.h | 2 ++ 6 files changed, 72 insertions(+), 3 deletions(-)target/i386/hax-all.c +5
-2@@ -259,8 +259,9 @@ struct hax_vm *hax_vm_create(struct hax_state *hax, int max_cpus) goto error; } -if (max_cpus >HAX_MAX_VCPU ) { -fprintf (stderr,"Maximum VCPU number QEMU supported is %d\n" ,HAX_MAX_VCPU ); +if (max_cpus > hax->hax_max_vcpu) { +fprintf (stderr,"Maximum VCPU number QEMU and HAXM driver supported is %d\n" , + hax->hax_max_vcpu); goto error; }@@ -332,6 +333,8 @@ static int hax_init(ram_addr_t ram_size, int max_cpus) goto error; } + hax->hax_max_vcpu =hax_max_vcpus_support (hax); +if (!hax_version_support (hax)) { ret = -EINVAL ; goto error;target/i386/hax-i386.h +3
-1@@ -38,9 +38,10 @@ struct hax_state {struct hax_vm *vm;uint64_t mem_quota;bool supports_64bit_ramblock; +int hax_max_vcpu; }; -#define HAX_MAX_VCPU 0x10 +#define HAX_MAX_VCPU 0x40#define MAX_VM_ID 0x40#define MAX_VCPU_ID 0x40@@ -74,6 +75,7 @@ int hax_notify_qemu_version(hax_fd vm_fd, struct hax_qemu_version *qversion);int hax_set_ram (uint64_t start_pa,uint32_t size,uint64_t host_va,int flags);/* Common host function */ +int hax_max_vcpus_support (struct hax_state *hax);int hax_host_create_vm (struct hax_state *hax,int *vm_id);hax_fd hax_host_open_vm (struct hax_state *hax,int vm_id);int hax_host_create_vcpu (hax_fd vm_fd,int vcpuid);target/i386/hax-posix.c +29
-0@@ -163,6 +163,35 @@ int hax_host_create_vm(struct hax_state *hax, int *vmid)return ret; } +int hax_max_vcpus_support (struct hax_state *hax) +{ +int ret; +int vcpu_num =0 ; + +if (hax_invalid_fd (hax->fd)) { +return vcpu_num; + } + + ret =ioctl (hax->fd,HAX_IOCTL_CAP_MAX_VCPU , &vcpu_num); + +if (ret ==0 && vcpu_num >0 ) { +if (vcpu_num !=HAX_MAX_VCPU ) { +fprintf (stderr,"Warning: HAXM driver and QEMU are inconsistent" +" in max vcpu number, HAXM driver: %d, QEMU: %d," +" refers to the smaller one.\n" , vcpu_num,HAX_MAX_VCPU ); +if (vcpu_num >HAX_MAX_VCPU ) { + vcpu_num =HAX_MAX_VCPU ; + } + } + }else { + vcpu_num =HAX_MAX_VCPU ; +fprintf (stderr,"Warning: HAXM driver doesn't support HAX_IOCTL_CAP_MAX_VCPU," +" will refer to max value defined in QEMU\n" ); + } + +return vcpu_num; +} +hax_fd hax_host_open_vm (struct hax_state *hax,int vm_id) {hax_fd fd;target/i386/hax-posix.h +1
-0@@ -38,6 +38,7 @@ static inline void hax_close_fd(hax_fd fd)#define HAX_IOCTL_CREATE_VM _IOWR(0, 0x21, uint32_t)#define HAX_IOCTL_DESTROY_VM _IOW(0, 0x22, uint32_t)#define HAX_IOCTL_CAPABILITY _IOR(0, 0x23, struct hax_capabilityinfo) +#define HAX_IOCTL_CAP_MAX_VCPU _IOR(0, 0x25, uint32_t)#define HAX_VM_IOCTL_VCPU_CREATE _IOWR(0, 0x80, uint32_t)#define HAX_VM_IOCTL_ALLOC_RAM _IOWR(0, 0x81, struct hax_alloc_ram_info)target/i386/hax-windows.c +32
-0@@ -249,6 +249,38 @@ int hax_host_create_vm(struct hax_state *hax, int *vmid)return 0 ; } +int hax_max_vcpus_support (struct hax_state *hax) +{ +int ret; +int vcpu_num =0 ; +DWORD dSize =0 ; + +if (hax_invalid_fd (hax->fd)) { +return vcpu_num; + } + + ret =DeviceIoControl (hax->fd, +HAX_IOCTL_CAP_MAX_VCPU , +NULL ,0 , &vcpu_num,sizeof (vcpu_num), &dSize, + (LPOVERLAPPED )NULL ); +if (ret && vcpu_num >0 ) { +if (vcpu_num !=HAX_MAX_VCPU ) { +fprintf (stderr,"Warning: HAXM driver and QEMU are inconsistent" +" in max vcpu number, HAXM driver: %d, QEMU: %d," +" refers to the smaller one.\n" , vcpu_num,HAX_MAX_VCPU ); +if (vcpu_num >HAX_MAX_VCPU ) { + vcpu_num =HAX_MAX_VCPU ; + } + } + }else { + vcpu_num =HAX_MAX_VCPU ; +fprintf (stderr,"Warning: HAXM driver doesn't support HAX_IOCTL_CAP_MAX_VCPU," +" will refer to max value defined in QEMU\n" ); + } + +return vcpu_num; +} +hax_fd hax_host_open_vm (struct hax_state *hax,int vm_id) {char *vm_name =NULL ;target/i386/hax-windows.h +2
-0@@ -48,6 +48,8 @@ static inline int hax_invalid_fd(hax_fd fd) METHOD_BUFFERED, FILE_ANY_ACCESS)#define HAX_IOCTL_CAPABILITY CTL_CODE(HAX_DEVICE_TYPE, 0x910, \ METHOD_BUFFERED, FILE_ANY_ACCESS) +#define HAX_IOCTL_CAP_MAX_VCPU CTL_CODE(HAX_DEVICE_TYPE, 0x917, \ + METHOD_BUFFERED, FILE_ANY_ACCESS)#define HAX_VM_IOCTL_VCPU_CREATE CTL_CODE(HAX_DEVICE_TYPE, 0x902, \ METHOD_BUFFERED, FILE_ANY_ACCESS)Signature · 1 line
2.24.1
Hi Paolo,
Would you also help queue this one for PULL?
--
Best Regards,
Colin Xu
Quoted 212 lines · Colin Xu
Looks good to me.
Reviewed-by Colin Xu <[email protected]>--
Best Regards,
Colin XuQuoted 201 lines · WangBowen
This commit tried to obtain max vcpu of haxm driver by calling
HAX_IOCTL_CAP_MAX_VCPUbefore creating the vm so that if using hax as the accelerator and the smp value is larger than the haxm driver supported max value, the program will terminate. Previously, it will create vm and vcpu one by one until haxm reports error. Also, the maximum vcpu value in qemu for haxm is updated from0x10to0x40inhax-i386.h.This patch resolves the issue by calling hax device ioctl
HAX_IOCTL_CAP_MAX_VCPUinhax_initand store themin(haxm max, qemu max)inhax_statestructure. The value will be compared with smp value invm_create. (ioctl naming credit to KVM)This commit results in if ioctl doesn't exist or occur error, it will continue running but output warning, if smp value is larger than the
min(hax max,qemu max), it will terminate and output error message.Signed-off-by WangBowen <[email protected]>---
target/i386/hax-all.c | 7 +++++-- target/i386/hax-i386.h | 4 +++- target/i386/hax-posix.c | 29 +++++++++++++++++++++++++++++ target/i386/hax-posix.h | 1 + target/i386/hax-windows.c | 32 ++++++++++++++++++++++++++++++++ target/i386/hax-windows.h | 2 ++ 6 files changed, 72 insertions(+), 3 deletions(-)target/i386/hax-all.c +3
-2@@ -259,8 +259,9 @@ struct hax_vm *hax_vm_create(struct hax_state *hax, int max_cpus) goto error; } -if (max_cpus >HAX_MAX_VCPU ) { -fprintf (stderr,"Maximum VCPU number QEMU supported is %d\n" , HAX_MAX_VCPU); +if (max_cpus > hax->hax_max_vcpu) { + fprintf(stderr, "Maximum VCPU number QEMU and HAXM driver supported is %d\n", + hax->hax_max_vcpu);goto error; }target/i386/hax-all.c +2
-0@@ -332,6 +333,8 @@ static int hax_init(ram_addr_t ram_size, int max_cpus) goto error; } + hax->hax_max_vcpu =hax_max_vcpus_support (hax); +if (!hax_version_support (hax)) { ret = -EINVAL ; goto error;target/i386/hax-i386.h +3
-1@@ -38,9 +38,10 @@ struct hax_state {struct hax_vm *vm;uint64_t mem_quota;bool supports_64bit_ramblock; +int hax_max_vcpu; }; -#define HAX_MAX_VCPU 0x10 +#define HAX_MAX_VCPU 0x40#define MAX_VM_ID 0x40#define MAX_VCPU_ID 0x40@@ -74,6 +75,7 @@ int hax_notify_qemu_version(hax_fd vm_fd, struct hax_qemu_version *qversion);int hax_set_ram (uint64_t start_pa,uint32_t size,uint64_t host_va,int flags);/* Common host function */ +int hax_max_vcpus_support (struct hax_state *hax);int hax_host_create_vm (struct hax_state *hax,int *vm_id);hax_fd hax_host_open_vm (struct hax_state *hax,int vm_id);int
hax_host_create_vcpu(hax_fd vm_fd, int vcpuid);target/i386/hax-posix.c +14
-0@@ -163,6 +163,35 @@ int hax_host_create_vm(struct hax_state *hax, int *vmid)return ret; } +int hax_max_vcpus_support (struct hax_state *hax) +{ +int ret; +int vcpu_num =0 ; + +if (hax_invalid_fd (hax->fd)) { +return vcpu_num; + } + + ret =ioctl (hax->fd,HAX_IOCTL_CAP_MAX_VCPU , &vcpu_num); + +if (ret ==0 && vcpu_num >0 ) { +if (vcpu_num !=HAX_MAX_VCPU ) { + fprintf(stderr, "Warning: HAXM driver and QEMU areinconsistent"
target/i386/hax-posix.c +2
-0+" in max vcpu number, HAXM driver: %d, QEMU: %d," + " refers to the smaller one.\n", vcpu_num,
HAX_MAX_VCPU);target/i386/hax-posix.c +7
-0+if (vcpu_num >HAX_MAX_VCPU ) { + vcpu_num =HAX_MAX_VCPU ; + } + } + }else { + vcpu_num =HAX_MAX_VCPU ; + fprintf(stderr, "Warning: HAXM driver doesn't support
HAX_IOCTL_CAP_MAX_VCPU,"target/i386/hax-posix.c +6
-0+ " will refer to max value defined in QEMU\n"); + } + +return vcpu_num; +} +
hax_fdhax_host_open_vm(struct hax_state *hax, int vm_id){ hax_fd fd;target/i386/hax-posix.h +1
-0@@ -38,6 +38,7 @@ static inline void hax_close_fd(hax_fd fd)#define HAX_IOCTL_CREATE_VM _IOWR(0, 0x21, uint32_t)#define HAX_IOCTL_DESTROY_VM _IOW(0, 0x22, uint32_t)#define HAX_IOCTL_CAPABILITY _IOR(0, 0x23, struct hax_capabilityinfo) +#define HAX_IOCTL_CAP_MAX_VCPU _IOR(0, 0x25, uint32_t)#define HAX_VM_IOCTL_VCPU_CREATE _IOWR(0, 0x80, uint32_t)#define HAX_VM_IOCTL_ALLOC_RAM _IOWR(0, 0x81, struct hax_alloc_ram_info)target/i386/hax-windows.c +17
-0@@ -249,6 +249,38 @@ int hax_host_create_vm(struct hax_state *hax, int *vmid)return 0 ; } +int hax_max_vcpus_support (struct hax_state *hax) +{ +int ret; +int vcpu_num =0 ; +DWORD dSize =0 ; + +if (hax_invalid_fd (hax->fd)) { +return vcpu_num; + } + + ret =DeviceIoControl (hax->fd, +HAX_IOCTL_CAP_MAX_VCPU , +NULL ,0 , &vcpu_num,sizeof (vcpu_num), &dSize, + (LPOVERLAPPED )NULL ); +if (ret && vcpu_num >0 ) { +if (vcpu_num !=HAX_MAX_VCPU ) { + fprintf(stderr, "Warning: HAXM driver and QEMU areinconsistent"
target/i386/hax-windows.c +2
-0+" in max vcpu number, HAXM driver: %d, QEMU: %d," + " refers to the smaller one.\n", vcpu_num,
HAX_MAX_VCPU);target/i386/hax-windows.c +7
-0+if (vcpu_num >HAX_MAX_VCPU ) { + vcpu_num =HAX_MAX_VCPU ; + } + } + }else { + vcpu_num =HAX_MAX_VCPU ; + fprintf(stderr, "Warning: HAXM driver doesn't support
HAX_IOCTL_CAP_MAX_VCPU,"target/i386/hax-windows.c +6
-0+ " will refer to max value defined in QEMU\n"); + } + +return vcpu_num; +} +
hax_fdhax_host_open_vm(struct hax_state *hax, int vm_id){ char *vm_name = NULL;target/i386/hax-windows.h +2
-0@@ -48,6 +48,8 @@ static inline int hax_invalid_fd(hax_fd fd) METHOD_BUFFERED, FILE_ANY_ACCESS)#define HAX_IOCTL_CAPABILITY CTL_CODE(HAX_DEVICE_TYPE, 0x910, \ METHOD_BUFFERED, FILE_ANY_ACCESS) +#define HAX_IOCTL_CAP_MAX_VCPU CTL_CODE(HAX_DEVICE_TYPE, 0x917, \ + METHOD_BUFFERED, FILE_ANY_ACCESS)#define HAX_VM_IOCTL_VCPU_CREATE CTL_CODE(HAX_DEVICE_TYPE, 0x902, \ METHOD_BUFFERED,
FILE_ANY_ACCESS)Signature · 1 line
2.24.1