Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2686456ybl; Thu, 29 Aug 2019 11:28:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqyPMGnnKqcclkMaJHk6UHXrO6nW5ehxkIS/nwqyoEw/CP0z0fLc6IjP8jZqSTphunBpfpiI X-Received: by 2002:a17:902:85:: with SMTP id a5mr11932739pla.213.1567103293585; Thu, 29 Aug 2019 11:28:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567103293; cv=none; d=google.com; s=arc-20160816; b=GOSF+NdAT0CP482gmrlb2Ju9HLUo/b7LwVShJIHFsTGl82vo+Z9meJofWjvRX+vRJA wJ9cfswJFbn6PpRG8r5Sz623Xho6Ho7NLpZ0qPGTor12XbnY4zhVS8pCHmLofWgJ/3Te oMgnbzlxbSqJSwgpZABEyug4r6eTtxHnj9dSVBd8jchkjM+0VkaBeMlqxOBoVf/4YC5Z Yo3uLamgV9IFYywPHlCtxCaYQ1Sj/xCZIN+uOgZt36XnunIbI8CjS0yPTMbbQi6meVRD JBcCWT+qcGQ2KSygYyeNgui9wfdI/KFXsZec0Jmgju0us/kEF66ISg85tkhyPydNXXp6 yNwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Ai6aRzqsJgB4/RSA9z71ho08y9e07gfamHQYkAX+HKU=; b=wKmXsDpV2XLB+lhF4FGRhOPiNGDDdF85gwD6gVbQaULV6ERxcGj0wzvMaKppsw9Zz5 H4KQLrB0cKyaNAePma4bgByHMxiwpkxhXn89pE/d8tTR0BbL9RNzk+eS3E8kdPet/6Q4 an4V9e8r9lOJfAnqa21BGN2/F8v7f8Pgf5xIyoZ95cQVH8N3VwmK2KohOG39ve4NCi3Y CO26C8RWB5yhoSm7dcpSMOBomb3Bv3fjsyC5az/ZP982mA3AcUWIUGg6NsiTgX0Vl6tG fYaWe8nD3GnApmmII8mS9N+Qrj4CkkFMsud9DJtkOCWlQP7XOJGax1Uz2Huy1lYk04Bq DNwQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BwWZM8mO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7si2609715pga.439.2019.08.29.11.27.58; Thu, 29 Aug 2019 11:28:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=BwWZM8mO; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729357AbfH2SPg (ORCPT + 99 others); Thu, 29 Aug 2019 14:15:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:57324 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729334AbfH2SPf (ORCPT ); Thu, 29 Aug 2019 14:15:35 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CD40023430; Thu, 29 Aug 2019 18:15:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567102534; bh=+BOd4fQzl5C2PN6oG2cxUQ/t/eadMzkdBLyAa6ZKW5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BwWZM8mOW+4dJmHdEmFNKm1hldog4lVUb8nxLTW4NAKYPh0W/5OmLY0r7giIfSmD3 z5Y6fhGFFwAElIJ094a7GvWuBj+liIRUi+va+tJipuggJaCAwkjFsBCw4lyUQgUT/g O1btQUMDeybEMwKXEaZCLo/csyRPO0ua2PTCxtOQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Andrew Jones , Mark Rutland , Marc Zyngier , Sasha Levin , kvmarm@lists.cs.columbia.edu Subject: [PATCH AUTOSEL 5.2 69/76] KVM: arm/arm64: Only skip MMIO insn once Date: Thu, 29 Aug 2019 14:13:04 -0400 Message-Id: <20190829181311.7562-69-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190829181311.7562-1-sashal@kernel.org> References: <20190829181311.7562-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Andrew Jones [ Upstream commit 2113c5f62b7423e4a72b890bd479704aa85c81ba ] If after an MMIO exit to userspace a VCPU is immediately run with an immediate_exit request, such as when a signal is delivered or an MMIO emulation completion is needed, then the VCPU completes the MMIO emulation and immediately returns to userspace. As the exit_reason does not get changed from KVM_EXIT_MMIO in these cases we have to be careful not to complete the MMIO emulation again, when the VCPU is eventually run again, because the emulation does an instruction skip (and doing too many skips would be a waste of guest code :-) We need to use additional VCPU state to track if the emulation is complete. As luck would have it, we already have 'mmio_needed', which even appears to be used in this way by other architectures already. Fixes: 0d640732dbeb ("arm64: KVM: Skip MMIO insn after emulation") Acked-by: Mark Rutland Signed-off-by: Andrew Jones Signed-off-by: Marc Zyngier Signed-off-by: Sasha Levin --- virt/kvm/arm/mmio.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/virt/kvm/arm/mmio.c b/virt/kvm/arm/mmio.c index a8a6a0c883f1b..6af5c91337f25 100644 --- a/virt/kvm/arm/mmio.c +++ b/virt/kvm/arm/mmio.c @@ -86,6 +86,12 @@ int kvm_handle_mmio_return(struct kvm_vcpu *vcpu, struct kvm_run *run) unsigned int len; int mask; + /* Detect an already handled MMIO return */ + if (unlikely(!vcpu->mmio_needed)) + return 0; + + vcpu->mmio_needed = 0; + if (!run->mmio.is_write) { len = run->mmio.len; if (len > sizeof(unsigned long)) @@ -188,6 +194,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; + vcpu->mmio_needed = 1; if (!ret) { /* We handled the access successfully in the kernel. */ -- 2.20.1