All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: stable@vger.kernel.org
Cc: "James Hogan" <james.hogan@imgtec.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Ralf Baechle" <ralf@linux-mips.org>,
	linux-mips@linux-mips.org, kvm@vger.kernel.org,
	"Jiri Slaby" <jslaby@suse.cz>
Subject: [patch added to 3.12-stable] MIPS: KVM: Propagate kseg0/mapped tlb fault errors
Date: Thu, 18 Aug 2016 14:49:19 +0200	[thread overview]
Message-ID: <20160818124953.31969-14-jslaby@suse.cz> (raw)
In-Reply-To: <20160818124953.31969-1-jslaby@suse.cz>

From: James Hogan <james.hogan@imgtec.com>

This patch has been added to the 3.12 stable tree. If you have any
objections, please let us know.

===============

commit 9b731bcfdec4c159ad2e4312e25d69221709b96a upstream.

Propagate errors from kvm_mips_handle_kseg0_tlb_fault() and
kvm_mips_handle_mapped_seg_tlb_fault(), usually triggering an internal
error since they normally indicate the guest accessed bad physical
memory or the commpage in an unexpected way.

Fixes: 858dd5d45733 ("KVM/MIPS32: MMU/TLB operations for the Guest.")
Fixes: e685c689f3a8 ("KVM/MIPS32: Privileged instruction/target branch emulation.")
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Radim Krčmář" <rkrcmar@redhat.com>
Cc: Ralf Baechle <ralf@linux-mips.org>
Cc: linux-mips@linux-mips.org
Cc: kvm@vger.kernel.org
Signed-off-by: Radim Krčmář <rkrcmar@redhat.com>
[james.hogan@imgtec.com: Backport to v3.10.y - v3.15.y]
Signed-off-by: James Hogan <james.hogan@imgtec.com>
Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 arch/mips/kvm/kvm_mips_emul.c | 33 ++++++++++++++++++++++++---------
 arch/mips/kvm/kvm_tlb.c       | 14 ++++++++++----
 2 files changed, 34 insertions(+), 13 deletions(-)

diff --git a/arch/mips/kvm/kvm_mips_emul.c b/arch/mips/kvm/kvm_mips_emul.c
index 33085819cd89..9f7643874fba 100644
--- a/arch/mips/kvm/kvm_mips_emul.c
+++ b/arch/mips/kvm/kvm_mips_emul.c
@@ -972,8 +972,13 @@ kvm_mips_emulate_cache(uint32_t inst, uint32_t *opc, uint32_t cause,
 	preempt_disable();
 	if (KVM_GUEST_KSEGX(va) == KVM_GUEST_KSEG0) {
 
-		if (kvm_mips_host_tlb_lookup(vcpu, va) < 0) {
-			kvm_mips_handle_kseg0_tlb_fault(va, vcpu);
+		if (kvm_mips_host_tlb_lookup(vcpu, va) < 0 &&
+		    kvm_mips_handle_kseg0_tlb_fault(va, vcpu)) {
+			kvm_err("%s: handling mapped kseg0 tlb fault for %lx, vcpu: %p, ASID: %#lx\n",
+				__func__, va, vcpu, read_c0_entryhi());
+			er = EMULATE_FAIL;
+			preempt_enable();
+			goto done;
 		}
 	} else if ((KVM_GUEST_KSEGX(va) < KVM_GUEST_KSEG0) ||
 		   KVM_GUEST_KSEGX(va) == KVM_GUEST_KSEG23) {
@@ -1006,11 +1011,16 @@ kvm_mips_emulate_cache(uint32_t inst, uint32_t *opc, uint32_t cause,
 								run, vcpu);
 				preempt_enable();
 				goto dont_update_pc;
-			} else {
-				/* We fault an entry from the guest tlb to the shadow host TLB */
-				kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb,
-								     NULL,
-								     NULL);
+			}
+			/* We fault an entry from the guest tlb to the shadow host TLB */
+			if (kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb,
+								 NULL, NULL)) {
+				kvm_err("%s: handling mapped seg tlb fault for %lx, index: %u, vcpu: %p, ASID: %#lx\n",
+					__func__, va, index, vcpu,
+					read_c0_entryhi());
+				er = EMULATE_FAIL;
+				preempt_enable();
+				goto done;
 			}
 		}
 	} else {
@@ -1821,8 +1831,13 @@ kvm_mips_handle_tlbmiss(unsigned long cause, uint32_t *opc,
 			     tlb->tlb_hi, tlb->tlb_lo0, tlb->tlb_lo1);
 #endif
 			/* OK we have a Guest TLB entry, now inject it into the shadow host TLB */
-			kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb, NULL,
-							     NULL);
+			if (kvm_mips_handle_mapped_seg_tlb_fault(vcpu, tlb,
+								 NULL, NULL)) {
+				kvm_err("%s: handling mapped seg tlb fault for %lx, index: %u, vcpu: %p, ASID: %#lx\n",
+					__func__, va, index, vcpu,
+					read_c0_entryhi());
+				er = EMULATE_FAIL;
+			}
 		}
 	}
 
