mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eric Auger <eric.auger@redhat.com>
To: Dmytro Maluka <dmy@semihalf.com>,
	Sean Christopherson <seanjc@google.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>, Borislav Petkov <bp@alien8.de>,
	Dave Hansen <dave.hansen@linux.intel.com>,
	x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
	linux-kernel@vger.kernel.org,
	Alex Williamson <alex.williamson@redhat.com>,
	Rong L Liu <rong.l.liu@intel.com>,
	Zhenyu Wang <zhenyuw@linux.intel.com>,
	Tomasz Nowicki <tn@semihalf.com>,
	Grzegorz Jaszczyk <jaz@semihalf.com>,
	upstream@semihalf.com, Dmitry Torokhov <dtor@google.com>
Subject: Re: [PATCH v2 1/5] KVM: x86: Move irq mask notifiers from x86 to generic KVM
Date: Tue, 9 Aug 2022 22:43:41 +0200	[thread overview]
Message-ID: <9548fad8-3146-7c28-1828-bc676d2a41bc@redhat.com> (raw)
In-Reply-To: <20220805193919.1470653-2-dmy@semihalf.com>

Hi Dmytro,
On 8/5/22 21:39, Dmytro Maluka wrote:
> Currently irq mask notifiers are used only internally in the x86 code
> for PIT emulation. However they are not really arch specific. We are
> going to use them in the generic irqfd code, for postponing resampler
> irqfd notification until the interrupt is unmasked. So move the
> implementation of mask notifiers to the generic code, to allow irqfd to
> register its mask notifiers.
>
> Note that calling mask notifiers via calling kvm_fire_mask_notifiers()
> is still implemented for x86 only, so registering mask notifiers on
> other architectures will have no effect for now.
>
> Signed-off-by: Dmytro Maluka <dmy@semihalf.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>

