From patchwork Mon Apr 13 12:29:19 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 6208761 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 9E54ABF4A6 for ; Mon, 13 Apr 2015 12:42:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B1CBB202D1 for ; Mon, 13 Apr 2015 12:42:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A0A032034B for ; Mon, 13 Apr 2015 12:42:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932675AbbDMMmX (ORCPT ); Mon, 13 Apr 2015 08:42:23 -0400 Received: from mail-wg0-f48.google.com ([74.125.82.48]:33835 "EHLO mail-wg0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754432AbbDMMck (ORCPT ); Mon, 13 Apr 2015 08:32:40 -0400 Received: by wgso17 with SMTP id o17so79113761wgs.1 for ; Mon, 13 Apr 2015 05:32:38 -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=x71EtNbnladd++cWo81ENhwSrXP/y5sLLIgBvWQyirA=; b=EzyQb2P84AtsJU52II+z8MSXo3pbe1kcBWHh0Ba05ANU0qqe3oG6PIPw94VxIH7nM1 v/9tpeBqgZwHwO+A3TI946ZXUmE13688Bx7VHiGJVUUVYVMGbEOyzrpqt3flkXsMSqRg nbT3ODKeDaCiTWym2IBy50ndpkQ3MKpXZksKKh+VbXOJn0NAF1WA4KLlwXewGgI35DQ0 3z699os2Ze3fy7hYa2sUf6H0hH8sEQ1+siSbjnP6l/Z9zkl5eMdIfvYbVPumxBLl3qym hljL0ptt7VOn4qkYLpKOELdhU9dZxaMZLUo4uRc1aUYEelOgWwFUIzQh/SPoTTj1a7WO omoQ== X-Gm-Message-State: ALoCoQk7DsIuThhqmdEspb4tYta0mvR1kP6OKbYiKuojKvT01W9absv+GnvdPW4bNE0vEDTKMsZU X-Received: by 10.195.11.73 with SMTP id eg9mr26900719wjd.62.1428928358849; Mon, 13 Apr 2015 05:32:38 -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 fl14sm2879910wjc.11.2015.04.13.05.32.37 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 Apr 2015 05:32:38 -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, pbonzini@redhat.com Cc: linux-kernel@vger.kernel.org, patches@linaro.org, feng.wu@intel.com, b.reynal@virtualopensystems.com Subject: [RFC v6 04/16] KVM: kvm-vfio: User API for IRQ forwarding Date: Mon, 13 Apr 2015 14:29:19 +0200 Message-Id: <1428928171-18884-5-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1428928171-18884-1-git-send-email-eric.auger@linaro.org> References: <1428928171-18884-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=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 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 8055706..1b78dd3 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -945,6 +945,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, @@ -964,6 +967,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 */