Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5656538ybl; Tue, 27 Aug 2019 07:55:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqxHtbmcae8eIRpRrDwtmML/rYY/n2E3vin8b0q4/UTbJezorzeh1QfccvQzR5WBd3wne4In X-Received: by 2002:a17:902:a515:: with SMTP id s21mr4597105plq.260.1566917711697; Tue, 27 Aug 2019 07:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566917711; cv=none; d=google.com; s=arc-20160816; b=XODdGZWVEyBzroh2UYbqGWuXvR6Wof9jPjypbclgYsjLxD2ipSkkoI7t0XBGU4qd3I RinDnm+ZpQD3AiIQrcsb0TPb9sVnkNmFJCQhCuRWWezpXATu9zUJZOvIeLecCSlL5/S4 6+ckmJ2r/mILFyU479xp2uWsaKkkE4VgZCa6c/ma3ijp+5owII5NL26aIHP7QUi4pLs/ k9/eSsXAs1ZKjc9SeKf4gPRClIQo/yTNuy5cuthuAK6Ex1Ph9H9/fax/Q7izqn9HyWQ5 VYtOqxngZFKm77Q4yp0+9zygYxrcqrITj4IufJBj7CKp4XbJ+f5nMEg4cnZAkWO4m2FE JvCQ== 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=NWc0TLieAkSf1fSu7YiAJ/xGe+imtqrRLLsdR2fxTa4=; b=aODQqBD9IvxdmT6RziqsJS0++NfmErOaK0eLA8pawRCR91epKPGefAewlW9RQz8IRV 9mh8KMgKLgiTqmGxclPu2fB1ShhMyfeTUNUcNfHyO5HdoVYkgWH44/ELr+7IWmFTzfHe MAGrgLq8MBai4zTLxsTuH56fvy4M3+4XbG0AsxtTG/GnknQz2mBu9HaWxc/whFfHDV4A wWq0F519UoKe/topwOmiC9/t0fTJagJzSUHfl9jFGs7whmZdyt1RwsnV2cAIbeEZPg9+ btRf0mEryFjrDyh1nkJL8629TV+fPhlhOy8pbEvt3EZjYY+knNMXY+mgK4HcrQ9M+v/Z jkVA== 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 j6si670697pfa.122.2019.08.27.07.54.55; Tue, 27 Aug 2019 07:55:11 -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 S1729959AbfH0OyA (ORCPT + 99 others); Tue, 27 Aug 2019 10:54:00 -0400 Received: from mga07.intel.com ([134.134.136.100]:21708 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726333AbfH0Ox7 (ORCPT ); Tue, 27 Aug 2019 10:53:59 -0400 X-Amp-Result: UNSCANNABLE X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Aug 2019 07:53:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,437,1559545200"; d="scan'208";a="380943529" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by fmsmga006.fm.intel.com with ESMTP; 27 Aug 2019 07:53:58 -0700 Date: Tue, 27 Aug 2019 07:53:58 -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" Subject: Re: [PATCH 2/3] KVM: x86: set ctxt->have_exception in x86_decode_insn() Message-ID: <20190827145358.GD27459@linux.intel.com> References: <1566911210-30059-1-git-send-email-jan.dakinevich@virtuozzo.com> <1566911210-30059-3-git-send-email-jan.dakinevich@virtuozzo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1566911210-30059-3-git-send-email-jan.dakinevich@virtuozzo.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 On Tue, Aug 27, 2019 at 01:07:08PM +0000, Jan Dakinevich wrote: > x86_emulate_instruction() takes into account ctxt->have_exception flag > during instruction decoding, but in practice this flag is never set in > x86_decode_insn(). > > 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/emulate.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c > index 6170ddf..f93880f 100644 > --- a/arch/x86/kvm/emulate.c > +++ b/arch/x86/kvm/emulate.c > @@ -5395,6 +5395,8 @@ int x86_decode_insn(struct x86_emulate_ctxt *ctxt, void *insn, int insn_len) > ctxt->memopp->addr.mem.ea + ctxt->_eip); > > done: > + if (rc == X86EMUL_PROPAGATE_FAULT) > + ctxt->have_exception = true; We should add a sanity check or two on the vector since the emulator code goes all over the place, e.g. #UD should not be injected/propagated, and trap-like exceptions should not be handled/encountered during decode. Note, exception_type() also warns on illegal vectors. WARN_ON_ONCE(ctxt->exception.vector == UD_VECTOR || exception_type(ctxt->exception.vector) == EXCPT_TRAP); > return (rc != X86EMUL_CONTINUE) ? EMULATION_FAILED : EMULATION_OK; > } > > -- > 2.1.4 >