From patchwork Mon Nov 24 21:26:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Nikolaev X-Patchwork-Id: 5370131 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 B3AEE9F39D for ; Mon, 24 Nov 2014 21:30:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CA51420120 for ; Mon, 24 Nov 2014 21:30:37 +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 D52AB2011B for ; Mon, 24 Nov 2014 21:30:36 +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 1Xt1BA-0001Zo-2Y; Mon, 24 Nov 2014 21:28:16 +0000 Received: from mail-wi0-f174.google.com ([209.85.212.174]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Xt1AK-0000gw-Gb for linux-arm-kernel@lists.infradead.org; Mon, 24 Nov 2014 21:27:25 +0000 Received: by mail-wi0-f174.google.com with SMTP id h11so7145787wiw.7 for ; Mon, 24 Nov 2014 13:27:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:from:to:cc:date:message-id:in-reply-to :references:user-agent:mime-version:content-type :content-transfer-encoding; bh=jMZCLhhmuICXYoRho0MKyHLUeeC4MCsYluGCVUyJeEk=; b=PCBdjVcCuVnkEVz7A674nWeCPUdXG1FoMYyUI3Mi750k4cXPOLKFJRN/vichqhLb2g nq03SdFyTpukSDbIUyYivZYKI3B2JLF1Ebj8AhqEb4kNbaG/Nl9bsQMiuOkTZxRUhucn x6cc92ZcdV1fXE3Cp8IZiUEmtFoOwPPutr3HU79OrSP4Mmtd7+ZshRm8FJLBXYUFaNXU vzaVhMBPKkLXHlSrFIpD/X0cPJfofRu0EuIUtaHIkoNco3mGWEkmc0IWjcbQRSaM5LyI v74ZbTr8/BxRDUd6/yuTSrst6a0I9ntsLY7BmIkOsZR3LJ59YZNvwhXB3Zm12tZFQiJQ 8O/w== X-Gm-Message-State: ALoCoQmeJ7L/nnDVRMyW1cESB/O3DnRQJLrIK13gRpEJUKjaWsUH6AAAtZn7ZpWPTVfiydXqON0a X-Received: by 10.194.77.38 with SMTP id p6mr34307560wjw.50.1416864421836; Mon, 24 Nov 2014 13:27:01 -0800 (PST) Received: from [127.0.1.1] ([82.146.27.14]) by mx.google.com with ESMTPSA id h14sm41991wic.8.2014.11.24.13.27.00 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Nov 2014 13:27:01 -0800 (PST) Subject: [RFC PATCH 3/5] KVM: ARM VGIC add kvm_io_bus_ frontend From: Nikolay Nikolaev To: kvm@vger.kernel.org, eric.auger@linaro.org, marc.zyngier@arm.com, andre.przywara@arm.com, kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org Date: Mon, 24 Nov 2014 23:26:58 +0200 Message-ID: <20141124212658.10605.16215.stgit@i3820> In-Reply-To: <20141124212240.10605.46770.stgit@i3820> References: <20141124212240.10605.46770.stgit@i3820> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141124_132724_894388_1D367D8A X-CRM114-Status: GOOD ( 16.14 ) X-Spam-Score: -0.7 (/) Cc: tech@virtualopensystems.com, linux-arm-kernel@lists.infradead.org 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: , 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 In io_mem_abort remove the call to vgic_handle_mmio. The target is to have a single MMIO handling path - that is through the kvm_io_bus_ API. Register a kvm_io_device in kvm_vgic_init on the whole vGIC MMIO region. Both read and write calls are redirected to vgic_io_dev_access where kvm_exit_mmio is composed to pass it to vm_ops.handle_mmio. Signed-off-by: Nikolay Nikolaev --- arch/arm/kvm/mmio.c | 3 -- include/kvm/arm_vgic.h | 3 +- virt/kvm/arm/vgic.c | 88 ++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 74 insertions(+), 20 deletions(-) diff --git a/arch/arm/kvm/mmio.c b/arch/arm/kvm/mmio.c index 81230da..1c44a2b 100644 --- a/arch/arm/kvm/mmio.c +++ b/arch/arm/kvm/mmio.c @@ -227,9 +227,6 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run, if (mmio.is_write) mmio_write_buf(mmio.data, mmio.len, data); - if (vgic_handle_mmio(vcpu, run, &mmio)) - return 1; - if (handle_kernel_mmio(vcpu, run, &mmio)) return 1; diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h index e452ef7..d9b7d2a 100644 --- a/include/kvm/arm_vgic.h +++ b/include/kvm/arm_vgic.h @@ -233,6 +233,7 @@ struct vgic_dist { unsigned long *irq_pending_on_cpu; struct vgic_vm_ops vm_ops; + struct kvm_io_device *io_dev; #endif }; @@ -307,8 +308,6 @@ int kvm_vgic_inject_irq(struct kvm *kvm, int cpuid, unsigned int irq_num, bool level); void vgic_v3_dispatch_sgi(struct kvm_vcpu *vcpu, u64 reg); int kvm_vgic_vcpu_pending_irq(struct kvm_vcpu *vcpu); -bool vgic_handle_mmio(struct kvm_vcpu *vcpu, struct kvm_run *run, - struct kvm_exit_mmio *mmio); #define irqchip_in_kernel(k) (!!((k)->arch.vgic.in_kernel)) #define vgic_initialized(k) ((k)->arch.vgic.ready) diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c index 1213da5..3da1115 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -31,6 +31,9 @@ #include #include #include +#include + +#include "iodev.h" /* * How the whole thing works (courtesy of Christoffer Dall): @@ -775,28 +778,81 @@ bool vgic_handle_mmio_range(struct kvm_vcpu *vcpu, struct kvm_run *run, return true; } -/** - * vgic_handle_mmio - handle an in-kernel MMIO access for the GIC emulation - * @vcpu: pointer to the vcpu performing the access - * @run: pointer to the kvm_run structure - * @mmio: pointer to the data describing the access - * - * returns true if the MMIO access has been performed in kernel space, - * and false if it needs to be emulated in user space. - * Calls the actual handling routine for the selected VGIC model. - */ -bool vgic_handle_mmio(struct kvm_vcpu *vcpu, struct kvm_run *run, - struct kvm_exit_mmio *mmio) +static int vgic_io_dev_access(struct kvm_vcpu *vcpu, struct kvm_io_device *this, + gpa_t addr, int len, void *val, bool is_write) { - if (!irqchip_in_kernel(vcpu->kvm)) - return false; + struct kvm_exit_mmio mmio; + bool ret; + + mmio = (struct kvm_exit_mmio) { + .phys_addr = addr, + .len = len, + .is_write = is_write, + }; + + if (is_write) + memcpy(mmio.data, val, len); /* * This will currently call either vgic_v2_handle_mmio() or * vgic_v3_handle_mmio(), which in turn will call * vgic_handle_mmio_range() defined above. */ - return vcpu->kvm->arch.vgic.vm_ops.handle_mmio(vcpu, run, mmio); + ret = vcpu->kvm->arch.vgic.vm_ops.handle_mmio(vcpu, vcpu->run, &mmio); + + if (!is_write) + memcpy(val, mmio.data, len); + + return ret ? 0 : 1; +} + +static int vgic_io_dev_read(struct kvm_vcpu *vcpu, struct kvm_io_device *this, + gpa_t addr, int len, void *val) +{ + return vgic_io_dev_access(vcpu, this, addr, len, val, false); +} + +static int vgic_io_dev_write(struct kvm_vcpu *vcpu, struct kvm_io_device *this, + gpa_t addr, int len, const void *val) +{ + return vgic_io_dev_access(vcpu, this, addr, len, (void *)val, true); +} + +static const struct kvm_io_device_ops vgic_io_dev_ops = { + .read = vgic_io_dev_read, + .write = vgic_io_dev_write, +}; + +static int vgic_register_kvm_io_dev(struct kvm *kvm) +{ + struct kvm_io_device *dev; + int ret; + + struct vgic_dist *dist = &kvm->arch.vgic; + unsigned long base = dist->vgic_dist_base; + + dev = kzalloc(sizeof(struct kvm_io_device), GFP_KERNEL); + if (!dev) + return -ENOMEM; + + kvm_iodevice_init(dev, &vgic_io_dev_ops); + + mutex_lock(&kvm->slots_lock); + + ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, + base, KVM_VGIC_V2_DIST_SIZE, dev); + if (ret < 0) + goto out_free_dev; + mutex_unlock(&kvm->slots_lock); + + kvm->arch.vgic.io_dev = dev; + + return 0; + +out_free_dev: + mutex_unlock(&kvm->slots_lock); + kfree(dev); + return ret; } static int vgic_nr_shared_irqs(struct vgic_dist *dist) @@ -1545,6 +1601,8 @@ int kvm_vgic_init(struct kvm *kvm) mutex_lock(&kvm->lock); + vgic_register_kvm_io_dev(kvm); + if (vgic_initialized(kvm)) goto out;