mirror of https://gitee.com/openkylin/linux.git
xsk: Remove explicit_free parameter from __xsk_rcv()
The explicit_free parameter of the __xsk_rcv() function was used to mark whether the call was via the generic XDP or the native XDP path. Instead of clutter the code with if-statements and "true/false" parameters which are hard to understand, simply move the explicit free to the __xsk_map_redirect() which is always called from the native XDP path. Signed-off-by: Björn Töpel <bjorn.topel@intel.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com> Link: https://lore.kernel.org/bpf/20210122105351.11751-2-bjorn.topel@gmail.com
This commit is contained in:
parent
6e66fbb105
commit
458f727234
|
@ -184,12 +184,13 @@ static void xsk_copy_xdp(struct xdp_buff *to, struct xdp_buff *from, u32 len)
|
||||||
memcpy(to_buf, from_buf, len + metalen);
|
memcpy(to_buf, from_buf, len + metalen);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int __xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len,
|
static int __xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
|
||||||
bool explicit_free)
|
|
||||||
{
|
{
|
||||||
struct xdp_buff *xsk_xdp;
|
struct xdp_buff *xsk_xdp;
|
||||||
int err;
|
int err;
|
||||||
|
u32 len;
|
||||||
|
|
||||||
|
len = xdp->data_end - xdp->data;
|
||||||
if (len > xsk_pool_get_rx_frame_size(xs->pool)) {
|
if (len > xsk_pool_get_rx_frame_size(xs->pool)) {
|
||||||
xs->rx_dropped++;
|
xs->rx_dropped++;
|
||||||
return -ENOSPC;
|
return -ENOSPC;
|
||||||
|
@ -207,8 +208,6 @@ static int __xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp, u32 len,
|
||||||
xsk_buff_free(xsk_xdp);
|
xsk_buff_free(xsk_xdp);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
if (explicit_free)
|
|
||||||
xdp_return_buff(xdp);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,11 +229,8 @@ static bool xsk_is_bound(struct xdp_sock *xs)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp,
|
static int xsk_rcv_check(struct xdp_sock *xs, struct xdp_buff *xdp)
|
||||||
bool explicit_free)
|
|
||||||
{
|
{
|
||||||
u32 len;
|
|
||||||
|
|
||||||
if (!xsk_is_bound(xs))
|
if (!xsk_is_bound(xs))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
|
@ -242,11 +238,7 @@ static int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp,
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
sk_mark_napi_id_once_xdp(&xs->sk, xdp);
|
sk_mark_napi_id_once_xdp(&xs->sk, xdp);
|
||||||
len = xdp->data_end - xdp->data;
|
return 0;
|
||||||
|
|
||||||
return xdp->rxq->mem.type == MEM_TYPE_XSK_BUFF_POOL ?
|
|
||||||
__xsk_rcv_zc(xs, xdp, len) :
|
|
||||||
__xsk_rcv(xs, xdp, len, explicit_free);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void xsk_flush(struct xdp_sock *xs)
|
static void xsk_flush(struct xdp_sock *xs)
|
||||||
|
@ -261,18 +253,41 @@ int xsk_generic_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
spin_lock_bh(&xs->rx_lock);
|
spin_lock_bh(&xs->rx_lock);
|
||||||
err = xsk_rcv(xs, xdp, false);
|
err = xsk_rcv_check(xs, xdp);
|
||||||
xsk_flush(xs);
|
if (!err) {
|
||||||
|
err = __xsk_rcv(xs, xdp);
|
||||||
|
xsk_flush(xs);
|
||||||
|
}
|
||||||
spin_unlock_bh(&xs->rx_lock);
|
spin_unlock_bh(&xs->rx_lock);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int xsk_rcv(struct xdp_sock *xs, struct xdp_buff *xdp)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
u32 len;
|
||||||
|
|
||||||
|
err = xsk_rcv_check(xs, xdp);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
if (xdp->rxq->mem.type == MEM_TYPE_XSK_BUFF_POOL) {
|
||||||
|
len = xdp->data_end - xdp->data;
|
||||||
|
return __xsk_rcv_zc(xs, xdp, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
err = __xsk_rcv(xs, xdp);
|
||||||
|
if (!err)
|
||||||
|
xdp_return_buff(xdp);
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
int __xsk_map_redirect(struct xdp_sock *xs, struct xdp_buff *xdp)
|
int __xsk_map_redirect(struct xdp_sock *xs, struct xdp_buff *xdp)
|
||||||
{
|
{
|
||||||
struct list_head *flush_list = this_cpu_ptr(&xskmap_flush_list);
|
struct list_head *flush_list = this_cpu_ptr(&xskmap_flush_list);
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = xsk_rcv(xs, xdp, true);
|
err = xsk_rcv(xs, xdp);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue