From: Corey Minyard <corey@minyard.net>
To: linux-kernel@vger.kernel.org,
openipmi-developer@lists.sourceforge.net,
Rik van Riel <riel@surriel.com>
Cc: "Paul E . McKenney" <paulmck@kernel.org>,
Breno Leitao <leitao@debian.org>,
Corey Minyard <corey@minyard.net>,
Corey Minyard <cminyard@mvista.com>
Subject: [PATCH 12/23] ipmi:msghandler: Fix locking around users and interfaces
Date: Thu, 24 Apr 2025 11:49:49 -0500 [thread overview]
Message-ID: <20250424165020.627193-13-corey@minyard.net> (raw)
In-Reply-To: <20250424165020.627193-1-corey@minyard.net>
Now that SRCU is gone from IPMI, it can no longer be sloppy about
locking. Use the users mutex now when sending a message, not the big
ipmi_interfaces mutex, because it can result in a recursive lock. The
users mutex will work because the interface destroy code claims it after
setting the interface in shutdown mode.
Also, due to the same changes, rework the refcounting on users and
interfaces. Remove the refcount to an interface when the user is
freed, not when it is destroyed. If the interface is destroyed
while the user still exists, the user will still point to the
interface to test that it is valid if the user tries to do anything
but delete the user.
Signed-off-by: Corey Minyard <cminyard@mvista.com>
---
drivers/char/ipmi/ipmi_msghandler.c | 51 ++++++++++++++---------------
1 file changed, 25 insertions(+), 26 deletions(-)
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index e7bed764b4bb..d05032dc1f69 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -46,6 +46,7 @@ static void handle_new_recv_msgs(struct ipmi_smi *intf);
static void need_waiter(struct ipmi_smi *intf);
static int handle_one_recv_msg(struct ipmi_smi *intf,
struct ipmi_smi_msg *msg);
+static void intf_free(struct kref *ref);
static bool initialized;
static bool drvregistered;
@@ -196,25 +197,6 @@ struct ipmi_user {
atomic_t nr_msgs;
};
-static void free_ipmi_user(struct kref *ref)
-{
- struct ipmi_user *user = container_of(ref, struct ipmi_user, refcount);
-
- vfree(user);
-}
-
-static void release_ipmi_user(struct ipmi_user *user)
-{
- kref_put(&user->refcount, free_ipmi_user);
-}
-
-static struct ipmi_user *acquire_ipmi_user(struct ipmi_user *user)
-{
- if (!kref_get_unless_zero(&user->refcount))
- return NULL;
- return user;
-}
-
struct cmd_rcvr {
struct list_head link;
@@ -611,6 +593,28 @@ static int __ipmi_bmc_register(struct ipmi_smi *intf,
bool guid_set, guid_t *guid, int intf_num);
static int __scan_channels(struct ipmi_smi *intf, struct ipmi_device_id *id);
+static void free_ipmi_user(struct kref *ref)
+{
+ struct ipmi_user *user = container_of(ref, struct ipmi_user, refcount);
+ struct module *owner;
+
+ owner = user->intf->owner;
+ kref_put(&user->intf->refcount, intf_free);
+ module_put(owner);
+ vfree(user);
+}
+
+static void release_ipmi_user(struct ipmi_user *user)
+{
+ kref_put(&user->refcount, free_ipmi_user);
+}
+
+static struct ipmi_user *acquire_ipmi_user(struct ipmi_user *user)
+{
+ if (!kref_get_unless_zero(&user->refcount))
+ return NULL;
+ return user;
+}
/*
* The driver model view of the IPMI messaging driver.
@@ -1330,7 +1334,6 @@ static void _ipmi_destroy_user(struct ipmi_user *user)
unsigned long flags;
struct cmd_rcvr *rcvr;
struct cmd_rcvr *rcvrs = NULL;
- struct module *owner;
if (!refcount_dec_if_one(&user->destroyed))
return;
@@ -1382,10 +1385,6 @@ static void _ipmi_destroy_user(struct ipmi_user *user)
}
release_ipmi_user(user);
-
- owner = intf->owner;
- kref_put(&intf->refcount, intf_free);
- module_put(owner);
}
void ipmi_destroy_user(struct ipmi_user *user)
@@ -2315,7 +2314,7 @@ static int i_ipmi_request(struct ipmi_user *user,
}
}
- mutex_lock(&ipmi_interfaces_mutex);
+ mutex_lock(&intf->users_mutex);
if (intf->in_shutdown) {
rv = -ENODEV;
goto out_err;
@@ -2361,7 +2360,7 @@ static int i_ipmi_request(struct ipmi_user *user,
smi_send(intf, intf->handlers, smi_msg, priority);
}
- mutex_unlock(&ipmi_interfaces_mutex);
+ mutex_unlock(&intf->users_mutex);
out:
if (rv && user)
--
2.43.0
next prev parent reply other threads:[~2025-04-24 16:50 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-24 16:49 [PATCH 00/23] ipmi: Remove SRCU and handle the fallout Corey Minyard
2025-04-24 16:49 ` [PATCH 01/23] ipmi:msghandler: Use READ_ONCE on run_to_completion Corey Minyard
2025-04-24 16:49 ` [PATCH 02/23] ipmi:msghandler: Rename recv_work to smi_work Corey Minyard
2025-04-24 16:49 ` [PATCH 03/23] ipmi:msghandler: Move timer handling into a work queue Corey Minyard
2025-04-24 16:49 ` [PATCH 04/23] ipmi:msghandler: Deliver user messages in " Corey Minyard
2025-04-24 16:49 ` [PATCH 05/23] ipmi_msghandler: Change the events lock to a mutex Corey Minyard
2025-04-24 16:49 ` [PATCH 06/23] ipmi:msghandler: Use the system_wq, not system_bh_wq Corey Minyard
2025-04-24 16:49 ` [PATCH 07/23] ipmi:msghandler: Remove srcu from the ipmi user structure Corey Minyard
2025-04-24 16:49 ` [PATCH 08/23] ipmi:msghandler: Remove srcu for the ipmi_interfaces list Corey Minyard
2025-04-24 16:49 ` [PATCH 09/23] ipmi:watchdog: Change lock to mutex Corey Minyard
2025-04-24 16:49 ` [PATCH 10/23] ipmi: Add a note about the pretimeout callback Corey Minyard
2025-04-24 16:49 ` [PATCH 11/23] ipmi:msghandler: Remove some user level processing in panic mode Corey Minyard
2025-04-24 16:49 ` Corey Minyard [this message]
2025-04-24 16:49 ` [PATCH 13/23] ipmi:msghandler: Don't acquire a user refcount for queued messages Corey Minyard
2025-04-24 16:49 ` [PATCH 14/23] ipmi:msghandler: Don't check for shutdown when returning responses Corey Minyard
2025-04-24 16:49 ` [PATCH 15/23] ipmi:msghandler: Remove proc_fs.h Corey Minyard
2025-04-24 16:49 ` [PATCH 16/23] ipmi:msghandler: Shut down lower layer first at unregister Corey Minyard
2025-04-24 16:49 ` [PATCH 17/23] ipmi:msghandler: Add a error return from unhandle LAN cmds Corey Minyard
2025-04-24 16:49 ` [PATCH 18/23] ipmi:si: Rework startup of IPMI devices Corey Minyard
2025-04-24 16:49 ` [PATCH 19/23] ipmi:msghandler: Don't deliver messages to deleted users Corey Minyard
2025-04-24 16:49 ` [PATCH 20/23] ipmi:ssif: Fix a shutdown race Corey Minyard
2025-04-24 16:49 ` [PATCH 21/23] Documentation:ipmi: Remove comments about interrupt level Corey Minyard
2025-04-24 16:49 ` [PATCH 22/23] ipmi:msghandler: Export and fix panic messaging capability Corey Minyard
2025-04-24 16:50 ` [PATCH 23/23] ipmi:watchdog: Use the new interface for panic messages Corey Minyard
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=20250424165020.627193-13-corey@minyard.net \
--to=corey@minyard.net \
--cc=cminyard@mvista.com \
--cc=leitao@debian.org \
--cc=linux-kernel@vger.kernel.org \
--cc=openipmi-developer@lists.sourceforge.net \
--cc=paulmck@kernel.org \
--cc=riel@surriel.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®