All of lore.kernel.org
 help / color / mirror / Atom feed
From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Jesus Sanchez-Palencia <jesus.sanchez-palencia@intel.com>
Cc: "Network Development" <netdev@vger.kernel.org>,
	"Thomas Gleixner" <tglx@linutronix.de>,
	jan.altenberg@linutronix.de,
	"Vinicius Gomes" <vinicius.gomes@intel.com>,
	kurt.kanzenbach@linutronix.de, "Henrik Austad" <henrik@austad.us>,
	"Richard Cochran" <richardcochran@gmail.com>,
	ilias.apalodimas@linaro.org, ivan.khoronzhuk@linaro.org,
	"Miroslav Lichvar" <mlichvar@redhat.com>,
	"Willem de Bruijn" <willemb@google.com>,
	"Jamal Hadi Salim" <jhs@mojatatu.com>,
	"Cong Wang" <xiyou.wangcong@gmail.com>,
	"Jiří Pírko" <jiri@resnulli.us>,
	"Alexander Duyck" <alexander.duyck@gmail.com>
Subject: Re: [PATCH v1 net-next 14/14] net/sched: Make etf report drops on error_queue
Date: Fri, 29 Jun 2018 14:49:01 -0400	[thread overview]
Message-ID: <CAF=yD-KqkuZsstXK2-s9_ttuCKx=wucHS9zEmkdH=BsgMY=a0Q@mail.gmail.com> (raw)
In-Reply-To: <88846dcd-b4dc-ddde-6c4b-5a29ffde016b@intel.com>

