public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next v3 0/4] flower: validate control flags
@ 2024-04-11 10:52 Asbjørn Sloth Tønnesen
  2024-04-11 10:52 ` [PATCH net-next v3 1/4] flow_offload: add control flag checking helpers Asbjørn Sloth Tønnesen
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Asbjørn Sloth Tønnesen @ 2024-04-11 10:52 UTC (permalink / raw)
  To: netdev
  Cc: Asbjørn Sloth Tønnesen, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-kernel, Louis Peens, Yanguo Li,
	oss-drivers, Taras Chornyi, Woojung Huh, UNGLinuxDriver,
	Andrew Lunn, Florian Fainelli, Vladimir Oltean, Edward Cree,
	Jamal Hadi Salim, Cong Wang, Jiri Pirko

I have reviewed the flower control flags code.
In all, but one (sfc), the flags field wasn't
checked properly for unsupported flags.

In this series I have only included a single example
user for each helper function. Once the helpers are in,
I will submit patches for all other drivers implementing
flower.

After which there will be:
- 6 drivers using flow_rule_is_supp_control_flags()
- 8 drivers using flow_rule_has_control_flags()
- 11 drivers using flow_rule_match_has_control_flags()

---
Changelog:

v3:
- Added Reviewed-by from Louis Peens (first two patches)
- Properly fixed kernel-doc format

v2: https://lore.kernel.org/netdev/20240410093235.5334-1-ast@fiberby.net/
- Squashed the 3 helper functions to one commmit (requested by Baowen Zheng)
- Renamed helper functions to avoid double negatives (suggested by Louis Peens)
- Reverse booleans in some functions and callsites to align with new names
- Fix autodoc format

v1: https://lore.kernel.org/netdev/20240408130927.78594-1-ast@fiberby.net/

Asbjørn Sloth Tønnesen (4):
  flow_offload: add control flag checking helpers
  nfp: flower: fix check for unsupported control flags
  net: prestera: flower: validate control flags
  net: dsa: microchip: ksz9477: flower: validate control flags

 drivers/net/dsa/microchip/ksz9477_tc_flower.c |  3 +
 .../marvell/prestera/prestera_flower.c        |  4 ++
 .../ethernet/netronome/nfp/flower/offload.c   |  6 +-
 include/net/flow_offload.h                    | 55 +++++++++++++++++++
 4 files changed, 65 insertions(+), 3 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH net-next v3 1/4] flow_offload: add control flag checking helpers
  2024-04-11 10:52 [PATCH net-next v3 0/4] flower: validate control flags Asbjørn Sloth Tønnesen
@ 2024-04-11 10:52 ` Asbjørn Sloth Tønnesen
  2024-04-11 10:52 ` [PATCH net-next v3 2/4] nfp: flower: fix check for unsupported control flags Asbjørn Sloth Tønnesen
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Asbjørn Sloth Tønnesen @ 2024-04-11 10:52 UTC (permalink / raw)
  To: netdev
  Cc: Asbjørn Sloth Tønnesen, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-kernel, Louis Peens, Yanguo Li,
	oss-drivers, Taras Chornyi, Woojung Huh, UNGLinuxDriver,
	Andrew Lunn, Florian Fainelli, Vladimir Oltean, Edward Cree,
	Jamal Hadi Salim, Cong Wang, Jiri Pirko

These helpers aim to help drivers, with checking
for the presence of unsupported control flags.

For drivers supporting at least one control flag:
  flow_rule_is_supp_control_flags()

For drivers using flow_rule_match_control(), but not using flags:
  flow_rule_has_control_flags()

For drivers not using flow_rule_match_control():
  flow_rule_match_has_control_flags()

While primarily aimed at FLOW_DISSECTOR_KEY_CONTROL
and flow_rule_match_control(), then the first two
can also be used with FLOW_DISSECTOR_KEY_ENC_CONTROL
and flow_rule_match_enc_control().

These helpers mirrors the existing check done in sfc:
  drivers/net/ethernet/sfc/tc.c +276

Only compile-tested.

Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
Reviewed-by: Louis Peens <louis.peens@corigine.com>
---
 include/net/flow_offload.h | 55 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)

diff --git a/include/net/flow_offload.h b/include/net/flow_offload.h
index 314087a5e1818..0e3d3dc332e47 100644
--- a/include/net/flow_offload.h
+++ b/include/net/flow_offload.h
@@ -449,6 +449,61 @@ static inline bool flow_rule_match_key(const struct flow_rule *rule,
 	return dissector_uses_key(rule->match.dissector, key);
 }
 
+/**
+ * flow_rule_is_supp_control_flags() - check for supported control flags
+ * @supp_flags: control flags supported by driver
+ * @ctrl_flags: control flags present in rule
+ * @extack: The netlink extended ACK for reporting errors.
+ *
+ * Return: true if only supported control flags are set, false otherwise.
+ */
+static inline bool flow_rule_is_supp_control_flags(const u32 supp_flags,
+						   const u32 ctrl_flags,
+						   struct netlink_ext_ack *extack)
+{
+	if (likely((ctrl_flags & ~supp_flags) == 0))
+		return true;
+
+	NL_SET_ERR_MSG_FMT_MOD(extack,
+			       "Unsupported match on control.flags %#x",
+			       ctrl_flags);
+
+	return false;
+}
+
+/**
+ * flow_rule_has_control_flags() - check for presence of any control flags
+ * @ctrl_flags: control flags present in rule
+ * @extack: The netlink extended ACK for reporting errors.
+ *
+ * Return: true if control flags are set, false otherwise.
+ */
+static inline bool flow_rule_has_control_flags(const u32 ctrl_flags,
+					       struct netlink_ext_ack *extack)
+{
+	return !flow_rule_is_supp_control_flags(0, ctrl_flags, extack);
+}
+
+/**
+ * flow_rule_match_has_control_flags() - match and check for any control flags
+ * @rule: The flow_rule under evaluation.
+ * @extack: The netlink extended ACK for reporting errors.
+ *
+ * Return: true if control flags are set, false otherwise.
+ */
+static inline bool flow_rule_match_has_control_flags(struct flow_rule *rule,
+						     struct netlink_ext_ack *extack)
+{
+	struct flow_match_control match;
+
+	if (!flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_CONTROL))
+		return false;
+
+	flow_rule_match_control(rule, &match);
+
+	return flow_rule_has_control_flags(match.mask->flags, extack);
+}
+
 struct flow_stats {
 	u64	pkts;
 	u64	bytes;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next v3 2/4] nfp: flower: fix check for unsupported control flags
  2024-04-11 10:52 [PATCH net-next v3 0/4] flower: validate control flags Asbjørn Sloth Tønnesen
  2024-04-11 10:52 ` [PATCH net-next v3 1/4] flow_offload: add control flag checking helpers Asbjørn Sloth Tønnesen
