Commit 76d62f24 authored by John Stultz's avatar John Stultz Committed by Kees Cook

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 <wvw@google.com>
Cc: Midas Chien<midaschieh@google.com>
Cc: Connor O'Brien <connoro@google.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Anton Vorontsov <anton@enomsg.org>
Cc: Colin Cross <ccross@android.com>
Cc: Tony Luck <tony.luck@intel.com>
Cc: kernel-team@android.com
Fixes: 9d5438f4 ("pstore: Add pmsg - user-space accessible pstore object")
Reported-by: default avatarWei Wang <wvw@google.com>
Signed-off-by: default avatarJohn Stultz <jstultz@google.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20221214231834.3711880-1-jstultz@google.com
parent e6b84274
...@@ -7,9 +7,10 @@ ...@@ -7,9 +7,10 @@
#include <linux/device.h> #include <linux/device.h>
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/rtmutex.h>
#include "internal.h" #include "internal.h"
static DEFINE_MUTEX(pmsg_lock); static DEFINE_RT_MUTEX(pmsg_lock);
static ssize_t write_pmsg(struct file *file, const char __user *buf, static ssize_t write_pmsg(struct file *file, const char __user *buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
...@@ -28,9 +29,9 @@ static ssize_t write_pmsg(struct file *file, const char __user *buf, ...@@ -28,9 +29,9 @@ static ssize_t write_pmsg(struct file *file, const char __user *buf,
if (!access_ok(buf, count)) if (!access_ok(buf, count))
return -EFAULT; return -EFAULT;
mutex_lock(&pmsg_lock); rt_mutex_lock(&pmsg_lock);
ret = psinfo->write_user(&record, buf); ret = psinfo->write_user(&record, buf);
mutex_unlock(&pmsg_lock); rt_mutex_unlock(&pmsg_lock);
return ret ? ret : count; return ret ? ret : count;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment