Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2115660ybl; Thu, 29 Aug 2019 03:52:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqzbWELJ3tMsvH2JPclKI/epFXJDjK2ZS1I2Pho9PxmrianRu9fEukH4gaPFM3fh0i15gla4 X-Received: by 2002:a17:902:ff0c:: with SMTP id f12mr2442894plj.67.1567075974909; Thu, 29 Aug 2019 03:52:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567075974; cv=none; d=google.com; s=arc-20160816; b=b3zQBUdaw66poQAYUFcbMkRNawVwLeWxbrhJVA5DO1E+ImwMZBK+r6WUHkX8+53g0k EI+3Cxsz0H12fFmbdW+xDTekGOY1yM7SJQwfoSIyBdJvBIYB9W5PdPjedRV4eKofo8xX 7iwpeAnoSPX/tiT2sFpi5aFkomaNrkXhwXfK5DGzUV+aoUAxbxPhaEimU0M7lWUW4Zb3 Y1+MwV0s8qQyTU7EkygZ6B0AoVOnKbLvNWgnA7R1lw2A2kfQn/2SJLPzJnDLmazBThWP DpZ780ndwqWV6sim7Log+zFZsGkJJCr4zmszcFNw/YGi9AKdWqMFa6osrVHRdjZVDN6U fDkg== 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=aWOJRTHuLKn+U+Twb/K9bcYtujOFhmzJBf3kdv02m4w=; b=yvZnhefD/WRB4vHu2ou3O97+5WTqyVlj4untYa8cf1evJ3BFki5QdWYUaHd/yRDhlp GN3T0nPfTBUuZCvA9cFQHPHj2r0EQP3gbDAJos/XOXqXjWQusKBkbz7bBXmZOtk5+tyP w05govKRJ8R2s6vesXcASnd8WNBfodLa4KFTcCrLV3RQJKdOixOTUkndT0ymEp6ebKrO PkS7N3usOilQJdruI+d9Ll5vDX0/eekycKOYBXzDQaeoNvEArSmusRulH/cxNI3Kba9F zittsDY1iuxkeE5vfF1vBiipbO1psDSG6LevjfQkkTFVpCGvoxkYz62L1TCa15j1ebY6 nDrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=LS0OrBMn; 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 m2si1830731pjk.86.2019.08.29.03.52.39; Thu, 29 Aug 2019 03:52:54 -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=LS0OrBMn; 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 S1728611AbfH2KvW (ORCPT + 99 others); Thu, 29 Aug 2019 06:51:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:58536 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726852AbfH2Ku7 (ORCPT ); Thu, 29 Aug 2019 06:50:59 -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 4530423405; Thu, 29 Aug 2019 10:50:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1567075858; bh=7pQ3zLdVbcKZHrcATLCC4qK5jFKHe/pZSZMuUtpgVME=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LS0OrBMniI5ZW6KaQ7Z50/ruYA3WNhzSgJ4qO64bSSGSPb0H/JoUEwfSMuOZBFxwx FENuDEVJS21N2hV1u8UghgKpGGX1894q6/UOhXyGExcIypoEugjAGQB3KQiHr0p3z1 sCst3y/cyZR7YT+JBMpXUwa1il3NyTckvQeFFYpw= 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, kvm@vger.kernel.org Subject: [PATCH AUTOSEL 4.14 12/14] KVM: arm/arm64: Only skip MMIO insn once Date: Thu, 29 Aug 2019 06:50:41 -0400 Message-Id: <20190829105043.2508-12-sashal@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190829105043.2508-1-sashal@kernel.org> References: <20190829105043.2508-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 08443a15e6be8..3caee91bca089 100644 --- a/virt/kvm/arm/mmio.c +++ b/virt/kvm/arm/mmio.c @@ -98,6 +98,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)) @@ -200,6 +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; + vcpu->mmio_needed = 1; if (!ret) { /* We handled the access successfully in the kernel. */ -- 2.20.1