summaryrefslogtreecommitdiffstats
path: root/mm/page_reporting.c
diff options
context:
space:
mode:
authorSeongJae Park <sj@kernel.org>2022-12-28 17:59:42 +0000
committerAndrew Morton <akpm@linux-foundation.org>2023-01-18 17:12:50 -0800
commit01b5022f0a8a2911bb8f2bc3f0c9b9b2c21c3316 (patch)
tree5b358fd606e1fe2fbb9adad9ef52d7fdecc97ad1 /mm/page_reporting.c
parent3783e1721b650588938d28e4a084a1c9748361c8 (diff)
downloadlinux-stable-01b5022f0a8a2911bb8f2bc3f0c9b9b2c21c3316.tar.gz
linux-stable-01b5022f0a8a2911bb8f2bc3f0c9b9b2c21c3316.tar.bz2
linux-stable-01b5022f0a8a2911bb8f2bc3f0c9b9b2c21c3316.zip
mm/page_reporting: replace rcu_access_pointer() with rcu_dereference_protected()
Page reporting fetches pr_dev_info using rcu_access_pointer(), which is for safely fetching a pointer that will not be dereferenced but could concurrently updated. The code indeed does not dereference pr_dev_info after fetching it using rcu_access_pointer(), but it fetches the pointer while concurrent updates to the pointer is avoided by holding the update side lock, page_reporting_mutex. In the case, rcu_dereference_protected() should be used instead because it provides better readability and performance on some cases, as rcu_dereference_protected() avoids use of READ_ONCE(). Replace the rcu_access_pointer() calls with rcu_dereference_protected(). Link: https://lkml.kernel.org/r/20221228175942.149491-1-sj@kernel.org Fixes: 36e66c554b5c ("mm: introduce Reported pages") Signed-off-by: SeongJae Park <sj@kernel.org> Cc: Alexander Duyck <alexander.h.duyck@linux.intel.com> Cc: Matthew Wilcox <willy@infradead.org> Cc: Miaohe Lin <linmiaohe@huawei.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'mm/page_reporting.c')
-rw-r--r--mm/page_reporting.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/mm/page_reporting.c b/mm/page_reporting.c
index 79a8554f024c..c65813a9dc78 100644
--- a/mm/page_reporting.c
+++ b/mm/page_reporting.c
@@ -356,7 +356,8 @@ int page_reporting_register(struct page_reporting_dev_info *prdev)
mutex_lock(&page_reporting_mutex);
/* nothing to do if already in use */
- if (rcu_access_pointer(pr_dev_info)) {
+ if (rcu_dereference_protected(pr_dev_info,
+ lockdep_is_held(&page_reporting_mutex))) {
err = -EBUSY;
goto err_out;
}
@@ -401,7 +402,8 @@ void page_reporting_unregister(struct page_reporting_dev_info *prdev)
{
mutex_lock(&page_reporting_mutex);
- if (rcu_access_pointer(pr_dev_info) == prdev) {
+ if (prdev == rcu_dereference_protected(pr_dev_info,
+ lockdep_is_held(&page_reporting_mutex))) {
/* Disable page reporting notification */
RCU_INIT_POINTER(pr_dev_info, NULL);
synchronize_rcu();