spapr: Guest exploitation of the XIVE interrupt controller (POWER9)
v2 cover spapr: Guest exploitation of the XIVE interrupt controller (POWER9)
Hello,
On a POWER9 sPAPR machine, the Client Architecture Support (CAS) negotiation process determines whether the guest operates with an interrupt controller using the XICS legacy model, as found on POWER8, or in XIVE exploitation mode, the newer POWER9 interrupt model. XIVE is a complex interrupt controller introducing a large number of new features, for virtualization in particular.
It is composed of three sub-engines :
- Interrupt Virtualization Source Engine (IVSE). These are in PHBs, in the main controller for the IPIS and in the PSI host bridge. They are configured to feed the IVRE with events.
- Interrupt Virtualization Routing Engine (IVRE). Their job is to match an event source with a Notification Virtualization Target (NVT), a priority and an Event Queue (EQ) to determine if a Virtual Processor can handle the event.
- Interrupt Virtualization Presentation Engine (IVPE). It maintains the interrupt state of each hardware thread and present the notification as an external exception.
Each of the engines uses a set of internal tables to redirect exceptions from event sources to CPU threads. Interrupt sources have a 2-bit state machine, the Event State Buffer (ESB), that allows events to be triggered. If the event is let through, the IVRE looks up in the Interrupt Virtualization Entry (IVE) table for the Event Queue Descriptor configured for the source. Each Event Queue Descriptor defines a notification path to a CPU and an in-memory queue in which will be recorded an event identifier for the OS to pull.
The high level ideas of the current design are :
- introduce a persistent XIVE object under the sPAPR machine for newer machines and let the CAS negotiation process decide whether it should be used or not. Use the 'ov5_cas' attribute for this purpose.
- introduce a persistent XIVE interrupt presenter under the sPAPR core and switch ICP after CAS. Each core has now two ICPs, one active through the 'intc' pointer and another one among its children ready to be used if the guest requires it.
- move the XIVE EQs under the cores to simplify the XIVE model
- allocate the CPU IPIs at the beginning of the IRQ number space to be compatible with XICS (which starts at 4096) and also to simplify the model. This means that the XIVE model covers the whole IRQ number space. There are no offset like in XICS splitting the IRQ number space.
The patchset first introduces new models for XIVE :
- sPAPRXive holding the internal tables and the MMIO regions used by the XIVE controller.
- sPAPRXiveNVT object storing the interrupt state of the CPU and acting as the XIVE interrupt presenter
then, describes the notification process and the interrupt delivery to the CPU.
It finishes with the integration of sPAPRXive object under the sPAPR machine, the introducion of the new XIVE hcalls, the device tree layout, and the necessary adjustments to support the CAS negotiation.
Migration is addressed, CPU hotplug, and support for older machines and QEMU versions also. KVM support is not addressed yet and the guest needs to be run with kernel_irqchip=off on a POWER9 system.
Code is here:
https://github.com/legoater/qemu/commits/xive
Thanks,
C.
Changes since v1 :
- used g_new0 instead of g_malloc0
- removed VMSTATE_STRUCT_VARRAY_UINT32_ALLOC
- introduced a device reset handler. the object needs to be parented to sysbus when created.
- renamed spapr_xive_irq_set() to spapr_xive_irq_enable()
- renamed spapr_xive_irq_unset() to spapr_xive_irq_disable()
- moved the PPC_BIT macros under target/ppc/cpu.h
- shrinked file copyright header
- reworked the event notification logic of the qemu_irq handlers.
- introduced XIVE_ESB_STORE_EOI support
- removed 'esb_shift' field
- removed a useless check on the validity of the IVE in the memory region handlers.
- removed the overall ESB memory region. We now have only one region for the provisioned sources.
- improved 'info pic' output
- improved LSI support
- renamed 'sPAPRXiveICP' to 'sPAPRXiveNVT'
- renamed 'tima' field to 'regs'
- renamed 'tima_os' fiels to 'ring_os'
- removed 'tm_shift' field
- introduced a memory region to model the User TIMA and another one for the OS TIMA. One page size for each.
- removed useless checks in the memory region handlers
- removed support for 970 ...
- removed spapr_xive_eq_for_server() which did the EQ indexing.
- changed spapr_xive_get_eq() to use a server and a priority parameter
- introduced a couple of macro for the EQ indexing.
- replaced dma_memory_write() by stl_be_dma()
- set initial TM_PIPR to 0xFF in sPAPRXiveNVT
- conditioned the creation of the sPAPRXive object to the xive_exploitation bool which false on older pseries machine.
- parented the sPAPRXive object to sysbus.
- simplified priority_is_valid() routine (to its minimum)
- used PPC_BIT() macros to define the hcall flags
- removed useless casts
- defined the default characteristic of the single XIVE interrupt source to be : *XIVE_SRC_TRIGGER | XIVE_SRC_STORE_EOI*
- removed EQ_W0_UCOND_NOTIFY when the EQ is reseted
- fixed XIVE_EQ_DEBUG support. Offset for the generation bit was wrong
- added a unit id to the nodename
- added properties for the LSIs
- simplified the array for the "ibm,plat-res-int-priorities" property
- renamed spapr_xive_populate() to spapr_dt_xive()
- moved the mapping of the XIVE memory region and the setting of the ICP under the machine reset handler.
- introduced a spapr_xive_qirq() helper
- introduced a spapr_xive_nvt_create() helper
- handled more errors in spapr_post_load() to return EINVAL
Cédric Le Goater (19):
dma-helpers: add a return value to store helpers
spapr: introduce a skeleton for the XIVE interrupt controller
spapr: introduce the XIVE interrupt sources
spapr: add support for the LSI interrupt sources
spapr: introduce a XIVE interrupt presenter model
spapr: introduce the XIVE Event Queues
spapr: push the XIVE EQ data in OS event queue
spapr: notify the CPU when the XIVE interrupt priority is more
privileged
spapr: add support for the SET_OS_PENDING command (XIVE)
spapr: introduce a 'xive_exploitation' boolean to enable XIVE
spapr: add a sPAPRXive object to the machine
spapr: add hcalls support for the XIVE exploitation interrupt mode
spapr: add device tree support for the XIVE interrupt mode
spapr: introduce a helper to map the XIVE memory regions
spapr: add XIVE support to spapr_qirq()
spapr: introduce a spapr_icp_create() helper
spapr: toggle the ICP depending on the selected interrupt mode
spapr: add support to dump XIVE information
spapr: advertise XIVE exploitation mode in CAS
default-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/spapr_xive.c | 1013 +++++++++++++++++++++++++++++++++++++ hw/intc/spapr_xive_hcall.c | 923 +++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 196 +++++++ hw/ppc/spapr.c | 188 ++++++- hw/ppc/spapr_cpu_core.c | 37 +- hw/ppc/spapr_hcall.c | 6 + include/hw/ppc/spapr.h | 20 +- include/hw/ppc/spapr_cpu_core.h | 1 + include/hw/ppc/spapr_xive.h | 72 +++ include/sysemu/dma.h | 4 +- 12 files changed, 2449 insertions(+), 13 deletions(-) create mode 100644 hw/intc/spapr_xive.c create mode 100644 hw/intc/spapr_xive_hcall.c create mode 100644 hw/intc/xive-internal.h create mode 100644 include/hw/ppc/spapr_xive.h
Signature · 1 line
2.13.6
PATCH v2 1/19 dma-helpers: add a return value to store helpers
--- include/sysemu/dma.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
include/sysemu/dma.h +2 -2
@@ -153,12 +153,12 @@ static inline void dma_memory_unmap(AddressSpace *as,dma_memory_read (as, addr, &val, (_bits) /8 ); \ return _end##_bits##_to_cpu(val); \ } \ - static inline void st##_sname##_##_end##_dma(AddressSpace *as, \ + static inline int st##_sname##_##_end##_dma(AddressSpace *as, \dma_addr_t addr, \ uint##_bits##_t val) \ { \ val = cpu_to_##_end##_bits(val); \ -dma_memory_write (as, addr, &val, (_bits) /8 ); \ +return dma_memory_write (as, addr, &val, (_bits) /8 ); \ }static inline uint8_t ldub_dma (AddressSpace *as,dma_addr_t addr)
Signature · 1 line
2.13.6
PATCH v2 2/19 spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Cédric Le GoaterWith the POWER9 processor comes a new interrupt controller called XIVE. It is composed of three sub-engines :
- Interrupt Virtualization Source Engine (IVSE). These are in PHBs, in the main controller for the IPIS and in the PSI host bridge. They are configured to feed the IVRE with events.
- Interrupt Virtualization Routing Engine (IVRE). Their job is to match an event source with a Notification Virtualization Target (NVT), a priority and an Event Queue (EQ) to determine if a Virtual Processor can handle the event.
- Interrupt Virtualization Presentation Engine (IVPE). It maintains the interrupt state of each hardware thread and present the notification as an external exception.
Each of the engines uses a set of internal tables to redirect exceptions from event sources to CPU threads. The first table we introduce is the Interrupt Virtualization Entry (IVE) table, part of the virtualization engine in charge of routing events. It associates event sources (IRQ numbers) to event queues which will forward, or not, the event notification to the presentation controller.
The XIVE model is designed to make use of the full range of the IRQ number space and does not use an offset like the XICS mode does. Hence, the IVE table is directly indexed by the IRQ number.
---
Changes since v1 :
- used g_new0 instead of g_malloc0
- removed VMSTATE_STRUCT_VARRAY_UINT32_ALLOC
- introduced a device reset handler. the object needs to be parented to sysbus when created.
- renamed spapr_xive_irq_set to spapr_xive_irq_enable
- renamed spapr_xive_irq_unset to spapr_xive_irq_disable
- moved the PPC_BIT macros under target/ppc/cpu.h
- shrinked file copyright header
default-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/spapr_xive.c | 156 ++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 41 ++++++++++ include/hw/ppc/spapr_xive.h | 35 +++++++++ 5 files changed, 234 insertions(+) create mode 100644 hw/intc/spapr_xive.c create mode 100644 hw/intc/xive-internal.h create mode 100644 include/hw/ppc/spapr_xive.h
default-configs/ppc64-softmmu.mak +1 -0
@@ -56,6 +56,7 @@ CONFIG_SM501=y CONFIG_XICS=$(CONFIG_PSERIES) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM)) +CONFIG_XIVE_SPAPR=$(CONFIG_PSERIES) # For PReP CONFIG_SERIAL_ISA=y CONFIG_MC146818RTC=y
hw/intc/Makefile.objs +1 -0
@@ -35,6 +35,7 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o +obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o obj-$(CONFIG_POWERNV) += xics_pnv.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.o
hw/intc/spapr_xive.c new file +156 -0
156 lines not on this page · raw message
hw/intc/xive-internal.h new file +41 -0
41 lines not on this page · raw message
include/hw/ppc/spapr_xive.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* QEMU PowerPC sPAPR XIVE interrupt controller model +* +* Copyright (c) 2017, IBM Corporation. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +*/ + +#ifndef PPC_SPAPR_XIVE_H +#define PPC_SPAPR_XIVE_H + +#include <hw/sysbus.h> + +typedef struct sPAPRXive sPAPRXive ; +typedef struct XiveIVE XiveIVE ; + +#define TYPE_SPAPR_XIVE "spapr-xive" +#define SPAPR_XIVE (obj) OBJECT_CHECK(sPAPRXive, (obj), TYPE_SPAPR_XIVE) + +struct sPAPRXive { +SysBusDevice parent; + +/* Properties */ +uint32_t nr_irqs; + +/* XIVE internal tables */ +XiveIVE *ivt; +}; + +bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn); +bool spapr_xive_irq_disable (sPAPRXive *xive,uint32_t lisn); +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon); + +#endif /* PPC_SPAPR_XIVE_H */
Signature · 1 line
2.13.6
PATCH v2 3/19 spapr: introduce the XIVE interrupt sources
In reply to Cédric Le GoaterEach XIVE interrupt source is associated with a two bit state machine called an Event State Buffer (ESB) : the first bit "P" means that an interrupt is "pending" and waiting for an EOI and the bit "Q" (queued) means a new interrupt was triggered while another was still pending.
When an event is triggered, the associated interrupt state bits are fetched and modified and forwarded to the virtualization engine of the controller doing the routing. These can also be controlled by MMIO, to trigger events or turn off the sources for instance. See code for more details on the states and transitions.
The MMIO space for the ESBs is 512GB large on the bare-metal system (PowerNV) and the BAR depends on the chip id. In our model for the sPAPR machine, we choose to only map the sub-region for the provisioned IRQ numbers and to use the mapping address of chip 0 of a real system.
In the real world, each source may have different characteristics depending on the revision of a controller or the CPU. Early systems had two different MMIO pages for trigger and for EOI. We choose to use the same characteristics for all sources to simplify the model. The minimum CPU level for XIVE exploitation mode will be DD2.X as it has full support.
The OS will obtain the address of the MMIO page of the ESB entry associated with a source and its characteristic using the H_INT_GET_SOURCE_INFO hcall. This will be addressed in the patch introducing the hcalls.
The spapr_xive_irq() routine in charge of triggering the CPU interrupt line will be filled later on.
---
Changes since v1:
- merged in the same patch the qemu_irq handlers
- reworked the event notification logic of the qemu_irq handlers.
- introduced XIVE_ESB_STORE_EOI support
- removed 'esb_shift' field
- removed a useless check on the validity of the IVE in the memory region handlers.
- fixed spapr_xive_pq_trigger() to return true when XIVE_ESB_QUEUED is set
- removed the overall ESB memory region. We now have only one region for the provisioned sources.
- improved 'info pic' output
hw/intc/spapr_xive.c | 254 +++++++++++++++++++++++++++++++++++++++++++- hw/intc/xive-internal.h | 10 ++ include/hw/ppc/spapr_xive.h | 9 ++ 3 files changed, 271 insertions(+), 2 deletions(-)
hw/intc/spapr_xive.c +252 -2
@@ -18,23 +18,252 @@#include "xive-internal.h" +static void spapr_xive_irq (sPAPRXive *xive,int lisn) +{ + +} +/* -* Main XIVE object +* XIVE Interrupt Source +*/ + +/* +* "magic" Event State Buffer (ESB) MMIO offsets. +* +* Each interrupt source has a 2-bit state machine called ESB +* which can be controlled by MMIO. It's made of 2 bits, P and +* Q. P indicates that an interrupt is pending (has been sent +* to a queue and is waiting for an EOI). Q indicates that the +* interrupt has been triggered while pending. +* +* This acts as a coalescing mechanism in order to guarantee +* that a given interrupt only occurs at most once in a queue. +* +* When doing an EOI, the Q bit will indicate if the interrupt +* needs to be re-triggered. +* +* The following offsets into the ESB MMIO allow to read or +* manipulate the PQ bits. They must be used with an 8-bytes +* load instruction. They all return the previous state of the +* interrupt (atomically). +* +* Additionally, some ESB pages support doing an EOI via a +* store at 0 and some ESBs support doing a trigger via a +* separate trigger page. +*/ +#define XIVE_ESB_STORE_EOI 0x400/* Store */ +#define XIVE_ESB_LOAD_EOI 0x000/* Load */ +#define XIVE_ESB_GET 0x800/* Load */ +#define XIVE_ESB_SET_PQ_00 0xc00/* Load */ +#define XIVE_ESB_SET_PQ_01 0xd00/* Load */ +#define XIVE_ESB_SET_PQ_10 0xe00/* Load */ +#define XIVE_ESB_SET_PQ_11 0xf00/* Load */ + +#define XIVE_ESB_VAL_P 0x2 +#define XIVE_ESB_VAL_Q 0x1 + +#define XIVE_ESB_RESET 0x0 +#define XIVE_ESB_PENDING XIVE_ESB_VAL_P +#define XIVE_ESB_QUEUED (XIVE_ESB_VAL_P | XIVE_ESB_VAL_Q) +#define XIVE_ESB_OFF XIVE_ESB_VAL_Q + +static uint8_t spapr_xive_pq_get (sPAPRXive *xive,uint32_t lisn) +{ +uint32_t byte = lisn /4 ; +uint32_t bit = (lisn %4 ) *2 ; + +assert (byte < xive->sbe_size); + +return (xive->sbe[byte] >> bit) &0x3 ; +} + +static uint8_t spapr_xive_pq_set (sPAPRXive *xive,uint32_t lisn,uint8_t pq) +{ +uint32_t byte = lisn /4 ; +uint32_t bit = (lisn %4 ) *2 ; +uint8_t old, new; + +assert (byte < xive->sbe_size); + + old = xive->sbe[byte]; + + new = xive->sbe[byte] & ~(0x3 << bit); + new |= (pq &0x3 ) << bit; + + xive->sbe[byte] = new; + +return (old >> bit) &0x3 ; +} + +static bool spapr_xive_pq_eoi (sPAPRXive *xive,uint32_t lisn) +{ +uint8_t old_pq =spapr_xive_pq_get (xive, lisn); + +switch (old_pq) { +case XIVE_ESB_RESET : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_RESET ); +return false; +case XIVE_ESB_PENDING : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_RESET ); +return false; +case XIVE_ESB_QUEUED : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_PENDING ); +return true; +case XIVE_ESB_OFF : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_OFF ); +return false; +default : +g_assert_not_reached (); + } +} + +/* +* Returns whether the event notification should be forwarded to the +* IVE for routing. */ +static bool spapr_xive_pq_trigger (sPAPRXive *xive,uint32_t lisn) +{ +uint8_t old_pq =spapr_xive_pq_get (xive, lisn); +switch (old_pq) { +case XIVE_ESB_RESET : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_PENDING ); +return true; +case XIVE_ESB_PENDING : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_QUEUED ); +return false; +case XIVE_ESB_QUEUED : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_QUEUED ); +return false; +case XIVE_ESB_OFF : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_OFF ); +return false; +default : +g_assert_not_reached (); + } +} + +/* +* XIVE Interrupt Source MMIOs +*/ + +/* +* Some HW use a separate page for trigger. We only support the case +* in which the trigger can be done in the same page as the EOI. +*/ +static uint64_t spapr_xive_esb_read (void *opaque,hwaddr addr,unsigned size) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); +uint32_t offset = addr &0xF00 ; +uint32_t lisn = addr >>ESB_SHIFT ; +uint64_t ret =-1 ; + +switch (offset) { +case XIVE_ESB_LOAD_EOI : +/* +* EOI on load is not used anymore as we now advertise +* XIVE_ESB_STORE_EOI support for the interrupt sources +*/ + ret =spapr_xive_pq_eoi (xive, lisn); +break ; + +case XIVE_ESB_GET : + ret =spapr_xive_pq_get (xive, lisn); +break ; + +case XIVE_ESB_SET_PQ_00 : +case XIVE_ESB_SET_PQ_01 : +case XIVE_ESB_SET_PQ_10 : +case XIVE_ESB_SET_PQ_11 : + ret =spapr_xive_pq_set (xive, lisn, (offset >>8 ) &0x3 ); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid ESB addr %d\n" , offset); + } + +return ret; +} + +static void spapr_xive_esb_write (void *opaque,hwaddr addr, +uint64_t value,unsigned size) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); +uint32_t offset = addr &0xF00 ; +uint32_t lisn = addr >>ESB_SHIFT ; +bool notify = false; + +switch (offset) { +case 0 : + notify =spapr_xive_pq_trigger (xive, lisn); +break ; +case XIVE_ESB_STORE_EOI : +/* If the Q bit is set, we should forward a new source event +* notification +*/ + notify =spapr_xive_pq_eoi (xive, lisn); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid ESB write addr %d\n" , + offset); +return ; + } + +/* Forward the source event notification for routing */ +if (notify) { +spapr_xive_irq (xive, lisn); + } +} + +static const MemoryRegionOps spapr_xive_esb_ops = { + .read = spapr_xive_esb_read, + .write = spapr_xive_esb_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =8 , + .max_access_size =8 , + }, + .impl = { + .min_access_size =8 , + .max_access_size =8 , + }, +}; + +static void spapr_xive_source_set_irq (void *opaque,int lisn,int val) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); +bool notify = false; + +if (val) { + notify =spapr_xive_pq_trigger (xive, lisn); + } + +/* Forward the source event notification for routing */ +if (notify) { +spapr_xive_irq (xive, lisn); + } +} + +/* +* Main XIVE object +*/ void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) {int i;for (i =0 ; i < xive->nr_irqs; i++) {XiveIVE *ive = &xive->ivt[i]; +uint8_t pq;if (!(ive->w &IVE_VALID )) {continue ; } -monitor_printf (mon," %4x %s %08x %08x\n" , i, + pq =spapr_xive_pq_get (xive, i); + +monitor_printf (mon," %4x %s %c%c %08x %08x\n" , i, ive->w &IVE_MASKED ?"M" :" " , + pq &XIVE_ESB_VAL_P ?'P' :'-' , + pq &XIVE_ESB_VAL_Q ?'Q' :'-' , (int )GETFIELD (IVE_EQ_INDEX , ive->w), (int )GETFIELD (IVE_EQ_DATA , ive->w)); }
@@ -52,6 +281,9 @@ static void spapr_xive_reset(DeviceState *dev) ive->w |=IVE_MASKED ; } } + +/* SBEs are initialized to 0b01 which corresponds to "ints off" */ +memset (xive->sbe,0x55 , xive->sbe_size); }static void spapr_xive_realize (DeviceState *dev,Error **errp)
@@ -65,6 +297,23 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)/* Allocate the IVT (Interrupt Virtualization Table) */ xive->ivt =g_new0 (XiveIVE, xive->nr_irqs); + +/* QEMU IRQs */ + xive->qirqs =qemu_allocate_irqs (spapr_xive_source_set_irq, xive, + xive->nr_irqs); + +/* Allocate SBEs (State Bit Entry). 2 bits, so 4 entries per byte */ + xive->sbe_size =DIV_ROUND_UP (xive->nr_irqs,4 ); + xive->sbe =g_malloc0 (xive->sbe_size); + +/* VC BAR. Use address of chip 0 to install the ESB memory region +* for *all* interrupt sources */ + xive->esb_base = (P9_MMIO_BASE |VC_BAR_DEFAULT ); + +memory_region_init_io (&xive->esb_iomem,OBJECT (xive), + &spapr_xive_esb_ops, xive,"xive.esb" , + (1ull <<ESB_SHIFT ) * xive->nr_irqs); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &xive->esb_iomem); }static const VMStateDescription vmstate_spapr_xive_ive = {
@@ -92,6 +341,7 @@ static const VMStateDescription vmstate_spapr_xive = { VMSTATE_UINT32_EQUAL(nr_irqs, sPAPRXive, NULL), VMSTATE_STRUCT_VARRAY_UINT32(ivt, sPAPRXive, nr_irqs, 1, vmstate_spapr_xive_ive, XiveIVE), + VMSTATE_VBUFFER_UINT32(sbe, sPAPRXive, 1, NULL, sbe_size),VMSTATE_END_OF_LIST () }, };
hw/intc/xive-internal.h +10 -0
@@ -16,6 +16,16 @@#define SETFIELD (m, v, val) \ (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m))) +/* +* XIVE MMIO regions +*/ +#define P9_MMIO_BASE 0x006000000000000ull + +/* VC BAR contains set translations for the ESBs and the EQs. */ +#define VC_BAR_DEFAULT 0x10000000000ull +#define VC_BAR_SIZE 0x08000000000ull +#define ESB_SHIFT 16/* One 64k page. OPAL has two */ +/* IVE/EAS * * One per interrupt source. Targets that interrupt to a given EQ
include/hw/ppc/spapr_xive.h +9 -0
@@ -24,8 +24,17 @@ struct sPAPRXive {/* Properties */ uint32_t nr_irqs; +/* IRQ */ +qemu_irq *qirqs; +/* XIVE internal tables */ XiveIVE *ivt; +uint8_t *sbe; +uint32_t sbe_size; + +/* ESB memory region */ +hwaddr esb_base; +MemoryRegion esb_iomem; };bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn);
Signature · 1 line
2.13.6
PATCH v2 4/19 spapr: add support for the LSI interrupt sources
In reply to Cédric Le GoaterThe 'sent' status of the LSI interrupt source is modeled with the 'P' bit of the ESB and the assertion status of the source is maintained in an array under the main sPAPRXive object. The type of the source is stored in the same array for practical reasons.
The OS will use the H_INT_GET_SOURCE_INFO hcall to determine the type of an interrupt source.
--- hw/intc/spapr_xive.c | 54 +++++++++++++++++++++++++++++++++++++++++---- include/hw/ppc/spapr_xive.h | 10 ++++++++- 2 files changed, 59 insertions(+), 5 deletions(-)
hw/intc/spapr_xive.c +50 -4
@@ -144,6 +144,21 @@ static bool spapr_xive_pq_trigger(sPAPRXive *xive, uint32_t lisn) }/* +* LSI interrupt sources use the P bit and a custom assertion flag +*/ +static bool spapr_xive_lsi_trigger (sPAPRXive *xive,uint32_t lisn) +{ +uint8_t old_pq =spapr_xive_pq_get (xive, lisn); + +if (old_pq ==XIVE_ESB_RESET && + xive->status[lisn] &XIVE_STATUS_ASSERTED ) { +spapr_xive_pq_set (xive, lisn,XIVE_ESB_PENDING ); +return true; + } +return false; +} + +/* * XIVE Interrupt Source MMIOs */
@@ -165,6 +180,14 @@ static uint64_t spapr_xive_esb_read(void *opaque, hwaddr addr, unsigned size)* XIVE_ESB_STORE_EOI support for the interrupt sources */ ret =spapr_xive_pq_eoi (xive, lisn); + +/* If the LSI source is still asserted, forward a new source +* event notification */ +if (spapr_xive_irq_is_lsi (xive, lisn)) { +if (spapr_xive_lsi_trigger (xive, lisn)) { +spapr_xive_irq (xive, lisn); + } + }break ;case XIVE_ESB_GET :
@@ -201,6 +224,14 @@ static void spapr_xive_esb_write(void *opaque, hwaddr addr,* notification */ notify =spapr_xive_pq_eoi (xive, lisn); + +/* LSI sources do not set the Q bit but they can still be +* asserted, in which case we should forward a new source +* event notification +*/ +if (spapr_xive_irq_is_lsi (xive, lisn)) { + notify =spapr_xive_lsi_trigger (xive, lisn); + }break ;default : qemu_log_mask(LOG_GUEST_ERROR, "XIVE: invalid ESB write addr %d\n",
@@ -233,8 +264,17 @@ static void spapr_xive_source_set_irq(void *opaque, int lisn, int val)sPAPRXive *xive =SPAPR_XIVE (opaque);bool notify = false; -if (val) { - notify =spapr_xive_pq_trigger (xive, lisn); +if (spapr_xive_irq_is_lsi (xive, lisn)) { +if (val) { + xive->status[lisn] |=XIVE_STATUS_ASSERTED ; + }else { + xive->status[lisn] &= ~XIVE_STATUS_ASSERTED ; + } + notify =spapr_xive_lsi_trigger (xive, lisn); + }else { +if (val) { + notify =spapr_xive_pq_trigger (xive, lisn); + } }/* Forward the source event notification for routing */
@@ -260,7 +300,8 @@ void spapr_xive_pic_print_info(sPAPRXive *xive, Monitor *mon) pq =spapr_xive_pq_get (xive, i); - monitor_printf(mon, " %4x %s %c%c %08x %08x\n", i, + monitor_printf(mon, " %4x %s %s %c%c %08x %08x\n", i, + spapr_xive_irq_is_lsi(xive, i) ? "LSI" : "MSI", ive->w & IVE_MASKED ? "M" : " ", pq & XIVE_ESB_VAL_P ? 'P' : '-', pq & XIVE_ESB_VAL_Q ? 'Q' : '-',
@@ -274,6 +315,8 @@ static void spapr_xive_reset(DeviceState *dev)sPAPRXive *xive =SPAPR_XIVE (dev);int i; +/* Do not clear IRQ's status */ +/* Mask all valid IVEs in the IRQ number space. */ for (i =0 ; i < xive->nr_irqs; i++) {XiveIVE *ive = &xive->ivt[i];
@@ -301,6 +344,7 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)/* QEMU IRQs */ xive->qirqs =qemu_allocate_irqs (spapr_xive_source_set_irq, xive, xive->nr_irqs); + xive->status =g_malloc0 (xive->nr_irqs);/* Allocate SBEs (State Bit Entry). 2 bits, so 4 entries per byte */ xive->sbe_size =DIV_ROUND_UP (xive->nr_irqs,4 );
@@ -381,7 +425,7 @@ XiveIVE *spapr_xive_get_ive(sPAPRXive *xive, uint32_t lisn)return lisn < xive->nr_irqs ? &xive->ivt[lisn] :NULL ; } -bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn) +bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn,bool lsi) {XiveIVE *ive =spapr_xive_get_ive (xive, lisn);
@@ -390,6 +434,7 @@ bool spapr_xive_irq_enable(sPAPRXive *xive, uint32_t lisn) } ive->w |=IVE_VALID ; + xive->status[lisn] |= lsi ?XIVE_STATUS_LSI :0 ;return true; }
@@ -402,5 +447,6 @@ bool spapr_xive_irq_disable(sPAPRXive *xive, uint32_t lisn) } ive->w &= ~IVE_VALID ; + xive->status[lisn] =0 ;return true; }
include/hw/ppc/spapr_xive.h +9 -1
@@ -23,6 +23,9 @@ struct sPAPRXive {/* Properties */ uint32_t nr_irqs; +#define XIVE_STATUS_LSI 0x1 +#define XIVE_STATUS_ASSERTED 0x2 +uint8_t *status;/* IRQ */ qemu_irq *qirqs;
@@ -37,7 +40,12 @@ struct sPAPRXive {MemoryRegion esb_iomem; }; -bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn); +static inline bool spapr_xive_irq_is_lsi (sPAPRXive *xive,int lisn) +{ +return xive->status[lisn] &XIVE_STATUS_LSI ; +} + +bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn,bool lsi);bool spapr_xive_irq_disable (sPAPRXive *xive,uint32_t lisn);void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon);
Signature · 1 line
2.13.6
PATCH v2 5/19 spapr: introduce a XIVE interrupt presenter model
In reply to Cédric Le GoaterOnce an event has been routed by the IVRE, it reaches the XIVE virtualization presentation engine which, simply speaking, raises one bit in the Interrupt Pending Buffer (IBP) register corresponding to the priority of the pending interrupt. This indicates there is an event pending in one of the 8 priority queues and the interrupt can then be delivered to the Virtual Processor.
The XIVE presenter engine uses a set of registers to handle priority management and interrupt acknowledgment among other things. The most important being :
- Interrupt Priority Register (PIPR)
- Interrupt Pending Buffer (IPB)
- Current Processor Priority (CPPR)
- Notification Source Register (NSR)
There is one set of registers per level of privilege, four in all :
HW, HV pool, OS and User. These are called rings. All registers are accessible through a specific MMIO region called the Thread Interrupt Management Areas (TIMA) but, depending on the privilege level of the CPU, the view of the TIMA is filtered. The sPAPR machine runs at the OS privilege and therefore can only accesses the OS and the User rings. The others are for hypervisor levels.
The CPU interrupt state is modeled with a sPAPRXiveNVT object which stores the values of the different registers. The different TIMA views are mapped at the same address for each CPU and 'current_cpu' is used to retrieve the sPAPRXiveNVT holding the ring registers.
---
Changes since v1:
- renamed 'sPAPRXiveICP' to 'sPAPRXiveNVT'
- renamed 'tima' to 'regs'
- renamed 'tima_os' to 'ring_os'
- introduced TM_RING_SIZE
- removed 'tm_shift' field
- introduced a memory region to model the User TIMA and another one for the OS TIMA. One page size for each.
- removed useless checks in the memory region handlers
- removed support for 970 ...
hw/intc/spapr_xive.c | 281 ++++++++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 92 +++++++++++++++ include/hw/ppc/spapr_xive.h | 11 ++ 3 files changed, 384 insertions(+)
hw/intc/spapr_xive.c +281 -0
@@ -15,9 +15,177 @@#include "sysemu/dma.h" #include "monitor/monitor.h" #include "hw/ppc/spapr_xive.h" +#include "hw/ppc/xics.h" #include "xive-internal.h" +struct sPAPRXiveNVT { +DeviceState parent_obj; + +CPUState *cs; +qemu_irq output; + +/* Registers for all rings but sPAPR can only access the OS ring */ +uint8_t regs[TM_RING_COUNT *TM_RING_SIZE ]; + +/* Shortcut to the OS ring */ +uint8_t *ring_os; +}; + +static uint64_t spapr_xive_nvt_accept (sPAPRXiveNVT *nvt) +{ +return 0 ; +} + +static void spapr_xive_nvt_set_cppr (sPAPRXiveNVT *nvt,uint8_t cppr) +{ +if (cppr >XIVE_PRIORITY_MAX ) { + cppr =0xff ; + } + + nvt->ring_os[TM_CPPR ] = cppr; +} + +/* +* Thread Interrupt Management Area MMIO +*/ +static uint64_t spapr_xive_tm_read_special (sPAPRXiveNVT *nvt,hwaddr offset, +unsigned size) +{ +uint64_t ret =-1 ; + +if (offset ==TM_SPC_ACK_OS_REG && size ==2 ) { + ret =spapr_xive_nvt_accept (nvt); + }else { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid TIMA read @%" + HWADDR_PRIx" size %d\n" , offset, size); + } + +return ret; +} + +#define TM_RING (offset) ((offset) & 0xf0) + +static uint64_t spapr_xive_tm_os_read (void *opaque,hwaddr offset, +unsigned size) +{ +PowerPCCPU *cpu =POWERPC_CPU (current_cpu); +sPAPRXiveNVT *nvt =SPAPR_XIVE_NVT (cpu->intc); +uint64_t ret =-1 ; +int i; + +if (offset >=TM_SPC_ACK_EBB ) { +return spapr_xive_tm_read_special (nvt, offset, size); + } + +if (TM_RING (offset) !=TM_QW1_OS ) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid access to non-OS ring @%" + HWADDR_PRIx"\n" , offset); +return ret; + } + + ret =0 ; +for (i =0 ; i < size; i++) { + ret |= nvt->regs[offset + i] << (8 * i); + } + +return ret; +} + +static bool spapr_xive_tm_is_readonly (uint8_t offset) +{ +return offset !=TM_QW1_OS +TM_CPPR ; +} + +static void spapr_xive_tm_write_special (sPAPRXiveNVT *nvt,hwaddr offset, +uint64_t value,unsigned size) +{ +/* TODO: support TM_SPC_SET_OS_PENDING */ + +/* TODO: support TM_SPC_ACK_OS_EL */ +} + +static void spapr_xive_tm_os_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +PowerPCCPU *cpu =POWERPC_CPU (current_cpu); +sPAPRXiveNVT *nvt =SPAPR_XIVE_NVT (cpu->intc); +int i; + +if (offset >=TM_SPC_ACK_EBB ) { +spapr_xive_tm_write_special (nvt, offset, value, size); +return ; + } + +if (TM_RING (offset) !=TM_QW1_OS ) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid access to non-OS ring @%" + HWADDR_PRIx"\n" , offset); +return ; + } + +switch (size) { +case 1 : +if (offset ==TM_QW1_OS +TM_CPPR ) { +spapr_xive_nvt_set_cppr (nvt, value &0xff ); + } +break ; +case 4 : +case 8 : +for (i =0 ; i < size; i++) { +if (!spapr_xive_tm_is_readonly (offset + i)) { + nvt->regs[offset + i] = (value >> (8 * i)) &0xff ; + } + } +break ; +default : +g_assert_not_reached (); + } +} + +static const MemoryRegionOps spapr_xive_tm_os_ops = { + .read = spapr_xive_tm_os_read, + .write = spapr_xive_tm_os_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =1 , + .max_access_size =8 , + }, + .impl = { + .min_access_size =1 , + .max_access_size =8 , + }, +}; + +static uint64_t spapr_xive_tm_user_read (void *opaque,hwaddr offset, +unsigned size) +{ +qemu_log_mask (LOG_UNIMP ,"XIVE: invalid access to User TIMA @%" + HWADDR_PRIx"\n" , offset); +return -1 ; +} + +static void spapr_xive_tm_user_write (void *opaque,hwaddr offset, +uint64_t value,unsigned size) +{ +qemu_log_mask (LOG_UNIMP ,"XIVE: invalid access to User TIMA @%" + HWADDR_PRIx"\n" , offset); +} + + +static const MemoryRegionOps spapr_xive_tm_user_ops = { + .read = spapr_xive_tm_user_read, + .write = spapr_xive_tm_user_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =1 , + .max_access_size =8 , + }, + .impl = { + .min_access_size =1 , + .max_access_size =8 , + }, +}; +static void spapr_xive_irq (sPAPRXive *xive,int lisn) {
@@ -358,6 +526,22 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp) &spapr_xive_esb_ops, xive,"xive.esb" , (1ull << ESB_SHIFT) * xive->nr_irqs);sysbus_init_mmio (SYS_BUS_DEVICE (dev), &xive->esb_iomem); + +/* The Thread Interrupt Management Area has the same address for +* each chip. On sPAPR, we only need to expose the User and OS +* level views of the TIMA. +*/ + xive->tm_base = (P9_MMIO_BASE |TM_BAR_DEFAULT ); + +memory_region_init_io (&xive->tm_iomem_user,OBJECT (xive), + &spapr_xive_tm_user_ops, xive,"xive.tima.user" , +1ull <<TM_SHIFT ); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &xive->tm_iomem_user); + +memory_region_init_io (&xive->tm_iomem_os,OBJECT (xive), + &spapr_xive_tm_os_ops, xive,"xive.tima.os" , +1ull <<TM_SHIFT ); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &xive->tm_iomem_os); }static const VMStateDescription vmstate_spapr_xive_ive = {
@@ -413,9 +597,106 @@ static const TypeInfo spapr_xive_info = { .class_init = spapr_xive_class_init, }; +void spapr_xive_nvt_pic_print_info (sPAPRXiveNVT *nvt,Monitor *mon) +{ +int cpu_index = nvt->cs ? nvt->cs->cpu_index :-1 ; + +monitor_printf (mon,"CPU %d CPPR=%02x IPB=%02x PIPR=%02x NSR=%02x\n" , + cpu_index, nvt->ring_os[TM_CPPR ], nvt->ring_os[TM_IPB ], + nvt->ring_os[TM_PIPR ], nvt->ring_os[TM_NSR ]); +} + +static void spapr_xive_nvt_reset (void *dev) +{ +sPAPRXiveNVT *nvt =SPAPR_XIVE_NVT (dev); + +memset (nvt->regs,0 ,sizeof (nvt->regs)); +} + +static void spapr_xive_nvt_realize (DeviceState *dev,Error **errp) +{ +sPAPRXiveNVT *nvt =SPAPR_XIVE_NVT (dev); +PowerPCCPU *cpu; +CPUPPCState *env; +Object *obj; +Error *err =NULL ; + + obj =object_property_get_link (OBJECT (dev),ICP_PROP_CPU , &err); +if (!obj) { +error_propagate (errp, err); +error_prepend (errp,"required link '" ICP_PROP_CPU "' not found: " ); +return ; + } + + cpu =POWERPC_CPU (obj); + nvt->cs =CPU (obj); + + env = &cpu->env; +switch (PPC_INPUT (env)) { +case PPC_FLAGS_INPUT_POWER7 : + nvt->output = env->irq_inputs[POWER7_INPUT_INT ]; +break ; + +default : +error_setg (errp,"XIVE interrupt controller does not support " +"this CPU bus model" ); +return ; + } + +qemu_register_reset (spapr_xive_nvt_reset, dev); +} + +static void spapr_xive_nvt_unrealize (DeviceState *dev,Error **errp) +{ +qemu_unregister_reset (spapr_xive_nvt_reset, dev); +} + +static void spapr_xive_nvt_init (Object *obj) +{ +sPAPRXiveNVT *nvt =SPAPR_XIVE_NVT (obj); + + nvt->ring_os = &nvt->regs[TM_QW1_OS ]; +} + +static bool vmstate_spapr_xive_nvt_needed (void *opaque) +{ +/* TODO check machine XIVE support */ +return true; +} + +static const VMStateDescription vmstate_spapr_xive_nvt = { + .name =TYPE_SPAPR_XIVE_NVT , + .version_id =1 , + .minimum_version_id =1 , + .needed = vmstate_spapr_xive_nvt_needed, + .fields = (VMStateField []) { +VMSTATE_BUFFER (regs, sPAPRXiveNVT), +VMSTATE_END_OF_LIST () + }, +}; + +static void spapr_xive_nvt_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = spapr_xive_nvt_realize; + dc->unrealize = spapr_xive_nvt_unrealize; + dc->desc ="sPAPR XIVE Interrupt Presenter" ; + dc->vmsd = &vmstate_spapr_xive_nvt; +} + +static const TypeInfo xive_nvt_info = { + .name =TYPE_SPAPR_XIVE_NVT , + .parent =TYPE_DEVICE , + .instance_size =sizeof (sPAPRXiveNVT), + .instance_init = spapr_xive_nvt_init, + .class_init = spapr_xive_nvt_class_init, +}; +static void spapr_xive_register_types (void ) {type_register_static (&spapr_xive_info); +type_register_static (&xive_nvt_info); }type_init (spapr_xive_register_types)
hw/intc/xive-internal.h +92 -0
104 lines not on this page · raw message
include/hw/ppc/spapr_xive.h +11 -0
@@ -14,10 +14,15 @@typedef struct sPAPRXive sPAPRXive ;typedef struct XiveIVE XiveIVE ; +typedef struct sPAPRXiveNVT sPAPRXiveNVT ;#define TYPE_SPAPR_XIVE "spapr-xive"#define SPAPR_XIVE (obj) OBJECT_CHECK(sPAPRXive, (obj), TYPE_SPAPR_XIVE) +#define TYPE_SPAPR_XIVE_NVT "spapr-xive-nvt" +#define SPAPR_XIVE_NVT (obj) \ + OBJECT_CHECK(sPAPRXiveNVT, (obj), TYPE_SPAPR_XIVE_NVT) +struct sPAPRXive {SysBusDevice parent;
@@ -38,6 +43,11 @@ struct sPAPRXive {/* ESB memory region */ hwaddr esb_base;MemoryRegion esb_iomem; + +/* TIMA memory regions */ +hwaddr tm_base; +MemoryRegion tm_iomem_user; +MemoryRegion tm_iomem_os; };static inline bool spapr_xive_irq_is_lsi (sPAPRXive *xive,int lisn)
@@ -48,5 +58,6 @@ static inline bool spapr_xive_irq_is_lsi(sPAPRXive *xive, int lisn)bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn,bool lsi);bool spapr_xive_irq_disable (sPAPRXive *xive,uint32_t lisn);void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon); +void spapr_xive_nvt_pic_print_info (sPAPRXiveNVT *nvt,Monitor *mon);#endif /* PPC_SPAPR_XIVE_H */
Signature · 1 line
2.13.6
PATCH v2 6/19 spapr: introduce the XIVE Event Queues
In reply to Cédric Le GoaterThe Event Queue Descriptor (EQD) table, also known as Event Notification Descriptor (END), is an internal table of the XIVE virtualization routing engine. It specifies on which Event Queue the event data should be posted when an exception occurs (later on pulled by the OS) and which Virtual Processor to notify. The Event Queue is a much more complex structure but we start with a simple model for the sPAPR machine.
There is one XiveEQ per priority and the model chooses to store them under the XIVE virtualization presenter model (sPAPRXiveNVT) to save an extra table. EQs are simply indexed with :
(server << 3) | (priority & 0x7)
This is not in the XIVE architecture but as the EQ index is never exposed to the guest, in the hcalls or in the device tree, we are free to use what fits best the current model.
---
Changes since v1:
- removed spapr_xive_eq_for_server() which did the EQ indexing.
- changed spapr_xive_get_eq() to use a server and a priority parameter
- introduced a couple of macro for the EQ indexing.
- improved 'info pic' output
hw/intc/spapr_xive.c | 48 ++++++++++++++++++++++++++++++++++++++++++-- hw/intc/xive-internal.h | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 2 deletions(-)
hw/intc/spapr_xive.c +46 -2
@@ -15,6 +15,7 @@#include "sysemu/dma.h" #include "monitor/monitor.h" #include "hw/ppc/spapr_xive.h" +#include "hw/ppc/spapr.h" #include "hw/ppc/xics.h" #include "xive-internal.h"
@@ -30,6 +31,8 @@ struct sPAPRXiveNVT {/* Shortcut to the OS ring */ uint8_t *ring_os; + +XiveEQ eqt[XIVE_PRIORITY_MAX +1 ]; };static uint64_t spapr_xive_nvt_accept (sPAPRXiveNVT *nvt)
@@ -186,6 +189,13 @@ static const MemoryRegionOps spapr_xive_tm_user_ops = { }, }; +static sPAPRXiveNVT *spapr_xive_nvt_get (sPAPRXive *xive,int server) +{ +PowerPCCPU *cpu =spapr_find_cpu (server); + +return cpu ?SPAPR_XIVE_NVT (cpu->intc) :NULL ; +} +static void spapr_xive_irq (sPAPRXive *xive,int lisn) {
@@ -461,19 +471,22 @@ void spapr_xive_pic_print_info(sPAPRXive *xive, Monitor *mon)for (i =0 ; i < xive->nr_irqs; i++) {XiveIVE *ive = &xive->ivt[i];uint8_t pq; +uint32_t eq_idx;if (!(ive->w &IVE_VALID )) {continue ; } pq =spapr_xive_pq_get (xive, i); + eq_idx =GETFIELD (IVE_EQ_INDEX , ive->w); -monitor_printf (mon," %4x %s %s %c%c %08x %08x\n" , i, +monitor_printf (mon," %4x %s %s %c%c server:%d prio:%d %08x\n" , i,spapr_xive_irq_is_lsi (xive, i) ?"LSI" :"MSI" , ive->w &IVE_MASKED ?"M" :" " , pq &XIVE_ESB_VAL_P ?'P' :'-' , pq &XIVE_ESB_VAL_Q ?'Q' :'-' , - (int )GETFIELD (IVE_EQ_INDEX , ive->w), +XIVE_EQ_INDEX_SERVER (eq_idx), +XIVE_EQ_INDEX_PRIO (eq_idx), (int )GETFIELD (IVE_EQ_DATA , ive->w)); } }
@@ -611,6 +624,8 @@ static void spapr_xive_nvt_reset(void *dev)sPAPRXiveNVT *nvt =SPAPR_XIVE_NVT (dev);memset (nvt->regs,0 ,sizeof (nvt->regs)); + +memset (nvt->eqt,0 ,sizeof (nvt->eqt)); }static void spapr_xive_nvt_realize (DeviceState *dev,Error **errp)
@@ -658,6 +673,23 @@ static void spapr_xive_nvt_init(Object *obj) nvt->ring_os = &nvt->regs[TM_QW1_OS ]; } +static const VMStateDescription vmstate_spapr_xive_nvt_eq = { + .name =TYPE_SPAPR_XIVE_NVT "/eq" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (w0, XiveEQ), +VMSTATE_UINT32 (w1, XiveEQ), +VMSTATE_UINT32 (w2, XiveEQ), +VMSTATE_UINT32 (w3, XiveEQ), +VMSTATE_UINT32 (w4, XiveEQ), +VMSTATE_UINT32 (w5, XiveEQ), +VMSTATE_UINT32 (w6, XiveEQ), +VMSTATE_UINT32 (w7, XiveEQ), +VMSTATE_END_OF_LIST () + }, +}; +static bool vmstate_spapr_xive_nvt_needed (void *opaque) {/* TODO check machine XIVE support */
@@ -671,6 +703,8 @@ static const VMStateDescription vmstate_spapr_xive_nvt = { .needed = vmstate_spapr_xive_nvt_needed, .fields = (VMStateField []) {VMSTATE_BUFFER (regs, sPAPRXiveNVT), +VMSTATE_STRUCT_ARRAY (eqt, sPAPRXiveNVT, (XIVE_PRIORITY_MAX +1 ),1 , + vmstate_spapr_xive_nvt_eq, XiveEQ),VMSTATE_END_OF_LIST () }, };
@@ -731,3 +765,13 @@ bool spapr_xive_irq_disable(sPAPRXive *xive, uint32_t lisn) xive->status[lisn] =0 ;return true; } + +XiveEQ *spapr_xive_get_eq (sPAPRXive *xive,uint32_t server,uint8_t priority) +{ +sPAPRXiveNVT *nvt =spapr_xive_nvt_get (xive, server); + +if (!nvt || priority >XIVE_PRIORITY_MAX ) { +return NULL ; + } +return &nvt->eqt[priority]; +}
hw/intc/xive-internal.h +53 -0
61 lines not on this page · raw message
Signature · 1 line
2.13.6
PATCH v2 7/19 spapr: push the XIVE EQ data in OS event queue
In reply to Cédric Le GoaterIf a triggered event is let through by the XIVE virtualization routing engine, the Event Queue data defined in the associated IVE is pushed in the in-memory event queue. The latter is a circular buffer provided by the OS using the H_INT_SET_QUEUE_CONFIG hcall, one per server and priority couple. Each Event Queue entry is 4 bytes long, the first bit being a 'generation' bit and the 31 following bits the EQ Data field.
The EQ Data field provides a way to set an invariant logical event source number for an IRQ. It is set with the H_INT_SET_SOURCE_CONFIG hcall when the EISN flag is used.
---
Changes since v1:
- replaced dma_memory_write() by stl_be_dma()
- improved 'info pic' output
hw/intc/spapr_xive.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 3 deletions(-)
hw/intc/spapr_xive.c +95 -3
@@ -196,9 +196,87 @@ static sPAPRXiveNVT *spapr_xive_nvt_get(sPAPRXive *xive, int server)return cpu ?SPAPR_XIVE_NVT (cpu->intc) :NULL ; } +static void spapr_xive_pic_print_info_eq (XiveEQ *eq,Monitor *mon) +{ +uint64_t qaddr_base = (((uint64_t )(eq->w2 &0x0fffffff )) <<32 ) | eq->w3; +uint32_t qindex =GETFIELD (EQ_W1_PAGE_OFF , eq->w1); +uint32_t qgen =GETFIELD (EQ_W1_GENERATION , eq->w1); +uint32_t qsize =GETFIELD (EQ_W0_QSIZE , eq->w0); +uint32_t qentries =1 << (qsize +10 ); + +monitor_printf (mon,"eq:@%08" PRIx64"% 6d/%5d ^%d" , qaddr_base, + qindex, qentries, qgen); +} + +static void spapr_xive_eq_push (XiveEQ *eq,uint32_t data) +{ +uint64_t qaddr_base = (((uint64_t )(eq->w2 &0x0fffffff )) <<32 ) | eq->w3; +uint32_t qsize =GETFIELD (EQ_W0_QSIZE , eq->w0); +uint32_t qindex =GETFIELD (EQ_W1_PAGE_OFF , eq->w1); +uint32_t qgen =GETFIELD (EQ_W1_GENERATION , eq->w1); + +uint64_t qaddr = qaddr_base + (qindex <<2 ); +uint32_t qdata = (qgen <<31 ) | (data &0x7fffffff ); +uint32_t qentries =1 << (qsize +10 ); + +if (stl_be_dma (&address_space_memory, qaddr, qdata)) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: failed to write EQ data @0x%" + HWADDR_PRIx"\n" , qaddr); +return ; + } + + qindex = (qindex +1 ) % qentries; +if (qindex ==0 ) { + qgen ^=1 ; + eq->w1 =SETFIELD (EQ_W1_GENERATION , eq->w1, qgen); + } + eq->w1 =SETFIELD (EQ_W1_PAGE_OFF , eq->w1, qindex); +} +static void spapr_xive_irq (sPAPRXive *xive,int lisn) { +XiveIVE *ive; +XiveEQ *eq; +uint32_t eq_idx; +uint8_t priority; + + ive =spapr_xive_get_ive (xive, lisn); +if (!ive || !(ive->w &IVE_VALID )) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid LISN %d\n" , lisn); +return ; + } +if (ive->w &IVE_MASKED ) { +return ; + } + +/* Find our XiveEQ */ + eq_idx =GETFIELD (IVE_EQ_INDEX , ive->w); + eq =spapr_xive_get_eq (xive,XIVE_EQ_INDEX_SERVER (eq_idx), +XIVE_EQ_INDEX_PRIO (eq_idx)); +if (!eq) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: No EQ for LISN %d\n" , lisn); +return ; + } + +if (eq->w0 &EQ_W0_ENQUEUE ) { +spapr_xive_eq_push (eq,GETFIELD (IVE_EQ_DATA , ive->w)); + } + +if (!(eq->w0 &EQ_W0_UCOND_NOTIFY )) { +qemu_log_mask (LOG_UNIMP ,"XIVE: !UCOND_NOTIFY not implemented\n" ); + } + +if (GETFIELD (EQ_W6_FORMAT_BIT , eq->w6) ==0 ) { + priority =GETFIELD (EQ_W7_F0_PRIORITY , eq->w7); + +/* The EQ is masked. Can this happen ? */ +if (priority ==0xff ) { +g_assert_not_reached (); + } + }else { +qemu_log_mask (LOG_UNIMP ,"XIVE: w7 format1 not implemented\n" ); + } }/*
@@ -480,14 +558,28 @@ void spapr_xive_pic_print_info(sPAPRXive *xive, Monitor *mon) pq =spapr_xive_pq_get (xive, i); eq_idx =GETFIELD (IVE_EQ_INDEX , ive->w); -monitor_printf (mon," %4x %s %s %c%c server:%d prio:%d %08x\n" , i, +monitor_printf (mon," %4x %s %s %c%c server:%d prio:%d " , i,spapr_xive_irq_is_lsi (xive, i) ?"LSI" :"MSI" , ive->w &IVE_MASKED ?"M" :" " , pq &XIVE_ESB_VAL_P ?'P' :'-' , pq &XIVE_ESB_VAL_Q ?'Q' :'-' ,XIVE_EQ_INDEX_SERVER (eq_idx), -XIVE_EQ_INDEX_PRIO (eq_idx), - (int )GETFIELD (IVE_EQ_DATA , ive->w)); +XIVE_EQ_INDEX_PRIO (eq_idx)); + +if (!(ive->w &IVE_MASKED )) { +XiveEQ *eq; + + eq =spapr_xive_get_eq (xive,XIVE_EQ_INDEX_SERVER (eq_idx), +XIVE_EQ_INDEX_PRIO (eq_idx)); +if (eq) { +spapr_xive_pic_print_info_eq (eq, mon); +monitor_printf (mon," data:%08x" , + (int )GETFIELD (IVE_EQ_DATA , ive->w)); + }else { +monitor_printf (mon,"no eq ?!" ); + } + } +monitor_printf (mon,"\n" ); } }
Signature · 1 line
2.13.6
PATCH v2 8/19 spapr: notify the CPU when the XIVE interrupt priority is more privileged
In reply to Cédric Le GoaterOnce an event has been routed, the XIVE virtualization presenter engine raises the bit corresponding to the priority of the pending interrupt in the register IBP (Interrupt Pending Buffer). The Pending Interrupt Priority Register (PIPR) is also updated using the IPB. It contains the priority of the most favored pending notification.
The PIPR is then compared to the the Current Processor Priority Register (CPPR). If it is more favored (numerically less than), the CPU interrupt line is raised and the EO bit of the Notification Source Register (NSR) is updated to notify the presence of an exception for the O/S. The check needs to be done whenever the PIPR or the CPPR are changed.
The O/S acknowledges the interrupt with a special load in the Thread Interrupt Management Area. If the EO bit of the NSR is set, the CPPR takes the value of PIPR. The bit number in the IBP corresponding to the priority of the pending interrupt is reseted and so is the EO bit of the NSR.
---
Changes since v1:
- set initial TM_PIPR to 0xFF
hw/intc/spapr_xive.c | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-)
hw/intc/spapr_xive.c +88 -1
@@ -35,9 +35,68 @@ struct sPAPRXiveNVT {XiveEQ eqt[XIVE_PRIORITY_MAX +1 ]; }; +/* Convert a priority number to an Interrupt Pending Buffer (IPB) +* register, which indicates a pending interrupt at the priority +* corresponding to the bit number +*/ +static uint8_t priority_to_ipb (uint8_t priority) +{ +return priority >XIVE_PRIORITY_MAX ? +0 :1 << (XIVE_PRIORITY_MAX - priority); +} + +/* Convert an Interrupt Pending Buffer (IPB) register to a Pending +* Interrupt Priority Register (PIPR), which contains the priority of +* the most favored pending notification. +*/ +static uint8_t ipb_to_pipr (uint8_t ibp) +{ +return ibp ?clz32 ((uint32_t )ibp <<24 ) :0xff ; +} + +/* +* TODO: +* +* Ben says: " +* +* PIPR is clamped to CPPR. So the value in the PIPR is: +* +* v = leftmost_bit_of(ipb) (or 0xff); +* pipr = v < cppr ? v : cppr; +* +* which means it's never actually 0xff ... surprise !". +* +* But, the CPPR is set to 0xFF by the OS and so the PIPR will always +* be more favored ... I am confused ... +*/ static uint64_t spapr_xive_nvt_accept (sPAPRXiveNVT *nvt) { -return 0 ; +uint8_t nsr = nvt->ring_os[TM_NSR ]; + +qemu_irq_lower (nvt->output); + +if (nvt->ring_os[TM_NSR ] &TM_QW1_NSR_EO ) { +uint8_t cppr = nvt->ring_os[TM_PIPR ]; + + nvt->ring_os[TM_CPPR ] = cppr; + +/* Reset the pending buffer bit */ + nvt->ring_os[TM_IPB ] &= ~priority_to_ipb (cppr); + nvt->ring_os[TM_PIPR ] =ipb_to_pipr (nvt->ring_os[TM_IPB ]); + +/* Drop Exception bit for OS */ + nvt->ring_os[TM_NSR ] &= ~TM_QW1_NSR_EO ; + } + +return (nsr <<8 ) | nvt->ring_os[TM_CPPR ]; +} + +static void spapr_xive_nvt_notify (sPAPRXiveNVT *nvt) +{ +if (nvt->ring_os[TM_PIPR ] < nvt->ring_os[TM_CPPR ]) { + nvt->ring_os[TM_NSR ] |=TM_QW1_NSR_EO ; +qemu_irq_raise (nvt->output); + } }static void spapr_xive_nvt_set_cppr (sPAPRXiveNVT *nvt,uint8_t cppr)
@@ -47,6 +106,10 @@ static void spapr_xive_nvt_set_cppr(sPAPRXiveNVT *nvt, uint8_t cppr) } nvt->ring_os[TM_CPPR ] = cppr; + +/* CPPR has changed, check if we need to redistribute a pending +* exception */ +spapr_xive_nvt_notify (nvt); }/*
@@ -239,6 +302,8 @@ static void spapr_xive_irq(sPAPRXive *xive, int lisn)XiveEQ *eq;uint32_t eq_idx;uint8_t priority; +uint32_t server; +sPAPRXiveNVT *nvt; ive =spapr_xive_get_ive (xive, lisn);if (!ive || !(ive->w &IVE_VALID )) {
@@ -267,6 +332,13 @@ static void spapr_xive_irq(sPAPRXive *xive, int lisn)qemu_log_mask (LOG_UNIMP ,"XIVE: !UCOND_NOTIFY not implemented\n" ); } + server =GETFIELD (EQ_W6_NVT_INDEX , eq->w6); + nvt =spapr_xive_nvt_get (xive, server); +if (!nvt) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: No NVT for server %d\n" , server); +return ; + } +if (GETFIELD (EQ_W6_FORMAT_BIT , eq->w6) ==0 ) { priority =GETFIELD (EQ_W7_F0_PRIORITY , eq->w7);
@@ -274,9 +346,18 @@ static void spapr_xive_irq(sPAPRXive *xive, int lisn)if (priority ==0xff ) {g_assert_not_reached (); } + +/* Update the IPB (Interrupt Pending Buffer) with the priority +* of the new notification and inform the NVT, which will +* decide to raise the exception, or not, depending the CPPR. +*/ + nvt->ring_os[TM_IPB ] |=priority_to_ipb (priority); + nvt->ring_os[TM_PIPR ] =ipb_to_pipr (nvt->ring_os[TM_IPB ]); }else {qemu_log_mask (LOG_UNIMP ,"XIVE: w7 format1 not implemented\n" ); } + +spapr_xive_nvt_notify (nvt); }/*
@@ -717,6 +798,12 @@ static void spapr_xive_nvt_reset(void *dev)memset (nvt->regs,0 ,sizeof (nvt->regs)); +/* +* Initialize PIPR to 0xFF to avoid phantom interrupts when the +* CPPR is first set. +*/ + nvt->ring_os[TM_PIPR ] =ipb_to_pipr (nvt->ring_os[TM_IPB ]); +memset (nvt->eqt,0 ,sizeof (nvt->eqt)); }
Signature · 1 line
2.13.6
PATCH v2 9/19 spapr: add support for the SET_OS_PENDING command (XIVE)
In reply to Cédric Le GoaterThis command offers the possibility for the O/S to adjust the IPB to allow a CPU to process event queues of other priorities during one physical interrupt cycle. This is not currently used by the XIVE support for sPAPR in Linux but it is by the hypervisor.
More from Ben :
It's a way to avoid the SW replay on EOI.
IE, assume you have 2 interrupts in the queue. You take the exception, ack the first one, process it etc... Then you EOI, the HW won't send a second notification. You need to look at the queue and continue consuming until it's empty.
Today Linux checks the queue on EOI and use a SW mechanism to synthesize a new pseudo-external interrupt.
This MMIO command would allow the OS to instead set back the corresponding priority bit to 1 in the IPB and cause the HW to re-emit the interrupt instead of SW.
Linux doesn't use this today because DD1 didn't support it for the HV level, but other OSes might and we also might use it when we do groups, thus allowing redistribution.
--- hw/intc/spapr_xive.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
hw/intc/spapr_xive.c +16 -2
@@ -166,9 +166,23 @@ static bool spapr_xive_tm_is_readonly(uint8_t offset)static void spapr_xive_tm_write_special (sPAPRXiveNVT *nvt,hwaddr offset,uint64_t value,unsigned size) { -/* TODO: support TM_SPC_SET_OS_PENDING */ +switch (offset) { +case TM_SPC_SET_OS_PENDING : +if (size ==1 ) { + nvt->ring_os[TM_IPB ] |=priority_to_ipb (value &0xff ); + nvt->ring_os[TM_PIPR ] =ipb_to_pipr (nvt->ring_os[TM_IPB ]); +spapr_xive_nvt_notify (nvt); + } +break ; +case TM_SPC_ACK_OS_EL :/* TODO */ +qemu_log_mask (LOG_UNIMP ,"XIVE: no command to acknowledge O/S " +"Interrupt to even O/S reporting line\n" ); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid TIMA write @%" + HWADDR_PRIx" size %d\n" , offset, size); + } -/* TODO: support TM_SPC_ACK_OS_EL */ } static void spapr_xive_tm_os_write(void *opaque, hwaddr offset,
Signature · 1 line
2.13.6
PATCH v2 10/19 spapr: introduce a 'xive_exploitation' boolean to enable XIVE
In reply to Cédric Le GoaterThe XIVE exploitation interrupt mode will be enabled for newer machines and disabled for older ones. Also provide a command line machine option to switch XIVE off on newer machines if needed.
--- hw/intc/spapr_xive.c | 10 ++++++---- hw/ppc/spapr.c | 35 +++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 1 + 3 files changed, 42 insertions(+), 4 deletions(-)
hw/intc/spapr_xive.c +6 -4
@@ -756,8 +756,9 @@ static const VMStateDescription vmstate_spapr_xive_ive = {static bool vmstate_spapr_xive_needed (void *opaque) { -/* TODO check machine XIVE support */ -return true; +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); + +return spapr->xive_exploitation; }static const VMStateDescription vmstate_spapr_xive = {
@@ -885,8 +886,9 @@ static const VMStateDescription vmstate_spapr_xive_nvt_eq = {static bool vmstate_spapr_xive_nvt_needed (void *opaque) { -/* TODO check machine XIVE support */ -return true; +sPAPRMachineState *spapr =SPAPR_MACHINE (qdev_get_machine ()); + +return spapr->xive_exploitation; }static const VMStateDescription vmstate_spapr_xive_nvt = {
hw/ppc/spapr.c +35 -0
@@ -2820,6 +2820,29 @@ static void spapr_set_vsmt(Object *obj, Visitor *v, const char *name,visit_type_uint32 (v, name, (uint32_t *)opaque, errp); } +static bool spapr_get_xive_exploitation (Object *obj,Error **errp) +{ +sPAPRMachineState *spapr =SPAPR_MACHINE (obj); + +return spapr->xive_exploitation; +} + +static void spapr_set_xive_exploitation (Object *obj,bool value, +Error **errp) +{ +sPAPRMachineState *spapr =SPAPR_MACHINE (obj); + +if (value) { +/* Don't let older machines activate XIVE */ +if (!spapr->xive_exploitation) { +error_setg (errp,"\"xive-exploitation\" option can not be " +"switched on" ); + } + }else { + spapr->xive_exploitation = false; + } +} +static void spapr_machine_initfn (Object *obj) {sPAPRMachineState *spapr =SPAPR_MACHINE (obj);
@@ -2855,6 +2878,15 @@ static void spapr_machine_initfn(Object *obj)object_property_set_description (obj,"vsmt" ,"Virtual SMT: KVM behaves as if this were" " the host's SMT mode" , &error_abort); + + spapr->xive_exploitation = true; +object_property_add_bool (obj,"xive-exploitation" , + spapr_get_xive_exploitation, + spapr_set_xive_exploitation, +NULL ); +object_property_set_description (obj,"xive-exploitation" , +"XIVE exploitation mode POWER9" , +NULL ); }static void spapr_machine_finalizefn (Object *obj)
@@ -3890,7 +3922,10 @@ DEFINE_SPAPR_MACHINE(2_12, "2.12", true);static void spapr_machine_2_11_instance_options (MachineState *machine) { +sPAPRMachineState *spapr =SPAPR_MACHINE (machine); +spapr_machine_2_12_instance_options (machine); + spapr->xive_exploitation = false; }static void spapr_machine_2_11_class_options (MachineClass *mc)
include/hw/ppc/spapr.h +1 -0
@@ -127,6 +127,7 @@ struct sPAPRMachineState {MemoryHotplugState hotplug_memory;const char *icp_type; +bool xive_exploitation; };#define H_SUCCESS 0
Signature · 1 line
2.13.6
PATCH v2 11/19 spapr: add a sPAPRXive object to the machine
In reply to Cédric Le GoaterThe sPAPRXive object is designed to be always available, so it is created unconditionally on newer machines. Depending on the configuration and the guest capabilities, the CAS negotiation process will decide which interrupt mode to activate: legacy or XIVE exploitation.
The XIVE model makes use of the full range of the IRQ number space. The IRQ numbers for the CPU IPIs in XIVE are allocated at the bottom of this space, below XICS_IRQ_BASE, to preserve compatibility with XICS which does not use that range.
That leaves us with 4K possible IPIs. This should be enough for sometime given that the maximum number of CPUs is 1024 for the sPAPR machine under QEMU. For the record, the biggest POWER8 or POWER9 system has a maximum of 1536 HW threads (16 sockets, 192 cores, SMT8).
Also make sure that the allocated IRQ numbers are kept in sync between XICS and XIVE, when available.
---
Changes since v1:
- conditioned the creation of the sPAPRXive object to the xive_exploitation bool which false on older pseries machine.
- merged in the IPI allocation patch
- parented the sPAPRXive object to sysbus.
hw/ppc/spapr.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr.h | 2 ++ 2 files changed, 52 insertions(+)
hw/ppc/spapr.c +50 -0
@@ -56,6 +56,7 @@#include "hw/ppc/spapr_vio.h" #include "hw/pci-host/spapr.h" #include "hw/ppc/xics.h" +#include "hw/ppc/spapr_xive.h" #include "hw/pci/msi.h" #include "hw/pci/pci.h"
@@ -204,6 +205,30 @@ static void xics_system_init(MachineState *machine, int nr_irqs, Error **errp) } } +static sPAPRXive *spapr_xive_create (sPAPRMachineState *spapr,int nr_irqs, +Error **errp) +{ +Error *local_err =NULL ; +Object *obj; + + obj =object_new (TYPE_SPAPR_XIVE ); +object_property_add_child (OBJECT (spapr),"xive" , obj, &error_abort); +object_property_set_int (obj, nr_irqs,"nr-irqs" , &local_err); +if (local_err) { + goto error; + } +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { + goto error; + } + +qdev_set_parent_bus (DEVICE (obj),sysbus_get_default ()); +return SPAPR_XIVE (obj); +error: +error_propagate (errp, local_err); +return NULL ; +} +static int spapr_fixup_cpu_smt_dt (void *fdt,int offset,PowerPCCPU *cpu,int smt_threads) {
@@ -2390,6 +2415,25 @@ static void ppc_spapr_init(MachineState *machine)/* Set up Interrupt Controller before we create the VCPUs */ xics_system_init (machine,XICS_IRQS_SPAPR , &error_fatal); +if (spapr->xive_exploitation) { +/* We don't have KVM support yet, so check for irqchip=on */ +if (kvm_enabled () &&machine_kernel_irqchip_required (machine)) { +error_report ("kernel_irqchip requested. no XIVE support" ); +exit (1 ); + }else { +/* XIVE uses the full range of IRQ numbers. The CPU IPIs +* will use the range below XICS_IRQ_BASE, unused by XICS. */ + spapr->xive = +spapr_xive_create (spapr,XICS_IRQ_BASE +XICS_IRQS_SPAPR , + &error_fatal); + +/* Allocate the first IRQ numbers for the XIVE IPIs */ +for (i =0 ; i <xics_max_server_number (); ++i) { +spapr_xive_irq_enable (spapr->xive, i, false); + } + } + } +/* Set up containers for ibm,client-architecture-support negotiated options */ spapr->ov5 =spapr_ovec_new ();
@@ -3647,6 +3691,9 @@ static int ics_find_free_block(ICSState *ics, int num, int alignnum)static void spapr_irq_set_lsi (sPAPRMachineState *spapr,int irq,bool lsi) {ics_set_irq_type (spapr->ics, irq - spapr->ics->offset, lsi); +if (spapr->xive_exploitation) { +spapr_xive_irq_enable (spapr->xive, irq, lsi); + } } int spapr_irq_alloc(sPAPRMachineState *spapr, int irq_hint, bool lsi,
@@ -3737,6 +3784,9 @@ void spapr_irq_free(sPAPRMachineState *spapr, int irq, int num)memset (&ics->irqs[i],0 ,sizeof (ICSIRQState)); } } +if (spapr->xive_exploitation) { +spapr_xive_irq_disable (spapr->xive, irq); + } }qemu_irq spapr_qirq (sPAPRMachineState *spapr,int irq)
include/hw/ppc/spapr.h +2 -0
@@ -14,6 +14,7 @@ struct sPAPRNVRAM;typedef struct sPAPREventLogEntry sPAPREventLogEntry ;typedef struct sPAPREventSource sPAPREventSource ;typedef struct sPAPRPendingHPT sPAPRPendingHPT ; +typedef struct sPAPRXive sPAPRXive ;#define HPTE64_V_HPTE_DIRTY 0x0000000000000040ULL#define SPAPR_ENTRY_POINT 0x100
@@ -128,6 +129,7 @@ struct sPAPRMachineState {const char *icp_type;bool xive_exploitation; +sPAPRXive *xive; };#define H_SUCCESS 0
Signature · 1 line
2.13.6
PATCH v2 12/19 spapr: add hcalls support for the XIVE exploitation interrupt mode
In reply to Cédric Le GoaterThe different XIVE virtualization engines (sources and event queues) are configured with a set of Hypervisor calls :
- H_INT_GET_SOURCE_INFO
used to obtain the address of the MMIO page of the Event State Buffer (PQ bits) entry associated with the source.
- H_INT_SET_SOURCE_CONFIG
assigns a source to a "target".
- H_INT_GET_SOURCE_CONFIG
determines which "target" and "priority" is assigned to a source
- H_INT_GET_QUEUE_INFO
returns the address of the notification management page associated with the specified "target" and "priority".
- H_INT_SET_QUEUE_CONFIG
sets or resets the event queue for a given "target" and "priority". It is also used to set the notification configuration associated with the queue, only unconditional notification is supported for the moment. Reset is performed with a queue size of 0 and queueing is disabled in that case.
- H_INT_GET_QUEUE_CONFIG
returns the queue settings for a given "target" and "priority".
- H_INT_RESET
resets all of the guest's internal interrupt structures to their initial state, losing all configuration set via the hcalls H_INT_SET_SOURCE_CONFIG and H_INT_SET_QUEUE_CONFIG.
- H_INT_SYNC
issue a synchronisation on a source to make sure all notifications have reached their queue.
Calls that still need to be addressed :
H_INT_SET_OS_REPORTING_LINE
H_INT_GET_OS_REPORTING_LINE
See the code for more documentation on each hcall.
All sources are emulated under the main XIVE object and share the same characteristics :
XIVE_SRC_TRIGGER | XIVE_SRC_STORE_EOI;
---
Changes since v1:
- simplified priority_is_valid() routine (to its minimum)
- used PPC_BIT() macros to define the hcall flags
- removed useless casts
- defined the default characteristic of the single XIVE interrupt source to be : *XIVE_SRC_TRIGGER | XIVE_SRC_STORE_EOI*
- made use of the new spapr_xive_get_eq() prototype
- removed EQ_W0_UCOND_NOTIFY when the EQ is reseted
- fixed XIVE_EQ_DEBUG support. Offset for the generation bit was wrong
hw/intc/Makefile.objs | 2 +- hw/intc/spapr_xive_hcall.c | 859 ++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr.c | 2 + include/hw/ppc/spapr.h | 15 +- include/hw/ppc/spapr_xive.h | 4 + 5 files changed, 880 insertions(+), 2 deletions(-) create mode 100644 hw/intc/spapr_xive_hcall.c
hw/intc/Makefile.objs +1 -1
@@ -35,7 +35,7 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o -obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o +obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o spapr_xive_hcall.o obj-$(CONFIG_POWERNV) += xics_pnv.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.o
hw/intc/spapr_xive_hcall.c new file +859 -0
859 lines not on this page · raw message
hw/ppc/spapr.c +2 -0
@@ -222,6 +222,8 @@ static sPAPRXive *spapr_xive_create(sPAPRMachineState *spapr, int nr_irqs, goto error; } +spapr_xive_hcall_init (spapr); +qdev_set_parent_bus (DEVICE (obj),sysbus_get_default ());return SPAPR_XIVE (obj); error:
include/hw/ppc/spapr.h +14 -1
@@ -388,7 +388,20 @@ struct sPAPRMachineState {#define H_INVALIDATE_PID 0x378#define H_REGISTER_PROC_TBL 0x37C#define H_SIGNAL_SYS_RESET 0x380 -#define MAX_HCALL_OPCODE H_SIGNAL_SYS_RESET + +#define H_INT_GET_SOURCE_INFO 0x3A8 +#define H_INT_SET_SOURCE_CONFIG 0x3AC +#define H_INT_GET_SOURCE_CONFIG 0x3B0 +#define H_INT_GET_QUEUE_INFO 0x3B4 +#define H_INT_SET_QUEUE_CONFIG 0x3B8 +#define H_INT_GET_QUEUE_CONFIG 0x3BC +#define H_INT_SET_OS_REPORTING_LINE 0x3C0 +#define H_INT_GET_OS_REPORTING_LINE 0x3C4 +#define H_INT_ESB 0x3C8 +#define H_INT_SYNC 0x3CC +#define H_INT_RESET 0x3D0 + +#define MAX_HCALL_OPCODE H_INT_RESET/* The hcalls above are standardized in PAPR and implemented by pHyp * as well.
include/hw/ppc/spapr_xive.h +4 -0
@@ -60,4 +60,8 @@ bool spapr_xive_irq_disable(sPAPRXive *xive, uint32_t lisn);void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon);void spapr_xive_nvt_pic_print_info (sPAPRXiveNVT *nvt,Monitor *mon); +typedef struct sPAPRMachineState sPAPRMachineState ; + +void spapr_xive_hcall_init (sPAPRMachineState *spapr); +#endif /* PPC_SPAPR_XIVE_H */
Signature · 1 line
2.13.6
PATCH v2 13/19 spapr: add device tree support for the XIVE interrupt mode
In reply to Cédric Le GoaterThe XIVE interface for the guest is described in the device tree under the "interrupt-controller" node. A couple of new properties are specific to XIVE :
- "reg"
contains the base address and size of the thread interrupt managnement areas (TIMA), also called rings, for the User level and for the Guest OS level. Only the Guest OS level is taken into account today.
- "ibm,xive-eq-sizes"
the size of the event queues. One cell per size supported, contains log2 of size, in ascending order.
- "ibm,xive-lisn-ranges"
the IRQ interrupt number ranges assigned to the guest for the IPIs.
and also under the root node :
- "ibm,plat-res-int-priorities"
contains a list of priorities that the hypervisor has reserved for its own use. OPAL uses the priority 7 queue to automatically escalate interrupts for all other queues (DD2.X POWER9). So only priorities [0..6] are allowed for the guest.
When the XIVE exploitation interrupt mode is activated after the CAS negotiation, the machine will perform a reboot to rebuild the device tree.
---
Changes since v1:
- added a unit id to the nodename
- added properties for the LSIs
- simplified the array for the "ibm,plat-res-int-priorities" property
- renamed to spapr_dt_xive()
hw/intc/spapr_xive_hcall.c | 64 +++++++++++++++++++++++++++++++++++++++++++++ hw/ppc/spapr.c | 7 ++++- hw/ppc/spapr_hcall.c | 6 +++++ include/hw/ppc/spapr_xive.h | 2 ++ 4 files changed, 78 insertions(+), 1 deletion(-)
hw/intc/spapr_xive_hcall.c +64 -0
@@ -857,3 +857,67 @@ void spapr_xive_hcall_init(sPAPRMachineState *spapr)spapr_register_hypercall (H_INT_SYNC , h_int_sync);spapr_register_hypercall (H_INT_RESET , h_int_reset); } + +void spapr_dt_xive (sPAPRMachineState *spapr,int nr_servers, +void *fdt,uint32_t phandle) +{ +sPAPRXive *xive = spapr->xive; +int node; +uint64_t timas[2 *2 ]; +/* Interrupt number ranges for the IPIs */ +uint32_t lisn_ranges[] = { +cpu_to_be32 (0 ), +cpu_to_be32 (nr_servers), + }; +uint32_t eq_sizes[] = { +cpu_to_be32 (12 ),/* 4K */ +cpu_to_be32 (16 ),/* 64K */ +cpu_to_be32 (21 ),/* 2M */ +cpu_to_be32 (24 ),/* 16M */ + }; +/* The following array is in sync with the 'priority_is_valid' +* routine above. Linux is expected to choose priority 6. +*/ +uint32_t plat_res_int_priorities[] = { +cpu_to_be32 (7 ),/* start */ +cpu_to_be32 (0xf8 ),/* count */ + }; +int i; +gchar *nodename; + +/* Thread Interrupt Management Area : User and OS views */ +for (i =0 ; i <2 ; i++) { + timas[i *2 ] =cpu_to_be64 (xive->tm_base + i * (1ull <<TM_SHIFT )); + timas[i *2 +1 ] =cpu_to_be64 (1ull <<TM_SHIFT ); + } + + nodename =g_strdup_printf ("interrupt-controller@%" PRIx64, xive->tm_base); +_FDT (node =fdt_add_subnode (fdt,0 , nodename)); +g_free (nodename); + +_FDT (fdt_setprop_string (fdt, node,"device_type" ,"power-ivpe" )); +_FDT (fdt_setprop (fdt, node,"reg" , timas,sizeof (timas))); + +_FDT (fdt_setprop_string (fdt, node,"compatible" ,"ibm,power-ivpe" )); +_FDT (fdt_setprop (fdt, node,"ibm,xive-eq-sizes" , eq_sizes, +sizeof (eq_sizes))); +_FDT (fdt_setprop (fdt, node,"ibm,xive-lisn-ranges" , lisn_ranges, +sizeof (lisn_ranges))); + +/* For Linux to link the LSIs to the main interrupt controller. +* These properties are not in XIVE exploitation mode sPAPR +* specs +*/ +_FDT (fdt_setprop (fdt, node,"interrupt-controller" ,NULL ,0 )); +_FDT (fdt_setprop_cell (fdt, node,"#interrupt-cells" ,2 )); + +/* For SLOF */ +_FDT (fdt_setprop_cell (fdt, node,"linux,phandle" , phandle)); +_FDT (fdt_setprop_cell (fdt, node,"phandle" , phandle)); + +/* The "ibm,plat-res-int-priorities" property defines the priority +* ranges reserved by the hypervisor +*/ +_FDT (fdt_setprop (fdt,0 ,"ibm,plat-res-int-priorities" , + plat_res_int_priorities,sizeof (plat_res_int_priorities))); +}
hw/ppc/spapr.c +6 -1
@@ -1155,7 +1155,12 @@ static void *spapr_build_fdt(sPAPRMachineState *spapr,_FDT (fdt_setprop_cell (fdt,0 ,"#size-cells" ,2 ));/* /interrupt controller */ -spapr_dt_xics (xics_max_server_number (), fdt,PHANDLE_XICP ); +if (!spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +spapr_dt_xics (xics_max_server_number (), fdt,PHANDLE_XICP ); + }else { +/* Populate device tree for XIVE */ +spapr_dt_xive (spapr,xics_max_server_number (), fdt,PHANDLE_XICP ); + } ret =spapr_populate_memory (spapr, fdt);if (ret <0 ) {
hw/ppc/spapr_hcall.c +6 -0
@@ -1646,6 +1646,12 @@ static target_ulong h_client_architecture_support(PowerPCCPU *cpu, (spapr_h_cas_compose_response (spapr, args[1 ], args[2 ], ov5_updates) !=0 ); } + +/* We need to rebuild the device tree for XIVE, generate a reset */ +if (!spapr->cas_reboot) { + spapr->cas_reboot =spapr_ovec_test (ov5_updates,OV5_XIVE_EXPLOIT ); + } +spapr_ovec_cleanup (ov5_updates);if (spapr->cas_reboot) {
include/hw/ppc/spapr_xive.h +2 -0
@@ -63,5 +63,7 @@ void spapr_xive_nvt_pic_print_info(sPAPRXiveNVT *nvt, Monitor *mon);typedef struct sPAPRMachineState sPAPRMachineState ;void spapr_xive_hcall_init (sPAPRMachineState *spapr); +void spapr_dt_xive (sPAPRMachineState *spapr,int nr_servers,void *fdt, +uint32_t phandle);#endif /* PPC_SPAPR_XIVE_H */
Signature · 1 line
2.13.6
PATCH v2 14/19 spapr: introduce a helper to map the XIVE memory regions
In reply to Cédric Le GoaterWhen the XIVE exploitation interrupt mode is activated, the machine needs to expose to the guest the MMIO regions used by the controller :
- Event State Buffers
- Thread Interrupt Management Area for the OS and User views
Migration will also need to reflect the current interrupt mode in use.
---
Changes since v1:
- moved the mapping of the XIVE memory region under the machine reset handler.
hw/intc/spapr_xive.c | 10 ++++++++++ hw/ppc/spapr.c | 10 ++++++++++ include/hw/ppc/spapr_xive.h | 1 + 3 files changed, 21 insertions(+)
hw/intc/spapr_xive.c +10 -0
@@ -970,3 +970,13 @@ XiveEQ *spapr_xive_get_eq(sPAPRXive *xive, uint32_t server, uint8_t priority) }return &nvt->eqt[priority]; } + +void spapr_xive_mmio_map (sPAPRXive *xive) +{ +/* ESBs */ +sysbus_mmio_map (SYS_BUS_DEVICE (xive),0 , xive->esb_base); + +/* Thread Management Interrupt Area: User and OS views */ +sysbus_mmio_map (SYS_BUS_DEVICE (xive),1 , xive->tm_base); +sysbus_mmio_map (SYS_BUS_DEVICE (xive),2 , xive->tm_base + (1 <<TM_SHIFT )); +}
hw/ppc/spapr.c +10 -0
@@ -1537,6 +1537,11 @@ static void ppc_spapr_reset(void)ppc_set_compat_all (spapr->max_compat_pvr, &error_fatal); } +/* Setup XIVE resources if required by CAS */ +if (spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +spapr_xive_mmio_map (spapr->xive); + } + fdt =spapr_build_fdt (spapr, rtas_addr, spapr->rtas_size);spapr_load_rtas (spapr, fdt, rtas_addr);
@@ -1644,6 +1649,11 @@ static int spapr_post_load(void *opaque, int version_id) } } +/* Restore XIVE resources if required by CAS */ +if (spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +spapr_xive_mmio_map (spapr->xive); + } +return err; }
include/hw/ppc/spapr_xive.h +1 -0
@@ -59,6 +59,7 @@ bool spapr_xive_irq_enable(sPAPRXive *xive, uint32_t lisn, bool lsi);bool spapr_xive_irq_disable (sPAPRXive *xive,uint32_t lisn);void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon);void spapr_xive_nvt_pic_print_info (sPAPRXiveNVT *nvt,Monitor *mon); +void spapr_xive_mmio_map (sPAPRXive *xive);typedef struct sPAPRMachineState sPAPRMachineState ;
Signature · 1 line
2.13.6
PATCH v2 15/19 spapr: add XIVE support to spapr_qirq()
In reply to Cédric Le GoaterThe XIVE object has its own set of qirqs which is to be used when the XIVE exploitation interrupt mode is activated.
---
Changes since v1:
- introduced a spapr_xive_qirq() helper
hw/intc/spapr_xive.c | 12 ++++++++++++ hw/ppc/spapr.c | 4 ++++ include/hw/ppc/spapr_xive.h | 1 + 3 files changed, 17 insertions(+)
hw/intc/spapr_xive.c +12 -0
@@ -980,3 +980,15 @@ void spapr_xive_mmio_map(sPAPRXive *xive)sysbus_mmio_map (SYS_BUS_DEVICE (xive),1 , xive->tm_base);sysbus_mmio_map (SYS_BUS_DEVICE (xive),2 , xive->tm_base + (1 <<TM_SHIFT )); } + +qemu_irq spapr_xive_qirq (sPAPRXive *xive,int lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive || !(ive->w &IVE_VALID )) { +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid LISN %d\n" , lisn); +return NULL ; + } + +return xive->qirqs[lisn]; +}
hw/ppc/spapr.c +4 -0
@@ -3810,6 +3810,10 @@ qemu_irq spapr_qirq(sPAPRMachineState *spapr, int irq) {ICSState *ics = spapr->ics; +if (spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +return spapr_xive_qirq (spapr->xive, irq); + } +if (ics_valid_irq (ics, irq)) {return ics->qirqs[irq - ics->offset]; }
include/hw/ppc/spapr_xive.h +1 -0
@@ -60,6 +60,7 @@ bool spapr_xive_irq_disable(sPAPRXive *xive, uint32_t lisn);void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon);void spapr_xive_nvt_pic_print_info (sPAPRXiveNVT *nvt,Monitor *mon);void spapr_xive_mmio_map (sPAPRXive *xive); +qemu_irq spapr_xive_qirq (sPAPRXive *xive,int lisn);typedef struct sPAPRMachineState sPAPRMachineState ;
Signature · 1 line
2.13.6
PATCH v2 16/19 spapr: introduce a spapr_icp_create() helper
In reply to Cédric Le GoaterOn sPAPR, the creation of the interrupt presenter depends on some of the machine attributes. When the XIVE exploitation interrupt mode is available, this will get more complex. So provide a machine-level helper to isolate the process and hide the details to the sPAPR core realize function.
--- hw/ppc/spapr.c | 14 ++++++++++++++ hw/ppc/spapr_cpu_core.c | 3 +-- include/hw/ppc/spapr.h | 2 ++ 3 files changed, 17 insertions(+), 2 deletions(-)
hw/ppc/spapr.c +14 -0
@@ -3821,6 +3821,20 @@ qemu_irq spapr_qirq(sPAPRMachineState *spapr, int irq)return NULL ; } +Object *spapr_icp_create (sPAPRMachineState *spapr,Object *cpu,Error **errp) +{ +Error *local_err =NULL ; +Object *obj; + + obj =icp_create (cpu, spapr->icp_type,XICS_FABRIC (spapr), &local_err); +if (local_err) { +error_propagate (errp, local_err); +return NULL ; + } + +return obj; +} +static void spapr_pic_print_info (InterruptStatsProvider *obj,Monitor *mon) {
hw/ppc/spapr_cpu_core.c +1 -2
@@ -121,8 +121,7 @@ static void spapr_cpu_core_realize_child(Object *child, goto error; } - cpu->intc =icp_create (child, spapr->icp_type,XICS_FABRIC (spapr), - &local_err); + cpu->intc =spapr_icp_create (spapr, child, &local_err);if (local_err) { goto error; }
include/hw/ppc/spapr.h +2 -0
@@ -740,4 +740,6 @@ int spapr_irq_alloc_block(sPAPRMachineState *spapr, int num, bool lsi,void spapr_irq_free (sPAPRMachineState *spapr,int irq,int num);qemu_irq spapr_qirq (sPAPRMachineState *spapr,int irq); +Object *spapr_icp_create (sPAPRMachineState *spapr,Object *cpu,Error **errp); +#endif /* HW_SPAPR_H */
Signature · 1 line
2.13.6
PATCH v2 17/19 spapr: toggle the ICP depending on the selected interrupt mode
In reply to Cédric Le GoaterEach interrupt mode has its own specific interrupt presenter object, that we store under the CPU object, one for XICS and one for XIVE. The active presenter, corresponding to the current interrupt mode, is simply selected with a lookup on the children of the CPU.
Migration and CPU hotplug also need to reflect the current interrupt mode in use.
---
Changes since v1:
- conditioned the creation of the sPAPRXiveNVT object to the xive_exploitation bool which false on older pseries machine.
- moved the setting of the ICP under the machine reset handler.
- introduced a spapr_xive_nvt_create() helper
- handled errors in spapr_post_load() to return EINVAL
hw/intc/spapr_xive.c | 19 +++++++++++++++++++ hw/ppc/spapr.c | 29 +++++++++++++++++++++++++++++ hw/ppc/spapr_cpu_core.c | 34 ++++++++++++++++++++++++++++++++++ include/hw/ppc/spapr_cpu_core.h | 1 + include/hw/ppc/spapr_xive.h | 1 + 5 files changed, 84 insertions(+)
hw/intc/spapr_xive.c +19 -0
@@ -992,3 +992,22 @@ qemu_irq spapr_xive_qirq(sPAPRXive *xive, int lisn)return xive->qirqs[lisn]; } + +Object *spapr_xive_nvt_create (Object *cpu,const char *type,Error **errp) +{ +Error *local_err =NULL ; +Object *obj; + + obj =object_new (type); +object_property_add_child (cpu, type, obj, &error_abort); +object_unref (obj); +object_property_add_const_link (obj,ICP_PROP_CPU , cpu, &error_abort); +object_property_set_bool (obj, true,"realized" , &local_err); +if (local_err) { +object_unparent (obj); +error_propagate (errp, local_err); + obj =NULL ; + } + +return obj; +}
hw/ppc/spapr.c +29 -0
@@ -1539,7 +1539,10 @@ static void ppc_spapr_reset(void)/* Setup XIVE resources if required by CAS */ if (spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +spapr_cpu_core_set_icp (TYPE_SPAPR_XIVE_NVT , &error_fatal);spapr_xive_mmio_map (spapr->xive); + }else { +spapr_cpu_core_set_icp (spapr->icp_type, &error_fatal); } fdt =spapr_build_fdt (spapr, rtas_addr, spapr->rtas_size);
@@ -1651,7 +1654,13 @@ static int spapr_post_load(void *opaque, int version_id)/* Restore XIVE resources if required by CAS */ if (spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +Error *local_err =NULL ; +spapr_xive_mmio_map (spapr->xive); +spapr_cpu_core_set_icp (TYPE_SPAPR_XIVE_NVT , &local_err); +if (local_err) { +return -EINVAL ; + } }return err;
@@ -3832,6 +3841,26 @@ Object *spapr_icp_create(sPAPRMachineState *spapr, Object *cpu, Error **errp)return NULL ; } +if (spapr->xive_exploitation) { +Object *obj_xive; + +/* Add a XIVE interrupt presenter. The machine will switch +* the CPU ICP depending on the interrupt model negotiated +* at CAS time. +*/ + obj_xive =spapr_xive_nvt_create (cpu,TYPE_SPAPR_XIVE_NVT , &local_err); +if (local_err) { +object_unparent (obj); +error_propagate (errp, local_err); +return NULL ; + } + +/* when hotplugged, the CPU should have the correct ICP */ +if (spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +return obj_xive; + } + } +return obj; }
hw/ppc/spapr_cpu_core.c +34 -0
@@ -253,3 +253,37 @@ static const TypeInfo spapr_cpu_core_type_infos[] = { };DEFINE_TYPES (spapr_cpu_core_type_infos) + +typedef struct ForeachFindICPArgs { +const char *icp_type; +Object *icp; +} ForeachFindICPArgs; + +static int spapr_cpu_core_find_icp (Object *child,void *opaque) +{ +ForeachFindICPArgs *args = opaque; + +if (object_dynamic_cast (child, args->icp_type)) { + args->icp = child; + } + +return args->icp !=NULL ; +} + +void spapr_cpu_core_set_icp (const char *icp_type,Error **errp) +{ +CPUState *cs; + +CPU_FOREACH (cs) { +ForeachFindICPArgs args = { icp_type,NULL }; +PowerPCCPU *cpu =POWERPC_CPU (cs); + +object_child_foreach (OBJECT (cs), spapr_cpu_core_find_icp, &args); +if (!args.icp) { +error_setg (errp,"Couldn't find a '%s' icp" , icp_type); +return ; + } + + cpu->intc = args.icp; + } +}
include/hw/ppc/spapr_cpu_core.h +1 -0
@@ -38,4 +38,5 @@ typedef struct sPAPRCPUCoreClass { } sPAPRCPUCoreClass;const char *spapr_get_cpu_core_type (const char *cpu_type); +void spapr_cpu_core_set_icp (const char *icp_type,Error **errp);#endif
include/hw/ppc/spapr_xive.h +1 -0
@@ -59,6 +59,7 @@ bool spapr_xive_irq_enable(sPAPRXive *xive, uint32_t lisn, bool lsi);bool spapr_xive_irq_disable (sPAPRXive *xive,uint32_t lisn);void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon);void spapr_xive_nvt_pic_print_info (sPAPRXiveNVT *nvt,Monitor *mon); +Object *spapr_xive_nvt_create (Object *cpu,const char *type,Error **errp);void spapr_xive_mmio_map (sPAPRXive *xive);qemu_irq spapr_xive_qirq (sPAPRXive *xive,int lisn);
Signature · 1 line
2.13.6
PATCH v2 18/19 spapr: add support to dump XIVE information
In reply to Cédric Le GoaterModify the InterruptStatsProvider output to reflect the interrupt mode currently in use by the machine.
--- hw/ppc/spapr.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
hw/ppc/spapr.c +10 -2
@@ -3873,10 +3873,18 @@ static void spapr_pic_print_info(InterruptStatsProvider *obj,CPU_FOREACH (cs) {PowerPCCPU *cpu =POWERPC_CPU (cs); -icp_pic_print_info (ICP (cpu->intc), mon); +if (spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +spapr_xive_nvt_pic_print_info (SPAPR_XIVE_NVT (cpu->intc), mon); + }else { +icp_pic_print_info (ICP (cpu->intc), mon); + } } -ics_pic_print_info (spapr->ics, mon); +if (spapr_ovec_test (spapr->ov5_cas,OV5_XIVE_EXPLOIT )) { +spapr_xive_pic_print_info (spapr->xive, mon); + }else { +ics_pic_print_info (spapr->ics, mon); + } }int spapr_vcpu_id (PowerPCCPU *cpu)
Signature · 1 line
2.13.6
PATCH v2 19/19 spapr: advertise XIVE exploitation mode in CAS
In reply to Cédric Le Goater--- hw/ppc/spapr.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-)
hw/ppc/spapr.c +20 -5
@@ -989,10 +989,11 @@ static void spapr_dt_rtas(sPAPRMachineState *spapr, void *fdt)spapr_dt_rtas_tokens (fdt, rtas); } -/* Prepare ibm,arch-vec-5-platform-support, which indicates the MMU features -* that the guest may request and thus the valid values for bytes 24..26 of -* option vector 5: */ -static void spapr_dt_ov5_platform_support (void *fdt,int chosen) +/* Prepare ibm,arch-vec-5-platform-support, which indicates the MMU +* and the XIVE features that the guest may request and thus the valid +* values for bytes 23..26 of option vector 5: */ +static void spapr_dt_ov5_platform_support (sPAPRMachineState *spapr,void *fdt, +int chosen) {PowerPCCPU *first_ppc_cpu =POWERPC_CPU (first_cpu);
@@ -1015,7 +1016,16 @@ static void spapr_dt_ov5_platform_support(void *fdt, int chosen) }else { val[3 ] =0x00 ;/* Hash */ } +/* TODO: introduce a kvmppc_has_cap_xive() ? Works with +* irqchip=off for now +*/ +if (spapr->xive_exploitation) { + val[1 ] =0x80 ;/* OV5_XIVE_BOTH */ + } }else { +if (spapr->xive_exploitation) { + val[1 ] =0x80 ;/* OV5_XIVE_BOTH */ + }/* V3 MMU supports both hash and radix in tcg (with dynamic switching) */ val[3 ] =0xC0 ; }
@@ -1076,7 +1086,7 @@ static void spapr_dt_chosen(sPAPRMachineState *spapr, void *fdt)_FDT (fdt_setprop_string (fdt, chosen,"linux,stdout-path" , stdout_path)); } -spapr_dt_ov5_platform_support (fdt, chosen); +spapr_dt_ov5_platform_support (spapr, fdt, chosen);g_free (stdout_path);g_free (bootlist);
@@ -2487,6 +2497,11 @@ static void ppc_spapr_init(MachineState *machine)spapr_ovec_set (spapr->ov5,OV5_HPT_RESIZE ); } +/* advertise XIVE if not disabled by the user */ +if (spapr->xive_exploitation) { +spapr_ovec_set (spapr->ov5,OV5_XIVE_EXPLOIT ); + } +/* init CPUs */ spapr_set_vsmt_mode (spapr, &error_fatal);
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Cédric Le Goaterhw/intc/spapr_xive.c line 94
Quoted 9 lines
hw/intc/spapr_xive.c new file +9
-0+static const VMStateDescription vmstate_spapr_xive = { + .name =TYPE_SPAPR_XIVE , + .version_id =1 , + .minimum_version_id =1 , + .needed = vmstate_spapr_xive_needed, + .fields = (VMStateField []) { +VMSTATE_UINT32_EQUAL (nr_irqs, sPAPRXive,NULL ), +VMSTATE_STRUCT_VARRAY_UINT32 (ivt, sPAPRXive, nr_irqs,1 , + vmstate_spapr_xive_ive, XiveIVE),
I got it wrong again. This should be :
VMSTATE_STRUCT_VARRAY_POINTER_UINT32(ivt, sPAPRXive, nr_irqs,
vmstate_spapr_xive_ive, XiveIVE),
for migration to work.
Cheers,
C.
Re: [Qemu-devel] [PATCH v2 03/19] spapr: introduce the XIVE interrupt sources
In reply to Cédric Le GoaterQuoted 13 lines
include/hw/ppc/spapr_xive.h +3
-0@@ -24,8 +24,17 @@ struct sPAPRXive {/* Properties */ uint32_t nr_irqs; +/* IRQ */ +qemu_irq *qirqs; +/* XIVE internal tables */
include/hw/ppc/spapr_xive.h struct sPAPRXive { · line 40
Quoted 10 lines
include/hw/ppc/spapr_xive.h +6
-0XiveIVE *ivt; +uint8_t *sbe; +uint32_t sbe_size; + +/* ESB memory region */ +hwaddr esb_base; +MemoryRegion esb_iomem; };bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn);
The addition of the XIVE source fields directly under the sPAPRXive object is really a design choice. But I am starting to think that having multiple XIVE source objects would be a good idea.
Roughly speaking, a XIVE source is a bunch of PQ bits plus a MMIO region to manipulate them and, in the QEMU model, a set of associated qemu_irqs to do the same from the handlers.
In real HW, the PSI host bridge controller on the P9 for instance, a register holds all the P bits of the IRQs (no Q bits because the IRQs are only LSIs) and there is a specific MMIO region for them. PSIHB also has a register to store the assertion level of each IRQ. So this is quite similar to what we are adding above and in the next patch for the LSI support.
The source triggering only depends on the PQ bits (plus the LSI level) and the result is a simple forward of the event notification to the central XIVE engine : the IVRE, doing the routing. The IVRE is really our sPAPRXive object.
The API between the source and the IVRE is extremely simple :
static void spapr_xive_irq(sPAPRXive *xive, int lisn)
The IVRE then scans its IVT, finds the EQ, and moves on to the presenter.
So, we can keep the IVRE engine (sPAPRXive) attached directly to the machine like we have today, this is good, and introduce multiple XIVE source objects. The sPAPR machine would have :
- one for the IPIs [ 0 - nr_servers ]
- one generic for the devices [ 4096 - ]
- one for each phb ?
The source address in the overall ESB MMIO region would be calculated from the offset of the source IRQ numbers in the IRQ number space. The offset could very well be hardcoded for each device. I don't see any XICS compatibility problems as we are sharing correctly the IRQ number space already.
I am starting this discussion because the support for XIVE in the QEMU PowerNV machine will need multiple sources, just like for POWER8. PnvXive will be a bit different because the IVRE tables (IVT and EQDT) are in the virtual machine memory. Most of the settings are done in the VM. The QEMU PowerNV machine will still have to implement the triggering and the routing logic using the guest tables.
Regards,
C.
Re: [Qemu-devel] [PATCH v2 03/19] spapr: introduce the XIVE interrupt sources
Quoted 6 lines · Cédric Le Goater
The API between the source and the IVRE is extremely simple :
static void
spapr_xive_irq(sPAPRXive *xive, int lisn)The IVRE then scans its IVT, finds the EQ, and moves on to the presenter.
In HW it's an MMIO store between the two units (from the source to the IVRE notification port). I wonder in the long run if we should model that the same way...
Quoted 21 lines
So, we can keep the IVRE engine (sPAPRXive) attached directly to the machine like we have today, this is good, and introduce multiple XIVE source objects. The sPAPR machine would have :
- one for the IPIs [ 0 -
nr_servers]
- one generic for the devices [ 4096 - ]
- one for each phb ?The source address in the overall ESB MMIO region would be calculated from the offset of the source IRQ numbers in the IRQ number space. The offset could very well be hardcoded for each device. I don't see any XICS compatibility problems as we are sharing correctly the IRQ number space already.
I am starting this discussion because the support for XIVE in the QEMU PowerNV machine will need multiple sources, just like for POWER8. PnvXive will be a bit different because the IVRE tables (IVT and EQDT) are in the virtual machine memory. Most of the settings are done in the VM. The QEMU PowerNV machine will still have to implement the triggering and the routing logic using the guest tables.
Re: [Qemu-devel] [PATCH v2 01/19] dma-helpers: add a return value to store helpers
In reply to Cédric Le GoaterQuoted 1 line · Cédric Le Goater
Signed-off-by Cédric Le Goater <[email protected]>
Hrm. I know I (indirectly) suggested this, but now that I see it, I'm thinking adding return values here but not on the read side (which would be awkward since they return the read values) seems like not a great idea.
So I'm ok with just open coding the dma_memory_write()s after all.
Quoted 23 lines
--- include/sysemu/dma.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/sysemu/dma.h +2
-2@@ -153,12 +153,12 @@ static inline void dma_memory_unmap(AddressSpace *as,dma_memory_read (as, addr, &val, (_bits) /8 ); \ return _end##_bits##_to_cpu(val); \ } \ - static inline void st##_sname##_##_end##_dma(AddressSpace *as, \ + static inline int st##_sname##_##_end##_dma(AddressSpace *as, \dma_addr_t addr, \ uint##_bits##_t val) \ { \ val = cpu_to_##_end##_bits(val); \ -dma_memory_write (as, addr, &val, (_bits) /8 ); \ +return dma_memory_write (as, addr, &val, (_bits) /8 ); \ }static inline uint8_t ldub_dma (AddressSpace *as,dma_addr_t addr)
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 03/19] spapr: introduce the XIVE interrupt sources
In reply to Benjamin HerrenschmidtQuoted 11 lines · Benjamin Herrenschmidt
Quoted 6 lines · Cédric Le Goater
The API between the source and the IVRE is extremely simple :
static void
spapr_xive_irq(sPAPRXive *xive, int lisn)The IVRE then scans its IVT, finds the EQ, and moves on to the presenter.
In HW it's an MMIO store between the two units (from the source to the IVRE notification port). I wonder in the long run if we should model that the same way...
It's a problem for PowerNV. IVSEs should all have an 'IVT offset' register and a 'notify trigger port address' address register for this purpose. Real HW performs a 4bytes store of the IRQ number to forward the notification to the IVRE. It even makes the model a little simpler because we don't have to look for the appropriate PnvXive object to handle the routing.
For sPAPR, we don't have such MMIOs but still, we could trigger directly the sPAPRXive object without using the qemu_irq objects which stand in the middle. XIVE IPIs don't use them at all and only use MMIOs.
Quoted 21 lines
Quoted 21 lines
So, we can keep the IVRE engine (sPAPRXive) attached directly to the machine like we have today, this is good, and introduce multiple XIVE source objects. The sPAPR machine would have :
- one for the IPIs [ 0 -
nr_servers]
- one generic for the devices [ 4096 - ]
- one for each phb ?The source address in the overall ESB MMIO region would be calculated from the offset of the source IRQ numbers in the IRQ number space. The offset could very well be hardcoded for each device. I don't see any XICS compatibility problems as we are sharing correctly the IRQ number space already.
I am starting this discussion because the support for XIVE in the QEMU PowerNV machine will need multiple sources, just like for POWER8. PnvXive will be a bit different because the IVRE tables (IVT and EQDT) are in the virtual machine memory. Most of the settings are done in the VM. The QEMU PowerNV machine will still have to implement the triggering and the routing logic using the guest tables.
Re: [Qemu-devel] [PATCH v2 01/19] dma-helpers: add a return value to store helpers
In reply to David GibsonQuoted 9 lines · David Gibson
Quoted 1 line · Cédric Le Goater
Signed-off-by Cédric Le Goater <[email protected]>Hrm. I know I (indirectly) suggested this, but now that I see it, I'm thinking adding return values here but not on the read side (which would be awkward since they return the read values) seems like not a great idea.
So I'm ok with just open coding the dma_memory_write()s after all.
OK. It's not a big change. Maybe I can use :
ldl_phys(CPU(cpu)->as, ...) stl_phys(CPU(cpu)->as, ...)
in some cases, which would give us the correct ordering.
The Pnv model does a few more peek/poke in RAM to use the XIVE structures which are larger, 8 * uint_64t for the XiveEQs and 16 for the XiveVPs.
Thanks,
C.
Quoted 25 lines
Quoted 24 lines
--- include/sysemu/dma.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)include/sysemu/dma.h +2
-2@@ -153,12 +153,12 @@ static inline void dma_memory_unmap(AddressSpace *as,dma_memory_read (as, addr, &val, (_bits) /8 ); \ return _end##_bits##_to_cpu(val); \ } \ - static inline void st##_sname##_##_end##_dma(AddressSpace *as, \ + static inline int st##_sname##_##_end##_dma(AddressSpace *as, \dma_addr_t addr, \ uint##_bits##_t val) \ { \ val = cpu_to_##_end##_bits(val); \ -dma_memory_write (as, addr, &val, (_bits) /8 ); \ +return dma_memory_write (as, addr, &val, (_bits) /8 ); \ }static inline uint8_t ldub_dma (AddressSpace *as,dma_addr_t addr)
Re: [Qemu-devel] [PATCH v2 03/19] spapr: introduce the XIVE interrupt sources
In reply to Cédric Le GoaterQuoted 20 lines · Cédric Le Goater
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 6 lines · Cédric Le Goater
The API between the source and the IVRE is extremely simple :
static void
spapr_xive_irq(sPAPRXive *xive, int lisn)The IVRE then scans its IVT, finds the EQ, and moves on to the presenter.
In HW it's an MMIO store between the two units (from the source to the IVRE notification port). I wonder in the long run if we should model that the same way...
It's a problem for PowerNV. IVSEs should all have an 'IVT offset' register and a 'notify trigger port address' address register for this purpose. Real HW performs a 4bytes store of the IRQ number to forward the notification to the IVRE. It even makes the model a little simpler because we don't have to look for the appropriate PnvXive object to handle the routing.
Quoted 4 lines
For sPAPR, we don't have such MMIOs but still, we could trigger directly the sPAPRXive object without using the
qemu_irqobjects which stand in the middle. XIVE IPIs don't use them at all and only use MMIOs.
Yeah, I think we're going to want a model more explicitly close to what the hardware does. It's tempting to shortcut it for PAPR, but a) it'll probably cause us less trouble when we need to implement powernv and b) I think it's less likely to break as we fill out the various details we need.
Quoted 23 lines
Quoted 22 lines
Quoted 22 lines
So, we can keep the IVRE engine (sPAPRXive) attached directly to the machine like we have today, this is good, and introduce multiple XIVE source objects. The sPAPR machine would have :
- one for the IPIs [ 0 -
nr_servers]
- one generic for the devices [ 4096 - ]
- one for each phb ?The source address in the overall ESB MMIO region would be calculated from the offset of the source IRQ numbers in the IRQ number space. The offset could very well be hardcoded for each device. I don't see any XICS compatibility problems as we are sharing correctly the IRQ number space already.
I am starting this discussion because the support for XIVE in the QEMU PowerNV machine will need multiple sources, just like for POWER8. PnvXive will be a bit different because the IVRE tables (IVT and EQDT) are in the virtual machine memory. Most of the settings are done in the VM. The QEMU PowerNV machine will still have to implement the triggering and the routing logic using the guest tables.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Cédric Le GoaterQuoted 23 lines · Cédric Le Goater
With the POWER9 processor comes a new interrupt controller called XIVE. It is composed of three sub-engines :
- Interrupt Virtualization Source Engine (IVSE). These are in PHBs, in the main controller for the IPIS and in the PSI host bridge. They are configured to feed the IVRE with events.
- Interrupt Virtualization Routing Engine (IVRE). Their job is to match an event source with a Notification Virtualization Target (NVT), a priority and an Event Queue (EQ) to determine if a Virtual Processor can handle the event.
- Interrupt Virtualization Presentation Engine (IVPE). It maintains the interrupt state of each hardware thread and present the notification as an external exception.
Each of the engines uses a set of internal tables to redirect exceptions from event sources to CPU threads. The first table we introduce is the Interrupt Virtualization Entry (IVE) table, part of the virtualization engine in charge of routing events. It associates event sources (IRQ numbers) to event queues which will forward, or not, the event notification to the presentation controller.
Quoted 5 lines
The XIVE model is designed to make use of the full range of the IRQ number space and does not use an offset like the XICS mode does. Hence, the IVE table is directly indexed by the IRQ number.
Signed-off-by Cédric Le Goater <[email protected]>
As you've suggested in yourself, I think we might need to more explicitly model the different components of the XIVE system. As part of that, I think you need to be clearer in this base skeleton about exactly what component your XIVE object represents.
If the answer is "the overall thing" I suspect that's not what you want - I had one of those for XICs which proved to be a mistake (eventually replaced by the XICSFabric interface).
Changing the model later isn't impossible, but doing so without breaking migration can be a real pain, so I think it's worth a reasonable effort to try and get it right initially.
Quoted 297 lines
---
Changes since v1 :
- used
g_new0instead ofg_malloc0
- removedVMSTATE_STRUCT_VARRAY_UINT32_ALLOC
- introduced a device reset handler. the object needs to be parented to sysbus when created.
- renamedspapr_xive_irq_settospapr_xive_irq_enable
- renamedspapr_xive_irq_unsettospapr_xive_irq_disable
- moved thePPC_BITmacros undertarget/ppc/cpu.h
- shrinked file copyright headerdefault-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/spapr_xive.c | 156 ++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 41 ++++++++++ include/hw/ppc/spapr_xive.h | 35 +++++++++ 5 files changed, 234 insertions(+) create mode 100644 hw/intc/spapr_xive.c create mode 100644 hw/intc/xive-internal.h create mode 100644 include/hw/ppc/spapr_xive.hdefault-configs/ppc64-softmmu.mak +1
-0@@ -56,6 +56,7 @@ CONFIG_SM501=y CONFIG_XICS=$(CONFIG_PSERIES) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM)) +CONFIG_XIVE_SPAPR=$(CONFIG_PSERIES) # For PReP CONFIG_SERIAL_ISA=y CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -35,6 +35,7 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o +obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o obj-$(CONFIG_POWERNV) += xics_pnv.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/spapr_xive.c new file +156
-0@@ -0,0 +1,156 @@ +/* +* QEMU PowerPC sPAPR XIVE interrupt controller model +* +* Copyright (c) 2017, IBM Corporation. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "target/ppc/cpu.h" +#include "sysemu/cpus.h" +#include "sysemu/dma.h" +#include "monitor/monitor.h" +#include "hw/ppc/spapr_xive.h" + +#include "xive-internal.h" + +/* +* Main XIVE object +*/ + +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) +{ +int i; + +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; + +if (!(ive->w &IVE_VALID )) { +continue ; + } + +monitor_printf (mon," %4x %s %08x %08x\n" , i, + ive->w &IVE_MASKED ?"M" :" " , + (int )GETFIELD (IVE_EQ_INDEX , ive->w), + (int )GETFIELD (IVE_EQ_DATA , ive->w)); + } +} + +static void spapr_xive_reset (DeviceState *dev) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); +int i; + +/* Mask all valid IVEs in the IRQ number space. */ +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; +if (ive->w &IVE_VALID ) { + ive->w |=IVE_MASKED ; + } + } +} + +static void spapr_xive_realize (DeviceState *dev,Error **errp) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); + +if (!xive->nr_irqs) { +error_setg (errp,"Number of interrupt needs to be greater 0" ); +return ; + } + +/* Allocate the IVT (Interrupt Virtualization Table) */ + xive->ivt =g_new0 (XiveIVE, xive->nr_irqs); +} + +static const VMStateDescription vmstate_spapr_xive_ive = { + .name =TYPE_SPAPR_XIVE "/ive" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (w, XiveIVE), +VMSTATE_END_OF_LIST () + }, +}; + +static bool vmstate_spapr_xive_needed (void *opaque) +{ +/* TODO check machine XIVE support */ +return true; +} + +static const VMStateDescription vmstate_spapr_xive = { + .name =TYPE_SPAPR_XIVE , + .version_id =1 , + .minimum_version_id =1 , + .needed = vmstate_spapr_xive_needed, + .fields = (VMStateField []) { +VMSTATE_UINT32_EQUAL (nr_irqs, sPAPRXive,NULL ), +VMSTATE_STRUCT_VARRAY_UINT32 (ivt, sPAPRXive, nr_irqs,1 , + vmstate_spapr_xive_ive, XiveIVE), +VMSTATE_END_OF_LIST () + }, +}; + +static Property spapr_xive_properties[] = { +DEFINE_PROP_UINT32 ("nr-irqs" , sPAPRXive, nr_irqs,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void spapr_xive_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = spapr_xive_realize; + dc->reset = spapr_xive_reset; + dc->props = spapr_xive_properties; + dc->desc ="sPAPR XIVE interrupt controller" ; + dc->vmsd = &vmstate_spapr_xive; +} + +static const TypeInfo spapr_xive_info = { + .name =TYPE_SPAPR_XIVE , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (sPAPRXive), + .class_init = spapr_xive_class_init, +}; + +static void spapr_xive_register_types (void ) +{ +type_register_static (&spapr_xive_info); +} + +type_init (spapr_xive_register_types) + +XiveIVE *spapr_xive_get_ive(sPAPRXive *xive, uint32_t lisn) +{ +return lisn < xive->nr_irqs ? &xive->ivt[lisn] :NULL ; +} + +bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) { +return false; + } + + ive->w |=IVE_VALID ; +return true; +} + +bool spapr_xive_irq_disable (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) { +return false; + } + + ive->w &= ~IVE_VALID ; +return true; +}hw/intc/xive-internal.h new file +41
-0@@ -0,0 +1,41 @@ +/* +* QEMU PowerPC XIVE interrupt controller model +* +* Copyright (c) 2016-2017, IBM Corporation. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +*/ + +#ifndef _INTC_XIVE_INTERNAL_H +#define _INTC_XIVE_INTERNAL_H + +/* Utilities to manipulate these (originaly from OPAL) */ +#define MASK_TO_LSH (m) (__builtin_ffsl(m) - 1) +#define GETFIELD (m, v) (((v) & (m)) >> MASK_TO_LSH(m)) +#define SETFIELD (m, v, val) \ + (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m))) + +/* IVE/EAS +* +* One per interrupt source. Targets that interrupt to a given EQ +* and provides the corresponding logical interrupt number (EQ data) +* +* We also map this structure to the escalation descriptor inside +* an EQ, though in that case the valid and masked bits are not used. +*/ +typedef struct XiveIVE { +/* Use a single 64-bit definition to make it easier to +* perform atomic updates +*/ +uint64_t w; +#define IVE_VALID PPC_BIT(0) +#define IVE_EQ_BLOCK PPC_BITMASK(4, 7)/* Destination EQ block# */ +#define IVE_EQ_INDEX PPC_BITMASK(8, 31)/* Destination EQ index */ +#define IVE_MASKED PPC_BIT(32)/* Masked */ +#define IVE_EQ_DATA PPC_BITMASK(33, 63)/* Data written to the EQ */ +}XiveIVE ; + +XiveIVE *spapr_xive_get_ive (sPAPRXive *xive,uint32_t lisn); + +#endif /* _INTC_XIVE_INTERNAL_H */ include/hw/ppc/spapr_xive.h new file +35
-0@@ -0,0 +1,35 @@ +/* +* QEMU PowerPC sPAPR XIVE interrupt controller model +* +* Copyright (c) 2017, IBM Corporation. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +*/ + +#ifndef PPC_SPAPR_XIVE_H +#define PPC_SPAPR_XIVE_H + +#include <hw/sysbus.h> + +typedef struct sPAPRXive sPAPRXive ; +typedef struct XiveIVE XiveIVE ; + +#define TYPE_SPAPR_XIVE "spapr-xive" +#define SPAPR_XIVE (obj) OBJECT_CHECK(sPAPRXive, (obj), TYPE_SPAPR_XIVE) + +struct sPAPRXive { +SysBusDevice parent; + +/* Properties */ +uint32_t nr_irqs; + +/* XIVE internal tables */ +XiveIVE *ivt; +}; + +bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn); +bool spapr_xive_irq_disable (sPAPRXive *xive,uint32_t lisn); +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon); + +#endif /* PPC_SPAPR_XIVE_H */
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 03/19] spapr: introduce the XIVE interrupt sources
In reply to Cédric Le GoaterQuoted 11 lines · Cédric Le Goater
Each XIVE interrupt source is associated with a two bit state machine called an Event State Buffer (ESB) : the first bit "P" means that an interrupt is "pending" and waiting for an EOI and the bit "Q" (queued) means a new interrupt was triggered while another was still pending.
When an event is triggered, the associated interrupt state bits are fetched and modified and forwarded to the virtualization engine of the controller doing the routing. These can also be controlled by MMIO, to trigger events or turn off the sources for instance. See code for more details on the states and transitions.
Quoted 5 lines
The MMIO space for the ESBs is 512GB large on the bare-metal system (PowerNV) and the BAR depends on the chip id. In our model for the sPAPR machine, we choose to only map the sub-region for the provisioned IRQ numbers and to use the mapping address of chip 0 of a real system.
I think we probably want a device property to make the virtualized base address arbitrary. It's fine for it to default to the chip 0 base, but that'll make it easier to adapt if we need to later on.
As noted in the followup messages, I think you're going to want to move this stuff from the current xive object into a "block of sources" object.
Apart from that this looks pretty sound.
Quoted 381 lines
In the real world, each source may have different characteristics depending on the revision of a controller or the CPU. Early systems had two different MMIO pages for trigger and for EOI. We choose to use the same characteristics for all sources to simplify the model. The minimum CPU level for XIVE exploitation mode will be DD2.X as it has full support.
The OS will obtain the address of the MMIO page of the ESB entry associated with a source and its characteristic using the
H_INT_GET_SOURCE_INFOhcall. This will be addressed in the patch introducing the hcalls.The
spapr_xive_irq()routine in charge of triggering the CPU interrupt line will be filled later on.Signed-off-by Cédric Le Goater <[email protected]>---
Changes since v1:
- merged in the same patch the
qemu_irqhandlers
- reworked the event notification logic of theqemu_irqhandlers.
- introducedXIVE_ESB_STORE_EOIsupport
- removed 'esb_shift' field
- removed a useless check on the validity of the IVE in the memory region handlers.
- fixedspapr_xive_pq_trigger()to return true whenXIVE_ESB_QUEUEDis set
- removed the overall ESB memory region. We now have only one region for the provisioned sources.
- improved 'info pic' outputhw/intc/spapr_xive.c | 254 +++++++++++++++++++++++++++++++++++++++++++- hw/intc/xive-internal.h | 10 ++ include/hw/ppc/spapr_xive.h | 9 ++ 3 files changed, 271 insertions(+), 2 deletions(-)hw/intc/spapr_xive.c +252
-2@@ -18,23 +18,252 @@#include "xive-internal.h" +static void spapr_xive_irq (sPAPRXive *xive,int lisn) +{ + +} +/* -* Main XIVE object +* XIVE Interrupt Source +*/ + +/* +* "magic" Event State Buffer (ESB) MMIO offsets. +* +* Each interrupt source has a 2-bit state machine called ESB +* which can be controlled by MMIO. It's made of 2 bits, P and +* Q. P indicates that an interrupt is pending (has been sent +* to a queue and is waiting for an EOI). Q indicates that the +* interrupt has been triggered while pending. +* +* This acts as a coalescing mechanism in order to guarantee +* that a given interrupt only occurs at most once in a queue. +* +* When doing an EOI, the Q bit will indicate if the interrupt +* needs to be re-triggered. +* +* The following offsets into the ESB MMIO allow to read or +* manipulate the PQ bits. They must be used with an 8-bytes +* load instruction. They all return the previous state of the +* interrupt (atomically). +* +* Additionally, some ESB pages support doing an EOI via a +* store at 0 and some ESBs support doing a trigger via a +* separate trigger page. +*/ +#define XIVE_ESB_STORE_EOI 0x400/* Store */ +#define XIVE_ESB_LOAD_EOI 0x000/* Load */ +#define XIVE_ESB_GET 0x800/* Load */ +#define XIVE_ESB_SET_PQ_00 0xc00/* Load */ +#define XIVE_ESB_SET_PQ_01 0xd00/* Load */ +#define XIVE_ESB_SET_PQ_10 0xe00/* Load */ +#define XIVE_ESB_SET_PQ_11 0xf00/* Load */ + +#define XIVE_ESB_VAL_P 0x2 +#define XIVE_ESB_VAL_Q 0x1 + +#define XIVE_ESB_RESET 0x0 +#define XIVE_ESB_PENDING XIVE_ESB_VAL_P +#define XIVE_ESB_QUEUED (XIVE_ESB_VAL_P | XIVE_ESB_VAL_Q) +#define XIVE_ESB_OFF XIVE_ESB_VAL_Q + +static uint8_t spapr_xive_pq_get (sPAPRXive *xive,uint32_t lisn) +{ +uint32_t byte = lisn /4 ; +uint32_t bit = (lisn %4 ) *2 ; + +assert (byte < xive->sbe_size); + +return (xive->sbe[byte] >> bit) &0x3 ; +} + +static uint8_t spapr_xive_pq_set (sPAPRXive *xive,uint32_t lisn,uint8_t pq) +{ +uint32_t byte = lisn /4 ; +uint32_t bit = (lisn %4 ) *2 ; +uint8_t old, new; + +assert (byte < xive->sbe_size); + + old = xive->sbe[byte]; + + new = xive->sbe[byte] & ~(0x3 << bit); + new |= (pq &0x3 ) << bit; + + xive->sbe[byte] = new; + +return (old >> bit) &0x3 ; +} + +static bool spapr_xive_pq_eoi (sPAPRXive *xive,uint32_t lisn) +{ +uint8_t old_pq =spapr_xive_pq_get (xive, lisn); + +switch (old_pq) { +case XIVE_ESB_RESET : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_RESET ); +return false; +case XIVE_ESB_PENDING : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_RESET ); +return false; +case XIVE_ESB_QUEUED : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_PENDING ); +return true; +case XIVE_ESB_OFF : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_OFF ); +return false; +default : +g_assert_not_reached (); + } +} + +/* +* Returns whether the event notification should be forwarded to the +* IVE for routing. */ +static bool spapr_xive_pq_trigger (sPAPRXive *xive,uint32_t lisn) +{ +uint8_t old_pq =spapr_xive_pq_get (xive, lisn); +switch (old_pq) { +case XIVE_ESB_RESET : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_PENDING ); +return true; +case XIVE_ESB_PENDING : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_QUEUED ); +return false; +case XIVE_ESB_QUEUED : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_QUEUED ); +return false; +case XIVE_ESB_OFF : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_OFF ); +return false; +default : +g_assert_not_reached (); + } +} + +/* +* XIVE Interrupt Source MMIOs +*/ + +/* +* Some HW use a separate page for trigger. We only support the case +* in which the trigger can be done in the same page as the EOI. +*/ +static uint64_t spapr_xive_esb_read (void *opaque,hwaddr addr,unsigned size) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); +uint32_t offset = addr &0xF00 ; +uint32_t lisn = addr >>ESB_SHIFT ; +uint64_t ret =-1 ; + +switch (offset) { +case XIVE_ESB_LOAD_EOI : +/* +* EOI on load is not used anymore as we now advertise +* XIVE_ESB_STORE_EOI support for the interrupt sources +*/ + ret =spapr_xive_pq_eoi (xive, lisn); +break ; + +case XIVE_ESB_GET : + ret =spapr_xive_pq_get (xive, lisn); +break ; + +case XIVE_ESB_SET_PQ_00 : +case XIVE_ESB_SET_PQ_01 : +case XIVE_ESB_SET_PQ_10 : +case XIVE_ESB_SET_PQ_11 : + ret =spapr_xive_pq_set (xive, lisn, (offset >>8 ) &0x3 ); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid ESB addr %d\n" , offset); + } + +return ret; +} + +static void spapr_xive_esb_write (void *opaque,hwaddr addr, +uint64_t value,unsigned size) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); +uint32_t offset = addr &0xF00 ; +uint32_t lisn = addr >>ESB_SHIFT ; +bool notify = false; + +switch (offset) { +case 0 : + notify =spapr_xive_pq_trigger (xive, lisn); +break ; +case XIVE_ESB_STORE_EOI : +/* If the Q bit is set, we should forward a new source event +* notification +*/ + notify =spapr_xive_pq_eoi (xive, lisn); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid ESB write addr %d\n" , + offset); +return ; + } + +/* Forward the source event notification for routing */ +if (notify) { +spapr_xive_irq (xive, lisn); + } +} + +static const MemoryRegionOps spapr_xive_esb_ops = { + .read = spapr_xive_esb_read, + .write = spapr_xive_esb_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =8 , + .max_access_size =8 , + }, + .impl = { + .min_access_size =8 , + .max_access_size =8 , + }, +}; + +static void spapr_xive_source_set_irq (void *opaque,int lisn,int val) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); +bool notify = false; + +if (val) { + notify =spapr_xive_pq_trigger (xive, lisn); + } + +/* Forward the source event notification for routing */ +if (notify) { +spapr_xive_irq (xive, lisn); + } +} + +/* +* Main XIVE object +*/ void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) {int i;for (i =0 ; i < xive->nr_irqs; i++) {XiveIVE *ive = &xive->ivt[i]; +uint8_t pq;if (!(ive->w &IVE_VALID )) {continue ; } -monitor_printf (mon," %4x %s %08x %08x\n" , i, + pq =spapr_xive_pq_get (xive, i); + +monitor_printf (mon," %4x %s %c%c %08x %08x\n" , i, ive->w &IVE_MASKED ?"M" :" " , + pq &XIVE_ESB_VAL_P ?'P' :'-' , + pq &XIVE_ESB_VAL_Q ?'Q' :'-' , (int )GETFIELD (IVE_EQ_INDEX , ive->w), (int )GETFIELD (IVE_EQ_DATA , ive->w)); }@@ -52,6 +281,9 @@ static void spapr_xive_reset(DeviceState *dev) ive->w |=IVE_MASKED ; } } + +/* SBEs are initialized to 0b01 which corresponds to "ints off" */ +memset (xive->sbe,0x55 , xive->sbe_size); }static void spapr_xive_realize (DeviceState *dev,Error **errp)@@ -65,6 +297,23 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)/* Allocate the IVT (Interrupt Virtualization Table) */ xive->ivt =g_new0 (XiveIVE, xive->nr_irqs); + +/* QEMU IRQs */ + xive->qirqs =qemu_allocate_irqs (spapr_xive_source_set_irq, xive, + xive->nr_irqs); + +/* Allocate SBEs (State Bit Entry). 2 bits, so 4 entries per byte */ + xive->sbe_size =DIV_ROUND_UP (xive->nr_irqs,4 ); + xive->sbe =g_malloc0 (xive->sbe_size); + +/* VC BAR. Use address of chip 0 to install the ESB memory region +* for *all* interrupt sources */ + xive->esb_base = (P9_MMIO_BASE |VC_BAR_DEFAULT ); + +memory_region_init_io (&xive->esb_iomem,OBJECT (xive), + &spapr_xive_esb_ops, xive,"xive.esb" , + (1ull <<ESB_SHIFT ) * xive->nr_irqs); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &xive->esb_iomem); }static const VMStateDescription vmstate_spapr_xive_ive = {@@ -92,6 +341,7 @@ static const VMStateDescription vmstate_spapr_xive = { VMSTATE_UINT32_EQUAL(nr_irqs, sPAPRXive, NULL), VMSTATE_STRUCT_VARRAY_UINT32(ivt, sPAPRXive, nr_irqs, 1, vmstate_spapr_xive_ive, XiveIVE), + VMSTATE_VBUFFER_UINT32(sbe, sPAPRXive, 1, NULL, sbe_size),VMSTATE_END_OF_LIST () }, };hw/intc/xive-internal.h +10
-0@@ -16,6 +16,16 @@#define SETFIELD (m, v, val) \ (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m))) +/* +* XIVE MMIO regions +*/ +#define P9_MMIO_BASE 0x006000000000000ull + +/* VC BAR contains set translations for the ESBs and the EQs. */ +#define VC_BAR_DEFAULT 0x10000000000ull +#define VC_BAR_SIZE 0x08000000000ull +#define ESB_SHIFT 16/* One 64k page. OPAL has two */ +/* IVE/EAS * * One per interrupt source. Targets that interrupt to a given EQ include/hw/ppc/spapr_xive.h +9
-0@@ -24,8 +24,17 @@ struct sPAPRXive {/* Properties */ uint32_t nr_irqs; +/* IRQ */ +qemu_irq *qirqs; +/* XIVE internal tables */ XiveIVE *ivt; +uint8_t *sbe; +uint32_t sbe_size; + +/* ESB memory region */ +hwaddr esb_base; +MemoryRegion esb_iomem; };bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn);
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to David GibsonQuoted 28 lines · David Gibson
Quoted 27 lines · Cédric Le Goater
With the POWER9 processor comes a new interrupt controller called XIVE. It is composed of three sub-engines :
- Interrupt Virtualization Source Engine (IVSE). These are in PHBs, in the main controller for the IPIS and in the PSI host bridge. They are configured to feed the IVRE with events.
- Interrupt Virtualization Routing Engine (IVRE). Their job is to match an event source with a Notification Virtualization Target (NVT), a priority and an Event Queue (EQ) to determine if a Virtual Processor can handle the event.
- Interrupt Virtualization Presentation Engine (IVPE). It maintains the interrupt state of each hardware thread and present the notification as an external exception.
Each of the engines uses a set of internal tables to redirect exceptions from event sources to CPU threads. The first table we introduce is the Interrupt Virtualization Entry (IVE) table, part of the virtualization engine in charge of routing events. It associates event sources (IRQ numbers) to event queues which will forward, or not, the event notification to the presentation controller.
The XIVE model is designed to make use of the full range of the IRQ number space and does not use an offset like the XICS mode does. Hence, the IVE table is directly indexed by the IRQ number.
Quoted 6 lines
Quoted 1 line
Signed-off-by Cédric Le Goater <[email protected]>As you've suggested in yourself, I think we might need to more explicitly model the different components of the XIVE system. As part of that, I think you need to be clearer in this base skeleton about exactly what component your XIVE object represents.
ok. The base skeleton is the IVRE, the central engine handling the routing.
Quoted 1 line
If the answer is "the overall thing"
Yes, it is more or less that currently.
The sPAPRXive object models the source engine and the routing engine in one object.
I have merged these for simplicity and because the interrupt controller has an internal source for the interrupts of the "IPI" type, which are used for the CPU IPIs but also for other generic interrupts, like the OpenCAPI ones. The XIVE sPAPR interface is also much simpler than the baremetal one, all the tables are maintained in the hypervisor, so this choice made some sense.
But since, I have started the PowerNV model and I am duplicating a lot of code to handle the triggering and the MMIOs in the different sources. So I am not convinced anymore. Nevertheless, the overall routing logic is the same even if some the tables are not located in QEMU anymore, but in the machine memory.
The sPAPRXiveNVT models some of the CPU presenter engine. It holds the virtual CPU interrupt states when not dispatched on a real HW thread. Real world is more complex. There are "CAM" lines in the HW threads which are compared to find a matching candidate. But I don't think we need to anything more complex than today unless we want to support KVM under TCG ...
Quoted 3 lines
I suspect that's not what you
want - I had one of those for XICs which proved to be a mistake (eventually replaced by the XICSFabric interface).
The XICSFabric would be the main Xive object. The interface between the sources and the routing engine is hidden in sPAPR, we can use a simple function call :
spapr_xive_irq(pnv->xive, irq);
we could get rid of the qirqs but they are required for XICS.
PowerNV uses MMIOs to notify an event and it makes the modeling somewhat easier. Each controller model has a notify port address register on which a interrupt number is written to forward an event to the routing engine. So it is a simple store.
I don't know why there is a different notify port address per source, may be for extra filtering at the routing engine level.
Quoted 3 lines
Changing the model later isn't impossible, but doing so without breaking migration can be a real pain, so I think it's worth a reasonable effort to try and get it right initially.
I completely agree.
This is why I have started the PnvXive model to challenge the current PAPR design. I have hacked a bunch of patches for XIVE, LPC, PSI, OCC and basic PPC support which boot a PowerNV P9 up to petitboot. It would look better with a source object, but the location of the PQ bits is a bit problematic. It highly depends on the controller. The main controller uses tables in the hypervisor memory. The PSIHB controller has its own bits. I suppose it is the same for PHB4. I need to take a closer look at how we could have a common source object.
The most important part is KVM support and how we expose the MMIO region. We need to make progress on that topic.
Thanks,
C.
Quoted 298 lines
Quoted 297 lines
---
Changes since v1 :
- used
g_new0instead ofg_malloc0
- removedVMSTATE_STRUCT_VARRAY_UINT32_ALLOC
- introduced a device reset handler. the object needs to be parented to sysbus when created.
- renamedspapr_xive_irq_settospapr_xive_irq_enable
- renamedspapr_xive_irq_unsettospapr_xive_irq_disable
- moved thePPC_BITmacros undertarget/ppc/cpu.h
- shrinked file copyright headerdefault-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/spapr_xive.c | 156 ++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 41 ++++++++++ include/hw/ppc/spapr_xive.h | 35 +++++++++ 5 files changed, 234 insertions(+) create mode 100644 hw/intc/spapr_xive.c create mode 100644 hw/intc/xive-internal.h create mode 100644 include/hw/ppc/spapr_xive.hdefault-configs/ppc64-softmmu.mak +1
-0@@ -56,6 +56,7 @@ CONFIG_SM501=y CONFIG_XICS=$(CONFIG_PSERIES) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM)) +CONFIG_XIVE_SPAPR=$(CONFIG_PSERIES) # For PReP CONFIG_SERIAL_ISA=y CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -35,6 +35,7 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o +obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o obj-$(CONFIG_POWERNV) += xics_pnv.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/spapr_xive.c new file +156
-0@@ -0,0 +1,156 @@ +/* +* QEMU PowerPC sPAPR XIVE interrupt controller model +* +* Copyright (c) 2017, IBM Corporation. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "target/ppc/cpu.h" +#include "sysemu/cpus.h" +#include "sysemu/dma.h" +#include "monitor/monitor.h" +#include "hw/ppc/spapr_xive.h" + +#include "xive-internal.h" + +/* +* Main XIVE object +*/ + +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) +{ +int i; + +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; + +if (!(ive->w &IVE_VALID )) { +continue ; + } + +monitor_printf (mon," %4x %s %08x %08x\n" , i, + ive->w &IVE_MASKED ?"M" :" " , + (int )GETFIELD (IVE_EQ_INDEX , ive->w), + (int )GETFIELD (IVE_EQ_DATA , ive->w)); + } +} + +static void spapr_xive_reset (DeviceState *dev) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); +int i; + +/* Mask all valid IVEs in the IRQ number space. */ +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; +if (ive->w &IVE_VALID ) { + ive->w |=IVE_MASKED ; + } + } +} + +static void spapr_xive_realize (DeviceState *dev,Error **errp) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); + +if (!xive->nr_irqs) { +error_setg (errp,"Number of interrupt needs to be greater 0" ); +return ; + } + +/* Allocate the IVT (Interrupt Virtualization Table) */ + xive->ivt =g_new0 (XiveIVE, xive->nr_irqs); +} + +static const VMStateDescription vmstate_spapr_xive_ive = { + .name =TYPE_SPAPR_XIVE "/ive" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (w, XiveIVE), +VMSTATE_END_OF_LIST () + }, +}; + +static bool vmstate_spapr_xive_needed (void *opaque) +{ +/* TODO check machine XIVE support */ +return true; +} + +static const VMStateDescription vmstate_spapr_xive = { + .name =TYPE_SPAPR_XIVE , + .version_id =1 , + .minimum_version_id =1 , + .needed = vmstate_spapr_xive_needed, + .fields = (VMStateField []) { +VMSTATE_UINT32_EQUAL (nr_irqs, sPAPRXive,NULL ), +VMSTATE_STRUCT_VARRAY_UINT32 (ivt, sPAPRXive, nr_irqs,1 , + vmstate_spapr_xive_ive, XiveIVE), +VMSTATE_END_OF_LIST () + }, +}; + +static Property spapr_xive_properties[] = { +DEFINE_PROP_UINT32 ("nr-irqs" , sPAPRXive, nr_irqs,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void spapr_xive_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = spapr_xive_realize; + dc->reset = spapr_xive_reset; + dc->props = spapr_xive_properties; + dc->desc ="sPAPR XIVE interrupt controller" ; + dc->vmsd = &vmstate_spapr_xive; +} + +static const TypeInfo spapr_xive_info = { + .name =TYPE_SPAPR_XIVE , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (sPAPRXive), + .class_init = spapr_xive_class_init, +}; + +static void spapr_xive_register_types (void ) +{ +type_register_static (&spapr_xive_info); +} + +type_init (spapr_xive_register_types) + +XiveIVE *spapr_xive_get_ive(sPAPRXive *xive, uint32_t lisn) +{ +return lisn < xive->nr_irqs ? &xive->ivt[lisn] :NULL ; +} + +bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) { +return false; + } + + ive->w |=IVE_VALID ; +return true; +} + +bool spapr_xive_irq_disable (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) { +return false; + } + + ive->w &= ~IVE_VALID ; +return true; +}hw/intc/xive-internal.h new file +41
-0@@ -0,0 +1,41 @@ +/* +* QEMU PowerPC XIVE interrupt controller model +* +* Copyright (c) 2016-2017, IBM Corporation. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +*/ + +#ifndef _INTC_XIVE_INTERNAL_H +#define _INTC_XIVE_INTERNAL_H + +/* Utilities to manipulate these (originaly from OPAL) */ +#define MASK_TO_LSH (m) (__builtin_ffsl(m) - 1) +#define GETFIELD (m, v) (((v) & (m)) >> MASK_TO_LSH(m)) +#define SETFIELD (m, v, val) \ + (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m))) + +/* IVE/EAS +* +* One per interrupt source. Targets that interrupt to a given EQ +* and provides the corresponding logical interrupt number (EQ data) +* +* We also map this structure to the escalation descriptor inside +* an EQ, though in that case the valid and masked bits are not used. +*/ +typedef struct XiveIVE { +/* Use a single 64-bit definition to make it easier to +* perform atomic updates +*/ +uint64_t w; +#define IVE_VALID PPC_BIT(0) +#define IVE_EQ_BLOCK PPC_BITMASK(4, 7)/* Destination EQ block# */ +#define IVE_EQ_INDEX PPC_BITMASK(8, 31)/* Destination EQ index */ +#define IVE_MASKED PPC_BIT(32)/* Masked */ +#define IVE_EQ_DATA PPC_BITMASK(33, 63)/* Data written to the EQ */ +}XiveIVE ; + +XiveIVE *spapr_xive_get_ive (sPAPRXive *xive,uint32_t lisn); + +#endif /* _INTC_XIVE_INTERNAL_H */ include/hw/ppc/spapr_xive.h new file +35
-0@@ -0,0 +1,35 @@ +/* +* QEMU PowerPC sPAPR XIVE interrupt controller model +* +* Copyright (c) 2017, IBM Corporation. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +*/ + +#ifndef PPC_SPAPR_XIVE_H +#define PPC_SPAPR_XIVE_H + +#include <hw/sysbus.h> + +typedef struct sPAPRXive sPAPRXive ; +typedef struct XiveIVE XiveIVE ; + +#define TYPE_SPAPR_XIVE "spapr-xive" +#define SPAPR_XIVE (obj) OBJECT_CHECK(sPAPRXive, (obj), TYPE_SPAPR_XIVE) + +struct sPAPRXive { +SysBusDevice parent; + +/* Properties */ +uint32_t nr_irqs; + +/* XIVE internal tables */ +XiveIVE *ivt; +}; + +bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn); +bool spapr_xive_irq_disable (sPAPRXive *xive,uint32_t lisn); +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon); + +#endif /* PPC_SPAPR_XIVE_H */
Re: [Qemu-devel] [PATCH v2 03/19] spapr: introduce the XIVE interrupt sources
In reply to David GibsonQuoted 18 lines · David Gibson
Quoted 11 lines · Cédric Le Goater
Each XIVE interrupt source is associated with a two bit state machine called an Event State Buffer (ESB) : the first bit "P" means that an interrupt is "pending" and waiting for an EOI and the bit "Q" (queued) means a new interrupt was triggered while another was still pending.
When an event is triggered, the associated interrupt state bits are fetched and modified and forwarded to the virtualization engine of the controller doing the routing. These can also be controlled by MMIO, to trigger events or turn off the sources for instance. See code for more details on the states and transitions.
Quoted 5 lines
The MMIO space for the ESBs is 512GB large on the bare-metal system (PowerNV) and the BAR depends on the chip id. In our model for the sPAPR machine, we choose to only map the sub-region for the provisioned IRQ numbers and to use the mapping address of chip 0 of a real system.
Quoted 3 lines
I think we probably want a device property to make the virtualized base address arbitrary. It's fine for it to default to the chip 0 base, but that'll make it easier to adapt if we need to later on.
yes. We can add a "bar" property for this purpose like for some of the pnv models
Quoted 3 lines
As noted in the followup messages, I think you're going to want to move this stuff from the current xive object into a "block of sources" object.
yes. I have now a new Xive source model for the POWER9 PSIHB controller. It should help to find common grounds. This is what I added to support XIVE in the current PSIHB:
+ /* P9 */ + MemoryRegion esb_iomem; + uint8_t sbe[4]; /* enough for 13 P&Q bits */ + uint32_t ivt_offset;
The ESB region mapping is handled at the machine level as it depends on the chip id.
The 'ivt_offset' is only used to forward the event notification to the routine engine :
+static void pnv_psi_notify(PnvPsi *psi, uint32_t lisn) +{
+ uint64_t notif_port =
+ psi->regs[PSIHB_REG(PSIHB9_ESB_NOTIF_ADDR)];
+ bool valid = notif_port & PSIHB9_ESB_NOTIF_VALID; + uint64_t notify_addr = notif_port & ~PSIHB9_ESB_NOTIF_VALID; + uint32_t data = cpu_to_be32(psi->ivt_offset | lisn);
+
+ if (valid) {
+ cpu_physical_memory_write(notify_addr, &data, sizeof(data));
+ }
+}
So It really depends on the controller type. I think that could be a class handler.
Thanks,
C.
Quoted 384 lines
Apart from that this looks pretty sound.
Quoted 381 lines
In the real world, each source may have different characteristics depending on the revision of a controller or the CPU. Early systems had two different MMIO pages for trigger and for EOI. We choose to use the same characteristics for all sources to simplify the model. The minimum CPU level for XIVE exploitation mode will be DD2.X as it has full support.
The OS will obtain the address of the MMIO page of the ESB entry associated with a source and its characteristic using the
H_INT_GET_SOURCE_INFOhcall. This will be addressed in the patch introducing the hcalls.The
spapr_xive_irq()routine in charge of triggering the CPU interrupt line will be filled later on.Signed-off-by Cédric Le Goater <[email protected]>---
Changes since v1:
- merged in the same patch the
qemu_irqhandlers
- reworked the event notification logic of theqemu_irqhandlers.
- introducedXIVE_ESB_STORE_EOIsupport
- removed 'esb_shift' field
- removed a useless check on the validity of the IVE in the memory region handlers.
- fixedspapr_xive_pq_trigger()to return true whenXIVE_ESB_QUEUEDis set
- removed the overall ESB memory region. We now have only one region for the provisioned sources.
- improved 'info pic' outputhw/intc/spapr_xive.c | 254 +++++++++++++++++++++++++++++++++++++++++++- hw/intc/xive-internal.h | 10 ++ include/hw/ppc/spapr_xive.h | 9 ++ 3 files changed, 271 insertions(+), 2 deletions(-)hw/intc/spapr_xive.c +252
-2@@ -18,23 +18,252 @@#include "xive-internal.h" +static void spapr_xive_irq (sPAPRXive *xive,int lisn) +{ + +} +/* -* Main XIVE object +* XIVE Interrupt Source +*/ + +/* +* "magic" Event State Buffer (ESB) MMIO offsets. +* +* Each interrupt source has a 2-bit state machine called ESB +* which can be controlled by MMIO. It's made of 2 bits, P and +* Q. P indicates that an interrupt is pending (has been sent +* to a queue and is waiting for an EOI). Q indicates that the +* interrupt has been triggered while pending. +* +* This acts as a coalescing mechanism in order to guarantee +* that a given interrupt only occurs at most once in a queue. +* +* When doing an EOI, the Q bit will indicate if the interrupt +* needs to be re-triggered. +* +* The following offsets into the ESB MMIO allow to read or +* manipulate the PQ bits. They must be used with an 8-bytes +* load instruction. They all return the previous state of the +* interrupt (atomically). +* +* Additionally, some ESB pages support doing an EOI via a +* store at 0 and some ESBs support doing a trigger via a +* separate trigger page. +*/ +#define XIVE_ESB_STORE_EOI 0x400/* Store */ +#define XIVE_ESB_LOAD_EOI 0x000/* Load */ +#define XIVE_ESB_GET 0x800/* Load */ +#define XIVE_ESB_SET_PQ_00 0xc00/* Load */ +#define XIVE_ESB_SET_PQ_01 0xd00/* Load */ +#define XIVE_ESB_SET_PQ_10 0xe00/* Load */ +#define XIVE_ESB_SET_PQ_11 0xf00/* Load */ + +#define XIVE_ESB_VAL_P 0x2 +#define XIVE_ESB_VAL_Q 0x1 + +#define XIVE_ESB_RESET 0x0 +#define XIVE_ESB_PENDING XIVE_ESB_VAL_P +#define XIVE_ESB_QUEUED (XIVE_ESB_VAL_P | XIVE_ESB_VAL_Q) +#define XIVE_ESB_OFF XIVE_ESB_VAL_Q + +static uint8_t spapr_xive_pq_get (sPAPRXive *xive,uint32_t lisn) +{ +uint32_t byte = lisn /4 ; +uint32_t bit = (lisn %4 ) *2 ; + +assert (byte < xive->sbe_size); + +return (xive->sbe[byte] >> bit) &0x3 ; +} + +static uint8_t spapr_xive_pq_set (sPAPRXive *xive,uint32_t lisn,uint8_t pq) +{ +uint32_t byte = lisn /4 ; +uint32_t bit = (lisn %4 ) *2 ; +uint8_t old, new; + +assert (byte < xive->sbe_size); + + old = xive->sbe[byte]; + + new = xive->sbe[byte] & ~(0x3 << bit); + new |= (pq &0x3 ) << bit; + + xive->sbe[byte] = new; + +return (old >> bit) &0x3 ; +} + +static bool spapr_xive_pq_eoi (sPAPRXive *xive,uint32_t lisn) +{ +uint8_t old_pq =spapr_xive_pq_get (xive, lisn); + +switch (old_pq) { +case XIVE_ESB_RESET : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_RESET ); +return false; +case XIVE_ESB_PENDING : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_RESET ); +return false; +case XIVE_ESB_QUEUED : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_PENDING ); +return true; +case XIVE_ESB_OFF : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_OFF ); +return false; +default : +g_assert_not_reached (); + } +} + +/* +* Returns whether the event notification should be forwarded to the +* IVE for routing. */ +static bool spapr_xive_pq_trigger (sPAPRXive *xive,uint32_t lisn) +{ +uint8_t old_pq =spapr_xive_pq_get (xive, lisn); +switch (old_pq) { +case XIVE_ESB_RESET : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_PENDING ); +return true; +case XIVE_ESB_PENDING : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_QUEUED ); +return false; +case XIVE_ESB_QUEUED : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_QUEUED ); +return false; +case XIVE_ESB_OFF : +spapr_xive_pq_set (xive, lisn,XIVE_ESB_OFF ); +return false; +default : +g_assert_not_reached (); + } +} + +/* +* XIVE Interrupt Source MMIOs +*/ + +/* +* Some HW use a separate page for trigger. We only support the case +* in which the trigger can be done in the same page as the EOI. +*/ +static uint64_t spapr_xive_esb_read (void *opaque,hwaddr addr,unsigned size) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); +uint32_t offset = addr &0xF00 ; +uint32_t lisn = addr >>ESB_SHIFT ; +uint64_t ret =-1 ; + +switch (offset) { +case XIVE_ESB_LOAD_EOI : +/* +* EOI on load is not used anymore as we now advertise +* XIVE_ESB_STORE_EOI support for the interrupt sources +*/ + ret =spapr_xive_pq_eoi (xive, lisn); +break ; + +case XIVE_ESB_GET : + ret =spapr_xive_pq_get (xive, lisn); +break ; + +case XIVE_ESB_SET_PQ_00 : +case XIVE_ESB_SET_PQ_01 : +case XIVE_ESB_SET_PQ_10 : +case XIVE_ESB_SET_PQ_11 : + ret =spapr_xive_pq_set (xive, lisn, (offset >>8 ) &0x3 ); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid ESB addr %d\n" , offset); + } + +return ret; +} + +static void spapr_xive_esb_write (void *opaque,hwaddr addr, +uint64_t value,unsigned size) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); +uint32_t offset = addr &0xF00 ; +uint32_t lisn = addr >>ESB_SHIFT ; +bool notify = false; + +switch (offset) { +case 0 : + notify =spapr_xive_pq_trigger (xive, lisn); +break ; +case XIVE_ESB_STORE_EOI : +/* If the Q bit is set, we should forward a new source event +* notification +*/ + notify =spapr_xive_pq_eoi (xive, lisn); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR ,"XIVE: invalid ESB write addr %d\n" , + offset); +return ; + } + +/* Forward the source event notification for routing */ +if (notify) { +spapr_xive_irq (xive, lisn); + } +} + +static const MemoryRegionOps spapr_xive_esb_ops = { + .read = spapr_xive_esb_read, + .write = spapr_xive_esb_write, + .endianness =DEVICE_BIG_ENDIAN , + .valid = { + .min_access_size =8 , + .max_access_size =8 , + }, + .impl = { + .min_access_size =8 , + .max_access_size =8 , + }, +}; + +static void spapr_xive_source_set_irq (void *opaque,int lisn,int val) +{ +sPAPRXive *xive =SPAPR_XIVE (opaque); +bool notify = false; + +if (val) { + notify =spapr_xive_pq_trigger (xive, lisn); + } + +/* Forward the source event notification for routing */ +if (notify) { +spapr_xive_irq (xive, lisn); + } +} + +/* +* Main XIVE object +*/ void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) {int i;for (i =0 ; i < xive->nr_irqs; i++) {XiveIVE *ive = &xive->ivt[i]; +uint8_t pq;if (!(ive->w &IVE_VALID )) {continue ; } -monitor_printf (mon," %4x %s %08x %08x\n" , i, + pq =spapr_xive_pq_get (xive, i); + +monitor_printf (mon," %4x %s %c%c %08x %08x\n" , i, ive->w &IVE_MASKED ?"M" :" " , + pq &XIVE_ESB_VAL_P ?'P' :'-' , + pq &XIVE_ESB_VAL_Q ?'Q' :'-' , (int )GETFIELD (IVE_EQ_INDEX , ive->w), (int )GETFIELD (IVE_EQ_DATA , ive->w)); }@@ -52,6 +281,9 @@ static void spapr_xive_reset(DeviceState *dev) ive->w |=IVE_MASKED ; } } + +/* SBEs are initialized to 0b01 which corresponds to "ints off" */ +memset (xive->sbe,0x55 , xive->sbe_size); }static void spapr_xive_realize (DeviceState *dev,Error **errp)@@ -65,6 +297,23 @@ static void spapr_xive_realize(DeviceState *dev, Error **errp)/* Allocate the IVT (Interrupt Virtualization Table) */ xive->ivt =g_new0 (XiveIVE, xive->nr_irqs); + +/* QEMU IRQs */ + xive->qirqs =qemu_allocate_irqs (spapr_xive_source_set_irq, xive, + xive->nr_irqs); + +/* Allocate SBEs (State Bit Entry). 2 bits, so 4 entries per byte */ + xive->sbe_size =DIV_ROUND_UP (xive->nr_irqs,4 ); + xive->sbe =g_malloc0 (xive->sbe_size); + +/* VC BAR. Use address of chip 0 to install the ESB memory region +* for *all* interrupt sources */ + xive->esb_base = (P9_MMIO_BASE |VC_BAR_DEFAULT ); + +memory_region_init_io (&xive->esb_iomem,OBJECT (xive), + &spapr_xive_esb_ops, xive,"xive.esb" , + (1ull <<ESB_SHIFT ) * xive->nr_irqs); +sysbus_init_mmio (SYS_BUS_DEVICE (dev), &xive->esb_iomem); }static const VMStateDescription vmstate_spapr_xive_ive = {@@ -92,6 +341,7 @@ static const VMStateDescription vmstate_spapr_xive = { VMSTATE_UINT32_EQUAL(nr_irqs, sPAPRXive, NULL), VMSTATE_STRUCT_VARRAY_UINT32(ivt, sPAPRXive, nr_irqs, 1, vmstate_spapr_xive_ive, XiveIVE), + VMSTATE_VBUFFER_UINT32(sbe, sPAPRXive, 1, NULL, sbe_size),VMSTATE_END_OF_LIST () }, };hw/intc/xive-internal.h +10
-0@@ -16,6 +16,16 @@#define SETFIELD (m, v, val) \ (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m))) +/* +* XIVE MMIO regions +*/ +#define P9_MMIO_BASE 0x006000000000000ull + +/* VC BAR contains set translations for the ESBs and the EQs. */ +#define VC_BAR_DEFAULT 0x10000000000ull +#define VC_BAR_SIZE 0x08000000000ull +#define ESB_SHIFT 16/* One 64k page. OPAL has two */ +/* IVE/EAS * * One per interrupt source. Targets that interrupt to a given EQ include/hw/ppc/spapr_xive.h +9
-0@@ -24,8 +24,17 @@ struct sPAPRXive {/* Properties */ uint32_t nr_irqs; +/* IRQ */ +qemu_irq *qirqs; +/* XIVE internal tables */ XiveIVE *ivt; +uint8_t *sbe; +uint32_t sbe_size; + +/* ESB memory region */ +hwaddr esb_base; +MemoryRegion esb_iomem; };bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn);
Re: [Qemu-devel] [PATCH v2 03/19] spapr: introduce the XIVE interrupt sources
Quoted 19 lines · Cédric Le Goater
Quoted 18 lines · David Gibson
Quoted 16 lines · Cédric Le Goater
Each XIVE interrupt source is associated with a two bit state machine called an Event State Buffer (ESB) : the first bit "P" means that an interrupt is "pending" and waiting for an EOI and the bit "Q" (queued) means a new interrupt was triggered while another was still pending.
When an event is triggered, the associated interrupt state bits are fetched and modified and forwarded to the virtualization engine of the controller doing the routing. These can also be controlled by MMIO, to trigger events or turn off the sources for instance. See code for more details on the states and transitions.
The MMIO space for the ESBs is 512GB large on the bare-metal system (PowerNV) and the BAR depends on the chip id. In our model for the sPAPR machine, we choose to only map the sub-region for the provisioned IRQ numbers and to use the mapping address of chip 0 of a real system.
Quoted 10 lines
Quoted 3 lines
I think we probably want a device property to make the virtualized base address arbitrary. It's fine for it to default to the chip 0 base, but that'll make it easier to adapt if we need to later on.
yes. We can add a "bar" property for this purpose like for some of the pnv models
Quoted 3 lines
As noted in the followup messages, I think you're going to want to move this stuff from the current xive object into a "block of sources" object.
I have (re)introduced a XiveSource object. Only a single instance, and under the sPAPRXive object (because it is easier to create). Adding a source list should not be too problematic if needed.
So the XiveSource is generic and I hope to be able to do the same for the presenter.
Just like for XICS, I am also adding a :
typedef struct XiveFabricClass {
InterfaceClass parent;
void (*notify)(XiveFabric *xive, int lisn);
} XiveFabricClass;which we can use for both the pnv and pseries machines, but the fabric is not the machine itself, it is the Xive routing engine, an object below.
C.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to David GibsonQuoted 6 lines · David Gibson
As you've suggested in yourself, I think we might need to more explicitly model the different components of the XIVE system. As part of that, I think you need to be clearer in this base skeleton about exactly what component your XIVE object represents.
Quoted 7 lines
If the answer is "the overall thing" I suspect that's not what you want - I had one of those for XICs which proved to be a mistake (eventually replaced by the XICSFabric interface).
Changing the model later isn't impossible, but doing so without breaking migration can be a real pain, so I think it's worth a reasonable effort to try and get it right initially.
Note: we do need to speed things up a bit, as having exploitation mode in KVM will significantly help with IPI performance among other things.
I'm about ready to do the KVM bits. The one thing we need to discuss and figure a good design for is how we map all those interrupt control pages into qemu.
Each interrupt (either PCIe pass-through or the "generic XIVE IPIs" which are used for guest IPIs and for vio/virtio/emulated interrupts) comes with a "control page" (ESB page) which needs to be mapped into the guest, and the generic IPIs also come with a trigger page which needs to be mapped into the guest for guest IPIs or OpenCAPI interrupts, or just qemu for emulated devices.
Now that can be thousands of these critters. I certainly don't want to create thousands of VMAs in qemu and even less thousands of memory regions in KVM.
So we need some kind of mechanism by wich a single large VMA gets mmap'ed into qemu (or maybe a couple of these, but not too many) and the interrupt pages can be assigned to slots in there and demand faulted.
For the generic interrupts, this can probably be covered by KVM, adding some arch ioctls for allocating IPIs and mmap'ing that region etc...
For pass-through, it's trickier, we don't want to mmap each irqfd individually for the above reason, so we want to "link" them to KVM. We don't want to allow qemu to take control of any arbitrary interrupt in the system though, so it has to related to the ownership of the irqfd coming from vfio.
OpenCAPI I suspect will be its own can of worms...
Also, have we decided how the process of switching between XICS and XIVE will work vs. CAS ? And how that will interact with KVM ? I was thinking the kernel would implement a different KVM device type, ie the "emulated XICS" would remain KVM_DEV_TYPE_XICS and XIVE would be KVM_DEV_TYPE_XIVE.
Cheers,
Ben.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 22 lines · Benjamin Herrenschmidt
Quoted 6 lines · David Gibson
As you've suggested in yourself, I think we might need to more explicitly model the different components of the XIVE system. As part of that, I think you need to be clearer in this base skeleton about exactly what component your XIVE object represents.
Quoted 7 lines
If the answer is "the overall thing" I suspect that's not what you want - I had one of those for XICs which proved to be a mistake (eventually replaced by the XICSFabric interface).
Changing the model later isn't impossible, but doing so without breaking migration can be a real pain, so I think it's worth a reasonable effort to try and get it right initially.
Note: we do need to speed things up a bit, as having exploitation mode in KVM will significantly help with IPI performance among other things.
I'm about ready to do the KVM bits. The one thing we need to discuss and figure a good design for is how we map all those interrupt control pages into qemu.
Quoted 6 lines
Each interrupt (either PCIe pass-through or the "generic XIVE IPIs" which are used for guest IPIs and for vio/virtio/emulated interrupts) comes with a "control page" (ESB page) which needs to be mapped into the guest, and the generic IPIs also come with a trigger page which needs to be mapped into the guest for guest IPIs or OpenCAPI interrupts, or just qemu for emulated devices.
what about the OS TIMA page ? Do we trap the accesses in QEMU and forward them to KVM ? or do we use a similar mechanism.
Quoted 3 lines
Now that can be thousands of these critters. I certainly don't want to create thousands of VMAs in qemu and even less thousands of memory regions in KVM.
we can provision one mapping per kvmppc_xive_src_block maybe ?
Quoted 4 lines
So we need some kind of mechanism by wich a single large VMA gets mmap'ed into qemu (or maybe a couple of these, but not too many) and the interrupt pages can be assigned to slots in there and demand faulted.
Frederic has started to put in place a similar mecanism for OpenCAPI.
Quoted 2 lines
For the generic interrupts, this can probably be covered by KVM, adding some arch ioctls for allocating IPIs and mmap'ing that region etc...
The KVM device has a ioctl handler :
struct kvm_device_ops {
long (*ioctl)(struct kvm_device *dev, unsigned int ioctl,
unsigned long arg);
};So a KVM device for the XIVE interrupt controller can implement a couple of extra calls for its need, like getting the VMA addresses, etc
Quoted 10 lines
For pass-through, it's trickier, we don't want to mmap each irqfd individually for the above reason, so we want to "link" them to KVM. We don't want to allow qemu to take control of any arbitrary interrupt in the system though, so it has to related to the ownership of the irqfd coming from vfio.
OpenCAPI I suspect will be its own can of worms...
Also, have we decided how the process of switching between XICS and XIVE will work vs. CAS ?
That's how it is described in the architecture. The current choice is to create both XICS and XIVE objects and choose at CAS which one to use. It relies today on the capability of the pseries machine to allocate IRQ numbers for both interrupt controller backends. These patches have been merged in QEMU.
A change of interrupt mode results in a reset. The device tree is populated accordingly and the ICPs are switched for the model in use.
Quoted 1 line
And how that will interact with KVM ?
I expect we will do the same, which is to create two KVM devices to be able to handle both interrupt controller backends depending on the mode negotiated by the guest.
Quoted 4 lines
I was
thinking the kernel would implement a different KVM device type, ie the "emulated XICS" would remainKVM_DEV_TYPE_XICSand XIVE would beKVM_DEV_TYPE_XIVE.
yes. it makes sense. The new device will have a lot in common with the KVM_DEV_TYPE_XICS using kvm_xive_ops.
C.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 51 lines · Cédric Le Goater
Quoted 22 lines · Benjamin Herrenschmidt
Quoted 6 lines · David Gibson
As you've suggested in yourself, I think we might need to more explicitly model the different components of the XIVE system. As part of that, I think you need to be clearer in this base skeleton about exactly what component your XIVE object represents.
Quoted 7 lines
If the answer is "the overall thing" I suspect that's not what you want - I had one of those for XICs which proved to be a mistake (eventually replaced by the XICSFabric interface).
Changing the model later isn't impossible, but doing so without breaking migration can be a real pain, so I think it's worth a reasonable effort to try and get it right initially.
Note: we do need to speed things up a bit, as having exploitation mode in KVM will significantly help with IPI performance among other things.
I'm about ready to do the KVM bits. The one thing we need to discuss and figure a good design for is how we map all those interrupt control pages into qemu.
Quoted 6 lines
Each interrupt (either PCIe pass-through or the "generic XIVE IPIs" which are used for guest IPIs and for vio/virtio/emulated interrupts) comes with a "control page" (ESB page) which needs to be mapped into the guest, and the generic IPIs also come with a trigger page which needs to be mapped into the guest for guest IPIs or OpenCAPI interrupts, or just qemu for emulated devices.
what about the OS TIMA page ? Do we trap the accesses in QEMU and forward them to KVM ? or do we use a similar mechanism.
Quoted 3 lines
Now that can be thousands of these critters. I certainly don't want to create thousands of VMAs in qemu and even less thousands of memory regions in KVM.
we can provision one mapping per
kvmppc_xive_src_blockmaybe ?Quoted 4 lines
So we need some kind of mechanism by wich a single large VMA gets mmap'ed into qemu (or maybe a couple of these, but not too many) and the interrupt pages can be assigned to slots in there and demand faulted.
Frederic has started to put in place a similar mecanism for OpenCAPI.
Quoted 2 lines
For the generic interrupts, this can probably be covered by KVM, adding some arch ioctls for allocating IPIs and mmap'ing that region etc...
The KVM device has a ioctl handler :
Quoted 8 lines
struct kvm_device_ops { long (*ioctl)(struct kvm_device *dev, unsigned int ioctl, unsigned long arg); };So a KVM device for the XIVE interrupt controller can implement a couple of extra calls for its need, like getting the VMA addresses, etc
or use set/get_attr.
I wonder if it would be possible to add a 'mmap' ops to kvm_device_fops for the KVM_DEV_TYPE_XIVE device.
C.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Cédric Le GoaterQuoted 30 lines · Cédric Le Goater
Quoted 22 lines · Benjamin Herrenschmidt
Quoted 6 lines · David Gibson
As you've suggested in yourself, I think we might need to more explicitly model the different components of the XIVE system. As part of that, I think you need to be clearer in this base skeleton about exactly what component your XIVE object represents.
Quoted 7 lines
If the answer is "the overall thing" I suspect that's not what you want - I had one of those for XICs which proved to be a mistake (eventually replaced by the XICSFabric interface).
Changing the model later isn't impossible, but doing so without breaking migration can be a real pain, so I think it's worth a reasonable effort to try and get it right initially.
Note: we do need to speed things up a bit, as having exploitation mode in KVM will significantly help with IPI performance among other things.
I'm about ready to do the KVM bits. The one thing we need to discuss and figure a good design for is how we map all those interrupt control pages into qemu.
Quoted 6 lines
Each interrupt (either PCIe pass-through or the "generic XIVE IPIs" which are used for guest IPIs and for vio/virtio/emulated interrupts) comes with a "control page" (ESB page) which needs to be mapped into the guest, and the generic IPIs also come with a trigger page which needs to be mapped into the guest for guest IPIs or OpenCAPI interrupts, or just qemu for emulated devices.
Quoted 2 lines
what about the OS TIMA page ? Do we trap the accesses in QEMU and forward them to KVM ? or do we use a similar mechanism.
No, no, we'll have an mmap facility for it in kvm but it worries me less as there's only one of these and there's little damage qemu can do having access to it :)
Quoted 6 lines
Quoted 4 lines
Now that can be thousands of these critters. I certainly don't want to create thousands of VMAs in qemu and even less thousands of memory regions in KVM.
we can provision one mapping per
kvmppc_xive_src_blockmaybe ?
Maybe. Last I looked KVM walk of memory regions was linear though. Mind you it's not a huge deal if the guest RAM is always in the first entries.
Quoted 6 lines
Quoted 4 lines
So we need some kind of mechanism by wich a single large VMA gets mmap'ed into qemu (or maybe a couple of these, but not too many) and the interrupt pages can be assigned to slots in there and demand faulted.
Frederic has started to put in place a similar mecanism for OpenCAPI.
I know, though he made it rather OpenCAPI specific which is going to be "interesting" when it comes to virtualizing OpenCAPI...
Quoted 31 lines
Quoted 2 lines
For the generic interrupts, this can probably be covered by KVM, adding some arch ioctls for allocating IPIs and mmap'ing that region etc...
The KVM device has a ioctl handler :
struct kvm_device_ops { long (*ioctl)(struct kvm_device *dev, unsigned int ioctl, unsigned long arg); };So a KVM device for the XIVE interrupt controller can implement a couple of extra calls for its need, like getting the VMA addresses, etc
Quoted 10 lines
For pass-through, it's trickier, we don't want to mmap each irqfd individually for the above reason, so we want to "link" them to KVM. We don't want to allow qemu to take control of any arbitrary interrupt in the system though, so it has to related to the ownership of the irqfd coming from vfio.
OpenCAPI I suspect will be its own can of worms...
Also, have we decided how the process of switching between XICS and XIVE will work vs. CAS ?
That's how it is described in the architecture. The current choice is to create both XICS and XIVE objects and choose at CAS which one to use. It relies today on the capability of the pseries machine to allocate IRQ numbers for both interrupt controller backends. These patches have been merged in QEMU.
Quoted 3 lines
A change of interrupt mode results in a reset. The device tree is populated accordingly and the ICPs are switched for the model in use.
For KVM we need to only instanciate one of them though.
Quoted 5 lines
Quoted 1 line
And how that will interact with KVM ?
I expect we will do the same, which is to create two KVM devices to be able to handle both interrupt controller backends depending on the mode negotiated by the guest.
That will be an ungodly mess, I'd rather we only instanciate the right one.
Quoted 7 lines
Quoted 4 lines
I was
thinking the kernel would implement a different KVM device type, ie the "emulated XICS" would remainKVM_DEV_TYPE_XICSand XIVE would beKVM_DEV_TYPE_XIVE.yes. it makes sense. The new device will have a lot in common with the
KVM_DEV_TYPE_XICSusingkvm_xive_ops.
Ben.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
Also, have we decided how the process of switching between XICS and XIVE will work vs. CAS ?
That's how it is described in the architecture. The current choice is to create both XICS and XIVE objects and choose at CAS which one to use. It relies today on the capability of the pseries machine to allocate IRQ numbers for both interrupt controller backends. These patches have been merged in QEMU.
Quoted 5 lines
Quoted 3 lines
A change of interrupt mode results in a reset. The device tree is populated accordingly and the ICPs are switched for the model in use.
For KVM we need to only instanciate one of them though.
Hmm,
How would we handle a guest rebooting on a kernel without XIVE support ? Are you suggesting to create the XICS or XIVE device in the CAS negotiation process ? So, the machine would not have any interrupt controller before CAS. That seems really late to me. grub uses the console for instance.
I think it should prepare for both options, start in XIVE legacy mode, which is XICS, then possibly switch to XIVE exploitation mode.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
And how that will interact with KVM ?
I expect we will do the same, which is to create two KVM devices to be able to handle both interrupt controller backends depending on the mode negotiated by the guest.
That will be an ungodly mess, I'd rather we only instanciate the right one.
It's rather transparent currently in the emulated version. There are two sets of objects in QEMU, switching is done in CAS. KVM support should not change anything in that area.
I expect the 'xive-kvm' object to get/set states for migration, just like for XICS and to setup the ESB+TIMA memory regions, which is new.
C.
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
I was
thinking the kernel would implement a different KVM device type, ie the "emulated XICS" would remainKVM_DEV_TYPE_XICSand XIVE would beKVM_DEV_TYPE_XIVE.yes. it makes sense. The new device will have a lot in common with the
KVM_DEV_TYPE_XICSusingkvm_xive_ops.Ben.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 13 lines · Cédric Le Goater
Quoted 13 lines
Quoted 12 lines
Quoted 2 lines
Also, have we decided how the process of switching between XICS and XIVE will work vs. CAS ?
That's how it is described in the architecture. The current choice is to create both XICS and XIVE objects and choose at CAS which one to use. It relies today on the capability of the pseries machine to allocate IRQ numbers for both interrupt controller backends. These patches have been merged in QEMU.
A change of interrupt mode results in a reset. The device tree is populated accordingly and the ICPs are switched for the model in use.
Quoted 5 lines
Quoted 1 line
For KVM we need to only instanciate one of them though.
Hmm,
How would we handle a guest rebooting on a kernel without XIVE support ?
It will do CAS again and we can change the devices.
Quoted 3 lines
Are you suggesting to create the XICS or XIVE device in the CAS negotiation process ? So, the machine would not have any interrupt controller before CAS. That seems really late to me. grub uses the console for instance.
We start with XICS by default.
Quoted 12 lines
I think it should prepare for both options, start in XIVE legacy mode, which is XICS, then possibly switch to XIVE exploitation mode.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
And how that will interact with KVM ?
I expect we will do the same, which is to create two KVM devices to be able to handle both interrupt controller backends depending on the mode negotiated by the guest.
That will be an ungodly mess, I'd rather we only instanciate the right one.
Quoted 6 lines
It's rather transparent currently in the emulated version. There are two sets of objects in QEMU, switching is done in CAS. KVM support should not change anything in that area.
I expect the 'xive-kvm' object to get/set states for migration, just like for XICS and to setup the ESB+TIMA memory regions, which is new.
But both XICS and XIVE are completely different kernel KVM devices that will need to "hook" into the same set of internal hooks for things like interrupts being passed through, RTAS calls etc...
How does KVM knows which one to "activate" ?
I don't think the kernel should have both.
Quoted 10 lines
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
I was
thinking the kernel would implement a different KVM device type, ie the "emulated XICS" would remainKVM_DEV_TYPE_XICSand XIVE would beKVM_DEV_TYPE_XIVE.yes. it makes sense. The new device will have a lot in common with the
KVM_DEV_TYPE_XICSusingkvm_xive_ops.Ben.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 14 lines · Benjamin Herrenschmidt
Quoted 13 lines · Cédric Le Goater
Quoted 13 lines
Quoted 12 lines
Quoted 2 lines
Also, have we decided how the process of switching between XICS and XIVE will work vs. CAS ?
That's how it is described in the architecture. The current choice is to create both XICS and XIVE objects and choose at CAS which one to use. It relies today on the capability of the pseries machine to allocate IRQ numbers for both interrupt controller backends. These patches have been merged in QEMU.
A change of interrupt mode results in a reset. The device tree is populated accordingly and the ICPs are switched for the model in use.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
For KVM we need to only instanciate one of them though.
Hmm,
How would we handle a guest rebooting on a kernel without XIVE support ?
It will do CAS again and we can change the devices.
So, we would destroy the previous QEMU ICS object and create a new one in the CAS hcall. That would probably work. There might be some issues in creating and destroying the ICS KVM device, but that can be studied without XIVE.
It used to be considered ugly to create a QEMU device at reset time, so I wonder if this is still the case, because when the machine reaches CAS, we really are beyond reset.
If this is OK, then the next "issue" is to keep in sync the allocated IRQ numbers. The IRQ allocator is now merged at the machine level, so the synchronization is obvious to do when both backend QEMU objects are available. that's the path I took. If both QEMU objects are not available, then we need to scan the IRQ number space in the current interrupt mode and allocate the same IRQs in the newly negotiated mode. Probably OK. I don't see major problems with the current code.
Migration is a problem. We will need both backend QEMU objects to be available anyhow if we want to migrate. So we are back to the current solution creating both QEMU objects but we can try to defer some of the KVM inits and create the KVM device on demand at CAS time.
The next problem is the ICP object that currently needs the KVM device fd to connect the vcpus ... So, we will need to change that also. That is probably the biggest problem today. We need a way to disconnect the vpcu from the KVM device and see how we can defer the connection. I need to make sure this is possible, I can check that without XIVE I think.
Quoted 5 lines
Quoted 3 lines
Are you suggesting to create the XICS or XIVE device in the CAS negotiation process ? So, the machine would not have any interrupt controller before CAS. That seems really late to me. grub uses the console for instance.
We start with XICS by default.
yes.
Quoted 16 lines
Quoted 16 lines
I think it should prepare for both options, start in XIVE legacy mode, which is XICS, then possibly switch to XIVE exploitation mode.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
And how that will interact with KVM ?
I expect we will do the same, which is to create two KVM devices to be able to handle both interrupt controller backends depending on the mode negotiated by the guest.
That will be an ungodly mess, I'd rather we only instanciate the right one.
It's rather transparent currently in the emulated version. There are two sets of objects in QEMU, switching is done in CAS. KVM support should not change anything in that area.
Quoted 8 lines
Quoted 2 lines
I expect the 'xive-kvm' object to get/set states for migration, just like for XICS and to setup the ESB+TIMA memory regions, which is new.
But both XICS and XIVE are completely different kernel KVM devices that will need to "hook" into the same set of internal hooks for things like interrupts being passed through, RTAS calls etc...
How does KVM knows which one to "activate" ?
Can't we add an extra IRQ type and use vcpu->arch.irq_type for that ? I haven't studied all the low level details though.
Quoted 1 line
I don't think the kernel should have both.
I hear that. From a QEMU perspective, it is much easier to put everything in place for both interrupt modes and let the guest decide what it wants to use.
If we choose not to, we will need to find solution to defer the KVM inits and to disconnect/reconnect the vcpus. For the latter, we could add a KVM_DISABLE_CAP ioctl or maybe better add a new capability like KVM_CAP_IRQ_XIVE to perform the switch.
C.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 4 lines
How does KVM knows which one to "activate" ?
Can't we add an extra IRQ type and use
vcpu->arch.irq_typefor that ? I haven't studied all the low level details though.
I don't think connecting a vcpu to two different KVM devices makes sense ... So we need to destroy/recreate the KVM device and disconnect/reconnect the vcpus. I will take a closer look.
C.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Cédric Le GoaterQuoted 4 lines · Cédric Le Goater
Migration is a problem. We will need both backend QEMU objects to be available anyhow if we want to migrate. So we are back to the current solution creating both QEMU objects but we can try to defer some of the KVM inits and create the KVM device on demand at CAS time.
Do we have a way to migrate a piece of info from the machine *first* that indicate what type of XICS/XIVE to instanciate ?
Quoted 5 lines
The next problem is the ICP object that currently needs the KVM device fd to connect the vcpus ... So, we will need to change that also. That is probably the biggest problem today. We need a way to disconnect the vpcu from the KVM device and see how we can defer the connection. I need to make sure this is possible, I can check that without XIVE
Ben.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 4 lines · Cédric Le Goater
Migration is a problem. We will need both backend QEMU objects to be available anyhow if we want to migrate. So we are back to the current solution creating both QEMU objects but we can try to defer some of the KVM inits and create the KVM device on demand at CAS time.
Do we have a way to migrate a piece of info from the machine *first* that indicate what type of XICS/XIVE to instanciate ?
The source and the target machines should have the same realized objects. I think this is the simplest solution to keep the migration framework maintainable.
I don't think it is a problem to call a xics_fini() routine to destroy the XICS KVM device if a new interrupt mode was negotiated in CAS. We would then call a xive_init() routing to create the new XIVE KVM device.
When done, the question boils down to disconnect and reconnect the vcpus to the KVM device. The QEMU CPU ->intc pointer should be updated also but that's a QEMU level problem. Already done.
In the QEMU "icp-kvm" object, the connection to the KVM device is currently forced in the realize routine but we can add some handlers to manage the link. Similar handlers would do the same in the QEMU "nvt-kvm" object when XIVE is on.
If we think this is a possible way to address the problem, I can check the above thinking on a XICS KVM machine and force the init/fini sequence in the CAS negotiation process. I will need a KVM ioctl to destroy a device and maybe a KVM VCPU ioctl to disable a capability.
Cheers,
C.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 3 lines · Cédric Le Goater
The source and the target machines should have the same realized objects. I think this is the simplest solution to keep the migration framework maintainable.
Yeah well, it all boils down to qemu migration being completely brain dead in relying on an external entity to create the same machine rather than carrying the configuration in the migration stream... ugh.
Quoted 8 lines
I don't think it is a problem to call a
xics_fini()routine to destroy the XICS KVM device if a new interrupt mode was negotiated in CAS. We would then call axive_init()routing to create the new XIVE KVM device.When done, the question boils down to disconnect and reconnect the vcpus to the KVM device. The QEMU CPU ->intc pointer should be updated also but that's a QEMU level problem. Already done.
The problem is more the in-kernel hooks.
Quoted 11 lines
In the QEMU "icp-kvm" object, the connection to the KVM device is currently forced in the realize routine but we can add some handlers to manage the link. Similar handlers would do the same in the QEMU "nvt-kvm" object when XIVE is on.
If we think this is a possible way to address the problem, I can check the above thinking on a XICS KVM machine and force the init/fini sequence in the CAS negotiation process. I will need a KVM ioctl to destroy a device and maybe a KVM VCPU ioctl to disable a capability.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Benjamin HerrenschmidtQuoted 8 lines · Benjamin Herrenschmidt
Quoted 4 lines · Cédric Le Goater
Migration is a problem. We will need both backend QEMU objects to be available anyhow if we want to migrate. So we are back to the current solution creating both QEMU objects but we can try to defer some of the KVM inits and create the KVM device on demand at CAS time.
Do we have a way to migrate a piece of info from the machine *first* that indicate what type of XICS/XIVE to instanciate ?
Nope. qemu migration doesn't work like that. Yes, it should, and everyone knows it, but changing it is a really long term project.
Quoted 9 lines
Quoted 6 lines
The next problem is the ICP object that currently needs the KVM device fd to connect the vcpus ... So, we will need to change that also. That is probably the biggest problem today. We need a way to disconnect the vpcu from the KVM device and see how we can defer the connection. I need to make sure this is possible, I can check that without XIVE
Ben.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 7 lines · David Gibson
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Cédric Le Goater
Migration is a problem. We will need both backend QEMU objects to be available anyhow if we want to migrate. So we are back to the current solution creating both QEMU objects but we can try to defer some of the KVM inits and create the KVM device on demand at CAS time.
Quoted 5 lines
Quoted 2 lines
Do we have a way to migrate a piece of info from the machine *first* that indicate what type of XICS/XIVE to instanciate ?
Nope. qemu migration doesn't work like that. Yes, it should, and everyone knows it, but changing it is a really long term project.
Well, we have a problem then. It looks like Qemu broken migration is fundamentally incompatible with PAPR and CAS design...
I know we don't migrate the configuration, that's not exactly what I had in mind tho... Can we have some piece of *data* from the machine be migrated first, and use it on the target to reconfigure the interrupt controller before the stream arrives ?
Otherwise, we have indeed no much choice but the horrible wart of creating both interrupt controllers with only one "active".
Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
The next problem is the ICP object that currently needs the KVM device fd to connect the vcpus ... So, we will need to change that also. That is probably the biggest problem today. We need a way to disconnect the vpcu from the KVM device and see how we can defer the connection. I need to make sure this is possible, I can check that without XIVE
Ben.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 14 lines · Benjamin Herrenschmidt
Quoted 7 lines · David Gibson
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Cédric Le Goater
Migration is a problem. We will need both backend QEMU objects to be available anyhow if we want to migrate. So we are back to the current solution creating both QEMU objects but we can try to defer some of the KVM inits and create the KVM device on demand at CAS time.
Quoted 5 lines
Quoted 2 lines
Do we have a way to migrate a piece of info from the machine *first* that indicate what type of XICS/XIVE to instanciate ?
Nope. qemu migration doesn't work like that. Yes, it should, and everyone knows it, but changing it is a really long term project.
Quoted 7 lines
Well, we have a problem then. It looks like Qemu broken migration is fundamentally incompatible with PAPR and CAS design...
I know we don't migrate the configuration, that's not exactly what I had in mind tho... Can we have some piece of *data* from the machine be migrated first, and use it on the target to reconfigure the interrupt controller before the stream arrives ?
These days this is done via libvirt - it reads properties it needs via QMP, then sends an XML with everything (the interrupt controller type may be one of such properties), and starts the destination QEMU with the explicit interrupt controller (like -machine pseries,intrc=xive).
Hacking QEMU to do all of this is still in a distant TODO...
Quoted 9 lines
Otherwise, we have indeed no much choice but the horrible wart of creating both interrupt controllers with only one "active".
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
The next problem is the ICP object that currently needs the KVM device fd to connect the vcpus ... So, we will need to change that also. That is probably the biggest problem today. We need a way to disconnect the vpcu from the KVM device and see how we can defer the connection. I need to make sure this is possible, I can check that without XIVE
Signature · 1 line
Alexey
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Benjamin HerrenschmidtQuoted 17 lines · Benjamin Herrenschmidt
Quoted 7 lines · David Gibson
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Cédric Le Goater
Migration is a problem. We will need both backend QEMU objects to be available anyhow if we want to migrate. So we are back to the current solution creating both QEMU objects but we can try to defer some of the KVM inits and create the KVM device on demand at CAS time.
Quoted 5 lines
Quoted 2 lines
Do we have a way to migrate a piece of info from the machine *first* that indicate what type of XICS/XIVE to instanciate ?
Nope. qemu migration doesn't work like that. Yes, it should, and everyone knows it, but changing it is a really long term project.
Well, we have a problem then. It looks like Qemu broken migration is fundamentally incompatible with PAPR and CAS design...
Quoted 7 lines
I know we don't migrate the configuration, that's not exactly what I had in mind tho... Can we have some piece of *data* from the machine be migrated first, and use it on the target to reconfigure the interrupt controller before the stream arrives ?
Otherwise, we have indeed no much choice but the horrible wart of creating both interrupt controllers with only one "active".
Well, both QEMU model objects would be created, yes, but one only KVM associated device. It's a bit ugly from a QEMU point of view because the KVM initialization is deferred at reset but, in the pratice, it results in a couple of calls to :
- disconnect the VCPU from the KVM interrupt device
- destroy the previous KVM interrupt device (new ioctl)
- create the new KVM interrupt device
- reconnect the VCPU to the KVM interrupt device
I don't think it will be a major problem.
What I am unease with currently, is how to share the same XIVE objects when under KVM and when not. The only difference is in the nature of the MMIO region and the qemu_irq handler. Work in progress.
And we have four interrupt modes to support : XICS-KVM, XICS, XIVE-KVM, XIVE.
Thanks,
C.
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 5 lines
The next problem is the ICP object that currently needs the KVM device fd to connect the vcpus ... So, we will need to change that also. That is probably the biggest problem today. We need a way to disconnect the vpcu from the KVM device and see how we can defer the connection. I need to make sure this is possible, I can check that without XIVE
Ben.
Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Alexey KardashevskiyQuoted 9 lines · Alexey Kardashevskiy
Quoted 7 lines · Benjamin Herrenschmidt
Well, we have a problem then. It looks like Qemu broken migration is fundamentally incompatible with PAPR and CAS design...
I know we don't migrate the configuration, that's not exactly what I had in mind tho... Can we have some piece of *data* from the machine be migrated first, and use it on the target to reconfigure the interrupt controller before the stream arrives ?
Quoted 4 lines
These days this is done via libvirt - it reads properties it needs via QMP, then sends an XML with everything (the interrupt controller type may be one of such properties), and starts the destination QEMU with the explicit interrupt controller (like -machine pseries,intrc=xive).
Clarification: libvirt will use the user-defined XML configuration to generate the QEMU command line both for the source and the target of the migration, but it will not automagically figure out properties through QMP. So if you want the controller to explicitly show up on the QEMU command line, libvirt should be taught about it.
Signature · 1 line
Andrea Bolognani / Red Hat / Virtualization
Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 15 lines · Andrea Bolognani
Quoted 9 lines · Alexey Kardashevskiy
Quoted 7 lines · Benjamin Herrenschmidt
Well, we have a problem then. It looks like Qemu broken migration is fundamentally incompatible with PAPR and CAS design...
I know we don't migrate the configuration, that's not exactly what I had in mind tho... Can we have some piece of *data* from the machine be migrated first, and use it on the target to reconfigure the interrupt controller before the stream arrives ?
Quoted 4 lines
These days this is done via libvirt - it reads properties it needs via QMP, then sends an XML with everything (the interrupt controller type may be one of such properties), and starts the destination QEMU with the explicit interrupt controller (like -machine pseries,intrc=xive).
Quoted 5 lines
Clarification: libvirt will use the user-defined XML configuration to generate the QEMU command line both for the source and the target of the migration, but it will not automagically figure out properties through QMP. So if you want the controller to explicitly show up on the QEMU command line, libvirt should be taught about it.
Which can't work because the guest pretty much decides what it will be early on during the boot process.
So we're back to square 1 having to instanciate both objects in qemu with some kind of "activation" flag.
Cheers,
Ben.
Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 16 lines · Benjamin Herrenschmidt
Quoted 15 lines · Andrea Bolognani
Quoted 13 lines · Alexey Kardashevskiy
Quoted 7 lines · Benjamin Herrenschmidt
Well, we have a problem then. It looks like Qemu broken migration is fundamentally incompatible with PAPR and CAS design...
I know we don't migrate the configuration, that's not exactly what I had in mind tho... Can we have some piece of *data* from the machine be migrated first, and use it on the target to reconfigure the interrupt controller before the stream arrives ?
These days this is done via libvirt - it reads properties it needs via QMP, then sends an XML with everything (the interrupt controller type may be one of such properties), and starts the destination QEMU with the explicit interrupt controller (like -machine pseries,intrc=xive).
Quoted 8 lines
Quoted 5 lines
Clarification: libvirt will use the user-defined XML configuration to generate the QEMU command line both for the source and the target of the migration, but it will not automagically figure out properties through QMP. So if you want the controller to explicitly show up on the QEMU command line, libvirt should be taught about it.
Which can't work because the guest pretty much decides what it will be early on during the boot process.
At the time of migration the guest has told QEMU what intrc it wants (via cas?) and libvirt can ask QEMU via QMP about that when migrating.
Quoted 6 lines
So we're back to square 1 having to instanciate both objects in qemu with some kind of "activation" flag.
Cheers,
Ben.
Signature · 1 line
Alexey
Re: [Qemu-devel] [Qemu-ppc] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Benjamin HerrenschmidtQuoted 22 lines · Benjamin Herrenschmidt
Quoted 15 lines · Andrea Bolognani
Quoted 9 lines · Alexey Kardashevskiy
Quoted 7 lines · Benjamin Herrenschmidt
Well, we have a problem then. It looks like Qemu broken migration is fundamentally incompatible with PAPR and CAS design...
I know we don't migrate the configuration, that's not exactly what I had in mind tho... Can we have some piece of *data* from the machine be migrated first, and use it on the target to reconfigure the interrupt controller before the stream arrives ?
Quoted 4 lines
These days this is done via libvirt - it reads properties it needs via QMP, then sends an XML with everything (the interrupt controller type may be one of such properties), and starts the destination QEMU with the explicit interrupt controller (like -machine pseries,intrc=xive).
Quoted 5 lines
Clarification: libvirt will use the user-defined XML configuration to generate the QEMU command line both for the source and the target of the migration, but it will not automagically figure out properties through QMP. So if you want the controller to explicitly show up on the QEMU command line, libvirt should be taught about it.
Quoted 5 lines
Which can't work because the guest pretty much decides what it will be early on during the boot process.
So we're back to square 1 having to instanciate both objects in qemu with some kind of "activation" flag.
yes and the activation flag is the associated bit in CAS OV5 :
spapr_ovec_test(spapr->ov5_cas, OV5_XIVE_EXPLOIT)
if a new interrupt mode is negotiated, a machine reset is required, a new device tree is populated, new ICPs are installed, etc. There is a little more to do with KVM and we need to find the right model abstraction for it. Anyhow, it is not a big problem to switch from one mode to another when both objects are around. It is even easier to keep the allocated IRQs in sync in fact.
What problem do you foresee with KVM ? this is already solved for irqchip=off.
Cheers,
C.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Benjamin HerrenschmidtQuoted 29 lines · Benjamin Herrenschmidt
Quoted 6 lines · David Gibson
As you've suggested in yourself, I think we might need to more explicitly model the different components of the XIVE system. As part of that, I think you need to be clearer in this base skeleton about exactly what component your XIVE object represents.
Quoted 7 lines
If the answer is "the overall thing" I suspect that's not what you want - I had one of those for XICs which proved to be a mistake (eventually replaced by the XICSFabric interface).
Changing the model later isn't impossible, but doing so without breaking migration can be a real pain, so I think it's worth a reasonable effort to try and get it right initially.
Note: we do need to speed things up a bit, as having exploitation mode in KVM will significantly help with IPI performance among other things.
I'm about ready to do the KVM bits. The one thing we need to discuss and figure a good design for is how we map all those interrupt control pages into qemu.
Each interrupt (either PCIe pass-through or the "generic XIVE IPIs" which are used for guest IPIs and for vio/virtio/emulated interrupts) comes with a "control page" (ESB page) which needs to be mapped into the guest, and the generic IPIs also come with a trigger page which needs to be mapped into the guest for guest IPIs or OpenCAPI interrupts, or just qemu for emulated devices.
Quoted 8 lines
Now that can be thousands of these critters. I certainly don't want to create thousands of VMAs in qemu and even less thousands of memory regions in KVM.
So we need some kind of mechanism by wich a single large VMA gets mmap'ed into qemu (or maybe a couple of these, but not too many) and the interrupt pages can be assigned to slots in there and demand faulted.
Ok, I see your point. We'll definitely need to be able to map things in as a block, rather than one by one.
Quoted 17 lines
For the generic interrupts, this can probably be covered by KVM, adding some arch ioctls for allocating IPIs and mmap'ing that region etc...
For pass-through, it's trickier, we don't want to mmap each irqfd individually for the above reason, so we want to "link" them to KVM. We don't want to allow qemu to take control of any arbitrary interrupt in the system though, so it has to related to the ownership of the irqfd coming from vfio.
OpenCAPI I suspect will be its own can of worms...
Also, have we decided how the process of switching between XICS and XIVE will work vs. CAS ? And how that will interact with KVM ? I was thinking the kernel would implement a different KVM device type, ie the "emulated XICS" would remain
KVM_DEV_TYPE_XICSand XIVE would beKVM_DEV_TYPE_XIVE.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Cédric Le GoaterQuoted 19 lines · Cédric Le Goater
Quoted 18 lines · Benjamin Herrenschmidt
Quoted 17 lines · Cédric Le Goater
Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
Also, have we decided how the process of switching between XICS and XIVE will work vs. CAS ?
That's how it is described in the architecture. The current choice is to create both XICS and XIVE objects and choose at CAS which one to use. It relies today on the capability of the pseries machine to allocate IRQ numbers for both interrupt controller backends. These patches have been merged in QEMU.
Quoted 5 lines
Quoted 3 lines
A change of interrupt mode results in a reset. The device tree is populated accordingly and the ICPs are switched for the model in use.
For KVM we need to only instanciate one of them though.
Hmm,
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
How would we handle a guest rebooting on a kernel without XIVE support ?
It will do CAS again and we can change the devices.
So, we would destroy the previous QEMU ICS object and create a new one in the CAS hcall. That would probably work. There might be some issues in creating and destroying the ICS KVM device, but that can be studied without XIVE.
Adding and removing devices at runtime based on guest requests like this will get really hairy in qemu.
As I've said before for the first cut, I think we want to select just one as a machine option to avoid this confusion.
Looking further ahead, I think we'll be better off having both the XIVE and XICS models always present (at least minimally) in qemu, but with only one "active" at any given time.
Note that having the inactive one destroy and clean up the corresponding KVM devices is fine, as is deallocating as much of its runtime state as we can without changing the notional QOM tree.
Quoted 75 lines
It used to be considered ugly to create a QEMU device at reset time, so I wonder if this is still the case, because when the machine reaches CAS, we really are beyond reset.
If this is OK, then the next "issue" is to keep in sync the allocated IRQ numbers. The IRQ allocator is now merged at the machine level, so the synchronization is obvious to do when both backend QEMU objects are available. that's the path I took. If both QEMU objects are not available, then we need to scan the IRQ number space in the current interrupt mode and allocate the same IRQs in the newly negotiated mode. Probably OK. I don't see major problems with the current code.
Migration is a problem. We will need both backend QEMU objects to be available anyhow if we want to migrate. So we are back to the current solution creating both QEMU objects but we can try to defer some of the KVM inits and create the KVM device on demand at CAS time.
The next problem is the ICP object that currently needs the KVM device fd to connect the vcpus ... So, we will need to change that also. That is probably the biggest problem today. We need a way to disconnect the vpcu from the KVM device and see how we can defer the connection. I need to make sure this is possible, I can check that without XIVE I think.
Quoted 5 lines
Quoted 3 lines
Are you suggesting to create the XICS or XIVE device in the CAS negotiation process ? So, the machine would not have any interrupt controller before CAS. That seems really late to me. grub uses the console for instance.
We start with XICS by default.
yes.
Quoted 16 lines
Quoted 16 lines
I think it should prepare for both options, start in XIVE legacy mode, which is XICS, then possibly switch to XIVE exploitation mode.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
And how that will interact with KVM ?
I expect we will do the same, which is to create two KVM devices to be able to handle both interrupt controller backends depending on the mode negotiated by the guest.
That will be an ungodly mess, I'd rather we only instanciate the right one.
It's rather transparent currently in the emulated version. There are two sets of objects in QEMU, switching is done in CAS. KVM support should not change anything in that area.
Quoted 8 lines
Quoted 2 lines
I expect the 'xive-kvm' object to get/set states for migration, just like for XICS and to setup the ESB+TIMA memory regions, which is new.
But both XICS and XIVE are completely different kernel KVM devices that will need to "hook" into the same set of internal hooks for things like interrupts being passed through, RTAS calls etc...
How does KVM knows which one to "activate" ?
Can't we add an extra IRQ type and use
vcpu->arch.irq_typefor that ? I haven't studied all the low level details though.Quoted 1 line
I don't think the kernel should have both.
I hear that. From a QEMU perspective, it is much easier to put everything in place for both interrupt modes and let the guest decide what it wants to use.
If we choose not to, we will need to find solution to defer the KVM inits and to disconnect/reconnect the vcpus. For the latter, we could add a
KVM_DISABLE_CAPioctl or maybe better add a new capability likeKVM_CAP_IRQ_XIVEto perform the switch.C.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Cédric Le GoaterQuoted 17 lines · Cédric Le Goater
Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
Also, have we decided how the process of switching between XICS and XIVE will work vs. CAS ?
That's how it is described in the architecture. The current choice is to create both XICS and XIVE objects and choose at CAS which one to use. It relies today on the capability of the pseries machine to allocate IRQ numbers for both interrupt controller backends. These patches have been merged in QEMU.
Quoted 5 lines
Quoted 3 lines
A change of interrupt mode results in a reset. The device tree is populated accordingly and the ICPs are switched for the model in use.
For KVM we need to only instanciate one of them though.
Hmm,
Quoted 7 lines
How would we handle a guest rebooting on a kernel without XIVE support ? Are you suggesting to create the XICS or XIVE device in the CAS negotiation process ? So, the machine would not have any interrupt controller before CAS. That seems really late to me. grub uses the console for instance.
I think it should prepare for both options, start in XIVE legacy mode, which is XICS, then possibly switch to XIVE exploitation mode.
I think for our first draft we should have XIVE and XICS based platforms as separate machine types (or a machine option, I guess).
We do want to allow this to be autonegotiated, but I feel like emphasising that at the beginning is causing unnatural design decisions in the XIVE model itself.
Quoted 30 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
And how that will interact with KVM ?
I expect we will do the same, which is to create two KVM devices to be able to handle both interrupt controller backends depending on the mode negotiated by the guest.
That will be an ungodly mess, I'd rather we only instanciate the right one.
It's rather transparent currently in the emulated version. There are two sets of objects in QEMU, switching is done in CAS. KVM support should not change anything in that area.
I expect the 'xive-kvm' object to get/set states for migration, just like for XICS and to setup the ESB+TIMA memory regions, which is new.
C.
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
I was
thinking the kernel would implement a different KVM device type, ie the "emulated XICS" would remainKVM_DEV_TYPE_XICSand XIVE would beKVM_DEV_TYPE_XIVE.yes. it makes sense. The new device will have a lot in common with the
KVM_DEV_TYPE_XICSusingkvm_xive_ops.Ben.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Benjamin HerrenschmidtQuoted 8 lines · Benjamin Herrenschmidt
Quoted 7 lines · David Gibson
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Cédric Le Goater
Migration is a problem. We will need both backend QEMU objects to be available anyhow if we want to migrate. So we are back to the current solution creating both QEMU objects but we can try to defer some of the KVM inits and create the KVM device on demand at CAS time.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Do we have a way to migrate a piece of info from the machine *first* that indicate what type of XICS/XIVE to instanciate ?
Nope. qemu migration doesn't work like that. Yes, it should, and everyone knows it, but changing it is a really long term project.
Well, we have a problem then. It looks like Qemu broken migration is fundamentally incompatible with PAPR and CAS design...
Hrm, the fit is very clunky certainly, but i think we can make it work.
Quoted 4 lines
I know we don't migrate the configuration, that's not exactly what I had in mind tho... Can we have some piece of *data* from the machine be migrated first, and use it on the target to reconfigure the interrupt controller before the stream arrives ?
Sorta.. maybe.. but it would probably get really ugly if we don't preserve the usual way object lifetimes work.
Quoted 2 lines
Otherwise, we have indeed no much choice but the horrible wart of creating both interrupt controllers with only one "active".
I really think this is the way to go, warts and all.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Cédric Le GoaterQuoted 29 lines · Cédric Le Goater
Quoted 28 lines · David Gibson
Quoted 27 lines · Cédric Le Goater
With the POWER9 processor comes a new interrupt controller called XIVE. It is composed of three sub-engines :
- Interrupt Virtualization Source Engine (IVSE). These are in PHBs, in the main controller for the IPIS and in the PSI host bridge. They are configured to feed the IVRE with events.
- Interrupt Virtualization Routing Engine (IVRE). Their job is to match an event source with a Notification Virtualization Target (NVT), a priority and an Event Queue (EQ) to determine if a Virtual Processor can handle the event.
- Interrupt Virtualization Presentation Engine (IVPE). It maintains the interrupt state of each hardware thread and present the notification as an external exception.
Each of the engines uses a set of internal tables to redirect exceptions from event sources to CPU threads. The first table we introduce is the Interrupt Virtualization Entry (IVE) table, part of the virtualization engine in charge of routing events. It associates event sources (IRQ numbers) to event queues which will forward, or not, the event notification to the presentation controller.
The XIVE model is designed to make use of the full range of the IRQ number space and does not use an offset like the XICS mode does. Hence, the IVE table is directly indexed by the IRQ number.
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Signed-off-by Cédric Le Goater <[email protected]>As you've suggested in yourself, I think we might need to more explicitly model the different components of the XIVE system. As part of that, I think you need to be clearer in this base skeleton about exactly what component your XIVE object represents.
Sorry it's been so long since I looked at these.
Quoted 9 lines
ok. The base skeleton is the IVRE, the central engine handling the routing.
Quoted 1 line
If the answer is "the overall thing"
Yes, it is more or less that currently.
The sPAPRXive object models the source engine and the routing engine in one object.
Yeah, I suspect we don't want that. Although it might seem simpler in the spapr case, at least at first glance, I think it will cause us problems later. At the very least, it's likely to make it harder to share code between the spapr and powernv case. I think it will also make for more confusion about exactly what things belong where.
Quoted 24 lines
I have merged these for simplicity and because the interrupt controller has an internal source for the interrupts of the "IPI" type, which are used for the CPU IPIs but also for other generic interrupts, like the OpenCAPI ones. The XIVE sPAPR interface is also much simpler than the baremetal one, all the tables are maintained in the hypervisor, so this choice made some sense.
But since, I have started the PowerNV model and I am duplicating a lot of code to handle the triggering and the MMIOs in the different sources. So I am not convinced anymore. Nevertheless, the overall routing logic is the same even if some the tables are not located in QEMU anymore, but in the machine memory.
The sPAPRXiveNVT models some of the CPU presenter engine. It holds the virtual CPU interrupt states when not dispatched on a real HW thread. Real world is more complex. There are "CAM" lines in the HW threads which are compared to find a matching candidate. But I don't think we need to anything more complex than today unless we want to support KVM under TCG ...
Quoted 3 lines
I suspect that's not what you
want - I had one of those for XICs which proved to be a mistake (eventually replaced by the XICSFabric interface).
Quoted 7 lines
The XICSFabric would be the main Xive object. The interface between the sources and the routing engine is hidden in sPAPR, we can use a simple function call :
spapr_xive_irq(pnv->xive, irq);we could get rid of the qirqs but they are required for XICS.
I don't quite follow, but this doesn't sound right.
Quoted 14 lines
PowerNV uses MMIOs to notify an event and it makes the modeling somewhat easier. Each controller model has a notify port address register on which a interrupt number is written to forward an event to the routing engine. So it is a simple store.
I don't know why there is a different notify port address per source, may be for extra filtering at the routing engine level.
Quoted 3 lines
Changing the model later isn't impossible, but doing so without breaking migration can be a real pain, so I think it's worth a reasonable effort to try and get it right initially.
I completely agree.
Quoted 9 lines
This is why I have started the PnvXive model to challenge the current PAPR design. I have hacked a bunch of patches for XIVE, LPC, PSI, OCC and basic PPC support which boot a PowerNV P9 up to petitboot. It would look better with a source object, but the location of the PQ bits is a bit problematic. It highly depends on the controller. The main controller uses tables in the hypervisor memory. The PSIHB controller has its own bits. I suppose it is the same for PHB4. I need to take a closer look at how we could have a common source object.
Ok, sounds like a good idea.
Quoted 308 lines
The most important part is KVM support and how we expose the MMIO region. We need to make progress on that topic.
Thanks,
C.
Quoted 298 lines
Quoted 297 lines
---
Changes since v1 :
- used
g_new0instead ofg_malloc0
- removedVMSTATE_STRUCT_VARRAY_UINT32_ALLOC
- introduced a device reset handler. the object needs to be parented to sysbus when created.
- renamedspapr_xive_irq_settospapr_xive_irq_enable
- renamedspapr_xive_irq_unsettospapr_xive_irq_disable
- moved thePPC_BITmacros undertarget/ppc/cpu.h
- shrinked file copyright headerdefault-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/spapr_xive.c | 156 ++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 41 ++++++++++ include/hw/ppc/spapr_xive.h | 35 +++++++++ 5 files changed, 234 insertions(+) create mode 100644 hw/intc/spapr_xive.c create mode 100644 hw/intc/xive-internal.h create mode 100644 include/hw/ppc/spapr_xive.hdefault-configs/ppc64-softmmu.mak +1
-0@@ -56,6 +56,7 @@ CONFIG_SM501=y CONFIG_XICS=$(CONFIG_PSERIES) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM)) +CONFIG_XIVE_SPAPR=$(CONFIG_PSERIES) # For PReP CONFIG_SERIAL_ISA=y CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -35,6 +35,7 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o +obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o obj-$(CONFIG_POWERNV) += xics_pnv.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/spapr_xive.c new file +156
-0@@ -0,0 +1,156 @@ +/* +* QEMU PowerPC sPAPR XIVE interrupt controller model +* +* Copyright (c) 2017, IBM Corporation. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "target/ppc/cpu.h" +#include "sysemu/cpus.h" +#include "sysemu/dma.h" +#include "monitor/monitor.h" +#include "hw/ppc/spapr_xive.h" + +#include "xive-internal.h" + +/* +* Main XIVE object +*/ + +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) +{ +int i; + +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; + +if (!(ive->w &IVE_VALID )) { +continue ; + } + +monitor_printf (mon," %4x %s %08x %08x\n" , i, + ive->w &IVE_MASKED ?"M" :" " , + (int )GETFIELD (IVE_EQ_INDEX , ive->w), + (int )GETFIELD (IVE_EQ_DATA , ive->w)); + } +} + +static void spapr_xive_reset (DeviceState *dev) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); +int i; + +/* Mask all valid IVEs in the IRQ number space. */ +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; +if (ive->w &IVE_VALID ) { + ive->w |=IVE_MASKED ; + } + } +} + +static void spapr_xive_realize (DeviceState *dev,Error **errp) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); + +if (!xive->nr_irqs) { +error_setg (errp,"Number of interrupt needs to be greater 0" ); +return ; + } + +/* Allocate the IVT (Interrupt Virtualization Table) */ + xive->ivt =g_new0 (XiveIVE, xive->nr_irqs); +} + +static const VMStateDescription vmstate_spapr_xive_ive = { + .name =TYPE_SPAPR_XIVE "/ive" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (w, XiveIVE), +VMSTATE_END_OF_LIST () + }, +}; + +static bool vmstate_spapr_xive_needed (void *opaque) +{ +/* TODO check machine XIVE support */ +return true; +} + +static const VMStateDescription vmstate_spapr_xive = { + .name =TYPE_SPAPR_XIVE , + .version_id =1 , + .minimum_version_id =1 , + .needed = vmstate_spapr_xive_needed, + .fields = (VMStateField []) { +VMSTATE_UINT32_EQUAL (nr_irqs, sPAPRXive,NULL ), +VMSTATE_STRUCT_VARRAY_UINT32 (ivt, sPAPRXive, nr_irqs,1 , + vmstate_spapr_xive_ive, XiveIVE), +VMSTATE_END_OF_LIST () + }, +}; + +static Property spapr_xive_properties[] = { +DEFINE_PROP_UINT32 ("nr-irqs" , sPAPRXive, nr_irqs,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void spapr_xive_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = spapr_xive_realize; + dc->reset = spapr_xive_reset; + dc->props = spapr_xive_properties; + dc->desc ="sPAPR XIVE interrupt controller" ; + dc->vmsd = &vmstate_spapr_xive; +} + +static const TypeInfo spapr_xive_info = { + .name =TYPE_SPAPR_XIVE , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (sPAPRXive), + .class_init = spapr_xive_class_init, +}; + +static void spapr_xive_register_types (void ) +{ +type_register_static (&spapr_xive_info); +} + +type_init (spapr_xive_register_types) + +XiveIVE *spapr_xive_get_ive(sPAPRXive *xive, uint32_t lisn) +{ +return lisn < xive->nr_irqs ? &xive->ivt[lisn] :NULL ; +} + +bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) { +return false; + } + + ive->w |=IVE_VALID ; +return true; +} + +bool spapr_xive_irq_disable (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) { +return false; + } + + ive->w &= ~IVE_VALID ; +return true; +}hw/intc/xive-internal.h new file +41
-0@@ -0,0 +1,41 @@ +/* +* QEMU PowerPC XIVE interrupt controller model +* +* Copyright (c) 2016-2017, IBM Corporation. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +*/ + +#ifndef _INTC_XIVE_INTERNAL_H +#define _INTC_XIVE_INTERNAL_H + +/* Utilities to manipulate these (originaly from OPAL) */ +#define MASK_TO_LSH (m) (__builtin_ffsl(m) - 1) +#define GETFIELD (m, v) (((v) & (m)) >> MASK_TO_LSH(m)) +#define SETFIELD (m, v, val) \ + (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m))) + +/* IVE/EAS +* +* One per interrupt source. Targets that interrupt to a given EQ +* and provides the corresponding logical interrupt number (EQ data) +* +* We also map this structure to the escalation descriptor inside +* an EQ, though in that case the valid and masked bits are not used. +*/ +typedef struct XiveIVE { +/* Use a single 64-bit definition to make it easier to +* perform atomic updates +*/ +uint64_t w; +#define IVE_VALID PPC_BIT(0) +#define IVE_EQ_BLOCK PPC_BITMASK(4, 7)/* Destination EQ block# */ +#define IVE_EQ_INDEX PPC_BITMASK(8, 31)/* Destination EQ index */ +#define IVE_MASKED PPC_BIT(32)/* Masked */ +#define IVE_EQ_DATA PPC_BITMASK(33, 63)/* Data written to the EQ */ +}XiveIVE ; + +XiveIVE *spapr_xive_get_ive (sPAPRXive *xive,uint32_t lisn); + +#endif /* _INTC_XIVE_INTERNAL_H */ include/hw/ppc/spapr_xive.h new file +35
-0@@ -0,0 +1,35 @@ +/* +* QEMU PowerPC sPAPR XIVE interrupt controller model +* +* Copyright (c) 2017, IBM Corporation. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +*/ + +#ifndef PPC_SPAPR_XIVE_H +#define PPC_SPAPR_XIVE_H + +#include <hw/sysbus.h> + +typedef struct sPAPRXive sPAPRXive ; +typedef struct XiveIVE XiveIVE ; + +#define TYPE_SPAPR_XIVE "spapr-xive" +#define SPAPR_XIVE (obj) OBJECT_CHECK(sPAPRXive, (obj), TYPE_SPAPR_XIVE) + +struct sPAPRXive { +SysBusDevice parent; + +/* Properties */ +uint32_t nr_irqs; + +/* XIVE internal tables */ +XiveIVE *ivt; +}; + +bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn); +bool spapr_xive_irq_disable (sPAPRXive *xive,uint32_t lisn); +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon); + +#endif /* PPC_SPAPR_XIVE_H */
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 30 lines · David Gibson
Quoted 29 lines · Cédric Le Goater
Quoted 28 lines · David Gibson
Quoted 27 lines · Cédric Le Goater
With the POWER9 processor comes a new interrupt controller called XIVE. It is composed of three sub-engines :
- Interrupt Virtualization Source Engine (IVSE). These are in PHBs, in the main controller for the IPIS and in the PSI host bridge. They are configured to feed the IVRE with events.
- Interrupt Virtualization Routing Engine (IVRE). Their job is to match an event source with a Notification Virtualization Target (NVT), a priority and an Event Queue (EQ) to determine if a Virtual Processor can handle the event.
- Interrupt Virtualization Presentation Engine (IVPE). It maintains the interrupt state of each hardware thread and present the notification as an external exception.
Each of the engines uses a set of internal tables to redirect exceptions from event sources to CPU threads. The first table we introduce is the Interrupt Virtualization Entry (IVE) table, part of the virtualization engine in charge of routing events. It associates event sources (IRQ numbers) to event queues which will forward, or not, the event notification to the presentation controller.
The XIVE model is designed to make use of the full range of the IRQ number space and does not use an offset like the XICS mode does. Hence, the IVE table is directly indexed by the IRQ number.
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Signed-off-by Cédric Le Goater <[email protected]>As you've suggested in yourself, I think we might need to more explicitly model the different components of the XIVE system. As part of that, I think you need to be clearer in this base skeleton about exactly what component your XIVE object represents.
Sorry it's been so long since I looked at these.
That's fine. I have been working on a XIVE device model for the PowerNV machine and KVM support for the pseries. I have a better understanding of the overall picture.
The patchset has not changed much so we can still discuss on this basis without me flooding the mailing list.
Quoted 7 lines
Quoted 7 lines
ok. The base skeleton is the IVRE, the central engine handling the routing.
Quoted 1 line
If the answer is "the overall thing"
Yes, it is more or less that currently.
Quoted 8 lines
Quoted 2 lines
The sPAPRXive object models the source engine and the routing engine in one object.
Yeah, I suspect we don't want that. Although it might seem simpler in the spapr case, at least at first glance, I think it will cause us problems later. At the very least, it's likely to make it harder to share code between the spapr and powernv case. I think it will also make for more confusion about exactly what things belong where.
I tend to agree.
We need to clarify (a bit) what is in the XIVE interrupt controller silicon, and how XIVE works. The XIVE device models for spapr and powernv should be very close as the differences are small. KVM support should be built on the spapr model.
There are 3 different sub-engines in the XIVE interrupt controller device :
* IVSE (XiveSource model)
interrupt sources, which expose their PQ bits through ESB MMIO pages (there are different levels of support depending on HW revision)
The XIVE interrupt controller has a set of internal sources for IPIs and CAPI like interrupts.
* IVRE (No real model)
in the middle, doing the routing of source event notification to (cpu) targets. It relies on internal tables which are stored in the hypervisor/QEMU/KVM for the spapr machine and in the VM RAM for the powernv machine.
Configuration updates of the XIVE tables are done through hcalls on spapr and with MMIOs on the IC regs on powernv. On the latter, the changes are flushed backed in the VM RAM.
* IVPE (XiveNVT)
set of registers for interrupt management at the CPU level. Exposed in a specific MMIO region called the TIMA.
The XIVE tables are :
* IVT
associate an interrupt source number with an event queue. the data to be pushed in the queue is stored there also.
* EQDT:
describes the queues in the OS RAM, also contains a set of flags, a virtual target, etc.
* VPDT:
describe the virtual targets, which can have different natures, a lpar, a cpu. This is for powernv, spapr does not have this concept.
So, the idea behind the sPAPRXive object is to model a XIVE interrupt controller device. It contains today :
- an internal source block for all interrupts : IPIs and virtual device interrupts. In the IRQ number space, the IPIs are below 4096 and the device interrupts above, which keeps compatibility with XICS. This is important to be able to change interrupt mode.
PowerNV has different source blocks, like for P8.
- a routing engine, which is limited to the IVT. This is a shortcut and it might be better to introduce a specific object. Anyhow, this is a state to capture.
In the current version I am working on, the XiveFabric interface is more complex :
typedef struct XiveFabricClass {
InterfaceClass parent;
XiveIVE *(*get_ive)(XiveFabric *xf, uint32_t lisn);
XiveNVT *(*get_nvt)(XiveFabric *xf, uint32_t server);
XiveEQ *(*get_eq)(XiveFabric *xf, uint32_t eq_idx);
} XiveFabricClass;It helps in making the routing algorithm independent of the model. I hope to make powernv converge and use it.
- a set of MMIOs for the TIMA. They model the presenter engine. current_cpu is used to retrieve the NVT object, which holds the registers for interrupt management.
The EQs are stored under the NVT. This saves us an unnecessary EQDT table. But we could add one under the XIVE device model.
Quoted 28 lines
Quoted 28 lines
I have merged these for simplicity and because the interrupt controller has an internal source for the interrupts of the "IPI" type, which are used for the CPU IPIs but also for other generic interrupts, like the OpenCAPI ones. The XIVE sPAPR interface is also much simpler than the baremetal one, all the tables are maintained in the hypervisor, so this choice made some sense.
But since, I have started the PowerNV model and I am duplicating a lot of code to handle the triggering and the MMIOs in the different sources. So I am not convinced anymore. Nevertheless, the overall routing logic is the same even if some the tables are not located in QEMU anymore, but in the machine memory.
The sPAPRXiveNVT models some of the CPU presenter engine. It holds the virtual CPU interrupt states when not dispatched on a real HW thread. Real world is more complex. There are "CAM" lines in the HW threads which are compared to find a matching candidate. But I don't think we need to anything more complex than today unless we want to support KVM under TCG ...
Quoted 3 lines
I suspect that's not what you
want - I had one of those for XICs which proved to be a mistake (eventually replaced by the XICSFabric interface).The XICSFabric would be the main Xive object. The interface between the sources and the routing engine is hidden in sPAPR, we can use a simple function call :
Quoted 5 lines
Quoted 3 lines
spapr_xive_irq(pnv->xive, irq);we could get rid of the qirqs but they are required for XICS.
I don't quite follow, but this doesn't sound right.
I don't remember what I had in mind at that time. Let's forget it.
Quoted 24 lines
Quoted 14 lines
PowerNV uses MMIOs to notify an event and it makes the modeling somewhat easier. Each controller model has a notify port address register on which a interrupt number is written to forward an event to the routing engine. So it is a simple store.
I don't know why there is a different notify port address per source, may be for extra filtering at the routing engine level.
Quoted 3 lines
Changing the model later isn't impossible, but doing so without breaking migration can be a real pain, so I think it's worth a reasonable effort to try and get it right initially.
I completely agree.
Quoted 9 lines
This is why I have started the PnvXive model to challenge the current PAPR design. I have hacked a bunch of patches for XIVE, LPC, PSI, OCC and basic PPC support which boot a PowerNV P9 up to petitboot. It would look better with a source object, but the location of the PQ bits is a bit problematic. It highly depends on the controller. The main controller uses tables in the hypervisor memory. The PSIHB controller has its own bits. I suppose it is the same for PHB4. I need to take a closer look at how we could have a common source object.
Quoted 1 line
Ok, sounds like a good idea.
I made progress and the spapr and powernv models are nearly reconciliated. the only difference in the routing algorithm is the privilege level at which the NVT notification is done. powernv work at the HV level.
Quoted 2 lines
Quoted 2 lines
The most important part is KVM support and how we expose the MMIO region. We need to make progress on that topic.
for KVM, a set of *_kvm objects handle the differences with the emulated mode. ram_device memory regions are needed for the ESB MMIO pages and the TIMA. That's mostly it.
C.
Quoted 305 lines
Quoted 304 lines
Thanks,
C.
Quoted 298 lines
Quoted 297 lines
---
Changes since v1 :
- used
g_new0instead ofg_malloc0
- removedVMSTATE_STRUCT_VARRAY_UINT32_ALLOC
- introduced a device reset handler. the object needs to be parented to sysbus when created.
- renamedspapr_xive_irq_settospapr_xive_irq_enable
- renamedspapr_xive_irq_unsettospapr_xive_irq_disable
- moved thePPC_BITmacros undertarget/ppc/cpu.h
- shrinked file copyright headerdefault-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/spapr_xive.c | 156 ++++++++++++++++++++++++++++++++++++++ hw/intc/xive-internal.h | 41 ++++++++++ include/hw/ppc/spapr_xive.h | 35 +++++++++ 5 files changed, 234 insertions(+) create mode 100644 hw/intc/spapr_xive.c create mode 100644 hw/intc/xive-internal.h create mode 100644 include/hw/ppc/spapr_xive.hdefault-configs/ppc64-softmmu.mak +1
-0@@ -56,6 +56,7 @@ CONFIG_SM501=y CONFIG_XICS=$(CONFIG_PSERIES) CONFIG_XICS_SPAPR=$(CONFIG_PSERIES) CONFIG_XICS_KVM=$(call land,$(CONFIG_PSERIES),$(CONFIG_KVM)) +CONFIG_XIVE_SPAPR=$(CONFIG_PSERIES) # For PReP CONFIG_SERIAL_ISA=y CONFIG_MC146818RTC=yhw/intc/Makefile.objs +1
-0@@ -35,6 +35,7 @@ obj-$(CONFIG_SH4) += sh_intc.o obj-$(CONFIG_XICS) += xics.o obj-$(CONFIG_XICS_SPAPR) += xics_spapr.o obj-$(CONFIG_XICS_KVM) += xics_kvm.o +obj-$(CONFIG_XIVE_SPAPR) += spapr_xive.o obj-$(CONFIG_POWERNV) += xics_pnv.o obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o obj-$(CONFIG_S390_FLIC) += s390_flic.ohw/intc/spapr_xive.c new file +156
-0@@ -0,0 +1,156 @@ +/* +* QEMU PowerPC sPAPR XIVE interrupt controller model +* +* Copyright (c) 2017, IBM Corporation. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qapi/error.h" +#include "target/ppc/cpu.h" +#include "sysemu/cpus.h" +#include "sysemu/dma.h" +#include "monitor/monitor.h" +#include "hw/ppc/spapr_xive.h" + +#include "xive-internal.h" + +/* +* Main XIVE object +*/ + +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon) +{ +int i; + +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; + +if (!(ive->w &IVE_VALID )) { +continue ; + } + +monitor_printf (mon," %4x %s %08x %08x\n" , i, + ive->w &IVE_MASKED ?"M" :" " , + (int )GETFIELD (IVE_EQ_INDEX , ive->w), + (int )GETFIELD (IVE_EQ_DATA , ive->w)); + } +} + +static void spapr_xive_reset (DeviceState *dev) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); +int i; + +/* Mask all valid IVEs in the IRQ number space. */ +for (i =0 ; i < xive->nr_irqs; i++) { +XiveIVE *ive = &xive->ivt[i]; +if (ive->w &IVE_VALID ) { + ive->w |=IVE_MASKED ; + } + } +} + +static void spapr_xive_realize (DeviceState *dev,Error **errp) +{ +sPAPRXive *xive =SPAPR_XIVE (dev); + +if (!xive->nr_irqs) { +error_setg (errp,"Number of interrupt needs to be greater 0" ); +return ; + } + +/* Allocate the IVT (Interrupt Virtualization Table) */ + xive->ivt =g_new0 (XiveIVE, xive->nr_irqs); +} + +static const VMStateDescription vmstate_spapr_xive_ive = { + .name =TYPE_SPAPR_XIVE "/ive" , + .version_id =1 , + .minimum_version_id =1 , + .fields = (VMStateField []) { +VMSTATE_UINT64 (w, XiveIVE), +VMSTATE_END_OF_LIST () + }, +}; + +static bool vmstate_spapr_xive_needed (void *opaque) +{ +/* TODO check machine XIVE support */ +return true; +} + +static const VMStateDescription vmstate_spapr_xive = { + .name =TYPE_SPAPR_XIVE , + .version_id =1 , + .minimum_version_id =1 , + .needed = vmstate_spapr_xive_needed, + .fields = (VMStateField []) { +VMSTATE_UINT32_EQUAL (nr_irqs, sPAPRXive,NULL ), +VMSTATE_STRUCT_VARRAY_UINT32 (ivt, sPAPRXive, nr_irqs,1 , + vmstate_spapr_xive_ive, XiveIVE), +VMSTATE_END_OF_LIST () + }, +}; + +static Property spapr_xive_properties[] = { +DEFINE_PROP_UINT32 ("nr-irqs" , sPAPRXive, nr_irqs,0 ), +DEFINE_PROP_END_OF_LIST (), +}; + +static void spapr_xive_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->realize = spapr_xive_realize; + dc->reset = spapr_xive_reset; + dc->props = spapr_xive_properties; + dc->desc ="sPAPR XIVE interrupt controller" ; + dc->vmsd = &vmstate_spapr_xive; +} + +static const TypeInfo spapr_xive_info = { + .name =TYPE_SPAPR_XIVE , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (sPAPRXive), + .class_init = spapr_xive_class_init, +}; + +static void spapr_xive_register_types (void ) +{ +type_register_static (&spapr_xive_info); +} + +type_init (spapr_xive_register_types) + +XiveIVE *spapr_xive_get_ive(sPAPRXive *xive, uint32_t lisn) +{ +return lisn < xive->nr_irqs ? &xive->ivt[lisn] :NULL ; +} + +bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) { +return false; + } + + ive->w |=IVE_VALID ; +return true; +} + +bool spapr_xive_irq_disable (sPAPRXive *xive,uint32_t lisn) +{ +XiveIVE *ive =spapr_xive_get_ive (xive, lisn); + +if (!ive) { +return false; + } + + ive->w &= ~IVE_VALID ; +return true; +}hw/intc/xive-internal.h new file +41
-0@@ -0,0 +1,41 @@ +/* +* QEMU PowerPC XIVE interrupt controller model +* +* Copyright (c) 2016-2017, IBM Corporation. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +*/ + +#ifndef _INTC_XIVE_INTERNAL_H +#define _INTC_XIVE_INTERNAL_H + +/* Utilities to manipulate these (originaly from OPAL) */ +#define MASK_TO_LSH (m) (__builtin_ffsl(m) - 1) +#define GETFIELD (m, v) (((v) & (m)) >> MASK_TO_LSH(m)) +#define SETFIELD (m, v, val) \ + (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m))) + +/* IVE/EAS +* +* One per interrupt source. Targets that interrupt to a given EQ +* and provides the corresponding logical interrupt number (EQ data) +* +* We also map this structure to the escalation descriptor inside +* an EQ, though in that case the valid and masked bits are not used. +*/ +typedef struct XiveIVE { +/* Use a single 64-bit definition to make it easier to +* perform atomic updates +*/ +uint64_t w; +#define IVE_VALID PPC_BIT(0) +#define IVE_EQ_BLOCK PPC_BITMASK(4, 7)/* Destination EQ block# */ +#define IVE_EQ_INDEX PPC_BITMASK(8, 31)/* Destination EQ index */ +#define IVE_MASKED PPC_BIT(32)/* Masked */ +#define IVE_EQ_DATA PPC_BITMASK(33, 63)/* Data written to the EQ */ +}XiveIVE ; + +XiveIVE *spapr_xive_get_ive (sPAPRXive *xive,uint32_t lisn); + +#endif /* _INTC_XIVE_INTERNAL_H */ include/hw/ppc/spapr_xive.h new file +35
-0@@ -0,0 +1,35 @@ +/* +* QEMU PowerPC sPAPR XIVE interrupt controller model +* +* Copyright (c) 2017, IBM Corporation. +* +* This code is licensed under the GPL version 2 or later. See the +* COPYING file in the top-level directory. +*/ + +#ifndef PPC_SPAPR_XIVE_H +#define PPC_SPAPR_XIVE_H + +#include <hw/sysbus.h> + +typedef struct sPAPRXive sPAPRXive ; +typedef struct XiveIVE XiveIVE ; + +#define TYPE_SPAPR_XIVE "spapr-xive" +#define SPAPR_XIVE (obj) OBJECT_CHECK(sPAPRXive, (obj), TYPE_SPAPR_XIVE) + +struct sPAPRXive { +SysBusDevice parent; + +/* Properties */ +uint32_t nr_irqs; + +/* XIVE internal tables */ +XiveIVE *ivt; +}; + +bool spapr_xive_irq_enable (sPAPRXive *xive,uint32_t lisn); +bool spapr_xive_irq_disable (sPAPRXive *xive,uint32_t lisn); +void spapr_xive_pic_print_info (sPAPRXive *xive,Monitor *mon); + +#endif /* PPC_SPAPR_XIVE_H */
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to David GibsonQuoted 34 lines · David Gibson
Quoted 33 lines · Benjamin Herrenschmidt
Quoted 6 lines · David Gibson
As you've suggested in yourself, I think we might need to more explicitly model the different components of the XIVE system. As part of that, I think you need to be clearer in this base skeleton about exactly what component your XIVE object represents.
Quoted 7 lines
If the answer is "the overall thing" I suspect that's not what you want - I had one of those for XICs which proved to be a mistake (eventually replaced by the XICSFabric interface).
Changing the model later isn't impossible, but doing so without breaking migration can be a real pain, so I think it's worth a reasonable effort to try and get it right initially.
Note: we do need to speed things up a bit, as having exploitation mode in KVM will significantly help with IPI performance among other things.
I'm about ready to do the KVM bits. The one thing we need to discuss and figure a good design for is how we map all those interrupt control pages into qemu.
Each interrupt (either PCIe pass-through or the "generic XIVE IPIs" which are used for guest IPIs and for vio/virtio/emulated interrupts) comes with a "control page" (ESB page) which needs to be mapped into the guest, and the generic IPIs also come with a trigger page which needs to be mapped into the guest for guest IPIs or OpenCAPI interrupts, or just qemu for emulated devices.
Now that can be thousands of these critters. I certainly don't want to create thousands of VMAs in qemu and even less thousands of memory regions in KVM.
Quoted 7 lines
Quoted 4 lines
So we need some kind of mechanism by wich a single large VMA gets mmap'ed into qemu (or maybe a couple of these, but not too many) and the interrupt pages can be assigned to slots in there and demand faulted.
Ok, I see your point. We'll definitely need to be able to map things in as a block, rather than one by one.
So, the approach taken is to use a mmap() exposed in a single ram_device memory region to the guest. The size is the irq number space size. This is hardcoded to 4096 (IPIs) + 1024 (virtual device interrupts) in QEMU. We can change that, but the 4K split is important for XICS compatibility. The kvm xive device should self adapt.
C.
Quoted 18 lines
Quoted 17 lines
For the generic interrupts, this can probably be covered by KVM, adding some arch ioctls for allocating IPIs and mmap'ing that region etc...
For pass-through, it's trickier, we don't want to mmap each irqfd individually for the above reason, so we want to "link" them to KVM. We don't want to allow qemu to take control of any arbitrary interrupt in the system though, so it has to related to the ownership of the irqfd coming from vfio.
OpenCAPI I suspect will be its own can of worms...
Also, have we decided how the process of switching between XICS and XIVE will work vs. CAS ? And how that will interact with KVM ? I was thinking the kernel would implement a different KVM device type, ie the "emulated XICS" would remain
KVM_DEV_TYPE_XICSand XIVE would beKVM_DEV_TYPE_XIVE.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to David GibsonQuoted 25 lines · David Gibson
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 7 lines · David Gibson
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Cédric Le Goater
Migration is a problem. We will need both backend QEMU objects to be available anyhow if we want to migrate. So we are back to the current solution creating both QEMU objects but we can try to defer some of the KVM inits and create the KVM device on demand at CAS time.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Do we have a way to migrate a piece of info from the machine *first* that indicate what type of XICS/XIVE to instanciate ?
Nope. qemu migration doesn't work like that. Yes, it should, and everyone knows it, but changing it is a really long term project.
Well, we have a problem then. It looks like Qemu broken migration is fundamentally incompatible with PAPR and CAS design...
Hrm, the fit is very clunky certainly, but i think we can make it work.
Quoted 4 lines
I know we don't migrate the configuration, that's not exactly what I had in mind tho... Can we have some piece of *data* from the machine be migrated first, and use it on the target to reconfigure the interrupt controller before the stream arrives ?
Quoted 8 lines
Sorta.. maybe.. but it would probably get really ugly if we don't preserve the usual way object lifetimes work.
Quoted 2 lines
Otherwise, we have indeed no much choice but the horrible wart of creating both interrupt controllers with only one "active".
I really think this is the way to go, warts and all.
Yes ... KVM makes it a little uglier.
A KVM_DEVICE_DESTROY device is needed to cleanup the VM and a DISABLE_CAP to disconnect the vpcu from the current KVM XIVE/XICS device. I have used an extra arg on ENABLE_CAP for the moment.
At the QEMU level, we need to connect/reconnect at reset time to handle possible changes in CAS, and at post_load.
Destroying the MemoryRegion is a bit problematic, I have not found a common layout compatible with both the emulated mode (std IO regions) and the KVM mode (ram device regions)
C.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to David GibsonQuoted 23 lines · David Gibson
Quoted 22 lines · Cédric Le Goater
Quoted 9 lines
Quoted 9 lines
Quoted 2 lines
Also, have we decided how the process of switching between XICS and XIVE will work vs. CAS ?
That's how it is described in the architecture. The current choice is to create both XICS and XIVE objects and choose at CAS which one to use. It relies today on the capability of the pseries machine to allocate IRQ numbers for both interrupt controller backends. These patches have been merged in QEMU.
Quoted 5 lines
Quoted 3 lines
A change of interrupt mode results in a reset. The device tree is populated accordingly and the ICPs are switched for the model in use.
For KVM we need to only instanciate one of them though.
Hmm,
How would we handle a guest rebooting on a kernel without XIVE support ? Are you suggesting to create the XICS or XIVE device in the CAS negotiation process ? So, the machine would not have any interrupt controller before CAS. That seems really late to me. grub uses the console for instance.
Quoted 5 lines
Quoted 2 lines
I think it should prepare for both options, start in XIVE legacy mode, which is XICS, then possibly switch to XIVE exploitation mode.
I think for our first draft we should have XIVE and XICS based platforms as separate machine types (or a machine option, I guess).
OK. This is my current choice for KVM.
Emulated mode is rather simple to handle, and this is why I have kept the reset after CAS if there is a change in the interrupt mode.
Quoted 3 lines
We do want to allow this to be autonegotiated, but I feel like emphasising that at the beginning is causing unnatural design decisions in the XIVE model itself.
Yes. This is mostly a KVM problem which also has impacts on XICS of course ...
C.
Quoted 31 lines
Quoted 30 lines
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
And how that will interact with KVM ?
I expect we will do the same, which is to create two KVM devices to be able to handle both interrupt controller backends depending on the mode negotiated by the guest.
That will be an ungodly mess, I'd rather we only instanciate the right one.
It's rather transparent currently in the emulated version. There are two sets of objects in QEMU, switching is done in CAS. KVM support should not change anything in that area.
I expect the 'xive-kvm' object to get/set states for migration, just like for XICS and to setup the ESB+TIMA memory regions, which is new.
C.
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
I was
thinking the kernel would implement a different KVM device type, ie the "emulated XICS" would remainKVM_DEV_TYPE_XICSand XIVE would beKVM_DEV_TYPE_XIVE.yes. it makes sense. The new device will have a lot in common with the
KVM_DEV_TYPE_XICSusingkvm_xive_ops.Ben.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to David GibsonQuoted 24 lines · David Gibson
Quoted 23 lines · Cédric Le Goater
Quoted 21 lines · Benjamin Herrenschmidt
Quoted 13 lines · Cédric Le Goater
Quoted 13 lines
Quoted 12 lines
Quoted 2 lines
Also, have we decided how the process of switching between XICS and XIVE will work vs. CAS ?
That's how it is described in the architecture. The current choice is to create both XICS and XIVE objects and choose at CAS which one to use. It relies today on the capability of the pseries machine to allocate IRQ numbers for both interrupt controller backends. These patches have been merged in QEMU.
A change of interrupt mode results in a reset. The device tree is populated accordingly and the ICPs are switched for the model in use.
Quoted 5 lines
Quoted 1 line
For KVM we need to only instanciate one of them though.
Hmm,
How would we handle a guest rebooting on a kernel without XIVE support ?
It will do CAS again and we can change the devices.
Quoted 7 lines
Quoted 4 lines
So, we would destroy the previous QEMU ICS object and create a new one in the CAS hcall. That would probably work. There might be some issues in creating and destroying the ICS KVM device, but that can be studied without XIVE.
Adding and removing devices at runtime based on guest requests like this will get really hairy in qemu.
I confirm ...
Quoted 2 lines
As I've said before for the first cut, I think we want to select just one as a machine option to avoid this confusion.
OK
Quoted 3 lines
Looking further ahead, I think we'll be better off having both the XIVE and XICS models always present (at least minimally) in qemu, but with only one "active" at any given time.
Under emulation it is not too complex to support both mode. XIVE and XICS objects are both created but spapr->ov5_cas filters their usage
However, syncing the change in KVM is more complex.
Quoted 3 lines
Note that having the inactive one destroy and clean up the corresponding KVM devices is fine, as is deallocating as much of its runtime state as we can without changing the notional QOM tree.
yes. I will try to send a patchset organized that way :
- spapr XIVE emulated mode (both mode supported)
- XIVE KVM in an exclusive way, the machine will need to be restarted from the command line to change interrupt mode.
- support of change of interrupt mode under KVM
- powernv device model (rough)
C.
Quoted 75 lines
Quoted 74 lines
It used to be considered ugly to create a QEMU device at reset time, so I wonder if this is still the case, because when the machine reaches CAS, we really are beyond reset.
If this is OK, then the next "issue" is to keep in sync the allocated IRQ numbers. The IRQ allocator is now merged at the machine level, so the synchronization is obvious to do when both backend QEMU objects are available. that's the path I took. If both QEMU objects are not available, then we need to scan the IRQ number space in the current interrupt mode and allocate the same IRQs in the newly negotiated mode. Probably OK. I don't see major problems with the current code.
Migration is a problem. We will need both backend QEMU objects to be available anyhow if we want to migrate. So we are back to the current solution creating both QEMU objects but we can try to defer some of the KVM inits and create the KVM device on demand at CAS time.
The next problem is the ICP object that currently needs the KVM device fd to connect the vcpus ... So, we will need to change that also. That is probably the biggest problem today. We need a way to disconnect the vpcu from the KVM device and see how we can defer the connection. I need to make sure this is possible, I can check that without XIVE I think.
Quoted 5 lines
Quoted 3 lines
Are you suggesting to create the XICS or XIVE device in the CAS negotiation process ? So, the machine would not have any interrupt controller before CAS. That seems really late to me. grub uses the console for instance.
We start with XICS by default.
yes.
Quoted 16 lines
Quoted 16 lines
I think it should prepare for both options, start in XIVE legacy mode, which is XICS, then possibly switch to XIVE exploitation mode.
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
And how that will interact with KVM ?
I expect we will do the same, which is to create two KVM devices to be able to handle both interrupt controller backends depending on the mode negotiated by the guest.
That will be an ungodly mess, I'd rather we only instanciate the right one.
It's rather transparent currently in the emulated version. There are two sets of objects in QEMU, switching is done in CAS. KVM support should not change anything in that area.
Quoted 8 lines
Quoted 2 lines
I expect the 'xive-kvm' object to get/set states for migration, just like for XICS and to setup the ESB+TIMA memory regions, which is new.
But both XICS and XIVE are completely different kernel KVM devices that will need to "hook" into the same set of internal hooks for things like interrupts being passed through, RTAS calls etc...
How does KVM knows which one to "activate" ?
Can't we add an extra IRQ type and use
vcpu->arch.irq_typefor that ? I haven't studied all the low level details though.Quoted 1 line
I don't think the kernel should have both.
I hear that. From a QEMU perspective, it is much easier to put everything in place for both interrupt modes and let the guest decide what it wants to use.
If we choose not to, we will need to find solution to defer the KVM inits and to disconnect/reconnect the vcpus. For the latter, we could add a
KVM_DISABLE_CAPioctl or maybe better add a new capability likeKVM_CAP_IRQ_XIVEto perform the switch.C.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Cédric Le GoaterQuoted 73 lines · Cédric Le Goater
Quoted 30 lines · David Gibson
Quoted 29 lines · Cédric Le Goater
Quoted 28 lines · David Gibson
Quoted 27 lines · Cédric Le Goater
With the POWER9 processor comes a new interrupt controller called XIVE. It is composed of three sub-engines :
- Interrupt Virtualization Source Engine (IVSE). These are in PHBs, in the main controller for the IPIS and in the PSI host bridge. They are configured to feed the IVRE with events.
- Interrupt Virtualization Routing Engine (IVRE). Their job is to match an event source with a Notification Virtualization Target (NVT), a priority and an Event Queue (EQ) to determine if a Virtual Processor can handle the event.
- Interrupt Virtualization Presentation Engine (IVPE). It maintains the interrupt state of each hardware thread and present the notification as an external exception.
Each of the engines uses a set of internal tables to redirect exceptions from event sources to CPU threads. The first table we introduce is the Interrupt Virtualization Entry (IVE) table, part of the virtualization engine in charge of routing events. It associates event sources (IRQ numbers) to event queues which will forward, or not, the event notification to the presentation controller.
The XIVE model is designed to make use of the full range of the IRQ number space and does not use an offset like the XICS mode does. Hence, the IVE table is directly indexed by the IRQ number.
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Signed-off-by Cédric Le Goater <[email protected]>As you've suggested in yourself, I think we might need to more explicitly model the different components of the XIVE system. As part of that, I think you need to be clearer in this base skeleton about exactly what component your XIVE object represents.
Sorry it's been so long since I looked at these.
That's fine. I have been working on a XIVE device model for the PowerNV machine and KVM support for the pseries. I have a better understanding of the overall picture.
The patchset has not changed much so we can still discuss on this basis without me flooding the mailing list.
Quoted 7 lines
Quoted 7 lines
ok. The base skeleton is the IVRE, the central engine handling the routing.
Quoted 1 line
If the answer is "the overall thing"
Yes, it is more or less that currently.
Quoted 8 lines
Quoted 2 lines
The sPAPRXive object models the source engine and the routing engine in one object.
Yeah, I suspect we don't want that. Although it might seem simpler in the spapr case, at least at first glance, I think it will cause us problems later. At the very least, it's likely to make it harder to share code between the spapr and powernv case. I think it will also make for more confusion about exactly what things belong where.
I tend to agree.
We need to clarify (a bit) what is in the XIVE interrupt controller silicon, and how XIVE works. The XIVE device models for spapr and powernv should be very close as the differences are small. KVM support should be built on the spapr model.
There are 3 different sub-engines in the XIVE interrupt controller device :
Quoted 7 lines
* IVSE (XiveSource model)
interrupt sources, which expose their PQ bits through ESB MMIO pages (there are different levels of support depending on HW revision)
The XIVE interrupt controller has a set of internal sources for IPIs and CAPI like interrupts.
Ok. IIUC in hardware there's one of these in each PHB, plus maybe one or two others. Is that right?
Quoted 7 lines
* IVRE (No real model)
in the middle, doing the routing of source event notification to (cpu) targets. It relies on internal tables which are stored in the hypervisor/QEMU/KVM for the spapr machine and in the VM RAM for the powernv machine.
What does VM RAM mean in the powernv context?
Quoted 8 lines
Configuration updates of the XIVE tables are done through hcalls on spapr and with MMIOs on the IC regs on powernv. On the latter, the changes are flushed backed in the VM RAM.
* IVPE (XiveNVT)
set of registers for interrupt management at the CPU level. Exposed in a specific MMIO region called the TIMA.
Ok.
Quoted 6 lines
The XIVE tables are :
* IVT
associate an interrupt source number with an event queue. the data to be pushed in the queue is stored there also.
Ok, so there would be one of these tables for each IVRE, with one entry for each source managed by that IVSE, yes?
Do the XIVE IPIs have entries here, or do they bypass this?
Quoted 4 lines
* EQDT:
describes the queues in the OS RAM, also contains a set of flags, a virtual target, etc.
So on real hardware this would be global, yes? And it would be consulted by the IVRE?
For guests, we'd expect one table per-guest? How would those be integrated with the host table?
Quoted 5 lines
* VPDT:
describe the virtual targets, which can have different natures, a lpar, a cpu. This is for powernv, spapr does not have this concept.
Ok On hardware that would also be global and consulted by the IVRE, yes?
Under PAPR, I'm guessing the concept is missing because it essentially has a fixed contents: an entry for each vcpu and maybe one for the lpar as a whole?
Quoted 2 lines
So, the idea behind the sPAPRXive object is to model a XIVE interrupt controller device. It contains today :
Yeah, what a "XIVE interrupt controller device" is not really clear to me. If it's something that is necessarily global, I think you'll be better off making it a machine-interface rather than a distinct object.
Quoted 11 lines
- an internal source block for all interrupts : IPIs and virtual device interrupts. In the IRQ number space, the IPIs are below 4096 and the device interrupts above, which keeps compatibility with XICS. This is important to be able to change interrupt mode.
PowerNV has different source blocks, like for P8.
- a routing engine, which is limited to the IVT. This is a shortcut and it might be better to introduce a specific object. Anyhow, this is a state to capture.
Ok. It sounds like this is roughly the equivalent of the XICSFabric, and likewise would probably be better handled by an interface on the machine rather than a distinct object. But I'm not clear enough to be certain of that yet.
Quoted 6 lines
In the current version I am working on, the XiveFabric interface is
more complex :
typedef struct XiveFabricClass {
InterfaceClass parent;
XiveIVE *(*get_ive)(XiveFabric *xf, uint32_t lisn);This does an IVT lookup, I take it?
Quoted 1 line
XiveNVT *(*get_nvt)(XiveFabric *xf, uint32_t server);
This one a VPDT lookup, yes?
Quoted 1 line
XiveEQ *(*get_eq)(XiveFabric *xf, uint32_t eq_idx);
And this one an EQDT lookup?
Quoted 8 lines
} XiveFabricClass;It helps in making the routing algorithm independent of the model. I hope to make powernv converge and use it.
- a set of MMIOs for the TIMA. They model the presenter engine.
current_cpuis used to retrieve the NVT object, which holds the registers for interrupt management.
Right. Now the TIMA is local to a target/server not an EQ, right?
I guess we need at least one of these per-vcpu. Do we also need an lpar-global, or other special ones?
Quoted 2 lines
The EQs are stored under the NVT. This saves us an unnecessary EQDT table. But we could add one under the XIVE device model.
I'm not sure of the distinction you're drawing between the NVT and the XIVE device mode.
[snip]
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to Cédric Le GoaterQuoted 35 lines · Cédric Le Goater
Quoted 25 lines · David Gibson
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 7 lines · David Gibson
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Cédric Le Goater
Migration is a problem. We will need both backend QEMU objects to be available anyhow if we want to migrate. So we are back to the current solution creating both QEMU objects but we can try to defer some of the KVM inits and create the KVM device on demand at CAS time.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Do we have a way to migrate a piece of info from the machine *first* that indicate what type of XICS/XIVE to instanciate ?
Nope. qemu migration doesn't work like that. Yes, it should, and everyone knows it, but changing it is a really long term project.
Well, we have a problem then. It looks like Qemu broken migration is fundamentally incompatible with PAPR and CAS design...
Hrm, the fit is very clunky certainly, but i think we can make it work.
Quoted 4 lines
I know we don't migrate the configuration, that's not exactly what I had in mind tho... Can we have some piece of *data* from the machine be migrated first, and use it on the target to reconfigure the interrupt controller before the stream arrives ?
Quoted 8 lines
Sorta.. maybe.. but it would probably get really ugly if we don't preserve the usual way object lifetimes work.
Quoted 2 lines
Otherwise, we have indeed no much choice but the horrible wart of creating both interrupt controllers with only one "active".
I really think this is the way to go, warts and all.
Quoted 8 lines
Yes ... KVM makes it a little uglier.
A
KVM_DEVICE_DESTROYdevice is needed to cleanup the VM and aDISABLE_CAPto disconnect the vpcu from the current KVM XIVE/XICS device. I have used an extra arg onENABLE_CAPfor the moment.At the QEMU level, we need to connect/reconnect at reset time to handle possible changes in CAS, and at
post_load.
Right.
Quoted 3 lines
Destroying the MemoryRegion is a bit problematic, I have not found a common layout compatible with both the emulated mode (std IO regions) and the KVM mode (ram device regions)
That sounds awkward, I guess we'll discuss the details of this later.
Btw, a secondary advantage of starting off with XIVE only under a different machine type is that we can declare that one not to be migration stable until we're ready. So we can merge something that's ok to experiment with, but reserve the right to incompatibly change the migration format until we're confident we're ready and can merge it into the "stable" machine type.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 38 lines · David Gibson
Quoted 37 lines · Cédric Le Goater
Quoted 25 lines · David Gibson
Quoted 8 lines · Benjamin Herrenschmidt
Quoted 7 lines · David Gibson
Quoted 6 lines · Benjamin Herrenschmidt
Quoted 4 lines · Cédric Le Goater
Migration is a problem. We will need both backend QEMU objects to be available anyhow if we want to migrate. So we are back to the current solution creating both QEMU objects but we can try to defer some of the KVM inits and create the KVM device on demand at CAS time.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Do we have a way to migrate a piece of info from the machine *first* that indicate what type of XICS/XIVE to instanciate ?
Nope. qemu migration doesn't work like that. Yes, it should, and everyone knows it, but changing it is a really long term project.
Well, we have a problem then. It looks like Qemu broken migration is fundamentally incompatible with PAPR and CAS design...
Hrm, the fit is very clunky certainly, but i think we can make it work.
Quoted 4 lines
I know we don't migrate the configuration, that's not exactly what I had in mind tho... Can we have some piece of *data* from the machine be migrated first, and use it on the target to reconfigure the interrupt controller before the stream arrives ?
Quoted 8 lines
Sorta.. maybe.. but it would probably get really ugly if we don't preserve the usual way object lifetimes work.
Quoted 2 lines
Otherwise, we have indeed no much choice but the horrible wart of creating both interrupt controllers with only one "active".
I really think this is the way to go, warts and all.
Yes ... KVM makes it a little uglier.
Quoted 8 lines
Quoted 6 lines
A
KVM_DEVICE_DESTROYdevice is needed to cleanup the VM and aDISABLE_CAPto disconnect the vpcu from the current KVM XIVE/XICS device. I have used an extra arg onENABLE_CAPfor the moment.At the QEMU level, we need to connect/reconnect at reset time to handle possible changes in CAS, and at
post_load.Right.
v3 uses the same 'reset' function to setup the interrupts at machine reset time and at post_load. Keep that in mind. May be we should have distinct routines.
Quoted 6 lines
Quoted 4 lines
Destroying the MemoryRegion is a bit problematic, I have not found a common layout compatible with both the emulated mode (std IO regions) and the KVM mode (ram device regions)
That sounds awkward, I guess we'll discuss the details of this later.
I have fixed that in v3.
Quoted 6 lines
Btw, a secondary advantage of starting off with XIVE only under a different machine type is that we can declare that one not to be migration stable until we're ready. So we can merge something that's ok to experiment with, but reserve the right to incompatibly change the migration format until we're confident we're ready and can merge it into the "stable" machine type.
Reseting KVM devices is not the most complex feature to support but it seems to have an impact on migration. So we might need the non-migratable machine type to fix that. Let's see how v3 is welcomed or not.
Thanks,
C.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
In reply to David GibsonQuoted 76 lines · David Gibson
Quoted 75 lines · Cédric Le Goater
Quoted 30 lines · David Gibson
Quoted 29 lines · Cédric Le Goater
Quoted 28 lines · David Gibson
Quoted 27 lines · Cédric Le Goater
With the POWER9 processor comes a new interrupt controller called XIVE. It is composed of three sub-engines :
- Interrupt Virtualization Source Engine (IVSE). These are in PHBs, in the main controller for the IPIS and in the PSI host bridge. They are configured to feed the IVRE with events.
- Interrupt Virtualization Routing Engine (IVRE). Their job is to match an event source with a Notification Virtualization Target (NVT), a priority and an Event Queue (EQ) to determine if a Virtual Processor can handle the event.
- Interrupt Virtualization Presentation Engine (IVPE). It maintains the interrupt state of each hardware thread and present the notification as an external exception.
Each of the engines uses a set of internal tables to redirect exceptions from event sources to CPU threads. The first table we introduce is the Interrupt Virtualization Entry (IVE) table, part of the virtualization engine in charge of routing events. It associates event sources (IRQ numbers) to event queues which will forward, or not, the event notification to the presentation controller.
The XIVE model is designed to make use of the full range of the IRQ number space and does not use an offset like the XICS mode does. Hence, the IVE table is directly indexed by the IRQ number.
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Signed-off-by Cédric Le Goater <[email protected]>As you've suggested in yourself, I think we might need to more explicitly model the different components of the XIVE system. As part of that, I think you need to be clearer in this base skeleton about exactly what component your XIVE object represents.
Sorry it's been so long since I looked at these.
That's fine. I have been working on a XIVE device model for the PowerNV machine and KVM support for the pseries. I have a better understanding of the overall picture.
The patchset has not changed much so we can still discuss on this basis without me flooding the mailing list.
Quoted 7 lines
Quoted 7 lines
ok. The base skeleton is the IVRE, the central engine handling the routing.
Quoted 1 line
If the answer is "the overall thing"
Yes, it is more or less that currently.
Quoted 8 lines
Quoted 2 lines
The sPAPRXive object models the source engine and the routing engine in one object.
Yeah, I suspect we don't want that. Although it might seem simpler in the spapr case, at least at first glance, I think it will cause us problems later. At the very least, it's likely to make it harder to share code between the spapr and powernv case. I think it will also make for more confusion about exactly what things belong where.
I tend to agree.
We need to clarify (a bit) what is in the XIVE interrupt controller silicon, and how XIVE works. The XIVE device models for spapr and powernv should be very close as the differences are small. KVM support should be built on the spapr model.
There are 3 different sub-engines in the XIVE interrupt controller device :
* IVSE (XiveSource model)
Quoted 7 lines
Quoted 5 lines
interrupt sources, which expose their PQ bits through ESB MMIO pages (there are different levels of support depending on HW revision)
The XIVE interrupt controller has a set of internal sources for IPIs and CAPI like interrupts.
Ok. IIUC in hardware there's one of these in each PHB,
yes
Quoted 1 line
plus maybe one or two others. Is that right?
yes. PSI for instance on PowerNV. I have this device as a first xive source on Power?V
Quoted 9 lines
Quoted 7 lines
* IVRE (No real model)
in the middle, doing the routing of source event notification to (cpu) targets. It relies on internal tables which are stored in the hypervisor/QEMU/KVM for the spapr machine and in the VM RAM for the powernv machine.
What does VM RAM mean in the powernv context?
The PowerNV is indeed not a VM. So I meant the RAM of the QEMU PowerNV machine. skiboot does the allocation and the HW setup using a set of IC registers exposed as MMIOs.
Quoted 11 lines
Quoted 8 lines
Configuration updates of the XIVE tables are done through hcalls on spapr and with MMIOs on the IC regs on powernv. On the latter, the changes are flushed backed in the VM RAM.
* IVPE (XiveNVT)
set of registers for interrupt management at the CPU level. Exposed in a specific MMIO region called the TIMA.
Ok.
Quoted 8 lines
Quoted 6 lines
The XIVE tables are :
* IVT
associate an interrupt source number with an event queue. the data to be pushed in the queue is stored there also.
Ok, so there would be one of these tables for each IVRE,
yes. one for each XIVE interrupt controller. That is one per processor or socket.
Quoted 1 line
with one entry for each source managed by that IVSE, yes?
yes. The table is simply indexed by the interrupt number in the global IRQ number space of the machine.
Quoted 1 line
Do the XIVE IPIs have entries here, or do they bypass this?
no. The IPIs have entries also in this table.
Quoted 7 lines
Quoted 4 lines
* EQDT:
describes the queues in the OS RAM, also contains a set of flags, a virtual target, etc.
So on real hardware this would be global, yes? And it would be consulted by the IVRE?
yes. Exactly. The XIVE routing routine :
https://github.com/legoater/qemu/blob/xive/hw/intc/xive.c#L706
gives a good overview of the usage of the tables.
Quoted 1 line
For guests, we'd expect one table per-guest?
yes but only in emulation mode.
Quoted 1 line
How would those be integrated with the host table?
Under KVM, this is handled by the host table (setup done in skiboot) and we are only interested in the state of the EQs for migration. This state is set with the H_INT_SET_QUEUE_CONFIG hcall, followed by an OPAL call and then a HW update. It defines the EQ page in which to push event notification for the couple server/priority.
Quoted 8 lines
Quoted 5 lines
* VPDT:
describe the virtual targets, which can have different natures, a lpar, a cpu. This is for powernv, spapr does not have this concept.
Ok On hardware that would also be global and consulted by the IVRE, yes?
yes.
Quoted 2 lines
Under PAPR, I'm guessing the concept is missing because it essentially has a fixed contents: an entry for each vcpu
yes.
Quoted 1 line
and maybe one for the lpar as a whole?
That would be more a host concept. But, yes, it exists in XIVE.
Quoted 7 lines
Quoted 2 lines
So, the idea behind the sPAPRXive object is to model a XIVE interrupt controller device. It contains today :
Yeah, what a "XIVE interrupt controller device" is not really clear to me. If it's something that is necessarily global, I think you'll be better off making it a machine-interface rather than a distinct object.
hmm, OK. We do need a XiveSource object (like in the XICS) and an IVE table. reshuffling is not a big problem. But then, we also have the associated KVM device which is very much like the QEMU emulated device.
Quoted 7 lines
Quoted 7 lines
- an internal source block for all interrupts : IPIs and virtual device interrupts. In the IRQ number space, the IPIs are below 4096 and the device interrupts above, which keeps compatibility with XICS. This is important to be able to change interrupt mode.
PowerNV has different source blocks, like for P8.
Quoted 7 lines
Quoted 3 lines
- a routing engine, which is limited to the IVT. This is a shortcut and it might be better to introduce a specific object. Anyhow, this is a state to capture.
Ok. It sounds like this is roughly the equivalent of the XICSFabric, and likewise would probably be better handled by an interface on the machine
yes indeed. it is the case in v3. PowerNV isn't quite in sync with this concept but it is getting close.
Quoted 2 lines
rather than a distinct object. But I'm not clear enough to be certain of that yet.
but we need to put the IVT somewhere.
Quoted 8 lines
Quoted 6 lines
In the current version I am working on, the XiveFabric interface is more complex : typedef struct XiveFabricClass { InterfaceClass parent; XiveIVE *(*get_ive)(XiveFabric *xf, uint32_t lisn);This does an IVT lookup, I take it?
yes. It is an interface for the underlying storage, which is different in sPAPR and PowerNV. The goal is to make the routing generic.
Quoted 3 lines
Quoted 1 line
XiveNVT *(*get_nvt)(XiveFabric *xf, uint32_t server);This one a VPDT lookup, yes?
yes.
Quoted 3 lines
Quoted 1 line
XiveEQ *(*get_eq)(XiveFabric *xf, uint32_t eq_idx);And this one an EQDT lookup?
yes.
Quoted 10 lines
Quoted 8 lines
} XiveFabricClass;It helps in making the routing algorithm independent of the model. I hope to make powernv converge and use it.
- a set of MMIOs for the TIMA. They model the presenter engine.
current_cpuis used to retrieve the NVT object, which holds the registers for interrupt management.Right. Now the TIMA is local to a target/server not an EQ, right?
The TIMA is the MMIO giving access to the registers which are per CPU. The EQ are for routing. They are under the CPU object because it is convenient.
Quoted 1 line
I guess we need at least one of these per-vcpu.
yes.
Quoted 1 line
Do we also need an lpar-global, or other special ones?
That would be for the host. AFAICT KVM does not use such special VPs.
Quoted 5 lines
Quoted 2 lines
The EQs are stored under the NVT. This saves us an unnecessary EQDT table. But we could add one under the XIVE device model.
I'm not sure of the distinction you're drawing between the NVT and the XIVE device mode.
we could add a new table under the XIVE interrupt device model sPAPRXive to store the EQs and indexed them like skiboot does. But it seems unnecessary to me as we can use the object below 'cpu->intc', which is the XiveNVT object.
C.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 7 lines · Cédric Le Goater
Quoted 5 lines · David Gibson
Quoted 4 lines · Cédric Le Goater
Quoted 3 lines · David Gibson
Quoted 2 lines · Cédric Le Goater
Quoted 1 line · David Gibson
On Sat, Dec 09, 2017 at 09:43:21AM +0100, Cédric Le Goater
wrote:
[snip]
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
The XIVE tables are :
* IVT
associate an interrupt source number with an event queue. the data to be pushed in the queue is stored there also.
Ok, so there would be one of these tables for each IVRE,
yes. one for each XIVE interrupt controller. That is one per processor or socket.
Ah.. so there can be more than one in a multi-socket system.
Quoted 4 lines
Quoted 1 line
with one entry for each source managed by that IVSE, yes?
yes. The table is simply indexed by the interrupt number in the global IRQ number space of the machine.
How does that work on a multi-chip machine? Does each chip just have a table for a slice of the global irq number space?
Quoted 14 lines
Quoted 1 line
Do the XIVE IPIs have entries here, or do they bypass this?
no. The IPIs have entries also in this table.
Quoted 7 lines
Quoted 4 lines
* EQDT:
describes the queues in the OS RAM, also contains a set of flags, a virtual target, etc.
So on real hardware this would be global, yes? And it would be consulted by the IVRE?
yes. Exactly. The XIVE routing routine :
Quoted 7 lines
https://github.com/legoater/qemu/blob/xive/hw/intc/xive.c#L706gives a good overview of the usage of the tables.
Quoted 1 line
For guests, we'd expect one table per-guest?
yes but only in emulation mode.
I'm not sure what you mean by this.
Quoted 4 lines
Quoted 1 line
How would those be integrated with the host table?
Under KVM, this is handled by the host table (setup done in skiboot) and we are only interested in the state of the EQs for migration.
This doesn't make sense to me; the guest is able to alter the IVT entries, so that configuration must be migrated somehow.
Quoted 1 line
This state is set with the
H_INT_SET_QUEUE_CONFIGhcall,
"This state" here meaning IVT entries?
Quoted 6 lines
followed
by an OPAL call and then a HW update. It defines the EQ page in which to push event notification for the couple server/priority.Quoted 2 lines
Quoted 2 lines
* VPDT:
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
describe the virtual targets, which can have different natures, a lpar, a cpu. This is for powernv, spapr does not have this concept.
Ok On hardware that would also be global and consulted by the IVRE, yes?
yes.
Except.. is it actually global, or is there one per-chip/socket?
[snip]
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
In the current version I am working on, the XiveFabric interface is more complex : typedef struct XiveFabricClass { InterfaceClass parent; XiveIVE *(*get_ive)(XiveFabric *xf, uint32_t lisn);This does an IVT lookup, I take it?
yes. It is an interface for the underlying storage, which is different in sPAPR and PowerNV. The goal is to make the routing generic.
Right. So, yes, we definitely want a method *somehwere* to do an IVT lookup. I'm not entirely sure where it belongs yet.
Quoted 28 lines
Quoted 4 lines
Quoted 2 lines
XiveNVT *(*get_nvt)(XiveFabric *xf, uint32_t server);This one a VPDT lookup, yes?
yes.
Quoted 3 lines
Quoted 1 line
XiveEQ *(*get_eq)(XiveFabric *xf, uint32_t eq_idx);And this one an EQDT lookup?
yes.
Quoted 10 lines
Quoted 8 lines
} XiveFabricClass;It helps in making the routing algorithm independent of the model. I hope to make powernv converge and use it.
- a set of MMIOs for the TIMA. They model the presenter engine.
current_cpuis used to retrieve the NVT object, which holds the registers for interrupt management.Right. Now the TIMA is local to a target/server not an EQ, right?
The TIMA is the MMIO giving access to the registers which are per CPU. The EQ are for routing. They are under the CPU object because it is convenient.
Quoted 8 lines
Quoted 1 line
I guess we need at least one of these per-vcpu.
yes.
Quoted 1 line
Do we also need an lpar-global, or other special ones?
That would be for the host. AFAICT KVM does not use such special VPs.
Um.. "does not use".. don't we get to decide that?
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines
The EQs are stored under the NVT. This saves us an unnecessary EQDT table. But we could add one under the XIVE device model.
I'm not sure of the distinction you're drawing between the NVT and the XIVE device mode.
we could add a new table under the XIVE interrupt device model sPAPRXive to store the EQs and indexed them like skiboot does. But it seems unnecessary to me as we can use the object below '
cpu->intc', which is the XiveNVT object.
So, basically assuming a fixed set of EQs (one per priority?) per CPU for a PAPR guest? That makes sense (assuming PAPR doesn't provide guest interfaces to ask for something else).
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 21 lines · David Gibson
Quoted 7 lines · Cédric Le Goater
Quoted 5 lines · David Gibson
Quoted 4 lines · Cédric Le Goater
Quoted 3 lines · David Gibson
Quoted 2 lines · Cédric Le Goater
Quoted 1 line · David Gibson
On Sat, Dec 09, 2017 at 09:43:21AM +0100, Cédric Le Goater
wrote:
[snip]
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
The XIVE tables are :
* IVT
associate an interrupt source number with an event queue. the data to be pushed in the queue is stored there also.
Ok, so there would be one of these tables for each IVRE,
yes. one for each XIVE interrupt controller. That is one per processor or socket.
Quoted 8 lines
Ah.. so there can be more than one in a multi-socket system.
Quoted 4 lines
Quoted 1 line
Quoted 1 line
with one entry for each source managed by that IVSE, yes?
yes. The table is simply indexed by the interrupt number in the global IRQ number space of the machine.
How does that work on a multi-chip machine? Does each chip just have a table for a slice of the global irq number space?
yes. IRQ Allocation is done relative to the chip, each chip having a range depending on its block id. XIVE has a concept of block, which is used in skiboot in a one-to-one relationship with the chip.
Quoted 16 lines
Quoted 16 lines
Quoted 1 line
Do the XIVE IPIs have entries here, or do they bypass this?
no. The IPIs have entries also in this table.
Quoted 7 lines
Quoted 4 lines
* EQDT:
describes the queues in the OS RAM, also contains a set of flags, a virtual target, etc.
So on real hardware this would be global, yes? And it would be consulted by the IVRE?
yes. Exactly. The XIVE routing routine :
https://github.com/legoater/qemu/blob/xive/hw/intc/xive.c#L706
Quoted 7 lines
Quoted 5 lines
gives a good overview of the usage of the tables.
Quoted 1 line
For guests, we'd expect one table per-guest?
yes but only in emulation mode.
I'm not sure what you mean by this.
I meant the sPAPR QEMU emulation mode. Linux/KVM relies on the overall table allocated in OPAL for the system.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
How would those be integrated with the host table?
Under KVM, this is handled by the host table (setup done in skiboot) and we are only interested in the state of the EQs for migration.
This doesn't make sense to me; the guest is able to alter the IVT entries, so that configuration must be migrated somehow.
yes. The IVE needs to be migrated. We use get/set KVM ioctls to save and restore the value which is cached in the KVM irq state struct (server, prio, eq data). no OPAL calls are needed though.
Quoted 3 lines
Quoted 1 line
This state is set with the
H_INT_SET_QUEUE_CONFIGhcall,"This state" here meaning IVT entries?
no. The H_INT_SET_QUEUE_CONFIG sets the event queue OS page for a server/priority couple. That is where the event queue data is pushed.
H_INT_SET_SOURCE_CONFIG does the targeting : irq, server, priority, and the eq data to be pushed in case of an event.
Quoted 10 lines
Quoted 10 lines
followed
by an OPAL call and then a HW update. It defines the EQ page in which to push event notification for the couple server/priority.Quoted 6 lines
Quoted 5 lines
* VPDT:
describe the virtual targets, which can have different natures, a lpar, a cpu. This is for powernv, spapr does not have this concept.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Ok On hardware that would also be global and consulted by the IVRE, yes?
yes.
Except.. is it actually global, or is there one per-chip/socket?
There is a global VP allocator splitting the ids depending on the block/chip, but, to be honest, I have not dug in the details
Quoted 8 lines
[snip]
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
In the current version I am working on, the XiveFabric interface is more complex : typedef struct XiveFabricClass { InterfaceClass parent; XiveIVE *(*get_ive)(XiveFabric *xf, uint32_t lisn);
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This does an IVT lookup, I take it?
yes. It is an interface for the underlying storage, which is different in sPAPR and PowerNV. The goal is to make the routing generic.
Right. So, yes, we definitely want a method *somehwere* to do an IVT lookup. I'm not entirely sure where it belongs yet.
Me either. I have stuffed the XiveFabric with all the abstraction needed for the moment.
I am starting to think that there should be an interface to forward events and another one to route them. The router being a special case of the forwarder, the last one. The "simple" devices, like PSI, should only be forwarders for the sources they own but the interrupt controllers should be forwarders (they have sources) and also routers.
Quoted 29 lines
Quoted 29 lines
Quoted 3 lines
Quoted 1 line
XiveNVT *(*get_nvt)(XiveFabric *xf, uint32_t server);This one a VPDT lookup, yes?
yes.
Quoted 3 lines
Quoted 1 line
XiveEQ *(*get_eq)(XiveFabric *xf, uint32_t eq_idx);And this one an EQDT lookup?
yes.
Quoted 10 lines
Quoted 8 lines
} XiveFabricClass;It helps in making the routing algorithm independent of the model. I hope to make powernv converge and use it.
- a set of MMIOs for the TIMA. They model the presenter engine.
current_cpuis used to retrieve the NVT object, which holds the registers for interrupt management.Right. Now the TIMA is local to a target/server not an EQ, right?
The TIMA is the MMIO giving access to the registers which are per CPU. The EQ are for routing. They are under the CPU object because it is convenient.
Quoted 1 line
I guess we need at least one of these per-vcpu.
Quoted 8 lines
Quoted 6 lines
yes.
Quoted 1 line
Do we also need an lpar-global, or other special ones?
That would be for the host. AFAICT KVM does not use such special VPs.
Um.. "does not use".. don't we get to decide that?
Well, that part in the specs is still a little obscure for me and I am not sure it will fit very well in the Linux/KVM model. It should be hidden to the guest anyway and can come in later.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
The EQs are stored under the NVT. This saves us an unnecessary EQDT table. But we could add one under the XIVE device model.
I'm not sure of the distinction you're drawing between the NVT and the XIVE device mode.
Quoted 6 lines
Quoted 4 lines
we could add a new table under the XIVE interrupt device model sPAPRXive to store the EQs and indexed them like skiboot does. But it seems unnecessary to me as we can use the object below '
cpu->intc', which is the XiveNVT object.So, basically assuming a fixed set of EQs (one per priority?)
yes. It's easier to capture the state and dump information from the monitor.
Quoted 1 line
per CPU for a PAPR guest?
yes, that's own it works.
Quoted 2 lines
That makes sense (assuming PAPR doesn't provide guest interfaces to ask for something else).
Yes. All hcalls take prio/server parameters and the reserved prio range for the platform is in the device tree. 0xFF is a special case to reset targeting.
Thanks,
C.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 28 lines · Cédric Le Goater
Quoted 27 lines · David Gibson
Quoted 7 lines · Cédric Le Goater
Quoted 5 lines · David Gibson
Quoted 4 lines · Cédric Le Goater
Quoted 3 lines · David Gibson
Quoted 2 lines · Cédric Le Goater
Quoted 1 line · David Gibson
On Sat, Dec 09, 2017 at 09:43:21AM +0100, Cédric Le Goater
wrote:
[snip]
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
The XIVE tables are :
* IVT
associate an interrupt source number with an event queue. the data to be pushed in the queue is stored there also.
Ok, so there would be one of these tables for each IVRE,
yes. one for each XIVE interrupt controller. That is one per processor or socket.
Ah.. so there can be more than one in a multi-socket system.
Quoted 4 lines
Quoted 1 line
Quoted 1 line
with one entry for each source managed by that IVSE, yes?
yes. The table is simply indexed by the interrupt number in the global IRQ number space of the machine.
Quoted 6 lines
Quoted 2 lines
How does that work on a multi-chip machine? Does each chip just have a table for a slice of the global irq number space?
yes. IRQ Allocation is done relative to the chip, each chip having a range depending on its block id. XIVE has a concept of block, which is used in skiboot in a one-to-one relationship with the chip.
Ok. I'm assuming this block id forms the high(ish) bits of the global irq number, yes?
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 1 line
Do the XIVE IPIs have entries here, or do they bypass this?
no. The IPIs have entries also in this table.
Quoted 7 lines
Quoted 4 lines
* EQDT:
describes the queues in the OS RAM, also contains a set of flags, a virtual target, etc.
So on real hardware this would be global, yes? And it would be consulted by the IVRE?
yes. Exactly. The XIVE routing routine :
https://github.com/legoater/qemu/blob/xive/hw/intc/xive.c#L706gives a good overview of the usage of the tables.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
For guests, we'd expect one table per-guest?
yes but only in emulation mode.
I'm not sure what you mean by this.
I meant the sPAPR QEMU emulation mode. Linux/KVM relies on the overall table allocated in OPAL for the system.
Right.. I'm thinking of this from the point of view of the guest and/or qemu, rather than from the implementation. Even if the actual storage of the entries is distributed across the host's global table, we still logically have a table per guest, right?
Quoted 11 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
How would those be integrated with the host table?
Under KVM, this is handled by the host table (setup done in skiboot) and we are only interested in the state of the EQs for migration.
This doesn't make sense to me; the guest is able to alter the IVT entries, so that configuration must be migrated somehow.
yes. The IVE needs to be migrated. We use get/set KVM ioctls to save and restore the value which is cached in the KVM irq state struct (server, prio, eq data). no OPAL calls are needed though.
Right. Again, at this stage I don't particularly care what the backend details are - whether the host calls OPAL or whatever. I'm more concerned with the logical model.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
This state is set with the
H_INT_SET_QUEUE_CONFIGhcall,"This state" here meaning IVT entries?
no. The
H_INT_SET_QUEUE_CONFIGsets the event queue OS page for a server/priority couple. That is where the event queue data is pushed.
Ah. Doesn't that mean the guest *does* effectively have an EQD table, updated by this call? We'd need to migrate that data as well, and it's not part of the IVT, right?
Quoted 2 lines
H_INT_SET_SOURCE_CONFIGdoes the targeting : irq, server, priority, and the eq data to be pushed in case of an event.
Ok - that's the IVT entries, yes?
Quoted 37 lines
Quoted 11 lines
Quoted 11 lines
followed
by an OPAL call and then a HW update. It defines the EQ page in which to push event notification for the couple server/priority.Quoted 6 lines
Quoted 5 lines
* VPDT:
describe the virtual targets, which can have different natures, a lpar, a cpu. This is for powernv, spapr does not have this concept.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Ok On hardware that would also be global and consulted by the IVRE, yes?
yes.
Except.. is it actually global, or is there one per-chip/socket?
There is a global VP allocator splitting the ids depending on the block/chip, but, to be honest, I have not dug in the details
Quoted 8 lines
[snip]
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
In the current version I am working on, the XiveFabric interface is more complex : typedef struct XiveFabricClass { InterfaceClass parent; XiveIVE *(*get_ive)(XiveFabric *xf, uint32_t lisn);Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This does an IVT lookup, I take it?
yes. It is an interface for the underlying storage, which is different in sPAPR and PowerNV. The goal is to make the routing generic.
Right. So, yes, we definitely want a method *somehwere* to do an IVT lookup. I'm not entirely sure where it belongs yet.
Quoted 8 lines
Me either. I have stuffed the XiveFabric with all the abstraction needed for the moment.
I am starting to think that there should be an interface to forward events and another one to route them. The router being a special case of the forwarder, the last one. The "simple" devices, like PSI, should only be forwarders for the sources they own but the interrupt controllers should be forwarders (they have sources) and also routers.
I'm not really clear what you mean by "forward" here.
Quoted 74 lines
Quoted 30 lines
Quoted 30 lines
Quoted 4 lines
Quoted 2 lines
XiveNVT *(*get_nvt)(XiveFabric *xf, uint32_t server);This one a VPDT lookup, yes?
yes.
Quoted 3 lines
Quoted 1 line
XiveEQ *(*get_eq)(XiveFabric *xf, uint32_t eq_idx);And this one an EQDT lookup?
yes.
Quoted 10 lines
Quoted 8 lines
} XiveFabricClass;It helps in making the routing algorithm independent of the model. I hope to make powernv converge and use it.
- a set of MMIOs for the TIMA. They model the presenter engine.
current_cpuis used to retrieve the NVT object, which holds the registers for interrupt management.Right. Now the TIMA is local to a target/server not an EQ, right?
The TIMA is the MMIO giving access to the registers which are per CPU. The EQ are for routing. They are under the CPU object because it is convenient.
Quoted 1 line
I guess we need at least one of these per-vcpu.
Quoted 8 lines
Quoted 6 lines
yes.
Quoted 1 line
Do we also need an lpar-global, or other special ones?
That would be for the host. AFAICT KVM does not use such special VPs.
Um.. "does not use".. don't we get to decide that?
Well, that part in the specs is still a little obscure for me and I am not sure it will fit very well in the Linux/KVM model. It should be hidden to the guest anyway and can come in later.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
The EQs are stored under the NVT. This saves us an unnecessary EQDT table. But we could add one under the XIVE device model.
I'm not sure of the distinction you're drawing between the NVT and the XIVE device mode.
Quoted 6 lines
Quoted 4 lines
we could add a new table under the XIVE interrupt device model sPAPRXive to store the EQs and indexed them like skiboot does. But it seems unnecessary to me as we can use the object below '
cpu->intc', which is the XiveNVT object.So, basically assuming a fixed set of EQs (one per priority?)
yes. It's easier to capture the state and dump information from the monitor.
Quoted 1 line
per CPU for a PAPR guest?
yes, that's own it works.
Quoted 2 lines
That makes sense (assuming PAPR doesn't provide guest interfaces to ask for something else).
Yes. All hcalls take prio/server parameters and the reserved prio range for the platform is in the device tree.
0xFFis a special case to reset targeting.Thanks,
C.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 32 lines · David Gibson
Quoted 31 lines · Cédric Le Goater
Quoted 29 lines · David Gibson
Quoted 7 lines · Cédric Le Goater
Quoted 5 lines · David Gibson
Quoted 4 lines · Cédric Le Goater
Quoted 3 lines · David Gibson
Quoted 2 lines · Cédric Le Goater
Quoted 1 line · David Gibson
On Sat, Dec 09, 2017 at 09:43:21AM +0100, Cédric Le Goater
wrote:
[snip]
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
The XIVE tables are :
* IVT
associate an interrupt source number with an event queue. the data to be pushed in the queue is stored there also.
Ok, so there would be one of these tables for each IVRE,
yes. one for each XIVE interrupt controller. That is one per processor or socket.
Ah.. so there can be more than one in a multi-socket system.
Quoted 4 lines
Quoted 1 line
Quoted 1 line
with one entry for each source managed by that IVSE, yes?
yes. The table is simply indexed by the interrupt number in the global IRQ number space of the machine.
How does that work on a multi-chip machine? Does each chip just have a table for a slice of the global irq number space?
Quoted 6 lines
Quoted 3 lines
yes. IRQ Allocation is done relative to the chip, each chip having a range depending on its block id. XIVE has a concept of block, which is used in skiboot in a one-to-one relationship with the chip.
Ok. I'm assuming this block id forms the high(ish) bits of the global irq number, yes?
yes. the 8 top bits are reserved, the next 4 bits are for the block id, 16 blocks for 16 socket/chips, and the 20 lower bits are for the ISN.
Quoted 24 lines
Quoted 24 lines
Quoted 23 lines
Quoted 14 lines
Quoted 1 line
Do the XIVE IPIs have entries here, or do they bypass this?
no. The IPIs have entries also in this table.
Quoted 7 lines
Quoted 4 lines
* EQDT:
describes the queues in the OS RAM, also contains a set of flags, a virtual target, etc.
So on real hardware this would be global, yes? And it would be consulted by the IVRE?
yes. Exactly. The XIVE routing routine :
Quoted 7 lines
https://github.com/legoater/qemu/blob/xive/hw/intc/xive.c#L706gives a good overview of the usage of the tables.
Quoted 1 line
For guests, we'd expect one table per-guest?
yes but only in emulation mode.
I'm not sure what you mean by this.
Quoted 7 lines
Quoted 2 lines
I meant the sPAPR QEMU emulation mode. Linux/KVM relies on the overall table allocated in OPAL for the system.
Right.. I'm thinking of this from the point of view of the guest and/or qemu, rather than from the implementation. Even if the actual storage of the entries is distributed across the host's global table, we still logically have a table per guest, right?
Yes. (the XiveSource object would be the table-per-guest and its counterpart in KVM: the source block)
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
How would those be integrated with the host table?
Under KVM, this is handled by the host table (setup done in skiboot) and we are only interested in the state of the EQs for migration.
This doesn't make sense to me; the guest is able to alter the IVT entries, so that configuration must be migrated somehow.
Quoted 7 lines
Quoted 3 lines
yes. The IVE needs to be migrated. We use get/set KVM ioctls to save and restore the value which is cached in the KVM irq state struct (server, prio, eq data). no OPAL calls are needed though.
Right. Again, at this stage I don't particularly care what the backend details are - whether the host calls OPAL or whatever. I'm more concerned with the logical model.
ok.
Quoted 10 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
This state is set with the
H_INT_SET_QUEUE_CONFIGhcall,"This state" here meaning IVT entries?
no. The
H_INT_SET_QUEUE_CONFIGsets the event queue OS page for a server/priority couple. That is where the event queue data is pushed.Ah. Doesn't that mean the guest *does* effectively have an EQD table,
well, yes, it's behing the hood. but the guest does not know anything about the Xive controller internal structures, IVE, EQD, VPD and tables. Only OPAL does in fact.
Quoted 1 line
updated by this call?
it is indeed the purpose of H_INT_SET_QUEUE_CONFIG
Quoted 1 line
We'd need to migrate that data as well,
yes we do and some fields require OPAL support.
Quoted 1 line
and it's not part of the IVT, right?
yes. The IVT only contains the EQ index, the server/priority tuple used for routing.
Quoted 4 lines
Quoted 2 lines
H_INT_SET_SOURCE_CONFIGdoes the targeting : irq, server, priority, and the eq data to be pushed in case of an event.Ok - that's the IVT entries, yes?
yes.
Quoted 39 lines
Quoted 39 lines
Quoted 10 lines
Quoted 10 lines
followed
by an OPAL call and then a HW update. It defines the EQ page in which to push event notification for the couple server/priority.Quoted 6 lines
Quoted 5 lines
* VPDT:
describe the virtual targets, which can have different natures, a lpar, a cpu. This is for powernv, spapr does not have this concept.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Ok On hardware that would also be global and consulted by the IVRE, yes?
yes.
Except.. is it actually global, or is there one per-chip/socket?
There is a global VP allocator splitting the ids depending on the block/chip, but, to be honest, I have not dug in the details
Quoted 8 lines
[snip]
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
In the current version I am working on, the XiveFabric interface is more complex : typedef struct XiveFabricClass { InterfaceClass parent; XiveIVE *(*get_ive)(XiveFabric *xf, uint32_t lisn);Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This does an IVT lookup, I take it?
yes. It is an interface for the underlying storage, which is different in sPAPR and PowerNV. The goal is to make the routing generic.
Right. So, yes, we definitely want a method *somehwere* to do an IVT lookup. I'm not entirely sure where it belongs yet.
Me either. I have stuffed the XiveFabric with all the abstraction needed for the moment.
Quoted 7 lines
Quoted 5 lines
I am starting to think that there should be an interface to forward events and another one to route them. The router being a special case of the forwarder, the last one. The "simple" devices, like PSI, should only be forwarders for the sources they own but the interrupt controllers should be forwarders (they have sources) and also routers.
I'm not really clear what you mean by "forward" here.
When a interrupt source is triggered, a notification event can be generated and forwarded to the XIVE router if the transition algo (depending on the PQ bit) lets it through. A forward is a simple load of the IRQ number at a specific MMIO address defined by the main IC.
For QEMU sPAPR, it's a funtion call but for QEMU powernv, it's a load.
C.
Quoted 74 lines
Quoted 73 lines
Quoted 29 lines
Quoted 29 lines
Quoted 3 lines
Quoted 1 line
XiveNVT *(*get_nvt)(XiveFabric *xf, uint32_t server);This one a VPDT lookup, yes?
yes.
Quoted 3 lines
Quoted 1 line
XiveEQ *(*get_eq)(XiveFabric *xf, uint32_t eq_idx);And this one an EQDT lookup?
yes.
Quoted 10 lines
Quoted 8 lines
} XiveFabricClass;It helps in making the routing algorithm independent of the model. I hope to make powernv converge and use it.
- a set of MMIOs for the TIMA. They model the presenter engine.
current_cpuis used to retrieve the NVT object, which holds the registers for interrupt management.Right. Now the TIMA is local to a target/server not an EQ, right?
The TIMA is the MMIO giving access to the registers which are per CPU. The EQ are for routing. They are under the CPU object because it is convenient.
Quoted 1 line
I guess we need at least one of these per-vcpu.
Quoted 8 lines
Quoted 6 lines
yes.
Quoted 1 line
Do we also need an lpar-global, or other special ones?
That would be for the host. AFAICT KVM does not use such special VPs.
Um.. "does not use".. don't we get to decide that?
Well, that part in the specs is still a little obscure for me and I am not sure it will fit very well in the Linux/KVM model. It should be hidden to the guest anyway and can come in later.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
The EQs are stored under the NVT. This saves us an unnecessary EQDT table. But we could add one under the XIVE device model.
I'm not sure of the distinction you're drawing between the NVT and the XIVE device mode.
Quoted 6 lines
Quoted 4 lines
we could add a new table under the XIVE interrupt device model sPAPRXive to store the EQs and indexed them like skiboot does. But it seems unnecessary to me as we can use the object below '
cpu->intc', which is the XiveNVT object.So, basically assuming a fixed set of EQs (one per priority?)
yes. It's easier to capture the state and dump information from the monitor.
Quoted 1 line
per CPU for a PAPR guest?
yes, that's own it works.
Quoted 2 lines
That makes sense (assuming PAPR doesn't provide guest interfaces to ask for something else).
Yes. All hcalls take prio/server parameters and the reserved prio range for the platform is in the device tree.
0xFFis a special case to reset targeting.Thanks,
C.
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 37 lines · Cédric Le Goater
Quoted 36 lines · David Gibson
Quoted 34 lines · Cédric Le Goater
Quoted 21 lines · David Gibson
Quoted 7 lines · Cédric Le Goater
Quoted 5 lines · David Gibson
Quoted 4 lines · Cédric Le Goater
Quoted 3 lines · David Gibson
Quoted 2 lines · Cédric Le Goater
Quoted 1 line · David Gibson
On Sat, Dec 09, 2017 at 09:43:21AM +0100, Cédric Le Goater
wrote:
[snip]
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
The XIVE tables are :
* IVT
associate an interrupt source number with an event queue. the data to be pushed in the queue is stored there also.
Ok, so there would be one of these tables for each IVRE,
yes. one for each XIVE interrupt controller. That is one per processor or socket.
Quoted 8 lines
Ah.. so there can be more than one in a multi-socket system.
Quoted 4 lines
Quoted 1 line
Quoted 1 line
with one entry for each source managed by that IVSE, yes?
yes. The table is simply indexed by the interrupt number in the global IRQ number space of the machine.
How does that work on a multi-chip machine? Does each chip just have a table for a slice of the global irq number space?
yes. IRQ Allocation is done relative to the chip, each chip having a range depending on its block id. XIVE has a concept of block, which is used in skiboot in a one-to-one relationship with the chip.
Quoted 6 lines
Quoted 2 lines
Ok. I'm assuming this block id forms the high(ish) bits of the global irq number, yes?
yes. the 8 top bits are reserved, the next 4 bits are for the block id, 16 blocks for 16 socket/chips, and the 20 lower bits are for the ISN.
Ok.
Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 16 lines
Quoted 16 lines
Quoted 1 line
Do the XIVE IPIs have entries here, or do they bypass this?
no. The IPIs have entries also in this table.
Quoted 7 lines
Quoted 4 lines
* EQDT:
describes the queues in the OS RAM, also contains a set of flags, a virtual target, etc.
So on real hardware this would be global, yes? And it would be consulted by the IVRE?
yes. Exactly. The XIVE routing routine :
https://github.com/legoater/qemu/blob/xive/hw/intc/xive.c#L706Quoted 7 lines
Quoted 5 lines
gives a good overview of the usage of the tables.
Quoted 1 line
For guests, we'd expect one table per-guest?
yes but only in emulation mode.
I'm not sure what you mean by this.
I meant the sPAPR QEMU emulation mode. Linux/KVM relies on the overall table allocated in OPAL for the system.
Quoted 7 lines
Quoted 4 lines
Right.. I'm thinking of this from the point of view of the guest and/or qemu, rather than from the implementation. Even if the actual storage of the entries is distributed across the host's global table, we still logically have a table per guest, right?
Yes. (the XiveSource object would be the table-per-guest and its counterpart in KVM: the source block)
Uh.. I'm talking about the IVT (or a slice of it) here, so this would be a XiveRouter, not a XiveSource owning it.
Quoted 28 lines
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
How would those be integrated with the host table?
Under KVM, this is handled by the host table (setup done in skiboot) and we are only interested in the state of the EQs for migration.
This doesn't make sense to me; the guest is able to alter the IVT entries, so that configuration must be migrated somehow.
Quoted 7 lines
Quoted 3 lines
yes. The IVE needs to be migrated. We use get/set KVM ioctls to save and restore the value which is cached in the KVM irq state struct (server, prio, eq data). no OPAL calls are needed though.
Right. Again, at this stage I don't particularly care what the backend details are - whether the host calls OPAL or whatever. I'm more concerned with the logical model.
ok.
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
This state is set with the
H_INT_SET_QUEUE_CONFIGhcall,"This state" here meaning IVT entries?
no. The
H_INT_SET_QUEUE_CONFIGsets the event queue OS page for a server/priority couple. That is where the event queue data is pushed.
Quoted 5 lines
Quoted 1 line
Ah. Doesn't that mean the guest *does* effectively have an EQD table,
well, yes, it's behing the hood. but the guest does not know anything about the Xive controller internal structures, IVE, EQD, VPD and tables. Only OPAL does in fact.
Right, it's under the hood. But then so is the IVT (and the TCE tables and the HPT for that matter). So we're probably going to have a (*get_eqd) method somewhere that looks up in guest RAM or in an external table depending.
Quoted 155 lines
Quoted 1 line
updated by this call?
it is indeed the purpose of
H_INT_SET_QUEUE_CONFIGQuoted 1 line
We'd need to migrate that data as well,
yes we do and some fields require OPAL support.
Quoted 1 line
and it's not part of the IVT, right?
yes. The IVT only contains the EQ index, the server/priority tuple used for routing.
Quoted 4 lines
Quoted 2 lines
H_INT_SET_SOURCE_CONFIGdoes the targeting : irq, server, priority, and the eq data to be pushed in case of an event.Ok - that's the IVT entries, yes?
yes.
Quoted 39 lines
Quoted 39 lines
Quoted 10 lines
Quoted 10 lines
followed
by an OPAL call and then a HW update. It defines the EQ page in which to push event notification for the couple server/priority.Quoted 6 lines
Quoted 5 lines
* VPDT:
describe the virtual targets, which can have different natures, a lpar, a cpu. This is for powernv, spapr does not have this concept.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Ok On hardware that would also be global and consulted by the IVRE, yes?
yes.
Except.. is it actually global, or is there one per-chip/socket?
There is a global VP allocator splitting the ids depending on the block/chip, but, to be honest, I have not dug in the details
Quoted 8 lines
[snip]
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
In the current version I am working on, the XiveFabric interface is more complex : typedef struct XiveFabricClass { InterfaceClass parent; XiveIVE *(*get_ive)(XiveFabric *xf, uint32_t lisn);Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This does an IVT lookup, I take it?
yes. It is an interface for the underlying storage, which is different in sPAPR and PowerNV. The goal is to make the routing generic.
Right. So, yes, we definitely want a method *somehwere* to do an IVT lookup. I'm not entirely sure where it belongs yet.
Me either. I have stuffed the XiveFabric with all the abstraction needed for the moment.
Quoted 7 lines
Quoted 5 lines
I am starting to think that there should be an interface to forward events and another one to route them. The router being a special case of the forwarder, the last one. The "simple" devices, like PSI, should only be forwarders for the sources they own but the interrupt controllers should be forwarders (they have sources) and also routers.
I'm not really clear what you mean by "forward" here.
When a interrupt source is triggered, a notification event can be generated and forwarded to the XIVE router if the transition algo (depending on the PQ bit) lets it through. A forward is a simple load of the IRQ number at a specific MMIO address defined by the main IC.
For QEMU sPAPR, it's a funtion call but for QEMU powernv, it's a load.
C.
Quoted 74 lines
Quoted 73 lines
Quoted 29 lines
Quoted 29 lines
Quoted 3 lines
Quoted 1 line
XiveNVT *(*get_nvt)(XiveFabric *xf, uint32_t server);This one a VPDT lookup, yes?
yes.
Quoted 3 lines
Quoted 1 line
XiveEQ *(*get_eq)(XiveFabric *xf, uint32_t eq_idx);And this one an EQDT lookup?
yes.
Quoted 10 lines
Quoted 8 lines
} XiveFabricClass;It helps in making the routing algorithm independent of the model. I hope to make powernv converge and use it.
- a set of MMIOs for the TIMA. They model the presenter engine.
current_cpuis used to retrieve the NVT object, which holds the registers for interrupt management.Right. Now the TIMA is local to a target/server not an EQ, right?
The TIMA is the MMIO giving access to the registers which are per CPU. The EQ are for routing. They are under the CPU object because it is convenient.
Quoted 1 line
I guess we need at least one of these per-vcpu.
Quoted 8 lines
Quoted 6 lines
yes.
Quoted 1 line
Do we also need an lpar-global, or other special ones?
That would be for the host. AFAICT KVM does not use such special VPs.
Um.. "does not use".. don't we get to decide that?
Well, that part in the specs is still a little obscure for me and I am not sure it will fit very well in the Linux/KVM model. It should be hidden to the guest anyway and can come in later.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
The EQs are stored under the NVT. This saves us an unnecessary EQDT table. But we could add one under the XIVE device model.
I'm not sure of the distinction you're drawing between the NVT and the XIVE device mode.
Quoted 6 lines
Quoted 4 lines
we could add a new table under the XIVE interrupt device model sPAPRXive to store the EQs and indexed them like skiboot does. But it seems unnecessary to me as we can use the object below '
cpu->intc', which is the XiveNVT object.So, basically assuming a fixed set of EQs (one per priority?)
yes. It's easier to capture the state and dump information from the monitor.
Quoted 1 line
per CPU for a PAPR guest?
yes, that's own it works.
Quoted 2 lines
That makes sense (assuming PAPR doesn't provide guest interfaces to ask for something else).
Yes. All hcalls take prio/server parameters and the reserved prio range for the platform is in the device tree.
0xFFis a special case to reset targeting.Thanks,
C.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [Qemu-devel] [PATCH v2 02/19] spapr: introduce a skeleton for the XIVE interrupt controller
Quoted 79 lines · David Gibson
Quoted 37 lines · Cédric Le Goater
Quoted 36 lines · David Gibson
Quoted 34 lines · Cédric Le Goater
Quoted 21 lines · David Gibson
Quoted 7 lines · Cédric Le Goater
Quoted 5 lines · David Gibson
Quoted 4 lines · Cédric Le Goater
Quoted 3 lines · David Gibson
Quoted 2 lines · Cédric Le Goater
Quoted 1 line · David Gibson
On Sat, Dec 09, 2017 at 09:43:21AM +0100, Cédric Le Goater
wrote:
[snip]
Quoted 11 lines
Quoted 8 lines
Quoted 6 lines
The XIVE tables are :
* IVT
associate an interrupt source number with an event queue. the data to be pushed in the queue is stored there also.
Ok, so there would be one of these tables for each IVRE,
yes. one for each XIVE interrupt controller. That is one per processor or socket.
Quoted 8 lines
Ah.. so there can be more than one in a multi-socket system.
Quoted 4 lines
Quoted 1 line
Quoted 1 line
with one entry for each source managed by that IVSE, yes?
yes. The table is simply indexed by the interrupt number in the global IRQ number space of the machine.
How does that work on a multi-chip machine? Does each chip just have a table for a slice of the global irq number space?
yes. IRQ Allocation is done relative to the chip, each chip having a range depending on its block id. XIVE has a concept of block, which is used in skiboot in a one-to-one relationship with the chip.
Quoted 6 lines
Quoted 2 lines
Ok. I'm assuming this block id forms the high(ish) bits of the global irq number, yes?
yes. the 8 top bits are reserved, the next 4 bits are for the block id, 16 blocks for 16 socket/chips, and the 20 lower bits are for the ISN.
Ok.
Quoted 32 lines
Quoted 31 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 1 line
Do the XIVE IPIs have entries here, or do they bypass this?
no. The IPIs have entries also in this table.
Quoted 7 lines
Quoted 4 lines
* EQDT:
describes the queues in the OS RAM, also contains a set of flags, a virtual target, etc.
So on real hardware this would be global, yes? And it would be consulted by the IVRE?
yes. Exactly. The XIVE routing routine :
https://github.com/legoater/qemu/blob/xive/hw/intc/xive.c#L706gives a good overview of the usage of the tables.
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
For guests, we'd expect one table per-guest?
yes but only in emulation mode.
I'm not sure what you mean by this.
I meant the sPAPR QEMU emulation mode. Linux/KVM relies on the overall table allocated in OPAL for the system.
Right.. I'm thinking of this from the point of view of the guest and/or qemu, rather than from the implementation. Even if the actual storage of the entries is distributed across the host's global table, we still logically have a table per guest, right?
Quoted 5 lines
Quoted 2 lines
Yes. (the XiveSource object would be the table-per-guest and its counterpart in KVM: the source block)
Uh.. I'm talking about the IVT (or a slice of it) here, so this would be a XiveRouter, not a XiveSource owning it.
yes. Sorry. sPAPR has a unique XiveSource and a corresponding IVT.
Quoted 29 lines
Quoted 29 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
How would those be integrated with the host table?
Under KVM, this is handled by the host table (setup done in skiboot) and we are only interested in the state of the EQs for migration.
This doesn't make sense to me; the guest is able to alter the IVT entries, so that configuration must be migrated somehow.
Quoted 7 lines
Quoted 3 lines
yes. The IVE needs to be migrated. We use get/set KVM ioctls to save and restore the value which is cached in the KVM irq state struct (server, prio, eq data). no OPAL calls are needed though.
Right. Again, at this stage I don't particularly care what the backend details are - whether the host calls OPAL or whatever. I'm more concerned with the logical model.
ok.
Quoted 10 lines
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
This state is set with the
H_INT_SET_QUEUE_CONFIGhcall,"This state" here meaning IVT entries?
no. The
H_INT_SET_QUEUE_CONFIGsets the event queue OS page for a server/priority couple. That is where the event queue data is pushed.Ah. Doesn't that mean the guest *does* effectively have an EQD table,
Quoted 8 lines
Quoted 3 lines
well, yes, it's behing the hood. but the guest does not know anything about the Xive controller internal structures, IVE, EQD, VPD and tables. Only OPAL does in fact.
Right, it's under the hood. But then so is the IVT (and the TCE tables and the HPT for that matter). So we're probably going to have a (
*get_eqd) method somewhere that looks up in guest RAM or in an external table depending.
yes. definitely.
C.
Quoted 156 lines
Quoted 155 lines
Quoted 1 line
updated by this call?
it is indeed the purpose of
H_INT_SET_QUEUE_CONFIGQuoted 1 line
We'd need to migrate that data as well,
yes we do and some fields require OPAL support.
Quoted 1 line
and it's not part of the IVT, right?
yes. The IVT only contains the EQ index, the server/priority tuple used for routing.
Quoted 4 lines
Quoted 2 lines
H_INT_SET_SOURCE_CONFIGdoes the targeting : irq, server, priority, and the eq data to be pushed in case of an event.Ok - that's the IVT entries, yes?
yes.
Quoted 39 lines
Quoted 39 lines
Quoted 10 lines
Quoted 10 lines
followed
by an OPAL call and then a HW update. It defines the EQ page in which to push event notification for the couple server/priority.Quoted 6 lines
Quoted 5 lines
* VPDT:
describe the virtual targets, which can have different natures, a lpar, a cpu. This is for powernv, spapr does not have this concept.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Ok On hardware that would also be global and consulted by the IVRE, yes?
yes.
Except.. is it actually global, or is there one per-chip/socket?
There is a global VP allocator splitting the ids depending on the block/chip, but, to be honest, I have not dug in the details
Quoted 8 lines
[snip]
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
In the current version I am working on, the XiveFabric interface is more complex : typedef struct XiveFabricClass { InterfaceClass parent; XiveIVE *(*get_ive)(XiveFabric *xf, uint32_t lisn);Quoted 7 lines
Quoted 4 lines
Quoted 1 line
This does an IVT lookup, I take it?
yes. It is an interface for the underlying storage, which is different in sPAPR and PowerNV. The goal is to make the routing generic.
Right. So, yes, we definitely want a method *somehwere* to do an IVT lookup. I'm not entirely sure where it belongs yet.
Me either. I have stuffed the XiveFabric with all the abstraction needed for the moment.
Quoted 7 lines
Quoted 5 lines
I am starting to think that there should be an interface to forward events and another one to route them. The router being a special case of the forwarder, the last one. The "simple" devices, like PSI, should only be forwarders for the sources they own but the interrupt controllers should be forwarders (they have sources) and also routers.
I'm not really clear what you mean by "forward" here.
When a interrupt source is triggered, a notification event can be generated and forwarded to the XIVE router if the transition algo (depending on the PQ bit) lets it through. A forward is a simple load of the IRQ number at a specific MMIO address defined by the main IC.
For QEMU sPAPR, it's a funtion call but for QEMU powernv, it's a load.
C.
Quoted 74 lines
Quoted 73 lines
Quoted 29 lines
Quoted 29 lines
Quoted 3 lines
Quoted 1 line
XiveNVT *(*get_nvt)(XiveFabric *xf, uint32_t server);This one a VPDT lookup, yes?
yes.
Quoted 3 lines
Quoted 1 line
XiveEQ *(*get_eq)(XiveFabric *xf, uint32_t eq_idx);And this one an EQDT lookup?
yes.
Quoted 10 lines
Quoted 8 lines
} XiveFabricClass;It helps in making the routing algorithm independent of the model. I hope to make powernv converge and use it.
- a set of MMIOs for the TIMA. They model the presenter engine.
current_cpuis used to retrieve the NVT object, which holds the registers for interrupt management.Right. Now the TIMA is local to a target/server not an EQ, right?
The TIMA is the MMIO giving access to the registers which are per CPU. The EQ are for routing. They are under the CPU object because it is convenient.
Quoted 1 line
I guess we need at least one of these per-vcpu.
Quoted 8 lines
Quoted 6 lines
yes.
Quoted 1 line
Do we also need an lpar-global, or other special ones?
That would be for the host. AFAICT KVM does not use such special VPs.
Um.. "does not use".. don't we get to decide that?
Well, that part in the specs is still a little obscure for me and I am not sure it will fit very well in the Linux/KVM model. It should be hidden to the guest anyway and can come in later.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
Quoted 2 lines
The EQs are stored under the NVT. This saves us an unnecessary EQDT table. But we could add one under the XIVE device model.
I'm not sure of the distinction you're drawing between the NVT and the XIVE device mode.
Quoted 6 lines
Quoted 4 lines
we could add a new table under the XIVE interrupt device model sPAPRXive to store the EQs and indexed them like skiboot does. But it seems unnecessary to me as we can use the object below '
cpu->intc', which is the XiveNVT object.So, basically assuming a fixed set of EQs (one per priority?)
yes. It's easier to capture the state and dump information from the monitor.
Quoted 1 line
per CPU for a PAPR guest?
yes, that's own it works.
Quoted 2 lines
That makes sense (assuming PAPR doesn't provide guest interfaces to ask for something else).
Yes. All hcalls take prio/server parameters and the reserved prio range for the platform is in the device tree.
0xFFis a special case to reset targeting.Thanks,
C.