All of lore.kernel.org
 help / color / mirror / Atom feed
From: Bandan Das <bsd@redhat.com>
To: "Dirk Müller" <dmueller@suse.com>
Cc: Joerg Roedel <joro@8bytes.org>,
	Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org
Subject: Re: [PATCH] Use WARN_ON_ONCE for missing X86_FEATURE_NRIPS
Date: Mon, 05 Oct 2015 18:00:54 -0400	[thread overview]
Message-ID: <jpgtwq5x9ex.fsf@linux.bootlegged.copy> (raw)
In-Reply-To: <4BCE1269-C3D0-4D38-887C-EF31F0AFBBA0@suse.com> ("Dirk \=\?utf-8\?Q\?M\=C3\=BCller\=22's\?\= message of "Mon, 5 Oct 2015 22:12:02 +0200")

Dirk Müller <dmueller@suse.com> writes:

>> So the right fix would be to just set the guests next_rip to 0 when we
>> emulate vmrun, just like real hardware does, no?
>
> Like this? (Note: I’m not sure what I’m doing here..). I Agree with you that the warning
> for this seems excessive, I’ve just removed it. 
>
>
> From 47db81837b6fe58aa302317bbf2a092b40af0a36 Mon Sep 17 00:00:00 2001
> From: Dirk Mueller <dirk@dmllr.de>
> Date: Fri, 2 Oct 2015 08:35:24 +0200
> Subject: [PATCH] KVM: nSVM: Check for NRIP support before passing on
>  control.next_rip
>
> NRIP support itself depends on cpuid Fn8000_000A_EDX[NRIPS], so
> ignore it if the cpu feature is not available. Remove the
> guest-triggerable WARN_ON for this as it just emulates real
> hardware behavior.
>
> Signed-off-by: Dirk Mueller <dmueller@suse.com>
> ---
>  arch/x86/kvm/svm.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index 0a42859..66e3a4c 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -514,8 +514,10 @@ static void skip_emulated_instruction(struct kvm_vcpu *vcpu)
>  	struct vcpu_svm *svm = to_svm(vcpu);
>  
>  	if (svm->vmcb->control.next_rip != 0) {
> -		WARN_ON_ONCE(!static_cpu_has(X86_FEATURE_NRIPS));
> -		svm->next_rip = svm->vmcb->control.next_rip;
> +		if (static_cpu_has(X86_FEATURE_NRIPS))
> +			svm->next_rip = svm->vmcb->control.next_rip;
> +		else
> +			svm->next_rip = 0;

skip_emulated_instruction probably isn't the right place.

>  	}

So, L1 writes this field in svm_check_intercept.

I went back to the spec and it says (15.7.1):
The next sequential instruction pointer (nRIP) is saved in the guest VMCB
control area at location C8h on all #VMEXITs that are due to instruction
intercepts, as defined in Section 15.9 on page 458, as well as MSR and
IOIO intercepts and exceptions caused by the INT3, INTO, and BOUND
instructions. For all other intercepts, nRIP is reset to zero.

So, I think a better way would be to reset the field on vmexit from
L2 to L0 if NRIP isn't supported. Maybe it's enough to do this only for
the intercepts mentioned above but I am not sure.

Also, please include a debug message (pr_debug_once will do). It seems
unnecessary today, but in 2 years when someone is scratching his head why his
nested guests won't run, he will thank you!

BTW, it seems possible to unconditionally advertise SVM_FEATURE_NRIP..

>  	if (!svm->next_rip) {

  reply	other threads:[~2015-10-05 22:00 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-01 11:43 [PATCH] Use WARN_ON_ONCE for missing X86_FEATURE_NRIPS Dirk Müller
2015-10-01 12:25 ` Paolo Bonzini
2015-10-01 12:45   ` Dirk Müller
2015-10-01 12:31 ` Paolo Bonzini
2015-10-01 22:31   ` Bandan Das
2015-10-02  6:43     ` Dirk Müller
2015-10-05  1:15       ` Bandan Das
2015-10-05  9:50     ` Joerg Roedel
2015-10-05 16:54       ` Bandan Das
2015-10-05 17:15         ` Joerg Roedel
2015-10-05 17:42           ` Bandan Das
2015-10-06 10:23             ` Joerg Roedel
2015-10-06 18:02               ` Bandan Das
2015-10-05 20:12           ` Dirk Müller
2015-10-05 22:00             ` Bandan Das [this message]
2015-10-06 10:28     ` Joerg Roedel
2015-10-06 17:59       ` Bandan Das
2015-10-07 11:03         ` Joerg Roedel
2015-10-07 12:47           ` [PATCH] kvm: svm: Only propagate next_rip when guest supports it Joerg Roedel
2015-10-07 12:57             ` kbuild test robot
2015-10-07 15:48             ` Bandan Das
2015-10-07 16:14               ` Joerg Roedel
2015-10-07 17:03                 ` Dirk Müller
2015-10-07 14:58           ` [PATCH] Use WARN_ON_ONCE for missing X86_FEATURE_NRIPS Bandan Das
2015-10-07 15:24             ` Joerg Roedel

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=jpgtwq5x9ex.fsf@linux.bootlegged.copy \
    --to=bsd@redhat.com \
    --cc=dmueller@suse.com \
    --cc=joro@8bytes.org \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.