From: Eric Dumazet <eric.dumazet@gmail.com>
To: Saeed Mahameed <saeedm@dev.mellanox.co.il>
Cc: Saeed Mahameed <saeedm@mellanox.com>,
"David S. Miller" <davem@davemloft.net>,
Linux Netdev List <netdev@vger.kernel.org>,
Or Gerlitz <ogerlitz@mellanox.com>,
Eran Ben Elisha <eranbe@mellanox.com>,
Tal Alon <talal@mellanox.com>, Tariq Toukan <tariqt@mellanox.com>,
Jesper Dangaard Brouer <brouer@redhat.com>
Subject: Re: [PATCH net-next 08/13] net/mlx5e: Add fragmented memory support for RX multi packet WQE
Date: Fri, 11 Mar 2016 11:58:39 -0800 [thread overview]
Message-ID: <1457726319.2663.50.camel@edumazet-ThinkPad-T530> (raw)
In-Reply-To: <CALzJLG_XU-KMp8dMqcNOpu1OxZRnJro4LFQohK=FLX+5uJKXpQ@mail.gmail.com>
On ven., 2016-03-11 at 21:25 +0200, Saeed Mahameed wrote:
> >> -void mlx5e_handle_rx_cqe_mpwrq(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe)
> >> +static void mlx5e_add_skb_frag(struct sk_buff *skb, int len, struct page *page,
> >> + int page_offset)
> >> +{
> >> + int f = skb_shinfo(skb)->nr_frags++;
> >> + skb_frag_t *fr = &skb_shinfo(skb)->frags[f];
> >> +
> >> + skb->len += len;
> >> + skb->data_len += len;
> >> + get_page(page);
> >> + skb_frag_set_page(skb, f, page);
> >> + skb_frag_size_set(fr, len);
> >> + fr->page_offset = page_offset;
> >> + skb->truesize = SKB_TRUESIZE(skb->len);
> >> +}
> >
> > Really I am speechless.
> >
> > It is hard to believe how much effort some drivers authors spend trying
> > to fool linux stack and risk OOM a host under stress.
>
> Eric, you got it all wrong my friend, no one is trying to fool nobody here.
> I will explain it to you below.
>
> >
> > SKB_TRUESIZE() is absolutely not something a driver is allowed to use.
> >
> > Here you want instead :
> >
> > skb->truesize += PAGE_SIZE;
> >
> > Assuming you allocate and use an order-0 page per fragment. Fact that
> > you receive say 100 bytes datagram is irrelevant to truesize.
>
> Your assumption is wrong, we allocate as many pages as a WQE needs,
> and a WQE can describe/handle
> up to 1024 packets which share the same page/pages, so the skb should
> really have a true size of the strides
> of that page it used and not the WHOLE page as you think.
>
> you should already learn this from the previous patch.
>
> each WQE (Receive Work Queue Element) contains 1024 strides each of
> the size 128B,
> i.e, a packet of the size 128B or less will consume only one stride of
> that WQE page, next packets on that WQE
> will use the following strides in that same page.
>
> So in opposite of what you think this new scheme is better than our
> old one in terms of memory utilization.
> before, we wasted MTU size per SKB/Packet regardless of the real
> packet size, now each SKB will consume only
> as much as 128B strides it will need, no more no less.
>
> BTW there will be only 16 WQEs per ring :), so this new approach
> doesn't drastically consume more memory than the previous one.
> But it sure can handle more small packets bursts.
>
> >
> > truesize is the real memory usage of one skb. Not the minimal size of an
> > optimally allocated skb for a given payload.
>
> I totally agree with this, we should have reported skb->truesize +=
> (consumed strides)*(stride size).
> but again this is not as critical as you think, in the worst case
> skb->truesize will be off by 127B at most.
Ouch. really you are completely wrong.
If one skb has a fragment of a page, and sits in a queue for a long
time, it really uses a full page, because the remaining part of the page
is not reusable. Only kmalloc(128) can deal with that idea of allowing
other parts of the page being 'freed and reusable'
It is trivial for an attacker to make sure the host will consume one
page + sk_buff + skb->head = 4096 + 256 + 512, by specially sending out
of order packets on TCP flows.
It is very tempting to have special memory allocators you know, but you
have to understand attackers are smart. Smarter than us.
If now you are telling me you plan to allocate 131072 bytes pages (1024
strides of 128 bytes), then a smart attacker can actually bump skb
truesize to 128KB
Really your RX allocation schem is easily DOSable.
next prev parent reply other threads:[~2016-03-11 19:58 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-03-11 13:39 [PATCH net-next 00/13] Mellanox 100G mlx5 driver receive path optimizations Saeed Mahameed
2016-03-11 13:39 ` [PATCH net-next 01/13] net/mlx5: Refactor mlx5_core_mr to mkey Saeed Mahameed
2016-03-11 13:39 ` [PATCH net-next 02/13] net/mlx5: Introduce device queue counters Saeed Mahameed
2016-03-11 13:39 ` [PATCH net-next 03/13] net/mlx5e: Allocate set of queue counters per netdev Saeed Mahameed
2016-03-11 13:39 ` [PATCH net-next 04/13] net/mlx5e: Use only close NUMA node for default RSS Saeed Mahameed
2016-03-11 14:08 ` Sergei Shtylyov
2016-03-11 19:29 ` Saeed Mahameed
2016-03-11 13:39 ` [PATCH net-next 05/13] net/mlx5e: Use function pointers for RX data path handling Saeed Mahameed
2016-03-11 13:39 ` [PATCH net-next 06/13] net/mlx5e: Support RX multi-packet WQE (Striding RQ) Saeed Mahameed
2016-03-14 21:33 ` Jesper Dangaard Brouer
2016-03-11 13:39 ` [PATCH net-next 07/13] net/mlx5e: Added ICO SQs Saeed Mahameed
2016-03-11 13:39 ` [PATCH net-next 08/13] net/mlx5e: Add fragmented memory support for RX multi packet WQE Saeed Mahameed
2016-03-11 14:32 ` Eric Dumazet
2016-03-11 19:25 ` Saeed Mahameed
2016-03-11 19:58 ` Eric Dumazet [this message]
2016-03-13 10:29 ` achiad shochat
2016-03-14 18:16 ` Saeed Mahameed
2016-03-14 19:16 ` achiad shochat
2016-03-14 20:26 ` Eric Dumazet
2016-03-14 20:29 ` Eric Dumazet
2016-03-14 20:23 ` Eric Dumazet
2016-03-11 13:39 ` [PATCH net-next 09/13] net/mlx5e: Change RX moderation period to be based on CQE Saeed Mahameed
2016-03-11 13:39 ` [PATCH net-next 10/13] net/mlx5e: Use napi_alloc_skb for RX SKB allocations Saeed Mahameed
2016-03-11 13:39 ` [PATCH net-next 11/13] net/mlx5e: Prefetch next RX CQE Saeed Mahameed
2016-03-11 13:39 ` [PATCH net-next 12/13] net/mlx5e: Remove redundant barrier Saeed Mahameed
2016-03-11 13:39 ` [PATCH net-next 13/13] net/mlx5e: Add ethtool counter for RX SKB allocation failures Saeed Mahameed
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=1457726319.2663.50.camel@edumazet-ThinkPad-T530 \
--to=eric.dumazet@gmail.com \
--cc=brouer@redhat.com \
--cc=davem@davemloft.net \
--cc=eranbe@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=ogerlitz@mellanox.com \
--cc=saeedm@dev.mellanox.co.il \
--cc=saeedm@mellanox.com \
--cc=talal@mellanox.com \
--cc=tariqt@mellanox.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