KVM: Don't assume that mpstate exists with in-kernel PIC always
PATCH v3 1/9 KVM: Don't assume that mpstate exists with in-kernel PIC always
From: Alexander Graf <[email protected]>
On PPC, we don't support MP state. So far it's not necessary and I'm not convinced yet that we really need to support it ever.
However, the current idle logic in QEMU assumes that an in-kernel PIC also means we support MP state. This assumption is not true anymore.
Let's split up the two cases into two different variables. That way PPC can expose an in-kernel PIC, while not implementing MP state.
---
v1 -> v2:
- use kvm_halt_in_kernel() instead
v2 -> v3:
- fix comment
--- cpus.c | 2 +- include/sysemu/kvm.h | 10 ++++++++++ kvm-all.c | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-)
cpus.c +1 -1
@@ -73,7 +73,7 @@ static bool cpu_thread_is_idle(CPUArchState *env)return true; }if (!cpu->halted ||qemu_cpu_has_work (cpu) || -kvm_async_interrupts_enabled ()) { +kvm_halt_in_kernel ()) {return false; }return true;
include/sysemu/kvm.h +10 -0
@@ -42,6 +42,7 @@extern bool kvm_allowed;extern bool kvm_kernel_irqchip;extern bool kvm_async_interrupts_allowed; +extern bool kvm_halt_in_kernel_allowed;extern bool kvm_irqfds_allowed;extern bool kvm_msi_via_irqfd_allowed;extern bool kvm_gsi_routing_allowed;
@@ -72,6 +73,14 @@ extern bool kvm_gsi_routing_allowed;#define kvm_async_interrupts_enabled () (kvm_async_interrupts_allowed)/** +* kvm_halt_in_kernel +* +* Returns: true if halted cpus should still get a KVM_RUN ioctl to run +* inside of kernel space. This only works if MP state is implemented. +*/ +#define kvm_halt_in_kernel () (kvm_halt_in_kernel_allowed) + +/** * kvm_irqfds_enabled: * * Returns: true if we can use irqfds to inject interrupts into
@@ -101,6 +110,7 @@ extern bool kvm_gsi_routing_allowed;#define kvm_enabled () (0)#define kvm_irqchip_in_kernel () (false)#define kvm_async_interrupts_enabled () (false) +#define kvm_halt_in_kernel () (false)#define kvm_irqfds_enabled () (false)#define kvm_msi_via_irqfd_enabled () (false)#define kvm_gsi_routing_allowed () (false)
kvm-all.c +2 -0
@@ -106,6 +106,7 @@ struct KVMStateKVMState *kvm_state;bool kvm_kernel_irqchip;bool kvm_async_interrupts_allowed; +bool kvm_halt_in_kernel_allowed;bool kvm_irqfds_allowed;bool kvm_msi_via_irqfd_allowed;bool kvm_gsi_routing_allowed;
@@ -1275,6 +1276,7 @@ static int kvm_irqchip_create(KVMState *s)* interrupt delivery (though the reverse is not necessarily true) */ kvm_async_interrupts_allowed = true; + kvm_halt_in_kernel_allowed = true;kvm_init_irq_routing (s);
Signature · 1 line
1.7.10.4
PATCH 2/9 KVM: PPC: Add dummy kvm_arch_init_irq_routing()
The common KVM code insists on calling kvm_arch_init_irq_routing() as soon as it sees kernel header support for it (regardless of whether QEMU supports it). Provide a dummy function to satisfy this.
Unlike x86, PPC does not have one default irqchip, so there's no common code that we'd stick here. Even if you ignore the routes themselves, which even on x86 are not set up in this function, the initial XICS kernel implementation will not support IRQ routing, so it's best to leave even the general feature flags up to the specific irqchip code.
---
Perhaps we shouldn't require each architecture to add a dummy function, but I wasn't sure if weak functions were acceptable in QEMU (didn't see any existing), and likewise with defining something like HAVE_ARCH_INIT_IRQ_ROUTING (which header would it go in?).
--- target-ppc/kvm.c | 4 ++++ 1 file changed, 4 insertions(+)
target-ppc/kvm.c +4 -0
@@ -1799,3 +1799,7 @@ int kvm_arch_on_sigbus(int code, void *addr) {return 1 ; } + +void kvm_arch_init_irq_routing (KVMState *s) +{ +}
Signature · 1 line
1.7.10.4
PATCH 3/9 linux-headers: update to kvm next
In reply to Scott WoodHeaders are imported from commit 4cee4b72f1e2600e19779a14d4d9a4f4016ce49f
in the next branch of git://git.kernel.org/pub/scm/virt/kvm/kvm.git
--- linux-headers/asm-arm/kvm.h | 12 +++--- linux-headers/asm-powerpc/kvm.h | 77 +++++++++++++++++++++++++++++++++++++++ linux-headers/asm-x86/kvm.h | 1 - linux-headers/linux/kvm.h | 40 +++++++++++++++++--- 4 files changed, 117 insertions(+), 13 deletions(-)
linux-headers/asm-arm/kvm.h +6 -6
@@ -53,12 +53,12 @@#define KVM_ARM_FIQ_spsr fiq_regs[7]struct kvm_regs { -struct pt_regs usr_regs;/* R0_usr - R14_usr, PC, CPSR */ -__u32 svc_regs[3 ];/* SP_svc, LR_svc, SPSR_svc */ -__u32 abt_regs[3 ];/* SP_abt, LR_abt, SPSR_abt */ -__u32 und_regs[3 ];/* SP_und, LR_und, SPSR_und */ -__u32 irq_regs[3 ];/* SP_irq, LR_irq, SPSR_irq */ -__u32 fiq_regs[8 ];/* R8_fiq - R14_fiq, SPSR_fiq */ +struct pt_regs usr_regs;/* R0_usr - R14_usr, PC, CPSR */ +unsigned long svc_regs[3 ];/* SP_svc, LR_svc, SPSR_svc */ +unsigned long abt_regs[3 ];/* SP_abt, LR_abt, SPSR_abt */ +unsigned long und_regs[3 ];/* SP_und, LR_und, SPSR_und */ +unsigned long irq_regs[3 ];/* SP_irq, LR_irq, SPSR_irq */ +unsigned long fiq_regs[8 ];/* R8_fiq - R14_fiq, SPSR_fiq */ };/* Supported Processor Types */
linux-headers/asm-powerpc/kvm.h +77 -0
107 lines not on this page · raw message
linux-headers/asm-x86/kvm.h +0 -1
@@ -29,7 +29,6 @@#define __KVM_HAVE_PIT#define __KVM_HAVE_IOAPIC#define __KVM_HAVE_IRQ_LINE -#define __KVM_HAVE_DEVICE_ASSIGNMENT#define __KVM_HAVE_MSI#define __KVM_HAVE_USER_NMI#define __KVM_HAVE_GUEST_DEBUG
linux-headers/linux/kvm.h +34 -6
@@ -561,9 +561,7 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_MP_STATE 14#define KVM_CAP_COALESCED_MMIO 15#define KVM_CAP_SYNC_MMU 16/* Changes to host mmap are reflected in guest */ -#ifdef __KVM_HAVE_DEVICE_ASSIGNMENT#define KVM_CAP_DEVICE_ASSIGNMENT 17 -#endif #define KVM_CAP_IOMMU 18#ifdef __KVM_HAVE_MSI#define KVM_CAP_DEVICE_MSI 20
@@ -579,13 +577,9 @@ struct kvm_ppc_smmu_info {#ifdef __KVM_HAVE_PIT#define KVM_CAP_REINJECT_CONTROL 24#endif -#ifdef __KVM_HAVE_IOAPIC#define KVM_CAP_IRQ_ROUTING 25 -#endif #define KVM_CAP_IRQ_INJECT_STATUS 26 -#ifdef __KVM_HAVE_DEVICE_ASSIGNMENT#define KVM_CAP_DEVICE_DEASSIGNMENT 27 -#endif #ifdef __KVM_HAVE_MSIX#define KVM_CAP_DEVICE_MSIX 28#endif
@@ -668,6 +662,9 @@ struct kvm_ppc_smmu_info {#define KVM_CAP_PPC_EPR 86#define KVM_CAP_ARM_PSCI 87#define KVM_CAP_ARM_SET_DEVICE_ADDR 88 +#define KVM_CAP_DEVICE_CTRL 89 +#define KVM_CAP_IRQ_MPIC 90 +#define KVM_CAP_PPC_RTAS 91#ifdef KVM_CAP_IRQ_ROUTING
@@ -821,6 +818,27 @@ struct kvm_arm_device_addr { };/* +* Device control API, available with KVM_CAP_DEVICE_CTRL +*/ +#define KVM_CREATE_DEVICE_TEST 1 + +struct kvm_create_device { +__u32 type;/* in: KVM_DEV_TYPE_xxx */ +__u32 fd;/* out: device handle */ +__u32 flags;/* in: KVM_CREATE_DEVICE_xxx */ +}; + +struct kvm_device_attr { +__u32 flags;/* no flags currently defined */ +__u32 group;/* device-defined */ +__u64 attr;/* group-defined */ +__u64 addr;/* userspace address of attr data */ +}; + +#define KVM_DEV_TYPE_FSL_MPIC_20 1 +#define KVM_DEV_TYPE_FSL_MPIC_42 2 + +/* * ioctls for VM fds */ #define KVM_SET_MEMORY_REGION _IOW(KVMIO, 0x40, struct kvm_memory_region)
@@ -907,6 +925,16 @@ struct kvm_s390_ucas_mapping {#define KVM_PPC_GET_HTAB_FD _IOW(KVMIO, 0xaa, struct kvm_get_htab_fd)/* Available with KVM_CAP_ARM_SET_DEVICE_ADDR */ #define KVM_ARM_SET_DEVICE_ADDR _IOW(KVMIO, 0xab, struct kvm_arm_device_addr) +/* Available with KVM_CAP_PPC_RTAS */ +#define KVM_PPC_RTAS_DEFINE_TOKEN _IOW(KVMIO, 0xac, struct kvm_rtas_token_args) + +/* ioctl for vm fd */ +#define KVM_CREATE_DEVICE _IOWR(KVMIO, 0xe0, struct kvm_create_device) + +/* ioctls for fds returned by KVM_CREATE_DEVICE */ +#define KVM_SET_DEVICE_ATTR _IOW(KVMIO, 0xe1, struct kvm_device_attr) +#define KVM_GET_DEVICE_ATTR _IOW(KVMIO, 0xe2, struct kvm_device_attr) +#define KVM_HAS_DEVICE_ATTR _IOW(KVMIO, 0xe3, struct kvm_device_attr)/* * ioctls for vcpu fds
Signature · 1 line
1.7.10.4
PATCH 4/9 KVM: Export kvm_init_irq_routing
In reply to Scott WoodFrom: Alexander Graf <[email protected]>
On PPC, we can have different types of interrupt controllers, so we really only know that we are going to use one when we created it.
Export kvm_init_irq_routing() to common code, so that we don't have to call kvm_irqchip_create().
--- include/sysemu/kvm.h | 1 + kvm-all.c | 4 ++-- kvm-stub.c | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-)
include/sysemu/kvm.h +1 -0
@@ -302,4 +302,5 @@ int kvm_irqchip_add_irqfd_notifier(KVMState *s, EventNotifier *n, int virq);int kvm_irqchip_remove_irqfd_notifier (KVMState *s,EventNotifier *n,int virq);void kvm_pc_gsi_handler (void *opaque,int n,int level);void kvm_pc_setup_irq_routing (bool pci_enabled); +void kvm_init_irq_routing (KVMState *s);#endif
kvm-all.c +2 -2
@@ -926,7 +926,7 @@ static void clear_gsi(KVMState *s, unsigned int gsi) s->used_gsi_bitmap[gsi /32 ] &= ~(1U << (gsi %32 )); } -static void kvm_init_irq_routing (KVMState *s) +void kvm_init_irq_routing (KVMState *s) {int gsi_count, i;
@@ -1214,7 +1214,7 @@ static int kvm_irqchip_assign_irqfd(KVMState *s, int fd, int virq, bool assign)#else /* !KVM_CAP_IRQ_ROUTING */ -static void kvm_init_irq_routing (KVMState *s) +void kvm_init_irq_routing (KVMState *s) { }
kvm-stub.c +4 -0
@@ -116,6 +116,10 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg)return -ENOSYS ; } +void kvm_init_irq_routing (KVMState *s) +{ +} +void kvm_irqchip_release_virq (KVMState *s,int virq) { }
Signature · 1 line
1.7.10.4
PATCH 5/9 KVM: MSI: Swap payload to native endianness
In reply to Scott WoodFrom: Alexander Graf <[email protected]>
The usual MSI injection mechanism writes msi.data into memory using an le32 wrapper. So on big endian guests, this swaps msg.data into the expected byte order.
For irqfd however, we don't swap the payload right now, rendering in-kernel MPIC emulation broken on PowerPC.
Swap msg.data to the correct endianness whenever we touch it.
---
Quoted 1 line
From Scott: This patch makes me wonder why we have four different open
coded instances of putting information from MSIMessage into struct kvm_irq_routing_msi...
--- kvm-all.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-)
kvm-all.c +5 -5
@@ -1103,7 +1103,7 @@ static KVMMSIRoute *kvm_lookup_msi_route(KVMState *s, MSIMessage msg) QTAILQ_FOREACH(route, &s->msi_hashtab[hash], entry) {if (route->kroute.u.msi.address_lo == (uint32_t )msg.address && route->kroute.u.msi.address_hi == (msg.address >>32 ) && - route->kroute.u.msi.data == msg.data) { + route->kroute.u.msi.data ==le32_to_cpu (msg.data)) {return route; } }
@@ -1118,7 +1118,7 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg)if (s->direct_msi) { msi.address_lo = (uint32_t )msg.address; msi.address_hi = msg.address >>32 ; - msi.data = msg.data; + msi.data =le32_to_cpu (msg.data); msi.flags =0 ;memset (msi.pad,0 ,sizeof (msi.pad));
@@ -1140,7 +1140,7 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg) route->kroute.flags =0 ; route->kroute.u.msi.address_lo = (uint32_t )msg.address; route->kroute.u.msi.address_hi = msg.address >>32 ; - route->kroute.u.msi.data = msg.data; + route->kroute.u.msi.data =le32_to_cpu (msg.data);kvm_add_routing_entry (s, &route->kroute);
@@ -1172,7 +1172,7 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg) kroute.flags =0 ; kroute.u.msi.address_lo = (uint32_t )msg.address; kroute.u.msi.address_hi = msg.address >>32 ; - kroute.u.msi.data = msg.data; + kroute.u.msi.data =le32_to_cpu (msg.data);kvm_add_routing_entry (s, &kroute);
@@ -1192,7 +1192,7 @@ int kvm_irqchip_update_msi_route(KVMState *s, int virq, MSIMessage msg) kroute.flags =0 ; kroute.u.msi.address_lo = (uint32_t )msg.address; kroute.u.msi.address_hi = msg.address >>32 ; - kroute.u.msi.data = msg.data; + kroute.u.msi.data =le32_to_cpu (msg.data);return kvm_update_routing_entry (s, &kroute); }
Signature · 1 line
1.7.10.4
PATCH 6/9 openpic: factor out some common defines into openpic.h
In reply to Scott Wood...for use by the KVM in-kernel irqchip stub.
--- hw/intc/openpic.c | 40 ++++++++++++++++++---------------------- include/hw/ppc/openpic.h | 11 +++++++++++ 2 files changed, 29 insertions(+), 22 deletions(-)
hw/intc/openpic.c +18 -22
@@ -57,11 +57,7 @@ static const int debug_openpic = 0; } while (0)#define MAX_CPU 32 -#define MAX_SRC 256 -#define MAX_TMR 4 -#define MAX_IPI 4#define MAX_MSI 8 -#define MAX_IRQ (MAX_SRC + MAX_IPI + MAX_TMR)#define VID 0x03/* MPIC version ID */ /* OpenPIC capability flags */
@@ -78,7 +74,7 @@ static const int debug_openpic = 0;#define OPENPIC_SUMMARY_REG_START 0x3800#define OPENPIC_SUMMARY_REG_SIZE 0x800#define OPENPIC_SRC_REG_START 0x10000 -#define OPENPIC_SRC_REG_SIZE (MAX_SRC * 0x20) +#define OPENPIC_SRC_REG_SIZE (OPENPIC_MAX_SRC * 0x20)#define OPENPIC_CPU_REG_START 0x20000#define OPENPIC_CPU_REG_SIZE 0x100 + ((MAX_CPU - 1) * 0x1000)
@@ -86,8 +82,8 @@ static const int debug_openpic = 0;#define RAVEN_MAX_CPU 2#define RAVEN_MAX_EXT 48#define RAVEN_MAX_IRQ 64 -#define RAVEN_MAX_TMR MAX_TMR -#define RAVEN_MAX_IPI MAX_IPI +#define RAVEN_MAX_TMR OPENPIC_MAX_TMR +#define RAVEN_MAX_IPI OPENPIC_MAX_IPI/* Interrupt definitions */ #define RAVEN_FE_IRQ (RAVEN_MAX_EXT)/* Internal functional IRQ */
@@ -209,7 +205,7 @@ typedef struct IRQQueue {/* Round up to the nearest 64 IRQs so that the queue length * won't change when moving between 32 and 64 bit hosts. */ -unsigned long queue[BITS_TO_LONGS ((MAX_IRQ +63 ) & ~63 )]; +unsigned long queue[BITS_TO_LONGS ((OPENPIC_MAX_IRQ +63 ) & ~63 )];int next;int priority; } IRQQueue;
@@ -283,7 +279,7 @@ typedef struct OpenPICState {uint32_t spve;/* Spurious vector register */ uint32_t tfrr;/* Timer frequency reporting register */ /* Source registers */ -IRQSource src[MAX_IRQ ]; +IRQSource src[OPENPIC_MAX_IRQ ];/* Local registers per output pin */ IRQDest dst[MAX_CPU ];uint32_t nb_cpus;
@@ -291,7 +287,7 @@ typedef struct OpenPICState {struct {uint32_t tccr;/* Global timer current count register */ uint32_t tbcr;/* Global timer base count register */ - } timers[MAX_TMR ]; + } timers[OPENPIC_MAX_TMR ];/* Shared MSI registers */ struct {uint32_t msir;/* Shared Message Signaled Interrupt Register */
@@ -503,7 +499,7 @@ static void openpic_set_irq(void *opaque, int n_IRQ, int level)OpenPICState *opp = opaque;IRQSource *src; -if (n_IRQ >=MAX_IRQ ) { +if (n_IRQ >=OPENPIC_MAX_IRQ ) {fprintf (stderr,"%s: IRQ %d out of range\n" , __func__, n_IRQ);abort (); }
@@ -576,7 +572,7 @@ static void openpic_reset(DeviceState *d) opp->dst[i].servicing.next =-1 ; }/* Initialise timers */ -for (i =0 ; i <MAX_TMR ; i++) { +for (i =0 ; i <OPENPIC_MAX_TMR ; i++) { opp->timers[i].tccr =0 ; opp->timers[i].tbcr =TBCR_CI ; }
@@ -1182,7 +1178,7 @@ static uint32_t openpic_iack(OpenPICState *opp, IRQDest *dst, int cpu)IRQ_resetbit (&dst->raised, irq); } -if ((irq >= opp->irq_ipi0) && (irq < (opp->irq_ipi0 +MAX_IPI ))) { +if ((irq >= opp->irq_ipi0) && (irq < (opp->irq_ipi0 +OPENPIC_MAX_IPI ))) { src->destmask &= ~(1 << cpu);if (src->destmask && !src->level) {/* trigger on CPUs that didn't know about it yet */
@@ -1381,7 +1377,7 @@ static void openpic_save(QEMUFile* f, void *opaque) sizeof(opp->dst[i].outputs_active)); } -for (i =0 ; i <MAX_TMR ; i++) { +for (i =0 ; i <OPENPIC_MAX_TMR ; i++) {qemu_put_be32s (f, &opp->timers[i].tccr);qemu_put_be32s (f, &opp->timers[i].tbcr); }
@@ -1440,7 +1436,7 @@ static int openpic_load(QEMUFile* f, void *opaque, int version_id) sizeof(opp->dst[i].outputs_active)); } -for (i =0 ; i <MAX_TMR ; i++) { +for (i =0 ; i <OPENPIC_MAX_TMR ; i++) {qemu_get_be32s (f, &opp->timers[i].tccr);qemu_get_be32s (f, &opp->timers[i].tbcr); }
@@ -1473,7 +1469,7 @@ typedef struct MemReg {static void fsl_common_init (OpenPICState *opp) {int i; -int virq =MAX_SRC ; +int virq =OPENPIC_MAX_SRC ; opp->vid =VID_REVISION_1_2 ; opp->vir =VIR_GENERIC ;
@@ -1481,14 +1477,14 @@ static void fsl_common_init(OpenPICState *opp) opp->tfrr_reset =0 ; opp->ivpr_reset =IVPR_MASK_MASK ; opp->idr_reset =1 <<0 ; - opp->max_irq =MAX_IRQ ; + opp->max_irq =OPENPIC_MAX_IRQ ; opp->irq_ipi0 = virq; - virq +=MAX_IPI ; + virq +=OPENPIC_MAX_IPI ; opp->irq_tim0 = virq; - virq +=MAX_TMR ; + virq +=OPENPIC_MAX_TMR ; -assert (virq <=MAX_IRQ ); +assert (virq <=OPENPIC_MAX_IRQ ); opp->irq_msi =224 ;
@@ -1498,13 +1494,13 @@ static void fsl_common_init(OpenPICState *opp) }/* Internal interrupts, including message and MSI */ -for (i =16 ; i <MAX_SRC ; i++) { +for (i =16 ; i <OPENPIC_MAX_SRC ; i++) { opp->src[i].type =IRQ_TYPE_FSLINT ; opp->src[i].level = true; }/* timers and IPIs */ -for (i =MAX_SRC ; i < virq; i++) { +for (i =OPENPIC_MAX_SRC ; i < virq; i++) { opp->src[i].type =IRQ_TYPE_FSLSPECIAL ; opp->src[i].level = false; }
include/hw/ppc/openpic.h +11 -0
@@ -1,6 +1,9 @@#if !defined(__OPENPIC_H__)#define __OPENPIC_H__ +#include "qemu-common.h" +#include "hw/qdev.h" +/* OpenPIC have 5 outputs per CPU connected and one IRQ out single output */ enum { OPENPIC_OUTPUT_INT = 0, /* IRQ */
@@ -15,4 +18,12 @@ enum {#define OPENPIC_MODEL_FSL_MPIC_20 1#define OPENPIC_MODEL_FSL_MPIC_42 2 +#define OPENPIC_MAX_SRC 256 +#define OPENPIC_MAX_TMR 4 +#define OPENPIC_MAX_IPI 4 +#define OPENPIC_MAX_IRQ (OPENPIC_MAX_SRC + OPENPIC_MAX_IPI + \ + OPENPIC_MAX_TMR) + +DeviceState *kvm_openpic_create (BusState *bus,int model); +#endif /* __OPENPIC_H__ */
Signature · 1 line
1.7.10.4
PATCH 7/9 PPC: e500: factor out mpic init code
In reply to Scott WoodKVM in-kernel MPIC support is going to expand this even more, so let's keep it contained.
--- hw/ppc/e500.c | 56 ++++++++++++++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 22 deletions(-)
hw/ppc/e500.c +34 -22
@@ -448,6 +448,38 @@ static void ppce500_cpu_reset(void *opaque)mmubooke_create_initial_mapping (env); } +static qemu_irq *ppce500_init_mpic (PPCE500Params *params,MemoryRegion *ccsr, +qemu_irq **irqs) +{ +qemu_irq *mpic; +DeviceState *dev; +SysBusDevice *s; +int i, j, k; + + mpic =g_new (qemu_irq,256 ); + dev =qdev_create (NULL ,"openpic" ); +qdev_prop_set_uint32 (dev,"nb_cpus" , smp_cpus); +qdev_prop_set_uint32 (dev,"model" , params->mpic_version); +qdev_init_nofail (dev); + s =SYS_BUS_DEVICE (dev); + + k =0 ; +for (i =0 ; i < smp_cpus; i++) { +for (j =0 ; j <OPENPIC_OUTPUT_NB ; j++) { +sysbus_connect_irq (s, k++, irqs[i][j]); + } + } + +for (i =0 ; i <256 ; i++) { + mpic[i] =qdev_get_gpio_in (dev, i); + } + +memory_region_add_subregion (ccsr,MPC8544_MPIC_REGS_OFFSET , + s->mmio[0 ].memory); + +return mpic; +} +void ppce500_init (PPCE500Params *params) {MemoryRegion *address_space_mem =get_system_memory ();
@@ -463,7 +495,7 @@ void ppce500_init(PPCE500Params *params)target_ulong initrd_base =0 ;target_long initrd_size =0 ;target_ulong cur_base =0 ; -int i =0 , j, k; +int i;unsigned int pci_irq_nrs[4 ] = {1 ,2 ,3 ,4 };qemu_irq **irqs, *mpic;DeviceState *dev;
@@ -538,27 +570,7 @@ void ppce500_init(PPCE500Params *params)memory_region_add_subregion (address_space_mem,MPC8544_CCSRBAR_BASE , ccsr_addr_space); -/* MPIC */ - mpic =g_new (qemu_irq,256 ); - dev =qdev_create (NULL ,"openpic" ); -qdev_prop_set_uint32 (dev,"nb_cpus" , smp_cpus); -qdev_prop_set_uint32 (dev,"model" , params->mpic_version); -qdev_init_nofail (dev); - s =SYS_BUS_DEVICE (dev); - - k =0 ; -for (i =0 ; i < smp_cpus; i++) { -for (j =0 ; j <OPENPIC_OUTPUT_NB ; j++) { -sysbus_connect_irq (s, k++, irqs[i][j]); - } - } - -for (i =0 ; i <256 ; i++) { - mpic[i] =qdev_get_gpio_in (dev, i); - } - -memory_region_add_subregion (ccsr_addr_space,MPC8544_MPIC_REGS_OFFSET , - s->mmio[0 ].memory); + mpic =ppce500_init_mpic (params, ccsr_addr_space, irqs);/* Serial */ if (serial_hds[0 ]) {
Signature · 1 line
1.7.10.4
PATCH 8/9 kvm/openpic: in-kernel mpic support
In reply to Scott WoodEnables support for the in-kernel MPIC that thas been merged into the KVM next branch. This includes irqfd/KVM_IRQ_LINE support from Alex Graf (along with some other improvements).
Note from Alex regarding kvm_irqchip_create():
On x86, one would call kvm_irqchip_create() to initialize an in-kernel interrupt controller. That function then goes ahead and initializes global capability variables as well as the default irq routing table.
On ppc, we can't call kvm_irqchip_create() because we can have different types of interrupt controllers. So we want to do all the things that function would do for us in the in-kernel device init handler.
--- default-configs/ppc-softmmu.mak | 1 + default-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/openpic_kvm.c | 256 +++++++++++++++++++++++++++++++++++++ hw/ppc/e500.c | 79 +++++++++++- include/hw/ppc/openpic.h | 2 +- 6 files changed, 334 insertions(+), 6 deletions(-) create mode 100644 hw/intc/openpic_kvm.c
default-configs/ppc-softmmu.mak +1 -0
@@ -43,5 +43,6 @@ CONFIG_XILINX=y CONFIG_XILINX_ETHLITE=y CONFIG_OPENPIC=y CONFIG_E500=$(CONFIG_FDT) +CONFIG_OPENPIC_KVM=$(and $(CONFIG_E500),$(CONFIG_KVM)) # For PReP CONFIG_MC146818RTC=y
default-configs/ppc64-softmmu.mak +1 -0
@@ -44,6 +44,7 @@ CONFIG_XILINX_ETHLITE=y CONFIG_OPENPIC=y CONFIG_PSERIES=$(CONFIG_FDT) CONFIG_E500=$(CONFIG_FDT) +CONFIG_OPENPIC_KVM=$(and $(CONFIG_E500),$(CONFIG_KVM)) # For pSeries CONFIG_PCI_HOTPLUG=y # For PReP
hw/intc/Makefile.objs +1 -0
@@ -20,4 +20,5 @@ obj-$(CONFIG_GRLIB) += grlib_irqmp.o obj-$(CONFIG_IOAPIC) += ioapic.o obj-$(CONFIG_OMAP) += omap_intc.o obj-$(CONFIG_OPENPIC) += openpic.o +obj-$(CONFIG_OPENPIC_KVM) += openpic_kvm.o obj-$(CONFIG_SH4) += sh_intc.o
hw/intc/openpic_kvm.c new file +256 -0
256 lines not on this page · raw message
hw/ppc/e500.c +74 -5
102 lines not on this page · raw message
include/hw/ppc/openpic.h +1 -1
@@ -24,6 +24,6 @@ enum {#define OPENPIC_MAX_IRQ (OPENPIC_MAX_SRC + OPENPIC_MAX_IPI + \ OPENPIC_MAX_TMR) -DeviceState *kvm_openpic_create (BusState *bus,int model); +int kvm_openpic_connect_vcpu (DeviceState *d,CPUState *cs);#endif /* __OPENPIC_H__ */
Signature · 1 line
1.7.10.4
Re: [Qemu-devel] [PATCH 8/9] kvm/openpic: in-kernel mpic support
Quoted 141 lines · Scott Wood
Enables support for the in-kernel MPIC that thas been merged into the KVM next branch. This includes irqfd/KVM_IRQ_LINE support from Alex Graf (along with some other improvements).
Note from Alex regarding
kvm_irqchip_create():On x86, one would call
kvm_irqchip_create()to initialize an in-kernel interrupt controller. That function then goes ahead and initializes global capability variables as well as the default irq routing table.On ppc, we can't call
kvm_irqchip_create()because we can have different types of interrupt controllers. So we want to do all the things that function would do for us in the in-kernel device init handler.Signed-off-by Scott Wood <[email protected]>---
default-configs/ppc-softmmu.mak | 1 + default-configs/ppc64-softmmu.mak | 1 + hw/intc/Makefile.objs | 1 + hw/intc/openpic_kvm.c | 256 +++++++++++++++++++++++++++++++++++++ hw/ppc/e500.c | 79 +++++++++++- include/hw/ppc/openpic.h | 2 +- 6 files changed, 334 insertions(+), 6 deletions(-)create mode 100644
hw/intc/openpic_kvm.cdefault-configs/ppc-softmmu.mak +0
-0@@ -43,5 +43,6 @@ CONFIG_XILINX=y
CONFIG_XILINX_ETHLITE=yCONFIG_OPENPIC=yCONFIG_E500=$(CONFIG_FDT)+CONFIG_OPENPIC_KVM=$(and $(CONFIG_E500),$(CONFIG_KVM)) # For PRePCONFIG_MC146818RTC=ydefault-configs/ppc64-softmmu.mak +0
-0@@ -44,6 +44,7 @@ CONFIG_XILINX_ETHLITE=y
CONFIG_OPENPIC=yCONFIG_PSERIES=$(CONFIG_FDT)CONFIG_E500=$(CONFIG_FDT)+CONFIG_OPENPIC_KVM=$(and $(CONFIG_E500),$(CONFIG_KVM)) # For pSeriesCONFIG_PCI_HOTPLUG=y
# For PRePhw/intc/Makefile.objs +0
-0@@ -20,4 +20,5 @@ obj-$(CONFIG_GRLIB) += grlib_irqmp.oobj-$(CONFIG_IOAPIC) += ioapic.o
obj-$(CONFIG_OMAP) += omap_intc.o
obj-$(CONFIG_OPENPIC) += openpic.o
+obj-$(CONFIG_OPENPIC_KVM) += openpic_kvm.o
obj-$(CONFIG_SH4) += sh_intc.ohw/intc/openpic_kvm.c new file +75
-0@@ -0,0 +1,256 @@ +/* +* KVM in-kernel OpenPIC +* +* Copyright 2013 Freescale Semiconductor, Inc. +* +* Permission is hereby granted, free of charge, to any person obtaining a copy +* of this software and associated documentation files (the "Software"), to deal +* in the Software without restriction, including without limitation the rights +* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +* copies of the Software, and to permit persons to whom the Software is +* furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in +* all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +*/ + +#include <sys/ioctl.h> +#include "exec/address-spaces.h" +#include "hw/hw.h" +#include "hw/ppc/openpic.h" +#include "hw/pci/msi.h" +#include "hw/sysbus.h" +#include "sysemu/kvm.h" +#include "qemu/log.h" + +typedef struct KVMOpenPICState { +SysBusDevice busdev; +MemoryRegion mem; +MemoryListener mem_listener; +uint32_t fd; +uint32_t model; +}KVMOpenPICState ; + +static void kvm_openpic_set_irq (void *opaque,int n_IRQ,int level) +{ +kvm_set_irq (kvm_state, n_IRQ, level); +} + +static void kvm_openpic_reset (DeviceState *d) +{ +qemu_log_mask (LOG_UNIMP ,"%s: unimplemented\n" , __func__); +} + +static void kvm_openpic_write (void *opaque,hwaddr addr,uint64_t val, +unsigned size) +{ +KVMOpenPICState *opp = opaque; +struct kvm_device_attr attr; +uint32_t val32 = val; +int ret; + + attr.group =KVM_DEV_MPIC_GRP_REGISTER ; + attr.attr = addr; + attr.addr = (uint64_t )(unsigned long )&val32; + + ret =ioctl (opp->fd,KVM_SET_DEVICE_ATTR , &attr); +if (ret <0 ) { +qemu_log_mask (LOG_UNIMP ,"%s: %s %llx\n" , __func__, +strerror (errno), attr.attr); + } +} + +static uint64_t kvm_openpic_read (void *opaque,hwaddr addr,unsigned size) +{ +KVMOpenPICState *opp = opaque; +struct kvm_device_attr attr; +uint32_t val =0xdeadbeef ;
hw/intc/openpic_kvm.c line 85
Quoted 10 lines
hw/intc/openpic_kvm.c new file +10
-0+int ret; + + attr.group =KVM_DEV_MPIC_GRP_REGISTER ; + attr.attr = addr; + attr.addr = (uint64_t )(unsigned long )&val; + + ret =ioctl (opp->fd,KVM_GET_DEVICE_ATTR , &attr); +if (ret <0 ) { +qemu_log_mask (LOG_UNIMP ,"%s: %s %llx\n" , __func__, +strerror (errno), attr.attr);
%llx on __u64. Please use PRIx64 instead. Same thing a few times below.
Quoted 20 lines
hw/intc/openpic_kvm.c new file +20
-0+return 0 ; + } + +return val; +} + +static const MemoryRegionOps kvm_openpic_mem_ops = { + .write = kvm_openpic_write, + .read = kvm_openpic_read, + .endianness =DEVICE_BIG_ENDIAN , + .impl = { + .min_access_size =4 , + .max_access_size =4 , + }, +}; + +static void kvm_openpic_region_add (MemoryListener *listener, +MemoryRegionSection *section) +{ + KVMOpenPICState *opp = container_of(listener, KVMOpenPICState,
hw/intc/openpic_kvm.c line 115
Quoted 10 lines
hw/intc/openpic_kvm.c new file +10
-0+ mem_listener); +struct kvm_device_attr attr; +uint64_t reg_base; +int ret; + +if (section->address_space != &address_space_memory) { +abort (); + } + +if (reg_base) {
Check on uninitialized variable.
Quoted 16 lines
hw/intc/openpic_kvm.c new file +16
-0+fprintf (stderr,"%s: reg_base already %llx\n" , __func__, reg_base); + } + + reg_base = section->offset_within_address_space; + + attr.group =KVM_DEV_MPIC_GRP_MISC ; + attr.attr =KVM_DEV_MPIC_BASE_ADDR ; + attr.addr = (uint64_t )(unsigned long )®_base; + + ret =ioctl (opp->fd,KVM_SET_DEVICE_ATTR , &attr); +if (ret <0 ) { +fprintf (stderr,"%s: %s %llx\n" , __func__,strerror (errno), reg_base); + } +} + +static void kvm_openpic_region_del(MemoryListener *listener,
hw/intc/openpic_kvm.c line 141
Quoted 10 lines
hw/intc/openpic_kvm.c new file +10
-0+ MemoryRegionSection *section) +{ +KVMOpenPICState *opp =container_of (listener, KVMOpenPICState, + mem_listener); +struct kvm_device_attr attr; +uint64_t reg_base =0 ; +int ret; + +if (!reg_base) { +return ;
This branch is always hit.
Alex
Re: [Qemu-devel] [Qemu-ppc] [PATCH 8/9] kvm/openpic: in-kernel mpic support
Quoted 18 lines · Alexander Graf
Quoted 4 lines · Scott Wood
hw/intc/openpic_kvm.c new file +4
-0+static void kvm_openpic_region_add (MemoryListener *listener, +MemoryRegionSection *section) +{ + KVMOpenPICState *opp = container_of(listener, KVMOpenPICState,hw/intc/openpic_kvm.c line 115
Quoted 10 lines
hw/intc/openpic_kvm.c new file +10
-0+ mem_listener); +struct kvm_device_attr attr; +uint64_t reg_base; +int ret; + +if (section->address_space != &address_space_memory) { +abort (); + } + +if (reg_base) {Check on uninitialized variable.
Oops, leftover debug code from when the code looked a bit different. :-P
I wonder why GCC (4.5) didn't warn about this.
-Scott
PATCH 9/9 KVM: PIC: Only commit irq routing when necessary
In reply to Scott WoodFrom: Alexander Graf <[email protected]>
The current logic updates KVM's view of our interrupt map every time we change it. While this is nice and bullet proof, it slows things down badly for me. QEMU spends about 3 seconds on every start telling KVM what news it has on its routing maps.
Instead, let's just synchronize the whole irq routing map as a whole when we're done constructing it. For things that change during runtime, we can still update the routing table on demand.
--- hw/i386/kvm/ioapic.c | 1 + hw/intc/openpic_kvm.c | 2 ++ include/sysemu/kvm.h | 1 + kvm-all.c | 6 +++--- 4 files changed, 7 insertions(+), 3 deletions(-)
hw/i386/kvm/ioapic.c +1 -0
@@ -40,6 +40,7 @@ void kvm_pc_setup_irq_routing(bool pci_enabled) } } } +kvm_irqchip_commit_routes (s); } }
hw/intc/openpic_kvm.c +2 -0
@@ -210,6 +210,8 @@ static int kvm_openpic_init(SysBusDevice *dev) kvm_msi_via_irqfd_allowed = true; kvm_gsi_routing_allowed = true; +kvm_irqchip_commit_routes (s); +return 0 ; }
include/sysemu/kvm.h +1 -0
@@ -220,6 +220,7 @@ int kvm_set_irq(KVMState *s, int irq, int level);int kvm_irqchip_send_msi (KVMState *s,MSIMessage msg);void kvm_irqchip_add_irq_route (KVMState *s,int gsi,int irqchip,int pin); +void kvm_irqchip_commit_routes (KVMState *s);void kvm_put_apic_state (DeviceState *d,struct kvm_lapic_state *kapic);void kvm_get_apic_state (DeviceState *d,struct kvm_lapic_state *kapic);
kvm-all.c +3 -3
@@ -957,7 +957,7 @@ void kvm_init_irq_routing(KVMState *s)kvm_arch_init_irq_routing (s); } -static void kvm_irqchip_commit_routes (KVMState *s) +void kvm_irqchip_commit_routes (KVMState *s) {int ret;
@@ -991,8 +991,6 @@ static void kvm_add_routing_entry(KVMState *s, new->u = entry->u;set_gsi (s, entry->gsi); - -kvm_irqchip_commit_routes (s); } static int kvm_update_routing_entry(KVMState *s,
@@ -1143,6 +1141,7 @@ int kvm_irqchip_send_msi(KVMState *s, MSIMessage msg) route->kroute.u.msi.data =le32_to_cpu (msg.data);kvm_add_routing_entry (s, &route->kroute); +kvm_irqchip_commit_routes (s);QTAILQ_INSERT_TAIL (&s->msi_hashtab[kvm_hash_msi (msg.data)], route, entry);
@@ -1175,6 +1174,7 @@ int kvm_irqchip_add_msi_route(KVMState *s, MSIMessage msg) kroute.u.msi.data =le32_to_cpu (msg.data);kvm_add_routing_entry (s, &kroute); +kvm_irqchip_commit_routes (s);return virq; }
Signature · 1 line
1.7.10.4
Alexander Graf
AppliedQuoted 8 lines · Scott Wood
From: Alexander Graf <[email protected]>
On PPC, we don't support MP state. So far it's not necessary and I'm not convinced yet that we really need to support it ever.
However, the current idle logic in QEMU assumes that an in-kernel PIC also means we support MP state. This assumption is not true anymore.
Quoted 6 lines
Let's split up the two cases into two different variables. That way PPC can expose an in-kernel PIC, while not implementing MP state.
Signed-off-by Alexander Graf <[email protected]>CC Jan Kiszka <[email protected]>Signed-off-by Scott Wood <[email protected]>
Thanks, applied all except 8/9 to ppc-next.
Alex
Quoted 12 lines · Alexander Graf
Quoted 6 lines · Scott Wood
From: Alexander Graf <[email protected]>
On PPC, we don't support MP state. So far it's not necessary and I'm not convinced yet that we really need to support it ever.
However, the current idle logic in QEMU assumes that an in-kernel
PIC
Quoted 2 lines
also means we support MP state. This assumption is not true anymore.
Quoted 8 lines
Quoted 6 lines
Let's split up the two cases into two different variables. That way PPC can expose an in-kernel PIC, while not implementing MP state.
Signed-off-by Alexander Graf <[email protected]>CC Jan Kiszka <[email protected]>Signed-off-by Scott Wood <[email protected]>Thanks, applied all except 8/9 to ppc-next.
Did you push? I don't see anything since early May on either repo.or.cz or github.
-Scott
Quoted 13 lines · Scott Wood
Quoted 12 lines · Alexander Graf
Quoted 11 lines · Scott Wood
From: Alexander Graf <[email protected]>
On PPC, we don't support MP state. So far it's not necessary and I'm not convinced yet that we really need to support it ever.
However, the current idle logic in QEMU assumes that an in-kernel PIC also means we support MP state. This assumption is not true anymore.
Let's split up the two cases into two different variables. That way PPC can expose an in-kernel PIC, while not implementing MP state.
Quoted 6 lines
Quoted 4 lines
Quoted 3 lines
Signed-off-by Alexander Graf <[email protected]>CC Jan Kiszka <[email protected]>Signed-off-by Scott Wood <[email protected]>Thanks, applied all except 8/9 to ppc-next.
Did you push? I don't see anything since early May on either repo.or.cz or github.
Sorry, I forgot to push. It's pushed to github now. I'm gradually deprecating the repo.or.cz one.
Alex