Skip to content

Commit 3e92fd7

Browse files
umgwanakikbutiIngo Molnar
authored andcommitted
connector/cn_proc: Protect send_msg() with a local lock
send_msg() disables preemption to avoid out-of-order messages. As the code inside the preempt disabled section acquires regular spinlocks, which are converted to 'sleeping' spinlocks on a PREEMPT_RT kernel and eventually calls into a memory allocator, this conflicts with the RT semantics. Convert it to a local_lock which allows RT kernels to substitute them with a real per CPU lock. On non RT kernels this maps to preempt_disable() as before. No functional change. [bigeasy: Patch description] Signed-off-by: Mike Galbraith <[email protected]> Signed-off-by: Sebastian Andrzej Siewior <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Acked-by: Peter Zijlstra <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent fd56200 commit 3e92fd7

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

drivers/connector/cn_proc.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/pid_namespace.h>
1919

2020
#include <linux/cn_proc.h>
21+
#include <linux/local_lock.h>
2122

2223
/*
2324
* Size of a cn_msg followed by a proc_event structure. Since the
@@ -38,25 +39,31 @@ static inline struct cn_msg *buffer_to_cn_msg(__u8 *buffer)
3839
static atomic_t proc_event_num_listeners = ATOMIC_INIT(0);
3940
static struct cb_id cn_proc_event_id = { CN_IDX_PROC, CN_VAL_PROC };
4041

41-
/* proc_event_counts is used as the sequence number of the netlink message */
42-
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+
};
4350

4451
static inline void send_msg(struct cn_msg *msg)
4552
{
46-
preempt_disable();
53+
local_lock(&local_event.lock);
4754

48-
msg->seq = __this_cpu_inc_return(proc_event_counts) - 1;
55+
msg->seq = __this_cpu_inc_return(local_event.count) - 1;
4956
((struct proc_event *)msg->data)->cpu = smp_processor_id();
5057

5158
/*
52-
* Preemption remains disabled during send to ensure the messages are
53-
* 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.
5461
*
5562
* If cn_netlink_send() fails, the data is not sent.
5663
*/
5764
cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_NOWAIT);
5865

59-
preempt_enable();
66+
local_unlock(&local_event.lock);
6067
}
6168

6269
void proc_fork_connector(struct task_struct *task)

0 commit comments

Comments
 (0)