Skip to content

Commit ce197d8

Browse files
tohojoAlexei Starovoitov
authored andcommitted
xdp: Handle device unregister for devmap_hash map type
It seems I forgot to add handling of devmap_hash type maps to the device unregister hook for devmaps. This omission causes devices to not be properly released, which causes hangs. Fix this by adding the missing handler. Fixes: 6f9d451 ("xdp: Add devmap_hash map type for looking up devices by hashed index") Reported-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Martin KaFai Lau <kafai@fb.com> Link: https://lore.kernel.org/bpf/20191019111931.2981954-1-toke@redhat.com
1 parent 05679ca commit ce197d8

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

‎kernel/bpf/devmap.c‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,32 @@ const struct bpf_map_ops dev_map_hash_ops = {
719719
.map_check_btf = map_check_no_btf,
720720
};
721721

722+
static void dev_map_hash_remove_netdev(struct bpf_dtab *dtab,
723+
struct net_device *netdev)
724+
{
725+
unsigned long flags;
726+
u32 i;
727+
728+
spin_lock_irqsave(&dtab->index_lock, flags);
729+
for (i = 0; i < dtab->n_buckets; i++) {
730+
struct bpf_dtab_netdev *dev;
731+
struct hlist_head *head;
732+
struct hlist_node *next;
733+
734+
head = dev_map_index_hash(dtab, i);
735+
736+
hlist_for_each_entry_safe(dev, next, head, index_hlist) {
737+
if (netdev != dev->dev)
738+
continue;
739+
740+
dtab->items--;
741+
hlist_del_rcu(&dev->index_hlist);
742+
call_rcu(&dev->rcu, __dev_map_entry_free);
743+
}
744+
}
745+
spin_unlock_irqrestore(&dtab->index_lock, flags);
746+
}
747+
722748
static int dev_map_notification(struct notifier_block *notifier,
723749
ulong event, void *ptr)
724750
{
@@ -735,6 +761,11 @@ static int dev_map_notification(struct notifier_block *notifier,
735761
*/
736762
rcu_read_lock();
737763
list_for_each_entry_rcu(dtab, &dev_map_list, list) {
764+
if (dtab->map.map_type == BPF_MAP_TYPE_DEVMAP_HASH) {
765+
dev_map_hash_remove_netdev(dtab, netdev);
766+
continue;
767+
}
768+
738769
for (i = 0; i < dtab->map.max_entries; i++) {
739770
struct bpf_dtab_netdev *dev, *odev;
740771

0 commit comments

Comments
 (0)