public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Maxim Levitsky <mlevitsk@redhat.com>
Cc: kvm@vger.kernel.org, Jim Mattson <jmattson@google.com>,
	Wanpeng Li <wanpengli@tencent.com>,
	Ingo Molnar <mingo@redhat.com>, "H. Peter Anvin" <hpa@zytor.com>,
	Borislav Petkov <bp@alien8.de>,
	linux-kernel@vger.kernel.org, Paolo Bonzini <pbonzini@redhat.com>,
	Joerg Roedel <joro@8bytes.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	"maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)"
	<x86@kernel.org>, Vitaly Kuznetsov <vkuznets@redhat.com>
Subject: Re: [PATCH v3] KVM: x86: inhibit APICv when KVM_GUESTDBG_BLOCKIRQ active
Date: Thu, 4 Nov 2021 19:26:20 +0000	[thread overview]
Message-ID: <YYQz3E/eNxdnNwBj@google.com> (raw)
In-Reply-To: <20211103143929.15264-1-mlevitsk@redhat.com>

On Wed, Nov 03, 2021, Maxim Levitsky wrote:
> KVM_GUESTDBG_BLOCKIRQ relies on interrupts being injected using
> standard kvm's inject_pending_event, and not via APICv/AVIC.
> 
> Since this is a debug feature, just inhibit APICv/AVIC while
> KVM_GUESTDBG_BLOCKIRQ is in use on at least one vCPU.

Very clever!

> Fixes: 61e5f69ef0837 ("KVM: x86: implement KVM_GUESTDBG_BLOCKIRQ")
> 
> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> ---

With the below nits resolved (tested on Intel w/ APICv):

Reviewed-and-tested-by: Sean Christopherson <seanjc@google.com>

> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index ac83d873d65b0..5d30cea58182e 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -10703,6 +10703,25 @@ int kvm_arch_vcpu_ioctl_set_sregs(struct kvm_vcpu *vcpu,
>  	return ret;
>  }
>  
> +static void kvm_arch_vcpu_guestdbg_update_apicv_inhibit(struct kvm *kvm)
> +{
> +	struct kvm_vcpu *vcpu = NULL;

vcpu doesn't need to be initialized.

> +	int i;

Nit, I'd prefer we use reverse fir tree when it's convenient, i.e.

	bool block_irq_used = false;
	struct kvm_vcpu *vcpu;
	int i;

> +	bool block_irq_used = false;
> +
> +	down_write(&kvm->arch.apicv_update_lock);
> +
> +	kvm_for_each_vcpu(i, vcpu, kvm) {
> +		if (vcpu->guest_debug & KVM_GUESTDBG_BLOCKIRQ) {
> +			block_irq_used = true;
> +			break;
> +		}
> +	}
> +	__kvm_request_apicv_update(kvm, !block_irq_used,
> +					       APICV_INHIBIT_REASON_BLOCKIRQ);

Heh, this indentation is still messed up, I think you need to change your

	if (r == -ENOCOFFEE)
		maxim_get_coffee();

to

	while (r == -ENOCOFFEE)
		r = maxim_get_coffee();

> +	up_write(&kvm->arch.apicv_update_lock);
> +}
> +
>  int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
>  					struct kvm_guest_debug *dbg)
>  {
> @@ -10755,6 +10774,8 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
>  
>  	static_call(kvm_x86_update_exception_bitmap)(vcpu);
>  
> +	kvm_arch_vcpu_guestdbg_update_apicv_inhibit(vcpu->kvm);
> +
>  	r = 0;
>  
>  out:
> -- 
> 2.26.3
> 

  reply	other threads:[~2021-11-04 19:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-03 14:39 [PATCH v3] KVM: x86: inhibit APICv when KVM_GUESTDBG_BLOCKIRQ active Maxim Levitsky
2021-11-04 19:26 ` Sean Christopherson [this message]
2021-11-08  8:55   ` Maxim Levitsky

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=YYQz3E/eNxdnNwBj@google.com \
    --to=seanjc@google.com \
    --cc=bp@alien8.de \
    --cc=hpa@zytor.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=mlevitsk@redhat.com \
    --cc=pbonzini@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