From patchwork Tue Oct 8 11:20:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13826285 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 CFCA3CEF152 for ; Tue, 8 Oct 2024 11:27:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 927E86B008C; Tue, 8 Oct 2024 07:27:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8FE656B0092; Tue, 8 Oct 2024 07:27:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7786E6B0093; Tue, 8 Oct 2024 07:27:13 -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 548626B008C for ; Tue, 8 Oct 2024 07:27:13 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id E6F621C539B for ; Tue, 8 Oct 2024 11:27:11 +0000 (UTC) X-FDA: 82650208746.21.F8FE9FA Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf04.hostedemail.com (Postfix) with ESMTP id 555CF40004 for ; Tue, 8 Oct 2024 11:27:09 +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=1728386696; 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=K7DaP8AjIvAeSiEghNo4IkYBUHyquAjZi+6Q36wegYo=; b=OBVftMjCJ/0h59M5d8wXH2zuSDzDqpDd4yT0wn3d6NF6m4UTO+fGafCeBMYIuSx3uBvc4/ 3PekorvAC8U6ifpfhX0pn3ZLwjlspQbDTKGef1g1s6jQ+ED6QO3YOGLWDsJ2F2duJEEcEq uX1TO0prYPkpK0IPMX6xqkuwC5NnT+U= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728386696; a=rsa-sha256; cv=none; b=DO7F/EEM0gvbftov3/F7yLIMhHkHuqpvf6J+InwgLhB966iH7wfFAqWZjnFm+AzaNGZWH6 1xipC2ct5oBJQAS3e3yku9AnNou/ewf5LnnxiDMeyK9OfIipfml6/Y6AsESL2x/kLNpykI yw3LZlWjtusil1z6hB4z47Pq5t9QREs= 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 Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4XNDFQ6x3Xzfd5N; Tue, 8 Oct 2024 19:24:42 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id 434271800DE; Tue, 8 Oct 2024 19:27:06 +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; Tue, 8 Oct 2024 19:27:05 +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 , Trond Myklebust , Anna Schumaker , Jeff Layton , Neil Brown , Olga Kornievskaia , Dai Ngo , Tom Talpey , Shuah Khan , , , , , , Subject: [PATCH net-next v20 04/14] mm: page_frag: avoid caller accessing 'page_frag_cache' directly Date: Tue, 8 Oct 2024 19:20:38 +0800 Message-ID: <20241008112049.2279307-5-linyunsheng@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20241008112049.2279307-1-linyunsheng@huawei.com> References: <20241008112049.2279307-1-linyunsheng@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.90.30.45] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggpemf200006.china.huawei.com (7.185.36.61) X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 555CF40004 X-Stat-Signature: 5m7ce6bsupjbdrrwkq7kizdta5hhkhek X-HE-Tag: 1728386829-633742 X-HE-Meta: U2FsdGVkX19NAyw9JFtiEjiKXqWLmXgpPIPpNlbS/hFIf2NH9mDUQaNiPT9mvg116Kpttz5Li+ApRTl2sQrydpXhSXaj0mBeiiLPql0wLcLkleCNJh2mNvt1mX7z75CBauZFDzw7Iz65V304EZpGkNMtg1Pe0E0h2V2jcK1vRN40cD8IL+Q1VMRYum3P4q+dSW1TJ/M/v1LWmUH9VJOHr2No84iOi2C/20Sso3SNDYYUNdQKWaEdUOmNvvqhQJTr9B08pKXQ/V70Yk/KCypn4uHA57KulHohRMpzZjwnxDc9lU/W2iatVWF96u61JWPcGO5IuA1VGAVVMpjal7UYtgks5lohW2iAqIyRCly5E5er99H6NkFAAoU1KNS6miCys5Z+yutuS3mCKME6x94q+6cEY3LTmFt6lcuzO2BKI1Ol8DW894QStB6Q2aQSnh3BOmAvWUW8PHIhNWeC0Z6Y/YGPtfqoeS8G3iz6ekvc2/PoaIVisB/FGxJZBDzpGM4gEQak4tlT7Pruvwa+K+R7uU4rKusGEek/46YrKnSl++9Fyrzvbn22M4XBh/Aq1bkES3RwrfuVOGegmt9OVRsubn5h78VNJkfpMi+WeOwy7vdBbtdyXs21afWYU46T+ERyvX8aiYp0NSoe2yrYR7Tobzzj/2fXMkSkotXbNtGyHBtOkXI6p1/8QGgQ7NIqU2rTzQc9HA8PtVqu6dE98g/SfIdGu/PZosxfPdKxNH8vA2Ft8U8MGDVm3W0SGGpeSAPLryCgC/a7E8jtkRvcuPT7IMgPRIPT/qtxi3GVhs8xrzFkwSZc1pwnwV3llQxI2EM0Ccsj0tc++7HxAXc9kL3FlpzBVLlAXiLgoevVUAlgyJ8zf38H8sz8MZWXwXwqxEeS2D2T0o5gQ5G94NMcWq+r1AAJIvHxQLB2o1rh/xizSRmffSnEOBn/h10Yj7GwYOUbR0Zk3SlKfcNqel1rbpK xQ+xXc4Y YMlW2DiwP2RZYEzR6qX9fEp0/OA0UbatXyFaPCbNZaUFaXmHE5PPYLcaJt2WrVwLWBwJEF2OPi2HS0lgVsEbdMSiB/53rZkLF3ySM0lFKV1UKmrMEuzSEd1iO6Ob/o/PJ5xNHiW7pcFmoyZl0gjOhWvMhwQ/2RoOswGXp5XZoKG9VCJBOwiJzhcKvaHlEh6yxO72ZaI7jZW4kBKjKwVySUnU+tjGgZiJ/oDvOOPUaBkEPRkiExMNVZ4cy/JyZfJ/+cWqxrAG/gbYACMElY4/pApu6TLfAA5dmbW663s5LfFUgvG8QqVmmdI4es+1bmL9xe53G+angVAr5I+7SoYJ67nEEBA== 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 74149dc4ee31..ca01880c7ad0 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 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 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 fdf204550c9a..36543a129e40 100644 --- a/tools/testing/selftests/mm/page_frag/page_frag_test.c +++ b/tools/testing/selftests/mm/page_frag/page_frag_test.c @@ -117,7 +117,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);