drivers: target: target_core_device: Pass lockdep expression to RCU lists
Subsystems (2)
PATCH 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.
Add macro for the corresponding lockdep expression to make the code clean and concise.
--- drivers/target/target_core_device.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-)
drivers/target/target_core_device.c +12 -6
@@ -36,6 +36,9 @@#include "target_core_pr.h" #include "target_core_ua.h" +#define lun_entry_mutex_held () \ + lockdep_is_held(&nacl->lun_entry_mutex) +static DEFINE_MUTEX (device_mutex);static LIST_HEAD (device_list);static DEFINE_IDR (devices_idr);
@@ -247,9 +250,10 @@ 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, +lun_entry_mutex_held ()) {struct se_lun *lun =rcu_dereference_check (deve->se_lun, -lockdep_is_held (&nacl->lun_entry_mutex)); +lun_entry_mutex_held ());core_disable_device_list_for_node (lun, deve, nacl, tpg); }mutex_unlock (&nacl->lun_entry_mutex);
@@ -276,7 +280,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, +rcu_read_lock_held () ||lun_entry_mutex_held ())if (deve->mapped_lun == mapped_lun)return deve;
@@ -339,7 +344,7 @@ int core_enable_device_list_for_node( orig =target_nacl_find_deve (nacl, mapped_lun);if (orig && orig->se_lun) {struct se_lun *orig_lun =rcu_dereference_check (orig->se_lun, -lockdep_is_held (&nacl->lun_entry_mutex)); +lun_entry_mutex_held ());if (orig_lun != lun) { pr_err("Existing orig->se_lun doesn't match new lun"
@@ -460,9 +465,10 @@ 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, +lun_entry_mutex_held ()) {struct se_lun *tmp_lun =rcu_dereference_check (deve->se_lun, -lockdep_is_held (&nacl->lun_entry_mutex)); +lun_entry_mutex_held ());if (lun != tmp_lun)continue ;
Signature · 1 line
2.24.1
PATCH 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.
Add macro for the corresponding lockdep expression to make the code clean and concise.
--- drivers/target/target_core_tpg.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/target/target_core_tpg.c +6 -3
@@ -30,6 +30,9 @@#include "target_core_pr.h" #include "target_core_ua.h" +#define tpg_lun_mutex_held () \ + lockdep_is_held(&tpg->tpg_lun_mutex) +extern struct se_device *g_lun0_dev;/* __core_tpg_get_initiator_node_acl():
@@ -110,12 +113,12 @@ 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, +tpg_lun_mutex_held ()) {if (lun_orig && lun != lun_orig)continue ; - dev =rcu_dereference_check (lun->lun_se_dev, -lockdep_is_held (&tpg->tpg_lun_mutex)); + dev =rcu_dereference_check (lun->lun_se_dev,tpg_lun_mutex_held ());/* * By default in LIO-Target $FABRIC_MOD, * demo_mode_write_protect is ON, or READ_ONLY;
Signature · 1 line
2.24.1
PATCH 3/3 drivers: target: tcm_fc: tfc_sess: Pass lockdep expression to RCU lists
In reply to Amol Groverhead 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.
Add macro for the corresponding lockdep expression to make the code clean and concise.
--- drivers/target/tcm_fc/tfc_sess.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/target/tcm_fc/tfc_sess.c +9 -6
@@ -32,6 +32,9 @@ (lport)->host->host_no, \ (lport)->port_id, ##args ) +#define ft_lport_lock_held () \ + lockdep_is_held(&ft_lport_lock) +static void ft_sess_delete_all (struct ft_tport *);/*
@@ -45,7 +48,7 @@ static struct ft_tport *ft_tport_get(struct fc_lport *lport)int i; tport =rcu_dereference_protected (lport->prov[FC_TYPE_FCP ], -lockdep_is_held (&ft_lport_lock)); +ft_lport_lock_held ());if (tport && tport->tpg)return tport;
@@ -170,7 +173,7 @@ 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,ft_lport_lock_held ()) {if (sess->port_id == port_id) {kref_get (&sess->kref);rcu_read_unlock ();
@@ -215,7 +218,7 @@ 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,ft_lport_lock_held ())if (sess->port_id == port_id)return sess;
@@ -264,7 +267,7 @@ 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,ft_lport_lock_held ()) {if (sess->port_id == port_id) {ft_sess_unhash (sess);return sess;
@@ -291,7 +294,7 @@ 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,ft_lport_lock_held ()) {ft_sess_unhash (sess);ft_close_sess (sess);/* release from table */ }
@@ -454,7 +457,7 @@ static void ft_prlo(struct fc_rport_priv *rdata)mutex_lock (&ft_lport_lock); tport =rcu_dereference_protected (rdata->local_port->prov[FC_TYPE_FCP ], -lockdep_is_held (&ft_lport_lock)); +ft_lport_lock_held ());if (!tport) {mutex_unlock (&ft_lport_lock);
Signature · 1 line
2.24.1