From patchwork Wed Jul 31 12:44:55 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13748709 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B81BEC3DA64 for ; Wed, 31 Jul 2024 12:50:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0E18F6B008C; Wed, 31 Jul 2024 08:50:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 092B66B0092; Wed, 31 Jul 2024 08:50:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E9D836B0095; Wed, 31 Jul 2024 08:50:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id BAA406B008C for ; Wed, 31 Jul 2024 08:50:58 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 759C6A4A7D for ; Wed, 31 Jul 2024 12:50:58 +0000 (UTC) X-FDA: 82400032596.03.94E8987 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf22.hostedemail.com (Postfix) with ESMTP id 08D9FC002F for ; Wed, 31 Jul 2024 12:50:55 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722430200; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EwZMLHgRLQ31cvJjRMZoZytD3CYHXQqT+91ejIA7Ets=; b=iAh1xqiU0aQ+VA3+AMDHX1/NZIqoNQyLVShHvXIKUykjzb+xa5wAMN+WMFIVVRvqDvefS5 UkySe71HU7+aep++vmR6BpBkg1lwseAeSgUHclO91LyKYF12NySxZT+qaYQnvO/ktdZUoV kWkH4caRSp1zf9tvO9j/4Awcr710zaY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722430200; a=rsa-sha256; cv=none; b=7mKdLqC4fC3wDnrhsYu17rvlhMYW0G4zZ/arbainHH8KEWcw68AGh2TiCrJ/htucCfLCm5 LVg+w4XCBRY2tC0Tzn0B2mOzpbJh6JOJd+QKEfgtWUQmURfZlMGjr9YOBDWeMPc3wP5RCy FYXOGO/B6xZ7QeuYoXoigQcHtxr6iWc= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WYsQT3Z71zxVyf; Wed, 31 Jul 2024 20:50:41 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id 33032180AE3; Wed, 31 Jul 2024 20:50:53 +0800 (CST) Received: from localhost.localdomain (10.90.30.45) by dggpemf200006.china.huawei.com (7.185.36.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 31 Jul 2024 20:50:52 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Alexander Duyck , "Michael S. Tsirkin" , Jason Wang , =?utf-8?q?Eugenio_P=C3=A9rez?= , Andrew Morton , Eric Dumazet , David Howells , Marc Dionne , Trond Myklebust , Anna Schumaker , Chuck Lever , Jeff Layton , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , , , , , Subject: [PATCH net-next v12 05/14] mm: page_frag: avoid caller accessing 'page_frag_cache' directly Date: Wed, 31 Jul 2024 20:44:55 +0800 Message-ID: <20240731124505.2903877-6-linyunsheng@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240731124505.2903877-1-linyunsheng@huawei.com> References: <20240731124505.2903877-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.30.45] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemf200006.china.huawei.com (7.185.36.61) X-Stat-Signature: 6qpgr3xd5iznw6y3d6mza91kchjfbc1z X-Rspamd-Queue-Id: 08D9FC002F X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1722430255-741869 X-HE-Meta: U2FsdGVkX1/9/Upzd+O0gTSh1SGZvxbcBVxynAxgK+DVZdKQ18LOaRwXZQ92isWEimcgV8s6qXr/sMUZsen+LP39PjH8WGepkJV8N9CZUAQh68qqdRAHhSxIlYytPU3u8B9xhxbka/XRJTW7mjz78MMGl5g8TBX9Ob+PK1kjeMRjQFFo+kSm+FZQtPUFQwdZUZaBv1SfjmcqXSzdI34M02VS0XaAEvh/Ey9fZbzNso4QRNY2G0Ccm3ubBqTXrK8c/Q8f5ZQYr+Sg6Ic8TbbHqWt7LK25XYohkMDsP+EhXMd0rMWKSa4wWa173euDP71NJBOZaIUdGoqpVey0nTzgaqt18N12Gk1d9o6tx/RVKjTl8G0A+KrGiIRJZ29IsjdKnXXp7uHWesC6IN0At0nsFStBW5TQ9QOmAgTcvFSnV2qzMnGPFpy9nKbTl+DEKFZzYM1NJ+xIO2qWiZPLq5F2wMHzPrAJhyejATjapQNT2I1OTI/EnDmTKpGPQsgDULkPfMzzr/QnQNfzwsNqHiWWWaI0Gk3wz86pG/djTou2zYwU9ra2zHI1uKnQIqGKIzNLoY2/TGe/P38a4BHFSQOm9d40xAgKraHrpRTVwb81zk/u+BTAmLmaNf6f6OBReJCCy7Q5xlE7V5gJ9cBcsgI9h2GV4lmoQCFVC/VqGDdf54FnYs8I2lCgz3E2iEDn2VoVnhG9Z1a4fL4NC2rgp5aOfeYmbyZP4lQVqbp6osNoCx/Z5LTcyqDyd/fkUm+E0HNbnQxvO5TQMvL27/kfZIF41qiH4ampG1Y2+IVjVWtHqmmiQeDyQB9rZbihYHAdqR5q2zEvH3JMTH0djCBRIGPygqB3LUSgXK+uHGX8+l2d874yhyOof4iOquLIj99XIwOM8XuM1S9bJ0FZYHSfBgE7adeJhvF3E8wSzXebLfmsnnZ2nULK0GrNfVSTSoN6/JB+hP2lhT1bUUdQhArBaH4 moeEQFlz uqIgADEoiYXq3XG7aUZ0iq1MSrsj6WHaKZEIvKJ/vDqxa4JtHluT/l38TZlbZgXB6KDwfAOUzE4R80TT5OLYScmkmVp0CLmCEeEK4mZiq3bRg3YWczequLWPrBRv8hRF9b3EFRrRvGD/N6sDy1TFzr0wC2SkCLj1yprNRJ0IGQa4EyHloCLsx9uSjJOqyyW0JV2k8C8re/mUlJb2ynsDQpQhl/R/g5czz9/cDuLgp6J3YwiUr9WRNzIoy1Blq+ONvXgya8guCTCn7Xr2uyAbNGmuXaOtD9pck0MpeDSNwKyWQaEYqnJItxBFATfYFQ/sGQ4QpSsUrEOZfJobNqijfnNAkXuFrJNkrajzL X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Use appropriate frag_page API instead of caller accessing 'page_frag_cache' directly. CC: Alexander Duyck Signed-off-by: Yunsheng Lin Reviewed-by: Alexander Duyck Acked-by: Chuck Lever --- drivers/vhost/net.c | 2 +- include/linux/page_frag_cache.h | 10 ++++++++++ mm/page_frag_test.c | 2 +- net/core/skbuff.c | 6 +++--- net/rxrpc/conn_object.c | 4 +--- net/rxrpc/local_object.c | 4 +--- net/sunrpc/svcsock.c | 6 ++---- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 6691fac01e0d..b2737dc0dc50 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -1325,7 +1325,7 @@ static int vhost_net_open(struct inode *inode, struct file *f) vqs[VHOST_NET_VQ_RX]); f->private_data = n; - n->pf_cache.va = NULL; + page_frag_cache_init(&n->pf_cache); return 0; } diff --git a/include/linux/page_frag_cache.h b/include/linux/page_frag_cache.h index ef038a07925c..7c9125a9aed3 100644 --- a/include/linux/page_frag_cache.h +++ b/include/linux/page_frag_cache.h @@ -7,6 +7,16 @@ #include #include +static inline void page_frag_cache_init(struct page_frag_cache *nc) +{ + nc->va = NULL; +} + +static inline bool page_frag_cache_is_pfmemalloc(struct page_frag_cache *nc) +{ + return !!nc->pfmemalloc; +} + void page_frag_cache_drain(struct page_frag_cache *nc); void __page_frag_cache_drain(struct page *page, unsigned int count); void *__page_frag_alloc_va_align(struct page_frag_cache *nc, diff --git a/mm/page_frag_test.c b/mm/page_frag_test.c index 9eaa3ab74b29..6df8d8865afe 100644 --- a/mm/page_frag_test.c +++ b/mm/page_frag_test.c @@ -344,7 +344,7 @@ static int __init page_frag_test_init(void) u64 duration; int ret; - test_frag.va = NULL; + page_frag_cache_init(&test_frag); atomic_set(&nthreads, 2); init_completion(&wait); diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 4b8acd967793..76a473b1072d 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -749,14 +749,14 @@ struct sk_buff *__netdev_alloc_skb(struct net_device *dev, unsigned int len, if (in_hardirq() || irqs_disabled()) { nc = this_cpu_ptr(&netdev_alloc_cache); data = page_frag_alloc_va(nc, len, gfp_mask); - pfmemalloc = nc->pfmemalloc; + pfmemalloc = page_frag_cache_is_pfmemalloc(nc); } else { local_bh_disable(); local_lock_nested_bh(&napi_alloc_cache.bh_lock); nc = this_cpu_ptr(&napi_alloc_cache.page); data = page_frag_alloc_va(nc, len, gfp_mask); - pfmemalloc = nc->pfmemalloc; + pfmemalloc = page_frag_cache_is_pfmemalloc(nc); local_unlock_nested_bh(&napi_alloc_cache.bh_lock); local_bh_enable(); @@ -846,7 +846,7 @@ struct sk_buff *napi_alloc_skb(struct napi_struct *napi, unsigned int len) len = SKB_HEAD_ALIGN(len); data = page_frag_alloc_va(&nc->page, len, gfp_mask); - pfmemalloc = nc->page.pfmemalloc; + pfmemalloc = page_frag_cache_is_pfmemalloc(&nc->page); } local_unlock_nested_bh(&napi_alloc_cache.bh_lock); diff --git a/net/rxrpc/conn_object.c b/net/rxrpc/conn_object.c index 1539d315afe7..694c4df7a1a3 100644 --- a/net/rxrpc/conn_object.c +++ b/net/rxrpc/conn_object.c @@ -337,9 +337,7 @@ static void rxrpc_clean_up_connection(struct work_struct *work) */ rxrpc_purge_queue(&conn->rx_queue); - if (conn->tx_data_alloc.va) - __page_frag_cache_drain(virt_to_page(conn->tx_data_alloc.va), - conn->tx_data_alloc.pagecnt_bias); + page_frag_cache_drain(&conn->tx_data_alloc); call_rcu(&conn->rcu, rxrpc_rcu_free_connection); } diff --git a/net/rxrpc/local_object.c b/net/rxrpc/local_object.c index 504453c688d7..a8cffe47cf01 100644 --- a/net/rxrpc/local_object.c +++ b/net/rxrpc/local_object.c @@ -452,9 +452,7 @@ void rxrpc_destroy_local(struct rxrpc_local *local) #endif rxrpc_purge_queue(&local->rx_queue); rxrpc_purge_client_connections(local); - if (local->tx_alloc.va) - __page_frag_cache_drain(virt_to_page(local->tx_alloc.va), - local->tx_alloc.pagecnt_bias); + page_frag_cache_drain(&local->tx_alloc); } /* diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c index 42d20412c1c3..4b1e87187614 100644 --- a/net/sunrpc/svcsock.c +++ b/net/sunrpc/svcsock.c @@ -1609,7 +1609,6 @@ static void svc_tcp_sock_detach(struct svc_xprt *xprt) static void svc_sock_free(struct svc_xprt *xprt) { struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt); - struct page_frag_cache *pfc = &svsk->sk_frag_cache; struct socket *sock = svsk->sk_sock; trace_svcsock_free(svsk, sock); @@ -1619,8 +1618,7 @@ static void svc_sock_free(struct svc_xprt *xprt) sockfd_put(sock); else sock_release(sock); - if (pfc->va) - __page_frag_cache_drain(virt_to_head_page(pfc->va), - pfc->pagecnt_bias); + + page_frag_cache_drain(&svsk->sk_frag_cache); kfree(svsk); }