@ 2024-04-11 10:52 ` Asbjørn Sloth Tønnesen
  2024-04-11 10:52 ` [PATCH net-next v3 3/4] net: prestera: flower: validate " Asbjørn Sloth Tønnesen
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Asbjørn Sloth Tønnesen @ 2024-04-11 10:52 UTC (permalink / raw)
  To: netdev
  Cc: Asbjørn Sloth Tønnesen, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-kernel, Louis Peens, Yanguo Li,
	oss-drivers, Taras Chornyi, Woojung Huh, UNGLinuxDriver,
	Andrew Lunn, Florian Fainelli, Vladimir Oltean, Edward Cree,
	Jamal Hadi Salim, Cong Wang, Jiri Pirko

Use flow_rule_is_supp_control_flags()

Check the mask, not the key, for unsupported control flags.

Only compile-tested, no access to HW

Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
Reviewed-by: Louis Peens <louis.peens@corigine.com>
---
 drivers/net/ethernet/netronome/nfp/flower/offload.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/flower/offload.c b/drivers/net/ethernet/netronome/nfp/flower/offload.c
index 0aceef9fe5826..8e0a890381b60 100644
--- a/drivers/net/ethernet/netronome/nfp/flower/offload.c
+++ b/drivers/net/ethernet/netronome/nfp/flower/offload.c
@@ -527,10 +527,10 @@ nfp_flower_calculate_key_layers(struct nfp_app *app,
 		struct flow_match_control ctl;
 
 		flow_rule_match_control(rule, &ctl);
-		if (ctl.key->flags & ~NFP_FLOWER_SUPPORTED_CTLFLAGS) {
-			NL_SET_ERR_MSG_MOD(extack, "unsupported offload: match on unknown control flag");
+
+		if (!flow_rule_is_supp_control_flags(NFP_FLOWER_SUPPORTED_CTLFLAGS,
+						     ctl.mask->flags, extack))
 			return -EOPNOTSUPP;
-		}
 	}
 
 	ret_key_ls->key_layer = key_layer;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next v3 3/4] net: prestera: flower: validate control flags
  2024-04-11 10:52 [PATCH net-next v3 0/4] flower: validate control flags Asbjørn Sloth Tønnesen
  2024-04-11 10:52 ` [PATCH net-next v3 1/4] flow_offload: add control flag checking helpers Asbjørn Sloth Tønnesen
  2024-04-11 10:52 ` [PATCH net-next v3 2/4] nfp: flower: fix check for unsupported control flags Asbjørn Sloth Tønnesen
@ 2024-04-11 10:52 ` Asbjørn Sloth Tønnesen
  2024-04-11 10:52 ` [PATCH net-next v3 4/4] net: dsa: microchip: ksz9477: " Asbjørn Sloth Tønnesen
  2024-04-15  9:40 ` [PATCH net-next v3 0/4] " patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Asbjørn Sloth Tønnesen @ 2024-04-11 10:52 UTC (permalink / raw)
  To: netdev
  Cc: Asbjørn Sloth Tønnesen, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-kernel, Louis Peens, Yanguo Li,
	oss-drivers, Taras Chornyi, Woojung Huh, UNGLinuxDriver,
	Andrew Lunn, Florian Fainelli, Vladimir Oltean, Edward Cree,
	Jamal Hadi Salim, Cong Wang, Jiri Pirko

Add check for unsupported control flags.

Only compile-tested, no access to HW.

Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
---
 drivers/net/ethernet/marvell/prestera/prestera_flower.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/net/ethernet/marvell/prestera/prestera_flower.c b/drivers/net/ethernet/marvell/prestera/prestera_flower.c
index 8b9455d8a4f7a..418101a931490 100644
--- a/drivers/net/ethernet/marvell/prestera/prestera_flower.c
+++ b/drivers/net/ethernet/marvell/prestera/prestera_flower.c
@@ -229,6 +229,10 @@ static int prestera_flower_parse(struct prestera_flow_block *block,
 
 		flow_rule_match_control(f_rule, &match);
 		addr_type = match.key->addr_type;
+
+		if (flow_rule_has_control_flags(match.mask->flags,
+						f->common.extack))
+			return -EOPNOTSUPP;
 	}
 
 	if (flow_rule_match_key(f_rule, FLOW_DISSECTOR_KEY_BASIC)) {
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH net-next v3 4/4] net: dsa: microchip: ksz9477: flower: validate control flags
  2024-04-11 10:52 [PATCH net-next v3 0/4] flower: validate control flags Asbjørn Sloth Tønnesen
                   ` (2 preceding siblings ...)
  2024-04-11 10:52 ` [PATCH net-next v3 3/4] net: prestera: flower: validate " Asbjørn Sloth Tønnesen
@ 2024-04-11 10:52 ` Asbjørn Sloth Tønnesen
  2024-04-15  9:40 ` [PATCH net-next v3 0/4] " patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: Asbjørn Sloth Tønnesen @ 2024-04-11 10:52 UTC (permalink / raw)
  To: netdev
  Cc: Asbjørn Sloth Tønnesen, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, linux-kernel, Louis Peens, Yanguo Li,
	oss-drivers, Taras Chornyi, Woojung Huh, UNGLinuxDriver,
	Andrew Lunn, Florian Fainelli, Vladimir Oltean, Edward Cree,
	Jamal Hadi Salim, Cong Wang, Jiri Pirko

Add check for unsupported control flags.

Only compile-tested, no access to HW.

Signed-off-by: Asbjørn Sloth Tønnesen <ast@fiberby.net>
---
 drivers/net/dsa/microchip/ksz9477_tc_flower.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz9477_tc_flower.c b/drivers/net/dsa/microchip/ksz9477_tc_flower.c
index 8b2f5be667e01..ca7830ab168ac 100644
--- a/drivers/net/dsa/microchip/ksz9477_tc_flower.c
+++ b/drivers/net/dsa/microchip/ksz9477_tc_flower.c
@@ -124,6 +124,9 @@ static int ksz9477_flower_parse_key(struct ksz_device *dev, int port,
 		return -EOPNOTSUPP;
 	}
 
+	if (flow_rule_match_has_control_flags(rule, extack))
+		return -EOPNOTSUPP;
+
 	if (flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_BASIC) ||
 	    flow_rule_match_key(rule, FLOW_DISSECTOR_KEY_ETH_ADDRS)) {
 		ret = ksz9477_flower_parse_key_l2(dev, port, extack, rule,
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH net-next v3 0/4] flower: validate control flags
  2024-04-11 10:52 [PATCH net-next v3 0/4] flower: validate control flags Asbjørn Sloth Tønnesen
                   ` (3 preceding siblings ...)
  2024-04-11 10:52 ` [PATCH net-next v3 4/4] net: dsa: microchip: ksz9477: " Asbjørn Sloth Tønnesen
@ 2024-04-15  9:40 ` patchwork-bot+netdevbpf
  4 siblings, 0 replies; 6+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-04-15  9:40 UTC (permalink / raw)
  To: =?utf-8?b?QXNiasO4cm4gU2xvdGggVMO4bm5lc2VuIDxhc3RAZmliZXJieS5uZXQ+?=
  Cc: netdev, davem, edumazet, kuba, pabeni, linux-kernel, louis.peens,
	yanguo.li, oss-drivers, taras.chornyi, woojung.huh,
	UNGLinuxDriver, andrew, f.fainelli, olteanv, ecree.xilinx, jhs,
	xiyou.wangcong, jiri

