Skip to contentSkip to conversation

Bluetooth: Use zero timeout for immediate scheduling

PATCH In review [email protected] 2 participants 8 messages Aug 17, 2014

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 Bluetooth: Use zero timeout for immediate scheduling

From: Johan Hedberg <[email protected]>

There's no point in passing a "small" timeout to queue_delayed_work() to try to get the callback faster scheduled. Passing 0 is perfectly valid and will cause a shortcut to a direct queue_work().

---
 include/net/bluetooth/hci_core.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/net/bluetooth/hci_core.h +2 -2
index aa75eee8ad7f..18c24f6fce6c 100644
@@ -791,7 +791,7 @@ static inline void hci_conn_drop(struct hci_conn *conn)
 				if (!conn->out)
 					timeo *= 2;
 			} else {
-				timeo = msecs_to_jiffies(10);
+				timeo = 0;
 			}
 			break;
 
@@ -800,7 +800,7 @@ static inline void hci_conn_drop(struct hci_conn *conn)
 			break;
 
 		default:
-			timeo = msecs_to_jiffies(10);
+			timeo = 0;
 			break;
 		}
 
Signature · 1 line
1.9.3
#1 lore raw

PATCH 2/4 Bluetooth: Fix hci_conn reference counting with hci_chan

From: Johan Hedberg <[email protected]>

The hci_chan_del() function was doing a hci_conn_drop() but there was no matching hci_conn_hold() in the hci_chan_create() function. Furthermore, as the hci_chan struct holds a pointer to the hci_conn there should be proper use of hci_conn_get/put. This patch fixes both issues so that hci_chan does correct reference counting of the hci_conn object.

---
 net/bluetooth/hci_conn.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/bluetooth/hci_conn.c +3 -1
index 4ecc9d5fce7a..7815826a48e4 100644
@@ -1295,7 +1295,8 @@ struct hci_chan *hci_chan_create(struct hci_conn *conn)
 	if (!chan)
 		return NULL;
 
-	chan->conn = conn;
+	chan->conn = hci_conn_get(conn);
+	hci_conn_hold(conn);
 	skb_queue_head_init(&chan->data_q);
 	chan->state = BT_CONNECTED;
 
@@ -1316,6 +1317,7 @@ void hci_chan_del(struct hci_chan *chan)
 	synchronize_rcu();
 
 	hci_conn_drop(conn);
+	hci_conn_put(conn);
 
 	skb_queue_purge(&chan->data_q);
 	kfree(chan);
Signature · 1 line
1.9.3
maintainer
#2 lore raw

Re: [PATCH 2/4] Bluetooth: Fix hci_conn reference counting with hci_chan

Hi Johan,

Quoted 10 lines

The hci_chan_del() function was doing a hci_conn_drop() but there was no matching hci_conn_hold() in the hci_chan_create() function. Furthermore, as the hci_chan struct holds a pointer to the hci_conn there should be proper use of hci_conn_get/put. This patch fixes both issues so that hci_chan does correct reference counting of the hci_conn object.

---
net/bluetooth/hci_conn.c | 4 +++-

1 file changed, 3 insertions(+), 1 deletion(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel

#3 lore raw

PATCH 3/4 Bluetooth: Set disc_timeout to 0 when calling hci_chan_del

In reply to [email protected]

From: Johan Hedberg <[email protected]>

The hci_chan_del() function is used in scenarios where we've decided we want to get rid of the underlying baseband link. It makes therefore sense to force the disc_timeout to 0 so that the disconnection routines are immediately scheduled.

---
 net/bluetooth/hci_conn.c | 3 +++
 1 file changed, 3 insertions(+)
net/bluetooth/hci_conn.c +3 -0
index 7815826a48e4..cb04a4e3c829 100644
@@ -1316,6 +1316,9 @@ void hci_chan_del(struct hci_chan *chan)
 
 	synchronize_rcu();
 
+	/* Force the connection to be immediately dropped */
+	conn->disc_timeout = 0;
+
 	hci_conn_drop(conn);
 	hci_conn_put(conn);
 
Signature · 1 line
1.9.3
maintainer
#4 lore raw

Re: [PATCH 3/4] Bluetooth: Set disc_timeout to 0 when calling hci_chan_del

Hi Johan,

Quoted 9 lines

The hci_chan_del() function is used in scenarios where we've decided we want to get rid of the underlying baseband link. It makes therefore sense to force the disc_timeout to 0 so that the disconnection routines are immediately scheduled.

---
net/bluetooth/hci_conn.c | 3 +++

1 file changed, 3 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel

#5 lore raw

PATCH 4/4 Bluetooth: Ignore incoming data after initiating disconnection

In reply to [email protected]

From: Johan Hedberg <[email protected]>

When hci_chan_del is called the disconnection routines get scheduled through a workqueue. If there's any incoming ACL data before the routines get executed there's a chance that a new hci_chan is created and the disconnection never happens. This patch adds a new hci_conn flag to indicate that we're in the process of driving the connection down. We set the flag in hci_chan_del and check for it in hci_chan_create so that no new channels are created for the same connection.

---
 include/net/bluetooth/hci_core.h | 1 +
 net/bluetooth/hci_conn.c         | 6 ++++++
 2 files changed, 7 insertions(+)
include/net/bluetooth/hci_core.h +1 -0
index 18c24f6fce6c..dbe73642c54c 100644
@@ -553,6 +553,7 @@ enum {
 	HCI_CONN_FIPS,
 	HCI_CONN_STK_ENCRYPT,
 	HCI_CONN_AUTH_INITIATOR,
+	HCI_CONN_DROP,
 };
 
 static inline bool hci_conn_ssp_enabled(struct hci_conn *conn)
net/bluetooth/hci_conn.c +6 -0
index cb04a4e3c829..aaa7e388d026 100644
@@ -1291,6 +1291,11 @@ struct hci_chan *hci_chan_create(struct hci_conn *conn)
 
 	BT_DBG("%s hcon %p", hdev->name, conn);
 
+	if (test_bit(HCI_CONN_DROP, &conn->flags)) {
+		BT_DBG("Refusing to create new hci_chan");
+		return NULL;
+	}
+
 	chan = kzalloc(sizeof(*chan), GFP_KERNEL);
 	if (!chan)
 		return NULL;
@@ -1318,6 +1323,7 @@ void hci_chan_del(struct hci_chan *chan)
 
 	/* Force the connection to be immediately dropped */
 	conn->disc_timeout = 0;
+	set_bit(HCI_CONN_DROP, &conn->flags);
 
 	hci_conn_drop(conn);
 	hci_conn_put(conn);
Signature · 1 line
1.9.3
maintainer
#6 lore raw

Re: [PATCH 4/4] Bluetooth: Ignore incoming data after initiating disconnection

Hi Johan,

Quoted 8 lines

When hci_chan_del is called the disconnection routines get scheduled through a workqueue. If there's any incoming ACL data before the routines get executed there's a chance that a new hci_chan is created and the disconnection never happens. This patch adds a new hci_conn flag to indicate that we're in the process of driving the connection down. We set the flag in hci_chan_del and check for it in hci_chan_create so that no new channels are created for the same connection.

Quoted 5 lines

---
include/net/bluetooth/hci_core.h | 1 +
net/bluetooth/hci_conn.c | 6 ++++++

2 files changed, 7 insertions(+)

patch has been applied to bluetooth-next tree.

Regards

Marcel

maintainer
#7 lore raw
In reply to [email protected]

Hi Johan,

Quoted 8 lines

There's no point in passing a "small" timeout to queue_delayed_work() to try to get the callback faster scheduled. Passing 0 is perfectly valid and will cause a shortcut to a direct queue_work().

---
include/net/bluetooth/hci_core.h | 4 ++--

1 file changed, 2 insertions(+), 2 deletions(-)

patch has been applied to bluetooth-next tree.

Regards

Marcel