Dev Passthrough QEMU patch
This patch is for testing only and goes along with other two patches for priodrop and dev passthrough, it should apply against 1.4.5.
cpus.c +20 -0
@@ -737,6 +737,26 @@ static void *qemu_kvm_cpu_thread_fn(void *arg)CPUState *cpu =ENV_GET_CPU (env);int r; +/* For now just do a 1:1 vCPU binding as they come online for device +* pass through +*/ +cpu_set_t cpuset; +int ret, i; +unsigned long cpu_index =kvm_arch_vcpu_id (cpu); + +CPU_ZERO (&cpuset); +CPU_SET (cpu_index, &cpuset); + ret =pthread_setaffinity_np (pthread_self (),sizeof (cpu_set_t), &cpuset); +if (ret !=0 ) { +printf ("pthread_setaffinity_np failed to setaffinity to CPU 0\n" ); +exit (-1 ); + } + +CPU_ZERO (&cpuset); +pthread_getaffinity_np (pthread_self (),sizeof (cpu_set_t), &cpuset); +if (CPU_ISSET (cpu_index,&cpuset)) +printf ("Binding: vCPU %ld --> CPU %d\n" , cpu_index, i); +qemu_mutex_lock (&qemu_global_mutex);qemu_thread_get_self (cpu->thread); cpu->thread_id =qemu_get_thread_id ();
linux-headers/linux/kvm.h +32 -0
@@ -904,6 +904,8 @@ struct kvm_s390_ucas_mapping {#define KVM_PPC_GET_HTAB_FD _IOW(KVMIO, 0xaa, struct kvm_get_htab_fd)/* Available with KVM_CAP_ARM_SET_DEVICE_ADDR */ #define KVM_ARM_SET_DEVICE_ADDR _IOW(KVMIO, 0xab, struct kvm_arm_device_addr) +#define KVM_ARM_GET_DEVICE_RESOURCES _IOW(KVMIO, 0xe1, struct kvm_arm_get_device_resources) +#define KVM_ARM_ASSIGN_DEVICE _IOW(KVMIO, 0xe2, struct kvm_arm_assigned_device)/* * ioctls for vcpu fds
@@ -1013,6 +1015,7 @@ struct kvm_assigned_irq { }; }; +struct kvm_assigned_msix_nr {__u32 assigned_dev_id;__u16 entry_nr;
@@ -1027,4 +1030,33 @@ struct kvm_assigned_msix_entry { __u16 padding[3]; }; + +/* MAX 6 MMIO resources per device */ +#define MAX_RES_PER_DEVICE 6 +struct kvm_arm_get_device_resources { +char devname[128 ]; +__u32 resource_cnt; +struct { +__u64 hpa; +__u32 size; +__u32 attr; +char host_name[64 ]; + } host_resources[MAX_RES_PER_DEVICE ]; +struct { +__u32 hwirq; +__u32 attr; +char host_name[64 ]; + } hostirq; +}; + +struct kvm_guest_device_resources { +__u64 gpa[MAX_RES_PER_DEVICE ]; +__u32 girq; +}; + +struct kvm_arm_assigned_device { +struct kvm_arm_get_device_resources dev_res; +struct kvm_guest_device_resources guest_res; +}; +#endif /* __LINUX_KVM_H */
target-arm/Makefile.objs +1 -1
@@ -1,5 +1,5 @@ obj-y += arm-semi.o obj-$(CONFIG_SOFTMMU) += machine.o -obj-$(CONFIG_KVM) += kvm.o +obj-$(CONFIG_KVM) += kvm.o device-assign.o obj-y += translate.o op_helper.o helper.o cpu.o obj-y += neon_helper.o iwmmxt_helper.o
target-arm/device-assign.c new file +118 -0
118 lines not on this page · raw message
target-arm/kvm.c +1 -0
@@ -22,6 +22,7 @@#include "kvm_arm.h" #include "cpu.h" #include "hw/arm/arm.h" +#include "qemu/error-report.h" const KVMCapabilityInfo kvm_arch_required_capabilities[] = {KVM_CAP_LAST_INFO
target-arm/kvm_arm.h +2 -0
@@ -29,4 +29,6 @@*/ void kvm_arm_register_device (MemoryRegion *mr,uint64_t devid); +int kvm_device_assign (KVMState *s,char *, ...); +#endif