From: "Jon Rosen (jrosen)" <jrosen@cisco.com>
To: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
Willem de Bruijn <willemb@google.com>,
Eric Dumazet <edumazet@google.com>,
Kees Cook <keescook@chromium.org>,
David Windsor <dwindsor@gmail.com>,
"Rosen, Rami" <rami.rosen@intel.com>,
"Reshetova, Elena" <elena.reshetova@intel.com>,
"Mike Maloney" <maloney@google.com>,
Benjamin Poirier <bpoirier@suse.com>,
"Thomas Gleixner" <tglx@linutronix.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"open list:NETWORKING [GENERAL]" <netdev@vger.kernel.org>,
open list <linux-kernel@vger.kernel.org>
Subject: RE: [PATCH v2] packet: track ring entry use using a shadow ring to prevent RX ring overrun
Date: Wed, 23 May 2018 11:08:33 +0000 [thread overview]
Message-ID: <e942c1bbe48b451b92620396746986ab@XCH-RTP-016.cisco.com> (raw)
In-Reply-To: <CAF=yD-KHFwhVt4xzED7FPLd_xej9nLmoZOgZG0PmsVgbrnN0Ng@mail.gmail.com>
> >>> I think the bigger issues as you've pointed out are the cost of
> >>> the additional spin lock and should the additional state be
> >>> stored in-band (fewer cache lines) or out-of band (less risk of
> >>> breaking due to unpredictable application behavior).
> >>
> >> We don't need the spinlock if clearing the shadow byte after
> >> setting the status to user.
> >>
> >> Worst case, user will set it back to kernel while the shadow
> >> byte is not cleared yet and the next producer will drop a packet.
> >> But next producers will make progress, so there is no deadlock
> >> or corruption.
> >
> > I thought so too for a while but after spending more time than I
> > care to admit I relized the following sequence was occuring:
> >
> > Core A Core B
> > ------ ------
> > - Enter spin_lock
> > - Get tp_status of head (X)
> > tp_status == 0
> > - Check inuse
> > inuse == 0
> > - Allocate entry X
> > advance head (X+1)
> > set inuse=1
> > - Exit spin_lock
> >
> > <very long delay>
> >
> > <allocate N-1 entries
> > where N = size of ring>
> >
> > - Enter spin_lock
> > - get tp_status of head (X+N)
> > tp_status == 0 (but slot
> > in use for X on core A)
> >
> > - write tp_status of <--- trouble!
> > X = TP_STATUS_USER <--- trouble!
> > - write inuse=0 <--- trouble!
> >
> > - Check inuse
> > inuse == 0
> > - Allocate entry X+N
> > advance head (X+N+1)
> > set inuse=1
> > - Exit spin_lock
> >
> >
> > At this point Core A just passed slot X to userspace with a
> > packet and Core B has just been assigned slot X+N (same slot as
> > X) for it's new packet. Both cores A and B end up filling in that
> > slot. Tracking ths donw was one of the reasons it took me a
> > while to produce these updated diffs.
>
> Is this not just an ordering issue? Since inuse is set after tp_status,
> it has to be tested first (and barriers are needed to avoid reordering).
I changed the code as you suggest to do the inuse check first and
removed the extra added spin_lock/unlock and it seems to be working.
I was able to run through the night without an issue (normally I would
hit the ring corruption in 1 to 2 hours).
Thanks for pointing that out, I should have caught that myself. Next
I'll look at your suggestion for where to put the shadow ring.
next prev parent reply other threads:[~2018-05-23 11:08 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-19 12:07 Jon Rosen
2018-05-20 22:51 ` Willem de Bruijn
2018-05-20 23:22 ` Willem de Bruijn
2018-05-21 12:57 ` Jon Rosen (jrosen)
2018-05-21 17:07 ` Willem de Bruijn
2018-05-21 18:16 ` Jon Rosen (jrosen)
2018-05-22 15:41 ` Willem de Bruijn
2018-05-23 11:08 ` Jon Rosen (jrosen) [this message]
2018-05-22 14:12 ` Jon Rosen (jrosen)
2018-05-22 15:46 ` Willem de Bruijn
2018-05-23 11:54 ` Jon Rosen (jrosen)
2018-05-23 13:37 ` Willem de Bruijn
2018-05-23 15:29 ` Jon Rosen (jrosen)
2018-05-23 15:53 ` Willem de Bruijn
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=e942c1bbe48b451b92620396746986ab@XCH-RTP-016.cisco.com \
--to=jrosen@cisco.com \
--cc=bpoirier@suse.com \
--cc=davem@davemloft.net \
--cc=dwindsor@gmail.com \
--cc=edumazet@google.com \
--cc=elena.reshetova@intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maloney@google.com \
--cc=netdev@vger.kernel.org \
--cc=rami.rosen@intel.com \
--cc=tglx@linutronix.de \
--cc=willemb@google.com \
--cc=willemdebruijn.kernel@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome