Commit c3ead2df authored by David S. Miller's avatar David S. Miller

Merge git://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf

Daniel Borkmann says:

====================
pull-request: bpf 2019-07-03

The following pull-request contains BPF updates for your *net* tree.

The main changes are:

1) Fix the interpreter to properly handle BPF_ALU32 | BPF_ARSH
   on BE architectures, from Jiong.

2) Fix several bugs in the x32 BPF JIT for handling shifts by 0,
   from Luke and Xi.

3) Fix NULL pointer deref in btf_type_is_resolve_source_only(),
   from Stanislav.

4) Properly handle the check that forwarding is enabled on the device
   in bpf_ipv6_fib_lookup() helper code, from Anton.

5) Fix UAPI bpf_prog_info fields alignment for archs that have 16 bit
   alignment such as m68k, from Baruch.

6) Fix kernel hanging in unregister_netdevice loop while unregistering
   device bound to XDP socket, from Ilya.

7) Properly terminate tail update in xskq_produce_flush_desc(), from Nathan.

8) Fix broken always_inline handling in test_lwt_seg6local, from Jiri.

9) Fix bpftool to use correct argument in cgroup errors, from Jakub.

10) Fix detaching dummy prog in XDP redirect sample code, from Prashant.

11) Add Jonathan to AF_XDP reviewers, from Björn.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 0d581ba3 455302d1
...@@ -17274,6 +17274,7 @@ N: xdp ...@@ -17274,6 +17274,7 @@ N: xdp
XDP SOCKETS (AF_XDP) XDP SOCKETS (AF_XDP)
M: Björn Töpel <bjorn.topel@intel.com> M: Björn Töpel <bjorn.topel@intel.com>
M: Magnus Karlsson <magnus.karlsson@intel.com> M: Magnus Karlsson <magnus.karlsson@intel.com>
R: Jonathan Lemon <jonathan.lemon@gmail.com>
L: netdev@vger.kernel.org L: netdev@vger.kernel.org
L: bpf@vger.kernel.org L: bpf@vger.kernel.org
S: Maintained S: Maintained
......
This diff is collapsed.
...@@ -61,6 +61,11 @@ struct xdp_sock { ...@@ -61,6 +61,11 @@ struct xdp_sock {
struct xsk_queue *tx ____cacheline_aligned_in_smp; struct xsk_queue *tx ____cacheline_aligned_in_smp;
struct list_head list; struct list_head list;
bool zc; bool zc;
enum {
XSK_READY = 0,
XSK_BOUND,
XSK_UNBOUND,
} state;
/* Protects multiple processes in the control path */ /* Protects multiple processes in the control path */
struct mutex mutex; struct mutex mutex;
/* Mutual exclusion of NAPI TX thread and sendmsg error paths /* Mutual exclusion of NAPI TX thread and sendmsg error paths
......
...@@ -3143,6 +3143,7 @@ struct bpf_prog_info { ...@@ -3143,6 +3143,7 @@ struct bpf_prog_info {
char name[BPF_OBJ_NAME_LEN]; char name[BPF_OBJ_NAME_LEN];
__u32 ifindex; __u32 ifindex;
__u32 gpl_compatible:1; __u32 gpl_compatible:1;
__u32 :31; /* alignment pad */
__u64 netns_dev; __u64 netns_dev;
__u64 netns_ino; __u64 netns_ino;
__u32 nr_jited_ksyms; __u32 nr_jited_ksyms;
......
...@@ -1928,8 +1928,8 @@ static int btf_array_resolve(struct btf_verifier_env *env, ...@@ -1928,8 +1928,8 @@ static int btf_array_resolve(struct btf_verifier_env *env,
/* Check array->index_type */ /* Check array->index_type */
index_type_id = array->index_type; index_type_id = array->index_type;
index_type = btf_type_by_id(btf, index_type_id); index_type = btf_type_by_id(btf, index_type_id);
if (btf_type_is_resolve_source_only(index_type) || if (btf_type_nosize_or_null(index_type) ||
btf_type_nosize_or_null(index_type)) { btf_type_is_resolve_source_only(index_type)) {
btf_verifier_log_type(env, v->t, "Invalid index"); btf_verifier_log_type(env, v->t, "Invalid index");
return -EINVAL; return -EINVAL;
} }
...@@ -1948,8 +1948,8 @@ static int btf_array_resolve(struct btf_verifier_env *env, ...@@ -1948,8 +1948,8 @@ static int btf_array_resolve(struct btf_verifier_env *env,
/* Check array->type */ /* Check array->type */
elem_type_id = array->type; elem_type_id = array->type;
elem_type = btf_type_by_id(btf, elem_type_id); elem_type = btf_type_by_id(btf, elem_type_id);
if (btf_type_is_resolve_source_only(elem_type) || if (btf_type_nosize_or_null(elem_type) ||
btf_type_nosize_or_null(elem_type)) { btf_type_is_resolve_source_only(elem_type)) {
btf_verifier_log_type(env, v->t, btf_verifier_log_type(env, v->t,
"Invalid elem"); "Invalid elem");
return -EINVAL; return -EINVAL;
...@@ -2170,8 +2170,8 @@ static int btf_struct_resolve(struct btf_verifier_env *env, ...@@ -2170,8 +2170,8 @@ static int btf_struct_resolve(struct btf_verifier_env *env,
const struct btf_type *member_type = btf_type_by_id(env->btf, const struct btf_type *member_type = btf_type_by_id(env->btf,
member_type_id); member_type_id);
if (btf_type_is_resolve_source_only(member_type) || if (btf_type_nosize_or_null(member_type) ||
btf_type_nosize_or_null(member_type)) { btf_type_is_resolve_source_only(member_type)) {
btf_verifier_log_member(env, v->t, member, btf_verifier_log_member(env, v->t, member,
"Invalid member"); "Invalid member");
return -EINVAL; return -EINVAL;
......
...@@ -1364,10 +1364,10 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, u64 *stack) ...@@ -1364,10 +1364,10 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn, u64 *stack)
insn++; insn++;
CONT; CONT;
ALU_ARSH_X: ALU_ARSH_X:
DST = (u64) (u32) ((*(s32 *) &DST) >> SRC); DST = (u64) (u32) (((s32) DST) >> SRC);
CONT; CONT;
ALU_ARSH_K: ALU_ARSH_K:
DST = (u64) (u32) ((*(s32 *) &DST) >> IMM); DST = (u64) (u32) (((s32) DST) >> IMM);
CONT; CONT;
ALU64_ARSH_X: ALU64_ARSH_X:
(*(s64 *) &DST) >>= SRC; (*(s64 *) &DST) >>= SRC;
......
...@@ -4737,7 +4737,7 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params, ...@@ -4737,7 +4737,7 @@ static int bpf_ipv6_fib_lookup(struct net *net, struct bpf_fib_lookup *params,
return -ENODEV; return -ENODEV;
idev = __in6_dev_get_safely(dev); idev = __in6_dev_get_safely(dev);
if (unlikely(!idev || !net->ipv6.devconf_all->forwarding)) if (unlikely(!idev || !idev->cnf.forwarding))
return BPF_FIB_LKUP_RET_FWD_DISABLED; return BPF_FIB_LKUP_RET_FWD_DISABLED;
if (flags & BPF_FIB_LOOKUP_OUTPUT) { if (flags & BPF_FIB_LOOKUP_OUTPUT) {
......
...@@ -105,6 +105,9 @@ int xdp_umem_assign_dev(struct xdp_umem *umem, struct net_device *dev, ...@@ -105,6 +105,9 @@ int xdp_umem_assign_dev(struct xdp_umem *umem, struct net_device *dev,
umem->dev = dev; umem->dev = dev;
umem->queue_id = queue_id; umem->queue_id = queue_id;
dev_hold(dev);
if (force_copy) if (force_copy)
/* For copy-mode, we are done. */ /* For copy-mode, we are done. */
goto out_rtnl_unlock; goto out_rtnl_unlock;
...@@ -124,7 +127,6 @@ int xdp_umem_assign_dev(struct xdp_umem *umem, struct net_device *dev, ...@@ -124,7 +127,6 @@ int xdp_umem_assign_dev(struct xdp_umem *umem, struct net_device *dev,
goto err_unreg_umem; goto err_unreg_umem;
rtnl_unlock(); rtnl_unlock();
dev_hold(dev);
umem->zc = true; umem->zc = true;
return 0; return 0;
...@@ -138,11 +140,13 @@ int xdp_umem_assign_dev(struct xdp_umem *umem, struct net_device *dev, ...@@ -138,11 +140,13 @@ int xdp_umem_assign_dev(struct xdp_umem *umem, struct net_device *dev,
return err; return err;
} }
static void xdp_umem_clear_dev(struct xdp_umem *umem) void xdp_umem_clear_dev(struct xdp_umem *umem)
{ {
struct netdev_bpf bpf; struct netdev_bpf bpf;
int err; int err;
ASSERT_RTNL();
if (!umem->dev) if (!umem->dev)
return; return;
...@@ -151,22 +155,17 @@ static void xdp_umem_clear_dev(struct xdp_umem *umem) ...@@ -151,22 +155,17 @@ static void xdp_umem_clear_dev(struct xdp_umem *umem)
bpf.xsk.umem = NULL; bpf.xsk.umem = NULL;
bpf.xsk.queue_id = umem->queue_id; bpf.xsk.queue_id = umem->queue_id;
rtnl_lock();
err = umem->dev->netdev_ops->ndo_bpf(umem->dev, &bpf); err = umem->dev->netdev_ops->ndo_bpf(umem->dev, &bpf);
rtnl_unlock();
if (err) if (err)
WARN(1, "failed to disable umem!\n"); WARN(1, "failed to disable umem!\n");
} }
rtnl_lock();
xdp_clear_umem_at_qid(umem->dev, umem->queue_id); xdp_clear_umem_at_qid(umem->dev, umem->queue_id);
rtnl_unlock();
if (umem->zc) { dev_put(umem->dev);
dev_put(umem->dev); umem->dev = NULL;
umem->zc = false; umem->zc = false;
}
} }
static void xdp_umem_unpin_pages(struct xdp_umem *umem) static void xdp_umem_unpin_pages(struct xdp_umem *umem)
...@@ -194,7 +193,9 @@ static void xdp_umem_unaccount_pages(struct xdp_umem *umem) ...@@ -194,7 +193,9 @@ static void xdp_umem_unaccount_pages(struct xdp_umem *umem)
static void xdp_umem_release(struct xdp_umem *umem) static void xdp_umem_release(struct xdp_umem *umem)
{ {
rtnl_lock();
xdp_umem_clear_dev(umem); xdp_umem_clear_dev(umem);
rtnl_unlock();
ida_simple_remove(&umem_ida, umem->id); ida_simple_remove(&umem_ida, umem->id);
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
int xdp_umem_assign_dev(struct xdp_umem *umem, struct net_device *dev, int xdp_umem_assign_dev(struct xdp_umem *umem, struct net_device *dev,
u16 queue_id, u16 flags); u16 queue_id, u16 flags);
void xdp_umem_clear_dev(struct xdp_umem *umem);
bool xdp_umem_validate_queues(struct xdp_umem *umem); bool xdp_umem_validate_queues(struct xdp_umem *umem);
void xdp_get_umem(struct xdp_umem *umem); void xdp_get_umem(struct xdp_umem *umem);
void xdp_put_umem(struct xdp_umem *umem); void xdp_put_umem(struct xdp_umem *umem);
......
...@@ -335,6 +335,22 @@ static int xsk_init_queue(u32 entries, struct xsk_queue **queue, ...@@ -335,6 +335,22 @@ static int xsk_init_queue(u32 entries, struct xsk_queue **queue,
return 0; return 0;
} }
static void xsk_unbind_dev(struct xdp_sock *xs)
{
struct net_device *dev = xs->dev;
if (!dev || xs->state != XSK_BOUND)
return;
xs->state = XSK_UNBOUND;
/* Wait for driver to stop using the xdp socket. */
xdp_del_sk_umem(xs->umem, xs);
xs->dev = NULL;
synchronize_net();
dev_put(dev);
}
static int xsk_release(struct socket *sock) static int xsk_release(struct socket *sock)
{ {
struct sock *sk = sock->sk; struct sock *sk = sock->sk;
...@@ -354,15 +370,7 @@ static int xsk_release(struct socket *sock) ...@@ -354,15 +370,7 @@ static int xsk_release(struct socket *sock)
sock_prot_inuse_add(net, sk->sk_prot, -1); sock_prot_inuse_add(net, sk->sk_prot, -1);
local_bh_enable(); local_bh_enable();
if (xs->dev) { xsk_unbind_dev(xs);
struct net_device *dev = xs->dev;
/* Wait for driver to stop using the xdp socket. */
xdp_del_sk_umem(xs->umem, xs);
xs->dev = NULL;
synchronize_net();
dev_put(dev);
}
xskq_destroy(xs->rx); xskq_destroy(xs->rx);
xskq_destroy(xs->tx); xskq_destroy(xs->tx);
...@@ -412,7 +420,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len) ...@@ -412,7 +420,7 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
return -EINVAL; return -EINVAL;
mutex_lock(&xs->mutex); mutex_lock(&xs->mutex);
if (xs->dev) { if (xs->state != XSK_READY) {
err = -EBUSY; err = -EBUSY;
goto out_release; goto out_release;
} }
...@@ -492,6 +500,8 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len) ...@@ -492,6 +500,8 @@ static int xsk_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
out_unlock: out_unlock:
if (err) if (err)
dev_put(dev); dev_put(dev);
else
xs->state = XSK_BOUND;
out_release: out_release:
mutex_unlock(&xs->mutex); mutex_unlock(&xs->mutex);
return err; return err;
...@@ -520,6 +530,10 @@ static int xsk_setsockopt(struct socket *sock, int level, int optname, ...@@ -520,6 +530,10 @@ static int xsk_setsockopt(struct socket *sock, int level, int optname,
return -EFAULT; return -EFAULT;
mutex_lock(&xs->mutex); mutex_lock(&xs->mutex);
if (xs->state != XSK_READY) {
mutex_unlock(&xs->mutex);
return -EBUSY;
}
q = (optname == XDP_TX_RING) ? &xs->tx : &xs->rx; q = (optname == XDP_TX_RING) ? &xs->tx : &xs->rx;
err = xsk_init_queue(entries, q, false); err = xsk_init_queue(entries, q, false);
mutex_unlock(&xs->mutex); mutex_unlock(&xs->mutex);
...@@ -534,7 +548,7 @@ static int xsk_setsockopt(struct socket *sock, int level, int optname, ...@@ -534,7 +548,7 @@ static int xsk_setsockopt(struct socket *sock, int level, int optname,
return -EFAULT; return -EFAULT;
mutex_lock(&xs->mutex); mutex_lock(&xs->mutex);
if (xs->umem) { if (xs->state != XSK_READY || xs->umem) {
mutex_unlock(&xs->mutex); mutex_unlock(&xs->mutex);
return -EBUSY; return -EBUSY;
} }
...@@ -561,6 +575,10 @@ static int xsk_setsockopt(struct socket *sock, int level, int optname, ...@@ -561,6 +575,10 @@ static int xsk_setsockopt(struct socket *sock, int level, int optname,
return -EFAULT; return -EFAULT;
mutex_lock(&xs->mutex); mutex_lock(&xs->mutex);
if (xs->state != XSK_READY) {
mutex_unlock(&xs->mutex);
return -EBUSY;
}
if (!xs->umem) { if (!xs->umem) {
mutex_unlock(&xs->mutex); mutex_unlock(&xs->mutex);
return -EINVAL; return -EINVAL;
...@@ -662,6 +680,9 @@ static int xsk_mmap(struct file *file, struct socket *sock, ...@@ -662,6 +680,9 @@ static int xsk_mmap(struct file *file, struct socket *sock,
unsigned long pfn; unsigned long pfn;
struct page *qpg; struct page *qpg;
if (xs->state != XSK_READY)
return -EBUSY;
if (offset == XDP_PGOFF_RX_RING) { if (offset == XDP_PGOFF_RX_RING) {
q = READ_ONCE(xs->rx); q = READ_ONCE(xs->rx);
} else if (offset == XDP_PGOFF_TX_RING) { } else if (offset == XDP_PGOFF_TX_RING) {
...@@ -693,6 +714,38 @@ static int xsk_mmap(struct file *file, struct socket *sock, ...@@ -693,6 +714,38 @@ static int xsk_mmap(struct file *file, struct socket *sock,
size, vma->vm_page_prot); size, vma->vm_page_prot);
} }
static int xsk_notifier(struct notifier_block *this,
unsigned long msg, void *ptr)
{
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
struct net *net = dev_net(dev);
struct sock *sk;
switch (msg) {
case NETDEV_UNREGISTER:
mutex_lock(&net->xdp.lock);
sk_for_each(sk, &net->xdp.list) {
struct xdp_sock *xs = xdp_sk(sk);
mutex_lock(&xs->mutex);
if (xs->dev == dev) {
sk->sk_err = ENETDOWN;
if (!sock_flag(sk, SOCK_DEAD))
sk->sk_error_report(sk);
xsk_unbind_dev(xs);
/* Clear device references in umem. */
xdp_umem_clear_dev(xs->umem);
}
mutex_unlock(&xs->mutex);
}
mutex_unlock(&net->xdp.lock);
break;
}
return NOTIFY_DONE;
}
static struct proto xsk_proto = { static struct proto xsk_proto = {
.name = "XDP", .name = "XDP",
.owner = THIS_MODULE, .owner = THIS_MODULE,
...@@ -764,6 +817,7 @@ static int xsk_create(struct net *net, struct socket *sock, int protocol, ...@@ -764,6 +817,7 @@ static int xsk_create(struct net *net, struct socket *sock, int protocol,
sock_set_flag(sk, SOCK_RCU_FREE); sock_set_flag(sk, SOCK_RCU_FREE);
xs = xdp_sk(sk); xs = xdp_sk(sk);
xs->state = XSK_READY;
mutex_init(&xs->mutex); mutex_init(&xs->mutex);
spin_lock_init(&xs->tx_completion_lock); spin_lock_init(&xs->tx_completion_lock);
...@@ -784,6 +838,10 @@ static const struct net_proto_family xsk_family_ops = { ...@@ -784,6 +838,10 @@ static const struct net_proto_family xsk_family_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
}; };
static struct notifier_block xsk_netdev_notifier = {
.notifier_call = xsk_notifier,
};
static int __net_init xsk_net_init(struct net *net) static int __net_init xsk_net_init(struct net *net)
{ {
mutex_init(&net->xdp.lock); mutex_init(&net->xdp.lock);
...@@ -816,8 +874,15 @@ static int __init xsk_init(void) ...@@ -816,8 +874,15 @@ static int __init xsk_init(void)
err = register_pernet_subsys(&xsk_net_ops); err = register_pernet_subsys(&xsk_net_ops);
if (err) if (err)
goto out_sk; goto out_sk;
err = register_netdevice_notifier(&xsk_netdev_notifier);
if (err)
goto out_pernet;
return 0; return 0;
out_pernet:
unregister_pernet_subsys(&xsk_net_ops);
out_sk: out_sk:
sock_unregister(PF_XDP); sock_unregister(PF_XDP);
out_proto: out_proto:
......
...@@ -288,7 +288,7 @@ static inline void xskq_produce_flush_desc(struct xsk_queue *q) ...@@ -288,7 +288,7 @@ static inline void xskq_produce_flush_desc(struct xsk_queue *q)
/* Order producer and data */ /* Order producer and data */
smp_wmb(); /* B, matches C */ smp_wmb(); /* B, matches C */
q->prod_tail = q->prod_head, q->prod_tail = q->prod_head;
WRITE_ONCE(q->ring->producer, q->prod_tail); WRITE_ONCE(q->ring->producer, q->prod_tail);
} }
......
...@@ -189,7 +189,7 @@ int main(int argc, char **argv) ...@@ -189,7 +189,7 @@ int main(int argc, char **argv)
} }
memset(&info, 0, sizeof(info)); memset(&info, 0, sizeof(info));
ret = bpf_obj_get_info_by_fd(prog_fd, &info, &info_len); ret = bpf_obj_get_info_by_fd(dummy_prog_fd, &info, &info_len);
if (ret) { if (ret) {
printf("can't get prog info - %s\n", strerror(errno)); printf("can't get prog info - %s\n", strerror(errno));
return ret; return ret;
......
...@@ -168,7 +168,7 @@ static int do_show(int argc, char **argv) ...@@ -168,7 +168,7 @@ static int do_show(int argc, char **argv)
cgroup_fd = open(argv[0], O_RDONLY); cgroup_fd = open(argv[0], O_RDONLY);
if (cgroup_fd < 0) { if (cgroup_fd < 0) {
p_err("can't open cgroup %s", argv[1]); p_err("can't open cgroup %s", argv[0]);
goto exit; goto exit;
} }
...@@ -356,7 +356,7 @@ static int do_attach(int argc, char **argv) ...@@ -356,7 +356,7 @@ static int do_attach(int argc, char **argv)
cgroup_fd = open(argv[0], O_RDONLY); cgroup_fd = open(argv[0], O_RDONLY);
if (cgroup_fd < 0) { if (cgroup_fd < 0) {
p_err("can't open cgroup %s", argv[1]); p_err("can't open cgroup %s", argv[0]);
goto exit; goto exit;
} }
...@@ -414,7 +414,7 @@ static int do_detach(int argc, char **argv) ...@@ -414,7 +414,7 @@ static int do_detach(int argc, char **argv)
cgroup_fd = open(argv[0], O_RDONLY); cgroup_fd = open(argv[0], O_RDONLY);
if (cgroup_fd < 0) { if (cgroup_fd < 0) {
p_err("can't open cgroup %s", argv[1]); p_err("can't open cgroup %s", argv[0]);
goto exit; goto exit;
} }
......
...@@ -3143,6 +3143,7 @@ struct bpf_prog_info { ...@@ -3143,6 +3143,7 @@ struct bpf_prog_info {
char name[BPF_OBJ_NAME_LEN]; char name[BPF_OBJ_NAME_LEN];
__u32 ifindex; __u32 ifindex;
__u32 gpl_compatible:1; __u32 gpl_compatible:1;
__u32 :31; /* alignment pad */
__u64 netns_dev; __u64 netns_dev;
__u64 netns_ino; __u64 netns_ino;
__u32 nr_jited_ksyms; __u32 nr_jited_ksyms;
......
...@@ -61,7 +61,7 @@ struct sr6_tlv_t { ...@@ -61,7 +61,7 @@ struct sr6_tlv_t {
unsigned char value[0]; unsigned char value[0];
} BPF_PACKET_HEADER; } BPF_PACKET_HEADER;
__attribute__((always_inline)) struct ip6_srh_t *get_srh(struct __sk_buff *skb) static __always_inline struct ip6_srh_t *get_srh(struct __sk_buff *skb)
{ {
void *cursor, *data_end; void *cursor, *data_end;
struct ip6_srh_t *srh; struct ip6_srh_t *srh;
...@@ -95,7 +95,7 @@ __attribute__((always_inline)) struct ip6_srh_t *get_srh(struct __sk_buff *skb) ...@@ -95,7 +95,7 @@ __attribute__((always_inline)) struct ip6_srh_t *get_srh(struct __sk_buff *skb)
return srh; return srh;
} }
__attribute__((always_inline)) static __always_inline
int update_tlv_pad(struct __sk_buff *skb, uint32_t new_pad, int update_tlv_pad(struct __sk_buff *skb, uint32_t new_pad,
uint32_t old_pad, uint32_t pad_off) uint32_t old_pad, uint32_t pad_off)
{ {
...@@ -125,7 +125,7 @@ int update_tlv_pad(struct __sk_buff *skb, uint32_t new_pad, ...@@ -125,7 +125,7 @@ int update_tlv_pad(struct __sk_buff *skb, uint32_t new_pad,
return 0; return 0;
} }
__attribute__((always_inline)) static __always_inline
int is_valid_tlv_boundary(struct __sk_buff *skb, struct ip6_srh_t *srh, int is_valid_tlv_boundary(struct __sk_buff *skb, struct ip6_srh_t *srh,
uint32_t *tlv_off, uint32_t *pad_size, uint32_t *tlv_off, uint32_t *pad_size,
uint32_t *pad_off) uint32_t *pad_off)
...@@ -184,7 +184,7 @@ int is_valid_tlv_boundary(struct __sk_buff *skb, struct ip6_srh_t *srh, ...@@ -184,7 +184,7 @@ int is_valid_tlv_boundary(struct __sk_buff *skb, struct ip6_srh_t *srh,
return 0; return 0;
} }
__attribute__((always_inline)) static __always_inline
int add_tlv(struct __sk_buff *skb, struct ip6_srh_t *srh, uint32_t tlv_off, int add_tlv(struct __sk_buff *skb, struct ip6_srh_t *srh, uint32_t tlv_off,
struct sr6_tlv_t *itlv, uint8_t tlv_size) struct sr6_tlv_t *itlv, uint8_t tlv_size)
{ {
...@@ -228,7 +228,7 @@ int add_tlv(struct __sk_buff *skb, struct ip6_srh_t *srh, uint32_t tlv_off, ...@@ -228,7 +228,7 @@ int add_tlv(struct __sk_buff *skb, struct ip6_srh_t *srh, uint32_t tlv_off,
return update_tlv_pad(skb, new_pad, pad_size, pad_off); return update_tlv_pad(skb, new_pad, pad_size, pad_off);
} }
__attribute__((always_inline)) static __always_inline
int delete_tlv(struct __sk_buff *skb, struct ip6_srh_t *srh, int delete_tlv(struct __sk_buff *skb, struct ip6_srh_t *srh,
uint32_t tlv_off) uint32_t tlv_off)
{ {
...@@ -266,7 +266,7 @@ int delete_tlv(struct __sk_buff *skb, struct ip6_srh_t *srh, ...@@ -266,7 +266,7 @@ int delete_tlv(struct __sk_buff *skb, struct ip6_srh_t *srh,
return update_tlv_pad(skb, new_pad, pad_size, pad_off); return update_tlv_pad(skb, new_pad, pad_size, pad_off);
} }
__attribute__((always_inline)) static __always_inline
int has_egr_tlv(struct __sk_buff *skb, struct ip6_srh_t *srh) int has_egr_tlv(struct __sk_buff *skb, struct ip6_srh_t *srh)
{ {
int tlv_offset = sizeof(struct ip6_t) + sizeof(struct ip6_srh_t) + int tlv_offset = sizeof(struct ip6_t) + sizeof(struct ip6_srh_t) +
......
...@@ -90,6 +90,91 @@ ...@@ -90,6 +90,91 @@
}, },
.result = ACCEPT, .result = ACCEPT,
}, },
{
"lsh64 by 0 imm",
.insns = {
BPF_LD_IMM64(BPF_REG_0, 1),
BPF_LD_IMM64(BPF_REG_1, 1),
BPF_ALU64_IMM(BPF_LSH, BPF_REG_1, 0),
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 1, 1),
BPF_MOV64_IMM(BPF_REG_0, 2),
BPF_EXIT_INSN(),
},
.result = ACCEPT,
.retval = 1,
},
{
"rsh64 by 0 imm",
.insns = {
BPF_LD_IMM64(BPF_REG_0, 1),
BPF_LD_IMM64(BPF_REG_1, 0x100000000LL),
BPF_ALU64_REG(BPF_MOV, BPF_REG_2, BPF_REG_1),
BPF_ALU64_IMM(BPF_RSH, BPF_REG_1, 0),
BPF_JMP_REG(BPF_JEQ, BPF_REG_1, BPF_REG_2, 1),
BPF_MOV64_IMM(BPF_REG_0, 2),
BPF_EXIT_INSN(),
},
.result = ACCEPT,
.retval = 1,
},
{
"arsh64 by 0 imm",
.insns = {
BPF_LD_IMM64(BPF_REG_0, 1),
BPF_LD_IMM64(BPF_REG_1, 0x100000000LL),
BPF_ALU64_REG(BPF_MOV, BPF_REG_2, BPF_REG_1),
BPF_ALU64_IMM(BPF_ARSH, BPF_REG_1, 0),
BPF_JMP_REG(BPF_JEQ, BPF_REG_1, BPF_REG_2, 1),
BPF_MOV64_IMM(BPF_REG_0, 2),
BPF_EXIT_INSN(),
},
.result = ACCEPT,
.retval = 1,
},
{
"lsh64 by 0 reg",
.insns = {
BPF_LD_IMM64(BPF_REG_0, 1),
BPF_LD_IMM64(BPF_REG_1, 1),
BPF_LD_IMM64(BPF_REG_2, 0),
BPF_ALU64_REG(BPF_LSH, BPF_REG_1, BPF_REG_2),
BPF_JMP_IMM(BPF_JEQ, BPF_REG_1, 1, 1),
BPF_MOV64_IMM(BPF_REG_0, 2),
BPF_EXIT_INSN(),
},
.result = ACCEPT,
.retval = 1,
},
{
"rsh64 by 0 reg",
.insns = {
BPF_LD_IMM64(BPF_REG_0, 1),
BPF_LD_IMM64(BPF_REG_1, 0x100000000LL),
BPF_ALU64_REG(BPF_MOV, BPF_REG_2, BPF_REG_1),
BPF_LD_IMM64(BPF_REG_3, 0),
BPF_ALU64_REG(BPF_RSH, BPF_REG_1, BPF_REG_3),
BPF_JMP_REG(BPF_JEQ, BPF_REG_1, BPF_REG_2, 1),
BPF_MOV64_IMM(BPF_REG_0, 2),
BPF_EXIT_INSN(),
},
.result = ACCEPT,
.retval = 1,
},
{
"arsh64 by 0 reg",
.insns = {
BPF_LD_IMM64(BPF_REG_0, 1),
BPF_LD_IMM64(BPF_REG_1, 0x100000000LL),
BPF_ALU64_REG(BPF_MOV, BPF_REG_2, BPF_REG_1),
BPF_LD_IMM64(BPF_REG_3, 0),
BPF_ALU64_REG(BPF_ARSH, BPF_REG_1, BPF_REG_3),
BPF_JMP_REG(BPF_JEQ, BPF_REG_1, BPF_REG_2, 1),
BPF_MOV64_IMM(BPF_REG_0, 2),
BPF_EXIT_INSN(),
},
.result = ACCEPT,
.retval = 1,
},
{ {
"invalid 64-bit BPF_END", "invalid 64-bit BPF_END",
.insns = { .insns = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment