Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1238636ybl; Wed, 28 Aug 2019 11:36:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqzcWqXc0eex8tXsDYLRQ2Iug5K2QFu16nST9fxdA+DRyY7xCtNpbYTMFH7vUbq37zGxqldY X-Received: by 2002:a17:902:d911:: with SMTP id c17mr5776456plz.70.1567017391373; Wed, 28 Aug 2019 11:36:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567017391; cv=none; d=google.com; s=arc-20160816; b=A8gdC0ZyJWSuzqSv6bNkLq6XcDYSw5y/66Gf34J7YAjRW8iok0ZIbpBQITM9ixidYl 9DViuGEBNVgnrrkctlaAeEb6nL6RO7KEwX8TVwULKwfU71/Jcsl1J8yIRy3zq7N/MU7g 9xDRCj90qf19C3uXctBgZC3AXOyHvO2GcUjRmH02KEeW+cN+U1jhjMlPzDhx6y4W8j+k bHMXbCjujc2pH6mkXR/lrSxYPFBI6F3P6qzO9pz3rCvyUR18lJTPtaTjIAAaomD8YsGJ kN9Y6Jvwbz+1kIXHcJxTqfR+UjWf0/3f3xr2uzrHyY1E/4qmubwIF7Qz3u2LQMWyQbBh 6Wuw== 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=SuFrW42lAU2w8wMnmULUC+AEi3fJl0axc68uhHHQyZI=; b=zjmpYKm8+PxiAJayhZ2sEWI4nW4kqC4XNgeKbgyBqxDYuj5688n3gVC8J1iDKEZoyQ EjExrSxXHpXORnfNZPfnopOzcW4f+waJ1L87ez+SMXjumhX3Cb/MXFYBhO/J5FI14k64 F9L3vkQqTbgx0qlYXrFacrxjQJy5D7/Z5x03nkhcsD9PmPyt6+xo4CouNy+En2Zp63XQ FSDoqqhNc9HOiZhLk+5naMOPkR8iFDiOYGExXjskTiXgEFU06xkMq0GYxcO87wXPxVVZ zkTfknaPd6OKLk0/WMipPR9IpeW6aNtqSAqzaWQyh4vondGC2RJd8qVOry+pEv9x/ES+ z5Fg== 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 r23si2846683pgv.451.2019.08.28.11.36.15; Wed, 28 Aug 2019 11:36:31 -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 S1726898AbfH1SfZ (ORCPT + 99 others); Wed, 28 Aug 2019 14:35:25 -0400 Received: from mga11.intel.com ([192.55.52.93]:7081 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726567AbfH1SfY (ORCPT ); Wed, 28 Aug 2019 14:35:24 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Aug 2019 11:35:24 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,442,1559545200"; d="scan'208";a="197623038" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.41]) by fmsmga001.fm.intel.com with ESMTP; 28 Aug 2019 11:35:23 -0700 Date: Wed, 28 Aug 2019 11:35:23 -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 v2 2/3] KVM: x86: make exception_class() and exception_type() globally visible Message-ID: <20190828183523.GC21651@linux.intel.com> References: <1567011759-9969-1-git-send-email-jan.dakinevich@virtuozzo.com> <1567011759-9969-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: <1567011759-9969-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 Wed, Aug 28, 2019 at 05:02:57PM +0000, Jan Dakinevich wrote: > exception_type() function was moved for upcoming sanity check in > emulation code. exceptions_class() function is not supposed to be used > right now, but it was moved as well to keep things together. Doh, I didn't realize exception_type() was confined to x86.c when I suggested the sanity check. It'd probably be better to add the check in x86_emulate_instruction and forego this patch, e.g.: if (ctxt->have_exception) { WARN_ON_ONCE(...); inject_emulated_exception(vcpu)); return EMULATE_DONE; } Arguably we shouldn't WARN on an unexpected vector until we actually try to inject it anyways. Sorry for the thrash. > > Cc: Denis Lunev > Cc: Roman Kagan > Cc: Denis Plotnikov > Signed-off-by: Jan Dakinevich > --- > arch/x86/kvm/x86.c | 46 ---------------------------------------------- > arch/x86/kvm/x86.h | 46 ++++++++++++++++++++++++++++++++++++++++++++++ > 2 files changed, 46 insertions(+), 46 deletions(-) > > diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c > index 903fb7c..2b69ae0 100644 > --- a/arch/x86/kvm/x86.c > +++ b/arch/x86/kvm/x86.c > @@ -364,52 +364,6 @@ asmlinkage __visible void kvm_spurious_fault(void) > } > EXPORT_SYMBOL_GPL(kvm_spurious_fault); > > -#define EXCPT_BENIGN 0 > -#define EXCPT_CONTRIBUTORY 1 > -#define EXCPT_PF 2 > - > -static int exception_class(int vector) > -{ > - switch (vector) { > - case PF_VECTOR: > - return EXCPT_PF; > - case DE_VECTOR: > - case TS_VECTOR: > - case NP_VECTOR: > - case SS_VECTOR: > - case GP_VECTOR: > - return EXCPT_CONTRIBUTORY; > - default: > - break; > - } > - return EXCPT_BENIGN; > -} > - > -#define EXCPT_FAULT 0 > -#define EXCPT_TRAP 1 > -#define EXCPT_ABORT 2 > -#define EXCPT_INTERRUPT 3 > - > -static int exception_type(int vector) > -{ > - unsigned int mask; > - > - if (WARN_ON(vector > 31 || vector == NMI_VECTOR)) > - return EXCPT_INTERRUPT; > - > - mask = 1 << vector; > - > - /* #DB is trap, as instruction watchpoints are handled elsewhere */ > - if (mask & ((1 << DB_VECTOR) | (1 << BP_VECTOR) | (1 << OF_VECTOR))) > - return EXCPT_TRAP; > - > - if (mask & ((1 << DF_VECTOR) | (1 << MC_VECTOR))) > - return EXCPT_ABORT; > - > - /* Reserved exceptions will result in fault */ > - return EXCPT_FAULT; > -} > - > void kvm_deliver_exception_payload(struct kvm_vcpu *vcpu) > { > unsigned nr = vcpu->arch.exception.nr; > diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h > index b5274e2..2b66347 100644 > --- a/arch/x86/kvm/x86.h > +++ b/arch/x86/kvm/x86.h > @@ -369,4 +369,50 @@ static inline bool kvm_pat_valid(u64 data) > void kvm_load_guest_xcr0(struct kvm_vcpu *vcpu); > void kvm_put_guest_xcr0(struct kvm_vcpu *vcpu); > > +#define EXCPT_BENIGN 0 > +#define EXCPT_CONTRIBUTORY 1 > +#define EXCPT_PF 2 > + > +static inline int exception_class(int vector) > +{ > + switch (vector) { > + case PF_VECTOR: > + return EXCPT_PF; > + case DE_VECTOR: > + case TS_VECTOR: > + case NP_VECTOR: > + case SS_VECTOR: > + case GP_VECTOR: > + return EXCPT_CONTRIBUTORY; > + default: > + break; > + } > + return EXCPT_BENIGN; > +} > + > +#define EXCPT_FAULT 0 > +#define EXCPT_TRAP 1 > +#define EXCPT_ABORT 2 > +#define EXCPT_INTERRUPT 3 > + > +static inline int exception_type(int vector) > +{ > + unsigned int mask; > + > + if (WARN_ON(vector > 31 || vector == NMI_VECTOR)) > + return EXCPT_INTERRUPT; > + > + mask = 1 << vector; > + > + /* #DB is trap, as instruction watchpoints are handled elsewhere */ > + if (mask & ((1 << DB_VECTOR) | (1 << BP_VECTOR) | (1 << OF_VECTOR))) > + return EXCPT_TRAP; > + > + if (mask & ((1 << DF_VECTOR) | (1 << MC_VECTOR))) > + return EXCPT_ABORT; > + > + /* Reserved exceptions will result in fault */ > + return EXCPT_FAULT; > +} > + > #endif > -- > 2.1.4 >