All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: Marcel Holtmann <marcel@holtmann.org>
Cc: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: Re: [RFC 1/4] Bluetooth: Add bt_skb_sendmsg helper
Date: Tue, 31 Aug 2021 17:20:17 -0700	[thread overview]
Message-ID: <CABBYNZ+LqknNZWaQkDY0E9QG5Q3JyMpp5=z-vNMEtVEC4mFnLg@mail.gmail.com> (raw)
In-Reply-To: <6AEBD579-90BB-486E-9915-614F7935880E@holtmann.org>

Hi Marcel,

On Tue, Aug 31, 2021 at 1:35 AM Marcel Holtmann <marcel@holtmann.org> wrote:
>
> Hi Luiz,
>
> > bt_skb_sendmsg helps takes care of allocation the skb and copying the
> > the contents of msg over to the skb while checking for possible errors
> > so it should be safe to call it without holding lock_sock.
> >
> > Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> > ---
> > include/net/bluetooth/bluetooth.h | 23 +++++++++++++++++++++++
> > 1 file changed, 23 insertions(+)
> >
> > diff --git a/include/net/bluetooth/bluetooth.h b/include/net/bluetooth/bluetooth.h
> > index 9125effbf448..1bfb5d3d24dd 100644
> > --- a/include/net/bluetooth/bluetooth.h
> > +++ b/include/net/bluetooth/bluetooth.h
> > @@ -420,6 +420,29 @@ static inline struct sk_buff *bt_skb_send_alloc(struct sock *sk,
> >       return NULL;
> > }
> >
> > +/* Shall not be called with lock_sock held */
> > +static inline struct sk_buff *bt_skb_sendmsg(struct sock *sk,
> > +                                          struct msghdr *msg,
> > +                                          size_t len, int reserve)
> > +{
> > +     struct sk_buff *skb;
> > +     int err;
> > +
> > +     skb = bt_skb_send_alloc(sk, len, msg->msg_flags & MSG_DONTWAIT, &err);
> > +     if (!skb)
> > +             return ERR_PTR(err);
> > +
> > +     if (memcpy_from_msg(skb_put(skb, len), msg, len)) {
> > +             kfree_skb(skb);
> > +             return ERR_PTR(-EFAULT);
> > +     }
> > +
> > +     skb_reserve(skb, reserve);
> > +     skb->priority = sk->sk_priority;
>
> have you tested this? I remember vaguely (really vaguely actually) that skb_reserve needs to be called before you do any changes to the buffer via skb_put and others. Especially since bt_skb_send_alloc already calls skb_reserve in the first place.

Yep, that and the fact that we need both a header and footer size to
be given separately since the len should only account for the payload
itself, anyway I will send an update shortly and Ive now tested with
rfcomm-tester and they are all passing.

> Regards
>
> Marcel
>


-- 
Luiz Augusto von Dentz

  reply	other threads:[~2021-09-01  0:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-31  1:15 [RFC 1/4] Bluetooth: Add bt_skb_sendmsg helper Luiz Augusto von Dentz
2021-08-31  1:15 ` [RFC 2/4] Bluetooth: Add bt_skb_sendmmsg helper Luiz Augusto von Dentz
2021-08-31  1:15 ` [RFC 3/4] Bluetooth: SCO: Replace use of memcpy_from_msg with bt_skb_sendmsg Luiz Augusto von Dentz
2021-08-31  1:15 ` [RFC 4/4] Bluetooth: RFCOMM: Replace use of memcpy_from_msg with bt_skb_sendmmsg Luiz Augusto von Dentz
2021-08-31  3:14   ` kernel test robot
2021-08-31 12:30   ` kernel test robot
2021-08-31 12:30     ` kernel test robot
2021-08-31  8:35 ` [RFC 1/4] Bluetooth: Add bt_skb_sendmsg helper Marcel Holtmann
2021-09-01  0:20   ` Luiz Augusto von Dentz [this message]
2021-08-31 19:11 ` [RFC,1/4] " bluez.test.bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CABBYNZ+LqknNZWaQkDY0E9QG5Q3JyMpp5=z-vNMEtVEC4mFnLg@mail.gmail.com' \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=marcel@holtmann.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.