Add flow tag support to flow specification
Subsystems (4)
cover Add flow tag support to flow specification
Hi Doug,
The flow tag feature allows an application to request to add an action to tag all the packets that matches this rule.
The tag is a number that will came as a metadata with every packet in the CQE.
The tag rule == 0 is chosen as the default tag and application can use it in order to avoid the need to classify the packets that came with a tag while continuing to benefit from this tag mechanism.
struct definition:
struct ib_uverbs_flow_spec_action_tag {
union {
struct ib_uverbs_flow_spec_hdr hdr;
struct {
__u32 type;
__u16 size;
__u16 reserved;
};
};
__be32 tag_id;
__u32 reserved1;
};struct ib_uverbs_flow_spec {
union {
union {
struct ib_uverbs_flow_spec_hdr hdr;
struct {
__u32 type;
__u16 size;
__u16 reserved;
};
};
struct ib_uverbs_flow_spec_eth eth;
struct ib_uverbs_flow_spec_ipv4 ipv4;
struct ib_uverbs_flow_spec_tcp_udp tcp_udp;
struct ib_uverbs_flow_spec_ipv6 ipv6;
struct ib_uverbs_flow_spec_action_tag flow_tag;
};
};Where:
* type, size, reserved fields are identical to the rest of the
* protocols,
and are used to identify the spec.
* flow_tag is a spec of type 'action'
* the ib_uverbs_flow_spec_hdr is identical to the rest of the specs.
* tag_id - is the value of the stream defined by the specs.
Thanks,
Moses
CC: Rony Efraim <ronye-VPRAkNaXOzVWk0Htik3J/[email protected]>
----
Doug,
I used this opportunity and fixed parse_flow_attr(..) return values. Adjusting this fix to this series minimizes chances of possible merge conflicts between different series.
This patchset was generated against commitf502d834950a ("net/mlx5: Activate support for 4K UARs") and it applies cleanly on k.o/for-4.11 branch.
Available in the "topic/flow-tag" topic branch of this git repo:git://git.kernel.org/pub/scm/linux/kernel/git/leon/linux-rdma.git
Or for browsing:
https://git.kernel.org/cgit/linux/kernel/git/leon/linux-rdma.git/log/?h=topic/flow-tag
Leon Romanovsky (1):
IB/mlx5: Replace ENOTSUPP usage with EOPNOTSUPP
Maor Gottlieb (1):
net/mlx5: Consolidate flow rules regardless their flow tag
Moses Reuben (3):
IB/core: Introduce flow tag specification
IB/uverbs: Add support for flow tag
IB/mlx5: Add flow tag support
drivers/infiniband/core/uverbs.h | 1 + drivers/infiniband/core/uverbs_cmd.c | 35 +++++++++++++++++++-- drivers/infiniband/hw/mlx5/main.c | 38 +++++++++++++++++------ drivers/net/ethernet/mellanox/mlx5/core/fs_core.c | 12 +++++-- include/rdma/ib_verbs.h | 9 ++++++ include/uapi/rdma/ib_user_verbs.h | 13 ++++++++ 6 files changed, 95 insertions(+), 13 deletions(-)
--
2.10.2
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 20170118125951.3469-1-leon-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org
PATCH 1/5 net/mlx5: Consolidate flow rules regardless their flow tag
From: Maor Gottlieb <maorg-VPRAkNaXOzVWk0Htik3J/[email protected]>
Flow rules with same match criteria and value should be mapped to the same flow table entry regardless the flow tag identifier.
Flow tag is part of flow table entry context and not of the destination, therefore we should return error when we try to add destination to flow table entry with different flow tag.
--- drivers/net/ethernet/mellanox/mlx5/core/fs_core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlx5/core/fs_core.c +10 -2
@@ -1232,10 +1232,18 @@ static struct mlx5_flow_handle *add_rule_fg(struct mlx5_flow_group *fg,fs_for_each_fte (fte, fg) {nested_lock_ref_node (&fte->node,FS_MUTEX_CHILD );if (compare_match_value (&fg->mask, match_value, &fte->val) && - (flow_act->action & fte->action) && - flow_act->flow_tag == fte->flow_tag) { + (flow_act->action & fte->action)) {int old_action = fte->action; +if (fte->flow_tag != flow_act->flow_tag) { +mlx5_core_warn (get_dev (&fte->node), +"FTE flow tag %u already exists with different flow tag %u\n" , + fte->flow_tag, + flow_act->flow_tag); + handle =ERR_PTR (-EEXIST ); + goto unlock_fte; + } + fte->action |= flow_act->action; handle =add_rule_fte (fte, fg, dest, dest_num, old_action != flow_act->action);
Signature · 6 lines
2.10.2 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 2/5 IB/core: Introduce flow tag specification
In reply to a message not in the archiveFrom: Moses Reuben <mosesr-VPRAkNaXOzVWk0Htik3J/[email protected]>
This specification identifies flow with a specific tag-id. This tag-id will be reported in the CQE.
--- include/rdma/ib_verbs.h | 9 +++++++++ 1 file changed, 9 insertions(+)
include/rdma/ib_verbs.h +9 -0
@@ -1604,6 +1604,8 @@ enum ib_flow_spec_type {IB_FLOW_SPEC_UDP =0x41 ,IB_FLOW_SPEC_VXLAN_TUNNEL =0x50 ,IB_FLOW_SPEC_INNER =0x100 , +/* Actions */ + IB_FLOW_SPEC_ACTION_TAG = 0x1000, };#define IB_FLOW_SPEC_LAYER_MASK 0xF0#define IB_FLOW_SPEC_SUPPORT_LAYERS 8
@@ -1726,6 +1728,12 @@ struct ib_flow_spec_tunnel {struct ib_flow_tunnel_filter mask; }; +struct ib_flow_spec_action_tag { +enum ib_flow_spec_type type; +u16 size; +u32 tag_id; +}; + union ib_flow_spec { struct { u32 type;
@@ -1737,6 +1745,7 @@ union ib_flow_spec {struct ib_flow_spec_tcp_udp tcp_udp;struct ib_flow_spec_ipv6 ipv6;struct ib_flow_spec_tunnel tunnel; +struct ib_flow_spec_action_tag flow_tag; };struct ib_flow_attr {
Signature · 6 lines
2.10.2 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/5 IB/uverbs: Add support for flow tag
In reply to a message not in the archiveFrom: Moses Reuben <mosesr-VPRAkNaXOzVWk0Htik3J/[email protected]>
The struct ib_uverbs_flow_spec_action_tag associates a tag_id with the flow defined by any number of other flow_spec entries which can reference L2, L3, and L4 packet contents.
Use of ib_uverbs_flow_spec_action_tag allows the consumer to identify the set of rules which where matched by
the packet by examining the tag_id in the CQE.
--- drivers/infiniband/core/uverbs.h | 1 + drivers/infiniband/core/uverbs_cmd.c | 35 +++++++++++++++++++++++++++++++++-- include/uapi/rdma/ib_user_verbs.h | 13 +++++++++++++ 3 files changed, 47 insertions(+), 2 deletions(-)
drivers/infiniband/core/uverbs.h +1 -0
@@ -228,6 +228,7 @@ struct ib_uverbs_flow_spec {struct ib_uverbs_flow_spec_ipv4 ipv4;struct ib_uverbs_flow_spec_tcp_udp tcp_udp;struct ib_uverbs_flow_spec_ipv6 ipv6; +struct ib_uverbs_flow_spec_action_tag flow_tag; }; };
drivers/infiniband/core/uverbs_cmd.c +33 -2
@@ -3143,6 +3143,25 @@ ssize_t ib_uverbs_detach_mcast(struct ib_uverbs_file *file,return ret ? ret : in_len; } +static int kern_spec_to_ib_spec_action (struct ib_uverbs_flow_spec *kern_spec, +union ib_flow_spec *ib_spec) +{ + ib_spec->type = kern_spec->type; +switch (ib_spec->type) { +case IB_FLOW_SPEC_ACTION_TAG : +if (kern_spec->flow_tag.size != +sizeof (struct ib_uverbs_flow_spec_action_tag )) +return -EINVAL ; + + ib_spec->flow_tag.size =sizeof (struct ib_flow_spec_action_tag ); + ib_spec->flow_tag.tag_id = kern_spec->flow_tag.tag_id; +break ; +default : +return -EINVAL ; + } +return 0 ; +} +static size_t kern_spec_filter_sz (struct ib_uverbs_flow_spec_hdr *spec) {/* Returns user space filter size, includes padding */
@@ -3167,8 +3186,8 @@ static ssize_t spec_filter_size(void *kern_spec_filter, u16 kern_filter_size,return kern_filter_size; } -static int kern_spec_to_ib_spec (struct ib_uverbs_flow_spec *kern_spec, -union ib_flow_spec *ib_spec) +static int kern_spec_to_ib_spec_filter (struct ib_uverbs_flow_spec *kern_spec, +union ib_flow_spec *ib_spec) {ssize_t actual_filter_sz;ssize_t kern_filter_sz;
@@ -3263,6 +3282,18 @@ static int kern_spec_to_ib_spec(struct ib_uverbs_flow_spec *kern_spec,return 0 ; } +static int kern_spec_to_ib_spec (struct ib_uverbs_flow_spec *kern_spec, +union ib_flow_spec *ib_spec) +{ +if (kern_spec->reserved) +return -EINVAL ; + +if (kern_spec->type >=IB_FLOW_SPEC_ACTION_TAG ) +return kern_spec_to_ib_spec_action (kern_spec, ib_spec); +else +return kern_spec_to_ib_spec_filter (kern_spec, ib_spec); +} + int ib_uverbs_ex_create_wq(struct ib_uverbs_file *file, struct ib_device *ib_dev, struct ib_udata *ucore,
include/uapi/rdma/ib_user_verbs.h +13 -0
@@ -929,6 +929,19 @@ struct ib_uverbs_flow_spec_ipv6 {struct ib_uverbs_flow_ipv6_filter mask; }; +struct ib_uverbs_flow_spec_action_tag { +union { +struct ib_uverbs_flow_spec_hdr hdr; +struct { +__u32 type; +__u16 size; +__u16 reserved; + }; + }; +__u32 tag_id; +__u32 reserved1; +}; +struct ib_uverbs_flow_tunnel_filter {__be32 tunnel_id; };
Signature · 6 lines
2.10.2 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 4/5 IB/mlx5: Add flow tag support
In reply to a message not in the archiveFrom: Moses Reuben <mosesr-VPRAkNaXOzVWk0Htik3J/[email protected]>
Set flow tag in flow table entry, when IB_FLOW_SPEC_ACTION_TAG is part of the flow specifications.
Flow tag doesn't support multicast flows, so it's passing to hardware only when used.
--- drivers/infiniband/hw/mlx5/main.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-)
drivers/infiniband/hw/mlx5/main.c +23 -3
@@ -1652,6 +1652,7 @@ static void set_tos(void *outer_c, void *outer_v, u8 mask, u8 val)#define LAST_IPV6_FIELD traffic_class#define LAST_TCP_UDP_FIELD src_port#define LAST_TUNNEL_FIELD tunnel_id +#define LAST_FLOW_TAG_FIELD tag_id/* Field is the last supported field */ #define FIELDS_NOT_SUPPORTED (filter, field)\
@@ -1662,7 +1663,7 @@ static void set_tos(void *outer_c, void *outer_v, u8 mask, u8 val) sizeof(filter.field))static int parse_flow_attr (u32 *match_c,u32 *match_v, -const union ib_flow_spec *ib_spec) +const union ib_flow_spec *ib_spec,u32 *tag_id) {void *misc_params_c =MLX5_ADDR_OF (fte_match_param, match_c, misc_parameters);
@@ -1854,6 +1855,15 @@ static int parse_flow_attr(u32 *match_c, u32 *match_v,MLX5_SET (fte_match_set_misc, misc_params_v, vxlan_vni,ntohl (ib_spec->tunnel.val.tunnel_id));break ; +case IB_FLOW_SPEC_ACTION_TAG : +if (FIELDS_NOT_SUPPORTED (ib_spec->flow_tag, +LAST_FLOW_TAG_FIELD )) +return -EOPNOTSUPP ; +if (ib_spec->flow_tag.tag_id >=BIT (24 )) +return -EINVAL ; + + *tag_id = ib_spec->flow_tag.tag_id; +break ;default :return -EINVAL ; }
@@ -2037,6 +2047,7 @@ static struct mlx5_ib_flow_handler *create_flow_rule(struct mlx5_ib_dev *dev,struct mlx5_flow_spec *spec;const void *ib_flow = (const void *)flow_attr +sizeof (*flow_attr);unsigned int spec_index; +u32 flow_tag =MLX5_FS_DEFAULT_FLOW_TAG ;int err =0 ;if (!is_valid_attr (flow_attr))
@@ -2053,7 +2064,7 @@ static struct mlx5_ib_flow_handler *create_flow_rule(struct mlx5_ib_dev *dev,for (spec_index =0 ; spec_index < flow_attr->num_of_specs; spec_index++) { err =parse_flow_attr (spec->match_criteria, - spec->match_value, ib_flow); + spec->match_value, ib_flow, &flow_tag);if (err <0 ) goto free;
@@ -2063,7 +2074,16 @@ static struct mlx5_ib_flow_handler *create_flow_rule(struct mlx5_ib_dev *dev, spec->match_criteria_enable =get_match_criteria_enable (spec->match_criteria); flow_act.action = dst ?MLX5_FLOW_CONTEXT_ACTION_FWD_DEST :MLX5_FLOW_CONTEXT_ACTION_FWD_NEXT_PRIO ; - flow_act.flow_tag =MLX5_FS_DEFAULT_FLOW_TAG ; + +if (flow_tag !=MLX5_FS_DEFAULT_FLOW_TAG && + (flow_attr->type ==IB_FLOW_ATTR_ALL_DEFAULT || + flow_attr->type ==IB_FLOW_ATTR_MC_DEFAULT )) { +mlx5_ib_warn (dev,"Flow tag %u and attribute type %x isn't allowed in leftovers\n" , + flow_tag, flow_attr->type); + err = -EINVAL ; + goto free; + } + flow_act.flow_tag = flow_tag; handler->rule =mlx5_add_flow_rules (ft, spec, &flow_act, dst,1 );
Signature · 6 lines
2.10.2 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 5/5 IB/mlx5: Replace ENOTSUPP usage with EOPNOTSUPP
In reply to a message not in the archiveFrom: Leon Romanovsky <leonro-VPRAkNaXOzVWk0Htik3J/[email protected]>
Flow steering is supposed to return EOPNOTSUPP error for unsupported fields and not ENOTSUPP error.
--- drivers/infiniband/hw/mlx5/main.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/infiniband/hw/mlx5/main.c +6 -6
@@ -1687,7 +1687,7 @@ static int parse_flow_attr(u32 *match_c, u32 *match_v,switch (ib_spec->type & ~IB_FLOW_SPEC_INNER ) {case IB_FLOW_SPEC_ETH :if (FIELDS_NOT_SUPPORTED (ib_spec->eth.mask,LAST_ETH_FIELD )) -return -ENOTSUPP ; +return -EOPNOTSUPP ; ether_addr_copy(MLX5_ADDR_OF(fte_match_set_lyr_2_4, headers_c, dmac_47_16),
@@ -1735,7 +1735,7 @@ static int parse_flow_attr(u32 *match_c, u32 *match_v,break ;case IB_FLOW_SPEC_IPV4 :if (FIELDS_NOT_SUPPORTED (ib_spec->ipv4.mask,LAST_IPV4_FIELD )) -return -ENOTSUPP ; +return -EOPNOTSUPP ;MLX5_SET (fte_match_set_lyr_2_4, headers_c, ethertype,0xffff );
@@ -1767,7 +1767,7 @@ static int parse_flow_attr(u32 *match_c, u32 *match_v,break ;case IB_FLOW_SPEC_IPV6 :if (FIELDS_NOT_SUPPORTED (ib_spec->ipv6.mask,LAST_IPV6_FIELD )) -return -ENOTSUPP ; +return -EOPNOTSUPP ;MLX5_SET (fte_match_set_lyr_2_4, headers_c, ethertype,0xffff );
@@ -1808,7 +1808,7 @@ static int parse_flow_attr(u32 *match_c, u32 *match_v,case IB_FLOW_SPEC_TCP :if (FIELDS_NOT_SUPPORTED (ib_spec->tcp_udp.mask,LAST_TCP_UDP_FIELD )) -return -ENOTSUPP ; +return -EOPNOTSUPP ;MLX5_SET (fte_match_set_lyr_2_4, headers_c, ip_protocol,0xff );
@@ -1828,7 +1828,7 @@ static int parse_flow_attr(u32 *match_c, u32 *match_v,case IB_FLOW_SPEC_UDP :if (FIELDS_NOT_SUPPORTED (ib_spec->tcp_udp.mask,LAST_TCP_UDP_FIELD )) -return -ENOTSUPP ; +return -EOPNOTSUPP ;MLX5_SET (fte_match_set_lyr_2_4, headers_c, ip_protocol,0xff );
@@ -1848,7 +1848,7 @@ static int parse_flow_attr(u32 *match_c, u32 *match_v,case IB_FLOW_SPEC_VXLAN_TUNNEL :if (FIELDS_NOT_SUPPORTED (ib_spec->tunnel.mask,LAST_TUNNEL_FIELD )) -return -ENOTSUPP ; +return -EOPNOTSUPP ;MLX5_SET (fte_match_set_misc, misc_params_c, vxlan_vni,ntohl (ib_spec->tunnel.mask.tunnel_id));
Signature · 6 lines
2.10.2 -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 99 lines · Leon Romanovsky
Hi Doug,
The flow tag feature allows an application to request to add an action
to tag all the packets that matches this rule.The tag is a number that will came as a metadata with every packet in the CQE.
The tag rule == 0 is chosen as the default tag and application can use
it in order to avoid the need to classify the packets that came with a
tag while continuing to benefit from this tag mechanism.struct definition:
struct
ib_uverbs_flow_spec_action_tag{
union {
structib_uverbs_flow_spec_hdrhdr;
struct {
__u32 type;
__u16 size;
__u16 reserved;
};
};
__be32 tag_id;
__u32 reserved1;
};struct
ib_uverbs_flow_spec{
union {
union {
structib_uverbs_flow_spec_hdrhdr; struct {
__u32 type;
__u16 size;
__u16 reserved;
};
};
struct ib_uverbs_flow_spec_eth eth; struct ib_uverbs_flow_spec_ipv4 ipv4; structib_uverbs_flow_spec_tcp_udptcp_udp; struct ib_uverbs_flow_spec_ipv6 ipv6; structib_uverbs_flow_spec_action_tagflow_tag; };
};Where:
* type, size, reserved fields are identical to the rest of the
* protocols,
and are used to identify the spec.
*flow_tagis a spec of type 'action'
* theib_uverbs_flow_spec_hdris identical to the rest of the specs.
*tag_id- is the value of the stream defined by the specs.Thanks,
MosesCC: Rony Efraim <[email protected]>
----Doug,
I used this opportunity and fixedparse_flow_attr(..)return values. Adjusting this fix to this series minimizes chances of possible merge conflicts between different series.This patchset was generated against commit
f502d834950a("net/mlx5: Activate support for 4K UARs") and it applies
cleanly on k.o/for-4.11 branch.Available in the "topic/flow-tag" topic branch of this git repo:
git://git.kernel.org/pub/scm/linux/kernel/git/leon/linux-rdma.gitOr for browsing:
https://git.kernel.org/cgit/linux/kernel/git/leon/linux-rdma.git/log/
?h=topic/flow-tagLeon Romanovsky (1):
IB/mlx5: Replace ENOTSUPP usage with EOPNOTSUPPMaor Gottlieb (1):
net/mlx5: Consolidate flow rules regardless their flow tagMoses Reuben (3):
IB/core: Introduce flow tag specification
IB/uverbs: Add support for flow tag
IB/mlx5: Add flow tag supportdrivers/infiniband/core/uverbs.h | 1 + drivers/infiniband/core/uverbs_cmd.c | 35
+++++++++++++++++++--
drivers/infiniband/hw/mlx5/main.c | 38
+++++++++++++++++------
drivers/net/ethernet/mellanox/mlx5/core/fs_core.c | 12 +++++-- include/rdma/ib_verbs.h | 9 ++++++ include/uapi/rdma/ib_user_verbs.h | 13 ++++++++
Quoted 1 line
6 files changed, 95 insertions(+), 13 deletions(-)
I looked through the API additions and they look reasonable to me (meaning that if anyone else wants to implement tags on specific flows, this API is appropriate for that, and if they want to do other things, then this is not appropriate, but there is no restriction against other action types in the enum, so extensibility is preserved). Series applied, thanks.
Signature · 4 lines
Doug Ledford <[email protected]> GPG KeyID: B826A3330E572FDD Key fingerprint = AE6B 1BDA 122B 23B4 265B 1274 B826 A333 0E57 2FDD