From patchwork Mon Sep 1 12:52:48 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 36364 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f198.google.com (mail-ie0-f198.google.com [209.85.223.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 95F8C2032B for ; Mon, 1 Sep 2014 12:53:58 +0000 (UTC) Received: by mail-ie0-f198.google.com with SMTP id rl12sf31259422iec.9 for ; Mon, 01 Sep 2014 05:53:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=nPM3fID2RE0yIsDO5AqK5OVf9EUfCt8ilZ3g0Dpq8ek=; b=CtdWONY5mJpokIk9lsxlY1B85//E4Iqe4lE8e2YIJPs0OS9tvZ4cZXJ9vQhRjmg0Kq z4JxLzkZ1X/Qe4/EFJUYnQYGWQgg2s8zlA2SoEHINyZdPTZt58QmcLa5xk2ZwB5VkaxQ sr/prXZWMordYTSi693H1x0c/Rp+AS+v0oJWsV3F29Ftqh3TpYaRxxwY7ewWXBKqL3iw StuZWXoOjBQavLnXzHfytHoieDk6ynxescjozUzesx5Q7O+kQC4LcaQRT55DbIU2AF5q oPC/WVNaSBwtVgsnVW0DrxxiP273Zys65hFBleqeM2UtUXiXWiGDmgjtISpfInxElf6p 6yWQ== X-Gm-Message-State: ALoCoQkgGDFP6M0/OtN9aVhbfl/uqpfzVOe7TDhbWWwg8H60L4tOC+Sc8YVnJN3e6MQ5wCdyxZET X-Received: by 10.42.35.10 with SMTP id o10mr16317140icd.6.1409576038236; Mon, 01 Sep 2014 05:53:58 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.21.200 with SMTP id 66ls2061181qgl.75.gmail; Mon, 01 Sep 2014 05:53:58 -0700 (PDT) X-Received: by 10.220.159.204 with SMTP id k12mr25195025vcx.15.1409576038133; Mon, 01 Sep 2014 05:53:58 -0700 (PDT) Received: from mail-vc0-f172.google.com (mail-vc0-f172.google.com [209.85.220.172]) by mx.google.com with ESMTPS id w18si282410vdj.103.2014.09.01.05.53.58 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Sep 2014 05:53:58 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) client-ip=209.85.220.172; Received: by mail-vc0-f172.google.com with SMTP id ij19so5527474vcb.3 for ; Mon, 01 Sep 2014 05:53:58 -0700 (PDT) X-Received: by 10.52.97.233 with SMTP id ed9mr21144948vdb.16.1409576038056; Mon, 01 Sep 2014 05:53:58 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp383173vcb; Mon, 1 Sep 2014 05:53:57 -0700 (PDT) X-Received: by 10.180.188.205 with SMTP id gc13mr21645304wic.66.1409576036963; Mon, 01 Sep 2014 05:53:56 -0700 (PDT) Received: from mail-wi0-f174.google.com (mail-wi0-f174.google.com [209.85.212.174]) by mx.google.com with ESMTPS id fy15si960935wjc.154.2014.09.01.05.53.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Sep 2014 05:53:56 -0700 (PDT) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.212.174 as permitted sender) client-ip=209.85.212.174; Received: by mail-wi0-f174.google.com with SMTP id d1so12571620wiv.7 for ; Mon, 01 Sep 2014 05:53:56 -0700 (PDT) X-Received: by 10.195.12.4 with SMTP id em4mr2801872wjd.98.1409576036370; Mon, 01 Sep 2014 05:53:56 -0700 (PDT) Received: from gnx2579.gnb.st.com (LCaen-156-56-7-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by mx.google.com with ESMTPSA id y5sm1928678wje.32.2014.09.01.05.53.54 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Sep 2014 05:53:55 -0700 (PDT) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, christoffer.dall@linaro.org, marc.zyngier@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, alex.williamson@redhat.com, joel.schopp@amd.com, kim.phillips@freescale.com, paulus@samba.org, gleb@kernel.org, pbonzini@redhat.com Cc: linux-kernel@vger.kernel.org, patches@linaro.org, will.deacon@arm.com, a.motakis@virtualopensystems.com, a.rigo@virtualopensystems.com, john.liuli@huawei.com Subject: [RFC v2 9/9] KVM: KVM-VFIO: ARM forwarding control Date: Mon, 1 Sep 2014 14:52:48 +0200 Message-Id: <1409575968-5329-10-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1409575968-5329-1-git-send-email-eric.auger@linaro.org> References: <1409575968-5329-1-git-send-email-eric.auger@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: eric.auger@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.172 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Enables forwarding control for ARM. By defining __KVM_HAVE_ARCH_KVM_VFIO_FORWARD the patch enables KVM_DEV_VFIO_DEVICE_FORWARD/UNFORWARD_IRQ command on ARM. As a result it brings an optimized injection/completion handling for forwarded IRQ. The ARM specific part is implemented in a new module, kvm_vfio_arm.c Signed-off-by: Eric Auger --- arch/arm/include/asm/kvm_host.h | 2 + arch/arm/kvm/Makefile | 2 +- arch/arm/kvm/kvm_vfio_arm.c | 85 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 88 insertions(+), 1 deletion(-) create mode 100644 arch/arm/kvm/kvm_vfio_arm.c diff --git a/arch/arm/include/asm/kvm_host.h b/arch/arm/include/asm/kvm_host.h index 1aee6bb..dfd3b05 100644 --- a/arch/arm/include/asm/kvm_host.h +++ b/arch/arm/include/asm/kvm_host.h @@ -25,6 +25,8 @@ #include #include +#define __KVM_HAVE_ARCH_KVM_VFIO_FORWARD + #if defined(CONFIG_KVM_ARM_MAX_VCPUS) #define KVM_MAX_VCPUS CONFIG_KVM_ARM_MAX_VCPUS #else diff --git a/arch/arm/kvm/Makefile b/arch/arm/kvm/Makefile index ea1fa76..26a5a42 100644 --- a/arch/arm/kvm/Makefile +++ b/arch/arm/kvm/Makefile @@ -19,7 +19,7 @@ kvm-arm-y = $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o $(KVM)/eventfd.o $(KVM)/vf obj-y += kvm-arm.o init.o interrupts.o obj-y += arm.o handle_exit.o guest.o mmu.o emulate.o reset.o -obj-y += coproc.o coproc_a15.o coproc_a7.o mmio.o psci.o perf.o +obj-y += coproc.o coproc_a15.o coproc_a7.o mmio.o psci.o perf.o kvm_vfio_arm.o obj-$(CONFIG_KVM_ARM_VGIC) += $(KVM)/arm/vgic.o obj-$(CONFIG_KVM_ARM_VGIC) += $(KVM)/arm/vgic-v2.o obj-$(CONFIG_KVM_ARM_TIMER) += $(KVM)/arm/arch_timer.o diff --git a/arch/arm/kvm/kvm_vfio_arm.c b/arch/arm/kvm/kvm_vfio_arm.c new file mode 100644 index 0000000..0d316b1 --- /dev/null +++ b/arch/arm/kvm/kvm_vfio_arm.c @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2014 Linaro Ltd. + * Authors: Eric Auger + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 2, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/** + * kvm_arch_set_fwd_state - change the forwarded state of an IRQ + * @pfwd: the forwarded irq struct + * @action: action to perform (set forward, set back normal, cleanup) + * + * programs the GIC and VGIC + * returns the VGIC map/unmap return status + * It is the responsability of the caller to make sure the physical IRQ + * is not active. there is a critical section between the start of the + * VFIO IRQ handler and LR programming. + */ +int kvm_arch_set_fwd_state(struct kvm_fwd_irq *pfwd, + enum kvm_fwd_irq_action action) +{ + int ret; + struct irq_desc *desc = irq_to_desc(pfwd->hwirq); + struct irq_data *d = &desc->irq_data; + struct irq_chip *chip = desc->irq_data.chip; + + disable_irq(pfwd->hwirq); + /* no fwd state change can happen if the IRQ is in progress */ + if (irqd_irq_inprogress(d)) { + kvm_err("%s cannot change fwd state (IRQ %d in progress\n", + __func__, pfwd->hwirq); + enable_irq(pfwd->hwirq); + return -1; + } + + if (action == KVM_VFIO_IRQ_SET_FORWARD) { + irqd_set_irq_forwarded(d); + ret = vgic_map_phys_irq(pfwd->vcpu, + pfwd->gsi + VGIC_NR_PRIVATE_IRQS, + pfwd->hwirq); + } else if (action == KVM_VFIO_IRQ_SET_NORMAL) { + irqd_clr_irq_forwarded(d); + ret = vgic_unmap_phys_irq(pfwd->vcpu, + pfwd->gsi + + VGIC_NR_PRIVATE_IRQS, + pfwd->hwirq); + } else if (action == KVM_VFIO_IRQ_CLEANUP) { + irqd_clr_irq_forwarded(d); + /* + * in case the guest did not complete the + * virtual IRQ, let's do it for him. + * when cleanup is called, VCPU have already + * been freed, do not manipulate VGIC + */ + chip->irq_eoi(d); + ret = 0; + } else { + enable_irq(pfwd->hwirq); + ret = -EINVAL; + } + + enable_irq(pfwd->hwirq); + return ret; +}