From patchwork Mon Dec 18 02:40:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 180112 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:24d3:b0:fb:cd0c:d3e with SMTP id r19csp993491dyi; Sun, 17 Dec 2023 18:45:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IGPYG/Gmm4Qyiin2BAcEw52gTRwafSOiQI3mnM7kz5vaslYuwWBtN4BnlOj1VaDCWzdmHSi X-Received: by 2002:a05:6871:d10c:b0:1fa:ed79:4cc4 with SMTP id pi12-20020a056871d10c00b001faed794cc4mr18479383oac.6.1702867544957; Sun, 17 Dec 2023 18:45:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702867544; cv=none; d=google.com; s=arc-20160816; b=Y139TS5Q4d5kPYllYaANFQOILrGszCwCUADnol41x97opvzXqNx282Bt7Ls6ZBgkqE 7YvdMT0WJZTRLKS/wXbSJ30Z6loy1y/3Gy0U9wy4jJpvZBWXTGFNvwEzX+M9OplXtxM0 CMvtJIcpg8Q49zg1EQydfQELdzZ+XPmg6/qtGjzEVyW8fZIu5k5Jdo8CYh5ZvUxcmxdr 7zfXGDRgRkdHXe3Gf1nmIeypIkMEBmZhVOnXP3kpS/XvUs4fiw9KyYR31Jjjr1pAaRGT 4xbQ3Znz1hDkViWIdCs+rJ3s2t7fcvMvFXBwGAVn7zM7a/9qrGqSyfVUmImPSP3MzAit T7kQ== ARC-Message-Signature: i=1; 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=e7ZiIb8MLUHR5WE0ilENIpcZDtQSwPuT0/gwz/yRXbY=; fh=8Y9D+7Eqr15uC+q4uaUvZHfnG7pix6ubnhqqWosbV7w=; b=stxurNyBnlaxeeJzhMdWYHanWnRfCJ7q+Huc+YlZQexJOURg6pCMtbaPxWCZU3GWvq fY5H15t3LbBhk84aJsAMfpmcqw8uTAH71bjHXmD88V7QnpJG9GebX/zgyZgYvhN5jxhf h0YsY62EY/ayily9OhlRtRor1xjMa9TzxfhO1w8zuJ5+biUhZj5X5e8ODzt+u9+J3hwf 25DUszW7Gonc+Ff9U16VmfQ4seKzuKlz6uNlHIerQoqE/fWAJ/cvJ0pxOPoSedO9Hcwc BoIOLcsC3RDVk/4mZp8D36ceF+MEx0ZglA377LJ8i+KvNOD3gUDC20ROYjP8WXCFDsyM cccw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=3ILoJPf9; spf=pass (google.com: domain of linux-kernel+bounces-2933-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2933-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id s15-20020a63214f000000b005aa7d3730dfsi16718651pgm.114.2023.12.17.18.45.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Dec 2023 18:45:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-2933-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=3ILoJPf9; spf=pass (google.com: domain of linux-kernel+bounces-2933-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-2933-ouuuleilei=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id AA3A4280FC2 for ; Mon, 18 Dec 2023 02:45:44 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E1BAC14AA5; Mon, 18 Dec 2023 02:40:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="3ILoJPf9" X-Original-To: linux-kernel@vger.kernel.org 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 4743BF508 for ; Mon, 18 Dec 2023 02:40:49 +0000 (UTC) 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-dbcd4696599so2129837276.1 for ; Sun, 17 Dec 2023 18:40:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702867248; x=1703472048; 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=e7ZiIb8MLUHR5WE0ilENIpcZDtQSwPuT0/gwz/yRXbY=; b=3ILoJPf9205oVpGba9KbKAe530sNaVfOo7qkOKIHsCfvN8sCKr2ia1FRwsndv6v2wZ j/qQuCkP1E4p9fn8SSh86lfKGD1BdFlst5axvtP4xgKPoriHUPTw322tZ2XEveScNb7h uCwh16bN9HgOENMIyuF88fDnvBjGF1bG8EEiDQhfULpERctkWJJSV+/k9yF69LFQMsiL IhweCn7jeD4A5+tGn3Iwy9b7G36ZuFqJ5lIo8/N40xz85cS24RidtSAzq0ZjBT76hA5d KYDH5+vNSzpkSdgHF2sFm97Vk2LmQVIAFhyiuLz5oxpZUxx7U0fOmI9zg3/AUuFndHjR ggHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702867248; x=1703472048; 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=e7ZiIb8MLUHR5WE0ilENIpcZDtQSwPuT0/gwz/yRXbY=; b=uooV+xFisOeir1tESTH56TjkhzHGxJOF7NU1rnYuoFPtu5HYh06DUuwytwhEFgJSR0 xLpiCrkjU05VxELnW3wNz7Wj0OYhZRtclDhJuNMM83VsO/YMlr4B80HhGy5Xw3WpQqm3 OSbWOcl+zU/Ri6Meajqt8F7Yl+yibLqCoijqjfp8tPM7FzBsknooo7/IiA2qaityq6Ck kr5OMdFZur2eX58hrQsSBTP+6PiuVBAJAxPFd0NqMJ3OASXvNSeMAHr7tiEk5+I2Z+cg HO/M0de0cUIw+msJrByCO89IyXiPqVmCzhbSYh6R6AbDsHeU/3g46du95iWM2Ne9PK8h pkjg== X-Gm-Message-State: AOJu0YzmbT//racdugTX9VFGS8uTWsR4eHoWP7yxGYBKLtGVAFPOqaq1 jfi0d1EM/OECI62E5/AbZUxCnkziYqMAKtmwQg== X-Received: from almasrymina.svl.corp.google.com ([2620:15c:2c4:200:5cbf:3534:fb34:758e]) (user=almasrymina job=sendgmr) by 2002:a25:83c1:0:b0:dbc:ff55:6067 with SMTP id v1-20020a2583c1000000b00dbcff556067mr1368244ybm.0.1702867248313; Sun, 17 Dec 2023 18:40:48 -0800 (PST) Date: Sun, 17 Dec 2023 18:40:16 -0800 In-Reply-To: <20231218024024.3516870-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: <20231218024024.3516870-1-almasrymina@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231218024024.3516870-10-almasrymina@google.com> Subject: [RFC PATCH net-next v5 09/14] net: support non paged skb frags From: Mina Almasry To: Mathieu Desnoyers , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , 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 , Jonathan Corbet , Richard Henderson , Ivan Kokshaysky , Matt Turner , Thomas Bogendoerfer , "James E.J. Bottomley" , Helge Deller , Jesper Dangaard Brouer , Ilias Apalodimas , Steven Rostedt , Masami Hiramatsu , Arnd Bergmann , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , David Ahern , Willem de Bruijn , Shuah Khan , Sumit Semwal , " =?utf-8?q?Christian_K=C3=B6nig?= " , Pavel Begunkov , David Wei , Jason Gunthorpe , Yunsheng Lin , Shailend Chand , Harshitha Ramamurthy , Shakeel Butt , Jeroen de Borst , Praveen Kaligineedi X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785586038441062487 X-GMAIL-MSGID: 1785586038441062487 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 --- Changes in v1: - Fix illegal_highdma() (Yunsheng). - Rework napi_pp_put_page() slightly to reduce code churn (Willem). (cherry picked from commit e11c8035ed635e22aab224a89c48d93b5e881278) also squashed assorted fixes --- include/linux/skbuff.h | 47 +++++++++++++++++++++++++++++++++++++----- net/core/dev.c | 3 ++- net/core/gro.c | 2 +- net/core/skbuff.c | 11 ++++++++++ net/ipv4/tcp.c | 3 +++ 5 files changed, 59 insertions(+), 7 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 1189d8d22da8..890fc2b94fc7 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3452,17 +3452,53 @@ static inline void skb_frag_off_copy(skb_frag_t *fragto, fragto->bv_offset = fragfrom->bv_offset; } +/* Returns 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->bv_page); +} + +/** + * skb_frag_net_iov - retrieve the net_iov referred to by fragment + * @frag: the fragment + * + * Returns 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->bv_page); +} + /** * skb_frag_page - retrieve the page referred to by a paged fragment * @frag: the paged fragment * - * Returns the &struct page associated with @frag. + * Returns 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->bv_page); } +/** + * skb_frag_netmem - retrieve the netmem referred to by a fragment + * @frag: the fragment + * + * Returns the &struct netmem associated with @frag. + */ +static inline struct netmem *skb_frag_netmem(const skb_frag_t *frag) +{ + return frag->bv_page; +} + /** * __skb_frag_ref - take an addition reference on a paged fragment. * @frag: the paged fragment @@ -3491,13 +3527,11 @@ bool napi_pp_put_page(struct netmem *netmem, bool napi_safe); static inline void napi_frag_unref(skb_frag_t *frag, bool recycle, bool napi_safe) { - struct page *page = skb_frag_page(frag); - #ifdef CONFIG_PAGE_POOL - if (recycle && napi_pp_put_page(page_to_netmem(page), napi_safe)) + if (recycle && napi_pp_put_page(skb_frag_netmem(frag), napi_safe)) return; #endif - put_page(page); + put_page(skb_frag_page(frag)); } /** @@ -3537,6 +3571,9 @@ static inline void skb_frag_unref(struct sk_buff *skb, int f) */ 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/net/core/dev.c b/net/core/dev.c index 20ba528ef426..ad616b3c8e35 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3709,8 +3709,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 0759277dc14e..42d7f6755f32 100644 --- a/net/core/gro.c +++ b/net/core/gro.c @@ -376,7 +376,7 @@ static inline void skb_gro_reset_offset(struct sk_buff *skb, u32 nhoff) NAPI_GRO_CB(skb)->frag0 = NULL; NAPI_GRO_CB(skb)->frag0_len = 0; - if (!skb_headlen(skb) && pinfo->nr_frags && + if (!skb_headlen(skb) && 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); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 96f85543f1dc..671775bad5f9 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -1239,6 +1239,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 -= frag->bv_len; + if (!len) + break; + continue; + } + skb_frag_foreach_page(frag, skb_frag_off(frag), skb_frag_size(frag), p, p_off, p_len, copied) { @@ -3004,6 +3012,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/tcp.c b/net/ipv4/tcp.c index 1d6b80145efb..82485af12cdc 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2157,6 +2157,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;