* [PATCH net] cxgb4: consider EtherType when validating filter priority ordering
@ 2026-07-08 13:16 Harshita V Rajput
0 siblings, 0 replies; only message in thread
From: Harshita V Rajput @ 2026-07-08 13:16 UTC (permalink / raw)
To: netdev; +Cc: davem, kuba, edumazet, pabeni, andrew+netdev, bharat,
harshitha.vr
cxgb4_filter_prio_in_range() currently validates the priority
ordering of adjacent filters based only on tc_prio. This can
incorrectly reject insertion of a new filter when an existing
filter with a higher priority matches a different EtherType.
For example:
- An LLDP filter (pref 4) blocks IPv4 (pref 2) and IPv6 (pref 3)
filters from being added.
- An IPv6 filter (pref 3) blocks an IPv4 (pref 2) filter from being
added.
In both cases the filters match different EtherTypes, so they could
never have matched the same packet anyway.
Fix this by considering both tc_prio and the matched EtherType. A
neighbouring filter only blocks the new filter if it has no specific
EtherType set, or its EtherType is the same as the new filter's.
Filters with different EtherTypes are now allowed regardless of
priority order. Filters with the same EtherType still follow the
original strict priority check, since they really can overlap.
Fixes: 41ec03e534ca ("cxgb4: check rule prio conflicts before offload")
Signed-off-by: Harshita V Rajput <harshitha.vr@chelsio.com>
Signed-off-by: Potnuri Bharat Teja <bharat@chelsio.com>
---
.../net/ethernet/chelsio/cxgb4/cxgb4_filter.c | 19 ++++++++++++++-----
.../ethernet/chelsio/cxgb4/cxgb4_tc_flower.c | 4 ++--
.../chelsio/cxgb4/cxgb4_tc_matchall.c | 2 +-
.../net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c | 2 +-
.../net/ethernet/chelsio/cxgb4/cxgb4_uld.h | 2 +-
5 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c
index 657d96b9e2f6..8462455d9330 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_filter.c
@@ -443,7 +443,7 @@ int cxgb4_get_filter_counters(struct net_device *dev, unsigned int fidx,
}
static bool cxgb4_filter_prio_in_range(struct tid_info *t, u32 idx, u8 nslots,
- u32 prio)
+ u32 prio, u32 ethtype)
{
struct filter_entry *prev_tab, *next_tab, *prev_fe, *next_fe;
u32 prev_ftid, next_ftid;
@@ -536,15 +536,24 @@ static bool cxgb4_filter_prio_in_range(struct tid_info *t, u32 idx, u8 nslots,
if (!prev_fe->fs.type)
prev_fe = &prev_tab[prev_ftid];
- if ((prev_fe->valid && prev_fe->fs.tc_prio > prio) ||
- (next_fe->valid && next_fe->fs.tc_prio < prio))
+ /* Filters with different EtherTypes can never match the same
+ * packet, so skip the priority check between them.
+ */
+ if (prev_fe->valid && prev_fe->fs.tc_prio > prio &&
+ (!prev_fe->fs.mask.ethtype || !ethtype ||
+ prev_fe->fs.val.ethtype == ethtype))
+ return false;
+
+ if (next_fe->valid && next_fe->fs.tc_prio < prio &&
+ (!next_fe->fs.mask.ethtype || !ethtype ||
+ next_fe->fs.val.ethtype == ethtype))
return false;
return true;
}
int cxgb4_get_free_ftid(struct net_device *dev, u8 family, bool hash_en,
- u32 tc_prio)
+ u32 tc_prio, u32 ethtype)
{
struct adapter *adap = netdev2adap(dev);
struct tid_info *t = &adap->tids;
@@ -671,7 +680,7 @@ int cxgb4_get_free_ftid(struct net_device *dev, u8 family, bool hash_en,
* with existing rules.
*/
if (cxgb4_filter_prio_in_range(t, ftid, n,
- tc_prio)) {
+ tc_prio, ethtype)) {
ftid &= ~(n - 1);
found = true;
break;
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c
index 41a2998ee2a0..754d9f5f0fe0 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_flower.c
@@ -911,8 +911,8 @@ int cxgb4_flow_rule_replace(struct net_device *dev, struct flow_rule *rule,
* rule. Only insert rule if its prio doesn't conflict with
* existing rules.
*/
- fidx = cxgb4_get_free_ftid(dev, inet_family, fs->hash,
- tc_prio);
+ fidx = cxgb4_get_free_ftid(dev, inet_family, fs->hash, tc_prio,
+ fs->mask.ethtype ? fs->val.ethtype : 0);
if (fidx < 0) {
NL_SET_ERR_MSG_MOD(extack,
"No free LETCAM index available");
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_matchall.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_matchall.c
index bc290430245e..bab263785082 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_matchall.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_matchall.c
@@ -312,7 +312,7 @@ static int cxgb4_matchall_add_filter(struct net_device *dev,
* existing rules.
*/
fidx = cxgb4_get_free_ftid(dev, filter_type ? PF_INET6 : PF_INET,
- false, cls->common.prio);
+ false, cls->common.prio, 0);
if (fidx < 0) {
NL_SET_ERR_MSG_MOD(extack,
"No free LETCAM index available");
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c
index 1c1a7bc5a896..37a878f07f91 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_tc_u32.c
@@ -174,7 +174,7 @@ int cxgb4_config_knode(struct net_device *dev, struct tc_cls_u32_offload *cls)
* existing rules.
*/
filter_id = cxgb4_get_free_ftid(dev, inet_family, false,
- TC_U32_NODE(cls->knode.handle));
+ TC_U32_NODE(cls->knode.handle), 0);
if (filter_id < 0) {
NL_SET_ERR_MSG_MOD(extack,
"No free LETCAM index available");
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h
index d7713038386c..42efc239df88 100644
--- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h
+++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_uld.h
@@ -282,7 +282,7 @@ struct chcr_ktls {
struct ch_filter_specification;
int cxgb4_get_free_ftid(struct net_device *dev, u8 family, bool hash_en,
- u32 tc_prio);
+ u32 tc_prio, u32 ethtype);
int __cxgb4_set_filter(struct net_device *dev, int filter_id,
struct ch_filter_specification *fs,
struct filter_ctx *ctx);
--
2.43.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-07-08 13:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-08 13:16 [PATCH net] cxgb4: consider EtherType when validating filter priority ordering Harshita V Rajput
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox