From patchwork Sat Mar 2 20:07:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 777555 Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B28C8405CB for ; Sat, 2 Mar 2024 20:07:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=195.140.195.201 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709410072; cv=pass; b=gwQuHO8vB9QyBXIPm0CFfApLBNZfiD0UcPFDYXTslA+hrjrKFOwqzDaXXj2mD2t+cdpV5sa9jpur3q9YuLVeIuHHLdKZZEGqI9woOp1T7G3KlqzFy47w/rSkk1AFdW23nJOV18LgXQNY7HS4xd8eiJrEhIs8SpWr9Ej/KykT9dA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709410072; c=relaxed/simple; bh=ROFbXOLH3jHR0dXu+krzdnYD20zsq9MJmvsRKJnOHu4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=tvHeueacD0sl+0nWFnH8MdOzJB82Dw9npAiATDWZuCi9FcG7V46TFIyqFLyvmC+p8tgMrgMhS8sUe1t6SJXEyTiC5Grjba9ERYfMNbe4Muxms42bYsjB7h33JmHiWr9115ScnU5cMGJUs2QCJHK6pVdOmgUoazxY70W4NZ5zQFA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi; spf=pass smtp.mailfrom=iki.fi; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b=dPUXuXgH; arc=pass smtp.client-ip=195.140.195.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iki.fi Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b="dPUXuXgH" Received: from monolith.lan (unknown [193.138.7.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pav) by meesny.iki.fi (Postfix) with ESMTPSA id 4TnGGW4mM4z100r; Sat, 2 Mar 2024 22:07:47 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1709410068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=An/mj6d1gOGyrMkwQ6JKMbWIX5kfocAe+0oQz/NspZ0=; b=dPUXuXgHFtwegrRPFvBOzVhuNi1j8CYgK1uL7955JVaXtX8WBCJkRslEgOhZNETc6M9TI/ P4Sg5/oUSq8dyMSiz3e5NwLM7HqXLZXNPQ2mNLMPDKWnuAbkbyDY44s6oVHWR5ySqgW0t+ qWHFHklwCgd57EXSnCqdJ40iK0pfctA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1709410068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=An/mj6d1gOGyrMkwQ6JKMbWIX5kfocAe+0oQz/NspZ0=; b=Qa89ptPTpHMlMKVyI+O2KLD3a0OLPboUDvsnJdg8DyFHgvfQqJZTm5aEGWXmZw23Wnwf1F M2EDTIAI9J8PxzbrsNYRU3ajjLHFFUdI2cYHsKTcCs6AB/mKNuUH4YJCMrq6ek7kuUGqcX rqFZFvGgbTYlZnVIi54sDvVaERZAMiQ= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1709410068; a=rsa-sha256; cv=none; b=CTp9sGCG4dXnaOCRt3svo8RezEruSHEr8zfAVBpiK7uaojqHX6By37ao8CvGD3zUU0m8dI PBTD1zVX0FmqYANMOQtaX6Ipke9sh6box3LxOt5jnT+4aeKkolXTyyVXs4sVRvcEuOVfC9 ij+Owx0FanCnBiRjiL+6wYU1UDEsFzQ= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH 1/3] Bluetooth: add support for skb TX timestamping Date: Sat, 2 Mar 2024 22:07:36 +0200 Message-ID: X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Support enabling TX timestamping for some skbs, and track them until packet completion. Generate SCM_TSTAMP_SCHED when sending to driver, and SCM_TSTAMP_SND at packet completion. Make the default situation with no TX timestamping more efficient by only counting packets in the queue when there is nothing to track. When there is something to track, we need to make clones, since the driver may modify sent skbs. Signed-off-by: Pauli Virtanen --- include/net/bluetooth/hci_core.h | 12 +++++ net/bluetooth/hci_conn.c | 78 ++++++++++++++++++++++++++++++++ net/bluetooth/hci_core.c | 5 ++ net/bluetooth/hci_event.c | 4 ++ 4 files changed, 99 insertions(+) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 56fb42df44a3..51b556612a6b 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -267,6 +267,12 @@ struct adv_info { struct delayed_work rpa_expired_cb; }; +struct tx_comp_queue { + struct sk_buff_head queue; + unsigned int extra; + unsigned int tracked; +}; + #define HCI_MAX_ADV_INSTANCES 5 #define HCI_DEFAULT_ADV_DURATION 2 @@ -763,6 +769,8 @@ struct hci_conn { struct sk_buff_head data_q; struct list_head chan_list; + struct tx_comp_queue tx_comp_queue; + struct delayed_work disc_work; struct delayed_work auto_accept_work; struct delayed_work idle_work; @@ -1546,6 +1554,10 @@ void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active); void hci_conn_failed(struct hci_conn *conn, u8 status); u8 hci_conn_set_handle(struct hci_conn *conn, u16 handle); +void hci_conn_tx_comp_queue(struct hci_conn *conn, struct sk_buff *skb); +void hci_conn_tx_comp_dequeue(struct hci_conn *conn); +void hci_tx_timestamp(struct sk_buff *skb, const struct sockcm_cookie *sockc); + /* * hci_conn_get() and hci_conn_put() are used to control the life-time of an * "hci_conn" object. They do not guarantee that the hci_conn object is running, diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c index 3ad74f76983b..f44d4b8fa0c6 100644 --- a/net/bluetooth/hci_conn.c +++ b/net/bluetooth/hci_conn.c @@ -27,6 +27,7 @@ #include #include +#include #include #include @@ -973,6 +974,7 @@ struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst, } skb_queue_head_init(&conn->data_q); + skb_queue_head_init(&conn->tx_comp_queue.queue); INIT_LIST_HEAD(&conn->chan_list); INIT_LIST_HEAD(&conn->link_list); @@ -1117,6 +1119,7 @@ void hci_conn_del(struct hci_conn *conn) } skb_queue_purge(&conn->data_q); + skb_queue_purge(&conn->tx_comp_queue.queue); /* Remove the connection from the list and cleanup its remaining * state. This is a separate function since for some cases like @@ -2928,3 +2931,78 @@ int hci_abort_conn(struct hci_conn *conn, u8 reason) return hci_cmd_sync_queue_once(hdev, abort_conn_sync, conn, NULL); } + +void hci_tx_timestamp(struct sk_buff *skb, const struct sockcm_cookie *sockc) +{ + /* This shall be called on a single skb of those generated by user + * sendmsg(), and only when the sendmsg() does not return error to + * user. This is required for keeping the tskey that increments here in + * sync with possible sendmsg() counting by user. + */ + + if (!skb || !sockc) + return; + + skb_setup_tx_timestamp(skb, sockc->tsflags); +} + +void hci_conn_tx_comp_queue(struct hci_conn *conn, struct sk_buff *skb) +{ + struct tx_comp_queue *comp = &conn->tx_comp_queue; + bool track = false; + + if (skb->sk) { + if (skb_shinfo(skb)->tx_flags & SKBTX_SCHED_TSTAMP) + __skb_tstamp_tx(skb, NULL, NULL, skb->sk, + SCM_TSTAMP_SCHED); + + if (skb_shinfo(skb)->tx_flags & SKBTX_SW_TSTAMP) + track = true; + } + + /* If nothing is tracked, just count extra skbs at the queue head */ + if (!track && !comp->tracked) { + comp->extra++; + return; + } + + if (track) { + skb = skb_clone_sk(skb); + if (!skb) + return; + + comp->tracked++; + } else { + skb = skb_clone(skb, GFP_KERNEL); + if (!skb) + return; + } + + skb_queue_tail(&comp->queue, skb); +} + +void hci_conn_tx_comp_dequeue(struct hci_conn *conn) +{ + struct tx_comp_queue *comp = &conn->tx_comp_queue; + struct sk_buff *skb; + + /* If there are tracked skbs, the counted extra go before dequeuing real + * skbs, to keep ordering. When nothing is tracked, the ordering doesn't + * matter so dequeue real skbs first to get rid of them ASAP. + */ + if (comp->extra && (comp->tracked || skb_queue_empty(&comp->queue))) { + comp->extra--; + return; + } + + skb = skb_dequeue(&comp->queue); + if (!skb) + return; + + if (skb->sk) { + comp->tracked--; + skb_tstamp_tx(skb, NULL); + } + + kfree_skb(skb); +} diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index df3aa41e376d..f4af6e99d798 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -3715,6 +3715,8 @@ static void hci_sched_acl_pkt(struct hci_dev *hdev) hci_conn_enter_active_mode(chan->conn, bt_cb(skb)->force_active); + hci_conn_tx_comp_queue(chan->conn, skb); + hci_send_frame(hdev, skb); hdev->acl_last_tx = jiffies; @@ -3876,6 +3878,9 @@ static void hci_sched_iso(struct hci_dev *hdev) while (*cnt && (conn = hci_low_sent(hdev, ISO_LINK, "e))) { while (quote-- && (skb = skb_dequeue(&conn->data_q))) { BT_DBG("skb %p len %d", skb, skb->len); + + hci_conn_tx_comp_queue(conn, skb); + hci_send_frame(hdev, skb); conn->sent++; diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index bffd2c7ff608..f56211d8ff7a 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -4438,6 +4438,7 @@ static void hci_num_comp_pkts_evt(struct hci_dev *hdev, void *data, struct hci_comp_pkts_info *info = &ev->handles[i]; struct hci_conn *conn; __u16 handle, count; + unsigned int i; handle = __le16_to_cpu(info->handle); count = __le16_to_cpu(info->count); @@ -4448,6 +4449,9 @@ static void hci_num_comp_pkts_evt(struct hci_dev *hdev, void *data, conn->sent -= count; + for (i = 0; i < count; ++i) + hci_conn_tx_comp_dequeue(conn); + switch (conn->type) { case ACL_LINK: hdev->acl_cnt += count; From patchwork Sat Mar 2 20:07:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 778380 Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 14175405DC for ; Sat, 2 Mar 2024 20:07:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=195.140.195.201 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709410073; cv=pass; b=QMbVKh+5ZFor27fF+SdJAjwvB1b+5T/SKLvY8AfMThYNifSqqWiTa7xjU5nqMcGEIPpybb6nsFfUvjPmi7Il96HrVIyRP5PBebSDDHlFelxbWKW6Oame8fYyaPbFzlKnebThwYAJ1lexkvgWOzJ3GrUyR1IGykkvpAAlrvXtnOM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709410073; c=relaxed/simple; bh=u7QC6sL64UDDNUT0h12AYOazbJmmDxqQxw0iFueGfRM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nfuPPFU2z7PoMlmAZftai+vTNIOkQB+pxWN5Vn+Ma6SybMsAQ/FUPua6ZrMem15+U/+gVe6L7Pl8+yipYo7xoPBdh6y5jUadYGcVH2/C2Q/Ohj10H9nMwqIohkb6UjPKnIPhlcoJZZBSWsIepaZyMKcRpax+pzfAm7bB9xfshmY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi; spf=pass smtp.mailfrom=iki.fi; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b=nSqK+fc0; arc=pass smtp.client-ip=195.140.195.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iki.fi Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b="nSqK+fc0" Received: from monolith.lan (unknown [193.138.7.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pav) by meesny.iki.fi (Postfix) with ESMTPSA id 4TnGGY20tXz101J; Sat, 2 Mar 2024 22:07:49 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1709410070; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sO3iKgGZFl9k7ukd0+W8p10Wm7ZC/0YzcmUduBWXufA=; b=nSqK+fc0Y5SvDVWfn+CtK8e3TSUsBVbCDuIQgPI2e+9m7A0fyZzZAjR7uepUI7WPkP0WHY hwul/cSFsZoz1HVi+WUhZOYCiIv1GPBNLzVkcSykibN5/+HZuLsAhXtL2Ql3PO3CRcZPxN gEMhWEAqePCAQwSoWJfZysn3rfBL0UM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1709410070; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sO3iKgGZFl9k7ukd0+W8p10Wm7ZC/0YzcmUduBWXufA=; b=JogKPYlomdxDM/lA4m5RZpjl5rR4315pwSfJ1M8ui7XX9beHI3tQVd6zPji0dNtyH5Jtd0 Rh/N58u0dGya8WWPCWIjxsMZnfsyHJdjhD8jnBzWW/LJduVJRgjVc2W+aswyDTGvwFu9Jh HRggNWUe9fhdX0ppYBXRwm3RweiDZBw= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1709410070; a=rsa-sha256; cv=none; b=H55YlO1xkio0jzZNoonrwlATJBHRYgrOBpbJZ7WHzI97n+lmj/xdDHjdI34qNZgkyLpWxc OjI2VhusNpkDuavrR4FuqKITcsbYANhtSklGz6G6yTDf4T/GOlKnUwtsq7HTGIi9ptPj0B DGpDYEDLnISUfxbkX6hvTGzLFROBgCA= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH 2/3] Bluetooth: ISO: add TX timestamping Date: Sat, 2 Mar 2024 22:07:37 +0200 Message-ID: <35bfe39b6d494fe93e656e8bd62e845d7ea7ee74.1709409547.git.pav@iki.fi> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add BT_SCM_ERROR socket CMSG type. Support TX timestamping in ISO sockets. Support MSG_ERRQUEUE in ISO recvmsg. Signed-off-by: Pauli Virtanen --- include/net/bluetooth/bluetooth.h | 1 + net/bluetooth/iso.c | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h index 7ffa8c192c3f..9280e72093ee 100644 --- a/include/net/bluetooth/bluetooth.h +++ b/include/net/bluetooth/bluetooth.h @@ -155,6 +155,7 @@ struct bt_voice { #define BT_PKT_STATUS 16 #define BT_SCM_PKT_STATUS 0x03 +#define BT_SCM_ERROR 0x04 #define BT_ISO_QOS 17 diff --git a/net/bluetooth/iso.c b/net/bluetooth/iso.c index 30c777c469f9..f610fa04f329 100644 --- a/net/bluetooth/iso.c +++ b/net/bluetooth/iso.c @@ -489,7 +489,8 @@ static struct bt_iso_qos *iso_sock_get_qos(struct sock *sk) return &iso_pi(sk)->qos; } -static int iso_send_frame(struct sock *sk, struct sk_buff *skb) +static int iso_send_frame(struct sock *sk, struct sk_buff *skb, + const struct sockcm_cookie *sockc) { struct iso_conn *conn = iso_pi(sk)->conn; struct bt_iso_qos *qos = iso_sock_get_qos(sk); @@ -509,10 +510,12 @@ static int iso_send_frame(struct sock *sk, struct sk_buff *skb) hdr->slen = cpu_to_le16(hci_iso_data_len_pack(len, HCI_ISO_STATUS_VALID)); - if (sk->sk_state == BT_CONNECTED) + if (sk->sk_state == BT_CONNECTED) { + hci_tx_timestamp(skb, sockc); hci_send_iso(conn->hcon, skb); - else + } else { len = -ENOTCONN; + } return len; } @@ -1266,6 +1269,7 @@ static int iso_sock_sendmsg(struct socket *sock, struct msghdr *msg, { struct sock *sk = sock->sk; struct sk_buff *skb, **frag; + struct sockcm_cookie sockc; size_t mtu; int err; @@ -1278,6 +1282,14 @@ static int iso_sock_sendmsg(struct socket *sock, struct msghdr *msg, if (msg->msg_flags & MSG_OOB) return -EOPNOTSUPP; + sockcm_init(&sockc, sk); + + if (msg->msg_controllen) { + err = sock_cmsg_send(sk, msg, &sockc); + if (err) + return err; + } + lock_sock(sk); if (sk->sk_state != BT_CONNECTED) { @@ -1323,7 +1335,7 @@ static int iso_sock_sendmsg(struct socket *sock, struct msghdr *msg, lock_sock(sk); if (sk->sk_state == BT_CONNECTED) - err = iso_send_frame(sk, skb); + err = iso_send_frame(sk, skb, &sockc); else err = -ENOTCONN; @@ -1379,6 +1391,10 @@ static int iso_sock_recvmsg(struct socket *sock, struct msghdr *msg, BT_DBG("sk %p", sk); + if (unlikely(flags & MSG_ERRQUEUE)) + return sock_recv_errqueue(sk, msg, len, SOL_BLUETOOTH, + BT_SCM_ERROR); + if (test_and_clear_bit(BT_SK_DEFER_SETUP, &bt_sk(sk)->flags)) { lock_sock(sk); switch (sk->sk_state) { From patchwork Sat Mar 2 20:07:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 777554 Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 301CC40847 for ; Sat, 2 Mar 2024 20:07:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=195.140.195.201 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709410074; cv=pass; b=dTLi3y/Z9MtcJv1h0FFeb4fvOf+1leGtQ0wGqq546/7m79C9jyiD1ruJokChccPF0WO3zTiPTDSWBpXOV3HJ145uzY5dcacc1uJ0rCp8dAmYjIbo8CZT2Fk6VL8XFchkso+GqUopbo9sz+hJpdjxgqcH5d3WWIBAc0+AUbo1jIM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709410074; c=relaxed/simple; bh=+/xvom5mfne17LXSydbTnDY/e4A8mQIUOXTRL6flW+w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=V+2Vk2F7XpPSrvankmAq0dbyu0qs27Uupj9KOXU+HQy9B4zAbpvIeIgtHugQohhL68UZNtqBytCu3LWMlqdhVnzflXDkHvQH9LKmgNaMyqusE3LxA5lqqd04kH8oTuHgErAQ6Vk3pkXwsaIuQZzVny26ylkmYEfiuKqdYEG7IgM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi; spf=pass smtp.mailfrom=iki.fi; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b=maXbWl8w; arc=pass smtp.client-ip=195.140.195.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=iki.fi Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=iki.fi Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=iki.fi header.i=@iki.fi header.b="maXbWl8w" Received: from monolith.lan (unknown [193.138.7.138]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pav) by meesny.iki.fi (Postfix) with ESMTPSA id 4TnGGZ2ssYzyys; Sat, 2 Mar 2024 22:07:50 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1709410071; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NsLZgdDHfimWlUePJ4AqPklJXSpJwRJMFjiDb6ZlYj8=; b=maXbWl8wzC7QIljbAVK8Cf82w7hAeenyLRsrtV3r7+D7U8N996Q3ymIPat/KNN4T2e0ePc utq+1MJW54dNe45/8i0McZeGRLokBTdlYmSJrb805FEdWPfUqXxlubAKFdNVxjai8NKo0Q 2aV4o8zKMI6agg6BdNvZNenmHH2991A= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1709410071; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=NsLZgdDHfimWlUePJ4AqPklJXSpJwRJMFjiDb6ZlYj8=; b=NLtIXP1NZ25I7bq5OJN5Eer3qH3vLo6vVTQn7frOHCTQoZ8Zbv1KcPnR5z7angj+blfpxe 7cXEVrCO+m2lXHYz9a/WgWAQ/Dw5Oqq4FLd8jpLsGvIpFI715DR02wRuQtMTbPcF6fN73i apwv1h28bKm8mMkQ2DNAUC9Eq2mo7x0= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1709410071; a=rsa-sha256; cv=none; b=DkCoIBnUfQ2NA5TJh32JquBLNMHJo/3A+6clI45P/u5MPFMdsI323p3120Zf6pkXnWkeMg CvpcsD0/qq2fP1FvBEZNSyQXZt0O5LbLFgi9Mlh4oMQqUUTCFaZiMaXh31BczxTachoiOh bTTiE1/NoNuHjAuubN+hHZKlj7oe34s= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH 3/3] Bluetooth: L2CAP: add TX timestamping Date: Sat, 2 Mar 2024 22:07:38 +0200 Message-ID: <68605b0923b5b57785cb00c7f60dc50d92c770b3.1709409547.git.pav@iki.fi> X-Mailer: git-send-email 2.44.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Support TX timestamping in L2CAP sockets. Support MSG_ERRQUEUE recvmsg. Signed-off-by: Pauli Virtanen --- include/net/bluetooth/l2cap.h | 3 ++- net/bluetooth/6lowpan.c | 2 +- net/bluetooth/l2cap_core.c | 11 ++++++++++- net/bluetooth/l2cap_sock.c | 15 ++++++++++++++- net/bluetooth/smp.c | 2 +- 5 files changed, 28 insertions(+), 5 deletions(-) diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h index a4278aa618ab..3f4057ced971 100644 --- a/include/net/bluetooth/l2cap.h +++ b/include/net/bluetooth/l2cap.h @@ -941,7 +941,8 @@ void l2cap_chan_close(struct l2cap_chan *chan, int reason); int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, bdaddr_t *dst, u8 dst_type, u16 timeout); int l2cap_chan_reconfigure(struct l2cap_chan *chan, __u16 mtu); -int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len); +int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len, + const struct sockcm_cookie *sockc); void l2cap_chan_busy(struct l2cap_chan *chan, int busy); int l2cap_chan_check_security(struct l2cap_chan *chan, bool initiator); void l2cap_chan_set_defaults(struct l2cap_chan *chan); diff --git a/net/bluetooth/6lowpan.c b/net/bluetooth/6lowpan.c index 27520a8a486f..24635f9e758a 100644 --- a/net/bluetooth/6lowpan.c +++ b/net/bluetooth/6lowpan.c @@ -443,7 +443,7 @@ static int send_pkt(struct l2cap_chan *chan, struct sk_buff *skb, memset(&msg, 0, sizeof(msg)); iov_iter_kvec(&msg.msg_iter, ITER_SOURCE, &iv, 1, skb->len); - err = l2cap_chan_send(chan, &msg, skb->len); + err = l2cap_chan_send(chan, &msg, skb->len, NULL); if (err > 0) { netdev->stats.tx_bytes += err; netdev->stats.tx_packets++; diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c index 467b242d8be0..cf3b8e9b7b3b 100644 --- a/net/bluetooth/l2cap_core.c +++ b/net/bluetooth/l2cap_core.c @@ -2488,7 +2488,8 @@ static void l2cap_le_flowctl_send(struct l2cap_chan *chan) skb_queue_len(&chan->tx_q)); } -int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len) +int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len, + const struct sockcm_cookie *sockc) { struct sk_buff *skb; int err; @@ -2503,6 +2504,8 @@ int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len) if (IS_ERR(skb)) return PTR_ERR(skb); + hci_tx_timestamp(skb, sockc); + l2cap_do_send(chan, skb); return len; } @@ -2526,6 +2529,8 @@ int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len) if (err) return err; + hci_tx_timestamp(skb_peek(&seg_queue), sockc); + skb_queue_splice_tail_init(&seg_queue, &chan->tx_q); l2cap_le_flowctl_send(chan); @@ -2547,6 +2552,8 @@ int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len) if (IS_ERR(skb)) return PTR_ERR(skb); + hci_tx_timestamp(skb, sockc); + l2cap_do_send(chan, skb); err = len; break; @@ -2570,6 +2577,8 @@ int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len) if (err) break; + hci_tx_timestamp(skb_peek(&seg_queue), sockc); + if (chan->mode == L2CAP_MODE_ERTM) l2cap_tx(chan, NULL, &seg_queue, L2CAP_EV_DATA_REQUEST); else diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c index 4287aa6cc988..9a9f933a748b 100644 --- a/net/bluetooth/l2cap_sock.c +++ b/net/bluetooth/l2cap_sock.c @@ -1115,6 +1115,7 @@ static int l2cap_sock_sendmsg(struct socket *sock, struct msghdr *msg, { struct sock *sk = sock->sk; struct l2cap_chan *chan = l2cap_pi(sk)->chan; + struct sockcm_cookie sockc; int err; BT_DBG("sock %p, sk %p", sock, sk); @@ -1129,6 +1130,14 @@ static int l2cap_sock_sendmsg(struct socket *sock, struct msghdr *msg, if (sk->sk_state != BT_CONNECTED) return -ENOTCONN; + sockcm_init(&sockc, sk); + + if (msg->msg_controllen) { + err = sock_cmsg_send(sk, msg, &sockc); + if (err) + return err; + } + lock_sock(sk); err = bt_sock_wait_ready(sk, msg->msg_flags); release_sock(sk); @@ -1136,7 +1145,7 @@ static int l2cap_sock_sendmsg(struct socket *sock, struct msghdr *msg, return err; l2cap_chan_lock(chan); - err = l2cap_chan_send(chan, msg, len); + err = l2cap_chan_send(chan, msg, len, &sockc); l2cap_chan_unlock(chan); return err; @@ -1149,6 +1158,10 @@ static int l2cap_sock_recvmsg(struct socket *sock, struct msghdr *msg, struct l2cap_pinfo *pi = l2cap_pi(sk); int err; + if (unlikely(flags & MSG_ERRQUEUE)) + return sock_recv_errqueue(sk, msg, len, SOL_BLUETOOTH, + BT_SCM_ERROR); + lock_sock(sk); if (sk->sk_state == BT_CONNECT2 && test_bit(BT_SK_DEFER_SETUP, diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c index 1e7ea3a4b7ef..4612115ec09a 100644 --- a/net/bluetooth/smp.c +++ b/net/bluetooth/smp.c @@ -608,7 +608,7 @@ static void smp_send_cmd(struct l2cap_conn *conn, u8 code, u16 len, void *data) iov_iter_kvec(&msg.msg_iter, ITER_SOURCE, iv, 2, 1 + len); - l2cap_chan_send(chan, &msg, 1 + len); + l2cap_chan_send(chan, &msg, 1 + len, NULL); if (!chan->data) return;