Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mm: page_frag: avoid caller accessing 'page_frag_cache' directly

Use appropriate frag_page API instead of caller accessing
'page_frag_cache' directly.

CC: Andrew Morton <akpm@linux-foundation.org>
CC: Linux-MM <linux-mm@kvack.org>
Signed-off-by: Yunsheng Lin <linyunsheng@huawei.com>
Reviewed-by: Alexander Duyck <alexanderduyck@fb.com>
Acked-by: Chuck Lever <chuck.lever@oracle.com>
Link: https://patch.msgid.link/20241028115343.3405838-5-linyunsheng@huawei.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Yunsheng Lin and committed by
Jakub Kicinski
3d18dfe6 8218f62c

+19 -15
+1 -1
drivers/vhost/net.c
··· 1325 1325 vqs[VHOST_NET_VQ_RX]); 1326 1326 1327 1327 f->private_data = n; 1328 - n->pf_cache.va = NULL; 1328 + page_frag_cache_init(&n->pf_cache); 1329 1329 1330 1330 return 0; 1331 1331 }
+10
include/linux/page_frag_cache.h
··· 7 7 #include <linux/mm_types_task.h> 8 8 #include <linux/types.h> 9 9 10 + static inline void page_frag_cache_init(struct page_frag_cache *nc) 11 + { 12 + nc->va = NULL; 13 + } 14 + 15 + static inline bool page_frag_cache_is_pfmemalloc(struct page_frag_cache *nc) 16 + { 17 + return !!nc->pfmemalloc; 18 + } 19 + 10 20 void page_frag_cache_drain(struct page_frag_cache *nc); 11 21 void __page_frag_cache_drain(struct page *page, unsigned int count); 12 22 void *__page_frag_alloc_align(struct page_frag_cache *nc, unsigned int fragsz,
+3 -3
net/core/skbuff.c
··· 753 753 if (in_hardirq() || irqs_disabled()) { 754 754 nc = this_cpu_ptr(&netdev_alloc_cache); 755 755 data = page_frag_alloc(nc, len, gfp_mask); 756 - pfmemalloc = nc->pfmemalloc; 756 + pfmemalloc = page_frag_cache_is_pfmemalloc(nc); 757 757 } else { 758 758 local_bh_disable(); 759 759 local_lock_nested_bh(&napi_alloc_cache.bh_lock); 760 760 761 761 nc = this_cpu_ptr(&napi_alloc_cache.page); 762 762 data = page_frag_alloc(nc, len, gfp_mask); 763 - pfmemalloc = nc->pfmemalloc; 763 + pfmemalloc = page_frag_cache_is_pfmemalloc(nc); 764 764 765 765 local_unlock_nested_bh(&napi_alloc_cache.bh_lock); 766 766 local_bh_enable(); ··· 850 850 len = SKB_HEAD_ALIGN(len); 851 851 852 852 data = page_frag_alloc(&nc->page, len, gfp_mask); 853 - pfmemalloc = nc->page.pfmemalloc; 853 + pfmemalloc = page_frag_cache_is_pfmemalloc(&nc->page); 854 854 } 855 855 local_unlock_nested_bh(&napi_alloc_cache.bh_lock); 856 856
+1 -3
net/rxrpc/conn_object.c
··· 337 337 */ 338 338 rxrpc_purge_queue(&conn->rx_queue); 339 339 340 - if (conn->tx_data_alloc.va) 341 - __page_frag_cache_drain(virt_to_page(conn->tx_data_alloc.va), 342 - conn->tx_data_alloc.pagecnt_bias); 340 + page_frag_cache_drain(&conn->tx_data_alloc); 343 341 call_rcu(&conn->rcu, rxrpc_rcu_free_connection); 344 342 } 345 343
+1 -3
net/rxrpc/local_object.c
··· 452 452 #endif 453 453 rxrpc_purge_queue(&local->rx_queue); 454 454 rxrpc_purge_client_connections(local); 455 - if (local->tx_alloc.va) 456 - __page_frag_cache_drain(virt_to_page(local->tx_alloc.va), 457 - local->tx_alloc.pagecnt_bias); 455 + page_frag_cache_drain(&local->tx_alloc); 458 456 } 459 457 460 458 /*
+2 -4
net/sunrpc/svcsock.c
··· 1608 1608 static void svc_sock_free(struct svc_xprt *xprt) 1609 1609 { 1610 1610 struct svc_sock *svsk = container_of(xprt, struct svc_sock, sk_xprt); 1611 - struct page_frag_cache *pfc = &svsk->sk_frag_cache; 1612 1611 struct socket *sock = svsk->sk_sock; 1613 1612 1614 1613 trace_svcsock_free(svsk, sock); ··· 1617 1618 sockfd_put(sock); 1618 1619 else 1619 1620 sock_release(sock); 1620 - if (pfc->va) 1621 - __page_frag_cache_drain(virt_to_head_page(pfc->va), 1622 - pfc->pagecnt_bias); 1621 + 1622 + page_frag_cache_drain(&svsk->sk_frag_cache); 1623 1623 kfree(svsk); 1624 1624 }
+1 -1
tools/testing/selftests/mm/page_frag/page_frag_test.c
··· 126 126 u64 duration; 127 127 int ret; 128 128 129 - test_nc.va = NULL; 129 + page_frag_cache_init(&test_nc); 130 130 atomic_set(&nthreads, 2); 131 131 init_completion(&wait); 132 132