From patchwork Tue Mar 29 12:33:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoffer Dall X-Patchwork-Id: 64595 Delivered-To: patch@linaro.org Received: by 10.112.199.169 with SMTP id jl9csp1982948lbc; Tue, 29 Mar 2016 05:34:48 -0700 (PDT) X-Received: by 10.67.14.6 with SMTP id fc6mr2936579pad.55.1459254888469; Tue, 29 Mar 2016 05:34:48 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id z13si23173481pfa.89.2016.03.29.05.34.48 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 29 Mar 2016 05:34:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org 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 1akspz-0006E6-G5; Tue, 29 Mar 2016 12:33:35 +0000 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1akspw-00067p-KD for linux-arm-kernel@lists.infradead.org; Tue, 29 Mar 2016 12:33:33 +0000 Received: by mail-wm0-x22e.google.com with SMTP id p65so136907748wmp.1 for ; Tue, 29 Mar 2016 05:33:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=9aNeE9tnwfR7+Mb+glChira5W9ZJ+FpV8k27WLQU2B0=; b=V5DhOysJtOGxb1OHjHcT1kvz8nO/LjZY2sNmF1uMXw3CmdzoODv+S5zULiELJlfnty 982QkWib8jboaieGrVBuTj/MHQsPtunLYth9maJGGs5uGgLuha7q+cNkb7HkzdbyJLkb hDSIAlVx7amZyVgia6NIwIR9HejXekfTZl15I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=9aNeE9tnwfR7+Mb+glChira5W9ZJ+FpV8k27WLQU2B0=; b=C0EiSdfML9KvqWtt5wWCZQ3ETW+3kPEY+IMjs2A2+ACRfPqYMg4schEu9nEvX2q9Ad uG1/K7HPU5Kl69o/O00Nq9DMoVaFkUf2QRV0tFOBFZBUcSy/Q+z2j3eE+B5/O7LrjAUt tr/le4rW0IUWFZ5H/XWVGdqx/BwQay0I74+LyiefYstxx6vv32oviEpmrZ34gpEN9woa lHNN/C2hcEcdKaei5pfEpOCqLyPMLtddl9Gh4F/I+un02/kRr3MVg/c3sVU7rTPdq4jd 3scpuEE40tdMmqm9c/JcyZaytK+hPu65Z2rg++0Ojwe8pvYUt8KD51rTF0ga9jf4kqyK V7pA== X-Gm-Message-State: AD7BkJKzVouvz9gUV3QSUdcb2xuGvsl6TnonB/IC/Mve1p4jElGap+45XIL2a4sZDHXvjnhf X-Received: by 10.194.103.72 with SMTP id fu8mr2644653wjb.70.1459254790578; Tue, 29 Mar 2016 05:33:10 -0700 (PDT) Received: from localhost ([94.18.191.146]) by smtp.gmail.com with ESMTPSA id gg7sm29146629wjd.10.2016.03.29.05.33.09 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Tue, 29 Mar 2016 05:33:09 -0700 (PDT) Date: Tue, 29 Mar 2016 14:33:08 +0200 From: Christoffer Dall To: Andre Przywara Subject: Re: [RFC PATCH 01/45] KVM: arm/arm64: add missing MMIO data write-back Message-ID: <20160329123308.GC4126@cbox> References: <1458871508-17279-1-git-send-email-andre.przywara@arm.com> <1458871508-17279-2-git-send-email-andre.przywara@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1458871508-17279-2-git-send-email-andre.przywara@arm.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160329_053332_842209_F0A89C58 X-CRM114-Status: GOOD ( 19.94 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:22e listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Marc Zyngier , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, Eric Auger Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org On Fri, Mar 25, 2016 at 02:04:24AM +0000, Andre Przywara wrote: > When the kernel was handling a guest MMIO access internally, we need > to copy the emulation result into the run->mmio structure in order > for the kvm_handle_mmio_return() function to pick it up and inject > the result back into the guest. > Currently the only user of kvm_io_bus for ARM is the VGIC, which did > this copying itself, so this was not causing issues so far. > But with upcoming kvm_io_bus users we need to do the copying here. > > Signed-off-by: Andre Przywara > --- > arch/arm/kvm/mmio.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm/kvm/mmio.c b/arch/arm/kvm/mmio.c > index 0f6600f..d5c2727 100644 > --- a/arch/arm/kvm/mmio.c > +++ b/arch/arm/kvm/mmio.c > @@ -206,7 +206,7 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run, > run->mmio.is_write = is_write; > run->mmio.phys_addr = fault_ipa; > run->mmio.len = len; > - if (is_write) > + if (is_write || !ret) > memcpy(run->mmio.data, data_buf, len); I had a really hard time understanding this, how about this instead: _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm/kvm/mmio.c b/arch/arm/kvm/mmio.c index 0f6600f..0158e9e 100644 --- a/arch/arm/kvm/mmio.c +++ b/arch/arm/kvm/mmio.c @@ -87,11 +87,10 @@ static unsigned long mmio_read_buf(char *buf, unsigned int len) /** * kvm_handle_mmio_return -- Handle MMIO loads after user space emulation + * or in-kernel IO emulation + * * @vcpu: The VCPU pointer * @run: The VCPU run struct containing the mmio data - * - * This should only be called after returning from userspace for MMIO load - * emulation. */ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run) { @@ -206,18 +205,19 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run, run->mmio.is_write = is_write; run->mmio.phys_addr = fault_ipa; run->mmio.len = len; - if (is_write) - memcpy(run->mmio.data, data_buf, len); if (!ret) { /* We handled the access successfully in the kernel. */ + if (!is_write) + memcpy(run->mmio.data, data_buf, len); vcpu->stat.mmio_exit_kernel++; kvm_handle_mmio_return(vcpu, run); return 1; - } else { - vcpu->stat.mmio_exit_user++; } + if (is_write) + memcpy(run->mmio.data, data_buf, len); + vcpu->stat.mmio_exit_user++; run->exit_reason = KVM_EXIT_MMIO; return 0; } diff --git a/virt/kvm/arm/vgic.c b/virt/kvm/arm/vgic.c index 00429b3..63e99cb 100644 --- a/virt/kvm/arm/vgic.c +++ b/virt/kvm/arm/vgic.c @@ -850,12 +850,6 @@ static int vgic_handle_mmio_access(struct kvm_vcpu *vcpu, updated_state = false; } spin_unlock(&dist->lock); - run->mmio.is_write = is_write; - run->mmio.len = len; - run->mmio.phys_addr = addr; - memcpy(run->mmio.data, val, len); - - kvm_handle_mmio_return(vcpu, run); if (updated_state) vgic_kick_vcpus(vcpu->kvm);