[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240812183519.57314-1-kuniyu@amazon.com>
Date: Mon, 12 Aug 2024 11:35:19 -0700
From: Kuniyuki Iwashima <kuniyu@...zon.com>
To: <vineeth.karumanchi@....com>
CC: <claudiu.beznea@...on.dev>, <davem@...emloft.net>, <edumazet@...gle.com>,
<kuba@...nel.org>, <kuni1840@...il.com>, <kuniyu@...zon.com>,
<netdev@...r.kernel.org>, <nicolas.ferre@...rochip.com>, <pabeni@...hat.com>
Subject: Re: [PATCH v1 net] net: macb: Use rcu_dereference() for idev->ifa_list in macb_suspend().
From: Vineeth Karumanchi <vineeth.karumanchi@....com>
Date: Mon, 12 Aug 2024 14:41:40 +0530
> On 08/08/24 10:15 am, Kuniyuki Iwashima wrote:
> > From: Vineeth Karumanchi <vineeth.karumanchi@....com>
> > Date: Thu, 8 Aug 2024 09:53:42 +0530
> >> Hi Kuniyuki,
> >>
> >> On 08/08/24 9:30 am, Kuniyuki Iwashima wrote:
> >>> In macb_suspend(), idev->ifa_list is fetched with rcu_access_pointer()
> >>> and later the pointer is dereferenced as ifa->ifa_local.
> >>>
> >>> So, idev->ifa_list must be fetched with rcu_dereference().
> >>>
> >>
> >> Is there any functional breakage ?
> >
> > rcu_dereference() triggers lockdep splat if not called under
> > rcu_read_lock().
> >
> > Also in include/linux/rcupdate.h:
> >
> > /**
> > * rcu_access_pointer() - fetch RCU pointer with no dereferencing
> > ...
> > * It is usually best to test the rcu_access_pointer() return value
> > * directly in order to avoid accidental dereferences being introduced
> > * by later inattentive changes. In other words, assigning the
> > * rcu_access_pointer() return value to a local variable results in an
> > * accident waiting to happen.
> >
> >
> >> I sent initial patch with rcu_dereference, but there is a review comment:
> >>
> >> https://lore.kernel.org/netdev/a02fac3b21a97dc766d65c4ed2d080f1ed87e87e.camel@redhat.com/
> >
> > I guess the following ifa_local was missed then ?
>
> I am ok to use rcu_dereference(), just curios why the check
> idev->ifa_list was removed ?
"if (idev->ifa_list)" could fetch an invalid pointer due to lack of
READ_ONCE(), it's not a big problem, but neither we should write it as
if (rcu_assign_pointer(idev->ifa_list))
ifa = rcu_dereference(idev->ifa_list)
because rcu_dereference()ed ifa is not guaranteed as the same value
(non-NULL) with rcu_assign_pointer(), so we need the following check
anyway:
if (!ifa)
Basically, we can't use rcu_assign_pointer() with rcu_dereference().
list_first_or_null_rcu() is a nice example:
include/linux/rculist.h
/*
* Where are list_empty_rcu() and list_first_entry_rcu()?
*
* They do not exist because they would lead to subtle race conditions:
*
* if (!list_empty_rcu(mylist)) {
* struct foo *bar = list_first_entry_rcu(mylist, struct foo, list_member);
* do_something(bar);
* }
*
* The list might be non-empty when list_empty_rcu() checks it, but it
* might have become empty by the time that list_first_entry_rcu() rereads
* the ->next pointer, which would result in a SEGV.
Powered by blists - more mailing lists