Re: [RFC PATCH net-next v1 2/4] net: introduce abstraction for network memory

From: David Ahern
Date: Thu Dec 14 2023 - 01:34:50 EST


On 12/13/23 7:05 PM, Mina Almasry wrote:
> diff --git a/include/net/netmem.h b/include/net/netmem.h
> new file mode 100644
> index 000000000000..e4309242d8be
> --- /dev/null
> +++ b/include/net/netmem.h
> @@ -0,0 +1,35 @@
> +/* SPDX-License-Identifier: GPL-2.0
> + *
> + * netmem.h
> + * Author: Mina Almasry <almasrymina@xxxxxxxxxx>
> + * Copyright (C) 2023 Google LLC
> + */
> +
> +#ifndef _NET_NETMEM_H
> +#define _NET_NETMEM_H
> +
> +struct netmem {
> + union {
> + struct page page;
> +
> + /* Stub to prevent compiler implicitly converting from page*
> + * to netmem_t* and vice versa.
> + *
> + * Other memory type(s) net stack would like to support
> + * can be added to this union.
> + */
> + void *addr;
> + };
> +};
> +
> +static inline struct page *netmem_to_page(struct netmem *netmem)
> +{
> + return &netmem->page;
> +}
> +
> +static inline struct netmem *page_to_netmem(struct page *page)
> +{
> + return (struct netmem *)page;

container_of; no typecasts.


> +}
> +
> +#endif /* _NET_NETMEM_H */