From patchwork Thu Dec 14 02:05:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mina Almasry X-Patchwork-Id: 178410 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp8267639dys; Wed, 13 Dec 2023 18:06:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEfOekZBr4Ix7cTcuN6lcPzaFG84V8iZQiuEVE08e14yhaItyRAX3W6xxHGghWyNw0qwm9w X-Received: by 2002:a17:903:26ce:b0:1cf:d2c3:2865 with SMTP id jg14-20020a17090326ce00b001cfd2c32865mr7950080plb.40.1702519585017; Wed, 13 Dec 2023 18:06:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702519585; cv=none; d=google.com; s=arc-20160816; b=cYvsFqK4gnwi0drIEiqrIiBN3nPC+HnyMhC1UKewV90MDFRKS70jGe4fHulTmLjfo1 EJFDE9DfeJ8pFtpqElolWdlAqEJpI2grQYPHhsnpkIAUVycwCxOayqUWQmQS/HSvbV9Y dGEj0uZan6JLFIBmlkqUj8TfPtYf4OcaLes40tPf+9P5xmkKAjQ9tJ6DbAenQ4gPYpKI Ldl+pV5zmNxEi9ToFtZ5d4zYW8jy4HVINgnw6yT8gehAbafPRDcX4wgxP1fL6RfR4SQF D5ysbgBMBjrTT81LI+TerZ3BSc2p5KJ8HJlELb1gLrk4mV7N62pWdtcDW+B/Cj9UKQW2 0B1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=dUMRyPJzc2KBqp9rlzOcicivZPWQYvb+p95UviyM3iw=; fh=2cTpkOQdVNm4Kv9XaiKb49A4tmrQwCTD9dCd1XGCiM8=; b=Cw718sUt4zVBXtCStzwIDU6jplg5iHGpgiaATMG2Q+RGgBUJHbyS+sdxNrZ51EqZVK rnlZUx4iJvdIbH2SguZXKg9x07OC6K8ZxDWWCxvf8RCbgih0fM95CRH5SZ4sP9hwWQdT BfGqhkJPO51MOiUs4HGrpoH9W5xaXtxVx1cPS+EF7HSxN9vDtiop4gSWl7eev49wir51 LHOUPSUs1PVJZd2fkA6RIO6JvG7NqR/253gPoxL6hXR03RfydT78IlDzNSBXfyjc9vZn lhuxBpn6ahHnfq6Pzi9ZOn71GIg0gYzRUeWDPvS2h7q8W2HSNgrJHpgSBpb/AQixX9ZD v/0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=fUN8P8ea; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id q18-20020a17090311d200b001d06d410ea0si6468859plh.448.2023.12.13.18.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 18:06:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=fUN8P8ea; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 8F46280C0575; Wed, 13 Dec 2023 18:06:00 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1443024AbjLNCFu (ORCPT + 99 others); Wed, 13 Dec 2023 21:05:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235271AbjLNCFg (ORCPT ); Wed, 13 Dec 2023 21:05:36 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 903AC107 for ; Wed, 13 Dec 2023 18:05:42 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-dbcc62c68fdso2156905276.2 for ; Wed, 13 Dec 2023 18:05:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1702519542; x=1703124342; 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=dUMRyPJzc2KBqp9rlzOcicivZPWQYvb+p95UviyM3iw=; b=fUN8P8eaFBYXz025ievhny71hWvob2+/oQllg6fLGdRdwjGqADeA7CYptTERsYLqsm DVspJIT/TkLY6wLUrC0k7gAf6DmLaERZ0lEfkVUuny03YesDuBch898IVJ3070T/0tWX ppAJnbY+q+wxKDZJTWWhVIQzWFmiu7dtq0sjeocWivEuoRHZwH2W2CtSMMcSVELXQ+rH 61GZxyTXzTCY5Fh90R/yb9ylV8Q/GOJmspmXlXNSUNxrE0bg/nvmONpKDfoMesic+Tnf DvUnTE6C0t1hx/nbOJcLR+m1t8iulLxmgE4fc0rRMYk19R3N7sLb4bDBBAJATNOy5qKm yAdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702519542; x=1703124342; 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=dUMRyPJzc2KBqp9rlzOcicivZPWQYvb+p95UviyM3iw=; b=ORboojoMtj8elXL/Qlt+H8el5LSX059m3S2RT+WE9zWn/By7sAdjymNgP1o5PpZSJ3 gth7hQTyeoHPktvu7FtmMLZR7uIQ18AtDutTw9jNZCZXloH0MWskYTiubjjNN3RGNC2m BMo1SRKKHuE7L0+3XrvUFVsWa3HDqF9OKpicAPWsajP2l7PRHRQO1h73U7t30TcV2M7L 5BtURbzioAN8RkAZLqfzb35xe3xXoTts+u3RP0cfYexLb4pngPJVCfcBrFiQBLhXnbhI NlI3/ZqJDnW0UuvrJf1O2b5t6rAQwPzzE7cFkGGwP2MYdhpFUKHfv5Crwx+PmmlX/Cyu h24w== X-Gm-Message-State: AOJu0YwS+pZuHb9y0YSpCJLyCOVkwI7lZ9wQcfo4HHZ+8vTbVRkwlSQU Z94BdYfU2EOe3avQs2hfrBTYLTN7N9fzN2bRrP83ev8V6JgpJc5nY9qHOgMiL+REVRyb9jJurZZ pJVhZxwtAizJB0680NQQr2osxpxUtWogNvVrHfwAitFYNpi9SjFjoYix9YBFuQE93cN1G9+C0NJ wf18elB0E= X-Received: from almasrymina.svl.corp.google.com ([2620:15c:2c4:200:d31b:c1a:fb6a:2488]) (user=almasrymina job=sendgmr) by 2002:a25:c0d4:0:b0:dbc:b692:65a7 with SMTP id c203-20020a25c0d4000000b00dbcb69265a7mr49497ybf.10.1702519540921; Wed, 13 Dec 2023 18:05:40 -0800 (PST) Date: Wed, 13 Dec 2023 18:05:26 -0800 In-Reply-To: <20231214020530.2267499-1-almasrymina@google.com> Mime-Version: 1.0 References: <20231214020530.2267499-1-almasrymina@google.com> X-Mailer: git-send-email 2.43.0.472.g3155946c3a-goog Message-ID: <20231214020530.2267499-4-almasrymina@google.com> Subject: [RFC PATCH net-next v1 3/4] net: add netmem_t to skb_frag_t From: Mina Almasry To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org, bpf@vger.kernel.org Cc: Mina Almasry , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Greg Kroah-Hartman , "Rafael J. Wysocki" , Sumit Semwal , " =?utf-8?q?Christian_K=C3=B6nig?= " , Michael Chan , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Wei Fang , Shenwei Wang , Clark Wang , NXP Linux Team , Jeroen de Borst , Praveen Kaligineedi , Shailend Chand , Yisen Zhuang , Salil Mehta , Jesse Brandeburg , Tony Nguyen , Thomas Petazzoni , Marcin Wojtas , Russell King , Sunil Goutham , Geetha sowjanya , Subbaraya Sundeep , hariprasad , Felix Fietkau , John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , Matthias Brugger , AngeloGioacchino Del Regno , Saeed Mahameed , Leon Romanovsky , Horatiu Vultur , UNGLinuxDriver@microchip.com, "K. Y. Srinivasan" , Haiyang Zhang , Wei Liu , Dexuan Cui , Jassi Brar , Ilias Apalodimas , Alexandre Torgue , Jose Abreu , Maxime Coquelin , Siddharth Vadapalli , Ravi Gunasekaran , Roger Quadros , Jiawen Wu , Mengyuan Lou , Ronak Doshi , VMware PV-Drivers Reviewers , Ryder Lee , Shayne Chen , Kalle Valo , Juergen Gross , Stefano Stabellini , Oleksandr Tyshchenko , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Stefan Hajnoczi , Stefano Garzarella , Shuah Khan , " =?utf-8?q?Micka=C3=ABl_Sala=C3=BCn?= " , Nathan Chancellor , Nick Desaulniers , Bill Wendling , Justin Stitt , Jason Gunthorpe , Shakeel Butt , Yunsheng Lin , Willem de Bruijn X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 13 Dec 2023 18:06:00 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785221176647773595 X-GMAIL-MSGID: 1785221176647773595 Use netmem_t instead of page directly in skb_frag_t. Currently netmem_t is always a struct page underneath, but the abstraction allows efforts to add support for skb frags not backed by pages. There is unfortunately 1 instance where the skb_frag_t is assumed to be a bio_vec in kcm. For this case, add a debug assert that the skb frag is indeed backed by a page, and do a cast. Signed-off-by: Mina Almasry --- include/linux/skbuff.h | 11 ++++++++--- net/kcm/kcmsock.c | 9 +++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index b370eb8d70f7..6d681c40213c 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -37,6 +37,7 @@ #endif #include #include +#include /** * DOC: skb checksums @@ -359,7 +360,11 @@ extern int sysctl_max_skb_frags; */ #define GSO_BY_FRAGS 0xFFFF -typedef struct bio_vec skb_frag_t; +typedef struct skb_frag { + struct netmem *bv_page; + unsigned int bv_len; + unsigned int bv_offset; +} skb_frag_t; /** * skb_frag_size() - Returns the size of a skb fragment @@ -2435,7 +2440,7 @@ static inline void skb_frag_fill_page_desc(skb_frag_t *frag, struct page *page, int off, int size) { - frag->bv_page = page; + frag->bv_page = page_to_netmem(page); frag->bv_offset = off; skb_frag_size_set(frag, size); } @@ -3422,7 +3427,7 @@ static inline void skb_frag_off_copy(skb_frag_t *fragto, */ static inline struct page *skb_frag_page(const skb_frag_t *frag) { - return frag->bv_page; + return netmem_to_page(frag->bv_page); } /** diff --git a/net/kcm/kcmsock.c b/net/kcm/kcmsock.c index 65d1f6755f98..926349eeeaf6 100644 --- a/net/kcm/kcmsock.c +++ b/net/kcm/kcmsock.c @@ -636,9 +636,14 @@ static int kcm_write_msgs(struct kcm_sock *kcm) for (i = 0; i < skb_shinfo(skb)->nr_frags; i++) msize += skb_shinfo(skb)->frags[i].bv_len; + /* The cast to struct bio_vec* here assumes the frags are + * struct page based. + */ + DEBUG_NET_WARN_ON_ONCE(!skb_frag_page(&skb_shinfo(skb)->frags[0])); + iov_iter_bvec(&msg.msg_iter, ITER_SOURCE, - skb_shinfo(skb)->frags, skb_shinfo(skb)->nr_frags, - msize); + (const struct bio_vec *)skb_shinfo(skb)->frags, + skb_shinfo(skb)->nr_frags, msize); iov_iter_advance(&msg.msg_iter, txm->frag_offset); do {