From patchwork Wed Nov 19 05:16:21 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ming Lei X-Patchwork-Id: 5334441 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5CDEC9F3ED for ; Wed, 19 Nov 2014 05:18:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 776CC201F2 for ; Wed, 19 Nov 2014 05:18:57 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8C372201E4 for ; Wed, 19 Nov 2014 05:18:56 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XqxdX-0008Nc-8W; Wed, 19 Nov 2014 05:17:03 +0000 Received: from mail-pa0-f48.google.com ([209.85.220.48]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XqxdU-0008J5-RI for linux-arm-kernel@lists.infradead.org; Wed, 19 Nov 2014 05:17:01 +0000 Received: by mail-pa0-f48.google.com with SMTP id rd3so12473647pab.35 for ; Tue, 18 Nov 2014 21:16:40 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=from:to:cc:subject:date:message-id; bh=79s+SeREpUdAeV5pcG5nE9RET9NnDZwnLEqJgaZopG4=; b=OgMTKaHM4ei1OjUdLZTOJjZfJ/NOZ1ZMvA7WxjztcH1J2IR7/Sb9KjvZjTmaRrP4Dx XwCGQuAxv4JKTz0AAnAv80AGkk8FUFK+Hiqiff1s867uJT7crRP1RTADA5p88gCuY/Yy TNKopJMervWsQm7Mfsa6IBDoyfKjYcEBSohVsrb/3eU+JGlJ+DFMsMTZSP8BlZEf0+LM DvEgl19XCSHXyfa7zobu3e/7Q7UNQx4b4dKLEosPLLaEiF36fIa4kbupzPJs1SaHxK+2 NhZ6oQcKk1m2loupeHRLJFogYJHB2wNkh6RvDfdlwrLGQwkAyKsq7PiHJ3JCEYKQof/N WDiQ== X-Received: by 10.70.53.102 with SMTP id a6mr33211073pdp.70.1416374199489; Tue, 18 Nov 2014 21:16:39 -0800 (PST) Received: from localhost ([183.14.17.209]) by mx.google.com with ESMTPSA id pi2sm526133pdb.14.2014.11.18.21.16.38 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 18 Nov 2014 21:16:38 -0800 (PST) From: Ming Lei To: kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH v1] ARM/ARM64: support KVM_IOEVENTFD Date: Wed, 19 Nov 2014 13:16:21 +0800 Message-Id: <1416374181-28415-1-git-send-email-ming.lei@canonical.com> X-Mailer: git-send-email 1.7.9.5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141118_211700_987701_40152DA3 X-CRM114-Status: GOOD ( 13.81 ) X-Spam-Score: -0.7 (/) Cc: Marc Zyngier , Catalin Marinas , Ming Lei , Gleb Natapov , Paolo Bonzini , Christoffer Dall X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, 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 From Documentation/virtual/kvm/api.txt, all ARCHs should support ioeventfd. Also ARM VM has supported PCI bus already, and ARM64 will do too, ioeventfd is required for some popular devices, like virtio-blk and virtio-scsi dataplane in QEMU. Without this patch, virtio-blk-pci dataplane can't work in QEMU. This patch has been tested on both ARM and ARM64. Signed-off-by: Ming Lei --- v1: - make eventfd.o built in ARM64 arch/arm/kvm/Kconfig | 1 + arch/arm/kvm/Makefile | 2 +- arch/arm/kvm/arm.c | 1 + arch/arm/kvm/mmio.c | 19 +++++++++++++++++++ arch/arm64/kvm/Kconfig | 1 + arch/arm64/kvm/Makefile | 2 +- 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/arch/arm/kvm/Kconfig b/arch/arm/kvm/Kconfig index 466bd29..25bd83a 100644 --- a/arch/arm/kvm/Kconfig +++ b/arch/arm/kvm/Kconfig @@ -23,6 +23,7 @@ config KVM select HAVE_KVM_CPU_RELAX_INTERCEPT select KVM_MMIO select KVM_ARM_HOST + select HAVE_KVM_EVENTFD depends on ARM_VIRT_EXT && ARM_LPAE ---help--- Support hosting virtualized guest machines. You will also diff --git a/arch/arm/kvm/Makefile b/arch/arm/kvm/Makefile index f7057ed..859db09 100644 --- a/arch/arm/kvm/Makefile +++ b/arch/arm/kvm/Makefile @@ -15,7 +15,7 @@ AFLAGS_init.o := -Wa,-march=armv7-a$(plus_virt) AFLAGS_interrupts.o := -Wa,-march=armv7-a$(plus_virt) KVM := ../../../virt/kvm -kvm-arm-y = $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o +kvm-arm-y = $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o $(KVM)/eventfd.o obj-y += kvm-arm.o init.o interrupts.o obj-y += arm.o handle_exit.o guest.o mmu.o emulate.o reset.o diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c index 9e193c8..d90d989 100644 --- a/arch/arm/kvm/arm.c +++ b/arch/arm/kvm/arm.c @@ -172,6 +172,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) case KVM_CAP_IRQCHIP: r = vgic_present; break; + case KVM_CAP_IOEVENTFD: case KVM_CAP_DEVICE_CTRL: case KVM_CAP_USER_MEMORY: case KVM_CAP_SYNC_MMU: diff --git a/arch/arm/kvm/mmio.c b/arch/arm/kvm/mmio.c index 4cb5a93..ee332a7 100644 --- a/arch/arm/kvm/mmio.c +++ b/arch/arm/kvm/mmio.c @@ -162,6 +162,21 @@ static int decode_hsr(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, return 0; } +static int handle_io_bus_rw(struct kvm_vcpu *vcpu, gpa_t addr, + int len, void *val, bool write) +{ + int idx, ret; + + idx = srcu_read_lock(&vcpu->kvm->srcu); + if (write) + ret = kvm_io_bus_write(vcpu->kvm, KVM_MMIO_BUS, addr, len, val); + else + ret = kvm_io_bus_read(vcpu->kvm, KVM_MMIO_BUS, addr, len, val); + srcu_read_unlock(&vcpu->kvm->srcu, idx); + + return ret; +} + int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run, phys_addr_t fault_ipa) { @@ -200,6 +215,10 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run, if (vgic_handle_mmio(vcpu, run, &mmio)) return 1; + if (!handle_io_bus_rw(vcpu, fault_ipa, mmio.len, &mmio.data, + mmio.is_write)) + return 1; + kvm_prepare_mmio(run, &mmio); return 0; } diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig index 8ba85e9..642f57c 100644 --- a/arch/arm64/kvm/Kconfig +++ b/arch/arm64/kvm/Kconfig @@ -26,6 +26,7 @@ config KVM select KVM_ARM_HOST select KVM_ARM_VGIC select KVM_ARM_TIMER + select HAVE_KVM_EVENTFD ---help--- Support hosting virtualized guest machines. diff --git a/arch/arm64/kvm/Makefile b/arch/arm64/kvm/Makefile index 32a0961..2e6b827 100644 --- a/arch/arm64/kvm/Makefile +++ b/arch/arm64/kvm/Makefile @@ -11,7 +11,7 @@ ARM=../../../arch/arm/kvm obj-$(CONFIG_KVM_ARM_HOST) += kvm.o -kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o +kvm-$(CONFIG_KVM_ARM_HOST) += $(KVM)/kvm_main.o $(KVM)/coalesced_mmio.o $(KVM)/eventfd.o kvm-$(CONFIG_KVM_ARM_HOST) += $(ARM)/arm.o $(ARM)/mmu.o $(ARM)/mmio.o kvm-$(CONFIG_KVM_ARM_HOST) += $(ARM)/psci.o $(ARM)/perf.o