Received: by 2002:a05:6500:2018:b0:1fb:9675:f89d with SMTP id t24csp41084lqh; Thu, 30 May 2024 13:20:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUToKdThbjPTdBBYNxEsoq6Wd8MJ6VHpE0jatWwA939rDWCJlTBvinZvZwcyGXuQ5YzDo84PpPAHEpX99I0zAPTUv1NfCoXWjfWEyCU+g== X-Google-Smtp-Source: AGHT+IGJ7Ll0jWqK633cWLvbxdJE0YRrRwB3ua+FJygK0MTDxAEK+PO/39BX9hHoF4EQkfwHUEv0 X-Received: by 2002:a05:6122:1686:b0:4ea:edac:3ae1 with SMTP id 71dfb90a1353d-4eaf21a0a92mr3797301e0c.5.1717100419550; Thu, 30 May 2024 13:20:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717100419; cv=pass; d=google.com; s=arc-20160816; b=mhOJZ9efWdHFknWOoBTBAkH45G9On5jpaRVXx+4PmMKtkxBnTy6QSkdqVX70sV5XUb ImZDw9G7/I+d+sha491NUuU0VTrFKQgmI2FCao/bN/4nUueYw+IFOeltuSN5eDBWOczk xNng8EEqgp79nrMmoxgBcsP/Q+yNX3eyuc9F4HKfwaRDseM1uKYU2zqWgKebZR5cFQsx paA99zbfI91gxiQeGVLeAdeOQ2dn7I8g+MU53vlXNhgrF034Bg5qfwpP7NtqQ8mOaebS KXy3auPrXoSYup4NeziKO/uHqJSp3OV3zCXdr3Sq9ymdyCpYDtMlOeyE1waMZNq8uzyj HY8A== 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=4VHwsybC76BjSd/TLfeeZU8mB9GHVxTARyHrEMUfZaU=; fh=GZ2XDknd9qFN1EVR0Ec6y1MfwhjCu/vQc02tH8rTu6Q=; b=J5tlG6C+ya69bUdR5+slrypFtgL+cq8dMQgfNouwKwY+FB9hq0t5zQxoA3I+ihak8Z OmUFwlbnaVfcsOzYC6YK21JfxMl/E5WPuFb1KMGRCHitzlIXBGYGkMatkepiLRiW/7QQ zaq6qyjYt7ggOXOusUDRwhqgNgHnXyrH96givCPor+bp3o8mjmZDqa4OSvUMq93xEb1e xPpfwAwR0aA/eHr+squDDSNRxD5U3Vx+4748s0PG6OdX4gdCqumxbhj5ZqoSPu6irT+q dwvnosZ4INFqJxSdyf097CU6ryyurOaby3yNhWhDWMaajC1/yq+7dZI9zIUIoE7Kup8W MG/Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=0DNszwm9; 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-195867-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195867-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-794f32a909csi31348385a.677.2024.05.30.13.20.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 13:20:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-195867-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=0DNszwm9; 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-195867-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-195867-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 3344D1C2342F for ; Thu, 30 May 2024 20:20:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 419EA194C99; Thu, 30 May 2024 20:16:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0DNszwm9" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.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 B5751178387 for ; Thu, 30 May 2024 20:16:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717100205; cv=none; b=tDdqWK8eHdqhKkB8/uvoNSUJFBirJRk6WWwgXmyIM3zAHgP7sumec9I8rOEasNrSPJ5EsXTPYgLln9Ry/u+Cl9SOH9lwyOswY1SZf0K+OJ9EIXQbsbnetEli/BA+MSwOCzD+PrBh3akhtbJIZfxiZTFt0m1/p+Qg3qh0CnlUuig= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717100205; c=relaxed/simple; bh=N/PKNPhbZAnFozij5TrzZpCLO8lVcepjbZBpWFLmKCc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=iD2DodQa/dLC1AdVfUk7Tr6wGmL1cyEDxSDWB8faICWWPTJKpAJ1Q7ygboiEyDdjQtap1FrEjyeDd8dOQWR8KNo6UrWxU95EblXfcoWtwTHRuC3sa8eXXncTdaYuh5XQ4I1DwiAdRuPFNI3syIRh7cyDCsLs5t62DVKgLyH5rMs= 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=0DNszwm9; arc=none smtp.client-ip=209.85.219.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-yb1-f202.google.com with SMTP id 3f1490d57ef6-dfa5a48b3b7so2533552276.0 for ; Thu, 30 May 2024 13:16:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1717100196; x=1717704996; 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=4VHwsybC76BjSd/TLfeeZU8mB9GHVxTARyHrEMUfZaU=; b=0DNszwm9VlTE1fke2Z58tl8VgcTVYNMSdaczNDerve6Qx6bASoOa7eo2+nUsBxv7ME Pycn6bKKNHcpKUF35CCQ1c9dDvEz5zgIrOqeuYamAw7+3w4e4v4eOyKrnOr821byDDhe jC7gpa+Kc1lkNTeKpbJLDxtkzrvzXlxAmGcmAdGg3UeoCftpQxqyPRGfJzEpJw3rmdf3 h4VxvZ0C7T6+HO87DJnrgnIylo1PI6kKFG3NL5gF1Stto2DcAkzjQlOOlaMgKW9ehnqU spSwuHu4eHG/laPte6I48CFziD2xsISeWIz/rBGx3w/SQ4Naf83YYy1Bowh8O/oA7U0N XoIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717100196; x=1717704996; 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=4VHwsybC76BjSd/TLfeeZU8mB9GHVxTARyHrEMUfZaU=; b=emzY3YArZxZbcIv4Iy3Z/QH7NCa7W/cdmbVu2DmJrHsHpamECRyvANYPDpmI2HxheB cJ+cERBKuTKk5LE8+TSfi/y87D7xN7idDMTgRCroyBzXZkIiHqi5BiKTqivueDC1C1Qw u7KB77bSMONJbQgoQe6lfZtNUOMo90HSx1EmqIJpVPU0ozhjj7C13LDc33WOxPUnVvKB zHJelanEqFu5uuAoyoL9a1GuYToapsHmp5YbDqcNynZDCPaTOST8d7vOiYt+NJSqRweI S7Od+yx+X/8wqdw3FGnfpfBUrxDXHMGlRR4NvTevpG38KpNHCm4CaHZJhleqs0BgfPCM HPfg== X-Forwarded-Encrypted: i=1; AJvYcCXvEBhHj2geoZM/4P5rOBGeub4kqBf4r1y3nh+3kMcclxTB+H6No7o86FbxBilsIul1w1sEIFNi1Vy+kmn3sJ+sw+lptztFQaJHSI3G X-Gm-Message-State: AOJu0YzDU+qE53x1EycpJLcV+DgTuajnmkyL6ZW2Uu73TqjLRCN3cdM2 cen+KGrCWxI788h5j+f5OYI/dtxOAtpCnH1QBXPfE6Tul5PG9h8Whb4m1nzFhCW0CKBoT7enqPi tXnlpjPukpPwqC0GQGom5MA== X-Received: from almasrymina.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:4bc5]) (user=almasrymina job=sendgmr) by 2002:a05:6902:102d:b0:df7:8c1b:430a with SMTP id 3f1490d57ef6-dfa5a5ae224mr744184276.3.1717100195557; Thu, 30 May 2024 13:16:35 -0700 (PDT) Date: Thu, 30 May 2024 20:16:08 +0000 In-Reply-To: <20240530201616.1316526-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: <20240530201616.1316526-1-almasrymina@google.com> X-Mailer: git-send-email 2.45.1.288.g0e0cd299f1-goog Message-ID: <20240530201616.1316526-10-almasrymina@google.com> Subject: [PATCH net-next v10 09/14] 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 , "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 , 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?=" , 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 981f5ef9e8580..bbbf3af99a14b 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 2e49a6ea21af3..99cf1ee73836d 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 5fa68e7f6ddbf..679cb51aaaf2b 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2171,6 +2171,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.1.288.g0e0cd299f1-goog