From patchwork Fri Sep 6 07:36:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yunsheng Lin X-Patchwork-Id: 13793530 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 14795CE7AE6 for ; Fri, 6 Sep 2024 07:42:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43BF36B008A; Fri, 6 Sep 2024 03:42:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C7EF6B008C; Fri, 6 Sep 2024 03:42:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1F0436B0092; Fri, 6 Sep 2024 03:42:55 -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 F06B16B008A for ; Fri, 6 Sep 2024 03:42:54 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A91781C562C for ; Fri, 6 Sep 2024 07:42:54 +0000 (UTC) X-FDA: 82533521868.28.F26F246 Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by imf18.hostedemail.com (Postfix) with ESMTP id 0C5F61C001C for ; Fri, 6 Sep 2024 07:42:51 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.191 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=1725608547; 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=GtonIyiO4poQSNhyMpkdJV5gDy9SV0Nh687A6ckntA4=; b=joQNGuDe3L/Tr3981rH0eI27X7waEqhgl+Ei2exNwsKRn3YgUNPagkVcHsMqU6Fj4aIJym Y6snqdXmC60b0h7L01O1v9dPD4TshvlvyyZi1R8KtBXQ5KNqsRWVkUP1juJxbMJEYpgx2x uHbSPkDJfuQD0FzqsfWMnJyk+xU9Sro= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; spf=pass (imf18.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.191 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=1725608547; a=rsa-sha256; cv=none; b=bIMVr3sjLCovjINdwacfWpllCAK6N4482k9puD3CsgGxQIS4ytab4Wigku92Pfo8vGAcPb Tv/bR/dU4u13iDDcIhx992lIPg6Z7paRR/up7NMqkcHqtq9cC2y15Fz3/duhmoOCTTLHAc rYk22Q9akY/r89BDn6p//ZExTdTTFnU= Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4X0Sqj3ntrz1j8Dx; Fri, 6 Sep 2024 15:42:25 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id 19E2B1402CD; Fri, 6 Sep 2024 15:42:48 +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; Fri, 6 Sep 2024 15:42:47 +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 v18 04/14] mm: page_frag: avoid caller accessing 'page_frag_cache' directly Date: Fri, 6 Sep 2024 15:36:36 +0800 Message-ID: <20240906073646.2930809-5-linyunsheng@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20240906073646.2930809-1-linyunsheng@huawei.com> References: <20240906073646.2930809-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-Rspam-User: X-Stat-Signature: 5nd5efckfj97o4obhf7uwj9fn4gx3hpz X-Rspamd-Queue-Id: 0C5F61C001C X-Rspamd-Server: rspam11 X-HE-Tag: 1725608571-684507 X-HE-Meta: U2FsdGVkX1+WYpsrZbdB269yD7zr/QiCQTYgOIiE3jvG3vgH+CaKxxbmZh4N/FwRKHi7uGF5J3J9v1ZqZOlzqc2ZIxDUiQQKLBQQUE6mazXxJwxPfLp67Bs2TfFbSRnfEo28bYkW9X9zmmIr93sxgfY876g9LmkAbhzVgd4zsnM9ekOK8lNmbd78cJ6g6WadIzr6+PpyXBai5TiyD0PS/w3R0jHXNE3y8IUDYmYg6qANpTCvTyEpC4OYeWRI21CS/ildvuM3DuZD3TegnnjxBXRCUCP0dokfJDwXwMAecqotDxfzwboxTPYwAeU2CtW+l5/XPEuwboY3xonpgLwy7uv2iqZW5KpFQWX0vlo3oCMgjFsT69zUJyxL3UZWlT23BwGOpBRJ2+4jyLqhEwfSiKtsL2Eq8skpaA/dr9VSHThOMcanQsw4h094xSF00WU/Q4c0uhxnnKZhr3hksUf30SIjCIYg4wXAQ/sPdJoKPZ/Vk4AsDpjdlM1lci/A4mwxFqIfiY60/cTReL9P0vuIqOyX2m49GV37KYfHccuWdCd3CpWDHouZ3zQ9RpaD4bygEysO5M+82du5hcYiw3kd3UgQZOfz2rzu85vuZoH1WUfsZ8Dmh36fxNB+iA0YpU2BVHooTQ1OZHPukuK7Ka/syp1/Up4ACk4VVkggatBMzfAmLBXZjeDOdGQBVpXweUAn3XvwcCP3eItaH+hqW068AEWu8s6dGoDhHcymPq2N8GxBAoic2i+SyH8I+SgGkXPKhFsRVQcUSgzYYjojSG8gQAalrWY/eAy8TY/9tZF6sUKhkVdXCESUHFdBWZbujdpdH6IT0BCSd/w7jQd54lufRr558QvQ6GPzJ5C7lQPhQ6D++6FbMdO3QuGyr0/nia9CCuifmuf5ktDlOxhx1vrzR2Ro0zlzCtcBa4m/WTVTqN0dA1UP8QF0dVEhlgVZlqBi+jdUVVbe4omBy+aLiq8 52v/qNTm GZ8joMnGVYEPuLpOpdPz01hZq6ZiujzICabeKPBHVjt31+78Adc0Fj+todTQ2D8LfVMklG3F7CJBNfnGTFELyTnscXxc4oGLxHZSZnQG4m/Fq0L8CTE7pC7pNEEP3n6GMH0NSl15TTf6GAyXJumz0gO1MbwgWOlkJBdU7hcE7ZdgwgMhctINGtg5S5kBPXYVjIxDnoNnbMs9TirUKM+X60PkSIoXvCKO6PxDr7mq21bkQTsW22pUD0ZePf2fnNJspEm+t6a1iRs6eo2MrOgvHh8c8ZLZQcFcZLnl/HeCateG3OQkzzl5Pt+KgFWXZkzrfuRygH8xBc+Nd/nM= 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 a52638363ea5..a5f8e4e0c649 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -752,14 +752,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(); @@ -849,7 +849,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 6b3f01beb294..dcfd84cf0694 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); } 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 5395a36e4030..a4bd543d6950 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);