mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 1/4] ipmi: msghandler: Add a limit for the number of users
Date: Wed, 30 Mar 2022 00:12:39 +0800	[thread overview]
Message-ID: <tencent_D9F2E3B84F62AA514CF2332F90E521A9CF05@qq.com> (raw)
In-Reply-To: <20220329161242.76457-1-chen.chenchacha@foxmail.com>

The administrator sets the limit for the number of users by modifying
/sys/module/ipmi_msghandler/parameters/default_max_users.

Signed-off-by: Chen Guanqiao <chen.chenchacha@foxmail.com>
---
 drivers/char/ipmi/ipmi_msghandler.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index c59265146e9c..7886c8337368 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -145,6 +145,12 @@ module_param(default_max_retries, uint, 0644);
 MODULE_PARM_DESC(default_max_retries,
 		 "The time (milliseconds) between retry sends in maintenance mode");

+/* The default maximum number of users per intf */
+static unsigned int default_max_users = 50;
+module_param(default_max_users, uint, 0644);
+MODULE_PARM_DESC(default_max_users,
+		 "The maximum number of users per interface");
+
 /* Call every ~1000 ms. */
 #define IPMI_TIMEOUT_TIME	1000

@@ -579,6 +585,9 @@ struct ipmi_smi {

 	atomic_t stats[IPMI_NUM_STATS];

+	/* The number of user in this interface */
+	atomic_t user_count;
+
 	/*
 	 * run_to_completion duplicate of smb_info, smi_info
 	 * and ipmi_serial_info structures. Used to decrease numbers of
@@ -1182,9 +1191,11 @@ static void free_user_work(struct work_struct *work)
 {
 	struct ipmi_user *user = container_of(work, struct ipmi_user,
 					      remove_work);
+	struct ipmi_smi *intf = user->intf;

 	cleanup_srcu_struct(&user->release_barrier);
 	vfree(user);
+	atomic_dec(&intf->user_count);
 }

 int ipmi_create_user(unsigned int          if_num,
@@ -1230,6 +1241,12 @@ int ipmi_create_user(unsigned int          if_num,
 	goto out_kfree;

  found:
+	if (atomic_inc_return(&intf->user_count) > default_max_users) {
+		atomic_dec(&intf->user_count);
+		rv = -EBUSY;
+		goto out_kfree;
+	}
+
 	INIT_WORK(&new_user->remove_work, free_user_work);

 	rv = init_srcu_struct(&new_user->release_barrier);
@@ -3548,6 +3565,7 @@ int ipmi_add_smi(struct module         *owner,
 	spin_lock_init(&intf->events_lock);
 	spin_lock_init(&intf->watch_lock);
 	atomic_set(&intf->event_waiters, 0);
+	atomic_set(&intf->user_count, 0);
 	intf->ticks_to_req_ev = IPMI_REQUEST_EV_TIME;
 	INIT_LIST_HEAD(&intf->waiting_events);
 	intf->waiting_events_count = 0;
--
2.25.1


       reply	other threads:[~2022-03-29 16:12 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 ` Chen Guanqiao [this message]
2022-03-29 16:12 ` [PATCH v2 2/4] ipmi: msghandler: Add a limit for the number of messages Chen Guanqiao
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_D9F2E3B84F62AA514CF2332F90E521A9CF05@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®