Skip to content
This repository was archived by the owner on Jan 28, 2023. It is now read-only.

Commit decf12c

Browse files
committed
Add max vcpu IOCTL and support 64 vcpu (netbsd 16)
This commit tried to add ioctl HAX_IOCTL_CAP_MAX_VCPU that will return the HAXM max vcpu support. Also, the switch case for Linux hax and vm device add return -ENOSYS in the default case. Moreover, the max HAXM vcpu value is updated from 16 to 64 (netbsd still 16). Previously, HAXM doesn't support IOCTL that would return the max vcpu value. This issue is resolved by adding a new IOCTL HAX_IOCTL_CAP_MAX_VCPU that will simply return HAX_MAX_VCPUS. (IOCTL naming credit to KVM) This commit results in if QEMU calls this IOCTL, it will get the max vcpu value HAXM driver supported and can then compare it with the QEMU max value and smp value to determine whether the smp value is valid. Signed-off-by: WangBowen <[email protected]>
1 parent e178418 commit decf12c

File tree

10 files changed

+40
-3
lines changed

10 files changed

+40
-3
lines changed

core/include/config.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,13 @@ struct config_t {
6666
int no_msr_pass_through;
6767
};
6868

69-
#define HAX_MAX_VCPUS 16
7069

7170
#ifdef HAX_PLATFORM_NETBSD
72-
// TODO: Handle 64 VMs
71+
// TODO: Handle 64 VMs and 64 VCPUs
72+
#define HAX_MAX_VCPUS 16
7373
#define HAX_MAX_VMS 8
7474
#else
75+
#define HAX_MAX_VCPUS 64
7576
// Matches the number of bits in vm_mid_bits (see vm.c)
7677
#define HAX_MAX_VMS 64
7778
#endif

include/darwin/hax_interface_mac.h

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#define HAX_IOCTL_DESTROY_VM _IOW(0, 0x22, uint32_t)
4242
#define HAX_IOCTL_CAPABILITY _IOR(0, 0x23, struct hax_capabilityinfo)
4343
#define HAX_IOCTL_SET_MEMLIMIT _IOWR(0, 0x24, struct hax_set_memlimit)
44+
#define HAX_IOCTL_CAP_MAX_VCPU _IOR(0, 0x25, uint32_t)
4445

4546
// Only for backward compatibility with old Qemu.
4647
#define HAX_VM_IOCTL_VCPU_CREATE_ORIG _IOR(0, 0x80, int)

include/linux/hax_interface_linux.h

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#define HAX_IOCTL_DESTROY_VM _IOW(0, 0x22, uint32_t)
4343
#define HAX_IOCTL_CAPABILITY _IOR(0, 0x23, struct hax_capabilityinfo)
4444
#define HAX_IOCTL_SET_MEMLIMIT _IOWR(0, 0x24, struct hax_set_memlimit)
45+
#define HAX_IOCTL_CAP_MAX_VCPU _IOR(0, 0x25, uint32_t)
4546

4647
// Only for backward compatibility with old Qemu.
4748
#define HAX_VM_IOCTL_VCPU_CREATE_ORIG _IOR(0, 0x80, int)

include/netbsd/hax_interface_netbsd.h

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#define HAX_IOCTL_DESTROY_VM _IOW(0, 0x22, uint32_t)
4646
#define HAX_IOCTL_CAPABILITY _IOR(0, 0x23, struct hax_capabilityinfo)
4747
#define HAX_IOCTL_SET_MEMLIMIT _IOWR(0, 0x24, struct hax_set_memlimit)
48+
#define HAX_IOCTL_CAP_MAX_VCPU _IOR(0, 0x25, uint32_t)
4849

4950
// Only for backward compatibility with old Qemu.
5051
#define HAX_VM_IOCTL_VCPU_CREATE_ORIG _IOR(0, 0x80, int)

platforms/darwin/com_intel_hax_ui.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
*/
3030

3131
#include "com_intel_hax.h"
32+
#include "../../core/include/config.h"
3233

