mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-24 12:09:58 +00:00
spapr: introduce routines to delete the KVM IRQ device
If a new interrupt mode is chosen by CAS, the machine generates a reset to reconfigure. At this point, the connection with the previous KVM device needs to be closed and a new connection needs to opened with the KVM device operating the chosen interrupt mode. New routines are introduced to destroy the XICS and the XIVE KVM devices. They make use of a new KVM device ioctl which destroys the device and also disconnects the IRQ presenters from the vCPUs. Signed-off-by: Cédric Le Goater <clg@kaod.org> Reviewed-by: David Gibson <david@gibson.dropbear.id.au> Message-Id: <20190513084245.25755-10-clg@kaod.org> Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
parent
90c20e1e2c
commit
56b11587df
@ -58,6 +58,16 @@ static void kvm_cpu_enable(CPUState *cs)
|
||||
QLIST_INSERT_HEAD(&kvm_enabled_cpus, enabled_cpu, node);
|
||||
}
|
||||
|
||||
static void kvm_cpu_disable_all(void)
|
||||
{
|
||||
KVMEnabledCPU *enabled_cpu, *next;
|
||||
|
||||
QLIST_FOREACH_SAFE(enabled_cpu, &kvm_enabled_cpus, node, next) {
|
||||
QLIST_REMOVE(enabled_cpu, node);
|
||||
g_free(enabled_cpu);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* XIVE Thread Interrupt Management context (KVM)
|
||||
*/
|
||||
@ -709,3 +719,49 @@ void kvmppc_xive_connect(SpaprXive *xive, Error **errp)
|
||||
/* Map all regions */
|
||||
spapr_xive_map_mmio(xive);
|
||||
}
|
||||
|
||||
void kvmppc_xive_disconnect(SpaprXive *xive, Error **errp)
|
||||
{
|
||||
XiveSource *xsrc;
|
||||
size_t esb_len;
|
||||
|
||||
/* The KVM XIVE device is not in use */
|
||||
if (!xive || xive->fd == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!kvmppc_has_cap_xive()) {
|
||||
error_setg(errp, "IRQ_XIVE capability must be present for KVM");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Clear the KVM mapping */
|
||||
xsrc = &xive->source;
|
||||
esb_len = (1ull << xsrc->esb_shift) * xsrc->nr_irqs;
|
||||
|
||||
sysbus_mmio_unmap(SYS_BUS_DEVICE(xive), 0);
|
||||
munmap(xsrc->esb_mmap, esb_len);
|
||||
|
||||
sysbus_mmio_unmap(SYS_BUS_DEVICE(xive), 1);
|
||||
|
||||
sysbus_mmio_unmap(SYS_BUS_DEVICE(xive), 2);
|
||||
munmap(xive->tm_mmap, 4ull << TM_SHIFT);
|
||||
|
||||
/*
|
||||
* When the KVM device fd is closed, the KVM device is destroyed
|
||||
* and removed from the list of devices of the VM. The VCPU
|
||||
* presenters are also detached from the device.
|
||||
*/
|
||||
close(xive->fd);
|
||||
xive->fd = -1;
|
||||
|
||||
kvm_kernel_irqchip = false;
|
||||
kvm_msi_via_irqfd_allowed = false;
|
||||
kvm_gsi_direct_mapping = false;
|
||||
|
||||
/* Clear the local list of presenter (hotplug) */
|
||||
kvm_cpu_disable_all();
|
||||
|
||||
/* VM Change state handler is not needed anymore */
|
||||
qemu_del_vm_change_state_handler(xive->change);
|
||||
}
|
||||
|
@ -51,6 +51,16 @@ typedef struct KVMEnabledICP {
|
||||
static QLIST_HEAD(, KVMEnabledICP)
|
||||
kvm_enabled_icps = QLIST_HEAD_INITIALIZER(&kvm_enabled_icps);
|
||||
|
||||
static void kvm_disable_icps(void)
|
||||
{
|
||||
KVMEnabledICP *enabled_icp, *next;
|
||||
|
||||
QLIST_FOREACH_SAFE(enabled_icp, &kvm_enabled_icps, node, next) {
|
||||
QLIST_REMOVE(enabled_icp, node);
|
||||
g_free(enabled_icp);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* ICP-KVM
|
||||
*/
|
||||
@ -360,3 +370,44 @@ fail:
|
||||
kvmppc_define_rtas_kernel_token(0, "ibm,int-off");
|
||||
return -1;
|
||||
}
|
||||
|
||||
void xics_kvm_disconnect(SpaprMachineState *spapr, Error **errp)
|
||||
{
|
||||
/* The KVM XICS device is not in use */
|
||||
if (kernel_xics_fd == -1) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!kvm_enabled() || !kvm_check_extension(kvm_state, KVM_CAP_IRQ_XICS)) {
|
||||
error_setg(errp,
|
||||
"KVM and IRQ_XICS capability must be present for KVM XICS device");
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* Only on P9 using the XICS-on XIVE KVM device:
|
||||
*
|
||||
* When the KVM device fd is closed, the device is destroyed and
|
||||
* removed from the list of devices of the VM. The VCPU presenters
|
||||
* are also detached from the device.
|
||||
*/
|
||||
close(kernel_xics_fd);
|
||||
kernel_xics_fd = -1;
|
||||
|
||||
spapr_rtas_unregister(RTAS_IBM_SET_XIVE);
|
||||
spapr_rtas_unregister(RTAS_IBM_GET_XIVE);
|
||||
spapr_rtas_unregister(RTAS_IBM_INT_OFF);
|
||||
spapr_rtas_unregister(RTAS_IBM_INT_ON);
|
||||
|
||||
kvmppc_define_rtas_kernel_token(0, "ibm,set-xive");
|
||||
kvmppc_define_rtas_kernel_token(0, "ibm,get-xive");
|
||||
kvmppc_define_rtas_kernel_token(0, "ibm,int-on");
|
||||
kvmppc_define_rtas_kernel_token(0, "ibm,int-off");
|
||||
|
||||
kvm_kernel_irqchip = false;
|
||||
kvm_msi_via_irqfd_allowed = false;
|
||||
kvm_gsi_direct_mapping = false;
|
||||
|
||||
/* Clear the presenter from the VCPUs */
|
||||
kvm_disable_icps();
|
||||
}
|
||||
|
@ -71,6 +71,7 @@ int spapr_xive_end_to_target(uint8_t end_blk, uint32_t end_idx,
|
||||
* KVM XIVE device helpers
|
||||
*/
|
||||
void kvmppc_xive_connect(SpaprXive *xive, Error **errp);
|
||||
void kvmppc_xive_disconnect(SpaprXive *xive, Error **errp);
|
||||
void kvmppc_xive_reset(SpaprXive *xive, Error **errp);
|
||||
void kvmppc_xive_set_source_config(SpaprXive *xive, uint32_t lisn, XiveEAS *eas,
|
||||
Error **errp);
|
||||
|
@ -34,6 +34,7 @@
|
||||
void spapr_dt_xics(SpaprMachineState *spapr, uint32_t nr_servers, void *fdt,
|
||||
uint32_t phandle);
|
||||
int xics_kvm_init(SpaprMachineState *spapr, Error **errp);
|
||||
void xics_kvm_disconnect(SpaprMachineState *spapr, Error **errp);
|
||||
void xics_spapr_init(SpaprMachineState *spapr);
|
||||
|
||||
#endif /* XICS_SPAPR_H */
|
||||
|
Loading…
Reference in New Issue
Block a user