From patchwork Mon Aug 25 13:27:39 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Auger X-Patchwork-Id: 4774761 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 45AD2C0338 for ; Mon, 25 Aug 2014 13:31:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 377B92011E for ; Mon, 25 Aug 2014 13:31:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3F5FA200F3 for ; Mon, 25 Aug 2014 13:31:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932673AbaHYNan (ORCPT ); Mon, 25 Aug 2014 09:30:43 -0400 Received: from mail-wi0-f169.google.com ([209.85.212.169]:34304 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932091AbaHYN2q (ORCPT ); Mon, 25 Aug 2014 09:28:46 -0400 Received: by mail-wi0-f169.google.com with SMTP id n3so3690852wiv.4 for ; Mon, 25 Aug 2014 06:28: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=jMEZuFS/oaSUmTMKyMXcZi55Z5UvaHWDmrzYIa4fHH4=; b=QsPj3RSdD5n6K9abXXLl0Jg53G2/S305bhCEM/UKOMAM5e2YQZvBIdDCrZzGeSWmSf eQ+kwLz2lm5K7i/9UkMrmzLNsV9un1nvE/9XDH30pRuczLMLY+YwUQpltIL+91QaJznd qF07g0Zjmo336M9Kz88d6FkHQf4s9r0XqGpyyj9Dob/7U7b+ytf96/EXU5LDcht1/Hiy 0XCJqKMCdh8ShTwvCz/8csYgRj3mWPx+Azza8ehDBVPGGRGlBkJ08FVYwX8h8O2c2SZR AxX/VrBzkxsdE0LR4d+XWPwxYp7ulM1KsiWgWFSF8a0co208myNHlDj9sB0FPoIOPLjY PHCA== X-Gm-Message-State: ALoCoQlQJtLnhfQ9tDhVpFvcM9REldlEdlSLY8J8/zixrsMZV2XC6ZfTrdNSvVqPLUVsbk5Lq7Re X-Received: by 10.194.90.233 with SMTP id bz9mr9076761wjb.94.1408973324323; Mon, 25 Aug 2014 06:28: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 co6sm100101595wjb.31.2014.08.25.06.28.42 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 25 Aug 2014 06:28: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 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 4/9] KVM: KVM-VFIO: update user API to program forwarded IRQ Date: Mon, 25 Aug 2014 15:27:39 +0200 Message-Id: <1408973264-30384-5-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1408973264-30384-1-git-send-email-eric.auger@linaro.org> References: <1408973264-30384-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, 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_ASSIGN_IRQ and KVM_DEV_VFIO_DEVICE_DEASSIGN_IRQ which enable to turn forwarded IRQ mode on/off. Signed-off-by: Eric Auger --- Documentation/virtual/kvm/devices/vfio.txt | 25 +++++++++++++++++++++++++ arch/arm/include/uapi/asm/kvm.h | 6 ++++++ include/uapi/linux/kvm.h | 3 +++ 3 files changed, 34 insertions(+) diff --git a/Documentation/virtual/kvm/devices/vfio.txt b/Documentation/virtual/kvm/devices/vfio.txt index ef51740..c8b3fa1 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,27 @@ 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_ASSIGN_IRQ + KVM_DEV_VFIO_DEVICE_DEASSIGN_IRQ + +For each, kvm_device_attr.addr points to an kvm_arch_forwarded_irq. +This user API makes possible to create a special IRQ handling mode, +currently supported only on ARM, 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 irq_index is injected to the VM guest_irq. + +On ASSIGN_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 avoid trapping the end-of-interrupt for level sensitive IRQ. + +On DEASSIGN_IRQ, one come back to the mode where the host completes the +physical IRQ and the guest only completes the virtual IRQ. + +It is up to the caller of this API to get the assurance the IRQ is not +outstanding when the ASSIGN/DEASSIGN is called. This could lead to some +inconsistency on who is going to complete the IRQ. diff --git a/arch/arm/include/uapi/asm/kvm.h b/arch/arm/include/uapi/asm/kvm.h index 3034c66..1920b33 100644 --- a/arch/arm/include/uapi/asm/kvm.h +++ b/arch/arm/include/uapi/asm/kvm.h @@ -109,6 +109,12 @@ struct kvm_sync_regs { struct kvm_arch_memory_slot { }; +struct kvm_arch_forwarded_irq { + __u32 fd; /* file desciptor of the VFIO device */ + __u32 irq_index; /* platform device index of the IRQ */ + __u32 guest_irq; /* virtual IRQ number */ +}; + /* If you need to interpret the index values, here is the key: */ #define KVM_REG_ARM_COPROC_MASK 0x000000000FFF0000 #define KVM_REG_ARM_COPROC_SHIFT 16 diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index cf3a2ff..b149ba8 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -954,6 +954,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_ASSIGN_IRQ 1 +#define KVM_DEV_VFIO_DEVICE_DEASSIGN_IRQ 2 #define KVM_DEV_TYPE_ARM_VGIC_V2 5 #define KVM_DEV_TYPE_FLIC 6