From patchwork Wed Feb 11 08:32:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 44560 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CC13A21527 for ; Wed, 11 Feb 2015 08:35:09 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id x12sf1212137wgg.0 for ; Wed, 11 Feb 2015 00:35:09 -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=rtcdkXoaJr3Yqre29bzos/d4v/IXOA8/mbbLu96LEes=; b=bKY3mqRcA53509stH7czyCxi2M6yjvytoH77PaHxUPGRUJdIKLHkmrYoNwk1GVlq68 pv0bvB3XEfY2ZBAr4jXtAfYJ2vCeK5mpYGDTON/LhwvONFuBsX4t1RMHRrKnVYkCoKYZ l6DrFUsDpbKhZjUO6VL1mFSZQzGXWvdPJrooNjzfouNaOfX5wdpFDvRvTuNOHZLBtzt6 9Qn9LfeEFodi1EFRBmpZo5j4Tc49Y4SvKjVqkz3mLsfIQ/0NFO0UGH5nrwM+su1iZSM/ kNtj+cAIMjPM7/1bMcxwWeZ2qrQFfCcUG2vLZftZCWgPlKAvLl4wlvp/xFJgYKj2Sx/t Sx0A== X-Gm-Message-State: ALoCoQlUisoCKJ3NPZCTgOrtd4EImvM9ihlATOn2ZG3glfd/h8ROEIrxiKU0IgcRz3csGAg+ukTG X-Received: by 10.194.142.174 with SMTP id rx14mr3252196wjb.4.1423643709122; Wed, 11 Feb 2015 00:35:09 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.25.229 with SMTP id f5ls31649lag.15.gmail; Wed, 11 Feb 2015 00:35:08 -0800 (PST) X-Received: by 10.152.87.50 with SMTP id u18mr5021703laz.82.1423643708860; Wed, 11 Feb 2015 00:35:08 -0800 (PST) Received: from mail-lb0-f179.google.com (mail-lb0-f179.google.com. [209.85.217.179]) by mx.google.com with ESMTPS id lc2si109921lbb.21.2015.02.11.00.35.08 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Feb 2015 00:35:08 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.179 as permitted sender) client-ip=209.85.217.179; Received: by mail-lb0-f179.google.com with SMTP id w7so1782818lbi.10 for ; Wed, 11 Feb 2015 00:35:08 -0800 (PST) X-Received: by 10.152.45.100 with SMTP id l4mr26401382lam.112.1423643708775; Wed, 11 Feb 2015 00:35:08 -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.35.133 with SMTP id h5csp1110120lbj; Wed, 11 Feb 2015 00:35:07 -0800 (PST) X-Received: by 10.51.17.40 with SMTP id gb8mr2252093igd.44.1423643707114; Wed, 11 Feb 2015 00:35:07 -0800 (PST) Received: from mail-ie0-f181.google.com (mail-ie0-f181.google.com. [209.85.223.181]) by mx.google.com with ESMTPS id eb5si1317190icc.1.2015.02.11.00.35.06 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Feb 2015 00:35:07 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 209.85.223.181 as permitted sender) client-ip=209.85.223.181; Received: by iecrd18 with SMTP id rd18so2355158iec.5 for ; Wed, 11 Feb 2015 00:35:06 -0800 (PST) X-Received: by 10.50.30.3 with SMTP id o3mr28348998igh.44.1423643706361; Wed, 11 Feb 2015 00:35:06 -0800 (PST) Received: from gnx2579.solutionip.com ([113.28.134.59]) by mx.google.com with ESMTPSA id m38sm62189ioi.39.2015.02.11.00.35.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 11 Feb 2015 00:35:05 -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, feng.wu@intel.com Cc: andre.przywara@arm.com, patches@linaro.org, a.motakis@virtualopensystems.com, a.rigo@virtualopensystems.com, b.reynal@virtualopensystems.com, gleb@kernel.org, pbonzini@redhat.com Subject: [RFC v4 04/13] KVM: kvm-vfio: User API for IRQ forwarding Date: Wed, 11 Feb 2015 09:32:14 +0100 Message-Id: <1423643543-24409-5-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1423643543-24409-1-git-send-email-eric.auger@linaro.org> References: <1423643543-24409-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.217.179 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 documents 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_vfio_dev_irq. Signed-off-by: Eric Auger --- v3 -> v4: - rename kvm_arch_forwarded_irq into kvm_vfio_dev_irq - some rewording in commit message - document forwarding restrictions and remove unforwarding ones 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 | 12 +++++++++++ 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/Documentation/virtual/kvm/devices/vfio.txt b/Documentation/virtual/kvm/devices/vfio.txt index ef51740..6186e6d 100644 --- a/Documentation/virtual/kvm/devices/vfio.txt +++ b/Documentation/virtual/kvm/devices/vfio.txt @@ -4,15 +4,20 @@ 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 enables to control some IRQ settings of VFIO devices: +forwarding/posting. 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 +25,20 @@ 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_vfio_dev_irq struct. + +When forwarded, a physical IRQ is completed by the guest and not by the +host. This requires HW support in the interrupt controller. + +Forwarding can only be set when the corresponding VFIO IRQ is not masked +(would it be through VFIO_DEVICE_SET_IRQS command or as a consequence of this +IRQ being currently handled) or active at interrupt controller level. +In such a situation, -EAGAIN is returned. It is advised to to set the +forwarding before the VFIO signaling is set up, this avoids trial and errors. + +Unforwarding can happen at any time. diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index a37fd12..d1a6496 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -938,6 +938,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, @@ -955,6 +958,15 @@ enum kvm_device_type { KVM_DEV_TYPE_MAX, }; +struct kvm_vfio_dev_irq { + __u32 argsz; /* structure length */ + __u32 fd; /* file descriptor of the VFIO device */ + __u32 index; /* VFIO device IRQ index */ + __u32 start; /* start of subindex range */ + __u32 count; /* size of subindex range */ + __u32 gsi[]; /* gsi, ie. virtual IRQ number */ +}; + /* * ioctls for VM fds */