From patchwork Sat Oct 12 11:23:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13833395 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 EA585CF2566 for ; Sat, 12 Oct 2024 11:29:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C4A86B0088; Sat, 12 Oct 2024 07:29:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 625036B0089; Sat, 12 Oct 2024 07:29:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A09F6B008A; Sat, 12 Oct 2024 07:29:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 282106B0088 for ; Sat, 12 Oct 2024 07:29:48 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id DF7BD12165E for ; Sat, 12 Oct 2024 11:29:42 +0000 (UTC) X-FDA: 82664730330.08.290DB6E Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf04.hostedemail.com (Postfix) with ESMTP id 835AD40006 for ; Sat, 12 Oct 2024 11:29:40 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.188 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=1728732401; 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=3cLH1ffUbO2p6/7QpbTwciO6JuoslQhl1JD6NmimWEA=; b=XJdrx85CB3tSjLgrqJThxPN7vz2PM6roVmfuHUHy3qqnfS4781bQ+58Pq/Ry3SZYuZjqxe JZrB24Sru80oJqhbwQOfO1YKHiCb1+3lVIUPvx/5i2csP1lp5tBFBDTLPBtcaAEF3NSNhP 6rHoJK6HhMZUwn1zBDHm+hX6F1S3Wh8= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728732401; a=rsa-sha256; cv=none; b=3X1KAeQq6v4+wunVgYKASMY/f+noZ+0WygeQjNLnVz6hSiBi5TwYFYPsRtoKc+6AqrD0SZ 7CxUYGGThAHkwUq+oThD3x0e2Kn+8HJBbhO1nkbrlM1EuaGjpa57GzngZ6NK54Gspb4uS7 UxDlfAtHDfj0oemPEXG9AuA3q3zLE20= Received: from mail.maildlp.com (unknown [172.19.88.105]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4XQh732snczpWct; Sat, 12 Oct 2024 19:27:43 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id 91AF9140393; Sat, 12 Oct 2024 19:29:42 +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; Sat, 12 Oct 2024 19:29:42 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Alexander Duyck , Chuck Lever , "Michael S. Tsirkin" , Jason Wang , =?utf-8?q?Eugenio_P=C3=A9rez?= , Andrew Morton , Eric Dumazet , David Howells , Marc Dionne , Jeff Layton , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Trond Myklebust , Anna Schumaker , Shuah Khan , , , , , , Subject: [PATCH net-next v21 04/14] mm: page_frag: avoid caller accessing 'page_frag_cache' directly Date: Sat, 12 Oct 2024 19:23:10 +0800 Message-ID: <20241012112320.2503906-5-linyunsheng@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241012112320.2503906-1-linyunsheng@huawei.com> References: <20241012112320.2503906-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.30.45] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemf200006.china.huawei.com (7.185.36.61) X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 835AD40006 X-Stat-Signature: 5a8o5iwcgtcxbo3re33a95r5jmwdifea X-Rspam-User: X-HE-Tag: 1728732580-606491 X-HE-Meta: U2FsdGVkX1925ZpByF/QdlbaTpPGtAv8qH/1CgRDrN1804Xd0Mal/Mcjr74+0b+NmQcnvTRlF7qZS8b51e3poAbmpZs8+Q6icI8RyUPR3RduENQa63dHpq6MXJG5RzmgW7U1ZLlzYpwRyuMes4qV6FjXCpxgKKsQajMRcS3YOno7+j8sxx5UHatMFHxnqITpcBB6gHUuNO2elQbp2l19KYYnd4yXlCjxuyM/lfUoce+o4tWkoLDbgZZybO+sCCaClF6cPAJ5Zw1V2FQhXs0NkxnFAqTtpvrZ7m/82Oxk356dxrjP8eq3z2EL6OhvjSs3nAXvovjtgcmAcQ67XMXPtTafnRQWR1yHDdpPNAdu5oqZb/f6utc9eZc7gbr4Q3yQ/UmtQ1RDjPS2CrRmXuA23Vw/u9I5qiVS8O1c3o4bYlqnxMLtkbZCki14qKQQQcre62so+C94cmkLUW2RxsYkl/Go5cD/1bG3UCLVan9V5gZLAFWzwL149iMWEZBnNSrckLQaqmt7ixcspiJRYn/MEQdVzucoraWYvgqossb54Q8xLegz9NtQ6NMYpOYWod1gJ35HBoMhWdVvVtHti3ROOE6QC+HKgIb4TsGfRJDUsABz8XY/4LtfbC9b5pKXa8EhIsfJwxepqU5t33pmFYnDdQScRjTVn6yRvOJYRTBd3gzW/sJlaC6U6DEAoxLZpB34myX/ntPcNVIhz/W6I3T+aMCtuN0C7JPQ/n7KsoR7aobcxlaHzixL5dK4K7lAOeK1aDYXi8JxFPilKC9Jj/qd+yCCv4oFigHYTiBa1b9SvThXJLxCy7zLfj/33bIhW3ykxgE9nuEfq+GbkJ3X8UW2dy/rOwP331FXTOWHGyvp3XMOOzTIVEiBAw2hO+JmY80HB3siS1SlF/VGXkRDlcmGYnj7i9slTt2BM0zG2VzIeaM7hBfPScLYidY4cJpwMfxBmiZg0OMgZS7NxoiywGS 78gtclJr Y49nC63Jxn9nkrjLe0VPZezsouosRTXPC5gPf0+PpszoAcwrALUv3g0VMWm7eEKpbf2Cz51LOZjrEzlGJFab1ou8lLAut6lMk9rLwVwZ2WK0gIOPnrYAU4ghZti2cD2kGfZbZwkTZedQsMRKF8mNbopEmKNJNe0ARXBBEcwYGHkGpyf35sBhORHSzAX3v/3F27FkrYKzP0saP/zjPKxqIfQs0zd4pxWx/ZGTtttVZ/HsrDAwuTV871sCsJ6p0zP0E0o+h/dCj0y8vL8YhhvHB/b7SUhHw193w8Om/zhshNazYkU7pD21QBEXlu7ay0P16zEUCvrAbHd6gex57kZ0Pwti27Q== 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 ++++++++++ net/core/skbuff.c | 6 +++--- net/rxrpc/conn_object.c | 4 +--- net/rxrpc/local_object.c | 4 +--- net/sunrpc/svcsock.c | 6 ++---- tools/testing/selftests/mm/page_frag/page_frag_test.c | 2 +- 7 files changed, 19 insertions(+), 15 deletions(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index f16279351db5..9ad37c012189 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 67ac8626ed9b..0a52f7a179c8 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_align(struct page_frag_cache *nc, unsigned int fragsz, diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 00afeb90c23a..6841e61a6bd0 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -753,14 +753,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(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(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(); @@ -850,7 +850,7 @@ struct sk_buff *napi_alloc_skb(struct napi_struct *napi, unsigned int len) len = SKB_HEAD_ALIGN(len); data = page_frag_alloc(&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 f9623ace2201..2792d2304605 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 825ec5357691..b785425c3315 100644 --- a/net/sunrpc/svcsock.c +++ b/net/sunrpc/svcsock.c @@ -1608,7 +1608,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); @@ -1618,8 +1617,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); } diff --git a/tools/testing/selftests/mm/page_frag/page_frag_test.c b/tools/testing/selftests/mm/page_frag/page_frag_test.c index 13c44133e009..e806c1866e36 100644 --- a/tools/testing/selftests/mm/page_frag/page_frag_test.c +++ b/tools/testing/selftests/mm/page_frag/page_frag_test.c @@ -126,7 +126,7 @@ static int __init page_frag_test_init(void) u64 duration; int ret; - test_nc.va = NULL; + page_frag_cache_init(&test_nc); atomic_set(&nthreads, 2); init_completion(&wait);