lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date:   Mon, 08 Nov 2021 10:55:19 +0200
From:   Maxim Levitsky <mlevitsk@...hat.com>
To:     Sean Christopherson <seanjc@...gle.com>
Cc:     kvm@...r.kernel.org, Jim Mattson <jmattson@...gle.com>,
        Wanpeng Li <wanpengli@...cent.com>,
        Ingo Molnar <mingo@...hat.com>,
        "H. Peter Anvin" <hpa@...or.com>, Borislav Petkov <bp@...en8.de>,
        linux-kernel@...r.kernel.org, Paolo Bonzini <pbonzini@...hat.com>,
        Joerg Roedel <joro@...tes.org>,
        Thomas Gleixner <tglx@...utronix.de>,
        "maintainer:X86 ARCHITECTURE (32-BIT AND 64-BIT)" <x86@...nel.org>,
        Vitaly Kuznetsov <vkuznets@...hat.com>
Subject: Re: [PATCH v3] KVM: x86: inhibit APICv when KVM_GUESTDBG_BLOCKIRQ
 active

On Thu, 2021-11-04 at 19:26 +0000, Sean Christopherson wrote:
> 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!

Thanks! It is now possible to enjoy this,
after we broke our back making APICv/AVIC inhibition actually work...

> 
> > Fixes: 61e5f69ef0837 ("KVM: x86: implement KVM_GUESTDBG_BLOCKIRQ")
> > 
> > Signed-off-by: Maxim Levitsky <mlevitsk@...hat.com>
> > ---
> 
> With the below nits resolved (tested on Intel w/ APICv):
> 
> Reviewed-and-tested-by: Sean Christopherson <seanjc@...gle.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.
True, fixed in v4
> 
> > +	int i;
> 
> Nit, I'd prefer we use reverse fir tree when it's convenient, i.e.
Fixed in v4

> 
> 	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();

Yep :-)

> 
> > +	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
> > 

Thanks for the review,
	Best regards,
		Maxim Levitsky


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