From patchwork Mon Apr 1 22:47:53 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Wood X-Patchwork-Id: 2373301 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id F148CDFE82 for ; Mon, 1 Apr 2013 22:48:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1759280Ab3DAWsW (ORCPT ); Mon, 1 Apr 2013 18:48:22 -0400 Received: from co9ehsobe003.messaging.microsoft.com ([207.46.163.26]:58344 "EHLO co9outboundpool.messaging.microsoft.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758910Ab3DAWsE (ORCPT ); Mon, 1 Apr 2013 18:48:04 -0400 Received: from mail162-co9-R.bigfish.com (10.236.132.244) by CO9EHSOBE010.bigfish.com (10.236.130.73) with Microsoft SMTP Server id 14.1.225.23; Mon, 1 Apr 2013 22:48:03 +0000 Received: from mail162-co9 (localhost [127.0.0.1]) by mail162-co9-R.bigfish.com (Postfix) with ESMTP id A1C833E020F; Mon, 1 Apr 2013 22:48:03 +0000 (UTC) X-Forefront-Antispam-Report: CIP:70.37.183.190; KIP:(null); UIP:(null); IPV:NLI; H:mail.freescale.net; RD:none; EFVD:NLI X-SpamScore: 1 X-BigFish: VS1(z551bizzz1f42h1fc6h1ee6h1de0h1202h1e76h1d1ah1d2ahzz8275bhz2dh2a8h668h839hd24he5bhf0ah1288h12a5h12a9h12bdh12e5h137ah139eh13b6h1441h1504h1537h162dh1631h1758h1898h18e1h1946h19b5h1ad9h1b0ah1155h) Received: from mail162-co9 (localhost.localdomain [127.0.0.1]) by mail162-co9 (MessageSwitch) id 136485648212957_27549; Mon, 1 Apr 2013 22:48:02 +0000 (UTC) Received: from CO9EHSMHS014.bigfish.com (unknown [10.236.132.234]) by mail162-co9.bigfish.com (Postfix) with ESMTP id 000572E027A; Mon, 1 Apr 2013 22:48:01 +0000 (UTC) Received: from mail.freescale.net (70.37.183.190) by CO9EHSMHS014.bigfish.com (10.236.130.24) with Microsoft SMTP Server (TLS) id 14.1.225.23; Mon, 1 Apr 2013 22:47:59 +0000 Received: from tx30smr01.am.freescale.net (10.81.153.31) by 039-SN1MMR1-005.039d.mgd.msft.net (10.84.1.17) with Microsoft SMTP Server (TLS) id 14.2.328.11; Mon, 1 Apr 2013 22:47:58 +0000 Received: from snotra.am.freescale.net ([10.214.82.232]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id r31MlrhK004047; Mon, 1 Apr 2013 15:47:58 -0700 From: Scott Wood To: Alexander Graf CC: , , , Scott Wood Subject: [RFC PATCH v2 6/6] kvm/ppc/mpic: add KVM_CAP_IRQ_MPIC Date: Mon, 1 Apr 2013 17:47:53 -0500 Message-ID: <1364856473-25245-7-git-send-email-scottwood@freescale.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1364856473-25245-1-git-send-email-scottwood@freescale.com> References: <1360820960-12537-1-git-send-email-scottwood@freescale.com> <1364856473-25245-1-git-send-email-scottwood@freescale.com> MIME-Version: 1.0 X-OriginatorOrg: freescale.com Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Enabling this capability connects the vcpu to the designated in-kernel MPIC. Using explicit connections between vcpus and irqchips allows for flexibility, but the main benefit at the moment is that it simplifies the code -- KVM doesn't need vm-global state to remember which MPIC object is associated with this vm, and it doesn't need to care about ordering between irqchip creation and vcpu creation. Signed-off-by: Scott Wood --- Documentation/virtual/kvm/api.txt | 8 ++++++ arch/powerpc/include/asm/kvm_host.h | 10 ++++--- arch/powerpc/include/asm/kvm_ppc.h | 2 ++ arch/powerpc/kvm/booke.c | 4 ++- arch/powerpc/kvm/mpic.c | 49 +++++++++++++++++++++++++++++++---- arch/powerpc/kvm/powerpc.c | 25 +++++++++++++++--- include/uapi/linux/kvm.h | 1 + 7 files changed, 86 insertions(+), 13 deletions(-) diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt index 77328aa..38f9b6d 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt @@ -2728,3 +2728,11 @@ to receive the topmost interrupt vector. When disabled (args[0] == 0), behavior is as if this facility is unsupported. When this capability is enabled, KVM_EXIT_EPR can occur. + +6.6 KVM_CAP_IRQ_MPIC + +Architectures: ppc +Parameters: args[0] is the MPIC device fd + args[1] is the MPIC CPU number for this vcpu + +This capability connects the vcpu to an in-kernel MPIC device. diff --git a/arch/powerpc/include/asm/kvm_host.h b/arch/powerpc/include/asm/kvm_host.h index 6713327..2a2e235 100644 --- a/arch/powerpc/include/asm/kvm_host.h +++ b/arch/powerpc/include/asm/kvm_host.h @@ -375,8 +375,10 @@ struct kvmppc_booke_debug_reg { u64 dac[KVMPPC_BOOKE_MAX_DAC]; }; -#define KVMPPC_IRQCHIP_NONE 0 -#define KVMPPC_IRQCHIP_MPIC 1 +#define KVMPPC_IRQ_DEFAULT 0 +#define KVMPPC_IRQ_MPIC 1 + +struct openpic; struct kvm_vcpu_arch { ulong host_stack; @@ -557,8 +559,8 @@ struct kvm_vcpu_arch { unsigned long magic_page_pa; /* phys addr to map the magic page to */ unsigned long magic_page_ea; /* effect. addr to map the magic page to */ - int irqchip_type; - void *irqchip_priv; + int irq_type; /* one of KVM_IRQ_* */ + struct openpic *mpic; /* KVM_IRQ_MPIC */ #ifdef CONFIG_KVM_BOOK3S_64_HV struct kvm_vcpu_arch_shared shregs; diff --git a/arch/powerpc/include/asm/kvm_ppc.h b/arch/powerpc/include/asm/kvm_ppc.h index 20b2a5e..2cc18a4 100644 --- a/arch/powerpc/include/asm/kvm_ppc.h +++ b/arch/powerpc/include/asm/kvm_ppc.h @@ -273,6 +273,8 @@ static inline void kvmppc_set_epr(struct kvm_vcpu *vcpu, u32 epr) } void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu); +int kvmppc_mpic_connect_vcpu(struct file *mpic_filp, struct kvm_vcpu *vcpu, + u32 cpu); int kvm_vcpu_ioctl_config_tlb(struct kvm_vcpu *vcpu, struct kvm_config_tlb *cfg); diff --git a/arch/powerpc/kvm/booke.c b/arch/powerpc/kvm/booke.c index cddc6b3..7d00222 100644 --- a/arch/powerpc/kvm/booke.c +++ b/arch/powerpc/kvm/booke.c @@ -430,8 +430,10 @@ static int kvmppc_booke_irqprio_deliver(struct kvm_vcpu *vcpu, if (update_epr == true) { if (vcpu->arch.epr_flags & KVMPPC_EPR_USER) kvm_make_request(KVM_REQ_EPR_EXIT, vcpu); - else if (vcpu->arch.epr_flags & KVMPPC_EPR_KERNEL) + else if (vcpu->arch.epr_flags & KVMPPC_EPR_KERNEL) { + BUG_ON(vcpu->arch.irq_type != KVMPPC_IRQ_MPIC); kvmppc_mpic_set_epr(vcpu); + } } new_msr &= msr_mask; diff --git a/arch/powerpc/kvm/mpic.c b/arch/powerpc/kvm/mpic.c index 9aace50..b790f47 100644 --- a/arch/powerpc/kvm/mpic.c +++ b/arch/powerpc/kvm/mpic.c @@ -1159,7 +1159,7 @@ static uint32_t openpic_iack(struct openpic *opp, struct irq_dest *dst, void kvmppc_mpic_set_epr(struct kvm_vcpu *vcpu) { - struct openpic *opp = vcpu->arch.irqchip_priv; + struct openpic *opp = vcpu->arch.mpic; int cpu = vcpu->vcpu_id; unsigned long flags; @@ -1442,10 +1442,10 @@ static void map_mmio(struct openpic *opp) static void unmap_mmio(struct openpic *opp) { - BUG_ON(opp->mmio_mapped); - opp->mmio_mapped = false; - - kvm_io_bus_unregister_dev(opp->kvm, KVM_MMIO_BUS, &opp->mmio); + if (opp->mmio_mapped) { + opp->mmio_mapped = false; + kvm_io_bus_unregister_dev(opp->kvm, KVM_MMIO_BUS, &opp->mmio); + } } static int set_base_addr(struct openpic *opp, struct kvm_device_attr *attr) @@ -1683,6 +1683,45 @@ static const struct file_operations kvm_mpic_fops = { .release = kvm_mpic_release, }; +int kvmppc_mpic_connect_vcpu(struct file *mpic_filp, struct kvm_vcpu *vcpu, + u32 cpu) +{ + struct openpic *opp = mpic_filp->private_data; + int ret = 0; + + if (mpic_filp->f_op != &kvm_mpic_fops) + return -EPERM; + if (opp->kvm != vcpu->kvm) + return -EPERM; + if (cpu < 0 || cpu >= MAX_CPU) + return -EPERM; + + spin_lock_irq(&opp->lock); + + if (opp->dst[cpu].vcpu) { + ret = -EEXIST; + goto out; + } + if (vcpu->arch.irq_type) { + return -EBUSY; + goto out; + } + + opp->dst[cpu].vcpu = vcpu; + opp->nb_cpus = max(opp->nb_cpus, cpu + 1); + + vcpu->arch.mpic = opp; + vcpu->arch.irq_type = KVMPPC_IRQ_MPIC; + atomic_inc(&opp->users); + + if (opp->mpic_mode_mask == GCR_MODE_PROXY) + vcpu->arch.epr_flags |= KVMPPC_EPR_KERNEL; + +out: + spin_unlock_irq(&opp->lock); + return ret; +} + int kvm_create_mpic(struct kvm *kvm, u32 type) { struct openpic *opp; diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c index 5656d12..9f67edd 100644 --- a/arch/powerpc/kvm/powerpc.c +++ b/arch/powerpc/kvm/powerpc.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -327,6 +328,9 @@ int kvm_dev_ioctl_check_extension(long ext) #if defined(CONFIG_KVM_E500V2) || defined(CONFIG_KVM_E500MC) case KVM_CAP_SW_TLB: #endif +#ifdef CONFIG_KVM_MPIC + case KVM_CAP_IRQ_MPIC: +#endif r = 1; break; case KVM_CAP_COALESCED_MMIO: @@ -461,9 +465,9 @@ void kvm_arch_vcpu_free(struct kvm_vcpu *vcpu) kvmppc_remove_vcpu_debugfs(vcpu); - switch (vcpu->arch.irqchip_type) { - case KVMPPC_IRQCHIP_MPIC: - mpic_put(vcpu->arch.irqchip_priv); + switch (vcpu->arch.irq_type) { + case KVMPPC_IRQ_MPIC: + mpic_put(vcpu->arch.mpic); break; } @@ -801,6 +805,21 @@ static int kvm_vcpu_ioctl_enable_cap(struct kvm_vcpu *vcpu, break; } #endif +#ifdef CONFIG_KVM_MPIC + case KVM_CAP_IRQ_MPIC: { + struct file *filp; + + r = -EBADF; + filp = fget(cap->args[0]); + if (!filp) + break; + + r = kvmppc_mpic_connect_vcpu(filp, vcpu, cap->args[1]); + + fput(filp); + break; + } +#endif default: r = -EINVAL; break; diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index d8f44ef..22fce7b 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -669,6 +669,7 @@ struct kvm_ppc_smmu_info { #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 #ifdef KVM_CAP_IRQ_ROUTING