All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vitaly Kuznetsov <vkuznets@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: cavery@redhat.com, jan.kiszka@siemens.com, wei.huang2@amd.com,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Subject: Re: [PATCH 1/4] KVM: nSVM: do not change host intercepts while nested VM is running
Date: Fri, 06 Mar 2020 15:42:46 +0100	[thread overview]
Message-ID: <87a74tee8p.fsf@vitty.brq.redhat.com> (raw)
In-Reply-To: <1583403227-11432-2-git-send-email-pbonzini@redhat.com>

Paolo Bonzini <pbonzini@redhat.com> writes:

> Instead of touching the host intercepts so that the bitwise OR in
> recalc_intercepts just works, mask away uninteresting intercepts
> directly in recalc_intercepts.
>
> This is cleaner and keeps the logic in one place even for intercepts
> that can change even while L2 is running.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  arch/x86/kvm/svm.c | 31 ++++++++++++++++++-------------
>  1 file changed, 18 insertions(+), 13 deletions(-)
>
> diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
> index 247e31d21b96..14cb5c194008 100644
> --- a/arch/x86/kvm/svm.c
> +++ b/arch/x86/kvm/svm.c
> @@ -519,10 +519,24 @@ static void recalc_intercepts(struct vcpu_svm *svm)
>  	h = &svm->nested.hsave->control;
>  	g = &svm->nested;
>  
> -	c->intercept_cr = h->intercept_cr | g->intercept_cr;
> -	c->intercept_dr = h->intercept_dr | g->intercept_dr;
> -	c->intercept_exceptions = h->intercept_exceptions | g->intercept_exceptions;
> -	c->intercept = h->intercept | g->intercept;
> +	c->intercept_cr = h->intercept_cr;
> +	c->intercept_dr = h->intercept_dr;
> +	c->intercept_exceptions = h->intercept_exceptions;
> +	c->intercept = h->intercept;
> +
> +	if (svm->vcpu.arch.hflags & HF_VINTR_MASK) {
> +		/* We only want the cr8 intercept bits of L1 */
> +		c->intercept_cr &= ~(1U << INTERCEPT_CR8_READ);
> +		c->intercept_cr &= ~(1U << INTERCEPT_CR8_WRITE);
> +	}
> +
> +	/* We don't want to see VMMCALLs from a nested guest */
> +	c->intercept &= ~(1ULL << INTERCEPT_VMMCALL);
> +
> +	c->intercept_cr |= g->intercept_cr;
> +	c->intercept_dr |= g->intercept_dr;
> +	c->intercept_exceptions |= g->intercept_exceptions;
> +	c->intercept |= g->intercept;
>  }
>  
>  static inline struct vmcb *get_host_vmcb(struct vcpu_svm *svm)
> @@ -3590,15 +3604,6 @@ static void enter_svm_guest_mode(struct vcpu_svm *svm, u64 vmcb_gpa,
>  	else
>  		svm->vcpu.arch.hflags &= ~HF_VINTR_MASK;
>  
> -	if (svm->vcpu.arch.hflags & HF_VINTR_MASK) {
> -		/* We only want the cr8 intercept bits of the guest */
> -		clr_cr_intercept(svm, INTERCEPT_CR8_READ);
> -		clr_cr_intercept(svm, INTERCEPT_CR8_WRITE);
> -	}
> -
> -	/* We don't want to see VMMCALLs from a nested guest */
> -	clr_intercept(svm, INTERCEPT_VMMCALL);
> -
>  	svm->vcpu.arch.tsc_offset += nested_vmcb->control.tsc_offset;
>  	svm->vmcb->control.tsc_offset = svm->vcpu.arch.tsc_offset;

FWIW,

Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>

-- 
Vitaly


  reply	other threads:[~2020-03-06 14:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-05 10:13 [PATCH 0/4] KVM: nSVM: first step towards fixing event injection Paolo Bonzini
2020-03-05 10:13 ` [PATCH 1/4] KVM: nSVM: do not change host intercepts while nested VM is running Paolo Bonzini
2020-03-06 14:42   ` Vitaly Kuznetsov [this message]
2020-03-05 10:13 ` [PATCH 2/4] KVM: nSVM: ignore L1 interrupt window while running L2 with V_INTR_MASKING=1 Paolo Bonzini
2020-03-05 10:13 ` [PATCH 3/4] KVM: nSVM: implement check_nested_events for interrupts Paolo Bonzini
2020-03-05 23:51   ` kbuild test robot
2020-03-05 23:51     ` kbuild test robot
2020-03-07  1:18   ` kbuild test robot
2020-03-07  1:18     ` kbuild test robot
2020-03-05 10:13 ` [PATCH 4/4] KVM: nSVM: avoid loss of pending IRQ/NMI before entering L2 Paolo Bonzini
2020-03-05 10:46   ` Jan Kiszka

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=87a74tee8p.fsf@vitty.brq.redhat.com \
    --to=vkuznets@redhat.com \
    --cc=cavery@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=wei.huang2@amd.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.