public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: 'Marcelo Ricardo Leitner' <marcelo.leitner@gmail.com>
To: David Laight <David.Laight@ACULAB.COM>
Cc: 'Xin Long' <lucien.xin@gmail.com>,
	network dev <netdev@vger.kernel.org>,
	"linux-sctp@vger.kernel.org" <linux-sctp@vger.kernel.org>,
	Neil Horman <nhorman@tuxdriver.com>,
	"davem@davemloft.net" <davem@davemloft.net>
Subject: Re: [PATCHv2 net-next 04/12] sctp: implement make_datafrag for sctp_stream_interleave
Date: Fri, 8 Dec 2017 14:02:04 -0200	[thread overview]
Message-ID: <20171208160204.GU13341@localhost.localdomain> (raw)
In-Reply-To: <60df84ed900b49799782a43c84be0bc4@AcuMS.aculab.com>

On Fri, Dec 08, 2017 at 03:32:54PM +0000, David Laight wrote:
> From: 'Marcelo Ricardo Leitner'
> > Sent: 08 December 2017 15:16
> > On Fri, Dec 08, 2017 at 03:01:31PM +0000, David Laight wrote:
> > > From: Marcelo Ricardo Leitner
> > > > Sent: 08 December 2017 14:57
> > > >
> > > > On Fri, Dec 08, 2017 at 02:06:04PM +0000, David Laight wrote:
> > > > > From: Xin Long
> > > > > > Sent: 08 December 2017 13:04
> > > > > ...
> > > > > > @@ -264,8 +264,8 @@ struct sctp_datamsg *sctp_datamsg_from_user(struct sctp_association *asoc,
> > > > > >  				frag |= SCTP_DATA_SACK_IMM;
> > > > > >  		}
> > > > > >
> > > > > > -		chunk = sctp_make_datafrag_empty(asoc, sinfo, len, frag,
> > > > > > -						 0, GFP_KERNEL);
> > > > > > +		chunk = asoc->stream.si->make_datafrag(asoc, sinfo, len, frag,
> > > > > > +						       GFP_KERNEL);
> > > > >
> > > > > I know that none of the sctp code is very optimised, but that indirect
> > > > > call is going to be horrid.
> > > >
> > > > Yeah.. but there is no way to avoid the double derreference
> > > > considering we only have the asoc pointer in there and we have to
> > > > reach the contents of the data chunk operations struct, and the .si
> > > > part is the same as 'stream' part as it's a constant offset.
> > > ...
> > >
> > > It isn't only the double indirect, the indirect call itself isn't 'fun'.
> > 
> > I meant in this context.
> > 
> > The indirect call is so we don't have to flood the stack with
> > if (old data chunk fmt) {
> > 	...
> > } else {
> > 	...
> > }
> > 
> > So instead of this, we now have some key operations identified and
> > wrapped up behind this struct, allowing us to abstract whatever data
> > chunk format it is.
> 
> Nothing wrong with:
> #define foo(asoc, ...) \
> 	if (asoc->new_fmt) \

Not all function pointers in sctp_stream_interleave have asoc as
a parameter, so we would have to have something like:

#define foo_asoc(asoc, ...) \
	if (asoc->new_fmt) \
		...

#define foo_chunk(chunk, ...) \
	if (chunk->asoc->new_fmt) \
		...

#define foo_ulpq(ulpq, ...) \
	if (ulpq->asoc->new_fmt) \
		...

and we're pretty much back to double deref.
Maybe some reworking on the parameters could alleviate some of these,
but not all.

