From nobody Sun Feb 8 10:25:51 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A53EC25B08 for ; Fri, 5 Aug 2022 19:41:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241421AbiHETk6 (ORCPT ); Fri, 5 Aug 2022 15:40:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241443AbiHETky (ORCPT ); Fri, 5 Aug 2022 15:40:54 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E86311805 for ; Fri, 5 Aug 2022 12:40:53 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id c17so4775160lfb.3 for ; Fri, 05 Aug 2022 12:40:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=0bqeAVxOv1cvt506AIyaShQcLeSdfwwBjFLTn7gNzK4=; b=f+F1IOVIZjUPQzuXQjLojG+pXD/2sSikKxH++DYAxDArMLZIaUoZP8lbDkzAlcjMUE 3W1VS4h7HTzzTgV8Rsi/LHB//SqzkqQmMnYRFk+p6ziWmHaNhHKVonZ9XA3/AE4MwK9I RajpOltnDRXaQ71wGyWRXMWHkU3GeLbwsqgBIKwzfTf41/bYJGWldMdHFUc2Pj1ml54W Ct6J49rpys0VfRvRk2Y6jZ95BcFSOOONBGH9pE/h/2FpmdEh6vH3BckAFsVmkP8CT4mB VfTaB4xrqr7TKe5Zv+rWY706d7g9ZLpEJL6Q7hBB2/gtLGPEpL+GsgEkfiIjln+JgsL9 dsIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=0bqeAVxOv1cvt506AIyaShQcLeSdfwwBjFLTn7gNzK4=; b=WSjXRtT1DT6pEWms0Aqki9VuXBRmJ6Q23fL4rTtiqFss/HanzqRfDFv+Y+a5ogR+J6 yU2KG8boY4UyaEfjy9En98hvYMazoKEGLt+/8PATF5DTfM69S8rVottCPmVNOGrWEY7z LTWTz7zflU0i/NVFzLc6fgn9xsbVhmEhErvSlFeTvj8Cz3TBdxcoldLoR4kwOdK2o91a GFK6P1ECgIgn0WdOKsSounPKYmMwcIEcMAGw+/sKjpuCJVSyE2yyVNEYvnHU8yF34aWa 3eY6ZwvEaGw10F+8vwQSHrZTSu3Y41LY1gbU36Az6WRFiMjxSZ/Qz5CFyqbRYnN/JW2u JmVQ== X-Gm-Message-State: ACgBeo2Sk2pmcL88lPg4rRmzzNFP/5USRG9a8nx88EbqJrYbDFWJ0ln1 S2wkPPQm159nzdI6rJukgwevdA== X-Google-Smtp-Source: AA6agR76FJBZdHn7btHunKBLYS4zn4FmHKBrHNCN2JU1T8z3s5vYHmzhIOcyrYHULuYztfgrwHMXQg== X-Received: by 2002:a05:6512:1283:b0:48b:9817:ce2b with SMTP id u3-20020a056512128300b0048b9817ce2bmr206194lfs.417.1659728451592; Fri, 05 Aug 2022 12:40:51 -0700 (PDT) Received: from dmaluka.office.semihalf.net ([83.142.187.84]) by smtp.gmail.com with ESMTPSA id o4-20020a056512230400b0048a407f41bbsm560079lfu.238.2022.08.05.12.40.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 12:40:51 -0700 (PDT) From: Dmytro Maluka To: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, Eric Auger , Alex Williamson , Rong L Liu , Zhenyu Wang , Tomasz Nowicki , Grzegorz Jaszczyk , upstream@semihalf.com, Dmitry Torokhov , Dmytro Maluka Subject: [PATCH v2 1/5] KVM: x86: Move irq mask notifiers from x86 to generic KVM Date: Fri, 5 Aug 2022 21:39:15 +0200 Message-Id: <20220805193919.1470653-2-dmy@semihalf.com> X-Mailer: git-send-email 2.37.1.559.g78731f0fdb-goog In-Reply-To: <20220805193919.1470653-1-dmy@semihalf.com> References: <20220805193919.1470653-1-dmy@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Reviewed-by: Eric Auger --- 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_hos= t.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 { =20 struct kvm_xen_hvm_config xen_hvm_config; =20 - /* reads protected by irq_srcu, writes by irq_lock */ - struct hlist_head mask_notifier_list; - struct kvm_hv hyperv; struct kvm_xen xen; =20 @@ -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); =20 -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 p= in, - bool mask); - extern bool tdp_enabled; =20 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_s= ource_id) mutex_unlock(&kvm->irq_lock); } =20 -void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq, - struct kvm_irq_mask_notifier *kimn) -{ - mutex_lock(&kvm->irq_lock); - kimn->irq =3D 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 p= in, - bool mask) -{ - struct kvm_irq_mask_notifier *kimn; - int idx, gsi; - - idx =3D srcu_read_lock(&kvm->irq_srcu); - gsi =3D kvm_irq_map_chip_pin(kvm, irqchip, pin); - if (gsi !=3D -1) - hlist_for_each_entry_rcu(kimn, &kvm->arch.mask_notifier_list, link) - if (kimn->irq =3D=3D 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; =20 - INIT_HLIST_HEAD(&kvm->arch.mask_notifier_list); INIT_LIST_HEAD(&kvm->arch.assigned_dev_head); atomic_set(&kvm->arch.noncoherent_dma_count, 0); =20 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 =20 #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); }; =20 +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 p= in, + 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 =3D 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 p= in, + bool mask) +{ + struct kvm_irq_mask_notifier *kimn; + int idx, gsi; + + idx =3D srcu_read_lock(&kvm->irq_srcu); + gsi =3D kvm_irq_map_chip_pin(kvm, irqchip, pin); + if (gsi !=3D -1) + hlist_for_each_entry_rcu(kimn, &kvm->irq_mask_notifier_list, link) + if (kimn->irq =3D=3D gsi) + kimn->func(kimn, mask); + srcu_read_unlock(&kvm->irq_srcu, idx); +} #endif =20 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) =20 #ifdef CONFIG_HAVE_KVM_IRQFD INIT_HLIST_HEAD(&kvm->irq_ack_notifier_list); + INIT_HLIST_HEAD(&kvm->irq_mask_notifier_list); #endif =20 r =3D kvm_init_mmu_notifier(kvm); --=20 2.37.1.559.g78731f0fdb-goog From nobody Sun Feb 8 10:25:51 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF0BFC25B08 for ; Fri, 5 Aug 2022 19:41:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241523AbiHETlG (ORCPT ); Fri, 5 Aug 2022 15:41:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241443AbiHETk7 (ORCPT ); Fri, 5 Aug 2022 15:40:59 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C11ED1180C for ; Fri, 5 Aug 2022 12:40:57 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id t1so4746870lft.8 for ; Fri, 05 Aug 2022 12:40:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=nWaiwEI17OMw/TfJNVGmv/dCiVpBuOpVxD5/Elxo9ZY=; b=bcIJTvqBYZIXumQuAeUKwNbrukb240x21rG74i0uII/e0CV/muhEriUE8e5APdlcu1 a5GwEXC3HxXKvTZm+GRT8f6DKoTA+0zEVWr/sTKB5STRoWIDFkWsTIXa76dLIayHjypN V7WA5ZUitV9Saigaa1ydSERvON1rw9+cRswhUR/cs3rH5NhlZpi5pyuTa9KjpTu8jlM5 YOCgqjv6Refivmq3GCE9OjPmS/aZRbCOArL+x6lvV3dViP2R3C1hflaHR27z9aWgH/Y3 Qa5oZYo2DbIOhK3U9ENvtceZ6qmV3VENG0f1L305xD7BjTkzxWq5hri+xu4M7FuUiMNm iJhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=nWaiwEI17OMw/TfJNVGmv/dCiVpBuOpVxD5/Elxo9ZY=; b=FWD38YQLvv8Ov2hRsn4fsxPYm2JOOZC2dk63lGeGqpavu3+S2UY+k63Em0ZiKOzxxX 0Q6gnkG5jtpr/Bv7SwNHCdGx2FwIlhhJQdi44ytvRBqBAE+90AkTTLVuSf+rXpec1CIf 3e4uJ5bN6SoMJ1EQlldkQ/YnoF4qAZJNXNJiB66HfM4h5sYRX8yCK7RIGwLSzUZxzBEu h5V6hKA44nSXdsyQBKAlXbIOBGWahRdJ99R5J45eAFqfPdZgjkDlikNKCE8aBc14f9fI T9Wys48A4D5qr5y8rGcTccLgv+aynPkJAkLA7oyUClgZ7+YaHNPSZ+Bc0MsLh+wzodV7 QUjQ== X-Gm-Message-State: ACgBeo0pxf93wQCqDHt2qVwtk4LoHDuaj2SKD+xFHb8i/UsT9zLopU+k BuJPYvSi7+rd3d3wLl+74mJLlg== X-Google-Smtp-Source: AA6agR5gx7Y1iJApwmxSXkrH2vMRjDQXL4qFLv5d1ot2fsQCeod87KU3DUrlSYADuz7ysT+9I3odYA== X-Received: by 2002:a05:6512:1c5:b0:48b:192:a29e with SMTP id f5-20020a05651201c500b0048b0192a29emr2564462lfp.250.1659728456050; Fri, 05 Aug 2022 12:40:56 -0700 (PDT) Received: from dmaluka.office.semihalf.net ([83.142.187.84]) by smtp.gmail.com with ESMTPSA id o4-20020a056512230400b0048a407f41bbsm560079lfu.238.2022.08.05.12.40.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 12:40:55 -0700 (PDT) From: Dmytro Maluka To: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, Eric Auger , Alex Williamson , Rong L Liu , Zhenyu Wang , Tomasz Nowicki , Grzegorz Jaszczyk , upstream@semihalf.com, Dmitry Torokhov , Dmytro Maluka Subject: [PATCH v2 2/5] KVM: x86: Add kvm_register_and_fire_irq_mask_notifier() Date: Fri, 5 Aug 2022 21:39:16 +0200 Message-Id: <20220805193919.1470653-3-dmy@semihalf.com> X-Mailer: git-send-email 2.37.1.559.g78731f0fdb-goog In-Reply-To: <20220805193919.1470653-1-dmy@semihalf.com> References: <20220805193919.1470653-1-dmy@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In order to implement postponing resamplefd notification until an interrupt is unmasked, we need not only to track changes of the interrupt mask state (which is already possible with kvm_register_irq_mask_notifier()) but also to know its initial mask state before any mask notifier has fired. Moreover, we need to do this initial check of the IRQ mask state in a race-free way, to ensure that we will not miss any further mask or unmask events after we check the initial mask state. So implement kvm_register_and_fire_irq_mask_notifier() which atomically registers an IRQ mask notifier and calls it with the current mask value of the IRQ. It does that using the same locking order as when calling notifier normally via kvm_fire_mask_notifiers(), to prevent deadlocks. Its implementation needs to be arch-specific since it relies on arch-specific synchronization (e.g. ioapic->lock and pic->lock on x86, or a per-IRQ lock on ARM vGIC) for serializing our initial reading of the IRQ mask state with a pending change of this mask state. For now implement it for x86 only, and for other archs add a weak dummy implementation which doesn't really call the notifier (as other archs don't currently implement calling notifiers normally via kvm_fire_mask_notifiers() either, i.e. registering mask notifiers has no effect on those archs anyway). Signed-off-by: Dmytro Maluka Link: https://lore.kernel.org/lkml/c7b7860e-ae3a-7b98-e97e-28a62470c470@sem= ihalf.com/ --- arch/x86/include/asm/kvm_host.h | 1 + arch/x86/kvm/i8259.c | 6 ++++ arch/x86/kvm/ioapic.c | 6 ++++ arch/x86/kvm/ioapic.h | 1 + arch/x86/kvm/irq_comm.c | 57 +++++++++++++++++++++++++++++++++ include/linux/kvm_host.h | 4 +++ virt/kvm/eventfd.c | 31 ++++++++++++++++-- 7 files changed, 104 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_hos= t.h index dc76617f11c1..cf0571ed2968 100644 --- a/arch/x86/include/asm/kvm_host.h +++ b/arch/x86/include/asm/kvm_host.h @@ -1834,6 +1834,7 @@ static inline int __kvm_irq_line_state(unsigned long = *irq_state, =20 int kvm_pic_set_irq(struct kvm_pic *pic, int irq, int irq_source_id, int l= evel); void kvm_pic_clear_all(struct kvm_pic *pic, int irq_source_id); +bool kvm_pic_irq_is_masked(struct kvm_pic *s, int irq); =20 void kvm_inject_nmi(struct kvm_vcpu *vcpu); =20 diff --git a/arch/x86/kvm/i8259.c b/arch/x86/kvm/i8259.c index e1bb6218bb96..1eb3127f6047 100644 --- a/arch/x86/kvm/i8259.c +++ b/arch/x86/kvm/i8259.c @@ -211,6 +211,12 @@ void kvm_pic_clear_all(struct kvm_pic *s, int irq_sour= ce_id) pic_unlock(s); } =20 +/* Called with s->lock held. */ +bool kvm_pic_irq_is_masked(struct kvm_pic *s, int irq) +{ + return !!(s->pics[irq >> 3].imr & (1 << irq)); +} + /* * acknowledge interrupt 'irq' */ diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c index 765943d7cfa5..fab11de1f885 100644 --- a/arch/x86/kvm/ioapic.c +++ b/arch/x86/kvm/ioapic.c @@ -478,6 +478,12 @@ void kvm_ioapic_clear_all(struct kvm_ioapic *ioapic, i= nt irq_source_id) spin_unlock(&ioapic->lock); } =20 +/* Called with ioapic->lock held. */ +bool kvm_ioapic_irq_is_masked(struct kvm_ioapic *ioapic, int irq) +{ + return !!ioapic->redirtbl[irq].fields.mask; +} + static void kvm_ioapic_eoi_inject_work(struct work_struct *work) { int i; diff --git a/arch/x86/kvm/ioapic.h b/arch/x86/kvm/ioapic.h index 539333ac4b38..fe1f51319992 100644 --- a/arch/x86/kvm/ioapic.h +++ b/arch/x86/kvm/ioapic.h @@ -114,6 +114,7 @@ void kvm_ioapic_destroy(struct kvm *kvm); int kvm_ioapic_set_irq(struct kvm_ioapic *ioapic, int irq, int irq_source_= id, int level, bool line_status); void kvm_ioapic_clear_all(struct kvm_ioapic *ioapic, int irq_source_id); +bool kvm_ioapic_irq_is_masked(struct kvm_ioapic *ioapic, int irq); void kvm_get_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state); void kvm_set_ioapic(struct kvm *kvm, struct kvm_ioapic_state *state); void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, diff --git a/arch/x86/kvm/irq_comm.c b/arch/x86/kvm/irq_comm.c index f27e4c9c403e..4bd4218821a2 100644 --- a/arch/x86/kvm/irq_comm.c +++ b/arch/x86/kvm/irq_comm.c @@ -234,6 +234,63 @@ void kvm_free_irq_source_id(struct kvm *kvm, int irq_s= ource_id) mutex_unlock(&kvm->irq_lock); } =20 +void kvm_register_and_fire_irq_mask_notifier(struct kvm *kvm, int irq, + struct kvm_irq_mask_notifier *kimn) +{ + struct kvm_pic *pic =3D kvm->arch.vpic; + struct kvm_ioapic *ioapic =3D kvm->arch.vioapic; + struct kvm_kernel_irq_routing_entry entries[KVM_NR_IRQCHIPS]; + struct kvm_kernel_irq_routing_entry *pic_e =3D NULL, *ioapic_e =3D NULL; + int idx, i, n; + bool masked; + + mutex_lock(&kvm->irq_lock); + + /* + * Not possible to detect if the guest uses the PIC or the + * IOAPIC. So assume the interrupt to be unmasked iff it is + * unmasked in at least one of both. + */ + idx =3D srcu_read_lock(&kvm->irq_srcu); + n =3D kvm_irq_map_gsi(kvm, entries, irq); + srcu_read_unlock(&kvm->irq_srcu, idx); + + for (i =3D 0; i < n; i++) { + if (entries[i].type !=3D KVM_IRQ_ROUTING_IRQCHIP) + continue; + + switch (entries[i].irqchip.irqchip) { + case KVM_IRQCHIP_PIC_MASTER: + case KVM_IRQCHIP_PIC_SLAVE: + pic_e =3D &entries[i]; + break; + case KVM_IRQCHIP_IOAPIC: + ioapic_e =3D &entries[i]; + break; + default: + break; + } + } + + if (pic_e) + spin_lock(&pic->lock); + if (ioapic_e) + spin_lock(&ioapic->lock); + + __kvm_register_irq_mask_notifier(kvm, irq, kimn); + + masked =3D (!pic_e || kvm_pic_irq_is_masked(pic, pic_e->irqchip.pin)) && + (!ioapic_e || kvm_ioapic_irq_is_masked(ioapic, ioapic_e->irqchip.pin)); + kimn->func(kimn, masked); + + if (ioapic_e) + spin_unlock(&ioapic->lock); + if (pic_e) + spin_unlock(&pic->lock); + + mutex_unlock(&kvm->irq_lock); +} + bool kvm_arch_can_set_irq_routing(struct kvm *kvm) { return irqchip_in_kernel(kvm); diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index dd5f14e31996..55233eb18eb4 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1608,8 +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_register_irq_mask_notifier(struct kvm *kvm, int irq, struct kvm_irq_mask_notifier *kimn); +void kvm_register_and_fire_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 p= in, diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c index 39403d9fbdcc..3007d956b626 100644 --- a/virt/kvm/eventfd.c +++ b/virt/kvm/eventfd.c @@ -519,15 +519,42 @@ void kvm_unregister_irq_ack_notifier(struct kvm *kvm, kvm_arch_post_irq_ack_notifier_list_update(kvm); } =20 +void __kvm_register_irq_mask_notifier(struct kvm *kvm, int irq, + struct kvm_irq_mask_notifier *kimn) +{ + kimn->irq =3D irq; + hlist_add_head_rcu(&kimn->link, &kvm->irq_mask_notifier_list); +} + void kvm_register_irq_mask_notifier(struct kvm *kvm, int irq, struct kvm_irq_mask_notifier *kimn) { mutex_lock(&kvm->irq_lock); - kimn->irq =3D irq; - hlist_add_head_rcu(&kimn->link, &kvm->irq_mask_notifier_list); + __kvm_register_irq_mask_notifier(kvm, irq, kimn); mutex_unlock(&kvm->irq_lock); } =20 +/* + * kvm_register_and_fire_irq_mask_notifier() registers the notifier and + * immediately calls it with the current mask value of the IRQ. It does + * that atomically, so that we will find out the initial mask state of + * the IRQ and will not miss any further mask or unmask events. It does + * that using the same locking order as when calling notifier normally + * via kvm_fire_mask_notifiers(), to prevent deadlocks. + * + * Implementation is arch-specific since it relies on arch-specific + * (irqchip-specific) synchronization. Below is a weak dummy + * implementation for archs not implementing it yet, as those archs + * don't implement calling notifiers normally via + * kvm_fire_mask_notifiers() either, i.e. registering mask notifiers + * has no effect on those archs anyway. + */ +void __weak kvm_register_and_fire_irq_mask_notifier(struct kvm *kvm, int i= rq, + struct kvm_irq_mask_notifier *kimn) +{ + kvm_register_irq_mask_notifier(kvm, irq, kimn); +} + void kvm_unregister_irq_mask_notifier(struct kvm *kvm, int irq, struct kvm_irq_mask_notifier *kimn) { --=20 2.37.1.559.g78731f0fdb-goog From nobody Sun Feb 8 10:25:51 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D98C3C25B07 for ; Fri, 5 Aug 2022 19:41:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241543AbiHETlL (ORCPT ); Fri, 5 Aug 2022 15:41:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233910AbiHETlE (ORCPT ); Fri, 5 Aug 2022 15:41:04 -0400 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A895812082 for ; Fri, 5 Aug 2022 12:41:00 -0700 (PDT) Received: by mail-lj1-x235.google.com with SMTP id x9so371064ljj.13 for ; Fri, 05 Aug 2022 12:41:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=KTuJSUaPvckI9Du4XAT5/wpgO5DYS6U+2V/PvzUapCc=; b=CnJP4zP5dxdWpRg2Pn2/r4br7GsKboh8QQ1SzrfQDPTHTZLnbpuf857jTuK05cwmlM aoiuuWjlK7uTfVZTy1kAGq3G4EYZkxBCWC6SlQ/Lb5jdpT4bs4nzpHH/3w7TBdKMoRA1 EItbyj2WI2l9c/L82DRkfhi0NDYfNgaGYYZU6ZhjBtUzBMm36HzG5DvbaPW68YpL/dNg DZsfDJNjpt0d2X8CbtGfSuFGAp7SEYxrI8wwiRs33Bg9qRNWm7Fspv1TBeEHGfZCqF6P tKTb9PvAaVdznRakJVqmTeZs9wVt9c8JucS67lLgE73rfL1sPF3imCUUSzJjM1WbImC0 0eXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=KTuJSUaPvckI9Du4XAT5/wpgO5DYS6U+2V/PvzUapCc=; b=K6vRiDwXnYWrWgTYEG1U+gaxeW2udtdoOZJ7bpXUh/Kgqr4U/5xt7Lt+5S30BHMsED xlQ1ivokUbTHPP67/b3JskH/aEGsCqxKfTyUPqLczpYgpgbEPOLpeDW4wL5k4DrCeV5a zbFhyB61e+cLHV/UO+RShUkCAAZHW36/MMWTXbEqFp05+l5KRTELSPDRDr0L9RMNttd1 nocOE+9QoMLFIa+yegBikKCYNsjZsaDBgl/NP51VIZF0csYIQpW9doSsFgezbz42r+QR sdJdDMmUojBYg7yqMf3nUuMHUUPBcCFpyFhpX10l1Eu2/R2BCxSWTB0yyGHQ4xq1SK6J iZyA== X-Gm-Message-State: ACgBeo2/QDaPYfMTb0QS/XFBY6KJ6x8GKl57/UnJpSAkumFIM0g61Olz nNakSKGg5ngcTAcxkmCPalOinQ== X-Google-Smtp-Source: AA6agR69s8eoV5hHBU1LiQJAtqO6q5LZae6rZH8W2t0RuMBzRYMAMHkPGRJo7i23KUn3+X13EWn9cw== X-Received: by 2002:a2e:a410:0:b0:25e:4bca:6287 with SMTP id p16-20020a2ea410000000b0025e4bca6287mr2568965ljn.31.1659728458667; Fri, 05 Aug 2022 12:40:58 -0700 (PDT) Received: from dmaluka.office.semihalf.net ([83.142.187.84]) by smtp.gmail.com with ESMTPSA id o4-20020a056512230400b0048a407f41bbsm560079lfu.238.2022.08.05.12.40.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 12:40:58 -0700 (PDT) From: Dmytro Maluka To: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, Eric Auger , Alex Williamson , Rong L Liu , Zhenyu Wang , Tomasz Nowicki , Grzegorz Jaszczyk , upstream@semihalf.com, Dmitry Torokhov , Dmytro Maluka Subject: [PATCH v2 3/5] KVM: irqfd: Postpone resamplefd notify for oneshot interrupts Date: Fri, 5 Aug 2022 21:39:17 +0200 Message-Id: <20220805193919.1470653-4-dmy@semihalf.com> X-Mailer: git-send-email 2.37.1.559.g78731f0fdb-goog In-Reply-To: <20220805193919.1470653-1-dmy@semihalf.com> References: <20220805193919.1470653-1-dmy@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The existing KVM mechanism for forwarding of level-triggered interrupts using resample eventfd doesn't work quite correctly in the case of interrupts that are handled in a Linux guest as oneshot interrupts (IRQF_ONESHOT). Such an interrupt is acked to the device in its threaded irq handler, i.e. later than it is acked to the interrupt controller (EOI at the end of hardirq), not earlier. Linux keeps such interrupt masked until its threaded handler finishes, to prevent the EOI from re-asserting an unacknowledged interrupt. However, with KVM + vfio (or whatever is listening on the resamplefd) we don't check that the interrupt is still masked in the guest at the moment of EOI. Resamplefd is notified regardless, so vfio prematurely unmasks the host physical IRQ, thus a new (unwanted) physical interrupt is generated in the host and queued for injection to the guest. The fact that the virtual IRQ is still masked doesn't prevent this new physical IRQ from being propagated to the guest, because: 1. It is not guaranteed that the vIRQ will remain masked by the time when vfio signals the trigger eventfd. 2. KVM marks this IRQ as pending (e.g. setting its bit in the virtual IRR register of IOAPIC on x86), so after the vIRQ is unmasked, this new pending interrupt is injected by KVM to the guest anyway. There are observed at least 2 user-visible issues caused by those extra erroneous pending interrupts for oneshot irq in the guest: 1. System suspend aborted due to a pending wakeup interrupt from ChromeOS EC (drivers/platform/chrome/cros_ec.c). 2. Annoying "invalid report id data" errors from ELAN0000 touchpad (drivers/input/mouse/elan_i2c_core.c), flooding the guest dmesg every time the touchpad is touched. This patch fixes the issue on x86 by checking if the interrupt is unmasked when we receive irq ack (EOI) and, in case if it's masked, postponing resamplefd notify until the guest unmasks it. It doesn't fix the issue for other archs yet, since it relies on KVM irq mask notifiers functionality which currently works only on x86. On other archs we can register mask notifiers but they are never called. So on other archs resampler->masked is always false, so the behavior is the same as before this patch. Link: https://lore.kernel.org/kvm/31420943-8c5f-125c-a5ee-d2fde2700083@semi= half.com/ Suggested-by: Sean Christopherson Signed-off-by: Dmytro Maluka --- include/linux/kvm_irqfd.h | 14 ++++++++++ virt/kvm/eventfd.c | 56 +++++++++++++++++++++++++++++++++++---- 2 files changed, 65 insertions(+), 5 deletions(-) diff --git a/include/linux/kvm_irqfd.h b/include/linux/kvm_irqfd.h index dac047abdba7..01754a1abb9e 100644 --- a/include/linux/kvm_irqfd.h +++ b/include/linux/kvm_irqfd.h @@ -19,6 +19,16 @@ * resamplefd. All resamplers on the same gsi are de-asserted * together, so we don't need to track the state of each individual * user. We can also therefore share the same irq source ID. + * + * A special case is when the interrupt is still masked at the moment + * an irq ack is received. That likely means that the interrupt has + * been acknowledged to the interrupt controller but not acknowledged + * to the device yet, e.g. it might be a Linux guest's threaded + * oneshot interrupt (IRQF_ONESHOT). In this case notifying through + * resamplefd is postponed until the guest unmasks the interrupt, + * which is detected through the irq mask notifier. This prevents + * erroneous extra interrupts caused by premature re-assert of an + * unacknowledged interrupt by the resamplefd listener. */ struct kvm_kernel_irqfd_resampler { struct kvm *kvm; @@ -28,6 +38,10 @@ struct kvm_kernel_irqfd_resampler { */ struct list_head list; struct kvm_irq_ack_notifier notifier; + struct kvm_irq_mask_notifier mask_notifier; + bool masked; + bool pending; + spinlock_t lock; /* * Entry in list of kvm->irqfd.resampler_list. Use for sharing * resamplers among irqfds on the same gsi. diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c index 3007d956b626..f98dcce3959c 100644 --- a/virt/kvm/eventfd.c +++ b/virt/kvm/eventfd.c @@ -67,6 +67,7 @@ irqfd_resampler_ack(struct kvm_irq_ack_notifier *kian) struct kvm *kvm; struct kvm_kernel_irqfd *irqfd; int idx; + bool notify =3D true; =20 resampler =3D container_of(kian, struct kvm_kernel_irqfd_resampler, notifier); @@ -75,13 +76,52 @@ irqfd_resampler_ack(struct kvm_irq_ack_notifier *kian) kvm_set_irq(kvm, KVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID, resampler->notifier.gsi, 0, false); =20 - idx =3D srcu_read_lock(&kvm->irq_srcu); + spin_lock(&resampler->lock); + if (resampler->masked) { + notify =3D false; + resampler->pending =3D true; + } + spin_unlock(&resampler->lock); + + if (notify) { + idx =3D srcu_read_lock(&kvm->irq_srcu); =20 - list_for_each_entry_srcu(irqfd, &resampler->list, resampler_link, - srcu_read_lock_held(&kvm->irq_srcu)) - eventfd_signal(irqfd->resamplefd, 1); + list_for_each_entry_srcu(irqfd, &resampler->list, resampler_link, + srcu_read_lock_held(&kvm->irq_srcu)) + eventfd_signal(irqfd->resamplefd, 1); =20 - srcu_read_unlock(&kvm->irq_srcu, idx); + srcu_read_unlock(&kvm->irq_srcu, idx); + } +} + +static void irqfd_resampler_mask_notify(struct kvm_irq_mask_notifier *kimn, + bool masked) +{ + struct kvm_kernel_irqfd_resampler *resampler; + struct kvm *kvm; + struct kvm_kernel_irqfd *irqfd; + int idx; + bool notify; + + resampler =3D container_of(kimn, + struct kvm_kernel_irqfd_resampler, mask_notifier); + kvm =3D resampler->kvm; + + spin_lock(&resampler->lock); + notify =3D !masked && resampler->pending; + resampler->masked =3D masked; + resampler->pending =3D false; + spin_unlock(&resampler->lock); + + if (notify) { + idx =3D srcu_read_lock(&kvm->irq_srcu); + + list_for_each_entry_srcu(irqfd, &resampler->list, resampler_link, + srcu_read_lock_held(&kvm->irq_srcu)) + eventfd_signal(irqfd->resamplefd, 1); + + srcu_read_unlock(&kvm->irq_srcu, idx); + } } =20 static void @@ -98,6 +138,8 @@ irqfd_resampler_shutdown(struct kvm_kernel_irqfd *irqfd) if (list_empty(&resampler->list)) { list_del(&resampler->link); kvm_unregister_irq_ack_notifier(kvm, &resampler->notifier); + kvm_unregister_irq_mask_notifier(kvm, resampler->mask_notifier.irq, + &resampler->mask_notifier); kvm_set_irq(kvm, KVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID, resampler->notifier.gsi, 0, false); kfree(resampler); @@ -367,9 +409,13 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *ar= gs) INIT_LIST_HEAD(&resampler->list); resampler->notifier.gsi =3D irqfd->gsi; resampler->notifier.irq_acked =3D irqfd_resampler_ack; + resampler->mask_notifier.func =3D irqfd_resampler_mask_notify; + spin_lock_init(&resampler->lock); INIT_LIST_HEAD(&resampler->link); =20 list_add(&resampler->link, &kvm->irqfds.resampler_list); + kvm_register_and_fire_irq_mask_notifier(kvm, irqfd->gsi, + &resampler->mask_notifier); kvm_register_irq_ack_notifier(kvm, &resampler->notifier); irqfd->resampler =3D resampler; --=20 2.37.1.559.g78731f0fdb-goog From nobody Sun Feb 8 10:25:51 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 781BCC00140 for ; Fri, 5 Aug 2022 19:41:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241552AbiHETlO (ORCPT ); Fri, 5 Aug 2022 15:41:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50820 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241493AbiHETlF (ORCPT ); Fri, 5 Aug 2022 15:41:05 -0400 Received: from mail-lj1-x22d.google.com (mail-lj1-x22d.google.com [IPv6:2a00:1450:4864:20::22d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B749012636 for ; Fri, 5 Aug 2022 12:41:02 -0700 (PDT) Received: by mail-lj1-x22d.google.com with SMTP id s9so4056909ljs.6 for ; Fri, 05 Aug 2022 12:41:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=fJt+8ihDsvIqc3+fCTYKstbstOdW0KiHTWXF75LAIsc=; b=LwND4vNWX5iBHrLIpe8UPID7KoTe+AGnxN9IU0iE3UvNUsAAgXJOu+KcUIzZ0whOm9 MZUNqD8fDTdAo60iPWNNaZyzj+vXPwy8Mkz/ewUOfecAIJd5XVgaLk/rF0wVEY8nFtzX CJaKdVUBF0P2HoeoFFVq2tex2aZtQ1b+2mjSnP13bGPHhKSZOqyF9IdQhbAExAie8F+m AR23t1DeeYSHSqus3bgD6MgrKtMiCNEtpdlCUfBZyEjEuAkS/Rd06BabXuWAAG2QZd5T 61zTI5xXk5GWFPvVqydP/d+pdw562Ducic0q5xO0Z9ytEI6f2TXWNkLWqj8G73HAdnFI ODoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=fJt+8ihDsvIqc3+fCTYKstbstOdW0KiHTWXF75LAIsc=; b=aWFT4jTed9cImcFQk1A4vB0oLa5Ulf5XryZXUWMVqEz+zC2+NQctwmeVYOTF0uscdp DvB0uQilw213hM74k6Su1du6RSmqnhk8N6wkinU3f/t37tGgbpbi6v3OD82KSAPrTJDS kdQ9HBa/EAcSE2/FFTyB1RTGH/MkL/meqP9eWR4rY2yjkkcgv4qbQGEVQCobh2iOss/R mVbNJ9cTLAgO47j/29LI0X6sQQSCNEPwBhFRaLg/w6jzARPdENs4tA08QRpI2eJNpSvR rgDaeoHtxuJr62KlIn5wihQ3nINvGxiaswGjcm7+FnNQfEv+E532RTybOBQxtU8DARj2 dBTg== X-Gm-Message-State: ACgBeo0AypatCtmlT655oLs/mp8Pk+JluggoseL5d3EGZ1QLCztw9SzX EzNVLEaT1uXENh6gS6WVphNjlw== X-Google-Smtp-Source: AA6agR4D/lxlr4L+0FdtafVudGsXVZxfDnLZ5pKhbtzeGxYhZI79kjSKtslKXyeRzb7fqdDc9U/nVg== X-Received: by 2002:a2e:b88b:0:b0:25d:a15a:bba9 with SMTP id r11-20020a2eb88b000000b0025da15abba9mr2626624ljp.357.1659728460550; Fri, 05 Aug 2022 12:41:00 -0700 (PDT) Received: from dmaluka.office.semihalf.net ([83.142.187.84]) by smtp.gmail.com with ESMTPSA id o4-20020a056512230400b0048a407f41bbsm560079lfu.238.2022.08.05.12.40.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 12:41:00 -0700 (PDT) From: Dmytro Maluka To: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, Eric Auger , Alex Williamson , Rong L Liu , Zhenyu Wang , Tomasz Nowicki , Grzegorz Jaszczyk , upstream@semihalf.com, Dmitry Torokhov , Dmytro Maluka Subject: [PATCH v2 4/5] KVM: irqfd: Rename resampler->notifier Date: Fri, 5 Aug 2022 21:39:18 +0200 Message-Id: <20220805193919.1470653-5-dmy@semihalf.com> X-Mailer: git-send-email 2.37.1.559.g78731f0fdb-goog In-Reply-To: <20220805193919.1470653-1-dmy@semihalf.com> References: <20220805193919.1470653-1-dmy@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Since resampler irqfd is now using a mask notifier along with an ack notifier, rename resampler->notifier to resampler->ack_notifier for clarity. Signed-off-by: Dmytro Maluka Reviewed-by: Eric Auger --- include/linux/kvm_irqfd.h | 2 +- virt/kvm/eventfd.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/linux/kvm_irqfd.h b/include/linux/kvm_irqfd.h index 01754a1abb9e..4df9e6bbd7db 100644 --- a/include/linux/kvm_irqfd.h +++ b/include/linux/kvm_irqfd.h @@ -37,7 +37,7 @@ struct kvm_kernel_irqfd_resampler { * RCU list modified under kvm->irqfds.resampler_lock */ struct list_head list; - struct kvm_irq_ack_notifier notifier; + struct kvm_irq_ack_notifier ack_notifier; struct kvm_irq_mask_notifier mask_notifier; bool masked; bool pending; diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c index f98dcce3959c..72de942dbb9c 100644 --- a/virt/kvm/eventfd.c +++ b/virt/kvm/eventfd.c @@ -70,11 +70,11 @@ irqfd_resampler_ack(struct kvm_irq_ack_notifier *kian) bool notify =3D true; =20 resampler =3D container_of(kian, - struct kvm_kernel_irqfd_resampler, notifier); + struct kvm_kernel_irqfd_resampler, ack_notifier); kvm =3D resampler->kvm; =20 kvm_set_irq(kvm, KVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID, - resampler->notifier.gsi, 0, false); + resampler->ack_notifier.gsi, 0, false); =20 spin_lock(&resampler->lock); if (resampler->masked) { @@ -137,11 +137,11 @@ irqfd_resampler_shutdown(struct kvm_kernel_irqfd *irq= fd) =20 if (list_empty(&resampler->list)) { list_del(&resampler->link); - kvm_unregister_irq_ack_notifier(kvm, &resampler->notifier); + kvm_unregister_irq_ack_notifier(kvm, &resampler->ack_notifier); kvm_unregister_irq_mask_notifier(kvm, resampler->mask_notifier.irq, &resampler->mask_notifier); kvm_set_irq(kvm, KVM_IRQFD_RESAMPLE_IRQ_SOURCE_ID, - resampler->notifier.gsi, 0, false); + resampler->ack_notifier.gsi, 0, false); kfree(resampler); } =20 @@ -390,7 +390,7 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *arg= s) =20 list_for_each_entry(resampler, &kvm->irqfds.resampler_list, link) { - if (resampler->notifier.gsi =3D=3D irqfd->gsi) { + if (resampler->ack_notifier.gsi =3D=3D irqfd->gsi) { irqfd->resampler =3D resampler; break; } @@ -407,8 +407,8 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *arg= s) =20 resampler->kvm =3D kvm; INIT_LIST_HEAD(&resampler->list); - resampler->notifier.gsi =3D irqfd->gsi; - resampler->notifier.irq_acked =3D irqfd_resampler_ack; + resampler->ack_notifier.gsi =3D irqfd->gsi; + resampler->ack_notifier.irq_acked =3D irqfd_resampler_ack; resampler->mask_notifier.func =3D irqfd_resampler_mask_notify; spin_lock_init(&resampler->lock); INIT_LIST_HEAD(&resampler->link); @@ -417,7 +417,7 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *arg= s) kvm_register_and_fire_irq_mask_notifier(kvm, irqfd->gsi, &resampler->mask_notifier); kvm_register_irq_ack_notifier(kvm, - &resampler->notifier); + &resampler->ack_notifier); irqfd->resampler =3D resampler; } =20 --=20 2.37.1.559.g78731f0fdb-goog From nobody Sun Feb 8 10:25:51 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBF53C3F6B0 for ; Fri, 5 Aug 2022 19:41:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241588AbiHETl2 (ORCPT ); Fri, 5 Aug 2022 15:41:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241504AbiHETlH (ORCPT ); Fri, 5 Aug 2022 15:41:07 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E2FA11C07 for ; Fri, 5 Aug 2022 12:41:05 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id v10so567227ljh.9 for ; Fri, 05 Aug 2022 12:41:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=semihalf.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=4EJyKAMA651b2XcODYAopraeU2a8WMK/LvyMG5AbrCA=; b=a+0caHKPzVuG3onuuFuqFN0007+7/sghqkSm3qxnx3rp53REYeqJLY6NdiuFfu28d2 Kw/bFK9yFXWg1Mfyyy1UtBfsFrG38s25u2DaAQRCThlvLdzo3CzLf/86946XIbC+hjI7 qFVlvaLDi9CHs8jquTaEzdi/4zfjq1M824ZI4JX1oPfRIlpFEk9u5J/aXth61QRYZb87 5PpOTYAlSthJ1GExEOhWQ70Li1TglUYdRsxQpFs4W2/+sYWMtJbMLC5KR+Uyi2QI6ldL i+zEE7nLn1Bb6X0qdax5wx1ukq7G069alS5CZC956xP/mcPcOQsk43MRUax8UmN8mo1k gypA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=4EJyKAMA651b2XcODYAopraeU2a8WMK/LvyMG5AbrCA=; b=Ot/vdyRAwXFGz8MhrVI3cyunMb6KcACO0laPLASceaK9qXbvj1+4uBVqT8qJDmTbEo RIEDuZ/fFVHcLQcpXcLPv2xkfB56zyxJq235nQWhsFqEZ5uonOjKcXpw/4J6ZJbUD7cV /SnH7JE8BfsvDEJ2caiPtzCiRRADB22NBr2KIrVwTWdOuyXWLdsZryPnTfUGUbFUrh7O wOQw7NclrCB3/O/MIajDRJ1DvnfPYXcd3Mmp2J3Aex40COv6Rbt22qFqlNYUENbr/CIk VfQZ+4NFiMCVeNjyH+rOd8zGn8c805usT3at5gBvo9Gtg8Y6yj6pI3E9NdH/6j3RK+ZH tgXA== X-Gm-Message-State: ACgBeo0hSFAIB+RxcE7j3Zqmp92udCGCRTtLv+jH7nFsdAEJEwErAf29 +3ShjenHmVJDjmfLPr5Fks9vWQ== X-Google-Smtp-Source: AA6agR74BE6pJuac4KoH7KYfDpn5kABc0A1RphRlFVWmRcLJpptyXdW2EWbwCWeE4KlOPIE2K42IrQ== X-Received: by 2002:a2e:8681:0:b0:25e:7181:ddd8 with SMTP id l1-20020a2e8681000000b0025e7181ddd8mr2594995lji.199.1659728463549; Fri, 05 Aug 2022 12:41:03 -0700 (PDT) Received: from dmaluka.office.semihalf.net ([83.142.187.84]) by smtp.gmail.com with ESMTPSA id o4-20020a056512230400b0048a407f41bbsm560079lfu.238.2022.08.05.12.41.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Aug 2022 12:41:03 -0700 (PDT) From: Dmytro Maluka To: Sean Christopherson , Paolo Bonzini , kvm@vger.kernel.org Cc: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , linux-kernel@vger.kernel.org, Eric Auger , Alex Williamson , Rong L Liu , Zhenyu Wang , Tomasz Nowicki , Grzegorz Jaszczyk , upstream@semihalf.com, Dmitry Torokhov , Dmytro Maluka Subject: [PATCH v2 5/5] KVM: Rename kvm_irq_has_notifier() Date: Fri, 5 Aug 2022 21:39:19 +0200 Message-Id: <20220805193919.1470653-6-dmy@semihalf.com> X-Mailer: git-send-email 2.37.1.559.g78731f0fdb-goog In-Reply-To: <20220805193919.1470653-1-dmy@semihalf.com> References: <20220805193919.1470653-1-dmy@semihalf.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Now we have irq mask notifiers available in generic KVM along with irq ack notifiers, so rename kvm_irq_has_notifier() to kvm_irq_has_ack_notifier() to make it clear which notifier it is about. Signed-off-by: Dmytro Maluka --- arch/x86/kvm/ioapic.c | 2 +- include/linux/kvm_host.h | 2 +- virt/kvm/eventfd.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/ioapic.c b/arch/x86/kvm/ioapic.c index fab11de1f885..20d758ac2234 100644 --- a/arch/x86/kvm/ioapic.c +++ b/arch/x86/kvm/ioapic.c @@ -291,7 +291,7 @@ void kvm_ioapic_scan_entry(struct kvm_vcpu *vcpu, ulong= *ioapic_handled_vectors) for (index =3D 0; index < IOAPIC_NUM_PINS; index++) { e =3D &ioapic->redirtbl[index]; if (e->fields.trig_mode =3D=3D IOAPIC_LEVEL_TRIG || - kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC, index) || + kvm_irq_has_ack_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC, index) || index =3D=3D RTC_GSI) { u16 dm =3D kvm_lapic_irq_dest_mode(!!e->fields.dest_mode); =20 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h index 55233eb18eb4..ba18276691e1 100644 --- a/include/linux/kvm_host.h +++ b/include/linux/kvm_host.h @@ -1601,7 +1601,7 @@ int kvm_set_msi(struct kvm_kernel_irq_routing_entry *= irq_entry, struct kvm *kvm, int kvm_arch_set_irq_inatomic(struct kvm_kernel_irq_routing_entry *e, struct kvm *kvm, int irq_source_id, int level, bool line_status); -bool kvm_irq_has_notifier(struct kvm *kvm, unsigned irqchip, unsigned pin); +bool kvm_irq_has_ack_notifier(struct kvm *kvm, unsigned irqchip, unsigned = pin); void kvm_notify_acked_gsi(struct kvm *kvm, int gsi); void kvm_notify_acked_irq(struct kvm *kvm, unsigned irqchip, unsigned pin); void kvm_register_irq_ack_notifier(struct kvm *kvm, diff --git a/virt/kvm/eventfd.c b/virt/kvm/eventfd.c index 72de942dbb9c..4dd7b6f2da69 100644 --- a/virt/kvm/eventfd.c +++ b/virt/kvm/eventfd.c @@ -502,7 +502,7 @@ kvm_irqfd_assign(struct kvm *kvm, struct kvm_irqfd *arg= s) return ret; } =20 -bool kvm_irq_has_notifier(struct kvm *kvm, unsigned irqchip, unsigned pin) +bool kvm_irq_has_ack_notifier(struct kvm *kvm, unsigned irqchip, unsigned = pin) { struct kvm_irq_ack_notifier *kian; int gsi, idx; @@ -521,7 +521,7 @@ bool kvm_irq_has_notifier(struct kvm *kvm, unsigned irq= chip, unsigned pin) =20 return false; } -EXPORT_SYMBOL_GPL(kvm_irq_has_notifier); +EXPORT_SYMBOL_GPL(kvm_irq_has_ack_notifier); =20 void kvm_notify_acked_gsi(struct kvm *kvm, int gsi) { --=20 2.37.1.559.g78731f0fdb-goog