Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp50577imm; Tue, 18 Sep 2018 16:20:34 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZFyL5J+lvhI9YwictZjIPRcEy7NWnK3mg/bT13hqcylXhchbLi4+bZshOjfdkiVfujc5l7 X-Received: by 2002:a17:902:b40c:: with SMTP id x12-v6mr31418962plr.163.1537312834559; Tue, 18 Sep 2018 16:20:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537312834; cv=none; d=google.com; s=arc-20160816; b=ftdTARD0ztVukVuKwc9rU+VGyD55AjsXp0+44b1A6LpuZL9Xfjnkq5xAY1HTE+xWZX i/aSllzEpcb/CpHE2UhPL9KZe6lK4p1Lx5kKX5zhOZGNbnlyw1cMfg7aqeruWr0e8fZS 5CyRxz+tpdXENkhdZcNT0e+RdUrabD2iRQQKXSaFL33Ej3jA+7nJ6NoddYktP6YXyrzN csWZ9orYHLgtk3Y4+7YxhqvXMUCvlknO2/DOfPGPCQgwc32nPBUYAthoSOaPQCO3l6/k 9chhlcNwVMtITIaixXSHfiscJuO2lM+kaYqIdUp4h4WpOUxLSbtRIFRECnrpT3QMaZPg bJ0w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=VZ2x5NooLirwxKcNirK708C+EIznrkljpzMy5apQgfw=; b=naMiE6AASFLJ3rqSJmi4HajWvG5q062WiUV4VLJYkoRkXFGY+P0ASmUbrK0zLBew9W lylO5jmtdtYWuRZG3BMIDHxmkJWTLL90KK+acEELgQJwugmn6sLnGz7ylnl9ITOQd66G m4pyGLKkyilBo9zMF2aC1C6Iq7jcRoSVRhREs+CkYvxy4AcUmzSlwpXGQbocW619GmsD wRuOXXAhnWCPgBenxTo/Vii62S6HjuRrFJK3rVjommJTssNYQCMP6de5P7i2/yzrLF2Q hE0WbD1vwBYxdI22/m3kKNOIkfQ02Flm+pDF3OxWNO8ULYLB6kJTVCPejXiDtZNwbZwB /ppg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a24-v6si19848111pgh.357.2018.09.18.16.19.50; Tue, 18 Sep 2018 16:20:34 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728163AbeISEyG (ORCPT + 99 others); Wed, 19 Sep 2018 00:54:06 -0400 Received: from mail115-100.sinamail.sina.com.cn ([218.30.115.100]:48655 "HELO mail115-100.sinamail.sina.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1725779AbeISEyG (ORCPT ); Wed, 19 Sep 2018 00:54:06 -0400 X-Greylist: delayed 325 seconds by postgrey-1.27 at vger.kernel.org; Wed, 19 Sep 2018 00:54:05 EDT Received: from unknown (HELO localhost.localdomain.localdomain)([110.184.36.9]) by sina.com with ESMTP id 5BA1846200000F8B; Tue, 19 Sep 2018 07:04:11 +0800 (CST) X-Sender: penghao122@sina.com.cn X-Auth-ID: penghao122@sina.com.cn X-SMAIL-MID: 460227132372 From: Peng Hao To: pbonzini@redhat.com, rkrcmar@redhat.com, tglx@linutronix.de, mingo@redhat.com, hpa@zytor.com Cc: linux-kernel@vger.kernel.org, kvm@vger.kernel.org, x86@kernel.org, peng.hao2@zte.com, Peng Hao Subject: [PATCH RESEND] kvm/x86: propagate fetch fault into guest Date: Tue, 18 Sep 2018 19:03:48 -0400 Message-Id: <1537311828-4547-1-git-send-email-penghao122@sina.com.cn> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peng Hao When handling ept misconfig exit, it will call emulate instruction with insn_len = 0. The decode instruction function may return a fetch fault and should propagate to guest. The problem will result to emulation fail. KVM internal error. Suberror: 1 emulation failure EAX=f81a0024 EBX=f6a07000 ECX=f6a0737c EDX=f8be0118 ESI=f6a0737c EDI=00000021 EBP=f6929f98 ESP=f6929f98 EIP=f8bdd141 EFL=00010086 [--S--P-] CPL=0 II=0 A20=1 SMM=0 HLT=0 ES =007b 00000000 ffffffff 00c0f300 DPL=3 DS [-WA] CS =0060 00000000 ffffffff 00c09b00 DPL=0 CS32 [-RA] SS =0068 00000000 ffffffff 00c09300 DPL=0 DS [-WA] DS =007b 00000000 ffffffff 00c0f300 DPL=3 DS [-WA] FS =00d8 2c044000 ffffffff 00809300 DPL=0 DS16 [-WA] GS =0033 081a44c8 01000fff 00d0f300 DPL=3 DS [-WA] LDT=0000 00000000 ffffffff 00000000 TR =0080 f6ea0c80 0000206b 00008b00 DPL=0 TSS32-busy GDT= f6e99000 000000ff IDT= fffbb000 000007ff CR0=80050033 CR2=b757d000 CR3=35d31000 CR4=001406d0 Signed-off-by: Peng Hao Reviewed-by: Jiang Biao --- arch/x86/kvm/emulate.c | 5 ++++- arch/x86/kvm/x86.c | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 106482d..aecf9a72 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -5105,8 +5105,11 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len) memcpy(ctxt->fetch.data, insn, insn_len); else { rc = __do_insn_fetch_bytes(ctxt, 1); - if (rc != X86EMUL_CONTINUE) + if (rc != X86EMUL_CONTINUE) { + if (rc == X86EMUL_PROPAGATE_FAULT) + ctxt->have_exception = true; return rc; + } } switch (mode) { diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 542f631..27072e1 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -6188,8 +6188,10 @@ int x86_emulate_instruction(struct kvm_vcpu *vcpu, if (reexecute_instruction(vcpu, cr2, write_fault_to_spt, emulation_type)) return EMULATE_DONE; - if (ctxt->have_exception && inject_emulated_exception(vcpu)) + if (ctxt->have_exception) { + inject_emulated_exception(vcpu); return EMULATE_DONE; + } if (emulation_type & EMULTYPE_SKIP) return EMULATE_FAIL; return handle_emulation_failure(vcpu, emulation_type); -- 1.8.3.1