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

From: SeongJae Park
Date: Tue Dec 27 2022 - 14:57:09 EST


On Tue, 27 Dec 2022 19:55:09 +0000 Matthew Wilcox <willy@xxxxxxxxxxxxx> wrote:

> 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.

Good point, agreed. Will do so in the next version.


Thanks,
SJ