Re: [PATCH v3 3/5] Bluetooth: ISO: add TX timestamping

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

ma, 2025-02-10 kello 13:19 +0800, Jason Xing kirjoitti:
> On Sun, Feb 9, 2025 at 6:39 PM Pauli Virtanen <pav@xxxxxx> wrote:
> > 
> > Add BT_SCM_ERROR socket CMSG type.
> > 
> > Support TX timestamping in ISO sockets.
> > 
> > Support MSG_ERRQUEUE in ISO recvmsg.
> > 
> > If a packet from sendmsg() is fragmented, only the first ACL fragment is
> > timestamped.
> > 
> > Signed-off-by: Pauli Virtanen <pav@xxxxxx>
> > ---
> >  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 435250c72d56..bbefde319f95 100644
> > --- a/include/net/bluetooth/bluetooth.h
> > +++ b/include/net/bluetooth/bluetooth.h
> > @@ -156,6 +156,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 44acddf58a0c..f497759a2af5 100644
> > --- a/net/bluetooth/iso.c
> > +++ b/net/bluetooth/iso.c
> > @@ -518,7 +518,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);
> > @@ -538,10 +539,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_setup_tx_timestamp(skb, 1, sockc);
> >                 hci_send_iso(conn->hcon, skb);
> > -       else
> > +       } else {
> >                 len = -ENOTCONN;
> > +       }
> > 
> >         return len;
> >  }
> > @@ -1348,6 +1351,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;
> > 
> > @@ -1360,6 +1364,14 @@ static int iso_sock_sendmsg(struct socket *sock, struct msghdr *msg,
> >         if (msg->msg_flags & MSG_OOB)
> >                 return -EOPNOTSUPP;
> > 
> > +       sockcm_init(&sockc, sk);
> 
> No need to initialize other irrelevant fields since Willem started to
> clean up this kind of init phase in TCP[1].
> 
> [1]: https://lore.kernel.org/all/20250206193521.2285488-2-willemdebruijn.kernel@xxxxxxxxx/

Ok.

> > +
> > +       if (msg->msg_controllen) {
> > +               err = sock_cmsg_send(sk, msg, &sockc);
> > +               if (err)
> > +                       return err;
> > +       }
> > +
> 
> I'm not familiar with bluetooth, but I'm wondering if the above code
> snippet is supposed to be protected by the socket lock as below since
> I refer to TCP as an example? Is it possible that multiple threads
> call this sendmsg at the same time?

I think parallel sendmsg() is possible, but I understood sock_cmsg_send
itself doesn't need lock_sock(), if I read correctly e.g. udp_sendmsg()
seems to be using it via ip_cmsg_send() unlocked.

The lock_sock() that are below IIRC protect the invariant that 
sk->sk_state == BT_CONNECTED has special meaning here.
> 

> >         lock_sock(sk);
> > 
> >         if (sk->sk_state != BT_CONNECTED) {
> > @@ -1405,7 +1417,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;
> > 
> > @@ -1474,6 +1486,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)) {
> >                 sock_hold(sk);
> >                 lock_sock(sk);
> > --
> > 2.48.1
> > 
> > 






[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux