Skip to content

Commit 76d62f2

Browse files
johnstultz-workkees
authored andcommitted
pstore: Switch pmsg_lock to an rt_mutex to avoid priority inversion
Wei Wang reported seeing priority inversion caused latencies caused by contention on pmsg_lock, and suggested it be switched to a rt_mutex. I was initially hesitant this would help, as the tasks in that trace all seemed to be SCHED_NORMAL, so the benefit would be limited to only nice boosting. However, another similar issue was raised where the priority inversion was seen did involve a blocked RT task so it is clear this would be helpful in that case. Cc: Wei Wang <[email protected]> Cc: Midas Chien<[email protected]> Cc: Connor O'Brien <[email protected]> Cc: Kees Cook <[email protected]> Cc: Anton Vorontsov <[email protected]> Cc: Colin Cross <[email protected]> Cc: Tony Luck <[email protected]> Cc: [email protected] Fixes: 9d5438f ("pstore: Add pmsg - user-space accessible pstore object") Reported-by: Wei Wang <[email protected]> Signed-off-by: John Stultz <[email protected]> Signed-off-by: Kees Cook <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent e6b8427 commit 76d62f2

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

fs/pstore/pmsg.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77
#include <linux/device.h>
88
#include <linux/fs.h>
99
#include <linux/uaccess.h>
10+
#include <linux/rtmutex.h>
1011
#include "internal.h"
1112

12-
static DEFINE_MUTEX(pmsg_lock);
13+
static DEFINE_RT_MUTEX(pmsg_lock);
1314

1415
static ssize_t write_pmsg(struct file *file, const char __user *buf,
1516
size_t count, loff_t *ppos)
@@ -28,9 +29,9 @@ static ssize_t write_pmsg(struct file *file, const char __user *buf,
2829
if (!access_ok(buf, count))
2930
return -EFAULT;
3031

31-
mutex_lock(&pmsg_lock);
32+
rt_mutex_lock(&pmsg_lock);
3233
ret = psinfo->write_user(&record, buf);
33-
mutex_unlock(&pmsg_lock);
34+
rt_mutex_unlock(&pmsg_lock);
3435
return ret ? ret : count;
3536
}
3637

0 commit comments

Comments
 (0)