From: Chen Guanqiao <chen.chenchacha@foxmail.com>
To: minyard@acm.org, openipmi-developer@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Cc: Chen Guanqiao <chen.chenchacha@foxmail.com>
Subject: [PATCH v2 2/4] ipmi: msghandler: Add a limit for the number of messages
Date: Wed, 30 Mar 2022 00:12:40 +0800 [thread overview]
Message-ID: <tencent_ADBE84293031AFCF8E409D87E2BE9B0FF507@qq.com> (raw)
In-Reply-To: <20220329161242.76457-1-chen.chenchacha@foxmail.com>
The administrator sets the limit for the number of messages by modifying
/sys/module/ipmi_msghandler/parameters/default_max_msgs.
Before create a message, count the number of outstanding messages, if
the number reaches the limit, it will return a busy.
Signed-off-by: Chen Guanqiao <chen.chenchacha@foxmail.com>
---
drivers/char/ipmi/ipmi_msghandler.c | 37 +++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index 7886c8337368..80ab88702c5f 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -151,6 +151,12 @@ module_param(default_max_users, uint, 0644);
MODULE_PARM_DESC(default_max_users,
"The maximum number of users per interface");
+/* The default maximum number of outstanding messages per intf */
+static unsigned int default_max_messages = 100;
+module_param(default_max_messages, uint, 0644);
+MODULE_PARM_DESC(default_max_messages,
+ "The maximum number of outstanding messages per interface");
+
/* Call every ~1000 ms. */
#define IPMI_TIMEOUT_TIME 1000
@@ -916,6 +922,30 @@ unsigned int ipmi_addr_length(int addr_type)
}
EXPORT_SYMBOL(ipmi_addr_length);
+static void intf_msg_count(struct ipmi_smi *intf,
+ unsigned int *hp_count, unsigned int *count)
+{
+ struct ipmi_smi_msg *msg;
+ unsigned long flags;
+ int hp_msg_count = 0, msg_count = 0;
+ int run_to_completion = intf->run_to_completion;
+
+ if (!run_to_completion)
+ spin_lock_irqsave(&intf->xmit_msgs_lock, flags);
+ if (!intf->in_shutdown) {
+ list_for_each_entry(msg, &intf->hp_xmit_msgs, link)
+ hp_msg_count++;
+
+ list_for_each_entry(msg, &intf->xmit_msgs, link)
+ msg_count++;
+ }
+ if (!run_to_completion)
+ spin_unlock_irqrestore(&intf->xmit_msgs_lock, flags);
+
+ *hp_count = hp_msg_count;
+ *count = msg_count;
+}
+
static int deliver_response(struct ipmi_smi *intf, struct ipmi_recv_msg *msg)
{
int rv = 0;
@@ -2299,6 +2329,7 @@ static int i_ipmi_request(struct ipmi_user *user,
{
struct ipmi_smi_msg *smi_msg;
struct ipmi_recv_msg *recv_msg;
+ unsigned hp_msg_count, msg_count;
int rv = 0;
if (supplied_recv)
@@ -2330,6 +2361,12 @@ static int i_ipmi_request(struct ipmi_user *user,
goto out_err;
}
+ intf_msg_count(intf, &hp_msg_count, &msg_count);
+ if ((hp_msg_count + msg_count) > default_max_messages) {
+ rv = -EBUSY;
+ goto out_err;
+ }
+
recv_msg->user = user;
if (user)
/* The put happens when the message is freed. */
--
2.25.1
next prev parent reply other threads:[~2022-03-29 16:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20220329161242.76457-1-chen.chenchacha@foxmail.com>
2022-03-29 16:12 ` [PATCH v2 1/4] ipmi: msghandler: Add a limit for the number of users Chen Guanqiao
2022-03-29 16:12 ` Chen Guanqiao [this message]
2022-03-29 16:12 ` [PATCH v2 3/4] ipmi: msghandler: Get the number of users and messages through sysfs Chen Guanqiao
2022-03-29 16:12 ` [PATCH v2 4/4] ipmi: msghandler: Add a interface to clean message queue in sysfs Chen Guanqiao
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=tencent_ADBE84293031AFCF8E409D87E2BE9B0FF507@qq.com \
--to=chen.chenchacha@foxmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=minyard@acm.org \
--cc=openipmi-developer@lists.sourceforge.net \
/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®