Received: by 2002:ab2:6f44:0:b0:1fd:c486:4f03 with SMTP id l4csp101454lqq; Wed, 12 Jun 2024 18:41:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVARJ30Z37By1nm+bM2rUU1RDIstkPQaLySLqfrtXInXFvcGuKxr0bE0YEgc0OK2LoIeyw8Puzi4NoJ4o+Br/SMdbUPks+on2lQkdg1Yw== X-Google-Smtp-Source: AGHT+IGgpcyICY4O7J0CgFV5o7hh/uAjCRteIqfkhIWSRXR8MGYfFl6sguXgQVd3St6+EPjVf5WR X-Received: by 2002:a50:ccda:0:b0:57c:70b4:7ac with SMTP id 4fb4d7f45d1cf-57cb4be84e5mr967254a12.15.1718242881992; Wed, 12 Jun 2024 18:41:21 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718242881; cv=pass; d=google.com; s=arc-20160816; b=eVArFSc9L3gKQ5yOrvrJb5Sb3P6liX5by7TJqzV6NeRxuvW9ZRNgkLmqSyAAOyvNPn fg93ygIy4eGCXjRZtSw5VtsZKqYXA12NhXNVuoACPGotIdVCCOpfjQrYk90ImiCrFf56 q0rxYX78u6Zqs9x58+ZJGm6wYL+jLcMPrjbOc+6gXobAkjgdiAVlY2wEOWApmwxC/xAi 0s3Li92pMaEpfa7mStrG2JXksYYHdRFhvkVOPQGVjXFSzGEafI35e+JpL9VrRsDS1oSg KTYTC9bwVz2IBJEV8rCFx3g1mXVawEW8kkXOGVcrmVwou9eswm27vTIUeBuJ7+SRJLyb eBSg== 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=vke/Y3RXkHvuIo71y1CtZzQU8HQdeb5g5OtFy2OuzgA=; fh=YmX2suX9YhXhfPuwZalxD9y1cRc5FUQ5YgXjZniE3Nc=; b=BUtUg8RssbhIs2YNXpbq7q+4VIWiVRe6kEvdi01RItGFYRjdgBbod+s4RbK3qx8F+P xScDF4XGu7ztifmvQvAg6+DJ1pEA4A/4Gw8S1ZVH9crIQf9jN/QHLkWex6QUN3TsWEk2 rBP/gLXr0+bzX1ZYZWHThu6rtwSaRG26iYECHSMxEv3kC2vH9yM1ZQ3mX0dDzJHNd36I ku7WNkdq8HuPX8/ZpnQQVc+Ehu/aam/r3eiKq9OQZxe1iISWyPQ8CQwkiOIA4e+3Mm7w ikqAb6dQiffoXNFdpXL1t/7Z9SHZuzlUQ3Gjfm/d7C6+9sMJ1wRlOMCF/VNKtJXuuVpr quvA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CbnMPAle; 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-212442-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212442-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id 4fb4d7f45d1cf-57cb7441278si176687a12.393.2024.06.12.18.41.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 18:41:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212442-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=CbnMPAle; 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-212442-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212442-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 787201F22555 for ; Thu, 13 Jun 2024 01:41:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B9745137C5B; Thu, 13 Jun 2024 01:36:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="CbnMPAle" Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) (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 F1D8D12D775 for ; Thu, 13 Jun 2024 01:36:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718242584; cv=none; b=dz0AHCU90unCKbyuBL9bqkcdWzDgp1+a6+VINT0uMUVGGpurtyiySMRl7H2Tyudaynf0/e4R9r6EZ3JB0Ugbv1y5GxhvNmCg12+FlsMLwc6QhrTH+6w2W+BtAwg5Ki/lGwsvTsjY9DtyN4D8UvJsV2m4ZLYqLVMZhTLlYErnEJU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718242584; c=relaxed/simple; bh=K4AF1j255QRy5HdgD09ucSWi0i7X+QMh41WBKz6AdZI=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=Yjod/JX58CqEWOtj0JsWHnYFxsaPF+k2LV/G1dauEe5z2QWKYY6v4np9DzlsvY7kfquLdsh22i5fB3lBdDZk/kxwlJz79c9jHLalCoULxRWbaGhXwhDzBwcGZwGifIBA1OhaPxovcnstbbyIYslTmJUQdHsXvkM26iY2qvFMXA4= 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=CbnMPAle; arc=none smtp.client-ip=209.85.219.201 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-yb1-f201.google.com with SMTP id 3f1490d57ef6-dfa73db88dcso744876276.0 for ; Wed, 12 Jun 2024 18:36:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718242576; x=1718847376; 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=vke/Y3RXkHvuIo71y1CtZzQU8HQdeb5g5OtFy2OuzgA=; b=CbnMPAle8FUNqXAA/xgIHdq8FUO0lFvJGHiK03Ah5PxK6li/Qblljifu4dafBJP+QL VYHVIclGotwozq2mZmvvtH4B2kTR/9zT+PYoDuUneYPu6wdJ4Cvyy3urEvgRqAGnHBQQ yvNW7qMB5pN8RWPprZIFIW7pvwzhdpl259RV8QYspVcz2c2wc6AnMJfCy5T9XIaQR5/B WffEKoOdYmoob4J0IkHz5a3pZNu876GhFUEfYHQGXUyzb4LGBvE/2PkelsbHsChixp+8 pbfnuEmx/2Nh4VysMWyQWdNKbliGjeS3uCJfT5GgmypE5QxZzMMTGf+load9f+oJswPk ZoMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718242576; x=1718847376; 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=vke/Y3RXkHvuIo71y1CtZzQU8HQdeb5g5OtFy2OuzgA=; b=HG0hBPx+T7/YQGRkc2IPa8UWL6queXz6Z9hwqeOVQGDoiXWTHs7BGYk9DM5V1mq+mM rXHpVCFZGY7jTlBYdkDaQBE2O8fjRooJt9SMG6SEp1YpNbscgrrsKyODYZWDP52BeYrp /QAjiLmUuk+A/UZ1vQKxkdtiEJRvGvwm08MZiqjxxV4tYb5oHWD06bfntWXh/XsyZf66 FMtJcRanVlSYhOp9ZzU/5AvUvPULN+M78oqiak9yC3g0ksTyGGakab6NehjI4BbG+dVh wRwI4t2jc/o8vPWTRs1RCHyR4gJBYMkc5mZ9qixj0H/R+N/XqL7R4LsmSje7uCoMzfAg XKDA== X-Forwarded-Encrypted: i=1; AJvYcCWZayx6EiLzd4y4bWp8gHdRiBzf7k9bWC+XxoOJodgYyAtyOP4VLXrNTw6ZgKey98e0OrWmC7MIGOTWws+4FCXfr3nUjUxMaBlhuD2T X-Gm-Message-State: AOJu0Ywg3Q+/oFDBnghfHEKYG6zY6Z6vc6OwOlLoHfifusv/2pA61/tr QMiEsqu25vKBBYkW3IeQTR7+2ha9KAJCQ2z3Ev/n6ANVmYR35p+9EwGo2Zbdayj8MWj3DNkJhfC kIuFcnq1CC7gahi6hmDj1Bw== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a05:6902:150b:b0:dfb:5bd:17b2 with SMTP id 3f1490d57ef6-dfe6655a7a9mr278872276.2.1718242575969; Wed, 12 Jun 2024 18:36:15 -0700 (PDT) Date: Thu, 13 Jun 2024 01:35:45 +0000 In-Reply-To: <20240613013557.1169171-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: <20240613013557.1169171-1-almasrymina@google.com> X-Mailer: git-send-email 2.45.2.505.gda0bf45e8d-goog Message-ID: <20240613013557.1169171-9-almasrymina@google.com> Subject: [PATCH net-next v12 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-renesas-soc@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 , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Donald Hunter , Jonathan Corbet , Richard Henderson , Ivan Kokshaysky , Matt Turner , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Andreas Larsson , Sergey Shtylyov , 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 84c9f96a6c9bf..7bbc3d94e01fa 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 e03a342c9162b..8050148d302b1 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2177,6 +2177,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