From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D300C4332F for ; Tue, 7 Nov 2023 09:00:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233616AbjKGJAr (ORCPT ); Tue, 7 Nov 2023 04:00:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229541AbjKGJAo (ORCPT ); Tue, 7 Nov 2023 04:00:44 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 928DD101; Tue, 7 Nov 2023 01:00:41 -0800 (PST) Received: from dggpemm500005.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SPhtd20XRzrTwF; Tue, 7 Nov 2023 16:57:29 +0800 (CST) Received: from [10.69.30.204] (10.69.30.204) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Tue, 7 Nov 2023 17:00:07 +0800 Subject: Re: [RFC PATCH v3 08/12] net: support non paged skb frags To: Mina Almasry , , , , , , , CC: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Jesper Dangaard Brouer , Ilias Apalodimas , Arnd Bergmann , David Ahern , Willem de Bruijn , Shuah Khan , Sumit Semwal , =?UTF-8?Q?Christian_K=c3=b6nig?= , Shakeel Butt , Jeroen de Borst , Praveen Kaligineedi References: <20231106024413.2801438-1-almasrymina@google.com> <20231106024413.2801438-9-almasrymina@google.com> From: Yunsheng Lin Message-ID: <7e851882-9a85-3672-c3d5-73b47599873c@huawei.com> Date: Tue, 7 Nov 2023 17:00:06 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: <20231106024413.2801438-9-almasrymina@google.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.69.30.204] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2023/11/6 10:44, Mina Almasry wrote: > Make skb_frag_page() fail in the case where the frag is not backed > by a page, and fix its relevent callers to handle this case. > > Correctly handle skb_frag refcounting in the page_pool_iovs case. > > Signed-off-by: Mina Almasry > ... > /** > * 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) > { > - return frag->bv_page; > + if (!page_is_page_pool_iov(frag->bv_page)) > + return frag->bv_page; > + > + return NULL; It seems most of callers don't expect NULL returning for skb_frag_page(), and this patch only changes a few relevant callers to handle the NULL case. It may make more sense to add a new helper to do the above checking, and add a warning in skb_frag_page() to catch any missing NULL checking for skb_frag_page() caller, something like below? static inline struct page *skb_frag_page(const skb_frag_t *frag) { - return frag->bv_page; + struct page *page = frag->bv_page; + + BUG_ON(page_is_page_pool_iov(page)); + + return page; +} + +static inline struct page *skb_frag_readable_page(const skb_frag_t *frag) +{ + struct page *page = frag->bv_page; + + if (!page_is_page_pool_iov(page)) + return page; + + return NULL; }