mirror of
https://github.com/FEX-Emu/linux.git
synced 2025-03-03 01:57:14 +00:00
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 <umgwanakikbuti@gmail.com> Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de> Signed-off-by: Ingo Molnar <mingo@kernel.org> Acked-by: Peter Zijlstra <peterz@infradead.org> Link: https://lore.kernel.org/r/20200527201119.1692513-6-bigeasy@linutronix.de
This commit is contained in:
parent
fd56200a16
commit
3e92fd7bd2
@ -18,6 +18,7 @@
|
|||||||
#include <linux/pid_namespace.h>
|
#include <linux/pid_namespace.h>
|
||||||
|
|
||||||
#include <linux/cn_proc.h>
|
#include <linux/cn_proc.h>
|
||||||
|
#include <linux/local_lock.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Size of a cn_msg followed by a proc_event structure. Since the
|
* 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)
|
|||||||
static atomic_t proc_event_num_listeners = ATOMIC_INIT(0);
|
static atomic_t proc_event_num_listeners = ATOMIC_INIT(0);
|
||||||
static struct cb_id cn_proc_event_id = { CN_IDX_PROC, CN_VAL_PROC };
|
static struct cb_id cn_proc_event_id = { CN_IDX_PROC, CN_VAL_PROC };
|
||||||
|
|
||||||
/* proc_event_counts is used as the sequence number of the netlink message */
|
/* local_event.count is used as the sequence number of the netlink message */
|
||||||
static DEFINE_PER_CPU(__u32, proc_event_counts) = { 0 };
|
struct local_event {
|
||||||
|
local_lock_t lock;
|
||||||
|
__u32 count;
|
||||||
|
};
|
||||||
|
static DEFINE_PER_CPU(struct local_event, local_event) = {
|
||||||
|
.lock = INIT_LOCAL_LOCK(lock),
|
||||||
|
};
|
||||||
|
|
||||||
static inline void send_msg(struct cn_msg *msg)
|
static inline void send_msg(struct cn_msg *msg)
|
||||||
{
|
{
|
||||||
preempt_disable();
|
local_lock(&local_event.lock);
|
||||||
|
|
||||||
msg->seq = __this_cpu_inc_return(proc_event_counts) - 1;
|
msg->seq = __this_cpu_inc_return(local_event.count) - 1;
|
||||||
((struct proc_event *)msg->data)->cpu = smp_processor_id();
|
((struct proc_event *)msg->data)->cpu = smp_processor_id();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Preemption remains disabled during send to ensure the messages are
|
* local_lock() disables preemption during send to ensure the messages
|
||||||
* ordered according to their sequence numbers.
|
* are ordered according to their sequence numbers.
|
||||||
*
|
*
|
||||||
* If cn_netlink_send() fails, the data is not sent.
|
* If cn_netlink_send() fails, the data is not sent.
|
||||||
*/
|
*/
|
||||||
cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_NOWAIT);
|
cn_netlink_send(msg, 0, CN_IDX_PROC, GFP_NOWAIT);
|
||||||
|
|
||||||
preempt_enable();
|
local_unlock(&local_event.lock);
|
||||||
}
|
}
|
||||||
|
|
||||||
void proc_fork_connector(struct task_struct *task)
|
void proc_fork_connector(struct task_struct *task)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user