> 		foo_new(asoc, __VA_LIST__); \
> 	else \
> 		foo_old(asoc, __VA_LIST__);
> 
> > > I think there are other hot paths where you've replaced a sizeof()
> > > with a ?: clause.
> > > Caching the result might be much better.
> > 
> > The only new ?: clause I could find this patchset is on patch 12 and
> > has nothing to do with sizeof().
> > 
> > The sizeof() results are indeed cached, as you can see in patch 4:
> > +static struct sctp_stream_interleave sctp_stream_interleave_0 = {
> > +       .data_chunk_len         = sizeof(struct sctp_data_chunk),
> > and the two helpers on it at the begining of the patch.
> 
> I was getting two bits mixed up.
> But the code that reads data_chunk_len is following an awful lot of pointers.

>From path 4:
        max_data = asoc->pathmtu -
                   sctp_sk(asoc->base.sk)->pf->af->net_header_len -
-                  sizeof(struct sctphdr) - sizeof(struct sctp_data_chunk);
+                  sizeof(struct sctphdr) - sctp_datachk_len(&asoc->stream);

You're worried with the double deref in sctp_datachk_len() but on the
line right above it we have 4 derefs. There are several other cases
of double deref in sctp stack even on hot path. Not sure why you're
picking on this one, but ok.

  Marcelo

  reply	other threads:[~2017-12-08 16:02 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-08 13:03 [PATCHv2 net-next 00/12] sctp: Implement Stream Interleave: The I-DATA Chunk Supporting User Message Interleaving Xin Long
2017-12-08 13:03 ` [PATCHv2 net-next 01/12] sctp: add stream interleave enable members and sockopt Xin Long
2017-12-08 13:03 ` [PATCHv2 net-next 02/12] sctp: add asoc intl_enable negotiation during 4 shakehands Xin Long
2017-12-08 13:04 ` [PATCHv2 net-next 03/12] sctp: add basic structures and make chunk function for idata Xin Long
2017-12-08 13:04 ` [PATCHv2 net-next 04/12] sctp: implement make_datafrag for sctp_stream_interleave Xin Long
2017-12-08 14:06   ` David Laight
2017-12-08 14:56     ` Marcelo Ricardo Leitner
2017-12-08 15:01       ` David Laight
2017-12-08 15:15         ` 'Marcelo Ricardo Leitner'
2017-12-08 15:32           ` David Laight
2017-12-08 16:02             ` 'Marcelo Ricardo Leitner' [this message]
2017-12-08 15:37       ` Neil Horman
2017-12-08 16:00         ` Marcelo Ricardo Leitner
2017-12-08 16:04           ` David Laight
2017-12-08 16:08             ` Neil Horman
2017-12-08 20:37               ` 'Marcelo Ricardo Leitner'
2017-12-08 16:17           ` Xin Long
2017-12-08 16:22             ` David Laight
2017-12-08 17:23               ` Xin Long
2017-12-08 17:29                 ` David Laight
2017-12-08 17:37                   ` Xin Long
2017-12-08 13:04 ` [PATCHv2 net-next 05/12] sctp: implement assign_number " Xin Long
2017-12-08 13:04 ` [PATCHv2 net-next 06/12] sctp: implement validate_data " Xin Long
2017-12-08 13:04 ` [PATCHv2 net-next 07/12] sctp: implement ulpevent_data " Xin Long
2017-12-08 13:04 ` [PATCHv2 net-next 08/12] sctp: implement enqueue_event " Xin Long
2017-12-08 13:04 ` [PATCHv2 net-next 09/12] sctp: implement renege_events " Xin Long
2017-12-08 13:04 ` [PATCHv2 net-next 10/12] sctp: implement start_pd " Xin Long
2017-12-08 13:04 ` [PATCHv2 net-next 11/12] sctp: implement abort_pd " Xin Long
2017-12-08 13:04 ` [PATCHv2 net-next 12/12] sctp: add support for the process of unordered idata Xin Long
2017-12-11 16:23 ` [PATCHv2 net-next 00/12] sctp: Implement Stream Interleave: The I-DATA Chunk Supporting User Message Interleaving David Miller

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=20171208160204.GU13341@localhost.localdomain \
    --to=marcelo.leitner@gmail.com \
    --cc=David.Laight@ACULAB.COM \
    --cc=davem@davemloft.net \
    --cc=linux-sctp@vger.kernel.org \
    --cc=lucien.xin@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=nhorman@tuxdriver.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