Re: [PATCH] mm/page_reporting: replace rcu_access_pointer() with rcu_dereference_protected()

From: Matthew Wilcox
Date: Tue Dec 27 2022 - 14:55:46 EST


On Tue, Dec 27, 2022 at 07:21:58PM +0000, SeongJae Park wrote:
> +++ b/mm/page_reporting.c
> @@ -356,7 +356,7 @@ 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, true)) {

Pretty sure that passing a bare 'true' is an antipattern.
Instead, document _what_ lock protects us, ie:

if (rcu_dereference_protected(pr_dev_info,
lockdep_is_held(&page_reporting_mutex))) {

Obviously, we took it just one line up, but if code moves around, it
may save us.