Re: [patch 1/4] KVM: x86: add start_assignment hook to kvm_x86_ops

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, May 10, 2021 at 02:26:47PM -0300, Marcelo Tosatti wrote:
> Add a start_assignment hook to kvm_x86_ops, which is called when 
> kvm_arch_start_assignment is done.
> 
> The hook is required to update the wakeup vector of a sleeping vCPU
> when a device is assigned to the guest.
> 
> Signed-off-by: Marcelo Tosatti <mtosatti@xxxxxxxxxx>
> 
> Index: kvm/arch/x86/include/asm/kvm_host.h
> ===================================================================
> --- kvm.orig/arch/x86/include/asm/kvm_host.h
> +++ kvm/arch/x86/include/asm/kvm_host.h
> @@ -1322,6 +1322,7 @@ struct kvm_x86_ops {
>  
>  	int (*update_pi_irte)(struct kvm *kvm, unsigned int host_irq,
>  			      uint32_t guest_irq, bool set);
> +	void (*start_assignment)(struct kvm *kvm);
>  	void (*apicv_post_state_restore)(struct kvm_vcpu *vcpu);
>  	bool (*dy_apicv_has_pending_interrupt)(struct kvm_vcpu *vcpu);
>  
> Index: kvm/arch/x86/kvm/svm/svm.c
> ===================================================================
> --- kvm.orig/arch/x86/kvm/svm/svm.c
> +++ kvm/arch/x86/kvm/svm/svm.c
> @@ -4601,6 +4601,7 @@ static struct kvm_x86_ops svm_x86_ops __
>  	.deliver_posted_interrupt = svm_deliver_avic_intr,
>  	.dy_apicv_has_pending_interrupt = svm_dy_apicv_has_pending_interrupt,
>  	.update_pi_irte = svm_update_pi_irte,
> +	.start_assignment = NULL,

Can this be dropped (as default NULL)?

>  	.setup_mce = svm_setup_mce,
>  
>  	.smi_allowed = svm_smi_allowed,
> Index: kvm/arch/x86/kvm/vmx/vmx.c
> ===================================================================
> --- kvm.orig/arch/x86/kvm/vmx/vmx.c
> +++ kvm/arch/x86/kvm/vmx/vmx.c
> @@ -7732,6 +7732,7 @@ static struct kvm_x86_ops vmx_x86_ops __
>  	.nested_ops = &vmx_nested_ops,
>  
>  	.update_pi_irte = pi_update_irte,
> +	.start_assignment = NULL,

Same here?

>  
>  #ifdef CONFIG_X86_64
>  	.set_hv_timer = vmx_set_hv_timer,
> Index: kvm/arch/x86/kvm/x86.c
> ===================================================================
> --- kvm.orig/arch/x86/kvm/x86.c
> +++ kvm/arch/x86/kvm/x86.c
> @@ -11295,7 +11295,11 @@ bool kvm_arch_can_dequeue_async_page_pre
>  
>  void kvm_arch_start_assignment(struct kvm *kvm)
>  {
> -	atomic_inc(&kvm->arch.assigned_device_count);
> +	int ret;
> +
> +	ret = atomic_inc_return(&kvm->arch.assigned_device_count);
> +	if (ret == 1)
> +		static_call_cond(kvm_x86_start_assignment)(kvm);

Maybe "ret" can be dropped too?

void kvm_arch_start_assignment(struct kvm *kvm)
{
	if (atomic_inc_return(&kvm->arch.assigned_device_count) == 1)
		static_call_cond(kvm_x86_start_assignment)(kvm);
}

Otherwise looks good to me.  Thanks,

-- 
Peter Xu




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux