Skip to content

Commit 6628eef

Browse files
elic307igregkh
authored andcommitted
net: Fix offloading indirect devices dependency on qdisc order creation
[ Upstream commit 74fc4f8 ] Currently, when creating an ingress qdisc on an indirect device before the driver registered for callbacks, the driver will not have a chance to register its filter configuration callbacks. To fix that, modify the code such that it keeps track of all the ingress qdiscs that call flow_indr_dev_setup_offload(). When a driver calls flow_indr_dev_register(), go through the list of tracked ingress qdiscs and call the driver callback entry point so as to give it a chance to register its callback. Reviewed-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Eli Cohen <elic@nvidia.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 881d24d commit 6628eef

5 files changed

Lines changed: 92 additions & 1 deletion

File tree

‎include/net/flow_offload.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ struct flow_block_offload {
451451
struct list_head *driver_block_list;
452452
struct netlink_ext_ack *extack;
453453
struct Qdisc *sch;
454+
struct list_head *cb_list_head;
454455
};
455456

456457
enum tc_setup_type;

‎net/core/flow_offload.c‎

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ EXPORT_SYMBOL(flow_block_cb_setup_simple);
321321
static DEFINE_MUTEX(flow_indr_block_lock);
322322
static LIST_HEAD(flow_block_indr_list);
323323
static LIST_HEAD(flow_block_indr_dev_list);
324+
static LIST_HEAD(flow_indir_dev_list);
324325

325326
struct flow_indr_dev {
326327
struct list_head list;
@@ -346,6 +347,33 @@ static struct flow_indr_dev *flow_indr_dev_alloc(flow_indr_block_bind_cb_t *cb,
346347
return indr_dev;
347348
}
348349

350+
struct flow_indir_dev_info {
351+
void *data;
352+
struct net_device *dev;
353+
struct Qdisc *sch;
354+
enum tc_setup_type type;
355+
void (*cleanup)(struct flow_block_cb *block_cb);
356+
struct list_head list;
357+
enum flow_block_command command;
358+
enum flow_block_binder_type binder_type;
359+
struct list_head *cb_list;
360+
};
361+
362+
static void existing_qdiscs_register(flow_indr_block_bind_cb_t *cb, void *cb_priv)
363+
{
364+
struct flow_block_offload bo;
365+
struct flow_indir_dev_info *cur;
366+
367+
list_for_each_entry(cur, &flow_indir_dev_list, list) {
368+
memset(&bo, 0, sizeof(bo));
369+
bo.command = cur->command;
370+
bo.binder_type = cur->binder_type;
371+
INIT_LIST_HEAD(&bo.cb_list);
372+
cb(cur->dev, cur->sch, cb_priv, cur->type, &bo, cur->data, cur->cleanup);
373+
list_splice(&bo.cb_list, cur->cb_list);
374+
}
375+
}
376+
349377
int flow_indr_dev_register(flow_indr_block_bind_cb_t *cb, void *cb_priv)
350378
{
351379
struct flow_indr_dev *indr_dev;
@@ -367,6 +395,7 @@ int flow_indr_dev_register(flow_indr_block_bind_cb_t *cb, void *cb_priv)
367395
}
368396

369397
list_add(&indr_dev->list, &flow_block_indr_dev_list);
398+
existing_qdiscs_register(cb, cb_priv);
370399
mutex_unlock(&flow_indr_block_lock);
371400

372401
return 0;
@@ -463,14 +492,72 @@ struct flow_block_cb *flow_indr_block_cb_alloc(flow_setup_cb_t *cb,
463492
}
464493
EXPORT_SYMBOL(flow_indr_block_cb_alloc);
465494

466-
int flow_indr_dev_setup_offload(struct net_device *dev, struct Qdisc *sch,
495+
static struct flow_indir_dev_info *find_indir_dev(void *data)
496+
{
497+
struct flow_indir_dev_info *cur;
498+
499+
list_for_each_entry(cur, &flow_indir_dev_list, list) {
500+
if (cur->data == data)
501+
return cur;
502+
}
503+
return NULL;
504+
}
505+
506+
static int indir_dev_add(void *data, struct net_device *dev, struct Qdisc *sch,
507+
enum tc_setup_type type, void (*cleanup)(struct flow_block_cb *block_cb),
508+
struct flow_block_offload *bo)
509+
{
510+
struct flow_indir_dev_info *info;
511+
512+
info = find_indir_dev(data);
513+
if (info)
514+
return -EEXIST;
515+
516+
info = kzalloc(sizeof(*info), GFP_KERNEL);
517+
if (!info)
518+
return -ENOMEM;
519+
520+
info->data = data;
521+
info->dev = dev;
522+
info->sch = sch;
523+
info->type = type;
524+
info->cleanup = cleanup;
525+
info->command = bo->command;
526+
info->binder_type = bo->binder_type;
527+
info->cb_list = bo->cb_list_head;
528+
529+
list_add(&info->list, &flow_indir_dev_list);
530+
return 0;
531+
}
532+
533+
static int indir_dev_remove(void *data)
534+
{
535+
struct flow_indir_dev_info *info;
536+
537+
info = find_indir_dev(data);
538+
if (!info)
539+
return -ENOENT;
540+
541+
list_del(&info->list);
542+
543+
kfree(info);
544+
return 0;
545+
}
546+
547+
int flow_indr_dev_setup_offload(struct net_device *dev, struct Qdisc *sch,
467548
enum tc_setup_type type, void *data,
468549
struct flow_block_offload *bo,
469550
void (*cleanup)(struct flow_block_cb *block_cb))
470551
{
471552
struct flow_indr_dev *this;
472553

473554
mutex_lock(&flow_indr_block_lock);
555+
556+
if (bo->command == FLOW_BLOCK_BIND)
557+
indir_dev_add(data, dev, sch, type, cleanup, bo);
558+
else if (bo->command == FLOW_BLOCK_UNBIND)
559+
indir_dev_remove(data);
560+
474561
list_for_each_entry(this, &flow_block_indr_dev_list, list)
475562
this->cb(dev, sch, this->cb_priv, type, bo, data, cleanup);
476563

‎net/netfilter/nf_flow_table_offload.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,6 +1097,7 @@ static void nf_flow_table_block_offload_init(struct flow_block_offload *bo,
10971097
bo->command = cmd;
10981098
bo->binder_type = FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS;
10991099
bo->extack = extack;
1100+
bo->cb_list_head = &flowtable->flow_block.cb_list;
11001101
INIT_LIST_HEAD(&bo->cb_list);
11011102
}
11021103

‎net/netfilter/nf_tables_offload.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ static void nft_flow_block_offload_init(struct flow_block_offload *bo,
353353
bo->command = cmd;
354354
bo->binder_type = FLOW_BLOCK_BINDER_TYPE_CLSACT_INGRESS;
355355
bo->extack = extack;
356+
bo->cb_list_head = &basechain->flow_block.cb_list;
356357
INIT_LIST_HEAD(&bo->cb_list);
357358
}
358359

‎net/sched/cls_api.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@ static void tcf_block_offload_init(struct flow_block_offload *bo,
634634
bo->block_shared = shared;
635635
bo->extack = extack;
636636
bo->sch = sch;
637+
bo->cb_list_head = &flow_block->cb_list;
637638
INIT_LIST_HEAD(&bo->cb_list);
638639
}
639640

0 commit comments

Comments
 (0)