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

Commit

Permalink
Add max vcpu IOCTL and support 64 vcpu (netbsd 16)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bowen218 committed Apr 10, 2020
1 parent e178418 commit decf12c
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 3 deletions.
5 changes: 3 additions & 2 deletions core/include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,13 @@ struct config_t {
int no_msr_pass_through;
};

#define HAX_MAX_VCPUS 16

#ifdef HAX_PLATFORM_NETBSD
// TODO: Handle 64 VMs
// TODO: Handle 64 VMs and 64 VCPUs
#define HAX_MAX_VCPUS 16
#define HAX_MAX_VMS 8
#else
#define HAX_MAX_VCPUS 64
// Matches the number of bits in vm_mid_bits (see vm.c)
#define HAX_MAX_VMS 64
#endif
Expand Down
1 change: 1 addition & 0 deletions include/darwin/hax_interface_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define HAX_IOCTL_DESTROY_VM _IOW(0, 0x22, uint32_t)
#define HAX_IOCTL_CAPABILITY _IOR(0, 0x23, struct hax_capabilityinfo)
#define HAX_IOCTL_SET_MEMLIMIT _IOWR(0, 0x24, struct hax_set_memlimit)
#define HAX_IOCTL_CAP_MAX_VCPU _IOR(0, 0x25, uint32_t)

// Only for backward compatibility with old Qemu.
#define HAX_VM_IOCTL_VCPU_CREATE_ORIG _IOR(0, 0x80, int)
Expand Down
1 change: 1 addition & 0 deletions include/linux/hax_interface_linux.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#define HAX_IOCTL_DESTROY_VM _IOW(0, 0x22, uint32_t)
#define HAX_IOCTL_CAPABILITY _IOR(0, 0x23, struct hax_capabilityinfo)
#define HAX_IOCTL_SET_MEMLIMIT _IOWR(0, 0x24, struct hax_set_memlimit)
#define HAX_IOCTL_CAP_MAX_VCPU _IOR(0, 0x25, uint32_t)

// Only for backward compatibility with old Qemu.
#define HAX_VM_IOCTL_VCPU_CREATE_ORIG _IOR(0, 0x80, int)
Expand Down
1 change: 1 addition & 0 deletions include/netbsd/hax_interface_netbsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#define HAX_IOCTL_DESTROY_VM _IOW(0, 0x22, uint32_t)
#define HAX_IOCTL_CAPABILITY _IOR(0, 0x23, struct hax_capabilityinfo)
#define HAX_IOCTL_SET_MEMLIMIT _IOWR(0, 0x24, struct hax_set_memlimit)
#define HAX_IOCTL_CAP_MAX_VCPU _IOR(0, 0x25, uint32_t)

// Only for backward compatibility with old Qemu.
#define HAX_VM_IOCTL_VCPU_CREATE_ORIG _IOR(0, 0x80, int)
Expand Down
6 changes: 5 additions & 1 deletion platforms/darwin/com_intel_hax_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/

#include "com_intel_hax.h"
#include "../../core/include/config.h"

#include <libkern/version.h>
#include <sys/proc.h>
Expand Down Expand Up @@ -596,7 +597,10 @@ static int hax_ioctl(dev_t dev, u_long cmd, caddr_t data, int flag,
*((uint32_t *)data) = vm_id;
break;
}

case HAX_IOCTL_CAP_MAX_VCPU: {
*((uint32_t *)data) = HAX_MAX_VCPUS;
break;
}
default: {
handle_unknown_ioctl(dev, cmd, p);
ret = -ENOSYS;
Expand Down
1 change: 1 addition & 0 deletions platforms/linux/components.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,7 @@ static long hax_vm_ioctl(struct file *filp, unsigned int cmd,
default:
// TODO: Print information about the process that sent the ioctl.
hax_log(HAX_LOGE, "Unknown VM IOCTL 0x%lx\n", cmd);
ret = -ENOSYS;
break;
}
hax_put_vm(cvm);
Expand Down
12 changes: 12 additions & 0 deletions platforms/linux/hax_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "../../include/hax_interface.h"
#include "../../include/hax_release_ver.h"
#include "../../core/include/hax_core_interface.h"
#include "../../core/include/config.h"

MODULE_LICENSE("Dual BSD/GPL");
MODULE_AUTHOR("Kryptos Logic");
Expand Down Expand Up @@ -106,7 +107,18 @@ static long hax_dev_ioctl(struct file *filp, unsigned int cmd,
return -EFAULT;
break;
}
case HAX_IOCTL_CAP_MAX_VCPU: {
int max_vcpu = HAX_MAX_VCPUS;

if (copy_to_user(argp, &max_vcpu, sizeof(max_vcpu)))
return -EFAULT;

break;
}

default:
hax_log(HAX_LOGE, "Invalid HAX IOCTL 0x%lx\n", cmd);
ret = -ENOSYS;
break;
}
return ret;
Expand Down
4 changes: 4 additions & 0 deletions platforms/netbsd/hax_entry_hax.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ int hax_ioctl(dev_t self __unused, u_long cmd, void *data, int flag,
*((uint32_t *)data) = vm_id;
break;
}
case HAX_IOCTL_CAP_MAX_VCPU: {
*((uint32_t *)data) = HAX_MAX_VCPUS;
break;
}
default:
hax_log(HAX_LOGE, "Unknown ioctl %#lx, pid=%d ('%s')\n", cmd,
l->l_proc->p_pid, l->l_proc->p_comm);
Expand Down
10 changes: 10 additions & 0 deletions platforms/windows/hax_entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <string.h>

#include "hax_win.h"
#include "../../core/include/config.h"

// vcpu.h
int vcpu_takeoff(struct vcpu_t *vcpu);
Expand Down Expand Up @@ -714,6 +715,15 @@ NTSTATUS HaxDeviceControl(PDEVICE_OBJECT DeviceObject,
infret = sizeof(uint32_t);
ret = STATUS_SUCCESS;
break;
case HAX_IOCTL_CAP_MAX_VCPU:
if (outBufLength < sizeof(uint32_t)) {
ret = STATUS_BUFFER_TOO_SMALL;
goto done;
}
*((uint32_t *)outBuf) = HAX_MAX_VCPUS;
infret = sizeof(uint32_t);
ret = STATUS_SUCCESS;
break;
default:
ret = STATUS_INVALID_DEVICE_REQUEST;
hax_log(HAX_LOGE, "Invalid hax ioctl %x\n",
Expand Down
2 changes: 2 additions & 0 deletions platforms/windows/hax_entry.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ extern PDRIVER_OBJECT HaxDriverObject;
CTL_CODE(HAX_DEVICE_TYPE, 0x910, METHOD_BUFFERED, FILE_ANY_ACCESS)
#define HAX_IOCTL_SET_MEMLIMIT \
CTL_CODE(HAX_DEVICE_TYPE, 0x911, 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)
Expand Down

0 comments on commit decf12c

Please sign in to comment.