From nobody Thu Sep 19 23:14:50 2024 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 16FCD16729D; Tue, 25 Jun 2024 13:55:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.187 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719323739; cv=none; b=moIJwNOqg0Si7+8/N/i7HWh0oMvjeL6JpD5AnqcANymq0CzV3hxtVZ2Xj1YP4RF0qJ15yn4y0K3rC4qwuOX9DVFQc2/7xW7jgI47Exwyw6BvqwLl8ORM9QK4jwNU4CQdJGdBOCskahxzbuPyU/fGx6oLg1KSDooiZyOiUFdKe9s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1719323739; c=relaxed/simple; bh=qojYIiLlVBn1RSQjDWl+bE5Qe0/KRzEy5j3Uos3uMNk=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YDC69eDwzMmcPdrMCnusaheFPneIkaQED03iSGiGN/UfrgUbwL9bSl1+/fl6qqdKxacnAPV9CXWh2ZrqFDGelNSPv54x6D2sw0YT+MIMPy+NC8ghsmqs8F9x2drV+z9Z49yumDtqLEX2t3RO3gon06EcTPk23kdORMxwD7eo2dI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.187 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=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=20P=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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemf200006.china.huawei.com (7.185.36.61) Content-Type: text/plain; charset="utf-8" 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]); =20 f->private_data =3D n; - n->pf_cache.va =3D NULL; + page_frag_cache_init(&n->pf_cache); =20 return 0; } diff --git a/include/linux/page_frag_cache.h b/include/linux/page_frag_cach= e.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; }; =20 +static inline void page_frag_cache_init(struct page_frag_cache *nc) +{ + nc->va =3D NULL; +} + +static inline bool page_frag_cache_is_pfmemalloc(struct page_frag_cache *n= c) +{ + 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; =20 - test_frag.va =3D NULL; + page_frag_cache_init(&test_frag); atomic_set(&nthreads, 2); init_completion(&wait); =20 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 =3D this_cpu_ptr(&netdev_alloc_cache); data =3D page_frag_alloc_va(nc, len, gfp_mask); - pfmemalloc =3D nc->pfmemalloc; + pfmemalloc =3D page_frag_cache_is_pfmemalloc(nc); } else { local_bh_disable(); local_lock_nested_bh(&napi_alloc_cache.bh_lock); =20 nc =3D this_cpu_ptr(&napi_alloc_cache.page); data =3D page_frag_alloc_va(nc, len, gfp_mask); - pfmemalloc =3D nc->pfmemalloc; + pfmemalloc =3D page_frag_cache_is_pfmemalloc(nc); =20 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 =3D SKB_HEAD_ALIGN(len); =20 data =3D page_frag_alloc_va(&nc->page, len, gfp_mask); - pfmemalloc =3D nc->page.pfmemalloc; + pfmemalloc =3D page_frag_cache_is_pfmemalloc(&nc->page); } local_unlock_nested_bh(&napi_alloc_cache.bh_lock); =20 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_struc= t *work) */ rxrpc_purge_queue(&conn->rx_queue); =20 - 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); } =20 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); } =20 /* 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 =3D container_of(xprt, struct svc_sock, sk_xprt); - struct page_frag_cache *pfc =3D &svsk->sk_frag_cache; struct socket *sock =3D svsk->sk_sock; =20 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); } --=20 2.33.0