diff --git a/arch/mips/kvm/kvm_tlb.c b/arch/mips/kvm/kvm_tlb.c
index 5a3c3731214f..4bee4397dca8 100644
--- a/arch/mips/kvm/kvm_tlb.c
+++ b/arch/mips/kvm/kvm_tlb.c
@@ -926,10 +926,16 @@ uint32_t kvm_get_inst(uint32_t *opc, struct kvm_vcpu *vcpu)
 				local_irq_restore(flags);
 				return KVM_INVALID_INST;
 			}
-			kvm_mips_handle_mapped_seg_tlb_fault(vcpu,
-							     &vcpu->arch.
-							     guest_tlb[index],
-							     NULL, NULL);
+			if (kvm_mips_handle_mapped_seg_tlb_fault(vcpu,
+						&vcpu->arch.guest_tlb[index],
+						NULL, NULL)) {
+				kvm_err("%s: handling mapped seg tlb fault failed for %p, index: %u, vcpu: %p, ASID: %#lx\n",
+					__func__, opc, index, vcpu,
+					read_c0_entryhi());
+				kvm_mips_dump_guest_tlbs(vcpu);
+				local_irq_restore(flags);
+				return KVM_INVALID_INST;
+			}
 			inst = *(opc);
 		}
 		local_irq_restore(flags);
-- 
2.9.3


  parent reply	other threads:[~2016-08-18 12:50 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-18 12:49 [patch added to 3.12-stable] x86, asmlinkage, lguest: Pass in globals into assembler statement Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] can: at91_can: RX queue could get stuck at high bus load Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] can: fix handling of unmodifiable configuration options fix Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] can: fix oops caused by wrong rtnl dellink usage Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] ipr: Clear interrupt on croc/crocodile when running with LSI Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] net: mvneta: set real interrupt per packet for tx_done Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] random32: add prandom_u32_max and convert open coded users Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] tcp: make challenge acks less predictable Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] net/irda: fix NULL pointer dereference on memory allocation failure Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] tcp: consider recv buf for the initial window scale Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] MIPS: KVM: Fix mapped fault broken commpage handling Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] MIPS: KVM: Add missing gfn range check Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] MIPS: KVM: Fix gfn range check in kseg0 tlb faults Jiri Slaby
2016-08-18 12:49 ` Jiri Slaby [this message]
2016-08-18 12:49 ` [patch added to 3.12-stable] HID: i2c-hid: set power sleep before shutdown Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] HID: multitouch: Add MT_QUIRK_NOT_SEEN_MEANS_UP to Surface Pro 3 Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] x86/mm: Improve switch_mm() barrier comments Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] arm: oabi compat: add missing access checks Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] KEYS: 64-bit MIPS needs to use compat_sys_keyctl for 32-bit userspace Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] apparmor: fix ref count leak when profile sha1 hash is read Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] block: fix use-after-free in seq file Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] sysv, ipc: fix security-layer leaking Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] fuse: fix wrong assignment of ->flags in fuse_send_init() Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] crypto: gcm - Filter out async ghash if necessary Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] crypto: scatterwalk - Fix test in scatterwalk_done Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] ext4: check for extents that wrap around Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] ext4: fix deadlock during page writeback Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] ext4: don't call ext4_should_journal_data() on the journal inode Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] ext4: short-cut orphan cleanup on error Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] ext4: fix reference counting bug on block allocation error Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] usb: renesas_usbhs: protect the CFIFOSEL setting in usbhsg_ep_enable() Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] USB: serial: option: add support for Telit LE910 PID 0x1206 Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] gpio: pca953x: Fix NBANK calculation for PCA9536 Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] s5p-mfc: Set device name for reserved memory region devs Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] s5p-mfc: Add release callback for " Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] Bluetooth: Fix l2cap_sock_setsockopt() with optname BT_RCVMTU Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] cifs: Check for existing directory when opening file with O_CREAT Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] cifs: fix crash due to race in hmac(md5) handling Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] CIFS: Fix a possible invalid memory access in smb2_query_symlink() Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] random: properly align get_random_int_hash Jiri Slaby
2016-08-19  3:14   ` Eric Biggers
2016-08-19  7:07     ` Jiri Slaby
2016-08-18 12:49 ` [patch added to 3.12-stable] nfs: don't create zero-length requests Jiri Slaby

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160818124953.31969-14-jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=james.hogan@imgtec.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=pbonzini@redhat.com \
    --cc=ralf@linux-mips.org \
    --cc=rkrcmar@redhat.com \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.