Hello:

This series was applied to netdev/net-next.git (main)
by David S. Miller <davem@davemloft.net>:

On Thu, 11 Apr 2024 10:52:53 +0000 you wrote:
> I have reviewed the flower control flags code.
> In all, but one (sfc), the flags field wasn't
> checked properly for unsupported flags.
> 
> In this series I have only included a single example
> user for each helper function. Once the helpers are in,
> I will submit patches for all other drivers implementing
> flower.
> 
> [...]

Here is the summary with links:
  - [net-next,v3,1/4] flow_offload: add control flag checking helpers
    https://git.kernel.org/netdev/net-next/c/d11e63119432
  - [net-next,v3,2/4] nfp: flower: fix check for unsupported control flags
    https://git.kernel.org/netdev/net-next/c/e36245dacd2c
  - [net-next,v3,3/4] net: prestera: flower: validate control flags
    https://git.kernel.org/netdev/net-next/c/f8a5ea8c2a7f
  - [net-next,v3,4/4] net: dsa: microchip: ksz9477: flower: validate control flags
    https://git.kernel.org/netdev/net-next/c/d9a1249e715b

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-04-15  9:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-11 10:52 [PATCH net-next v3 0/4] flower: validate control flags Asbjørn Sloth Tønnesen
2024-04-11 10:52 ` [PATCH net-next v3 1/4] flow_offload: add control flag checking helpers Asbjørn Sloth Tønnesen
2024-04-11 10:52 ` [PATCH net-next v3 2/4] nfp: flower: fix check for unsupported control flags Asbjørn Sloth Tønnesen
2024-04-11 10:52 ` [PATCH net-next v3 3/4] net: prestera: flower: validate " Asbjørn Sloth Tønnesen
2024-04-11 10:52 ` [PATCH net-next v3 4/4] net: dsa: microchip: ksz9477: " Asbjørn Sloth Tønnesen
2024-04-15  9:40 ` [PATCH net-next v3 0/4] " patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox