mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: "Michael S. Tsirkin" <mst@redhat.com>,
	Jason Wang <jasowang@redhat.com>,
	 Paolo Bonzini <pbonzini@redhat.com>,
	Alex Williamson <alex.williamson@redhat.com>
Cc: kvm@vger.kernel.org, virtualization@lists.linux.dev,
	 netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Sean Christopherson <seanjc@google.com>,
	Oliver Upton <oliver.upton@linux.dev>,
	 David Matlack <dmatlack@google.com>,
	Like Xu <like.xu.linux@gmail.com>,
	 Yong He <alexyonghe@tencent.com>
Subject: [PATCH 5/7] irqbypass: Use paired consumer/producer to disconnect during unregister
Date: Fri,  4 Apr 2025 14:14:47 -0700	[thread overview]
Message-ID: <20250404211449.1443336-6-seanjc@google.com> (raw)
In-Reply-To: <20250404211449.1443336-1-seanjc@google.com>

Use the paired consumer/producer information to disconnect IRQ bypass
producers/consumers in O(1) time (ignoring the cost of __disconnect()).

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 virt/lib/irqbypass.c | 50 +++++++-------------------------------------
 1 file changed, 8 insertions(+), 42 deletions(-)

diff --git a/virt/lib/irqbypass.c b/virt/lib/irqbypass.c
index 4c912c30b7e6..6d68a0f71dd9 100644
--- a/virt/lib/irqbypass.c
+++ b/virt/lib/irqbypass.c
@@ -138,32 +138,16 @@ EXPORT_SYMBOL_GPL(irq_bypass_register_producer);
  */
 void irq_bypass_unregister_producer(struct irq_bypass_producer *producer)
 {
-	struct irq_bypass_producer *tmp;
-	struct irq_bypass_consumer *consumer;
-
 	if (!producer->token)
 		return;
 
 	mutex_lock(&lock);
 
-	list_for_each_entry(tmp, &producers, node) {
-		if (tmp->token != producer->token)
-			continue;
+	if (producer->consumer)
+		__disconnect(producer, producer->consumer);
 
-		list_for_each_entry(consumer, &consumers, node) {
-			if (consumer->token == producer->token) {
-				WARN_ON_ONCE(producer->consumer != consumer);
-				__disconnect(producer, consumer);
-				break;
-			}
-		}
-
-		producer->token = NULL;
-		list_del(&producer->node);
-		break;
-	}
-
-	WARN_ON_ONCE(producer->token);
+	producer->token = NULL;
+	list_del(&producer->node);
 	mutex_unlock(&lock);
 }
 EXPORT_SYMBOL_GPL(irq_bypass_unregister_producer);
@@ -173,8 +157,6 @@ EXPORT_SYMBOL_GPL(irq_bypass_unregister_producer);
  * @consumer: pointer to consumer structure
  * @eventfd: pointer to the eventfd context associated with the consumer
  *
- * Add the provided IRQ consumer to the list of consumers and connect
- * with any matching token found on the IRQ producer list.
  */
 int irq_bypass_register_consumer(struct irq_bypass_consumer *consumer,
 				 struct eventfd_ctx *eventfd)
@@ -228,32 +210,16 @@ EXPORT_SYMBOL_GPL(irq_bypass_register_consumer);
  */
 void irq_bypass_unregister_consumer(struct irq_bypass_consumer *consumer)
 {
-	struct irq_bypass_consumer *tmp;
-	struct irq_bypass_producer *producer;
-
 	if (!consumer->token)
 		return;
 
 	mutex_lock(&lock);
 
-	list_for_each_entry(tmp, &consumers, node) {
-		if (tmp != consumer)
-			continue;
+	if (consumer->producer)
+		__disconnect(consumer->producer, consumer);
 
-		list_for_each_entry(producer, &producers, node) {
-			if (producer->token == consumer->token) {
-				WARN_ON_ONCE(consumer->producer != producer);
-				__disconnect(producer, consumer);
-				break;
-			}
-		}
-
-		consumer->token = NULL;
-		list_del(&consumer->node);
-		break;
-	}
-
-	WARN_ON_ONCE(consumer->token);
+	consumer->token = NULL;
+	list_del(&consumer->node);
 	mutex_unlock(&lock);
 }
 EXPORT_SYMBOL_GPL(irq_bypass_unregister_consumer);
-- 
2.49.0.504.g3bcea36a83-goog


  parent reply	other threads:[~2025-04-04 21:15 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-04 21:14 [PATCH 0/7] irqbypass: Cleanups and a perf improvement Sean Christopherson
2025-04-04 21:14 ` [PATCH 1/7] irqbypass: Drop pointless and misleading THIS_MODULE get/put Sean Christopherson
2025-04-10  7:12   ` Tian, Kevin
2025-04-04 21:14 ` [PATCH 2/7] irqbypass: Drop superfluous might_sleep() annotations Sean Christopherson
2025-04-10  7:13   ` Tian, Kevin
2025-04-04 21:14 ` [PATCH 3/7] irqbypass: Take ownership of producer/consumer token tracking Sean Christopherson
2025-04-10  7:28   ` Tian, Kevin
2025-04-10 15:51     ` Sean Christopherson
2025-04-10 21:28   ` Alex Williamson
2025-04-10 22:04     ` Sean Christopherson
2025-04-10 22:25       ` Alex Williamson
2025-04-04 21:14 ` [PATCH 4/7] irqbypass: Explicitly track producer and consumer bindings Sean Christopherson
2025-04-10  7:32   ` Tian, Kevin
2025-04-04 21:14 ` Sean Christopherson [this message]
2025-04-10  7:34   ` [PATCH 5/7] irqbypass: Use paired consumer/producer to disconnect during unregister Tian, Kevin
2025-04-04 21:14 ` [PATCH 6/7] irqbypass: Use guard(mutex) in lieu of manual lock+unlock Sean Christopherson
2025-04-10  7:34   ` Tian, Kevin
2025-04-04 21:14 ` [PATCH 7/7] irqbypass: Use xarray to track producers and consumers Sean Christopherson
2025-04-07  3:37   ` Binbin Wu
2025-04-10  7:38   ` Tian, Kevin
2025-04-10 14:52     ` Sean Christopherson
2025-04-11  0:09       ` Tian, Kevin
2025-04-08 11:49 ` [PATCH 0/7] irqbypass: Cleanups and a perf improvement Michael S. Tsirkin

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=20250404211449.1443336-6-seanjc@google.com \
    --to=seanjc@google.com \
    --cc=alex.williamson@redhat.com \
    --cc=alexyonghe@tencent.com \
    --cc=dmatlack@google.com \
    --cc=jasowang@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=like.xu.linux@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mst@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=oliver.upton@linux.dev \
    --cc=pbonzini@redhat.com \
    --cc=virtualization@lists.linux.dev \
    /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®