From patchwork Tue Jun 25 13:52:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13711194 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 07D46C2BBCA for ; Tue, 25 Jun 2024 13:55:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 921F86B02E6; Tue, 25 Jun 2024 09:55:42 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 882E16B02E7; Tue, 25 Jun 2024 09:55:42 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D6596B02E8; Tue, 25 Jun 2024 09:55:42 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4526F6B02E6 for ; Tue, 25 Jun 2024 09:55:42 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id E544CA19AD for ; Tue, 25 Jun 2024 13:55:41 +0000 (UTC) X-FDA: 82269558882.09.753D995 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf26.hostedemail.com (Postfix) with ESMTP id 6654614000C for ; Tue, 25 Jun 2024 13:55:38 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; spf=pass (imf26.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=1719323725; 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=rmCJOd77WilMvp7c5eSVWmMjPPfZqRmhqqK63cKayus=; b=E0sjZ+vRz3jf/4tVXfvSbhvHguJ+53yeH7vsS1gQu5DKA6zIydTIvuvP6sJ9F0xijEWMGV t1yBEa3DY5ie5JCTQvImMFbRtVOP2G9rPWGpa1kOTWAsJbMlvmvvdG6txH2sflCImaRZJ9 fC7+KOS9iaECXx8DvtKVpuGhoK2JeDc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1719323725; a=rsa-sha256; cv=none; b=QPSozrmrvRBO1O8zzDt+tJgxinLWIGYPMGkLFed4JA70SagYn1m7exXGMcPPKuce9QanjL Ijs9pSQrX5/QWE5uAA8KmHiqoJQC6AsxsK5iFeI0cVXAVqM93Wtawo/h4xsKzlX/yOzfdr JWchQW1KwqsQtbyzgWY5V4DLYaw0dqo= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; spf=pass (imf26.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.174]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4W7mSw4g6gzZg1h; Tue, 25 Jun 2024 21:51:12 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id BE8C614022E; Tue, 25 Jun 2024 21:55:35 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) 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; Tue, 25 Jun 2024 21:55:35 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , "Michael S. Tsirkin" , Jason Wang , =?utf-8?q?Eugenio_P=C3=A9rez?= , Andrew Morton , Eric Dumazet , David Howells , Marc Dionne , Chuck Lever , Jeff Layton , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , , , , , Subject: [PATCH net-next v9 05/13] mm: page_frag: avoid caller accessing 'page_frag_cache' directly Date: Tue, 25 Jun 2024 21:52:08 +0800 Message-ID: <20240625135216.47007-6-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240625135216.47007-1-linyunsheng@huawei.com> References: <20240625135216.47007-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.69.192.56] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemf200006.china.huawei.com (7.185.36.61) X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 6654614000C X-Stat-Signature: 8f7u5e3efu7c6bz78pp3cqdb4x89o86w X-HE-Tag: 1719323738-139060 X-HE-Meta: U2FsdGVkX18xlfetmA/ljBoS/VoN9hgefNtMuLtLy8drYVQ18eu6XytkkGVRsR1/hu9ba+CwRzIdPU9Awl+XncrXbmgfNPLZ41YIE/wfSzKc0r4xuOdRTqG1MWX8z2Q0IEDKg/9DYq31I9r6i28FMzwVzq3OOV1g20/JYQuiO8Qr19yIIUPchB5bH72qBPfF7G0vMZwFF5Bcl7GKKsrqyk3Nx/X3LL1lEYtgQ8hQOY9i59g+EDk3g0Fy+2GVuad9kFf76RtGyQk+VBmcCp6K0+l5/taqU2QDuM4nDYyAhQAHWZr2r8K0Bx03O9i4oLHPANYqZ65Vv7isxpERpwGIm/kHqZGmZ0ShAS5dTxcTfu+8wmMGhxBVDkQnTTpXNKZ5S9vqyZ6+gXW0ey+XgQP07oXqLtJMV24hY03aflVFQgn9KCsw8Hn+fPvj8JII/lO7CtgFTOemBWp+WP0ij9qL5bq84A/zU5838R8hg5Bau8mkdSUv4upFQCQUYZtnhalmWCipZJp8zwsSHJ/N1DUXShzAaZG5xREFAWnncjMpoyw5V+KRdPcwjgNInu3/jSahs6clMGHRQcH7tF/aM5/r0H7b3AuvXsz+kSUQ94qRzEG7dULt4RfRJQtWVxt5cfSA9nlUi05OizMRAlz+U+kx8WJpK+mQxcFFuQI5nZNSfH0zTG2HPoq8bPTbd5gcfCcX+fcyMq4XC923jsZvG107lIX9erJkNUa1hA23TsZ5+wILjeL2esAtvgM+XasF7xbeuGFNoRoVIY3K9Dc5bJP9VaXLJ1cPC+Bhd0La4uwrQhJ5GDIr5AHGel5eEOq29AAxT2SjM8Z98Zxf8KAqJA0eqJYnOyikCRyV6GNE1V6Lk9GfeVloEguCTOuQeilohfCsJXNlXXqQavh7dLo84hpmmVtaf6HPahPX+oqrmZ8VJfNtoGZux7rKitWMPeNgK/Br5MJUEb2glgXn/3JzLWD wJ2M5r/o u2gNsIMV482VHLkivS9v1HaYozATj0jo5Q4mamUntRyK59Mz3u75Nug2hG2HImzOWMt6unFLxY284QC8/f1RuCpciiGOsFaf9oOL/ZO/jKyRoTeMRCJpbUuOBcP0CM7A0rtv1B6zfg5PLmvN9YcuLRLciky6LExyV47uDTHkJW2iBWmyh4sn1MqSLYJUxLr4WINPl18/zeICZGvdDzi4sb3RtVLhoe9vrQxEC7WBxpZu7kcBNnVFGto6aUsfAEzvEtF3FeLl5Ojki5uo6rccWrKdivaIjAO5tOlC2 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 --- 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 c6fde197a6eb..6ac3a25089d1 100644 --- a/include/linux/page_frag_cache.h +++ b/include/linux/page_frag_cache.h @@ -23,6 +23,16 @@ struct page_frag_cache { bool pfmemalloc; }; +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 a0bd0ca5f343..cdffebc20a10 100644 --- a/mm/page_frag_test.c +++ b/mm/page_frag_test.c @@ -341,7 +341,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 6a84cc929505..59d42d642067 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); }