From patchwork Mon Sep 1 12:52:44 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 4819201 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D6B79C0338 for ; Mon, 1 Sep 2014 12:57:07 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1181520160 for ; Mon, 1 Sep 2014 12:57:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1EEBE2013A for ; Mon, 1 Sep 2014 12:57:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753937AbaIAMxs (ORCPT ); Mon, 1 Sep 2014 08:53:48 -0400 Received: from mail-wi0-f177.google.com ([209.85.212.177]:51252 "EHLO mail-wi0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753900AbaIAMxp (ORCPT ); Mon, 1 Sep 2014 08:53:45 -0400 Received: by mail-wi0-f177.google.com with SMTP id cc10so6044949wib.16 for ; Mon, 01 Sep 2014 05:53:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=AHAX+77uTqlmj5Ax6AhDKOfRw4M4xiXOYff3RvKJh/w=; b=C+d1i0/19VfTaxro7StON8HNk2pekl38W91sELn1/wfU1jHrw3rlYJipxA+dUCQFAK AfJ75NvyR5yRsXwdCsg/sBh0OlDKJ40wGc+C0ep7itKSVzzK50/dVh7D0xfxFh+WaQVg 0QmWYSqEzBZZceCm7A0c2nncKqrDhNt0sWnplFp0y8op8Vsr+adTU2AjVXBLyM6N9Wk4 HxJkRQI7is38JTQ3JT89yukAteWBAONcvOo40qofXzNDPGlhrAtmxdcHxxYizUCV7FsM DyEmWsVRKNOlnVVkaOWj/U+MJGIutP7ZmTJNi8rjz776Oh4NFCYYZWTbqB/aNPxUlSyv N/mQ== X-Gm-Message-State: ALoCoQkwxSlVzPUT80CDo9yOrrTth25CW24OgUE0iP4ClTuow8hjLb9yS8VxY54nvdcjXN1szD7v X-Received: by 10.194.122.6 with SMTP id lo6mr31825678wjb.17.1409576024266; Mon, 01 Sep 2014 05:53:44 -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.42 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Sep 2014 05:53:43 -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 5/9] KVM: KVM-VFIO: update user API to program forwarded IRQ Date: Mon, 1 Sep 2014 14:52:44 +0200 Message-Id: <1409575968-5329-6-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> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-8.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP add new device group commands: - KVM_DEV_VFIO_DEVICE_FORWARD_IRQ and KVM_DEV_VFIO_DEVICE_UNFORWARD_IRQ which enable to turn forwarded IRQ mode on/off. the kvm_arch_forwarded_irq struct embodies a forwarded IRQ Signed-off-by: Eric Auger --- v1 -> v2: - struct kvm_arch_forwarded_irq moved from arch/arm/include/uapi/asm/kvm.h to include/uapi/linux/kvm.h also irq_index renamed into index and guest_irq renamed into gsi - ASSIGN/DEASSIGN renamed into FORWARD/UNFORWARD --- Documentation/virtual/kvm/devices/vfio.txt | 26 ++++++++++++++++++++++++++ include/uapi/linux/kvm.h | 9 +++++++++ 2 files changed, 35 insertions(+) diff --git a/Documentation/virtual/kvm/devices/vfio.txt b/Documentation/virtual/kvm/devices/vfio.txt index ef51740..048baa0 100644 --- a/Documentation/virtual/kvm/devices/vfio.txt +++ b/Documentation/virtual/kvm/devices/vfio.txt @@ -13,6 +13,7 @@ VFIO-group is held by KVM. Groups: KVM_DEV_VFIO_GROUP + KVM_DEV_VFIO_DEVICE KVM_DEV_VFIO_GROUP attributes: KVM_DEV_VFIO_GROUP_ADD: Add a VFIO group to VFIO-KVM device tracking @@ -20,3 +21,28 @@ KVM_DEV_VFIO_GROUP attributes: For each, kvm_device_attr.addr points to an int32_t file descriptor for the VFIO group. + +KVM_DEV_VFIO_DEVICE attributes: + KVM_DEV_VFIO_DEVICE_FORWARD_IRQ + KVM_DEV_VFIO_DEVICE_UNFORWARD_IRQ + +For each, kvm_device_attr.addr points to a kvm_arch_forwarded_irq struct. +This user API makes possible to create a special IRQ handling mode, +where KVM and a VFIO platform driver collaborate to improve IRQ +handling performance. + +fd represents the file descriptor of a valid VFIO device whose physical +IRQ, referenced by its index, is injected into the VM guest irq (gsi). + +On FORWARD_IRQ, KVM-VFIO device programs: +- the host, to not complete the physical IRQ itself. +- the GIC, to automatically complete the physical IRQ when the guest + completes the virtual IRQ. +This avoids trapping the end-of-interrupt for level sensitive IRQ. + +On UNFORWARD_IRQ, one returns to the mode where the host completes the +physical IRQ and the guest completes the virtual IRQ. + +It is up to the caller of this API to make sure the IRQ is not +outstanding when the FORWARD/UNFORWARD is called. This could lead to +some inconsistency on who is going to complete the IRQ. diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index cf3a2ff..8cd7b0e 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -947,6 +947,12 @@ struct kvm_device_attr { __u64 addr; /* userspace address of attr data */ }; +struct kvm_arch_forwarded_irq { + __u32 fd; /* file desciptor of the VFIO device */ + __u32 index; /* VFIO device IRQ index */ + __u32 gsi; /* gsi, ie. virtual IRQ number */ +}; + #define KVM_DEV_TYPE_FSL_MPIC_20 1 #define KVM_DEV_TYPE_FSL_MPIC_42 2 #define KVM_DEV_TYPE_XICS 3 @@ -954,6 +960,9 @@ struct kvm_device_attr { #define KVM_DEV_VFIO_GROUP 1 #define KVM_DEV_VFIO_GROUP_ADD 1 #define KVM_DEV_VFIO_GROUP_DEL 2 +#define KVM_DEV_VFIO_DEVICE 2 +#define KVM_DEV_VFIO_DEVICE_FORWARD_IRQ 1 +#define KVM_DEV_VFIO_DEVICE_UNFORWARD_IRQ 2 #define KVM_DEV_TYPE_ARM_VGIC_V2 5 #define KVM_DEV_TYPE_FLIC 6