linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Christopherson <sean.j.christopherson@intel.com>
To: Jan Dakinevich <jan.dakinevich@virtuozzo.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"Denis Lunev" <den@virtuozzo.com>,
	"Roman Kagan" <rkagan@virtuozzo.com>,
	"Denis Plotnikov" <dplotnikov@virtuozzo.com>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Radim Krčmář" <rkrcmar@redhat.com>,
	"Vitaly Kuznetsov" <vkuznets@redhat.com>,
	"Wanpeng Li" <wanpengli@tencent.com>,
	"Jim Mattson" <jmattson@google.com>,
	"Joerg Roedel" <joro@8bytes.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	"Ingo Molnar" <mingo@redhat.com>,
	"Borislav Petkov" <bp@alien8.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	"x86@kernel.org" <x86@kernel.org>,
	"kvm@vger.kernel.org" <kvm@vger.kernel.org>
Subject: Re: [PATCH v2 2/3] KVM: x86: make exception_class() and exception_type() globally visible
Date: Wed, 28 Aug 2019 11:35:23 -0700	[thread overview]
Message-ID: <20190828183523.GC21651@linux.intel.com> (raw)
In-Reply-To: <1567011759-9969-3-git-send-email-jan.dakinevich@virtuozzo.com>

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 <den@virtuozzo.com>
> Cc: Roman Kagan <rkagan@virtuozzo.com>
> Cc: Denis Plotnikov <dplotnikov@virtuozzo.com>
> Signed-off-by: Jan Dakinevich <jan.dakinevich@virtuozzo.com>
> ---
>  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
> 

  reply	other threads:[~2019-08-28 18:35 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-28 17:02 [PATCH v2 0/3] fix emulation error on Windows bootup Jan Dakinevich
2019-08-28 17:02 ` [PATCH v2 1/3] KVM: x86: always stop emulation on page fault Jan Dakinevich
2019-08-28 17:02 ` [PATCH v2 2/3] KVM: x86: make exception_class() and exception_type() globally visible Jan Dakinevich
2019-08-28 18:35   ` Sean Christopherson [this message]
2019-08-28 17:02 ` [PATCH v2 3/3] KVM: x86: set ctxt->have_exception in x86_decode_insn() Jan Dakinevich

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=20190828183523.GC21651@linux.intel.com \
    --to=sean.j.christopherson@intel.com \
    --cc=bp@alien8.de \
    --cc=den@virtuozzo.com \
    --cc=dplotnikov@virtuozzo.com \
    --cc=hpa@zytor.com \
    --cc=jan.dakinevich@virtuozzo.com \
    --cc=jmattson@google.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rkagan@virtuozzo.com \
    --cc=rkrcmar@redhat.com \
    --cc=tglx@linutronix.de \
    --cc=vkuznets@redhat.com \
    --cc=wanpengli@tencent.com \
    --cc=x86@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).