3334
#include <libkern/version.h>
3435
#include <sys/proc.h>
@@ -596,7 +597,10 @@ static int hax_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag,
596597
*((uint32_t *)data) = vm_id;
597598
break;
598599
}
599-
600+
case HAX_IOCTL_CAP_MAX_VCPU: {
601+
*((uint32_t *)data) = HAX_MAX_VCPUS;
602+
break;
603+
}
600604
default: {
601605
handle_unknown_ioctl(dev, cmd, p);
602606
ret = -ENOSYS;

platforms/linux/components.c

+1
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ static long hax_vm_ioctl(struct file *filp, unsigned int cmd,
653653
default:
654654
// TODO: Print information about the process that sent the ioctl.
655655
hax_log(HAX_LOGE, "Unknown VM IOCTL 0x%lx\n", cmd);
656+
ret = -ENOSYS;
656657
break;
657658
}
658659
hax_put_vm(cvm);

platforms/linux/hax_entry.c

+12
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "../../include/hax_interface.h"
4040
#include "../../include/hax_release_ver.h"
4141
#include "../../core/include/hax_core_interface.h"
42+
#include "../../core/include/config.h"
4243

4344
MODULE_LICENSE("Dual BSD/GPL");
4445
MODULE_AUTHOR("Kryptos Logic");
@@ -106,7 +107,18 @@ static long hax_dev_ioctl(struct file *filp, unsigned int cmd,
106107
return -EFAULT;
107108
break;
108109
}
110+
case HAX_IOCTL_CAP_MAX_VCPU: {
111+
int max_vcpu = HAX_MAX_VCPUS;
112+
113+
if (copy_to_user(argp, &max_vcpu, sizeof(max_vcpu)))
114+
return -EFAULT;
115+
116+
break;
117+
}
118+
109119
default:
120+
hax_log(HAX_LOGE, "Invalid HAX IOCTL 0x%lx\n", cmd);
121+
ret = -ENOSYS;
110122
break;
111123
}
112124
return ret;

platforms/netbsd/hax_entry_hax.c

+4
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ int hax_ioctl(dev_t self __unused, u_long cmd, void *data, int flag,
116116
*((uint32_t *)data) = vm_id;
117117
break;
118118
}
119+
case HAX_IOCTL_CAP_MAX_VCPU: {
120+
*((uint32_t *)data) = HAX_MAX_VCPUS;
121+
break;
122+
}
119123
default:
120124
hax_log(HAX_LOGE, "Unknown ioctl %#lx, pid=%d ('%s')\n", cmd,
121125
l->l_proc->p_pid, l->l_proc->p_comm);

platforms/windows/hax_entry.c

+10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <string.h>
3636

3737
#include "hax_win.h"
38+
#include "../../core/include/config.h"
3839

3940
// vcpu.h
4041
int vcpu_takeoff(struct vcpu_t *vcpu);
@@ -714,6 +715,15 @@ NTSTATUS HaxDeviceControl(PDEVICE_OBJECT DeviceObject,
714715
infret = sizeof(uint32_t);
715716
ret = STATUS_SUCCESS;
716717
break;
718+
case HAX_IOCTL_CAP_MAX_VCPU:
719+
if (outBufLength < sizeof(uint32_t)) {
720+
ret = STATUS_BUFFER_TOO_SMALL;
721+
goto done;
722+
}
723+
*((uint32_t *)outBuf) = HAX_MAX_VCPUS;
724+
infret = sizeof(uint32_t);
725+
ret = STATUS_SUCCESS;
726+
break;
717727
default:
718728
ret = STATUS_INVALID_DEVICE_REQUEST;
719729
hax_log(HAX_LOGE, "Invalid hax ioctl %x\n",

platforms/windows/hax_entry.h

+2
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ extern PDRIVER_OBJECT HaxDriverObject;
120120
CTL_CODE(HAX_DEVICE_TYPE, 0x910, METHOD_BUFFERED, FILE_ANY_ACCESS)
121121
#define HAX_IOCTL_SET_MEMLIMIT \
122122
CTL_CODE(HAX_DEVICE_TYPE, 0x911, METHOD_BUFFERED, FILE_ANY_ACCESS)
123+
#define HAX_IOCTL_CAP_MAX_VCPU \
124+
CTL_CODE(HAX_DEVICE_TYPE, 0x917, METHOD_BUFFERED, FILE_ANY_ACCESS)
123125

124126
#define HAX_VM_IOCTL_VCPU_CREATE \
125127
CTL_CODE(HAX_DEVICE_TYPE, 0x902, METHOD_BUFFERED, FILE_ANY_ACCESS)

0 commit comments

Comments
 (0)