Commit 3d18dfe6 authored by Yunsheng Lin's avatar Yunsheng Lin Committed by Jakub Kicinski
Browse files

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: default avatarYunsheng Lin <linyunsheng@huawei.com>
Reviewed-by: default avatarAlexander Duyck <alexanderduyck@fb.com>
Acked-by: default avatarChuck Lever <chuck.lever@oracle.com>
Link: https://patch.msgid.link/20241028115343.3405838-5-linyunsheng@huawei.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 8218f62c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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;
}
+10 −0
Original line number Diff line number Diff line
@@ -7,6 +7,16 @@
#include <linux/mm_types_task.h>
#include <linux/types.h>

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,
+3 −3
Original line number Diff line number Diff line
@@ -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);

+1 −3
Original line number Diff line number Diff line
@@ -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);
}

+1 −3
Original line number Diff line number Diff line
@@ -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);
}

/*
Loading