mirror of
https://github.com/torvalds/linux.git
synced 2024-11-22 20:22:09 +00:00
18ddbf5cf0
Add the netmem_ref type, an abstraction for network memory. To add support for new memory types to the net stack, we must first abstract the current memory type. Currently parts of the net stack use struct page directly: - page_pool - drivers - skb_frag_t Originally the plan was to reuse struct page* for the new memory types, and to set the LSB on the page* to indicate it's not really a page. However, for compiler type checking we need to introduce a new type. netmem_ref is introduced to abstract the underlying memory type. Currently it's a no-op abstraction that is always a struct page underneath. In parallel there is an undergoing effort to add support for devmem to the net stack: https://lore.kernel.org/netdev/20231208005250.2910004-1-almasrymina@google.com/ netmem_ref can be pointers to different underlying memory types, and the low bits are set to indicate the memory type. Helpers are provided to convert netmem pointers to the underlying memory type (currently only struct page). In the devmem series helpers are provided so that calling code can use netmem without worrying about the underlying memory type unless absolutely necessary. Reviewed-by: Shakeel Butt <shakeelb@google.com> Signed-off-by: Mina Almasry <almasrymina@google.com> Signed-off-by: Paolo Abeni <pabeni@redhat.com>
42 lines
1.0 KiB
C
42 lines
1.0 KiB
C
/* SPDX-License-Identifier: GPL-2.0
|
|
*
|
|
* Network memory
|
|
*
|
|
* Author: Mina Almasry <almasrymina@google.com>
|
|
*/
|
|
|
|
#ifndef _NET_NETMEM_H
|
|
#define _NET_NETMEM_H
|
|
|
|
/**
|
|
* typedef netmem_ref - a nonexistent type marking a reference to generic
|
|
* network memory.
|
|
*
|
|
* A netmem_ref currently is always a reference to a struct page. This
|
|
* abstraction is introduced so support for new memory types can be added.
|
|
*
|
|
* Use the supplied helpers to obtain the underlying memory pointer and fields.
|
|
*/
|
|
typedef unsigned long __bitwise netmem_ref;
|
|
|
|
/* This conversion fails (returns NULL) if the netmem_ref is not struct page
|
|
* backed.
|
|
*
|
|
* Currently struct page is the only possible netmem, and this helper never
|
|
* fails.
|
|
*/
|
|
static inline struct page *netmem_to_page(netmem_ref netmem)
|
|
{
|
|
return (__force struct page *)netmem;
|
|
}
|
|
|
|
/* Converting from page to netmem is always safe, because a page can always be
|
|
* a netmem.
|
|
*/
|
|
static inline netmem_ref page_to_netmem(struct page *page)
|
|
{
|
|
return (__force netmem_ref)page;
|
|
}
|
|
|
|
#endif /* _NET_NETMEM_H */
|