> >> diff --git a/net/sched/sch_etf.c b/net/sched/sch_etf.c
> >> index 5514a8aa3bd5..166f4b72875b 100644
> >> --- a/net/sched/sch_etf.c
> >> +++ b/net/sched/sch_etf.c
> >> @@ -11,6 +11,7 @@
> >>  #include <linux/kernel.h>
> >>  #include <linux/string.h>
> >>  #include <linux/errno.h>
> >> +#include <linux/errqueue.h>
> >>  #include <linux/rbtree.h>
> >>  #include <linux/skbuff.h>
> >>  #include <linux/posix-timers.h>
> >> @@ -124,6 +125,35 @@ static void reset_watchdog(struct Qdisc *sch)
> >>         qdisc_watchdog_schedule_ns(&q->watchdog, ktime_to_ns(next));
> >>  }
> >>
> >> +static void report_sock_error(struct sk_buff *skb, u32 err, u8 code)
> >> +{
> >> +       struct sock_exterr_skb *serr;
> >> +       ktime_t txtime = skb->tstamp;
> >> +
> >> +       if (!skb->sk || !(skb->sk->sk_txtime_flags & SK_TXTIME_RECV_ERR_MASK))
> >> +               return;
> >> +
> >> +       skb = skb_clone_sk(skb);
> >> +       if (!skb)
> >> +               return;
> >> +
> >> +       sock_hold(skb->sk);
> >
> > Why take an extra reference? The skb holds a ref on the sk.
>
>
> Yes, the cloned skb holds a ref on the socket, but the documentation of
> skb_clone_sk() makes this explicit suggestion:
>
> (...)
>  * When passing buffers allocated with this function to sock_queue_err_skb
>  * it is necessary to wrap the call with sock_hold/sock_put in order to
>  * prevent the socket from being released prior to being enqueued on
>  * the sk_error_queue.
>  */
>
> which I believe is here just so we are protected against a possible race after
> skb_orphan() is called from sock_queue_err_skb(). Please let me know if I'm
> misreading anything.

Yes, indeed. Code only has to worry about that if there are no
concurrent references
on the socket.

I may be mistaken, but I believe that this complicated logic exists
only for cases where
the timestamp may be queued after the original skb has been released.
Specifically,
when a tx timestamp is returned from a hardware device after transmission of the
original skb. Then the cloned timestamp skb needs its own reference on
the sk while
it is waiting for the timestamp data (i.e., until the device
completion arrives) and then
we need a temporary extra ref to work around the skb_orphan in
sock_queue_err_skb.

Compare skb_complete_tx_timestamp with skb_tstamp_tx. The second is used in
the regular datapath to clone an skb and queue it on the error queue
immediately,
while holding the original skb. This does not call skb_clone_sk and
does not need the
extra sock_hold. This should be good enough for this code path, too.
As kb holds a
ref on skb->sk, the socket cannot go away in the middle of report_sock_error.

  reply	other threads:[~2018-06-29 18:49 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-27 21:59 [PATCH v1 net-next 00/14] Scheduled packet Transmission: ETF Jesus Sanchez-Palencia
2018-06-27 21:59 ` [PATCH v1 net-next 01/14] net: Clear skb->tstamp only on the forwarding path Jesus Sanchez-Palencia
2018-06-27 21:59 ` [PATCH v1 net-next 02/14] net: Add a new socket option for a future transmit time Jesus Sanchez-Palencia
2018-06-27 22:16   ` Eric Dumazet
2018-06-27 23:07     ` Jesus Sanchez-Palencia
2018-06-28  0:05       ` Eric Dumazet
2018-06-28  2:16   ` kbuild test robot
2018-06-28 14:26   ` Willem de Bruijn
2018-06-28 14:40     ` Willem de Bruijn
2018-06-28 18:33       ` Jesus Sanchez-Palencia
2018-06-27 21:59 ` [PATCH v1 net-next 03/14] net: ipv4: Hook into time based transmission Jesus Sanchez-Palencia
2018-06-28 14:26   ` Willem de Bruijn
2018-06-27 21:59 ` [PATCH v1 net-next 04/14] net: packet: " Jesus Sanchez-Palencia
2018-06-27 21:59 ` [PATCH v1 net-next 05/14] net/sched: Allow creating a Qdisc watchdog with other clocks Jesus Sanchez-Palencia
2018-06-27 21:59 ` [PATCH v1 net-next 06/14] net/sched: Introduce the ETF Qdisc Jesus Sanchez-Palencia
2018-06-27 21:59 ` [PATCH v1 net-next 07/14] net/sched: Add HW offloading capability to ETF Jesus Sanchez-Palencia
2018-06-27 21:59 ` [PATCH v1 net-next 08/14] igb: Refactor igb_configure_cbs() Jesus Sanchez-Palencia
2018-06-27 21:59 ` [PATCH v1 net-next 09/14] igb: Only change Tx arbitration when CBS is on Jesus Sanchez-Palencia
2018-06-27 21:59 ` [PATCH v1 net-next 10/14] igb: Refactor igb_offload_cbs() Jesus Sanchez-Palencia
2018-06-27 21:59 ` [PATCH v1 net-next 11/14] igb: Add support for ETF offload Jesus Sanchez-Palencia
2018-06-27 21:59 ` [PATCH v1 net-next 12/14] igb: Only call skb_tx_timestamp after descriptors are ready Jesus Sanchez-Palencia
2018-06-27 23:56   ` Eric Dumazet
2018-06-28 17:12     ` Jesus Sanchez-Palencia
2018-06-27 21:59 ` [PATCH v1 net-next 13/14] net/sched: Enforce usage of CLOCK_TAI for sch_etf Jesus Sanchez-Palencia
2018-06-28 14:26   ` Willem de Bruijn
2018-06-28 17:11     ` Jesus Sanchez-Palencia
2018-06-27 21:59 ` [PATCH v1 net-next 14/14] net/sched: Make etf report drops on error_queue Jesus Sanchez-Palencia
2018-06-28 14:27   ` Willem de Bruijn
2018-06-29 17:48     ` Jesus Sanchez-Palencia
2018-06-29 18:49       ` Willem de Bruijn [this message]
2018-06-29 20:14         ` Jesus Sanchez-Palencia

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='CAF=yD-KqkuZsstXK2-s9_ttuCKx=wucHS9zEmkdH=BsgMY=a0Q@mail.gmail.com' \
    --to=willemdebruijn.kernel@gmail.com \
    --cc=alexander.duyck@gmail.com \
    --cc=henrik@austad.us \
    --cc=ilias.apalodimas@linaro.org \
    --cc=ivan.khoronzhuk@linaro.org \
    --cc=jan.altenberg@linutronix.de \
    --cc=jesus.sanchez-palencia@intel.com \
    --cc=jhs@mojatatu.com \
    --cc=jiri@resnulli.us \
    --cc=kurt.kanzenbach@linutronix.de \
    --cc=mlichvar@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.com \
    --cc=tglx@linutronix.de \
    --cc=vinicius.gomes@intel.com \
    --cc=willemb@google.com \
    --cc=xiyou.wangcong@gmail.com \
    /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.