Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp735302lqt; Thu, 6 Jun 2024 17:56:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWWougEWWCHl3t85WQw+Z1AjOJAkwhrMrdYxbek6Rhc5UFcZTe9MDQlKMCkW2YnSraB6/mZKrkjNVlwjEqi586WJmG38BoONXlAdmkQlA== X-Google-Smtp-Source: AGHT+IG2EQDmoY6sa04tZm+BiqousoBF7K5QOEN8IHXVVAmBq52BjbN1G/JEXIYJamonL/FLcmlP X-Received: by 2002:a54:478c:0:b0:3c7:498c:6b0e with SMTP id 5614622812f47-3d210d2bd85mr1062194b6e.1.1717721793588; Thu, 06 Jun 2024 17:56:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717721793; cv=pass; d=google.com; s=arc-20160816; b=RbyPGTalsgLitVMZI/5MEOiAG+bb3F4Xn5OTiwHCU5IR4q5vNi4YkU3sJIVPjvDLaV EAQp49+57kWgfkQMeso+PxOJtVD48bgRdsfdQAX7D1YkSQyVioBgzeYRsKLe3Gz1cDOS HzCXV0XeAZzfSe2M7IA6RZmZ5Jzmey89ULAAoEGQ8NnafvsKjy9uyV2XeEKL5df0oxz/ gsNcSfxTY8OdCtrjYz/jimYSjnCJwvNhcFHb6dxqPTqVQDbMqaZubm8yCBNudxQqhLwk sm8Y9vFNcJuExbjdzMM5OphYU2aDstahx5p0R8FsL12Y8OD2MJhFTISkyxzsbXOTGVvz yszw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=N6xCNwW+oHdK+191elSmFQXDV8eNU/icLSxb9izKGcU=; fh=zD97DI9sQNXF3rpkwa2n5OyvATcR7GV5zzXfQNeJ5CM=; b=ku2udch0daYOFl7y99V0lofhNqcwue3whVCnu7aMYY3dnvdqoodGO33r8IwrgWVK2n GuqIMhoycdmoapArFX1vtwjwfDFFNevsi81+d7h5SPrdzi/Fsmb0iOq03OrxB7DcKUbg XLkncmS8JygzvW39IPgBPJBzkEfFpFgbSRwqaHjaaAAR0BOeONou2eG5qIZa1Cwyj+01 HXzsKG1URqHa4GR3uRRKk7l0pd4I675ovHziyrIz9JGrUczAV1g3+KorRbC4UQIw0kUZ mOWzP1qZx9BpwkBh+iJ0j9ce2CowO8ocSbiQTtSF23apF9qypCMZgMualvfVrjV5guAM acmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Gnp+qJto; arc=pass (i=1 spf=pass spfdomain=flex--almasrymina.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-205199-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205199-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id af79cd13be357-79533334505si193192785a.526.2024.06.06.17.56.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 17:56:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-205199-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=Gnp+qJto; arc=pass (i=1 spf=pass spfdomain=flex--almasrymina.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-205199-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-205199-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 405451C218E2 for ; Fri, 7 Jun 2024 00:56:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2791914F11A; Fri, 7 Jun 2024 00:52:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Gnp+qJto" Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EF889FC02 for ; Fri, 7 Jun 2024 00:51:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717721514; cv=none; b=Q3MUB1rhA+WGyBxUtsW32WE4tVAtY6nTFKxI5YBrUkWWDDmAEvgWuTmQEDON0VKnCGY+OZoRN1+U5Oe0C2bFt9bynoKgZYLUH9bwdBxAPssdyy4Msyg7y0Zpkdfo6bEsA7JWTHaL/j4ONrkmF9AO2glRRMxEgYcHSz2nKfUcH3Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717721514; c=relaxed/simple; bh=qXQG+NonAH1+PqrB3E+4t34SPZL0uZHfUL5dkTe2E7k=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=aPj/8UNRaBzz+YRgvYtZZ4xYAT4tXK9f4abCu1mksUMm8cuj/HjU6BtmIe4xA4FGFpWGyxfArcp8yWVdNh7ashZHg7rCxG1vkFx+riD95Y/8I+kaDbWHb2G7j83BbzvPPbX7WG6BhwLiNXPxiknTOHpGFmBvQl0hEEwEdRsuRzU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Gnp+qJto; arc=none smtp.client-ip=209.85.128.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--almasrymina.bounces.google.com Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-62a248f46aaso25182647b3.0 for ; Thu, 06 Jun 2024 17:51:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717721507; x=1718326307; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=N6xCNwW+oHdK+191elSmFQXDV8eNU/icLSxb9izKGcU=; b=Gnp+qJtoUH562hFy8/0X14KJKanhXsKB/50hajgCYoNP4ZnYo2q/DRSuLzTsLQz3CA rYWkCAPUqCu5i9gwyckOcY7NF0gpdVTeJUpZeTUg14y0iWx3SD9ag8kbLQFidMnF7f+c oSXm/H9DZZyL4nRcfqk7O5oIipMJihAg1LIKOlIA/pfO8PMl1t5ye2MZ+pxFjVZj6d6t KhimZtNpLu1iUSl5Rrw7Jj+Htx1S5lP13JOniS3hVXza6QHi+wgBCEAAiceK+nE5qD6X u55UCanD/7/Dh0VnwttfGIYGZAoUbbmOt/obTdoc4ACBgT5HVVnhhW7M4wxRb7dqfnbH /9wA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717721507; x=1718326307; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=N6xCNwW+oHdK+191elSmFQXDV8eNU/icLSxb9izKGcU=; b=NLR309QqvWfR8mxE2Umo2DVAfNJyiHx8OsavhnJY38CD/p19DK2uEwcwvJxkiat/ts VHELsIaJttSJUydyF8GXXyxeY/rTob5D9PJlzEVfVM79/uwI/vQnkhQNNcCQps0YeWrt 0c5stFmSJbikK64it9LEU9hN8a4ysHxfG9LQG8uW5DCpHVoKxDsP/KMtqLYlucNUcpQ+ IYtnY4zqFqZ1Q7a4J8OunBypsJ70xeSb97YCPceAiskJaXwCffuKFR+NZh5ssdFKZpMR tEX7H28AYbB4a2K98RkjEGgDcoqNzExHXmnUmqOteLjsP6O/vQr0PB9pq2rAMsCRpMqN HCIQ== X-Forwarded-Encrypted: i=1; AJvYcCVWCNLLxOyyOQYUOQ1SD73etn1fReSCFC1eAKJD7H56mSYVtKfBk6g1m9160b1gFKbdNMtVCGqEQCYvuFMNiaj7k9TEWoucKRikxN/+ X-Gm-Message-State: AOJu0YwmFeJihAwFKQsYthbg5AMBr9s6J514JqmYj6p/zP73iHHP47Re LEJ6ZT5VkmpN24ZfsdFWscPFe4rbugW54QYT3WWKaUxpMYI6irm/3ShJsuWXzSKV47W8X3BoSKT o7pohnIzsZtlda8XovcD2SQ== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a05:690c:ecc:b0:61a:dcd0:5a61 with SMTP id 00721157ae682-62cd5657808mr2127387b3.7.1717721506925; Thu, 06 Jun 2024 17:51:46 -0700 (PDT) Date: Fri, 7 Jun 2024 00:51:18 +0000 In-Reply-To: <20240607005127.3078656-1-almasrymina@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240607005127.3078656-1-almasrymina@google.com> X-Mailer: git-send-email 2.45.2.505.gda0bf45e8d-goog Message-ID: <20240607005127.3078656-9-almasrymina@google.com> Subject: [PATCH net-next v11 08/13] net: support non paged skb frags From: Mina Almasry To: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, sparclinux@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-arch@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org Cc: Mina Almasry , Donald Hunter , Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni , Jonathan Corbet , Richard Henderson , Ivan Kokshaysky , Matt Turner , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Andreas Larsson , Jesper Dangaard Brouer , Ilias Apalodimas , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Arnd Bergmann , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Steffen Klassert , Herbert Xu , David Ahern , Willem de Bruijn , Shuah Khan , Sumit Semwal , "=?UTF-8?q?Christian=20K=C3=B6nig?=" , Bagas Sanjaya , Christoph Hellwig , Nikolay Aleksandrov , Pavel Begunkov , David Wei , Jason Gunthorpe , Yunsheng Lin , Shailend Chand , Harshitha Ramamurthy , Shakeel Butt , Jeroen de Borst , Praveen Kaligineedi Content-Type: text/plain; charset="UTF-8" Make skb_frag_page() fail in the case where the frag is not backed by a page, and fix its relevant callers to handle this case. Signed-off-by: Mina Almasry --- v10: - Fixed newly generated kdoc warnings found by patchwork. While we're at it, fix the Return section of the functions I touched. v6: - Rebased on top of the merged netmem changes. Changes in v1: - Fix illegal_highdma() (Yunsheng). - Rework napi_pp_put_page() slightly to reduce code churn (Willem). --- include/linux/skbuff.h | 42 +++++++++++++++++++++++++++++++++++++- include/linux/skbuff_ref.h | 9 ++++---- net/core/dev.c | 3 ++- net/core/gro.c | 3 ++- net/core/skbuff.c | 11 ++++++++++ net/ipv4/esp4.c | 3 ++- net/ipv4/tcp.c | 3 +++ net/ipv6/esp6.c | 3 ++- 8 files changed, 67 insertions(+), 10 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index fe7d8dbef77e1..0a4df0025e6dc 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3492,21 +3492,58 @@ static inline void skb_frag_off_copy(skb_frag_t *fragto, fragto->offset = fragfrom->offset; } +/* Return: true if the skb_frag contains a net_iov. */ +static inline bool skb_frag_is_net_iov(const skb_frag_t *frag) +{ + return netmem_is_net_iov(frag->netmem); +} + +/** + * skb_frag_net_iov - retrieve the net_iov referred to by fragment + * @frag: the fragment + * + * Return: the &struct net_iov associated with @frag. Returns NULL if this + * frag has no associated net_iov. + */ +static inline struct net_iov *skb_frag_net_iov(const skb_frag_t *frag) +{ + if (!skb_frag_is_net_iov(frag)) + return NULL; + + return netmem_to_net_iov(frag->netmem); +} + /** * skb_frag_page - retrieve the page referred to by a paged fragment * @frag: the paged fragment * - * Returns the &struct page associated with @frag. + * Return: the &struct page associated with @frag. Returns NULL if this frag + * has no associated page. */ static inline struct page *skb_frag_page(const skb_frag_t *frag) { + if (skb_frag_is_net_iov(frag)) + return NULL; + return netmem_to_page(frag->netmem); } +/** + * skb_frag_netmem - retrieve the netmem referred to by a fragment + * @frag: the fragment + * + * Return: the &netmem_ref associated with @frag. + */ +static inline netmem_ref skb_frag_netmem(const skb_frag_t *frag) +{ + return frag->netmem; +} + int skb_pp_cow_data(struct page_pool *pool, struct sk_buff **pskb, unsigned int headroom); int skb_cow_data_for_xdp(struct page_pool *pool, struct sk_buff **pskb, struct bpf_prog *prog); + /** * skb_frag_address - gets the address of the data contained in a paged fragment * @frag: the paged fragment buffer @@ -3516,6 +3553,9 @@ int skb_cow_data_for_xdp(struct page_pool *pool, struct sk_buff **pskb, */ static inline void *skb_frag_address(const skb_frag_t *frag) { + if (!skb_frag_page(frag)) + return NULL; + return page_address(skb_frag_page(frag)) + skb_frag_off(frag); } diff --git a/include/linux/skbuff_ref.h b/include/linux/skbuff_ref.h index 16c241a234728..0f3c58007488a 100644 --- a/include/linux/skbuff_ref.h +++ b/include/linux/skbuff_ref.h @@ -34,14 +34,13 @@ static inline void skb_frag_ref(struct sk_buff *skb, int f) bool napi_pp_put_page(netmem_ref netmem); -static inline void -skb_page_unref(struct page *page, bool recycle) +static inline void skb_page_unref(netmem_ref netmem, bool recycle) { #ifdef CONFIG_PAGE_POOL - if (recycle && napi_pp_put_page(page_to_netmem(page))) + if (recycle && napi_pp_put_page(netmem)) return; #endif - put_page(page); + put_page(netmem_to_page(netmem)); } /** @@ -54,7 +53,7 @@ skb_page_unref(struct page *page, bool recycle) */ static inline void __skb_frag_unref(skb_frag_t *frag, bool recycle) { - skb_page_unref(skb_frag_page(frag), recycle); + skb_page_unref(skb_frag_netmem(frag), recycle); } /** diff --git a/net/core/dev.c b/net/core/dev.c index 25faa1fd64fc1..9fd81cf68350f 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3432,8 +3432,9 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb) if (!(dev->features & NETIF_F_HIGHDMA)) { for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) { skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; + struct page *page = skb_frag_page(frag); - if (PageHighMem(skb_frag_page(frag))) + if (page && PageHighMem(page)) return 1; } } diff --git a/net/core/gro.c b/net/core/gro.c index b3b43de1a6502..26f09c3e830b7 100644 --- a/net/core/gro.c +++ b/net/core/gro.c @@ -408,7 +408,8 @@ static inline void skb_gro_reset_offset(struct sk_buff *skb, u32 nhoff) pinfo = skb_shinfo(skb); frag0 = &pinfo->frags[0]; - if (pinfo->nr_frags && !PageHighMem(skb_frag_page(frag0)) && + if (pinfo->nr_frags && skb_frag_page(frag0) && + !PageHighMem(skb_frag_page(frag0)) && (!NET_IP_ALIGN || !((skb_frag_off(frag0) + nhoff) & 3))) { NAPI_GRO_CB(skb)->frag0 = skb_frag_address(frag0); NAPI_GRO_CB(skb)->frag0_len = min_t(unsigned int, diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 5aaaa796c5fb4..a0cd848a18dfa 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -1352,6 +1352,14 @@ void skb_dump(const char *level, const struct sk_buff *skb, bool full_pkt) struct page *p; u8 *vaddr; + if (skb_frag_is_net_iov(frag)) { + printk("%sskb frag %d: not readable\n", level, i); + len -= skb_frag_size(frag); + if (!len) + break; + continue; + } + skb_frag_foreach_page(frag, skb_frag_off(frag), skb_frag_size(frag), p, p_off, p_len, copied) { @@ -3142,6 +3150,9 @@ static bool __skb_splice_bits(struct sk_buff *skb, struct pipe_inode_info *pipe, for (seg = 0; seg < skb_shinfo(skb)->nr_frags; seg++) { const skb_frag_t *f = &skb_shinfo(skb)->frags[seg]; + if (WARN_ON_ONCE(!skb_frag_page(f))) + return false; + if (__splice_segment(skb_frag_page(f), skb_frag_off(f), skb_frag_size(f), offset, len, spd, false, sk, pipe)) diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c index 3968d3f98e083..4ce0bc41e7806 100644 --- a/net/ipv4/esp4.c +++ b/net/ipv4/esp4.c @@ -115,7 +115,8 @@ static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb) */ if (req->src != req->dst) for (sg = sg_next(req->src); sg; sg = sg_next(sg)) - skb_page_unref(sg_page(sg), skb->pp_recycle); + skb_page_unref(page_to_netmem(sg_page(sg)), + skb->pp_recycle); } #ifdef CONFIG_INET_ESPINTCP diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c index 6553221694ec2..5395f0e22c65f 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2176,6 +2176,9 @@ static int tcp_zerocopy_receive(struct sock *sk, break; } page = skb_frag_page(frags); + if (WARN_ON_ONCE(!page)) + break; + prefetchw(page); pages[pages_to_map++] = page; length += PAGE_SIZE; diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c index 34a9a5b9ed00b..0318aea0d4ce6 100644 --- a/net/ipv6/esp6.c +++ b/net/ipv6/esp6.c @@ -132,7 +132,8 @@ static void esp_ssg_unref(struct xfrm_state *x, void *tmp, struct sk_buff *skb) */ if (req->src != req->dst) for (sg = sg_next(req->src); sg; sg = sg_next(sg)) - skb_page_unref(sg_page(sg), skb->pp_recycle); + skb_page_unref(page_to_netmem(sg_page(sg)), + skb->pp_recycle); } #ifdef CONFIG_INET6_ESPINTCP -- 2.45.2.505.gda0bf45e8d-goog