Skip to content

Commit 74fc4f8

Browse files
elic307idavem330
authored andcommitted
net: Fix offloading indirect devices dependency on qdisc order creation
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>
1 parent c1c5cb3 commit 74fc4f8

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
@@ -453,6 +453,7 @@ struct flow_block_offload {
453453
struct list_head *driver_block_list;
454454
struct netlink_ext_ack *extack;
455455
struct Qdisc *sch;
456+
struct list_head *cb_list_head;
456457
};
457458

458459
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;
@@ -345,6 +346,33 @@ static struct flow_indr_dev *flow_indr_dev_alloc(flow_indr_block_bind_cb_t *cb,
345346
return indr_dev;
346347
}
347348

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

368396
list_add(&indr_dev->list, &flow_block_indr_dev_list);
397+
existing_qdiscs_register(cb, cb_priv);
369398
mutex_unlock(&flow_indr_block_lock);
370399

371400
return 0;
@@ -462,14 +491,72 @@ struct flow_block_cb *flow_indr_block_cb_alloc(flow_setup_cb_t *cb,
462491
}
463492
EXPORT_SYMBOL(flow_indr_block_cb_alloc);
464493

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

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

‎net/netfilter/nf_flow_table_offload.c‎

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

‎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)