From: Sean Christopherson <seanjc@google.com>
To: Sean Christopherson <seanjc@google.com>,
Paolo Bonzini <pbonzini@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
Jason Wang <jasowang@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,
Kevin Tian <kevin.tian@intel.com>,
Oliver Upton <oliver.upton@linux.dev>,
David Matlack <dmatlack@google.com>,
Like Xu <like.xu.linux@gmail.com>,
Binbin Wu <binbin.wu@linux.intel.com>,
Yong He <alexyonghe@tencent.com>
Subject: [PATCH v2 1/8] irqbypass: Drop pointless and misleading THIS_MODULE get/put
Date: Fri, 16 May 2025 16:07:27 -0700 [thread overview]
Message-ID: <20250516230734.2564775-2-seanjc@google.com> (raw)
In-Reply-To: <20250516230734.2564775-1-seanjc@google.com>
Drop irqbypass.ko's superfluous and misleading get/put calls on
THIS_MODULE. A module taking a reference to itself is useless; no amount
of checks will prevent doom and destruction if the caller hasn't already
guaranteed the liveliness of the module (this goes for any module). E.g.
if try_module_get() fails because irqbypass.ko is being unloaded, then the
kernel has already hit a use-after-free by virtue of executing code whose
lifecycle is tied to irqbypass.ko.
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
virt/lib/irqbypass.c | 20 --------------------
1 file changed, 20 deletions(-)
diff --git a/virt/lib/irqbypass.c b/virt/lib/irqbypass.c
index 28fda42e471b..080c706f3b01 100644
--- a/virt/lib/irqbypass.c
+++ b/virt/lib/irqbypass.c
@@ -92,9 +92,6 @@ int irq_bypass_register_producer(struct irq_bypass_producer *producer)
might_sleep();
- if (!try_module_get(THIS_MODULE))
- return -ENODEV;
-
mutex_lock(&lock);
list_for_each_entry(tmp, &producers, node) {
@@ -120,7 +117,6 @@ int irq_bypass_register_producer(struct irq_bypass_producer *producer)
return 0;
out_err:
mutex_unlock(&lock);
- module_put(THIS_MODULE);
return ret;
}
EXPORT_SYMBOL_GPL(irq_bypass_register_producer);
@@ -142,9 +138,6 @@ void irq_bypass_unregister_producer(struct irq_bypass_producer *producer)
might_sleep();
- if (!try_module_get(THIS_MODULE))
- return; /* nothing in the list anyway */
-
mutex_lock(&lock);
list_for_each_entry(tmp, &producers, node) {
@@ -159,13 +152,10 @@ void irq_bypass_unregister_producer(struct irq_bypass_producer *producer)
}
list_del(&producer->node);
- module_put(THIS_MODULE);
break;
}
mutex_unlock(&lock);
-
- module_put(THIS_MODULE);
}
EXPORT_SYMBOL_GPL(irq_bypass_unregister_producer);
@@ -188,9 +178,6 @@ int irq_bypass_register_consumer(struct irq_bypass_consumer *consumer)
might_sleep();
- if (!try_module_get(THIS_MODULE))
- return -ENODEV;
-
mutex_lock(&lock);
list_for_each_entry(tmp, &consumers, node) {
@@ -216,7 +203,6 @@ int irq_bypass_register_consumer(struct irq_bypass_consumer *consumer)
return 0;
out_err:
mutex_unlock(&lock);
- module_put(THIS_MODULE);
return ret;
}
EXPORT_SYMBOL_GPL(irq_bypass_register_consumer);
@@ -238,9 +224,6 @@ void irq_bypass_unregister_consumer(struct irq_bypass_consumer *consumer)
might_sleep();
- if (!try_module_get(THIS_MODULE))
- return; /* nothing in the list anyway */
-
mutex_lock(&lock);
list_for_each_entry(tmp, &consumers, node) {
@@ -255,12 +238,9 @@ void irq_bypass_unregister_consumer(struct irq_bypass_consumer *consumer)
}
list_del(&consumer->node);
- module_put(THIS_MODULE);
break;
}
mutex_unlock(&lock);
-
- module_put(THIS_MODULE);
}
EXPORT_SYMBOL_GPL(irq_bypass_unregister_consumer);
--
2.49.0.1112.g889b7c5bd8-goog
next prev parent reply other threads:[~2025-05-16 23:07 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-16 23:07 [PATCH v2 0/8] irqbypass: Cleanups and a perf improvement Sean Christopherson
2025-05-16 23:07 ` Sean Christopherson [this message]
2025-05-16 23:07 ` [PATCH v2 2/8] irqbypass: Drop superfluous might_sleep() annotations Sean Christopherson
2025-05-16 23:07 ` [PATCH v2 3/8] irqbypass: Take ownership of producer/consumer token tracking Sean Christopherson
2025-05-16 23:07 ` [PATCH v2 4/8] irqbypass: Explicitly track producer and consumer bindings Sean Christopherson
2025-05-16 23:07 ` [PATCH v2 5/8] irqbypass: Use paired consumer/producer to disconnect during unregister Sean Christopherson
2025-05-16 23:07 ` [PATCH v2 6/8] irqbypass: Use guard(mutex) in lieu of manual lock+unlock Sean Christopherson
2025-05-16 23:07 ` [PATCH v2 7/8] irqbypass: Use xarray to track producers and consumers Sean Christopherson
2025-05-16 23:07 ` [PATCH v2 8/8] irqbypass: Require producers to pass in Linux IRQ number during registration Sean Christopherson
2025-05-23 1:53 ` Tian, Kevin
2025-05-18 20:10 ` [PATCH v2 0/8] irqbypass: Cleanups and a perf improvement Michael S. Tsirkin
2025-06-02 18:54 ` Alex Williamson
2025-06-02 23:30 ` Sean Christopherson
2025-06-24 19:38 ` Sean Christopherson
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=20250516230734.2564775-2-seanjc@google.com \
--to=seanjc@google.com \
--cc=alex.williamson@redhat.com \
--cc=alexyonghe@tencent.com \
--cc=binbin.wu@linux.intel.com \
--cc=dmatlack@google.com \
--cc=jasowang@redhat.com \
--cc=kevin.tian@intel.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