Move msix.o back to target independent files list
v2 cover Move msix.o back to target independent files list
Due to a depedency on kvm's msix support, msix.c was changed to be a target dependent file. This patch set changes it back.
v2: make the msix.c->kvm.c interface at a finer granularity, removing the need
for kvm code to know about PCIDevice.
Avi Kivity (8):
msix: avoid leaking kvm data on init failure
kvm: drop kvm_context parameter from msix-related kvm functions Avoid using kvm_irq_routing_entry in PCIDevice
Avoid use of kvm_irq_routing_entry in hw/msix.c
kvm: Add stubs for msix support code
kvm: allow kvm.h to be included from target independent files
msix: remove CONFIG_KVM depedency
Move msix.o build back to Makefile.objs
Makefile.objs | 4 +-- Makefile.target | 4 -- hw/device-assignment.c | 14 ++++---- hw/msix.c | 82 ++++++++++++++++++++++++------------------------ hw/pci.h | 9 +++++- kvm-stub.c | 35 ++++++++++++++++++++ kvm.h | 22 +++++++++++-- qemu-kvm-x86.c | 14 ++++---- qemu-kvm.c | 77 ++++++++++++++++++++++++++++++++++++-------- qemu-kvm.h | 55 ++++---------------------------- roms/seabios | 2 +- 11 files changed, 189 insertions(+), 129 deletions(-)
Signature · 1 line
1.7.3.1
PATCH v2 1/8 msix: avoid leaking kvm data on init failure
Move initialization after we're certain to succeed, so we don't leak memory on failure.
--- hw/msix.c | 13 +++++++------ 1 files changed, 7 insertions(+), 6 deletions(-)
hw/msix.c +7 -6
@@ -374,12 +374,6 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries,if (nentries >MSIX_MAX_ENTRIES )return -EINVAL ; -#ifdef KVM_CAP_IRQCHIP -if (kvm_enabled () &&kvm_irqchip_in_kernel ()) { - dev->msix_irq_entries =qemu_malloc (nentries * -sizeof *dev->msix_irq_entries); - } -#endif dev->msix_mask_notifier_opaque =qemu_mallocz (nentries *sizeof *dev->msix_mask_notifier_opaque); dev->msix_mask_notifier =NULL ;
@@ -401,6 +395,13 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries,if (ret) goto err_config; +#ifdef KVM_CAP_IRQCHIP +if (kvm_enabled () &&kvm_irqchip_in_kernel ()) { + dev->msix_irq_entries =qemu_malloc (nentries * +sizeof *dev->msix_irq_entries); + } +#endif + dev->cap_present |=QEMU_PCI_CAP_MSIX ;return 0 ;
Signature · 1 line
1.7.3.1
PATCH v2 2/8 kvm: drop kvm_context parameter from msix-related kvm functions
In reply to Avi KivityThe kvm_context parameter serves no useful purpose since it's a global (and all callers reference that global); on the other hand it prevents the build when kvm is not configured in since the kvm_context symbol is not defined.
Remove the parameter and replace it by the global kvm_context in callees.
--- hw/device-assignment.c | 14 +++++++------- hw/msix.c | 20 ++++++++++---------- qemu-kvm-x86.c | 14 +++++++------- qemu-kvm.c | 33 +++++++++++++++++++-------------- qemu-kvm.h | 36 ++++++++++-------------------------- 5 files changed, 53 insertions(+), 64 deletions(-)
hw/device-assignment.c +7 -7
@@ -767,7 +767,7 @@ static void free_dev_irq_entries(AssignedDevice *dev)int i;for (i =0 ; i < dev->irq_entries_nr; i++) -kvm_del_routing_entry (kvm_context, &dev->entry[i]); +kvm_del_routing_entry (&dev->entry[i]);free (dev->entry); dev->entry =NULL ; dev->irq_entries_nr =0 ;
@@ -1080,15 +1080,15 @@ static void assigned_dev_update_msi(PCIDevice *pci_dev, unsigned int ctrl_pos) assigned_dev->entry->u.msi.data = *(uint16_t *)(pci_dev->config + pci_dev->cap.start +PCI_MSI_DATA_32 ); assigned_dev->entry->type =KVM_IRQ_ROUTING_MSI ; - r =kvm_get_irq_route_gsi (kvm_context); + r =kvm_get_irq_route_gsi ();if (r <0 ) {perror ("assigned_dev_update_msi: kvm_get_irq_route_gsi" );return ; } assigned_dev->entry->gsi = r; -kvm_add_routing_entry (kvm_context, assigned_dev->entry); -if (kvm_commit_irq_routes (kvm_context) <0 ) { +kvm_add_routing_entry (assigned_dev->entry); +if (kvm_commit_irq_routes () <0 ) {perror ("assigned_dev_update_msi: kvm_commit_irq_routes" ); assigned_dev->cap.state &= ~ASSIGNED_DEVICE_MSI_ENABLED ;return ;
@@ -1170,7 +1170,7 @@ static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev)memcpy (&msg_addr, va + i *16 ,4 );memcpy (&msg_upper_addr, va + i *16 +4 ,4 ); - r =kvm_get_irq_route_gsi (kvm_context); + r =kvm_get_irq_route_gsi ();if (r <0 )return r;
@@ -1181,7 +1181,7 @@ static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev) adev->entry[entries_nr].u.msi.address_hi = msg_upper_addr; adev->entry[entries_nr].u.msi.data = msg_data;DEBUG ("MSI-X data 0x%x, MSI-X addr_lo 0x%x\n!" , msg_data, msg_addr); -kvm_add_routing_entry (kvm_context, &adev->entry[entries_nr]); +kvm_add_routing_entry (&adev->entry[entries_nr]); msix_entry.gsi = adev->entry[entries_nr].gsi; msix_entry.entry = i;
@@ -1195,7 +1195,7 @@ static int assigned_dev_update_msix_mmio(PCIDevice *pci_dev) entries_nr ++; } -if (r ==0 &&kvm_commit_irq_routes (kvm_context) <0 ) { +if (r ==0 &&kvm_commit_irq_routes () <0 ) {perror ("assigned_dev_update_msix_mmio: kvm_commit_irq_routes" );return -EINVAL ; }
hw/msix.c +10 -10
@@ -54,12 +54,12 @@ static void kvm_msix_free(PCIDevice *dev)int vector, changed =0 ;for (vector =0 ; vector < dev->msix_entries_nr; ++vector) {if (dev->msix_entry_used[vector]) { -kvm_del_routing_entry (kvm_context, &dev->msix_irq_entries[vector]); +kvm_del_routing_entry (&dev->msix_irq_entries[vector]); changed =1 ; } }if (changed) { -kvm_commit_irq_routes (kvm_context); +kvm_commit_irq_routes (); } }
@@ -92,14 +92,14 @@ static void kvm_msix_update(PCIDevice *dev, int vector,kvm_msix_routing_entry (dev, vector, &e);if (memcmp (&entry->u.msi, &e.u.msi,sizeof entry->u.msi)) {int r; - r =kvm_update_routing_entry (kvm_context, entry, &e); + r =kvm_update_routing_entry (entry, &e);if (r) {fprintf (stderr,"%s: kvm_update_routing_entry failed: %s\n" , __func__,strerror (-r));exit (1 ); }memcpy (&entry->u.msi, &e.u.msi,sizeof entry->u.msi); - r =kvm_commit_irq_routes (kvm_context); + r =kvm_commit_irq_routes ();if (r) {fprintf (stderr,"%s: kvm_commit_irq_routes failed: %s\n" , __func__,strerror (-r));
@@ -113,27 +113,27 @@ static int kvm_msix_add(PCIDevice *dev, unsigned vector)struct kvm_irq_routing_entry *entry = dev->msix_irq_entries + vector;int r; -if (!kvm_has_gsi_routing (kvm_context)) { +if (!kvm_has_gsi_routing ()) {fprintf (stderr,"Warning: no MSI-X support found. " "At least kernel 2.6.30 is required for MSI-X support.\n" );return -EOPNOTSUPP ; } - r =kvm_get_irq_route_gsi (kvm_context); + r =kvm_get_irq_route_gsi ();if (r <0 ) {fprintf (stderr,"%s: kvm_get_irq_route_gsi failed: %s\n" , __func__,strerror (-r));return r; } entry->gsi = r;kvm_msix_routing_entry (dev, vector, entry); - r =kvm_add_routing_entry (kvm_context, entry); + r =kvm_add_routing_entry (entry);if (r <0 ) {fprintf (stderr,"%s: kvm_add_routing_entry failed: %s\n" , __func__,strerror (-r));return r; } - r =kvm_commit_irq_routes (kvm_context); + r =kvm_commit_irq_routes ();if (r <0 ) {fprintf (stderr,"%s: kvm_commit_irq_routes failed: %s\n" , __func__,strerror (-r));return r;
@@ -146,8 +146,8 @@ static void kvm_msix_del(PCIDevice *dev, unsigned vector)if (dev->msix_entry_used[vector]) {return ; } -kvm_del_routing_entry (kvm_context, &dev->msix_irq_entries[vector]); - kvm_commit_irq_routes(kvm_context); +kvm_del_routing_entry (&dev->msix_irq_entries[vector]); + kvm_commit_irq_routes(); }#else
qemu-kvm-x86.c +7 -7
@@ -1370,34 +1370,34 @@ int kvm_arch_init_irq_routing(void) {int i, r; -if (kvm_irqchip &&kvm_has_gsi_routing (kvm_context)) { -kvm_clear_gsi_routes (kvm_context); +if (kvm_irqchip &&kvm_has_gsi_routing ()) { +kvm_clear_gsi_routes ();for (i =0 ; i <8 ; ++i) {if (i ==2 ) {continue ; } - r =kvm_add_irq_route (kvm_context, i,KVM_IRQCHIP_PIC_MASTER , i); + r =kvm_add_irq_route (i,KVM_IRQCHIP_PIC_MASTER , i);if (r <0 ) {return r; } }for (i =8 ; i <16 ; ++i) { - r =kvm_add_irq_route (kvm_context, i,KVM_IRQCHIP_PIC_SLAVE , i -8 ); + r =kvm_add_irq_route (i,KVM_IRQCHIP_PIC_SLAVE , i -8 );if (r <0 ) {return r; } }for (i =0 ; i <24 ; ++i) {if (i ==0 && irq0override) { - r =kvm_add_irq_route (kvm_context, i,KVM_IRQCHIP_IOAPIC ,2 ); + r =kvm_add_irq_route (i,KVM_IRQCHIP_IOAPIC ,2 ); }else if (i !=2 || !irq0override) { - r =kvm_add_irq_route (kvm_context, i,KVM_IRQCHIP_IOAPIC , i); + r =kvm_add_irq_route (i,KVM_IRQCHIP_IOAPIC , i); }if (r <0 ) {return r; } } -kvm_commit_irq_routes (kvm_context); +kvm_commit_irq_routes (); }return 0 ; }
qemu-kvm.c +19 -14
@@ -800,7 +800,7 @@ int kvm_reinject_control(kvm_context_t kvm, int pit_reinject)return -ENOSYS ; } -int kvm_has_gsi_routing (kvm_context_t kvm) +int kvm_has_gsi_routing (void ) {int r =0 ;
@@ -819,9 +819,11 @@ int kvm_get_gsi_count(kvm_context_t kvm)#endif } -int kvm_clear_gsi_routes (kvm_context_t kvm) +int kvm_clear_gsi_routes (void ) {#ifdef KVM_CAP_IRQ_ROUTING +kvm_context_t kvm = kvm_context; + kvm->irq_routes->nr =0 ;return 0 ;#else
@@ -829,10 +831,10 @@ int kvm_clear_gsi_routes(kvm_context_t kvm)#endif } -int kvm_add_routing_entry (kvm_context_t kvm, -struct kvm_irq_routing_entry *entry) +int kvm_add_routing_entry (struct kvm_irq_routing_entry *entry) {#ifdef KVM_CAP_IRQ_ROUTING +kvm_context_t kvm = kvm_context;struct kvm_irq_routing *z;struct kvm_irq_routing_entry *new;int n, size;
@@ -867,7 +869,7 @@ int kvm_add_routing_entry(kvm_context_t kvm,#endif } -int kvm_add_irq_route (kvm_context_t kvm,int gsi,int irqchip,int pin) +int kvm_add_irq_route (int gsi,int irqchip,int pin) {#ifdef KVM_CAP_IRQ_ROUTING struct kvm_irq_routing_entry e;
@@ -877,16 +879,16 @@ int kvm_add_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin) e.flags =0 ; e.u.irqchip.irqchip = irqchip; e.u.irqchip.pin = pin; -return kvm_add_routing_entry (kvm, &e); +return kvm_add_routing_entry (&e);#else return -ENOSYS ;#endif } -int kvm_del_routing_entry (kvm_context_t kvm, -struct kvm_irq_routing_entry *entry) +int kvm_del_routing_entry (struct kvm_irq_routing_entry *entry) {#ifdef KVM_CAP_IRQ_ROUTING +kvm_context_t kvm = kvm_context;struct kvm_irq_routing_entry *e, *p;int i, gsi, found =0 ;
@@ -943,11 +945,11 @@ int kvm_del_routing_entry(kvm_context_t kvm,#endif } -int kvm_update_routing_entry (kvm_context_t kvm, -struct kvm_irq_routing_entry *entry, +int kvm_update_routing_entry (struct kvm_irq_routing_entry *entry,struct kvm_irq_routing_entry *newentry) {#ifdef KVM_CAP_IRQ_ROUTING +kvm_context_t kvm = kvm_context;struct kvm_irq_routing_entry *e;int i;
@@ -987,7 +989,7 @@ int kvm_update_routing_entry(kvm_context_t kvm,#endif } -int kvm_del_irq_route (kvm_context_t kvm,int gsi,int irqchip,int pin) +int kvm_del_irq_route (int gsi,int irqchip,int pin) {#ifdef KVM_CAP_IRQ_ROUTING struct kvm_irq_routing_entry e;
@@ -997,15 +999,17 @@ int kvm_del_irq_route(kvm_context_t kvm, int gsi, int irqchip, int pin) e.flags =0 ; e.u.irqchip.irqchip = irqchip; e.u.irqchip.pin = pin; -return kvm_del_routing_entry (kvm, &e); +return kvm_del_routing_entry (&e);#else return -ENOSYS ;#endif } -int kvm_commit_irq_routes (kvm_context_t kvm) +int kvm_commit_irq_routes (void ) {#ifdef KVM_CAP_IRQ_ROUTING +kvm_context_t kvm = kvm_context; + kvm->irq_routes->flags =0 ;return kvm_vm_ioctl (kvm_state,KVM_SET_GSI_ROUTING , kvm->irq_routes);#else
@@ -1013,8 +1017,9 @@ int kvm_commit_irq_routes(kvm_context_t kvm)#endif } -int kvm_get_irq_route_gsi (kvm_context_t kvm) +int kvm_get_irq_route_gsi (void ) { +kvm_context_t kvm = kvm_context;int i, bit;uint32_t *buf = kvm->used_gsi_bitmap;
qemu-kvm.h +10 -26
@@ -665,10 +665,8 @@ int kvm_deassign_pci_device(kvm_context_t kvm,* * Checks whether kvm can reroute interrupts among the various interrupt * controllers. -* -* \param kvm Pointer to the current kvm_context */ -int kvm_has_gsi_routing (kvm_context_t kvm); +int kvm_has_gsi_routing (void );/*! * \brief Determines the number of gsis that can be routed
@@ -687,29 +685,24 @@ int kvm_get_gsi_count(kvm_context_t kvm);* Clears the temporary irq routing table. Nothing is committed to the * running VM. * -* \param kvm Pointer to the current kvm_context */ -int kvm_clear_gsi_routes (kvm_context_t kvm); +int kvm_clear_gsi_routes (void );/*! * \brief Adds an irq route to the temporary irq routing table * * Adds an irq route to the temporary irq routing table. Nothing is * committed to the running VM. -* -* \param kvm Pointer to the current kvm_context */ -int kvm_add_irq_route (kvm_context_t kvm,int gsi,int irqchip,int pin); +int kvm_add_irq_route (int gsi,int irqchip,int pin);/*! * \brief Removes an irq route from the temporary irq routing table * * Adds an irq route to the temporary irq routing table. Nothing is * committed to the running VM. -* -* \param kvm Pointer to the current kvm_context */ -int kvm_del_irq_route (kvm_context_t kvm,int gsi,int irqchip,int pin); +int kvm_del_irq_route (int gsi,int irqchip,int pin);struct kvm_irq_routing_entry ;/*!
@@ -717,22 +710,16 @@ struct kvm_irq_routing_entry;* * Adds a filled routing entry to the temporary irq routing table. Nothing is * committed to the running VM. -* -* \param kvm Pointer to the current kvm_context */ -int kvm_add_routing_entry (kvm_context_t kvm, -struct kvm_irq_routing_entry *entry); +int kvm_add_routing_entry (struct kvm_irq_routing_entry *entry);/*! * \brief Removes a routing from the temporary irq routing table * * Remove a routing to the temporary irq routing table. Nothing is * committed to the running VM. -* -* \param kvm Pointer to the current kvm_context */ -int kvm_del_routing_entry (kvm_context_t kvm, -struct kvm_irq_routing_entry *entry); +int kvm_del_routing_entry (struct kvm_irq_routing_entry *entry);/*! * \brief Updates a routing in the temporary irq routing table
@@ -740,11 +727,8 @@ int kvm_del_routing_entry(kvm_context_t kvm,* Update a routing in the temporary irq routing table * with a new value. entry type and GSI can not be changed. * Nothing is committed to the running VM. -* -* \param kvm Pointer to the current kvm_context */ -int kvm_update_routing_entry (kvm_context_t kvm, -struct kvm_irq_routing_entry *entry, +int kvm_update_routing_entry (struct kvm_irq_routing_entry *entry,struct kvm_irq_routing_entry *newentry);/*!
@@ -754,7 +738,7 @@ int kvm_update_routing_entry(kvm_context_t kvm,* * \param kvm Pointer to the current kvm_context */ -int kvm_commit_irq_routes (kvm_context_t kvm); +int kvm_commit_irq_routes (void );/*! * \brief Get unused GSI number for irq routing table
@@ -763,7 +747,7 @@ int kvm_commit_irq_routes(kvm_context_t kvm);* * \param kvm Pointer to the current kvm_context */ -int kvm_get_irq_route_gsi (kvm_context_t kvm); +int kvm_get_irq_route_gsi (void );/*! * \brief Create a file descriptor for injecting interrupts
@@ -903,7 +887,7 @@ int kvm_arch_halt(CPUState *env);int handle_tpr_access (void *opaque,CPUState *env,uint64_t rip,int is_write); -#define qemu_kvm_has_gsi_routing () kvm_has_gsi_routing(kvm_context) +#define qemu_kvm_has_gsi_routing () kvm_has_gsi_routing()#ifdef TARGET_I386 #define qemu_kvm_has_pit_state2 () kvm_has_pit_state2(kvm_context)#endif
Signature · 1 line
1.7.3.1
PATCH v2 3/8 Avoid using kvm_irq_routing_entry in PCIDevice
In reply to Avi KivityThis structure is not available when !CONFIG_KVM. While an incomplete type works if it's not used, you can't do address arithmetic on it.
Use a new type kvm_msix_message instead.
--- hw/msix.c | 60 ++++++++++++++++++++++++++++++++++++++++++------------------ hw/pci.h | 9 ++++++++- 2 files changed, 50 insertions(+), 19 deletions(-)
hw/msix.c +42 -18
@@ -48,13 +48,29 @@int msix_supported;#ifdef CONFIG_KVM + +static void kvm_msix_message_to_routing_entry (struct kvm_msix_message *kmm, +struct kvm_irq_routing_entry *e) +{ + e->type =KVM_IRQ_ROUTING_MSI ; + e->flags =0 ; + e->u.msi.address_lo = kmm->addr_lo; + e->u.msi.address_hi = kmm->addr_hi; + e->u.msi.data = kmm->data; +} +/* KVM specific MSIX helpers */ static void kvm_msix_free (PCIDevice *dev) {int vector, changed =0 ; +struct kvm_msix_message *kmm; +struct kvm_irq_routing_entry entry; +for (vector =0 ; vector < dev->msix_entries_nr; ++vector) {if (dev->msix_entry_used[vector]) { -kvm_del_routing_entry (&dev->msix_irq_entries[vector]); + kmm = &dev->msix_irq_entries[vector]; +kvm_msix_message_to_routing_entry (kmm, &entry); +kvm_del_routing_entry (&entry); changed =1 ; } }
@@ -63,21 +79,20 @@ static void kvm_msix_free(PCIDevice *dev) } } -static void kvm_msix_routing_entry (PCIDevice *dev,unsigned vector, -struct kvm_irq_routing_entry *entry) +static void kvm_msix_message_from_vector (PCIDevice *dev,unsigned vector, +struct kvm_msix_message *kmm) {uint8_t *table_entry = dev->msix_table_page + vector *MSIX_ENTRY_SIZE ; - entry->type =KVM_IRQ_ROUTING_MSI ; - entry->flags =0 ; - entry->u.msi.address_lo =pci_get_long (table_entry +MSIX_MSG_ADDR ); - entry->u.msi.address_hi =pci_get_long (table_entry +MSIX_MSG_UPPER_ADDR ); - entry->u.msi.data =pci_get_long (table_entry +MSIX_MSG_DATA ); + + kmm->addr_lo =pci_get_long (table_entry +MSIX_MSG_ADDR ); + kmm->addr_hi =pci_get_long (table_entry +MSIX_MSG_UPPER_ADDR ); + kmm->data =pci_get_long (table_entry +MSIX_MSG_DATA ); }static void kvm_msix_update (PCIDevice *dev,int vector,int was_masked,int is_masked) { -struct kvm_irq_routing_entry e = {}, *entry; +struct kvm_msix_message e = {}, *entry;int mask_cleared = was_masked && !is_masked;/* It is only legal to change an entry when it is masked. Therefore, it is * enough to update the routing in kernel when mask is being cleared. */
@@ -89,16 +104,20 @@ static void kvm_msix_update(PCIDevice *dev, int vector, } entry = dev->msix_irq_entries + vector; e.gsi = entry->gsi; -kvm_msix_routing_entry (dev, vector, &e); -if (memcmp (&entry->u.msi, &e.u.msi,sizeof entry->u.msi)) { +kvm_msix_message_from_vector (dev, vector, &e); +if (memcmp (entry, &e,sizeof e) !=0 ) { +struct kvm_irq_routing_entry old, new;int r; - r =kvm_update_routing_entry (entry, &e); + +kvm_msix_message_to_routing_entry (entry, &old); +kvm_msix_message_to_routing_entry (&e, &new); + r =kvm_update_routing_entry (&old, &new);if (r) {fprintf (stderr,"%s: kvm_update_routing_entry failed: %s\n" , __func__,strerror (-r));exit (1 ); } -memcpy (&entry->u.msi, &e.u.msi,sizeof entry->u.msi); + *entry = e; r =kvm_commit_irq_routes ();if (r) { fprintf(stderr, "%s: kvm_commit_irq_routes failed: %s\n", __func__,
@@ -110,7 +129,8 @@ static void kvm_msix_update(PCIDevice *dev, int vector,static int kvm_msix_add (PCIDevice *dev,unsigned vector) { -struct kvm_irq_routing_entry *entry = dev->msix_irq_entries + vector; +struct kvm_msix_message *kmm = dev->msix_irq_entries + vector; +struct kvm_irq_routing_entry entry;int r;if (!kvm_has_gsi_routing ()) {
@@ -125,9 +145,10 @@ static int kvm_msix_add(PCIDevice *dev, unsigned vector)fprintf (stderr,"%s: kvm_get_irq_route_gsi failed: %s\n" , __func__,strerror (-r));return r; } - entry->gsi = r; -kvm_msix_routing_entry (dev, vector, entry); - r =kvm_add_routing_entry (entry); + kmm->gsi = r; +kvm_msix_message_from_vector (dev, vector, kmm); +kvm_msix_message_to_routing_entry (kmm, &entry); + r =kvm_add_routing_entry (&entry);if (r <0 ) {fprintf (stderr,"%s: kvm_add_routing_entry failed: %s\n" , __func__,strerror (-r));return r;
@@ -143,10 +164,13 @@ static int kvm_msix_add(PCIDevice *dev, unsigned vector)static void kvm_msix_del (PCIDevice *dev,unsigned vector) { +struct kvm_irq_routing_entry entry; +if (dev->msix_entry_used[vector]) {return ; } -kvm_del_routing_entry (&dev->msix_irq_entries[vector]); +kvm_msix_message_to_routing_entry (&dev->msix_irq_entries[vector], &entry); +kvm_del_routing_entry (&entry);kvm_commit_irq_routes (); }#else
hw/pci.h +8 -1
@@ -133,6 +133,13 @@ enum {typedef int (*msix_mask_notifier_func )(PCIDevice *,unsigned vector,void *opaque,int masked); +struct kvm_msix_message { +uint32_t gsi; +uint32_t addr_lo; +uint32_t addr_hi; +uint32_t data; +}; +struct PCIDevice {DeviceState qdev;/* PCI config space */
@@ -196,7 +203,7 @@ struct PCIDevice {* on the rest of the region. */ target_phys_addr_t msix_page_size; -struct kvm_irq_routing_entry *msix_irq_entries; +struct kvm_msix_message *msix_irq_entries;void **msix_mask_notifier_opaque;msix_mask_notifier_func msix_mask_notifier;
Signature · 1 line
1.7.3.1
PATCH v2 4/8 Avoid use of kvm_irq_routing_entry in hw/msix.c
In reply to Avi Kivitykvm_irq_routing_entry cannot be used when CONFIG_KVM is disabled; add a new interface to the kvm support code that uses scalars instead.
--- hw/msix.c | 35 ++++++++++------------------------- qemu-kvm.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ qemu-kvm.h | 9 +++++++++ roms/seabios | 2 +- 4 files changed, 64 insertions(+), 26 deletions(-)
hw/msix.c +10 -25
@@ -49,28 +49,16 @@ int msix_supported;#ifdef CONFIG_KVM -static void kvm_msix_message_to_routing_entry (struct kvm_msix_message *kmm, -struct kvm_irq_routing_entry *e) -{ - e->type =KVM_IRQ_ROUTING_MSI ; - e->flags =0 ; - e->u.msi.address_lo = kmm->addr_lo; - e->u.msi.address_hi = kmm->addr_hi; - e->u.msi.data = kmm->data; -} -/* KVM specific MSIX helpers */ static void kvm_msix_free (PCIDevice *dev) {int vector, changed =0 ;struct kvm_msix_message *kmm; -struct kvm_irq_routing_entry entry;for (vector =0 ; vector < dev->msix_entries_nr; ++vector) {if (dev->msix_entry_used[vector]) { kmm = &dev->msix_irq_entries[vector]; -kvm_msix_message_to_routing_entry (kmm, &entry); -kvm_del_routing_entry (&entry); +kvm_del_msix (kmm->gsi, kmm->addr_lo, kmm->addr_hi, kmm->data); changed =1 ; } }
@@ -106,14 +94,13 @@ static void kvm_msix_update(PCIDevice *dev, int vector, e.gsi = entry->gsi;kvm_msix_message_from_vector (dev, vector, &e);if (memcmp (entry, &e,sizeof e) !=0 ) { -struct kvm_irq_routing_entry old, new;int r; -kvm_msix_message_to_routing_entry (entry, &old); -kvm_msix_message_to_routing_entry (&e, &new); - r =kvm_update_routing_entry (&old, &new); + r =kvm_update_msix (entry->gsi, entry->addr_lo, + entry->addr_hi, entry->data, + e.gsi, e.addr_lo, e.addr_hi, e.data);if (r) { -fprintf (stderr,"%s: kvm_update_routing_entry failed: %s\n" , __func__, +fprintf (stderr,"%s: kvm_update_msix failed: %s\n" , __func__,strerror (-r));exit (1 ); }
@@ -130,7 +117,6 @@ static void kvm_msix_update(PCIDevice *dev, int vector,static int kvm_msix_add (PCIDevice *dev,unsigned vector) {struct kvm_msix_message *kmm = dev->msix_irq_entries + vector; -struct kvm_irq_routing_entry entry;int r;if (!kvm_has_gsi_routing ()) {
@@ -147,10 +133,9 @@ static int kvm_msix_add(PCIDevice *dev, unsigned vector) } kmm->gsi = r;kvm_msix_message_from_vector (dev, vector, kmm); -kvm_msix_message_to_routing_entry (kmm, &entry); - r =kvm_add_routing_entry (&entry); + r =kvm_add_msix (kmm->gsi, kmm->addr_lo, kmm->addr_hi, kmm->data);if (r <0 ) { -fprintf (stderr,"%s: kvm_add_routing_entry failed: %s\n" , __func__,strerror (-r)); +fprintf (stderr,"%s: kvm_add_msix failed: %s\n" , __func__,strerror (-r));return r; }
@@ -164,13 +149,13 @@ static int kvm_msix_add(PCIDevice *dev, unsigned vector)static void kvm_msix_del (PCIDevice *dev,unsigned vector) { -struct kvm_irq_routing_entry entry; +struct kvm_msix_message *kmm;if (dev->msix_entry_used[vector]) {return ; } -kvm_msix_message_to_routing_entry (&dev->msix_irq_entries[vector], &entry); -kvm_del_routing_entry (&entry); + kmm = &dev->msix_irq_entries[vector]; +kvm_del_msix (kmm->gsi, kmm->addr_lo, kmm->addr_hi, kmm->data);kvm_commit_irq_routes (); }#else
qemu-kvm.c +44 -0
50 lines not on this page · raw message
qemu-kvm.h +9 -0
@@ -704,6 +704,15 @@ int kvm_add_irq_route(int gsi, int irqchip, int pin);*/ int kvm_del_irq_route (int gsi,int irqchip,int pin); +int kvm_add_msix (uint32_t gsi,uint32_t addr_lo, +uint32_t addr_hi,uint32_t data); +int kvm_del_msix (uint32_t gsi,uint32_t addr_lo, +uint32_t addr_hi,uint32_t data); +int kvm_update_msix (uint32_t old_gsi,uint32_t old_addr_lo, +uint32_t old_addr_hi,uint32_t old_data, +uint32_t new_gsi,uint32_t new_addr_lo, +uint32_t new_addr_hi,uint32_t new_data); +struct kvm_irq_routing_entry ;/*! * \brief Adds a routing entry to the temporary irq routing table
roms/seabios +1 -1
@@ -1 +1 @@ -Subproject commit 17d3e46511aeedc9f09a8216d194d749187b80aa +Subproject commit 94dc9c49c283cd576c25692d17567035557a2505
Signature · 1 line
1.7.3.1
PATCH v2 5/8 kvm: Add stubs for msix support code
In reply to Avi KivityTo allow msix to build without kvm support, add stubs for these functions. Move the declarations to kvm.h so they are accessible when kvm support is not built.
--- kvm-stub.c | 35 +++++++++++++++++++++++++++++++++++ kvm.h | 13 +++++++++++++ qemu-kvm.h | 34 ---------------------------------- 3 files changed, 48 insertions(+), 34 deletions(-)
kvm-stub.c +35 -0
@@ -141,3 +141,38 @@ int kvm_set_ioeventfd_mmio_long(int fd, uint32_t adr, uint32_t val, bool assign) {return -ENOSYS ; } + +int kvm_has_gsi_routing (void ) +{ +return 0 ; +} + +int kvm_get_irq_route_gsi (void ) +{ +return -ENOSYS ; +} + +int kvm_add_msix (uint32_t gsi,uint32_t addr_lo, +uint32_t addr_hi,uint32_t data) +{ +return -ENOSYS ; +} + +int kvm_del_msix (uint32_t gsi,uint32_t addr_lo, +uint32_t addr_hi,uint32_t data) +{ +return -ENOSYS ; +} + +int kvm_update_msix (uint32_t old_gsi,uint32_t old_addr_lo, +uint32_t old_addr_hi,uint32_t old_data, +uint32_t new_gsi,uint32_t new_addr_lo, +uint32_t new_addr_hi,uint32_t new_data) +{ +return -ENOSYS ; +} + +int kvm_commit_irq_routes (void ) +{ +return -ENOSYS ; +}
kvm.h +13 -0
@@ -198,4 +198,17 @@ int kvm_set_ioeventfd_pio_word(int fd, uint16_t adr, uint16_t val, bool assign);int kvm_physical_memory_addr_from_ram (KVMState *s,ram_addr_t ram_addr,target_phys_addr_t *phys_addr); + +int kvm_has_gsi_routing (void ); +int kvm_get_irq_route_gsi (void ); +int kvm_add_msix (uint32_t gsi,uint32_t addr_lo, +uint32_t addr_hi,uint32_t data); +int kvm_del_msix (uint32_t gsi,uint32_t addr_lo, +uint32_t addr_hi,uint32_t data); +int kvm_update_msix (uint32_t old_gsi,uint32_t old_addr_lo, +uint32_t old_addr_hi,uint32_t old_data, +uint32_t new_gsi,uint32_t new_addr_lo, +uint32_t new_addr_hi,uint32_t new_data); +int kvm_commit_irq_routes (void ); +#endif
qemu-kvm.h +0 -34
@@ -661,14 +661,6 @@ int kvm_deassign_pci_device(kvm_context_t kvm,#endif /*! -* \brief Checks whether the generic irq routing capability is present -* -* Checks whether kvm can reroute interrupts among the various interrupt -* controllers. -*/ -int kvm_has_gsi_routing (void ); - -/*! * \brief Determines the number of gsis that can be routed * * Returns the number of distinct gsis that can be routed by kvm. This is
@@ -704,15 +696,6 @@ int kvm_add_irq_route(int gsi, int irqchip, int pin);*/ int kvm_del_irq_route (int gsi,int irqchip,int pin); -int kvm_add_msix (uint32_t gsi,uint32_t addr_lo, -uint32_t addr_hi,uint32_t data); -int kvm_del_msix (uint32_t gsi,uint32_t addr_lo, -uint32_t addr_hi,uint32_t data); -int kvm_update_msix (uint32_t old_gsi,uint32_t old_addr_lo, -uint32_t old_addr_hi,uint32_t old_data, -uint32_t new_gsi,uint32_t new_addr_lo, -uint32_t new_addr_hi,uint32_t new_data); -struct kvm_irq_routing_entry ;/*! * \brief Adds a routing entry to the temporary irq routing table
@@ -740,23 +723,6 @@ int kvm_del_routing_entry(struct kvm_irq_routing_entry *entry);int kvm_update_routing_entry (struct kvm_irq_routing_entry *entry,struct kvm_irq_routing_entry *newentry); -/*! -* \brief Commit the temporary irq routing table -* -* Commit the temporary irq routing table to the running VM. -* -* \param kvm Pointer to the current kvm_context -*/ -int kvm_commit_irq_routes (void ); - -/*! -* \brief Get unused GSI number for irq routing table -* -* Get unused GSI number for irq routing table -* -* \param kvm Pointer to the current kvm_context -*/ -int kvm_get_irq_route_gsi (void );/*! * \brief Create a file descriptor for injecting interrupts
Signature · 1 line
1.7.3.1
PATCH v2 6/8 kvm: allow kvm.h to be included from target independent files
In reply to Avi Kivity- don't include qemu-kvm.h when NEED_CPU_H not defined
- move a couple of declarations around
--- kvm.h | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-)
kvm.h +7 -4
@@ -17,7 +17,9 @@#include <errno.h> #include "config-host.h" #include "qemu-queue.h" +#ifdef NEED_CPU_H #include "qemu-kvm.h" +#endif #ifdef CONFIG_KVM #include <linux/kvm.h>
@@ -75,7 +77,6 @@ int kvm_set_signal_mask(CPUState *env, const sigset_t *sigset);#endif int kvm_pit_in_kernel (void ); -int kvm_irqchip_in_kernel (void );/* internal API */
@@ -181,6 +182,9 @@ static inline void cpu_synchronize_post_init(CPUState *env) } } +int kvm_physical_memory_addr_from_ram (KVMState *s,ram_addr_t ram_addr, +target_phys_addr_t *phys_addr); +#endif int kvm_set_ioeventfd_mmio_long (int fd,uint32_t adr,uint32_t val,bool assign);
@@ -196,9 +200,6 @@ int kvm_set_irqfd(int gsi, int fd, bool assigned)int kvm_set_ioeventfd_pio_word (int fd,uint16_t adr,uint16_t val,bool assign); -int kvm_physical_memory_addr_from_ram (KVMState *s,ram_addr_t ram_addr, -target_phys_addr_t *phys_addr); -int kvm_has_gsi_routing (void );int kvm_get_irq_route_gsi (void ); int kvm_add_msix(uint32_t gsi, uint32_t addr_lo,
@@ -211,4 +212,6 @@ int kvm_update_msix(uint32_t old_gsi, uint32_t old_addr_lo, uint32_t new_addr_hi, uint32_t new_data);int kvm_commit_irq_routes (void ); +int kvm_irqchip_in_kernel (void ); +#endif
Signature · 1 line
1.7.3.1
PATCH v2 7/8 msix: remove CONFIG_KVM depedency
In reply to Avi KivityNow that the kvm support is properly stubbed, we can build the msix/kvm glue unconditionally.
--- hw/msix.c | 10 ---------- 1 files changed, 0 insertions(+), 10 deletions(-)
hw/msix.c +0 -10
@@ -47,8 +47,6 @@/* Flag for interrupt controller to declare MSI-X support */ int msix_supported; -#ifdef CONFIG_KVM -/* KVM specific MSIX helpers */ static void kvm_msix_free (PCIDevice *dev) {
@@ -158,14 +156,6 @@ static void kvm_msix_del(PCIDevice *dev, unsigned vector)kvm_del_msix (kmm->gsi, kmm->addr_lo, kmm->addr_hi, kmm->data);kvm_commit_irq_routes (); } -#else - -static void kvm_msix_free (PCIDevice *dev) {} -static void kvm_msix_update (PCIDevice *dev,int vector, -int was_masked,int is_masked) {} -static int kvm_msix_add (PCIDevice *dev,unsigned vector) {return -1 ; } -static void kvm_msix_del (PCIDevice *dev,unsigned vector) {} -#endif /* Add MSI-X capability to the config space for the device. */ /* Given a bar and its size, add MSI-X table on top of it
Signature · 1 line
1.7.3.1
PATCH v2 8/8 Move msix.o build back to Makefile.objs
In reply to Avi KivityNow that hw/msix.c does not depend on CONFIG_KVM, remove it from Makefile.target and put it back in Makefile.objs.
--- Makefile.objs | 4 +--- Makefile.target | 4 ---- 2 files changed, 1 insertions(+), 7 deletions(-)
Makefile.objs +1 -3
@@ -196,9 +196,7 @@ hw-obj-$(CONFIG_PIIX4) += piix4.o # PCI watchdog devices hw-obj-y += wdt_i6300esb.o -# MSI-X depends on kvm for interrupt injection, -# so moved it from Makefile.objs to Makefile.target for now -# hw-obj-y += msix.o +hw-obj-y += msix.o # PCI network cards hw-obj-y += ne2000.o
Makefile.target +0 -4
@@ -183,10 +183,6 @@ obj-y += rwhandler.o obj-$(CONFIG_KVM) += kvm.o kvm-all.o obj-$(CONFIG_NO_KVM) += kvm-stub.o -# MSI-X depends on kvm for interrupt injection, -# so moved it from Makefile.objs to Makefile.target for now -obj-y += msix.o - LIBS+=-lz QEMU_CFLAGS += $(VNC_TLS_CFLAGS)
Signature · 1 line
1.7.3.1
Quoted 2 lines · Avi Kivity
Due to a depedency on kvm's msix support,
msix.cwas changed to be a target dependent file. This patch set changes it back.
Nothing to object to here :). FWIW
Quoted 28 lines
v2: make the
msix.c->kvm.cinterface at a finer granularity, removing the need
for kvm code to know about PCIDevice.Avi Kivity (8):
msix: avoid leaking kvm data on init failure
kvm: dropkvm_contextparameter from msix-related kvm functions Avoid usingkvm_irq_routing_entryin PCIDevice
Avoid use ofkvm_irq_routing_entryinhw/msix.c
kvm: Add stubs for msix support code
kvm: allowkvm.hto be included from target independent files
msix: removeCONFIG_KVMdepedency
Move msix.o build back to Makefile.objsMakefile.objs | 4 +-- Makefile.target | 4 -- hw/device-assignment.c | 14 ++++---- hw/msix.c | 82 ++++++++++++++++++++++++------------------------ hw/pci.h | 9 +++++- kvm-stub.c | 35 ++++++++++++++++++++ kvm.h | 22 +++++++++++-- qemu-kvm-x86.c | 14 ++++---- qemu-kvm.c | 77 ++++++++++++++++++++++++++++++++++++-------- qemu-kvm.h | 55 ++++---------------------------- roms/seabios | 2 +- 11 files changed, 189 insertions(+), 129 deletions(-)Signature · 1 line
1.7.3.1
Quoted 6 lines · Avi Kivity
Due to a depedency on kvm's msix support,
msix.cwas changed to be a target dependent file. This patch set changes it back.v2: make the
msix.c->kvm.cinterface at a finer granularity, removing the need
for kvm code to know about PCIDevice.
Quoted 9 lines
Avi Kivity (8):
msix: avoid leaking kvm data on init failure
kvm: dropkvm_contextparameter from msix-related kvm functions Avoid usingkvm_irq_routing_entryin PCIDevice
Avoid use ofkvm_irq_routing_entryinhw/msix.c
kvm: Add stubs for msix support code
kvm: allowkvm.hto be included from target independent files
msix: removeCONFIG_KVMdepedency
Move msix.o build back to Makefile.objs
Something strange happened: recent qemu-kvm seems much slower to me. Any chance kernel irqchip is now disabled?
Signature · 1 line
MST
Quoted 17 lines · Michael S. Tsirkin
Quoted 6 lines · Avi Kivity
Due to a depedency on kvm's msix support,
msix.cwas changed to be a target dependent file. This patch set changes it back.v2: make the
msix.c->kvm.cinterface at a finer granularity, removing the need
for kvm code to know about PCIDevice.Quoted 9 lines
Avi Kivity (8):
msix: avoid leaking kvm data on init failure
kvm: dropkvm_contextparameter from msix-related kvm functions Avoid usingkvm_irq_routing_entryin PCIDevice
Avoid use ofkvm_irq_routing_entryinhw/msix.c
kvm: Add stubs for msix support code
kvm: allowkvm.hto be included from target independent files
msix: removeCONFIG_KVMdepedency
Move msix.o build back to Makefile.objs
Quoted 3 lines
Something strange happened: recent qemu-kvm seems much slower to me. Any chance kernel irqchip is now disabled?
You can use strace of ftrace to find out if the right ioctls or traces are called.
Signature · 1 line
error compiling committee.c: too many arguments to function