Eric
> ---
>  arch/x86/include/asm/kvm_host.h | 16 ----------------
>  arch/x86/kvm/irq_comm.c         | 33 ---------------------------------
>  arch/x86/kvm/x86.c              |  1 -
>  include/linux/kvm_host.h        | 15 +++++++++++++++
>  virt/kvm/eventfd.c              | 33 +++++++++++++++++++++++++++++++++
>  virt/kvm/kvm_main.c             |  1 +
>  6 files changed, 49 insertions(+), 50 deletions(-)
>
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index 9217bd6cf0d1..dc76617f11c1 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -1198,9 +1198,6 @@ struct kvm_arch {
>  
>  	struct kvm_xen_hvm_config xen_hvm_config;
>  
> -	/* reads protected by irq_srcu, writes by irq_lock */
> -	struct hlist_head mask_notifier_list;
> -
>  	struct kvm_hv hyperv;
>  	struct kvm_xen xen;
>  
> @@ -1688,19 +1685,6 @@ int load_pdptrs(struct kvm_vcpu *vcpu, unsigned long cr3);
>  int emulator_write_phys(struct kvm_vcpu *vcpu, gpa_t gpa,
>  			  const void *val, int bytes);
>  
> -struct kvm_irq_mask_notifier {
> -	void (*func)(struct kvm_irq_mask_notifier *kimn, bool masked);
> -	int irq;
> -	struct hlist_node link;
> -};
> -
> -void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
> -				    struct kvm_irq_mask_notifier *kimn);
> -void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq,
> -				      struct kvm_irq_mask_notifier *kimn);
> -void kvm_fire_mask_notifiers(struct kvm *kvm, unsigned irqchip, unsigned pin,
> -			     bool mask);
> -
>  extern bool tdp_enabled;
>  
>  u64 vcpu_tsc_khz(struct kvm_vcpu *vcpu);
> diff --git a/arch/x86/kvm/irq_comm.c b/arch/x86/kvm/irq_comm.c
> index 0687162c4f22..f27e4c9c403e 100644
> --- a/arch/x86/kvm/irq_comm.c
> +++ b/arch/x86/kvm/irq_comm.c
> @@ -234,39 +234,6 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id)
>  	mutex_unlock(&kvm->irq_lock);
>  }
>  
> -void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
> -				    struct kvm_irq_mask_notifier *kimn)
> -{
> -	mutex_lock(&kvm->irq_lock);
> -	kimn->irq = irq;
> -	hlist_add_head_rcu(&kimn->link, &kvm->arch.mask_notifier_list);
> -	mutex_unlock(&kvm->irq_lock);
> -}
> -
> -void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq,
> -				      struct kvm_irq_mask_notifier *kimn)
> -{
> -	mutex_lock(&kvm->irq_lock);
> -	hlist_del_rcu(&kimn->link);
> -	mutex_unlock(&kvm->irq_lock);
> -	synchronize_srcu(&kvm->irq_srcu);
> -}
> -
> -void kvm_fire_mask_notifiers(struct kvm *kvm, unsigned irqchip, unsigned pin,
> -			     bool mask)
> -{
> -	struct kvm_irq_mask_notifier *kimn;
> -	int idx, gsi;
> -
> -	idx = srcu_read_lock(&kvm->irq_srcu);
> -	gsi = kvm_irq_map_chip_pin(kvm, irqchip, pin);
> -	if (gsi != -1)
> -		hlist_for_each_entry_rcu(kimn, &kvm->arch.mask_notifier_list, link)
> -			if (kimn->irq == gsi)
> -				kimn->func(kimn, mask);
> -	srcu_read_unlock(&kvm->irq_srcu, idx);
> -}
> -
>  bool kvm_arch_can_set_irq_routing(struct kvm *kvm)
>  {
>  	return irqchip_in_kernel(kvm);
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index e5fa335a4ea7..a0a776f5c42f 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -11818,7 +11818,6 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
>  	if (ret)
>  		goto out_page_track;
>  
> -	INIT_HLIST_HEAD(&kvm->arch.mask_notifier_list);
>  	INIT_LIST_HEAD(&kvm->arch.assigned_dev_head);
>  	atomic_set(&kvm->arch.noncoherent_dma_count, 0);
>  
> diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
> index 90a45ef7203b..dd5f14e31996 100644
> --- a/include/linux/kvm_host.h
> +++ b/include/linux/kvm_host.h
> @@ -760,7 +760,10 @@ struct kvm {
>  	struct kvm_irq_routing_table __rcu *irq_routing;
>  #endif
>  #ifdef CONFIG_HAVE_KVM_IRQFD
> +	/* reads protected by irq_srcu, writes by irq_lock */
>  	struct hlist_head irq_ack_notifier_list;
> +	/* reads protected by irq_srcu, writes by irq_lock */
> +	struct hlist_head irq_mask_notifier_list;
>  #endif
>  
>  #if defined(CONFIG_MMU_NOTIFIER) && defined(KVM_ARCH_WANT_MMU_NOTIFIER)
> @@ -1581,6 +1584,12 @@ struct kvm_irq_ack_notifier {
>  	void (*irq_acked)(struct kvm_irq_ack_notifier *kian);
>  };
>  
> +struct kvm_irq_mask_notifier {
> +	void (*func)(struct kvm_irq_mask_notifier *kimn, bool masked);
> +	int irq;
> +	struct hlist_node link;
> +};
> +
>  int kvm_irq_map_gsi(struct kvm *kvm,
>  		    struct kvm_kernel_irq_routing_entry *entries, int gsi);
>  int kvm_irq_map_chip_pin(struct kvm *kvm, unsigned irqchip, unsigned pin);
> @@ -1599,6 +1608,12 @@ void kvm_register_irq_ack_notifier(struct kvm *kvm,
>  				   struct kvm_irq_ack_notifier *kian);
>  void kvm_unregister_irq_ack_notifier(struct kvm *kvm,
>  				   struct kvm_irq_ack_notifier *kian);
> +void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
> +				    struct kvm_irq_mask_notifier *kimn);
> +void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq,
> +				      struct kvm_irq_mask_notifier *kimn);
> +void kvm_fire_mask_notifiers(struct kvm *kvm, unsigned irqchip, unsigned pin,
> +			     bool mask);
>  int kvm_request_irq_source_id(struct kvm *kvm);
>  void kvm_free_irq_source_id(struct kvm *kvm, int irq_source_id);
>  bool kvm_arch_irqfd_allowed(struct kvm *kvm, struct kvm_irqfd *args);
> diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c
> index 2a3ed401ce46..39403d9fbdcc 100644
> --- a/virt/kvm/eventfd.c
> +++ b/virt/kvm/eventfd.c
> @@ -518,6 +518,39 @@ void kvm_unregister_irq_ack_notifier(struct kvm *kvm,
>  	synchronize_srcu(&kvm->irq_srcu);
>  	kvm_arch_post_irq_ack_notifier_list_update(kvm);
>  }
> +
> +void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq,
> +				    struct kvm_irq_mask_notifier *kimn)
> +{
> +	mutex_lock(&kvm->irq_lock);
> +	kimn->irq = irq;
> +	hlist_add_head_rcu(&kimn->link, &kvm->irq_mask_notifier_list);
> +	mutex_unlock(&kvm->irq_lock);
> +}
> +
> +void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq,
> +				      struct kvm_irq_mask_notifier *kimn)
> +{
> +	mutex_lock(&kvm->irq_lock);
> +	hlist_del_rcu(&kimn->link);
> +	mutex_unlock(&kvm->irq_lock);
> +	synchronize_srcu(&kvm->irq_srcu);
> +}
> +
> +void kvm_fire_mask_notifiers(struct kvm *kvm, unsigned irqchip, unsigned pin,
> +			     bool mask)
> +{
> +	struct kvm_irq_mask_notifier *kimn;
> +	int idx, gsi;
> +
> +	idx = srcu_read_lock(&kvm->irq_srcu);
> +	gsi = kvm_irq_map_chip_pin(kvm, irqchip, pin);
> +	if (gsi != -1)
> +		hlist_for_each_entry_rcu(kimn, &kvm->irq_mask_notifier_list, link)
> +			if (kimn->irq == gsi)
> +				kimn->func(kimn, mask);
> +	srcu_read_unlock(&kvm->irq_srcu, idx);
> +}
>  #endif
>  
>  void
> diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
> index a49df8988cd6..5ca7fb0b8257 100644
> --- a/virt/kvm/kvm_main.c
> +++ b/virt/kvm/kvm_main.c
> @@ -1144,6 +1144,7 @@ static struct kvm *kvm_create_vm(unsigned long type)
>  
>  #ifdef CONFIG_HAVE_KVM_IRQFD
>  	INIT_HLIST_HEAD(&kvm->irq_ack_notifier_list);
> +	INIT_HLIST_HEAD(&kvm->irq_mask_notifier_list);
>  #endif
>  
>  	r = kvm_init_mmu_notifier(kvm);


  reply	other threads:[~2022-08-09 20:43 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-05 19:39 [PATCH v2 0/5] KVM: Fix oneshot interrupts forwarding Dmytro Maluka
2022-08-05 19:39 ` [PATCH v2 1/5] KVM: x86: Move irq mask notifiers from x86 to generic KVM Dmytro Maluka
2022-08-09 20:43   ` Eric Auger [this message]
2022-08-05 19:39 ` [PATCH v2 2/5] KVM: x86: Add kvm_register_and_fire_irq_mask_notifier() Dmytro Maluka
2022-08-09 20:43   ` Eric Auger
2022-08-09 23:56     ` Dmytro Maluka
2022-08-05 19:39 ` [PATCH v2 3/5] KVM: irqfd: Postpone resamplefd notify for oneshot interrupts Dmytro Maluka
2022-08-09 20:45   ` Eric Auger
2022-08-09 23:57     ` Dmytro Maluka
2022-08-10  8:41     ` Marc Zyngier
2022-08-05 19:39 ` [PATCH v2 4/5] KVM: irqfd: Rename resampler->notifier Dmytro Maluka
2022-08-09 20:46   ` Eric Auger
2022-08-05 19:39 ` [PATCH v2 5/5] KVM: Rename kvm_irq_has_notifier() Dmytro Maluka
2022-08-08 23:26 ` [PATCH v2 0/5] KVM: Fix oneshot interrupts forwarding Dong, Eddie
2022-08-09  7:24   ` Dmytro Maluka
2022-08-09 20:01     ` Dong, Eddie
2022-08-09 23:30       ` Dmytro Maluka
2022-08-10  6:51         ` Marc Zyngier
2022-08-10  8:12           ` Eric Auger
2022-08-10 13:01             ` Marc Zyngier
2022-08-10 17:02               ` Dmytro Maluka
2022-08-11  6:48                 ` Paolo Bonzini
2022-08-11 22:40                   ` Liu, Rong L
2022-08-13 14:04                     ` Dmytro Maluka
2022-08-11 12:21                 ` Marc Zyngier
2022-08-11 13:54                   ` Dmytro Maluka
2022-08-13 12:59                     ` Dmytro Maluka
2022-08-10 17:06           ` Dmytro Maluka
2022-08-11 12:35             ` Marc Zyngier
2022-08-11 13:04               ` Dmytro Maluka
2022-08-10 17:17         ` Dong, Eddie
2022-08-10 17:34           ` Dmytro Maluka
2022-08-10 17:53             ` Dong, Eddie

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=9548fad8-3146-7c28-1828-bc676d2a41bc@redhat.com \
    --to=eric.auger@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=bp@alien8.de \
    --cc=dave.hansen@linux.intel.com \
    --cc=dmy@semihalf.com \
    --cc=dtor@google.com \
    --cc=hpa@zytor.com \
    --cc=jaz@semihalf.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=rong.l.liu@intel.com \
    --cc=seanjc@google.com \
    --cc=tglx@linutronix.de \
    --cc=tn@semihalf.com \
    --cc=upstream@semihalf.com \
    --cc=x86@kernel.org \
    --cc=zhenyuw@linux.intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®