Skip to content

Commit

Permalink
net-tun: Eliminate two tun/xdp related function calls from vhost-net
Browse files Browse the repository at this point in the history
This provides a minor performance boost by virtue of inlining
instead of cross module function calls.

Test: builds

Signed-off-by: Maciej Żenczykowski <maze@google.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://lore.kernel.org/bpf/20200819010710.3959310-2-zenczykowski@gmail.com
  • Loading branch information
Maciej Żenczykowski authored and Alexei Starovoitov committed Aug 19, 2020
1 parent b558b6c commit 596b5ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 21 deletions.
18 changes: 0 additions & 18 deletions drivers/net/tun.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,24 +219,6 @@ struct veth {
__be16 h_vlan_TCI;
};

bool tun_is_xdp_frame(void *ptr)
{
return (unsigned long)ptr & TUN_XDP_FLAG;
}
EXPORT_SYMBOL(tun_is_xdp_frame);

void *tun_xdp_to_ptr(struct xdp_frame *xdp)
{
return (void *)((unsigned long)xdp | TUN_XDP_FLAG);
}
EXPORT_SYMBOL(tun_xdp_to_ptr);

struct xdp_frame *tun_ptr_to_xdp(void *ptr)
{
return (void *)((unsigned long)ptr & ~TUN_XDP_FLAG);
}
EXPORT_SYMBOL(tun_ptr_to_xdp);

static int tun_napi_receive(struct napi_struct *napi, int budget)
{
struct tun_file *tfile = container_of(napi, struct tun_file, napi);
Expand Down
15 changes: 12 additions & 3 deletions include/linux/if_tun.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@ struct tun_xdp_hdr {
#if defined(CONFIG_TUN) || defined(CONFIG_TUN_MODULE)
struct socket *tun_get_socket(struct file *);
struct ptr_ring *tun_get_tx_ring(struct file *file);
bool tun_is_xdp_frame(void *ptr);
void *tun_xdp_to_ptr(struct xdp_frame *xdp);
struct xdp_frame *tun_ptr_to_xdp(void *ptr);
static inline bool tun_is_xdp_frame(void *ptr)
{
return (unsigned long)ptr & TUN_XDP_FLAG;
}
static inline void *tun_xdp_to_ptr(struct xdp_frame *xdp)
{
return (void *)((unsigned long)xdp | TUN_XDP_FLAG);
}
static inline struct xdp_frame *tun_ptr_to_xdp(void *ptr)
{
return (void *)((unsigned long)ptr & ~TUN_XDP_FLAG);
}
void tun_ptr_free(void *ptr);
#else
#include <linux/err.h>
Expand Down

0 comments on commit 596b5ef

Please sign in to comment.