Skip to content

Commit 3607715

Browse files
committed
kvm: Introduce KVM irqchip change notifier
Awareness of an in kernel irqchip is usually local to the machine and its top-level interrupt controller. However, in a few cases other things need to know about it. In particular vfio devices need this in order to accelerate interrupt delivery. If interrupt routing is changed, such devices may need to readjust their connection to the KVM irqchip. pci_bus_fire_intx_routing_notifier() exists to do just this. However, for the pseries machine type we have a situation where the routing remains constant but the top-level irq chip itself is changed. This occurs because of PAPR feature negotiation which allows the guest to decide between the older XICS and newer XIVE irq chip models (both of which are paravirtualized). To allow devices like vfio to adjust to this change, introduce a new notifier for the purpose kvm_irqchip_change_notify(). Cc: Alex Williamson <[email protected]> Cc: Alexey Kardashevskiy <[email protected]> Signed-off-by: David Gibson <[email protected]> Tested-by: Alex Williamson <[email protected]> Reviewed-by: Alex Williamson <[email protected]> Reviewed-by: Greg Kurz <[email protected]> Acked-by: Alex Williamson <[email protected]>
1 parent 4545909 commit 3607715

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

accel/kvm/kvm-all.c

+18
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ static const KVMCapabilityInfo kvm_required_capabilites[] = {
149149
KVM_CAP_LAST_INFO
150150
};
151151

152+
static NotifierList kvm_irqchip_change_notifiers =
153+
NOTIFIER_LIST_INITIALIZER(kvm_irqchip_change_notifiers);
154+
152155
#define kvm_slots_lock(kml) qemu_mutex_lock(&(kml)->slots_lock)
153156
#define kvm_slots_unlock(kml) qemu_mutex_unlock(&(kml)->slots_lock)
154157

@@ -1396,6 +1399,21 @@ void kvm_irqchip_release_virq(KVMState *s, int virq)
13961399
trace_kvm_irqchip_release_virq(virq);
13971400
}
13981401

1402+
void kvm_irqchip_add_change_notifier(Notifier *n)
1403+
{
1404+
notifier_list_add(&kvm_irqchip_change_notifiers, n);
1405+
}
1406+
1407+
void kvm_irqchip_remove_change_notifier(Notifier *n)
1408+
{
1409+
notifier_remove(n);
1410+
}
1411+
1412+
void kvm_irqchip_change_notify(void)
1413+
{
1414+
notifier_list_notify(&kvm_irqchip_change_notifiers, NULL);
1415+
}
1416+
13991417
static unsigned int kvm_hash_msi(uint32_t data)
14001418
{
14011419
/* This is optimized for IA32 MSI layout. However, no other arch shall

accel/stubs/kvm-stub.c

+12
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,18 @@ void kvm_irqchip_commit_routes(KVMState *s)
138138
{
139139
}
140140

141+
void kvm_irqchip_add_change_notifier(Notifier *n)
142+
{
143+
}
144+
145+
void kvm_irqchip_remove_change_notifier(Notifier *n)
146+
{
147+
}
148+
149+
void kvm_irqchip_change_notify(void)
150+
{
151+
}
152+
141153
int kvm_irqchip_add_adapter_route(KVMState *s, AdapterInfo *adapter)
142154
{
143155
return -ENOSYS;

include/sysemu/kvm.h

+5
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ typedef struct KVMCapabilityInfo {
201201
struct KVMState;
202202
typedef struct KVMState KVMState;
203203
extern KVMState *kvm_state;
204+
typedef struct Notifier Notifier;
204205

205206
/* external API */
206207

@@ -401,6 +402,10 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg);
401402

402403
void kvm_irqchip_add_irq_route(KVMState *s, int gsi, int irqchip, int pin);
403404

405+
void kvm_irqchip_add_change_notifier(Notifier *n);
406+
void kvm_irqchip_remove_change_notifier(Notifier *n);
407+
void kvm_irqchip_change_notify(void);
408+
404409
void kvm_get_apic_state(DeviceState *d, struct kvm_lapic_state *kapic);
405410

406411
struct kvm_guest_debug;

0 commit comments

Comments
 (0)