Commit 0378b597 authored by Johan Hedberg's avatar Johan Hedberg Committed by Marcel Holtmann

Bluetooth: Convert link keys list to use RCU

This patch converts the hdev->link_keys list to be protected through
RCU, thereby eliminating the need to hold the hdev lock while accessing
the list.
Signed-off-by: default avatarJohan Hedberg <johan.hedberg@intel.com>
Signed-off-by: default avatarMarcel Holtmann <marcel@holtmann.org>
parent cb6f3f7a
...@@ -130,6 +130,7 @@ struct smp_irk { ...@@ -130,6 +130,7 @@ struct smp_irk {
struct link_key { struct link_key {
struct list_head list; struct list_head list;
struct rcu_head rcu;
bdaddr_t bdaddr; bdaddr_t bdaddr;
u8 type; u8 type;
u8 val[HCI_LINK_KEY_SIZE]; u8 val[HCI_LINK_KEY_SIZE];
......
...@@ -274,15 +274,13 @@ static const struct file_operations inquiry_cache_fops = { ...@@ -274,15 +274,13 @@ static const struct file_operations inquiry_cache_fops = {
static int link_keys_show(struct seq_file *f, void *ptr) static int link_keys_show(struct seq_file *f, void *ptr)
{ {
struct hci_dev *hdev = f->private; struct hci_dev *hdev = f->private;
struct list_head *p, *n; struct link_key *key;
hci_dev_lock(hdev); rcu_read_lock();
list_for_each_safe(p, n, &hdev->link_keys) { list_for_each_entry_rcu(key, &hdev->link_keys, list)
struct link_key *key = list_entry(p, struct link_key, list);
seq_printf(f, "%pMR %u %*phN %u\n", &key->bdaddr, key->type, seq_printf(f, "%pMR %u %*phN %u\n", &key->bdaddr, key->type,
HCI_LINK_KEY_SIZE, key->val, key->pin_len); HCI_LINK_KEY_SIZE, key->val, key->pin_len);
} rcu_read_unlock();
hci_dev_unlock(hdev);
return 0; return 0;
} }
...@@ -3101,15 +3099,11 @@ void hci_uuids_clear(struct hci_dev *hdev) ...@@ -3101,15 +3099,11 @@ void hci_uuids_clear(struct hci_dev *hdev)
void hci_link_keys_clear(struct hci_dev *hdev) void hci_link_keys_clear(struct hci_dev *hdev)
{ {
struct list_head *p, *n; struct link_key *key;
list_for_each_safe(p, n, &hdev->link_keys) {
struct link_key *key;
key = list_entry(p, struct link_key, list);
list_del(p); list_for_each_entry_rcu(key, &hdev->link_keys, list) {
kfree(key); list_del_rcu(&key->list);
kfree_rcu(key, rcu);
} }
} }
...@@ -3137,9 +3131,14 @@ struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) ...@@ -3137,9 +3131,14 @@ struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr)
{ {
struct link_key *k; struct link_key *k;
list_for_each_entry(k, &hdev->link_keys, list) rcu_read_lock();
if (bacmp(bdaddr, &k->bdaddr) == 0) list_for_each_entry_rcu(k, &hdev->link_keys, list) {
if (bacmp(bdaddr, &k->bdaddr) == 0) {
rcu_read_unlock();
return k; return k;
}
}
rcu_read_unlock();
return NULL; return NULL;
} }
...@@ -3290,7 +3289,7 @@ struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, ...@@ -3290,7 +3289,7 @@ struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn,
key = kzalloc(sizeof(*key), GFP_KERNEL); key = kzalloc(sizeof(*key), GFP_KERNEL);
if (!key) if (!key)
return NULL; return NULL;
list_add(&key->list, &hdev->link_keys); list_add_rcu(&key->list, &hdev->link_keys);
} }
BT_DBG("%s key for %pMR type %u", hdev->name, bdaddr, type); BT_DBG("%s key for %pMR type %u", hdev->name, bdaddr, type);
...@@ -3383,8 +3382,8 @@ int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) ...@@ -3383,8 +3382,8 @@ int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr)
BT_DBG("%s removing %pMR", hdev->name, bdaddr); BT_DBG("%s removing %pMR", hdev->name, bdaddr);
list_del(&key->list); list_del_rcu(&key->list);
kfree(key); kfree_rcu(key, rcu);
return 0; return 0;
} }
......
...@@ -3324,8 +3324,8 @@ static void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb) ...@@ -3324,8 +3324,8 @@ static void hci_link_key_notify_evt(struct hci_dev *hdev, struct sk_buff *skb)
*/ */
if (key->type == HCI_LK_DEBUG_COMBINATION && if (key->type == HCI_LK_DEBUG_COMBINATION &&
!test_bit(HCI_KEEP_DEBUG_KEYS, &hdev->dev_flags)) { !test_bit(HCI_KEEP_DEBUG_KEYS, &hdev->dev_flags)) {
list_del(&key->list); list_del_rcu(&key->list);
kfree(key); kfree_rcu(key, rcu);
} else if (conn) { } else if (conn) {
if (persistent) if (persistent)
clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags); clear_bit(HCI_CONN_FLUSH_KEY, &conn->flags);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment