Zero-copy L2CAP ERTM & streaming reassembly
Subsystems (2)
v2 cover Zero-copy L2CAP ERTM & streaming reassembly
This patch series changes SDU reassembly to link together PDU skbs using a frag list instead of copying all data bytes to a single, linear skb. The reduction in overhead is especially helpful with high speed AMP links.
Mat Martineau (3):
Bluetooth: Linearize skbs for use in BNEP, CMTP, HIDP, and RFCOMM
Bluetooth: Handle fragmented skbs in bt_sock_stream_recvmsg()
Bluetooth: Perform L2CAP SDU reassembly without copying data
include/net/bluetooth/l2cap.h | 3 +- net/bluetooth/af_bluetooth.c | 30 +++++- net/bluetooth/bnep/core.c | 5 +- net/bluetooth/cmtp/core.c | 5 +- net/bluetooth/hidp/core.c | 10 ++- net/bluetooth/l2cap_core.c | 241 ++++++++++++++--------------------------- net/bluetooth/rfcomm/core.c | 5 +- 7 files changed, 129 insertions(+), 170 deletions(-)
Signature · 6 lines
1.7.6 -- Mat Martineau Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
PATCH v2 1/3 Bluetooth: Linearize skbs for use in BNEP, CMTP, HIDP, and RFCOMM
Fragmented skbs are only encountered when receiving ERTM or streaming mode L2CAP data. BNEP, CMTP, HIDP, and RFCOMM generally use basic mode, but they need to handle fragments without crashing.
--- net/bluetooth/bnep/core.c | 5 ++++- net/bluetooth/cmtp/core.c | 5 ++++- net/bluetooth/hidp/core.c | 10 ++++++++-- net/bluetooth/rfcomm/core.c | 5 ++++- 4 files changed, 20 insertions(+), 5 deletions(-)
net/bluetooth/bnep/core.c +4 -1
@@ -490,7 +490,10 @@ static int bnep_session(void *arg)/* RX */ while ((skb =skb_dequeue (&sk->sk_receive_queue))) {skb_orphan (skb); -bnep_rx_frame (s, skb); +if (!skb_linearize (skb)) +bnep_rx_frame (s, skb); +else +kfree_skb (skb); }if (sk->sk_state !=BT_CONNECTED )
net/bluetooth/cmtp/core.c +4 -1
@@ -300,7 +300,10 @@ static int cmtp_session(void *arg)while ((skb =skb_dequeue (&sk->sk_receive_queue))) {skb_orphan (skb); -cmtp_recv_frame (session, skb); +if (!skb_linearize (skb)) +cmtp_recv_frame (session, skb); +else +kfree_skb (skb); }cmtp_process_transmit (session);
net/bluetooth/hidp/core.c +8 -2
@@ -716,12 +716,18 @@ static int hidp_session(void *arg)while ((skb =skb_dequeue (&ctrl_sk->sk_receive_queue))) {skb_orphan (skb); -hidp_recv_ctrl_frame (session, skb); +if (!skb_linearize (skb)) +hidp_recv_ctrl_frame (session, skb); +else +kfree_skb (skb); }while ((skb =skb_dequeue (&intr_sk->sk_receive_queue))) {skb_orphan (skb); -hidp_recv_intr_frame (session, skb); +if (!skb_linearize (skb)) +hidp_recv_intr_frame (session, skb); +else +kfree_skb (skb); }hidp_process_transmit (session);
net/bluetooth/rfcomm/core.c +4 -1
@@ -1855,7 +1855,10 @@ static inline void rfcomm_process_rx(struct rfcomm_session *s)/* Get data directly from socket receive queue without copying it. */ while ((skb =skb_dequeue (&sk->sk_receive_queue))) {skb_orphan (skb); -rfcomm_recv_frame (s, skb); +if (!skb_linearize (skb)) +rfcomm_recv_frame (s, skb); +else +kfree_skb (skb); }if (sk->sk_state ==BT_CLOSED ) {
Signature · 6 lines
1.7.6 -- Mat Martineau Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
PATCH v2 2/3 Bluetooth: Handle fragmented skbs in bt_sock_stream_recvmsg()
In reply to Mat MartineauERTM reassembly will be more efficient when skbs are linked together rather than copying every incoming data byte. The existing stream recv function assumes skbs are linear, so it needs to know how to handle fragments before reassembly is changed.
bt_sock_recvmsg() already handles fragmented skbs.
--- net/bluetooth/af_bluetooth.c | 30 ++++++++++++++++++++++++++++-- 1 files changed, 28 insertions(+), 2 deletions(-)
net/bluetooth/af_bluetooth.c +28 -2
@@ -349,7 +349,7 @@ int bt_sock_stream_recvmsg(struct kiocb *iocb, struct socket *sock, } chunk = min_t(unsigned int, skb->len, size); -if (memcpy_toiovec (msg->msg_iov, skb->data, chunk)) { +if (skb_copy_datagram_iovec (skb,0 , msg->msg_iov, chunk)) {skb_queue_head (&sk->sk_receive_queue, skb);if (!copied) copied = -EFAULT ;
@@ -361,7 +361,33 @@ int bt_sock_stream_recvmsg(struct kiocb *iocb, struct socket *sock,sock_recv_ts_and_drops (msg, sk, skb);if (!(flags &MSG_PEEK )) { -skb_pull (skb, chunk); +int skb_len =skb_headlen (skb); + +if (chunk <= skb_len) { +__skb_pull (skb, chunk); + }else { +struct sk_buff *frag; + +__skb_pull (skb, skb_len); + chunk -= skb_len; + + skb_walk_frags(skb, frag) { +if (chunk <= frag->len) { +/* Pulling partial data */ + skb->len -= chunk; + skb->data_len -= chunk; +__skb_pull (frag, chunk); +break ; + }else if (frag->len) { +/* Pulling all frag data */ + chunk -= frag->len; + skb->len -= frag->len; + skb->data_len -= frag->len; +__skb_pull (frag, frag->len); + } + } + } +if (skb->len) {skb_queue_head (&sk->sk_receive_queue, skb);break ;
Signature · 6 lines
1.7.6 -- Mat Martineau Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
PATCH v2 3/3 Bluetooth: Perform L2CAP SDU reassembly without copying data
In reply to Mat MartineauUse sk_buff fragment capabilities to link together incoming skbs instead of allocating a new skb for reassembly and copying.
The new reassembly code works equally well for ERTM and streaming mode, so there is now one reassembly function instead of two.
--- include/net/bluetooth/l2cap.h | 3 +- net/bluetooth/l2cap_core.c | 243 ++++++++++++++--------------------------- 2 files changed, 81 insertions(+), 165 deletions(-)
include/net/bluetooth/l2cap.h +1 -2
@@ -354,8 +354,8 @@ struct l2cap_chan {__u8 retry_count;__u8 num_acked;__u16 sdu_len; -__u16 partial_sdu_len;struct sk_buff *sdu; +struct sk_buff *sdu_last_frag;__u8 remote_tx_win;__u8 remote_max_tx;
@@ -454,7 +454,6 @@ enum {#define L2CAP_CONF_MAX_CONF_RSP 2enum { -CONN_SAR_SDU ,CONN_SREJ_SENT ,CONN_WAIT_F ,CONN_SREJ_ACT ,
net/bluetooth/l2cap_core.c +80 -163
307 lines not on this page · raw message
Signature · 6 lines
1.7.6 -- Mat Martineau Employee of Qualcomm Innovation Center, Inc. Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum
Re: [PATCH v2 3/3] Bluetooth: Perform L2CAP SDU reassembly without copying data
Hi Mat,
Quoted 11 lines · Mat Martineau
Use
sk_bufffragment capabilities to link together incoming skbs instead of allocating a new skb for reassembly and copying.The new reassembly code works equally well for ERTM and streaming mode, so there is now one reassembly function instead of two.
Signed-off-by Mat Martineau <[email protected]>--- include/net/bluetooth/l2cap.h | 3 +- net/bluetooth/l2cap_core.c | 243 ++++++++++++++--------------------------- 2 files changed, 81 insertions(+), 165 deletions(-)
All 3 patches applied, thanks.
Gustavo