From patchwork Sun Nov 23 18:35:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 41390 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 598862036A for ; Sun, 23 Nov 2014 18:37:43 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id b57sf4875078eek.1 for ; Sun, 23 Nov 2014 10:37:42 -0800 (PST) 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=9dzYUFSVMO6Kilk2we25tR14toghHSuH1ylxjvw88ts=; b=Q7Fk6n5nQbP8eJHn1gIkQeZE5BKtAkIIOyFR8hIhspryK80SThc/i9KsNEi4mezi8A VJejqQBeFjCeMkSIqA8zn1E01y3YzIUHTjo8DGPJPMqpdjS923UDkcWySs+jG5/7Gue+ G3Kud/DQuOaDkd0hTQ//JrB8Z7vynGCE6/Am6CJfMo0fTkyN+v/4tDGWAvVacUBe0vjd Ew+3+89PCKnkV7El2AWzhKgqboCYzZDrbZpmdidmdZjCKtQoHxQcAfw6Dm+0h6FeaBkU W1DX6Jm6uPjo62C/MCuyjL/KyLUYAlLr6Be0wggbOPuSaQ15uemkGgBhBgO7W4/WokIw fj4g== X-Gm-Message-State: ALoCoQmo1QPKu0W08EpH+r2ehm4dfy4fpcy2veVlV/jV8f1ywpzdDSxc++i7d7/l62CE/Uh8CaDM X-Received: by 10.180.106.67 with SMTP id gs3mr2954283wib.3.1416767862493; Sun, 23 Nov 2014 10:37:42 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.6.134 with SMTP id b6ls316603laa.77.gmail; Sun, 23 Nov 2014 10:37:42 -0800 (PST) X-Received: by 10.112.146.37 with SMTP id sz5mr16466291lbb.27.1416767862336; Sun, 23 Nov 2014 10:37:42 -0800 (PST) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id b19si12798071lbq.121.2014.11.23.10.37.41 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:37:41 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by mail-la0-f49.google.com with SMTP id hs14so6444250lab.22 for ; Sun, 23 Nov 2014 10:37:41 -0800 (PST) X-Received: by 10.152.6.228 with SMTP id e4mr16484462laa.71.1416767861923; Sun, 23 Nov 2014 10:37:41 -0800 (PST) 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.112.184.201 with SMTP id ew9csp156306lbc; Sun, 23 Nov 2014 10:37:41 -0800 (PST) X-Received: by 10.180.91.70 with SMTP id cc6mr15583811wib.5.1416767861259; Sun, 23 Nov 2014 10:37:41 -0800 (PST) Received: from mail-wg0-f50.google.com (mail-wg0-f50.google.com. [74.125.82.50]) by mx.google.com with ESMTPS id wo10si19598086wjc.32.2014.11.23.10.37.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:37:41 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 74.125.82.50 as permitted sender) client-ip=74.125.82.50; Received: by mail-wg0-f50.google.com with SMTP id k14so10400496wgh.23 for ; Sun, 23 Nov 2014 10:37:38 -0800 (PST) X-Received: by 10.194.205.103 with SMTP id lf7mr26171277wjc.134.1416767858089; Sun, 23 Nov 2014 10:37:38 -0800 (PST) Received: from gnx2579.gnb.st.com (weg38-3-78-232-41-119.fbx.proxad.net. [78.232.41.119]) by mx.google.com with ESMTPSA id hk9sm17535471wjb.46.2014.11.23.10.37.35 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 23 Nov 2014 10:37:37 -0800 (PST) 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, agraf@suse.de 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, ming.lei@canonical.com, feng.wu@intel.com Subject: [PATCH v3 4/8] KVM: kvm-vfio: User API for IRQ forwarding Date: Sun, 23 Nov 2014 19:35:56 +0100 Message-Id: <1416767760-14487-5-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1416767760-14487-1-git-send-email-eric.auger@linaro.org> References: <1416767760-14487-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.215.49 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: , This patch adds and document a new KVM_DEV_VFIO_DEVICE group and 2 device attributes: KVM_DEV_VFIO_DEVICE_FORWARD_IRQ, KVM_DEV_VFIO_DEVICE_UNFORWARD_IRQ. The purpose is to be able to set a VFIO device IRQ as forwarded or not forwarded. the command takes as argument a handle to a new struct named kvm_arch_forwarded_irq. Signed-off-by: Eric Auger --- v2 -> v3: - rework vfio kvm device documentation - reword commit message and title - add subindex in kvm_arch_forwarded_irq to be closer to VFIO API - forwarding state can only be changed with VFIO IRQ signaling is off 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 | 34 ++++++++++++++++++++++++------ include/uapi/linux/kvm.h | 10 +++++++++ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/Documentation/virtual/kvm/devices/vfio.txt b/Documentation/virtual/kvm/devices/vfio.txt index ef51740..f7aff29 100644 --- a/Documentation/virtual/kvm/devices/vfio.txt +++ b/Documentation/virtual/kvm/devices/vfio.txt @@ -4,15 +4,24 @@ VFIO virtual device Device types supported: KVM_DEV_TYPE_VFIO -Only one VFIO instance may be created per VM. The created device -tracks VFIO groups in use by the VM and features of those groups -important to the correctness and acceleration of the VM. As groups -are enabled and disabled for use by the VM, KVM should be updated -about their presence. When registered with KVM, a reference to the -VFIO-group is held by KVM. +Only one VFIO instance may be created per VM. + +The created device tracks VFIO groups in use by the VM and features +of those groups important to the correctness and acceleration of +the VM. As groups are enabled and disabled for use by the VM, KVM +should be updated about their presence. When registered with KVM, +a reference to the VFIO-group is held by KVM. + +The device also tracks & enable VFIO device forwarded IRQs, if any. +A physical forwarded IRQ is directly completed by the guest. This +requires HW support in the interrupt controller which must be able +to automatically complete the physical IRQ when it detects the guest +has completed the corresponding virtual IRQ. The modality sometimes +is named direct EOI. 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 +29,16 @@ 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: set a VFIO device IRQ as forwarded + KVM_DEV_VFIO_DEVICE_UNFORWARD_IRQ: set a VFIO device IRQ as not forwarded + +For each, kvm_device_attr.addr points to a kvm_arch_forwarded_irq struct. + +The forwarded state can only be changed when the VFIO signaling mechanism +for this physical IRQ is not set. In other words, forwarding must be +activated before VFIO_DEVICE_SET_IRQS has been called to trigger the IRQ +or associate an eventfd to it. Unforwarding can only be called while the +signaling has been disabled with VFIO_DEVICE_SET_IRQS. If this condition is +not satisfied, the command returns an -EBUSY. diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 6076882..a269a42 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -946,6 +946,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 enum kvm_device_type { KVM_DEV_TYPE_FSL_MPIC_20 = 1, @@ -963,6 +966,13 @@ enum kvm_device_type { KVM_DEV_TYPE_MAX, }; +struct kvm_arch_forwarded_irq { + __u32 fd; /* file desciptor of the VFIO device */ + __u32 index; /* VFIO device IRQ index */ + __u32 subindex; /* VFIO device IRQ subindex */ + __u32 gsi; /* gsi, ie. virtual IRQ number */ +}; + /* * ioctls for VM fds */