From patchwork Wed Apr 5 09:28:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 9663693 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9E19F602B8 for ; Wed, 5 Apr 2017 10:18:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7DEFA285A4 for ; Wed, 5 Apr 2017 10:18:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 72D0D285AF; Wed, 5 Apr 2017 10:18:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E250A285A4 for ; Wed, 5 Apr 2017 10:18:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=XiSI8rIuNJqWLWnVcs+P+eHUVaHWKQTzqg1kCuc9l5U=; b=aH2r/yfi8XvQWZ5sx3TgbShJKK PkVpu1X/xcXe7pcDYyLtw/YNYKTV1ePppQLpVncC4ytaY+m+C1qZb6XYEfxEtWXkNvIAhzaPItAY/ E+o0cuc3yg5apl0Q7LbxQZcKKMONmD6GqvlbcRa+hlOoHOZUheaqQTGFSpts4fCixw+2oyMqHGGI6 CB0CTAudj15Xr4COPzHs2ttZlfdOwqRJQspoHQxG36G4YY6UKF8TW+QalxtLP2pbwF8Aa5KWnTaya /YRhG1oyxXOje3OO9CQeqZbyJyYGjjRm0G6XXRDL7CQxpbi9gLC/2fc9L5eXE6CfqqNpkOREW+R26 tA3B4QNg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cvi1B-00060Q-2x; Wed, 05 Apr 2017 10:18:25 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cvhgo-0008Bz-B7 for linux-arm-kernel@bombadil.infradead.org; Wed, 05 Apr 2017 09:57:22 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=bHf3R3ymLM+AWVoccxQnv5sAFbPShcO3w0XhTWTqUJ0=; b=uopsS/NA2J/4NDY4CpFXE62QY BfMkdpwY6nLgCLEozi7eXe03NBB4cGpqMxDIuJUQWp1cmU27jlaPxqVVRRPGTw65avbsmpNUS7crj uQY2rY02LA9G/EEKxYde+osYv3Tq5+FmXjGKZZSiOa/tc2PCPWfDGoK7Q5DBAvGEJy6LS17flsG01 2TRlk10bAP8mmSPJjv2L3PvHLRB3dNsr6Ln6hmgO4+11pXfIf9YLsiiOcYpRwvahKEIh0xh5PRgYh dxJPT1+zSAwZOQSoFPRuDMMTXxtTji6p/O3WGkLPrsM8yc9b3aHSbVdq8cNWf2wTT7aveRTv+nESM K/u84hfww==; Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cvhF1-0006vi-4V for linux-arm-kernel@lists.infradead.org; Wed, 05 Apr 2017 09:28:41 +0000 Received: by mail-wm0-x235.google.com with SMTP id t189so8439460wmt.1 for ; Wed, 05 Apr 2017 02:28:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bHf3R3ymLM+AWVoccxQnv5sAFbPShcO3w0XhTWTqUJ0=; b=e8fAc8yQm9X+yj2OVAsy6BvQmEKWtVsjH2Nq5jFIQ8h5r+AD0z18cmiVXiAcHLol+V EE7eTMogHY/JRCKJkIELt3QlKtuld9PlPW/PhtjJEDllXVzpZzHuRPtxwOSHQIZxFMJ9 EqYlkjs5tO/JlUGni5YROPD3PeFspIASTv2PM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bHf3R3ymLM+AWVoccxQnv5sAFbPShcO3w0XhTWTqUJ0=; b=nK93CqgrQZVi7vsIWJ6rzn3RJq3Df1laAzd/o3BgU7q+Vp5s+RGU+ZkDoF8wGt1fnf ZJup1ZVSKk1/EvebRaghN2TpAqPv9s8Tq42f1I6m6A5TXzEPC0T6SWB5+mVXo1bS/P1V 4Y9C/ABPJazGnn4Fs2UqferSeBEYo25UzQXGoLP+a9zcAu0xFCLemjVcXcVvqGssUydb f7p53qJRxltkSHh9A9m8JqBUXbf4v7YasdU9EFWj1lcff6HoPEB1QWDAo6wZSfL36TS/ Sb5Tv3QDeMReNsxy5QDZgsq3MY9HCXHQcbUgY4165LfVW3DGtj6cmIbAVKGxvUEuo6HH qitg== X-Gm-Message-State: AFeK/H2b6Docc6y0lDaQ2pcIRbQt6FUgLSyJLHt9PGNSzo0YabXs+0aDarF7iPa9N/t0aabI X-Received: by 10.28.146.12 with SMTP id u12mr19143719wmd.142.1491384497393; Wed, 05 Apr 2017 02:28:17 -0700 (PDT) Received: from localhost.localdomain (xd93ddc2d.cust.hiper.dk. [217.61.220.45]) by smtp.gmail.com with ESMTPSA id g23sm21578135wme.8.2017.04.05.02.28.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 05 Apr 2017 02:28:16 -0700 (PDT) From: Christoffer Dall To: kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Subject: [PATCH v3 2/5] KVM: arm/arm64: Add ARM user space interrupt signaling ABI Date: Wed, 5 Apr 2017 11:28:12 +0200 Message-Id: <20170405092815.22503-3-cdall@linaro.org> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20170405092815.22503-1-cdall@linaro.org> References: <20170405092815.22503-1-cdall@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170405_102839_213171_82AF292F X-CRM114-Status: GOOD ( 20.03 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , kvm@vger.kernel.org, Marc Zyngier , Alexander Graf , Pekka Enberg , Christoffer Dall MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Alexander Graf We have 2 modes for dealing with interrupts in the ARM world. We can either handle them all using hardware acceleration through the vgic or we can emulate a gic in user space and only drive CPU IRQ pins from there. Unfortunately, when driving IRQs from user space, we never tell user space about events from devices emulated inside the kernel, which may result in interrupt line state changes, so we lose out on for example timer and PMU events if we run with user space gic emulation. Define an ABI to publish such device output levels to userspace. Signed-off-by: Alexander Graf Signed-off-by: Christoffer Dall Signed-off-by: Marc Zyngier --- Documentation/virtual/kvm/api.txt | 42 +++++++++++++++++++++++++++++++++++++++ arch/arm/include/uapi/asm/kvm.h | 2 ++ arch/arm64/include/uapi/asm/kvm.h | 2 ++ include/uapi/linux/kvm.h | 8 ++++++++ 4 files changed, 54 insertions(+) diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt index 3c248f7..3b4e76e 100644 --- a/Documentation/virtual/kvm/api.txt +++ b/Documentation/virtual/kvm/api.txt @@ -4147,3 +4147,45 @@ This capability, if KVM_CHECK_EXTENSION indicates that it is available, means that that the kernel can support guests using the hashed page table MMU defined in Power ISA V3.00 (as implemented in the POWER9 processor), including in-memory segment tables. + + +8.5 KVM_CAP_ARM_USER_IRQ + +Architectures: arm, arm64 +This capability, if KVM_CHECK_EXTENSION indicates that it is available, means +that if userspace creates a VM without an in-kernel interrupt controller, it +will be notified of changes to the output level of in-kernel emulated devices, +which can generate virtual interrupts, presented to the VM. +For such VMs, on every return to userspace, the kernel +updates the vcpu's run->s.regs.device_irq_level field to represent the actual +output level of the device. + +Whenever kvm detects a change in the device output level, kvm guarantees at +least one return to userspace before running the VM. This exit could either +be a KVM_EXIT_INTR or any other exit event, like KVM_EXIT_MMIO. This way, +userspace can always sample the device output level and re-compute the state of +the userspace interrupt controller. Userspace should always check the state +of run->s.regs.device_irq_level on every kvm exit. +The value in run->s.regs.device_irq_level can represent both level and edge +triggered interrupt signals, depending on the device. Edge triggered interrupt +signals will exit to userspace with the bit in run->s.regs.device_irq_level +set exactly once per edge signal. + +The field run->s.regs.device_irq_level is available independent of +run->kvm_valid_regs or run->kvm_dirty_regs bits. + +If KVM_CAP_ARM_USER_IRQ is supported, the KVM_CHECK_EXTENSION ioctl returns a +number larger than 0 indicating the version of this capability is implemented +and thereby which bits in in run->s.regs.device_irq_level can signal values. + +Currently the following bits are defined for the device_irq_level bitmap: + + KVM_CAP_ARM_USER_IRQ >= 1: + + KVM_ARM_DEV_EL1_VTIMER - EL1 virtual timer + KVM_ARM_DEV_EL1_PTIMER - EL1 physical timer + KVM_ARM_DEV_PMU - ARM PMU overflow interrupt signal + +Future versions of kvm may implement additional events. These will get +indicated by returning a higher number from KVM_CHECK_EXTENSION and will be +listed above. diff --git a/arch/arm/include/uapi/asm/kvm.h b/arch/arm/include/uapi/asm/kvm.h index 6ebd3e6..a5838d6 100644 --- a/arch/arm/include/uapi/asm/kvm.h +++ b/arch/arm/include/uapi/asm/kvm.h @@ -114,6 +114,8 @@ struct kvm_debug_exit_arch { }; struct kvm_sync_regs { + /* Used with KVM_CAP_ARM_USER_IRQ */ + __u64 device_irq_level; }; struct kvm_arch_memory_slot { diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h index c286035..cd6bea4 100644 --- a/arch/arm64/include/uapi/asm/kvm.h +++ b/arch/arm64/include/uapi/asm/kvm.h @@ -143,6 +143,8 @@ struct kvm_debug_exit_arch { #define KVM_GUESTDBG_USE_HW (1 << 17) struct kvm_sync_regs { + /* Used with KVM_CAP_ARM_USER_IRQ */ + __u64 device_irq_level; }; struct kvm_arch_memory_slot { diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index f51d508..6d6b9b2 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -883,6 +883,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_PPC_MMU_RADIX 134 #define KVM_CAP_PPC_MMU_HASH_V3 135 #define KVM_CAP_IMMEDIATE_EXIT 136 +#define KVM_CAP_ARM_USER_IRQ 137 #ifdef KVM_CAP_IRQ_ROUTING @@ -1354,4 +1355,11 @@ struct kvm_assigned_msix_entry { #define KVM_X2APIC_API_USE_32BIT_IDS (1ULL << 0) #define KVM_X2APIC_API_DISABLE_BROADCAST_QUIRK (1ULL << 1) +/* Available with KVM_CAP_ARM_USER_IRQ */ + +/* Bits for run->s.regs.device_irq_level */ +#define KVM_ARM_DEV_EL1_VTIMER (1 << 0) +#define KVM_ARM_DEV_EL1_PTIMER (1 << 1) +#define KVM_ARM_DEV_PMU (1 << 2) + #endif /* __LINUX_KVM_H */