* [PATCH v3] drivers: char: ipmi: ipmi_msghandler: Pass lockdep expression to RCU lists @ 2020-01-17 13:25 ` Amol Grover 0 siblings, 0 replies; 8+ messages in thread From: Amol Grover @ 2020-01-17 13:25 UTC (permalink / raw) To: Corey Minyard, Arnd Bergmann, Greg Kroah-Hartman Cc: openipmi-developer, linux-kernel, linux-kernel-mentees, Joel Fernandes, Madhuparna Bhowmik, Paul E . McKenney, Amol Grover intf->cmd_rcvrs is traversed with list_for_each_entry_rcu outside an RCU read-side critical section but under the protection of intf->cmd_rcvrs_mutex. ipmi_interfaces is traversed using list_for_each_entry_rcu outside an RCU read-side critical section but under the protection of ipmi_interfaces_mutex. Hence, add the corresponding lockdep expression to the list traversal primitive to silence false-positive lockdep warnings, and harden RCU lists. Add macro for the corresponding lockdep expression to make the code clean and concise. Signed-off-by: Amol Grover <frextrite@gmail.com> --- v3: - Remove rcu_read_lock_held() from lockdep expression since it is implicitly checked. - Remove unintended macro usage. v2: - Fix sparse error CHECK: Alignment should match open parenthesis drivers/char/ipmi/ipmi_msghandler.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c index cad9563f8f48..64ba16dcb681 100644 --- a/drivers/char/ipmi/ipmi_msghandler.c +++ b/drivers/char/ipmi/ipmi_msghandler.c @@ -618,6 +618,8 @@ static DEFINE_MUTEX(ipmidriver_mutex); static LIST_HEAD(ipmi_interfaces); static DEFINE_MUTEX(ipmi_interfaces_mutex); +#define ipmi_interfaces_mutex_held() \ + lockdep_is_held(&ipmi_interfaces_mutex) static struct srcu_struct ipmi_interfaces_srcu; /* @@ -1321,7 +1323,8 @@ static void _ipmi_destroy_user(struct ipmi_user *user) * synchronize_srcu()) then free everything in that list. */ mutex_lock(&intf->cmd_rcvrs_mutex); - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { if (rcvr->user == user) { list_del_rcu(&rcvr->link); rcvr->next = rcvrs; @@ -1599,7 +1602,8 @@ static struct cmd_rcvr *find_cmd_rcvr(struct ipmi_smi *intf, { struct cmd_rcvr *rcvr; - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) && (rcvr->chans & (1 << chan))) return rcvr; @@ -1614,7 +1618,8 @@ static int is_cmd_rcvr_exclusive(struct ipmi_smi *intf, { struct cmd_rcvr *rcvr; - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) && (rcvr->chans & chans)) return 0; @@ -3450,7 +3455,8 @@ int ipmi_add_smi(struct module *owner, /* Look for a hole in the numbers. */ i = 0; link = &ipmi_interfaces; - list_for_each_entry_rcu(tintf, &ipmi_interfaces, link) { + list_for_each_entry_rcu(tintf, &ipmi_interfaces, link, + ipmi_interfaces_mutex_held()) { if (tintf->intf_num != i) { link = &tintf->link; break; -- 2.24.1 ^ permalink raw reply related [flat|nested] 8+ messages in thread
* [Linux-kernel-mentees] [PATCH v3] drivers: char: ipmi: ipmi_msghandler: Pass lockdep expression to RCU lists @ 2020-01-17 13:25 ` Amol Grover 0 siblings, 0 replies; 8+ messages in thread From: Amol Grover @ 2020-01-17 13:25 UTC (permalink / raw) To: Corey Minyard, Arnd Bergmann, Greg Kroah-Hartman Cc: Paul E . McKenney, linux-kernel, Joel Fernandes, openipmi-developer, linux-kernel-mentees intf->cmd_rcvrs is traversed with list_for_each_entry_rcu outside an RCU read-side critical section but under the protection of intf->cmd_rcvrs_mutex. ipmi_interfaces is traversed using list_for_each_entry_rcu outside an RCU read-side critical section but under the protection of ipmi_interfaces_mutex. Hence, add the corresponding lockdep expression to the list traversal primitive to silence false-positive lockdep warnings, and harden RCU lists. Add macro for the corresponding lockdep expression to make the code clean and concise. Signed-off-by: Amol Grover <frextrite@gmail.com> --- v3: - Remove rcu_read_lock_held() from lockdep expression since it is implicitly checked. - Remove unintended macro usage. v2: - Fix sparse error CHECK: Alignment should match open parenthesis drivers/char/ipmi/ipmi_msghandler.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c index cad9563f8f48..64ba16dcb681 100644 --- a/drivers/char/ipmi/ipmi_msghandler.c +++ b/drivers/char/ipmi/ipmi_msghandler.c @@ -618,6 +618,8 @@ static DEFINE_MUTEX(ipmidriver_mutex); static LIST_HEAD(ipmi_interfaces); static DEFINE_MUTEX(ipmi_interfaces_mutex); +#define ipmi_interfaces_mutex_held() \ + lockdep_is_held(&ipmi_interfaces_mutex) static struct srcu_struct ipmi_interfaces_srcu; /* @@ -1321,7 +1323,8 @@ static void _ipmi_destroy_user(struct ipmi_user *user) * synchronize_srcu()) then free everything in that list. */ mutex_lock(&intf->cmd_rcvrs_mutex); - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { if (rcvr->user == user) { list_del_rcu(&rcvr->link); rcvr->next = rcvrs; @@ -1599,7 +1602,8 @@ static struct cmd_rcvr *find_cmd_rcvr(struct ipmi_smi *intf, { struct cmd_rcvr *rcvr; - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) && (rcvr->chans & (1 << chan))) return rcvr; @@ -1614,7 +1618,8 @@ static int is_cmd_rcvr_exclusive(struct ipmi_smi *intf, { struct cmd_rcvr *rcvr; - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) && (rcvr->chans & chans)) return 0; @@ -3450,7 +3455,8 @@ int ipmi_add_smi(struct module *owner, /* Look for a hole in the numbers. */ i = 0; link = &ipmi_interfaces; - list_for_each_entry_rcu(tintf, &ipmi_interfaces, link) { + list_for_each_entry_rcu(tintf, &ipmi_interfaces, link, + ipmi_interfaces_mutex_held()) { if (tintf->intf_num != i) { link = &tintf->link; break; -- 2.24.1 _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees ^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH v3] drivers: char: ipmi: ipmi_msghandler: Pass lockdep expression to RCU lists 2020-01-17 13:25 ` [Linux-kernel-mentees] " Amol Grover @ 2020-02-12 13:45 ` Corey Minyard -1 siblings, 0 replies; 8+ messages in thread From: Corey Minyard @ 2020-02-12 13:45 UTC (permalink / raw) To: Amol Grover Cc: Arnd Bergmann, Greg Kroah-Hartman, openipmi-developer, linux-kernel, linux-kernel-mentees, Joel Fernandes, Madhuparna Bhowmik, Paul E . McKenney On Fri, Jan 17, 2020 at 06:55:22PM +0530, Amol Grover wrote: > intf->cmd_rcvrs is traversed with list_for_each_entry_rcu > outside an RCU read-side critical section but under the > protection of intf->cmd_rcvrs_mutex. > > ipmi_interfaces is traversed using list_for_each_entry_rcu > outside an RCU read-side critical section but under the protection > of ipmi_interfaces_mutex. > > Hence, add the corresponding lockdep expression to the list traversal > primitive to silence false-positive lockdep warnings, and > harden RCU lists. > > Add macro for the corresponding lockdep expression to make the code > clean and concise. > > Signed-off-by: Amol Grover <frextrite@gmail.com> After reading everything, I think this is correct, but I would like Paul's stamp of approval on this. Thanks, -corey > --- > v3: > - Remove rcu_read_lock_held() from lockdep expression since it is > implicitly checked. > - Remove unintended macro usage. > > v2: > - Fix sparse error > CHECK: Alignment should match open parenthesis > > drivers/char/ipmi/ipmi_msghandler.c | 14 ++++++++++---- > 1 file changed, 10 insertions(+), 4 deletions(-) > > diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c > index cad9563f8f48..64ba16dcb681 100644 > --- a/drivers/char/ipmi/ipmi_msghandler.c > +++ b/drivers/char/ipmi/ipmi_msghandler.c > @@ -618,6 +618,8 @@ static DEFINE_MUTEX(ipmidriver_mutex); > > static LIST_HEAD(ipmi_interfaces); > static DEFINE_MUTEX(ipmi_interfaces_mutex); > +#define ipmi_interfaces_mutex_held() \ > + lockdep_is_held(&ipmi_interfaces_mutex) > static struct srcu_struct ipmi_interfaces_srcu; > > /* > @@ -1321,7 +1323,8 @@ static void _ipmi_destroy_user(struct ipmi_user *user) > * synchronize_srcu()) then free everything in that list. > */ > mutex_lock(&intf->cmd_rcvrs_mutex); > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > if (rcvr->user == user) { > list_del_rcu(&rcvr->link); > rcvr->next = rcvrs; > @@ -1599,7 +1602,8 @@ static struct cmd_rcvr *find_cmd_rcvr(struct ipmi_smi *intf, > { > struct cmd_rcvr *rcvr; > > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) > && (rcvr->chans & (1 << chan))) > return rcvr; > @@ -1614,7 +1618,8 @@ static int is_cmd_rcvr_exclusive(struct ipmi_smi *intf, > { > struct cmd_rcvr *rcvr; > > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) > && (rcvr->chans & chans)) > return 0; > @@ -3450,7 +3455,8 @@ int ipmi_add_smi(struct module *owner, > /* Look for a hole in the numbers. */ > i = 0; > link = &ipmi_interfaces; > - list_for_each_entry_rcu(tintf, &ipmi_interfaces, link) { > + list_for_each_entry_rcu(tintf, &ipmi_interfaces, link, > + ipmi_interfaces_mutex_held()) { > if (tintf->intf_num != i) { > link = &tintf->link; > break; > -- > 2.24.1 > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH v3] drivers: char: ipmi: ipmi_msghandler: Pass lockdep expression to RCU lists @ 2020-02-12 13:45 ` Corey Minyard 0 siblings, 0 replies; 8+ messages in thread From: Corey Minyard @ 2020-02-12 13:45 UTC (permalink / raw) To: Amol Grover Cc: Paul E . McKenney, Arnd Bergmann, linux-kernel, Joel Fernandes, openipmi-developer, linux-kernel-mentees On Fri, Jan 17, 2020 at 06:55:22PM +0530, Amol Grover wrote: > intf->cmd_rcvrs is traversed with list_for_each_entry_rcu > outside an RCU read-side critical section but under the > protection of intf->cmd_rcvrs_mutex. > > ipmi_interfaces is traversed using list_for_each_entry_rcu > outside an RCU read-side critical section but under the protection > of ipmi_interfaces_mutex. > > Hence, add the corresponding lockdep expression to the list traversal > primitive to silence false-positive lockdep warnings, and > harden RCU lists. > > Add macro for the corresponding lockdep expression to make the code > clean and concise. > > Signed-off-by: Amol Grover <frextrite@gmail.com> After reading everything, I think this is correct, but I would like Paul's stamp of approval on this. Thanks, -corey > --- > v3: > - Remove rcu_read_lock_held() from lockdep expression since it is > implicitly checked. > - Remove unintended macro usage. > > v2: > - Fix sparse error > CHECK: Alignment should match open parenthesis > > drivers/char/ipmi/ipmi_msghandler.c | 14 ++++++++++---- > 1 file changed, 10 insertions(+), 4 deletions(-) > > diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c > index cad9563f8f48..64ba16dcb681 100644 > --- a/drivers/char/ipmi/ipmi_msghandler.c > +++ b/drivers/char/ipmi/ipmi_msghandler.c > @@ -618,6 +618,8 @@ static DEFINE_MUTEX(ipmidriver_mutex); > > static LIST_HEAD(ipmi_interfaces); > static DEFINE_MUTEX(ipmi_interfaces_mutex); > +#define ipmi_interfaces_mutex_held() \ > + lockdep_is_held(&ipmi_interfaces_mutex) > static struct srcu_struct ipmi_interfaces_srcu; > > /* > @@ -1321,7 +1323,8 @@ static void _ipmi_destroy_user(struct ipmi_user *user) > * synchronize_srcu()) then free everything in that list. > */ > mutex_lock(&intf->cmd_rcvrs_mutex); > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > if (rcvr->user == user) { > list_del_rcu(&rcvr->link); > rcvr->next = rcvrs; > @@ -1599,7 +1602,8 @@ static struct cmd_rcvr *find_cmd_rcvr(struct ipmi_smi *intf, > { > struct cmd_rcvr *rcvr; > > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) > && (rcvr->chans & (1 << chan))) > return rcvr; > @@ -1614,7 +1618,8 @@ static int is_cmd_rcvr_exclusive(struct ipmi_smi *intf, > { > struct cmd_rcvr *rcvr; > > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) > && (rcvr->chans & chans)) > return 0; > @@ -3450,7 +3455,8 @@ int ipmi_add_smi(struct module *owner, > /* Look for a hole in the numbers. */ > i = 0; > link = &ipmi_interfaces; > - list_for_each_entry_rcu(tintf, &ipmi_interfaces, link) { > + list_for_each_entry_rcu(tintf, &ipmi_interfaces, link, > + ipmi_interfaces_mutex_held()) { > if (tintf->intf_num != i) { > link = &tintf->link; > break; > -- > 2.24.1 > _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] drivers: char: ipmi: ipmi_msghandler: Pass lockdep expression to RCU lists 2020-02-12 13:45 ` [Linux-kernel-mentees] " Corey Minyard @ 2020-02-12 21:49 ` Paul E. McKenney -1 siblings, 0 replies; 8+ messages in thread From: Paul E. McKenney @ 2020-02-12 21:49 UTC (permalink / raw) To: Corey Minyard Cc: Amol Grover, Arnd Bergmann, Greg Kroah-Hartman, openipmi-developer, linux-kernel, linux-kernel-mentees, Joel Fernandes, Madhuparna Bhowmik On Wed, Feb 12, 2020 at 07:45:52AM -0600, Corey Minyard wrote: > On Fri, Jan 17, 2020 at 06:55:22PM +0530, Amol Grover wrote: > > intf->cmd_rcvrs is traversed with list_for_each_entry_rcu > > outside an RCU read-side critical section but under the > > protection of intf->cmd_rcvrs_mutex. > > > > ipmi_interfaces is traversed using list_for_each_entry_rcu > > outside an RCU read-side critical section but under the protection > > of ipmi_interfaces_mutex. > > > > Hence, add the corresponding lockdep expression to the list traversal > > primitive to silence false-positive lockdep warnings, and > > harden RCU lists. > > > > Add macro for the corresponding lockdep expression to make the code > > clean and concise. > > > > Signed-off-by: Amol Grover <frextrite@gmail.com> > > After reading everything, I think this is correct, but I would like > Paul's stamp of approval on this. Acked-by: Paul E. McKenney <paulmck@kernel.org> But note that I did not trace the locking in the case of ipmi_add_smi(). I did the others, so lockdep can do the last one. ;-) Thanx, Paul > Thanks, > > -corey > > > --- > > v3: > > - Remove rcu_read_lock_held() from lockdep expression since it is > > implicitly checked. > > - Remove unintended macro usage. > > > > v2: > > - Fix sparse error > > CHECK: Alignment should match open parenthesis > > > > drivers/char/ipmi/ipmi_msghandler.c | 14 ++++++++++---- > > 1 file changed, 10 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c > > index cad9563f8f48..64ba16dcb681 100644 > > --- a/drivers/char/ipmi/ipmi_msghandler.c > > +++ b/drivers/char/ipmi/ipmi_msghandler.c > > @@ -618,6 +618,8 @@ static DEFINE_MUTEX(ipmidriver_mutex); > > > > static LIST_HEAD(ipmi_interfaces); > > static DEFINE_MUTEX(ipmi_interfaces_mutex); > > +#define ipmi_interfaces_mutex_held() \ > > + lockdep_is_held(&ipmi_interfaces_mutex) > > static struct srcu_struct ipmi_interfaces_srcu; > > > > /* > > @@ -1321,7 +1323,8 @@ static void _ipmi_destroy_user(struct ipmi_user *user) > > * synchronize_srcu()) then free everything in that list. > > */ > > mutex_lock(&intf->cmd_rcvrs_mutex); > > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > > if (rcvr->user == user) { > > list_del_rcu(&rcvr->link); > > rcvr->next = rcvrs; > > @@ -1599,7 +1602,8 @@ static struct cmd_rcvr *find_cmd_rcvr(struct ipmi_smi *intf, > > { > > struct cmd_rcvr *rcvr; > > > > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > > if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) > > && (rcvr->chans & (1 << chan))) > > return rcvr; > > @@ -1614,7 +1618,8 @@ static int is_cmd_rcvr_exclusive(struct ipmi_smi *intf, > > { > > struct cmd_rcvr *rcvr; > > > > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > > if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) > > && (rcvr->chans & chans)) > > return 0; > > @@ -3450,7 +3455,8 @@ int ipmi_add_smi(struct module *owner, > > /* Look for a hole in the numbers. */ > > i = 0; > > link = &ipmi_interfaces; > > - list_for_each_entry_rcu(tintf, &ipmi_interfaces, link) { > > + list_for_each_entry_rcu(tintf, &ipmi_interfaces, link, > > + ipmi_interfaces_mutex_held()) { > > if (tintf->intf_num != i) { > > link = &tintf->link; > > break; > > -- > > 2.24.1 > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH v3] drivers: char: ipmi: ipmi_msghandler: Pass lockdep expression to RCU lists @ 2020-02-12 21:49 ` Paul E. McKenney 0 siblings, 0 replies; 8+ messages in thread From: Paul E. McKenney @ 2020-02-12 21:49 UTC (permalink / raw) To: Corey Minyard Cc: Arnd Bergmann, linux-kernel, Joel Fernandes, openipmi-developer, linux-kernel-mentees On Wed, Feb 12, 2020 at 07:45:52AM -0600, Corey Minyard wrote: > On Fri, Jan 17, 2020 at 06:55:22PM +0530, Amol Grover wrote: > > intf->cmd_rcvrs is traversed with list_for_each_entry_rcu > > outside an RCU read-side critical section but under the > > protection of intf->cmd_rcvrs_mutex. > > > > ipmi_interfaces is traversed using list_for_each_entry_rcu > > outside an RCU read-side critical section but under the protection > > of ipmi_interfaces_mutex. > > > > Hence, add the corresponding lockdep expression to the list traversal > > primitive to silence false-positive lockdep warnings, and > > harden RCU lists. > > > > Add macro for the corresponding lockdep expression to make the code > > clean and concise. > > > > Signed-off-by: Amol Grover <frextrite@gmail.com> > > After reading everything, I think this is correct, but I would like > Paul's stamp of approval on this. Acked-by: Paul E. McKenney <paulmck@kernel.org> But note that I did not trace the locking in the case of ipmi_add_smi(). I did the others, so lockdep can do the last one. ;-) Thanx, Paul > Thanks, > > -corey > > > --- > > v3: > > - Remove rcu_read_lock_held() from lockdep expression since it is > > implicitly checked. > > - Remove unintended macro usage. > > > > v2: > > - Fix sparse error > > CHECK: Alignment should match open parenthesis > > > > drivers/char/ipmi/ipmi_msghandler.c | 14 ++++++++++---- > > 1 file changed, 10 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c > > index cad9563f8f48..64ba16dcb681 100644 > > --- a/drivers/char/ipmi/ipmi_msghandler.c > > +++ b/drivers/char/ipmi/ipmi_msghandler.c > > @@ -618,6 +618,8 @@ static DEFINE_MUTEX(ipmidriver_mutex); > > > > static LIST_HEAD(ipmi_interfaces); > > static DEFINE_MUTEX(ipmi_interfaces_mutex); > > +#define ipmi_interfaces_mutex_held() \ > > + lockdep_is_held(&ipmi_interfaces_mutex) > > static struct srcu_struct ipmi_interfaces_srcu; > > > > /* > > @@ -1321,7 +1323,8 @@ static void _ipmi_destroy_user(struct ipmi_user *user) > > * synchronize_srcu()) then free everything in that list. > > */ > > mutex_lock(&intf->cmd_rcvrs_mutex); > > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > > if (rcvr->user == user) { > > list_del_rcu(&rcvr->link); > > rcvr->next = rcvrs; > > @@ -1599,7 +1602,8 @@ static struct cmd_rcvr *find_cmd_rcvr(struct ipmi_smi *intf, > > { > > struct cmd_rcvr *rcvr; > > > > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > > if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) > > && (rcvr->chans & (1 << chan))) > > return rcvr; > > @@ -1614,7 +1618,8 @@ static int is_cmd_rcvr_exclusive(struct ipmi_smi *intf, > > { > > struct cmd_rcvr *rcvr; > > > > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > > if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) > > && (rcvr->chans & chans)) > > return 0; > > @@ -3450,7 +3455,8 @@ int ipmi_add_smi(struct module *owner, > > /* Look for a hole in the numbers. */ > > i = 0; > > link = &ipmi_interfaces; > > - list_for_each_entry_rcu(tintf, &ipmi_interfaces, link) { > > + list_for_each_entry_rcu(tintf, &ipmi_interfaces, link, > > + ipmi_interfaces_mutex_held()) { > > if (tintf->intf_num != i) { > > link = &tintf->link; > > break; > > -- > > 2.24.1 > > _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v3] drivers: char: ipmi: ipmi_msghandler: Pass lockdep expression to RCU lists 2020-02-12 21:49 ` [Linux-kernel-mentees] " Paul E. McKenney @ 2020-02-13 13:04 ` Corey Minyard -1 siblings, 0 replies; 8+ messages in thread From: Corey Minyard @ 2020-02-13 13:04 UTC (permalink / raw) To: Paul E. McKenney Cc: Amol Grover, Arnd Bergmann, Greg Kroah-Hartman, openipmi-developer, linux-kernel, linux-kernel-mentees, Joel Fernandes, Madhuparna Bhowmik On Wed, Feb 12, 2020 at 01:49:56PM -0800, Paul E. McKenney wrote: > On Wed, Feb 12, 2020 at 07:45:52AM -0600, Corey Minyard wrote: > > On Fri, Jan 17, 2020 at 06:55:22PM +0530, Amol Grover wrote: > > > intf->cmd_rcvrs is traversed with list_for_each_entry_rcu > > > outside an RCU read-side critical section but under the > > > protection of intf->cmd_rcvrs_mutex. > > > > > > ipmi_interfaces is traversed using list_for_each_entry_rcu > > > outside an RCU read-side critical section but under the protection > > > of ipmi_interfaces_mutex. > > > > > > Hence, add the corresponding lockdep expression to the list traversal > > > primitive to silence false-positive lockdep warnings, and > > > harden RCU lists. > > > > > > Add macro for the corresponding lockdep expression to make the code > > > clean and concise. > > > > > > Signed-off-by: Amol Grover <frextrite@gmail.com> > > > > After reading everything, I think this is correct, but I would like > > Paul's stamp of approval on this. > > Acked-by: Paul E. McKenney <paulmck@kernel.org> > > But note that I did not trace the locking in the case of ipmi_add_smi(). > I did the others, so lockdep can do the last one. ;-) Thanks, it's in my queue for 5.7. -corey > > Thanx, Paul > > > Thanks, > > > > -corey > > > > > --- > > > v3: > > > - Remove rcu_read_lock_held() from lockdep expression since it is > > > implicitly checked. > > > - Remove unintended macro usage. > > > > > > v2: > > > - Fix sparse error > > > CHECK: Alignment should match open parenthesis > > > > > > drivers/char/ipmi/ipmi_msghandler.c | 14 ++++++++++---- > > > 1 file changed, 10 insertions(+), 4 deletions(-) > > > > > > diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c > > > index cad9563f8f48..64ba16dcb681 100644 > > > --- a/drivers/char/ipmi/ipmi_msghandler.c > > > +++ b/drivers/char/ipmi/ipmi_msghandler.c > > > @@ -618,6 +618,8 @@ static DEFINE_MUTEX(ipmidriver_mutex); > > > > > > static LIST_HEAD(ipmi_interfaces); > > > static DEFINE_MUTEX(ipmi_interfaces_mutex); > > > +#define ipmi_interfaces_mutex_held() \ > > > + lockdep_is_held(&ipmi_interfaces_mutex) > > > static struct srcu_struct ipmi_interfaces_srcu; > > > > > > /* > > > @@ -1321,7 +1323,8 @@ static void _ipmi_destroy_user(struct ipmi_user *user) > > > * synchronize_srcu()) then free everything in that list. > > > */ > > > mutex_lock(&intf->cmd_rcvrs_mutex); > > > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > > > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > > > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > > > if (rcvr->user == user) { > > > list_del_rcu(&rcvr->link); > > > rcvr->next = rcvrs; > > > @@ -1599,7 +1602,8 @@ static struct cmd_rcvr *find_cmd_rcvr(struct ipmi_smi *intf, > > > { > > > struct cmd_rcvr *rcvr; > > > > > > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > > > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > > > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > > > if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) > > > && (rcvr->chans & (1 << chan))) > > > return rcvr; > > > @@ -1614,7 +1618,8 @@ static int is_cmd_rcvr_exclusive(struct ipmi_smi *intf, > > > { > > > struct cmd_rcvr *rcvr; > > > > > > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > > > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > > > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > > > if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) > > > && (rcvr->chans & chans)) > > > return 0; > > > @@ -3450,7 +3455,8 @@ int ipmi_add_smi(struct module *owner, > > > /* Look for a hole in the numbers. */ > > > i = 0; > > > link = &ipmi_interfaces; > > > - list_for_each_entry_rcu(tintf, &ipmi_interfaces, link) { > > > + list_for_each_entry_rcu(tintf, &ipmi_interfaces, link, > > > + ipmi_interfaces_mutex_held()) { > > > if (tintf->intf_num != i) { > > > link = &tintf->link; > > > break; > > > -- > > > 2.24.1 > > > ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Linux-kernel-mentees] [PATCH v3] drivers: char: ipmi: ipmi_msghandler: Pass lockdep expression to RCU lists @ 2020-02-13 13:04 ` Corey Minyard 0 siblings, 0 replies; 8+ messages in thread From: Corey Minyard @ 2020-02-13 13:04 UTC (permalink / raw) To: Paul E. McKenney Cc: Arnd Bergmann, linux-kernel, Joel Fernandes, openipmi-developer, linux-kernel-mentees On Wed, Feb 12, 2020 at 01:49:56PM -0800, Paul E. McKenney wrote: > On Wed, Feb 12, 2020 at 07:45:52AM -0600, Corey Minyard wrote: > > On Fri, Jan 17, 2020 at 06:55:22PM +0530, Amol Grover wrote: > > > intf->cmd_rcvrs is traversed with list_for_each_entry_rcu > > > outside an RCU read-side critical section but under the > > > protection of intf->cmd_rcvrs_mutex. > > > > > > ipmi_interfaces is traversed using list_for_each_entry_rcu > > > outside an RCU read-side critical section but under the protection > > > of ipmi_interfaces_mutex. > > > > > > Hence, add the corresponding lockdep expression to the list traversal > > > primitive to silence false-positive lockdep warnings, and > > > harden RCU lists. > > > > > > Add macro for the corresponding lockdep expression to make the code > > > clean and concise. > > > > > > Signed-off-by: Amol Grover <frextrite@gmail.com> > > > > After reading everything, I think this is correct, but I would like > > Paul's stamp of approval on this. > > Acked-by: Paul E. McKenney <paulmck@kernel.org> > > But note that I did not trace the locking in the case of ipmi_add_smi(). > I did the others, so lockdep can do the last one. ;-) Thanks, it's in my queue for 5.7. -corey > > Thanx, Paul > > > Thanks, > > > > -corey > > > > > --- > > > v3: > > > - Remove rcu_read_lock_held() from lockdep expression since it is > > > implicitly checked. > > > - Remove unintended macro usage. > > > > > > v2: > > > - Fix sparse error > > > CHECK: Alignment should match open parenthesis > > > > > > drivers/char/ipmi/ipmi_msghandler.c | 14 ++++++++++---- > > > 1 file changed, 10 insertions(+), 4 deletions(-) > > > > > > diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c > > > index cad9563f8f48..64ba16dcb681 100644 > > > --- a/drivers/char/ipmi/ipmi_msghandler.c > > > +++ b/drivers/char/ipmi/ipmi_msghandler.c > > > @@ -618,6 +618,8 @@ static DEFINE_MUTEX(ipmidriver_mutex); > > > > > > static LIST_HEAD(ipmi_interfaces); > > > static DEFINE_MUTEX(ipmi_interfaces_mutex); > > > +#define ipmi_interfaces_mutex_held() \ > > > + lockdep_is_held(&ipmi_interfaces_mutex) > > > static struct srcu_struct ipmi_interfaces_srcu; > > > > > > /* > > > @@ -1321,7 +1323,8 @@ static void _ipmi_destroy_user(struct ipmi_user *user) > > > * synchronize_srcu()) then free everything in that list. > > > */ > > > mutex_lock(&intf->cmd_rcvrs_mutex); > > > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > > > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > > > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > > > if (rcvr->user == user) { > > > list_del_rcu(&rcvr->link); > > > rcvr->next = rcvrs; > > > @@ -1599,7 +1602,8 @@ static struct cmd_rcvr *find_cmd_rcvr(struct ipmi_smi *intf, > > > { > > > struct cmd_rcvr *rcvr; > > > > > > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > > > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > > > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > > > if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) > > > && (rcvr->chans & (1 << chan))) > > > return rcvr; > > > @@ -1614,7 +1618,8 @@ static int is_cmd_rcvr_exclusive(struct ipmi_smi *intf, > > > { > > > struct cmd_rcvr *rcvr; > > > > > > - list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link) { > > > + list_for_each_entry_rcu(rcvr, &intf->cmd_rcvrs, link, > > > + lockdep_is_held(&intf->cmd_rcvrs_mutex)) { > > > if ((rcvr->netfn == netfn) && (rcvr->cmd == cmd) > > > && (rcvr->chans & chans)) > > > return 0; > > > @@ -3450,7 +3455,8 @@ int ipmi_add_smi(struct module *owner, > > > /* Look for a hole in the numbers. */ > > > i = 0; > > > link = &ipmi_interfaces; > > > - list_for_each_entry_rcu(tintf, &ipmi_interfaces, link) { > > > + list_for_each_entry_rcu(tintf, &ipmi_interfaces, link, > > > + ipmi_interfaces_mutex_held()) { > > > if (tintf->intf_num != i) { > > > link = &tintf->link; > > > break; > > > -- > > > 2.24.1 > > > _______________________________________________ Linux-kernel-mentees mailing list Linux-kernel-mentees@lists.linuxfoundation.org https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-02-13 13:04 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-01-17 13:25 [PATCH v3] drivers: char: ipmi: ipmi_msghandler: Pass lockdep expression to RCU lists Amol Grover 2020-01-17 13:25 ` [Linux-kernel-mentees] " Amol Grover 2020-02-12 13:45 ` Corey Minyard 2020-02-12 13:45 ` [Linux-kernel-mentees] " Corey Minyard 2020-02-12 21:49 ` Paul E. McKenney 2020-02-12 21:49 ` [Linux-kernel-mentees] " Paul E. McKenney 2020-02-13 13:04 ` Corey Minyard 2020-02-13 13:04 ` [Linux-kernel-mentees] " Corey Minyard
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.