Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5872167pxb; Tue, 16 Feb 2021 09:32:15 -0800 (PST) X-Google-Smtp-Source: ABdhPJxxuQCoQkd3i0qg+rdGOP+MbZ8+g3+Oxf4AZTetdlWtlow1SR6QFm8oSNcTEVlvnHykcIvE X-Received: by 2002:a17:906:fa05:: with SMTP id lo5mr10649567ejb.544.1613496735445; Tue, 16 Feb 2021 09:32:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613496735; cv=none; d=google.com; s=arc-20160816; b=C6siLBRO2g1LphYie+SEu18OD4abpipbdSv7UhVyzLj2U2Rav4066F+r0amIowuNJG 4FDY3Xh/nEDy87XsjeNNyj9MsfuLReDT3N+l20d9XzqvydXCrtsikm93DgTmfUSUihWW foPllkiLEI7n/TMGHI1XbOthkpwYVD4+xdT7X4GBRQCo0rvoZdwW8xWhi0Uvf7dCvxL8 f+Lo8pcgJUEWRsnjNfbrNcd9ilGtUfGimbJQ+j7AxJqEosHZXiY5dieubkAxHoD/yPu2 5Ks2sAzJiR/IDzSyxtjIYCLWfpjYsLyi9ximobZE04STJY/iC4/71X7C2win4YpFu2cf gZhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:reply-to:cc:from:to :dkim-signature:date; bh=rD+msxxQv7QdHAN2CCbl57zhJ/ALAb4aGQXqzumABFM=; b=bMsNt5h7xcGdOegRJCdkbYdF+c7nieYswqrfgwbUtGYWlo78cYYpYMUUbQ8ayuFFXm lU6gr2ypNJicSyAz4bB8WrcM6Pzj71UFAv2hp830FipVpor8ujS1o/J6HuYYu3rFEjYB nCZ9em+x9oUGGLBZVyC6ijhjS/W/46aSzkyfF5BOU7RZO6Akb4Gc5hv9ELhKTmTNM4dW PDUKs7p9g/VGjEzNK5Xi7R5yI8m1yACV2A7t67FhnI8cIVQ1DbzU2fCxQ/zuZzx3iFvJ rC80sALaB8lDbnZkQoPG5zV3WL0Fhf5dUCauAMvsKGYsqrtvERU5G479dgnCmEAWAf2W Mr0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=Ni6bHfF4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id zm17si13170825ejb.174.2021.02.16.09.31.52; Tue, 16 Feb 2021 09:32:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=Ni6bHfF4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231176AbhBPRa3 (ORCPT + 99 others); Tue, 16 Feb 2021 12:30:29 -0500 Received: from mail-40134.protonmail.ch ([185.70.40.134]:24793 "EHLO mail-40134.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231180AbhBPR2x (ORCPT ); Tue, 16 Feb 2021 12:28:53 -0500 Date: Tue, 16 Feb 2021 17:28:01 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1613496489; bh=rD+msxxQv7QdHAN2CCbl57zhJ/ALAb4aGQXqzumABFM=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=Ni6bHfF4XFjx2ia6fO83Q0T518R6Bel8xuoyg+zv8ELN+MYQjZ5VeId9LyxU76t1X nfH2p9IRFZk6CFbotdwRXLqAlRzys65NPwy667ttMX/l3gvr0sZRIk7S9BXm2fVWbx sxpEo6BMpSOEIVUhyfTIXWciksEtsLXqray4Sae6ahQYlTr3DFhT6WzlSSl6/dbhTx iMEwZ6vK9yDLyK/cOjPL/K/7u2utm6iqh5Jjc4Wf+kFUP3/m1OGVv+Mkm/xanPxg/S 1YmxrUP19F1jZDdjqNCNo5vE5rJXGs+TMycFWCq3oqVYYTPX3bzljFVRsopQMwlXA5 y07XqhHkrv1gA== To: Magnus Karlsson , =?utf-8?Q?Bj=C3=B6rn_T=C3=B6pel?= From: Alexander Lobakin Cc: "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Jakub Kicinski , Jonathan Lemon , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Paolo Abeni , Eric Dumazet , Xuan Zhuo , Dust Li , Alexander Lobakin , virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Reply-To: Alexander Lobakin Subject: [PATCH v6 bpf-next 5/6] xsk: respect device's headroom and tailroom on generic xmit path Message-ID: <20210216172640.374487-6-alobakin@pm.me> In-Reply-To: <20210216172640.374487-1-alobakin@pm.me> References: <20210216172640.374487-1-alobakin@pm.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-1.2 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org xsk_generic_xmit() allocates a new skb and then queues it for xmitting. The size of new skb's headroom is desc->len, so it comes to the driver/device with no reserved headroom and/or tailroom. Lots of drivers need some headroom (and sometimes tailroom) to prepend (and/or append) some headers or data, e.g. CPU tags, device-specific headers/descriptors (LSO, TLS etc.), and if case of no available space skb_cow_head() will reallocate the skb. Reallocations are unwanted on fast-path, especially when it comes to XDP, so generic XSK xmit should reserve the spaces declared in dev->needed_headroom and dev->needed tailroom to avoid them. Note on max(NET_SKB_PAD, L1_CACHE_ALIGN(dev->needed_headroom)): Usually, output functions reserve LL_RESERVED_SPACE(dev), which consists of dev->hard_header_len + dev->needed_headroom, aligned by 16. However, on XSK xmit hard header is already here in the chunk, so hard_header_len is not needed. But it'd still be better to align data up to cacheline, while reserving no less than driver requests for headroom. NET_SKB_PAD here is to double-insure there will be no reallocations even when the driver advertises no needed_headroom, but in fact need it (not so rare case). Fixes: 35fcde7f8deb ("xsk: support for Tx") Signed-off-by: Alexander Lobakin Acked-by: Magnus Karlsson --- net/xdp/xsk.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/net/xdp/xsk.c b/net/xdp/xsk.c index 4faabd1ecfd1..143979ea4165 100644 --- a/net/xdp/xsk.c +++ b/net/xdp/xsk.c @@ -454,12 +454,16 @@ static int xsk_generic_xmit(struct sock *sk) =09struct sk_buff *skb; =09unsigned long flags; =09int err =3D 0; +=09u32 hr, tr; =20 =09mutex_lock(&xs->mutex); =20 =09if (xs->queue_id >=3D xs->dev->real_num_tx_queues) =09=09goto out; =20 +=09hr =3D max(NET_SKB_PAD, L1_CACHE_ALIGN(xs->dev->needed_headroom)); +=09tr =3D xs->dev->needed_tailroom; + =09while (xskq_cons_peek_desc(xs->tx, &desc, xs->pool)) { =09=09char *buffer; =09=09u64 addr; @@ -471,11 +475,13 @@ static int xsk_generic_xmit(struct sock *sk) =09=09} =20 =09=09len =3D desc.len; -=09=09skb =3D sock_alloc_send_skb(sk, len, 1, &err); +=09=09skb =3D sock_alloc_send_skb(sk, hr + len + tr, 1, &err); =09=09if (unlikely(!skb)) =09=09=09goto out; =20 +=09=09skb_reserve(skb, hr); =09=09skb_put(skb, len); + =09=09addr =3D desc.addr; =09=09buffer =3D xsk_buff_raw_get_data(xs->pool, addr); =09=09err =3D skb_store_bits(skb, 0, buffer, len); --=20 2.30.1