Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp127861lqs; Mon, 4 Mar 2024 18:12:26 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUNGYfkNfzHu0SHMcGhGJj8KGFVKySQJN9er5qTb5P74jjFQf+p59DZn+X4Rna2hf9XnWJ4781o0K1iqukCX8M1zkLMmY96h7KHa7CReA== X-Google-Smtp-Source: AGHT+IE7fL72/xrZTHL7sl7X08U+N06WsER/dmzEEQVrRmFU/sKpsoR99Bw+79jfRH93Cay6KYAn X-Received: by 2002:a17:90a:6308:b0:29a:eeef:1a4c with SMTP id e8-20020a17090a630800b0029aeeef1a4cmr8037659pjj.29.1709604745735; Mon, 04 Mar 2024 18:12:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709604745; cv=pass; d=google.com; s=arc-20160816; b=RtWb2HNfmFsaOpkWlBrhbukO4TwdZKFNCVNL43MnC8jPcDzbisjQ9hRPaV2uQVBGuT iJ8P3QjBOoToaptPtLMOiLatH27WJB8vWfI+v7VcRIiPNgJS/yqEh/D6cdPqUDQXtGBf wnLqElJNro9nVznwkbRIqYnu56hFuSeLCjz14bdUlHf5UiRbA6zXZnXLboatVEMeXrAb LYXNWm9AXBfzTTfxSYsuWAaU09oUKAwwgDoxBtYjUqMcyYzibXDrv+AiSPhjGzkznFoI UClWBPs7DWXVDnEWcDwshJXtN6H7Q3Z6QxgduIOQCxH5VfGYlkp2WK71bUubJZ91InhD D54A== 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=kFOLH8z6Kc1/DHNjJCRtctXlk4wkt0G4E5LxaUbD2lM=; fh=4Z2C5wFP2bHujGOJlpYN8y/en/kfdsVFNRyU9T4C7nk=; b=y0ATtSHgG0XvJNEEKzitPHnEeZTdIPxikHxjHMOS50apdGwkfH0Xo2TiYpVM7wAUW5 fnLp3ShXPcKYAMR+AT8xQkZvFo0SIVhtgsrWxAb/6bSBE8WFK83V8g9FxCYm08tMZCm5 GVTT61eOank1Ki7hRsB5x3Q/8TXb8o8KbiJOqAialMqpxsyyT1tDuoypeX14OAfcD+KA yAU6oUVd60mlJ5QnbR6e+1xffLlVQ0m8F9I1P7OuEdUm7boQwYL5zcpfnoA6gdzJF7Ha yLZLi2Dn0tnO3XKuASCIJKPkID92kR1DcteTNvbyfYzgEeRS5j/TiX7G7DzGbHALPi+l D1CQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=WLoWZiZp; 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-91531-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91531-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id qi17-20020a17090b275100b0029b43ef634bsi3571993pjb.9.2024.03.04.18.12.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 18:12:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-91531-linux.lists.archive=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=WLoWZiZp; 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-91531-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91531-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id DBF1E288B88 for ; Tue, 5 Mar 2024 02:07:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A469280616; Tue, 5 Mar 2024 02:02:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WLoWZiZp" 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 F1B0D17C95 for ; Tue, 5 Mar 2024 02:02:20 +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=1709604144; cv=none; b=feg7svNykUFz+7+SXu6/oKZd9a3hIefIPzuIdY6mBsiKfJeVlJ9H74ZTyXXf1m3u6l97JW9YhTwyJCRM5eCfnjy3VqiCNIIUnHyyX5qboADcjlyyVVvzOhMrX/3H2W3PoaS4uN7X1qKVEWoszLC2imt0wpU8r9gCHryM/oIv5H8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709604144; c=relaxed/simple; bh=ZkKDRjbXOJaCgdsUUhVdqCPuQ0SfWJoIIrbbmmGQ/FE=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=H+7zQBWCG4JvzEcgMqd3ez/ML3AEhSolErD9TQOe4x9Deu+dRm28Tri7Fh0/z0cuxpTWKl9DuP0nX3uKrtiHjEMOI/OhXsFmZrHFw3OlE5d8oUGIpsMVHVODoHvw3JsSzmabecandHF5/Agr8pJZZoL2wIr43mHkdR8q8sukvsw= 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=WLoWZiZp; 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-dd0ae66422fso225729276.0 for ; Mon, 04 Mar 2024 18:02:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1709604139; x=1710208939; 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=kFOLH8z6Kc1/DHNjJCRtctXlk4wkt0G4E5LxaUbD2lM=; b=WLoWZiZpUGPt4dSD7lzG4aIwzfZFDrSu2b9dCRJI0s0vPx1F/4kssBhpB/fm7J5vM4 YGrzYu5FikmZpB/QM6HH8/roiaA3J/zaE9kbJwyib2Esv/gG7G2EtE0pvOSIMvYeuDZn cE1g0GZkmVTpkpY4ktpZPtuiBap6M6ChGB/G6zxyhq70o1sNFr7v8o/Xl7J2tkFosklJ rKP2Nx/+5+Wnc9JCAiPP09YRZa8EqY1HSxlr8Zjs9ut3WndncFAvAlNd38BuRBcZLcS7 KQ0OXjzG1WV6nuXHeVo62EjW9ffcoue8rRspAYYPDJJyqltH3qGHhZwD7pRWVqn4GHfm bP7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709604139; x=1710208939; 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=kFOLH8z6Kc1/DHNjJCRtctXlk4wkt0G4E5LxaUbD2lM=; b=ZZZCObzXs+LxIaZFID47Whxw25p444v2CP6kOJok3I8WKqwBHQPijuB+uXuSVuwZmc BcWSr7sNlc5OAgON15TZRC5b6fyb33jvlAYVJJ4qLIjECmnLFVTlRsDiRon0GLyefB5w 2b1dPFxPcQf15w3A1Eh7YevGZOCL8eWbwy+tLgFchbjUMlOkMJaR3o/dfr6uOdIfMEi2 2zOhB821PVlKTP0FqLsQzJZCUjn0HhU/LiBE0x01kyJD8otR1b4TuMe35vOK0u4ptvim m3PySLAQ4Yd4PVf0FYGofr2IOZfVS7pB+5jUHcKd0wUfcCkhMrqTlV+Y75mPKm1F1esi lSHQ== X-Forwarded-Encrypted: i=1; AJvYcCXpu8hpM0Rr2GtGepv5ed6HFqRh+6JQFHRIaU4PPiSVFR3rEHNVZv2RoC3JDA4IB2v+DcWPLeOm893Bl83tjcdi58bBfSZFhMgMO81n X-Gm-Message-State: AOJu0YyjGmjdXgvOkfrAGLkCLoQjkutpf4vkMOoZ5OL7vFDtS2IdsOi/ 4SUA4xITRD5WZVn2jV6GTEP1qB4bMF15NZuzPyqCyA5u5jaHw9CpTs3N7JYGl9e8TSNutx3kZoF z0r2CvYeR160fxcFhPg8OzA== X-Received: from almasrymina.svl.corp.google.com ([2620:15c:2c4:200:b614:914c:63cd:3830]) (user=almasrymina job=sendgmr) by 2002:a05:6902:1504:b0:dbd:b4e8:1565 with SMTP id q4-20020a056902150400b00dbdb4e81565mr342247ybu.4.1709604139120; Mon, 04 Mar 2024 18:02:19 -0800 (PST) Date: Mon, 4 Mar 2024 18:01:45 -0800 In-Reply-To: <20240305020153.2787423-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: <20240305020153.2787423-1-almasrymina@google.com> X-Mailer: git-send-email 2.44.0.rc1.240.g4c46232300-goog Message-ID: <20240305020153.2787423-11-almasrymina@google.com> Subject: [RFC PATCH net-next v6 10/15] 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 , 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 , 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 --- 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 | 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 ca29d1fd4561..d68d430dc596 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3466,17 +3466,53 @@ static inline void skb_frag_off_copy(skb_frag_t *fragto, fragto->offset = fragfrom->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->netmem); +} + +/** + * 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->netmem); +} + /** * 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->netmem); } +/** + * skb_frag_netmem - retrieve the netmem referred to by a fragment + * @frag: the fragment + * + * Returns the &netmem_ref associated with @frag. + */ +static inline netmem_ref skb_frag_netmem(const skb_frag_t *frag) +{ + return frag->netmem; +} + /** * __skb_frag_ref - take an addition reference on a paged fragment. * @frag: the paged fragment @@ -3509,13 +3545,11 @@ bool napi_pp_put_page(netmem_ref 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)); } /** @@ -3555,6 +3589,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 bbea1b252529..765f4a995693 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -3385,8 +3385,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 cf23392e97f5..907fff2894d3 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -1378,6 +1378,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) { @@ -3145,6 +3153,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 c82dc42f57c6..51a5d263e8b4 100644 --- a/net/ipv4/tcp.c +++ b/net/ipv4/tcp.c @@ -2166,6 +2166,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; -- 2.44.0.rc1.240.g4c46232300-goog