hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/connector/cn_proc.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * cn_proc.c - process events connector
34 *
....@@ -5,21 +6,6 @@
56 * Based on cn_fork.c by Guillaume Thouvenin <guillaume.thouvenin@bull.net>
67 * Original copyright notice follows:
78 * Copyright (C) 2005 BULL SA.
8
- *
9
- *
10
- * This program is free software; you can redistribute it and/or modify
11
- * it under the terms of the GNU General Public License as published by
12
- * the Free Software Foundation; either version 2 of the License, or
13
- * (at your option) any later version.
14
- *
15
- * This program is distributed in the hope that it will be useful,
16
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
- * GNU General Public License for more details.
19
- *
20
- * You should have received a copy of the GNU General Public License
21
- * along with this program; if not, write to the Free Software
22
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
239 */
2410
2511 #include <linux/kernel.h>
....@@ -32,6 +18,7 @@
3218 #include <linux/pid_namespace.h>
3319
3420 #include <linux/cn_proc.h>
21
+#include <linux/local_lock.h>
3522
3623 /*
3724 * Size of a cn_msg followed by a proc_event structure. Since the
....@@ -52,25 +39,31 @@
5239 static atomic_t proc_event_num_listeners = ATOMIC_INIT(0);
5340 static struct cb_id cn_proc_event_id = { CN_IDX_PROC, CN_VAL_PROC };
5441
55
-/* proc_event_counts is used as the sequence number of the netlink message */
56
-static DEFINE_PER_CPU(__u32, proc_event_counts) = { 0 };
42
+/* local_event.count is used as the sequence number of the netlink message */
43
+struct local_event {
44
+ local_lock_t lock;
45
+ __u32 count;
46
+};
47
+static DEFINE_PER_CPU(struct local_event, local_event) = {
48
+ .lock = INIT_LOCAL_LOCK(lock),
49
+};
5750
5851 static inline void send_msg(struct cn_msg *msg)
5952 {
60
- preempt_disable();
53
+ local_lock(&local_event.lock);
6154
62
- msg->seq = __this_cpu_inc_return(proc_event_counts) - 1;
55
+ msg->seq = __this_cpu_inc_return(local_event.count) - 1;
6356 ((struct proc_event *)msg->data)->cpu = smp_processor_id();
6457
6558 /*
66
- * Preemption remains disabled during send to ensure the messages are
67
- * ordered according to their sequence numbers.
59
+ * local_lock() disables preemption during send to ensure the messages
60
+ * are ordered according to their sequence numbers.
6861 *
6962 * If cn_netlink_send() fails, the data is not sent.
7063 */
7164 cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_NOWAIT);
7265
73
- preempt_enable();
66
+ local_unlock(&local_event.lock);
7467 }
7568
7669 void proc_fork_connector(struct task_struct *task)