Skip to content

Commit

Permalink
mm/page_reporting: replace rcu_access_pointer() with rcu_dereference_…
Browse files Browse the repository at this point in the history
…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 fetcing it using rcu_access_pointer(), but it fetches the pointer
while concurrent updtes to the pointer is avoided by holding the update
side lock, page_reporting_mutex.

In the case, rcu_dereference_protected() is recommended 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().

Signed-off-by: SeongJae Park <sj@kernel.org>
  • Loading branch information
sjp38 authored and intel-lab-lkp committed Dec 28, 2022
1 parent 2281bdb commit f774480
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mm/page_reporting.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_order))) {
err = -EBUSY;
goto err_out;
}
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit f774480

Please sign in to comment.