From patchwork Thu Jun 11 10:51:44 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Wu, Feng" X-Patchwork-Id: 49751 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f69.google.com (mail-la0-f69.google.com [209.85.215.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B937A20C81 for ; Thu, 11 Jun 2015 11:02:56 +0000 (UTC) Received: by laboh3 with SMTP id oh3sf1204874lab.0 for ; Thu, 11 Jun 2015 04:02:55 -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:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=aXEjUSewKLA1z3IZxBJOYpSLDiDBibcsihxo0ioouPA=; b=mYsW0rhq+TLIKJyFg9fiUdatRVt5jw/ZIQYLl2+CfOC+I63rgr1P8R6DclKKwtcjUP 8RqMUeUFjcXbYC2rcO1QR12nqsF2qsLBODSSwW5OR3qoZUADuVscAUlj8eCDoyVNcd6X /t/oYcACgmN5pzkeRWglKiRwZTh8bsF/OPoPeQxMWoZcc5fBbr4mMGzcJHca1gKMLB+5 +8VcCCNQZkP5nxS91+uDTySPXMaBHdyWsJDnwI7J3QDEVJZDfA/IM1wx1szTC0Sfq4n4 OJJuSeXej6m0jfz96bxT9EEOvGzlmxZ+5Kh+GSTtvT/gcSc+cFWTOF9OPs2hwbyLzHAZ tZrg== X-Gm-Message-State: ALoCoQm9P4aluJJDNnIxGLLDOEWhC90F4CFodSjMP6NJCa/qD0s4kRGlOds9NWlPXMz8Wcg4+bAe X-Received: by 10.112.142.67 with SMTP id ru3mr7917833lbb.1.1434020575723; Thu, 11 Jun 2015 04:02:55 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.168 with SMTP id w8ls390247lae.41.gmail; Thu, 11 Jun 2015 04:02:55 -0700 (PDT) X-Received: by 10.112.168.102 with SMTP id zv6mr9223346lbb.45.1434020575541; Thu, 11 Jun 2015 04:02:55 -0700 (PDT) Received: from mail-lb0-f173.google.com (mail-lb0-f173.google.com. [209.85.217.173]) by mx.google.com with ESMTPS id pc6si250832lbc.178.2015.06.11.04.02.55 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Jun 2015 04:02:55 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.173 as permitted sender) client-ip=209.85.217.173; Received: by lbbqq2 with SMTP id qq2so2296821lbb.3 for ; Thu, 11 Jun 2015 04:02:55 -0700 (PDT) X-Received: by 10.152.36.161 with SMTP id r1mr9222391laj.88.1434020575403; Thu, 11 Jun 2015 04:02:55 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.108.230 with SMTP id hn6csp3958143lbb; Thu, 11 Jun 2015 04:02:54 -0700 (PDT) X-Received: by 10.70.128.68 with SMTP id nm4mr14103948pdb.74.1434020565187; Thu, 11 Jun 2015 04:02:45 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y7si411399par.175.2015.06.11.04.02.44; Thu, 11 Jun 2015 04:02:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752207AbbFKLCk (ORCPT + 28 others); Thu, 11 Jun 2015 07:02:40 -0400 Received: from mga11.intel.com ([192.55.52.93]:24448 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752833AbbFKLBl (ORCPT ); Thu, 11 Jun 2015 07:01:41 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 11 Jun 2015 04:01:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,594,1427785200"; d="scan'208";a="741394191" Received: from feng-bdw-de.bj.intel.com ([10.238.154.75]) by fmsmga002.fm.intel.com with ESMTP; 11 Jun 2015 04:01:39 -0700 From: Feng Wu To: kvm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: pbonzini@redhat.com, mtosatti@redhat.com, alex.williamson@redhat.com, eric.auger@linaro.org, feng.wu@intel.com Subject: [v4 08/16] KVM: kvm-vfio: User API for IRQ forwarding Date: Thu, 11 Jun 2015 18:51:44 +0800 Message-Id: <1434019912-15423-9-git-send-email-feng.wu@intel.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1434019912-15423-1-git-send-email-feng.wu@intel.com> References: <1434019912-15423-1-git-send-email-feng.wu@intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: feng.wu@intel.com 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.173 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Eric Auger 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 --- 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 4b60056..798f3e4 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -999,6 +999,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, @@ -1018,6 +1021,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 */