2020-01-17 13:41:23

by Amol Grover

[permalink] [raw]
Subject: [PATCH v3 1/3] drivers: target: target_core_device: Pass lockdep expression to RCU lists

nacl->lun_entry_hlist is traversed with hlist_for_each_entry_rcu
outside an RCU read-side critical section but under the
protection of nacl->lun_entry_mutex.

Hence, add the corresponding lockdep expression to the list traversal
primitive to silence false-positive lockdep warnings, and
harden RCU lists.

Signed-off-by: Amol Grover <[email protected]>
---
v3:
- Remove rcu_read_lock_held() from lockdep expression since it is
implicitly checked for.
- Remove unintended macro usage.

v2:
- Fix sparse error
CHECK: Alignment should match open parenthesis

drivers/target/target_core_device.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
index 2d19f0e332b0..306c626183d5 100644
--- a/drivers/target/target_core_device.c
+++ b/drivers/target/target_core_device.c
@@ -247,7 +247,8 @@ void core_free_device_list_for_node(
struct se_dev_entry *deve;

mutex_lock(&nacl->lun_entry_mutex);
- hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) {
+ hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link,
+ lockdep_is_held(&nacl->lun_entry_mutex)) {
struct se_lun *lun = rcu_dereference_check(deve->se_lun,
lockdep_is_held(&nacl->lun_entry_mutex));
core_disable_device_list_for_node(lun, deve, nacl, tpg);
@@ -276,7 +277,8 @@ struct se_dev_entry *target_nacl_find_deve(struct se_node_acl *nacl, u64 mapped_
{
struct se_dev_entry *deve;

- hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link)
+ hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link,
+ lockdep_is_held(&nacl->lun_entry_mutex))
if (deve->mapped_lun == mapped_lun)
return deve;

@@ -460,7 +462,8 @@ void core_clear_lun_from_tpg(struct se_lun *lun, struct se_portal_group *tpg)
list_for_each_entry(nacl, &tpg->acl_node_list, acl_list) {

mutex_lock(&nacl->lun_entry_mutex);
- hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link) {
+ hlist_for_each_entry_rcu(deve, &nacl->lun_entry_hlist, link,
+ lockdep_is_held(&nacl->lun_entry_mutex)) {
struct se_lun *tmp_lun = rcu_dereference_check(deve->se_lun,
lockdep_is_held(&nacl->lun_entry_mutex));

--
2.24.1


2020-01-17 13:42:12

by Amol Grover

[permalink] [raw]
Subject: [PATCH v3 2/3] drivers: target: target_core_tpg: Pass lockdep expression to RCU lists

tpg->tpg_lun_hlist is traversed with hlist_for_each_entry_rcu
outside an RCU read-side critical section but under the
protection of tpg->tpg_lun_mutex.

Hence, add the corresponding lockdep expression to the list traversal
primitive to silence false-positive lockdep warnings, and
harden RCU lists.

Signed-off-by: Amol Grover <[email protected]>
---
drivers/target/target_core_tpg.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/target/target_core_tpg.c b/drivers/target/target_core_tpg.c
index d24e0a3ba3ff..7aa0240a7948 100644
--- a/drivers/target/target_core_tpg.c
+++ b/drivers/target/target_core_tpg.c
@@ -110,7 +110,8 @@ void core_tpg_add_node_to_devs(
struct se_device *dev;

mutex_lock(&tpg->tpg_lun_mutex);
- hlist_for_each_entry_rcu(lun, &tpg->tpg_lun_hlist, link) {
+ hlist_for_each_entry_rcu(lun, &tpg->tpg_lun_hlist, link,
+ lockdep_is_held(&tpg->tpg_lun_mutex)) {
if (lun_orig && lun != lun_orig)
continue;

--
2.24.1

2020-01-17 13:43:15

by Amol Grover

[permalink] [raw]
Subject: [PATCH v3 3/3] drivers: target: tcm_fc: tfc_sess: Pass lockdep expression to RCU lists

head is traversed with hlist_for_each_entry_rcu
outside an RCU read-side critical section but under the
protection of ft_lport_lock.

Hence, add the corresponding lockdep expression to the list traversal
primitive to silence false-positive lockdep warnings, and
harden RCU lists.

Signed-off-by: Amol Grover <[email protected]>
---
drivers/target/tcm_fc/tfc_sess.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/target/tcm_fc/tfc_sess.c b/drivers/target/tcm_fc/tfc_sess.c
index 4fd6a1de947c..bb70f61237a6 100644
--- a/drivers/target/tcm_fc/tfc_sess.c
+++ b/drivers/target/tcm_fc/tfc_sess.c
@@ -170,7 +170,8 @@ static struct ft_sess *ft_sess_get(struct fc_lport *lport, u32 port_id)
}

head = &tport->hash[ft_sess_hash(port_id)];
- hlist_for_each_entry_rcu(sess, head, hash) {
+ hlist_for_each_entry_rcu(sess, head, hash,
+ lockdep_is_held(&ft_lport_lock)) {
if (sess->port_id == port_id) {
kref_get(&sess->kref);
rcu_read_unlock();
@@ -215,7 +216,8 @@ static struct ft_sess *ft_sess_create(struct ft_tport *tport, u32 port_id,
ft_format_wwn(&initiatorname[0], TRANSPORT_IQN_LEN, rdata->ids.port_name);

head = &tport->hash[ft_sess_hash(port_id)];
- hlist_for_each_entry_rcu(sess, head, hash)
+ hlist_for_each_entry_rcu(sess, head, hash,
+ lockdep_is_held(&ft_lport_lock))
if (sess->port_id == port_id)
return sess;

@@ -264,7 +266,8 @@ static struct ft_sess *ft_sess_delete(struct ft_tport *tport, u32 port_id)
struct ft_sess *sess;

head = &tport->hash[ft_sess_hash(port_id)];
- hlist_for_each_entry_rcu(sess, head, hash) {
+ hlist_for_each_entry_rcu(sess, head, hash,
+ lockdep_is_held(&ft_lport_lock)) {
if (sess->port_id == port_id) {
ft_sess_unhash(sess);
return sess;
@@ -291,7 +294,8 @@ static void ft_sess_delete_all(struct ft_tport *tport)

for (head = tport->hash;
head < &tport->hash[FT_SESS_HASH_SIZE]; head++) {
- hlist_for_each_entry_rcu(sess, head, hash) {
+ hlist_for_each_entry_rcu(sess, head, hash,
+ lockdep_is_held(&ft_lport_lock)) {
ft_sess_unhash(sess);
ft_close_sess(sess); /* release from table */
}
--
2.24.1