offload.c (82ffd0454bd9bd57780966d47bfd56d579dd4fb3) | offload.c (dd27c2e3d0a05c01ff14bb672d1a3f0fdd8f98fc) |
---|---|
1/* 2 * Copyright (C) 2017-2018 Netronome Systems, Inc. 3 * 4 * This software is licensed under the GNU General License Version 2, 5 * June 1991 as shown in the file COPYING in the top-level directory of this 6 * source tree. 7 * 8 * THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" --- 21 unchanged lines hidden (view full) --- 30 * of all progs. 31 * RTNL lock cannot be taken when holding this lock. 32 */ 33static DECLARE_RWSEM(bpf_devs_lock); 34 35struct bpf_offload_dev { 36 const struct bpf_prog_offload_ops *ops; 37 struct list_head netdevs; | 1/* 2 * Copyright (C) 2017-2018 Netronome Systems, Inc. 3 * 4 * This software is licensed under the GNU General License Version 2, 5 * June 1991 as shown in the file COPYING in the top-level directory of this 6 * source tree. 7 * 8 * THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" --- 21 unchanged lines hidden (view full) --- 30 * of all progs. 31 * RTNL lock cannot be taken when holding this lock. 32 */ 33static DECLARE_RWSEM(bpf_devs_lock); 34 35struct bpf_offload_dev { 36 const struct bpf_prog_offload_ops *ops; 37 struct list_head netdevs; |
38 void *priv; |
|
38}; 39 40struct bpf_offload_netdev { 41 struct rhash_head l; 42 struct net_device *netdev; 43 struct bpf_offload_dev *offdev; 44 struct list_head progs; 45 struct list_head maps; --- 122 unchanged lines hidden (view full) --- 168 else 169 ret = 0; 170 } 171 up_read(&bpf_devs_lock); 172 173 return ret; 174} 175 | 39}; 40 41struct bpf_offload_netdev { 42 struct rhash_head l; 43 struct net_device *netdev; 44 struct bpf_offload_dev *offdev; 45 struct list_head progs; 46 struct list_head maps; --- 122 unchanged lines hidden (view full) --- 169 else 170 ret = 0; 171 } 172 up_read(&bpf_devs_lock); 173 174 return ret; 175} 176 |
177void 178bpf_prog_offload_replace_insn(struct bpf_verifier_env *env, u32 off, 179 struct bpf_insn *insn) 180{ 181 const struct bpf_prog_offload_ops *ops; 182 struct bpf_prog_offload *offload; 183 int ret = -EOPNOTSUPP; 184 185 down_read(&bpf_devs_lock); 186 offload = env->prog->aux->offload; 187 if (offload) { 188 ops = offload->offdev->ops; 189 if (!offload->opt_failed && ops->replace_insn) 190 ret = ops->replace_insn(env, off, insn); 191 offload->opt_failed |= ret; 192 } 193 up_read(&bpf_devs_lock); 194} 195 196void 197bpf_prog_offload_remove_insns(struct bpf_verifier_env *env, u32 off, u32 cnt) 198{ 199 struct bpf_prog_offload *offload; 200 int ret = -EOPNOTSUPP; 201 202 down_read(&bpf_devs_lock); 203 offload = env->prog->aux->offload; 204 if (offload) { 205 if (!offload->opt_failed && offload->offdev->ops->remove_insns) 206 ret = offload->offdev->ops->remove_insns(env, off, cnt); 207 offload->opt_failed |= ret; 208 } 209 up_read(&bpf_devs_lock); 210} 211 |
|
176static void __bpf_prog_offload_destroy(struct bpf_prog *prog) 177{ 178 struct bpf_prog_offload *offload = prog->aux->offload; 179 180 if (offload->dev_state) 181 offload->offdev->ops->destroy(prog); 182 183 /* Make sure BPF_PROG_GET_NEXT_ID can't find this dead program */ --- 445 unchanged lines hidden (view full) --- 629 WARN_ON(!list_empty(&ondev->maps)); 630 kfree(ondev); 631unlock: 632 up_write(&bpf_devs_lock); 633} 634EXPORT_SYMBOL_GPL(bpf_offload_dev_netdev_unregister); 635 636struct bpf_offload_dev * | 212static void __bpf_prog_offload_destroy(struct bpf_prog *prog) 213{ 214 struct bpf_prog_offload *offload = prog->aux->offload; 215 216 if (offload->dev_state) 217 offload->offdev->ops->destroy(prog); 218 219 /* Make sure BPF_PROG_GET_NEXT_ID can't find this dead program */ --- 445 unchanged lines hidden (view full) --- 665 WARN_ON(!list_empty(&ondev->maps)); 666 kfree(ondev); 667unlock: 668 up_write(&bpf_devs_lock); 669} 670EXPORT_SYMBOL_GPL(bpf_offload_dev_netdev_unregister); 671 672struct bpf_offload_dev * |
637bpf_offload_dev_create(const struct bpf_prog_offload_ops *ops) | 673bpf_offload_dev_create(const struct bpf_prog_offload_ops *ops, void *priv) |
638{ 639 struct bpf_offload_dev *offdev; 640 int err; 641 642 down_write(&bpf_devs_lock); 643 if (!offdevs_inited) { 644 err = rhashtable_init(&offdevs, &offdevs_params); 645 if (err) 646 return ERR_PTR(err); 647 offdevs_inited = true; 648 } 649 up_write(&bpf_devs_lock); 650 651 offdev = kzalloc(sizeof(*offdev), GFP_KERNEL); 652 if (!offdev) 653 return ERR_PTR(-ENOMEM); 654 655 offdev->ops = ops; | 674{ 675 struct bpf_offload_dev *offdev; 676 int err; 677 678 down_write(&bpf_devs_lock); 679 if (!offdevs_inited) { 680 err = rhashtable_init(&offdevs, &offdevs_params); 681 if (err) 682 return ERR_PTR(err); 683 offdevs_inited = true; 684 } 685 up_write(&bpf_devs_lock); 686 687 offdev = kzalloc(sizeof(*offdev), GFP_KERNEL); 688 if (!offdev) 689 return ERR_PTR(-ENOMEM); 690 691 offdev->ops = ops; |
692 offdev->priv = priv; |
|
656 INIT_LIST_HEAD(&offdev->netdevs); 657 658 return offdev; 659} 660EXPORT_SYMBOL_GPL(bpf_offload_dev_create); 661 662void bpf_offload_dev_destroy(struct bpf_offload_dev *offdev) 663{ 664 WARN_ON(!list_empty(&offdev->netdevs)); 665 kfree(offdev); 666} 667EXPORT_SYMBOL_GPL(bpf_offload_dev_destroy); | 693 INIT_LIST_HEAD(&offdev->netdevs); 694 695 return offdev; 696} 697EXPORT_SYMBOL_GPL(bpf_offload_dev_create); 698 699void bpf_offload_dev_destroy(struct bpf_offload_dev *offdev) 700{ 701 WARN_ON(!list_empty(&offdev->netdevs)); 702 kfree(offdev); 703} 704EXPORT_SYMBOL_GPL(bpf_offload_dev_destroy); |
705 706void *bpf_offload_dev_priv(struct bpf_offload_dev *offdev) 707{ 708 return offdev->priv; 709} 710EXPORT_SYMBOL_GPL(bpf_offload_dev_priv); |
|