Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5658021ybl; Tue, 27 Aug 2019 07:56:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqwqj8iZKtdu8fXIaCG5gyD77u49k7vwEJK4YVU1ncwO7k+ks16LemUMYKFlPSqmT1qqIrw5 X-Received: by 2002:a63:2a08:: with SMTP id q8mr21458213pgq.415.1566917785760; Tue, 27 Aug 2019 07:56:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566917785; cv=none; d=google.com; s=arc-20160816; b=NsfY46NM0GWoXGi6b2qR3oOrlqWbyi6O1K3mOn4bwfkQpv2FxfOMMJB2/2s94eX/cz EiK6yb+Tld3AiP9R3UbmmkK2xsXQ7HJZsAr8l05gHXESUoPMlge3rUkgsjPt2eu+hDJK +sQCjV9a3X0156GKFnNJfwEO4l12sNYpnQ0PVPHXqCGbO4X3FI7a5472zWv2TCa540BV 5IUt130xtodruirsvph/+uBb9dPcloAG/4yEShF9XorxovlxC0M1MCU09zB6DSJMnmQ/ Eieexg6j+bFn8deEeuyhcelE44QtYa0yV7dAo4kWTTOzg4MQ0vdClR1fHpUAuoXfjByK 3wdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=2vRReejizj8coxJ/M7hQTiVsb3Ub3p6dceA7BB3esn4=; b=vlKhYwNQE/8F6/d+MySAI+3nUygxdG6wOveEMgjtzSKMUaeNgPHEJCmgtkSzUWRwcr 2DL9oeyxi2TK8L4kl2rs+rAcLcx3JR/2HQj/Un7Ab5RteRy/KRmK0SAUMSh+TyiwL5ZL /Bcw7WJbHToP4k65q+txBAKhBEbba9Jaqpnzth3rx6tQ8fmQSgNbZ42gj/xr04uTuA1w gxqQ6mtqmrIYa+e2gB124us4OyWpWAL2NPUg0xdV5p08zQ8rmucLJBYzRHxD1MKUxeAX 5D1p9JJ6i8M+saVqaNpl2HuLRyLRXMIOfp/N79cwjJ5GMeaPJCnPMlN6UmutAab3nJco hURw== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i69si12007536pge.366.2019.08.27.07.56.10; Tue, 27 Aug 2019 07:56:25 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730116AbfH0OzF (ORCPT + 99 others); Tue, 27 Aug 2019 10:55:05 -0400 Received: from mga02.intel.com ([134.134.136.20]:20918 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725987AbfH0OzE (ORCPT ); Tue, 27 Aug 2019 10:55:04 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Aug 2019 07:55:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,437,1559545200"; d="scan'208";a="192257168" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by orsmga002.jf.intel.com with ESMTP; 27 Aug 2019 07:55:03 -0700 Date: Tue, 27 Aug 2019 07:55:03 -0700 From: Sean Christopherson To: Jan Dakinevich Cc: "linux-kernel@vger.kernel.org" , Denis Lunev , Roman Kagan , Denis Plotnikov , Paolo Bonzini , Radim =?utf-8?B?S3LEjW3DocWZ?= , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "x86@kernel.org" , "kvm@vger.kernel.org" , Yi Wang , Peng Hao Subject: Re: [PATCH 3/3] KVM: x86: always stop emulation on page fault Message-ID: <20190827145503.GE27459@linux.intel.com> References: <1566911210-30059-1-git-send-email-jan.dakinevich@virtuozzo.com> <1566911210-30059-4-git-send-email-jan.dakinevich@virtuozzo.com> <20190827145030.GC27459@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190827145030.GC27459@linux.intel.com> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Actually adding Peng Hao and Yi Wang... On Tue, Aug 27, 2019 at 07:50:30AM -0700, Sean Christopherson wrote: > +Cc Peng Hao and Yi Wang > > On Tue, Aug 27, 2019 at 01:07:09PM +0000, Jan Dakinevich wrote: > > inject_emulated_exception() returns true if and only if nested page > > fault happens. However, page fault can come from guest page tables > > walk, either nested or not nested. In both cases we should stop an > > attempt to read under RIP and give guest to step over its own page > > fault handler. > > > > Fixes: 6ea6e84 ("KVM: x86: inject exceptions produced by x86_decode_insn") > > Cc: Denis Lunev > > Cc: Roman Kagan > > Cc: Denis Plotnikov > > Signed-off-by: Jan Dakinevich > > --- > > arch/x86/kvm/x86.c | 4 +++- > > 1 file changed, 3 insertions(+), 1 deletion(-) > > > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > > index 93b0bd4..45caa69 100644 > > --- a/arch/x86/kvm/x86.c > > +++ b/arch/x86/kvm/x86.c > > @@ -6521,8 +6521,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; > > + } > > > Yikes, this patch and the previous have quite the sordid history. > > > The non-void return from inject_emulated_exception() was added by commit > > ef54bcfeea6c ("KVM: x86: skip writeback on injection of nested exception") > > for the purpose of skipping writeback. At the time, the above blob in the > decode flow didn't exist. > > > Decode exception handling was added by commit > > 6ea6e84309ca ("KVM: x86: inject exceptions produced by x86_decode_insn") > > but it was dead code even then. The patch discussion[1] even point out that > it was dead code, i.e. the change probably should have been reverted. > > > Peng Hao and Yi Wang later ran into what appears to be the same bug you're > hitting[2][3], and even had patches temporarily queued[4][5], but the > patches never made it to mainline as they broke kvm-unit-tests. Fun side > note, Radim even pointed out[4] the bug fixed by patch 1/3. > > So, the patches look correct, but there's the open question of why the > hypercall test was failing for Paolo. I've tried to reproduce the #DF to > no avail. > > [1] https://lore.kernel.org/patchwork/patch/850077/ > [2] https://lkml.kernel.org/r/1537311828-4547-1-git-send-email-penghao122@sina.com.cn > [3] https://lkml.kernel.org/r/20190111133002.GA14852@flask > [4] https://lkml.kernel.org/r/20190111133002.GA14852@flask > [5] https://lkml.kernel.org/r/9835d255-dd9a-222b-f4a2-93611175b326@redhat.com > > > if (emulation_type & EMULTYPE_SKIP) > > return EMULATE_FAIL; > > return handle_emulation_failure(vcpu, emulation_type); > > -- > > 2.1.4 > >