From 0d9597efec0248786606a3701f2cd749e5e768b8 Mon Sep 17 00:00:00 2001 From: Vadym Hlushko Date: Mon, 11 Apr 2022 15:52:34 +0000 Subject: [PATCH 1/2] [sflow + dropmon] added patches for the sFlow dropmon feature Signed-off-by: Vadym Hlushko --- ...apsulate-packet-metadata-in-a-struct.patch | 148 ++++++++++++++++++ ...e-Add-additional-metadata-attributes.patch | 136 ++++++++++++++++ ...dded-define-PSAMPLE_MD_EXTENDED_ATTR.patch | 26 +++ patch/series | 5 + 4 files changed, 315 insertions(+) create mode 100644 patch/0001-psample-Encapsulate-packet-metadata-in-a-struct.patch create mode 100644 patch/0002-psample-Add-additional-metadata-attributes.patch create mode 100644 patch/0003-psample-added-define-PSAMPLE_MD_EXTENDED_ATTR.patch diff --git a/patch/0001-psample-Encapsulate-packet-metadata-in-a-struct.patch b/patch/0001-psample-Encapsulate-packet-metadata-in-a-struct.patch new file mode 100644 index 000000000..7688c96fd --- /dev/null +++ b/patch/0001-psample-Encapsulate-packet-metadata-in-a-struct.patch @@ -0,0 +1,148 @@ +From ab65c38369aec72cbaac3e1c9d6731804edfc5b4 Mon Sep 17 00:00:00 2001 +From: Ido Schimmel +Date: Sun, 14 Mar 2021 14:19:30 +0200 +Subject: [PATCH 1/3] psample: Encapsulate packet metadata in a struct + +Currently, callers of psample_sample_packet() pass three metadata +attributes: Ingress port, egress port and truncated size. Subsequent +patches are going to add more attributes (e.g., egress queue occupancy), +which also need an indication whether they are valid or not. + +Encapsulate packet metadata in a struct in order to keep the number of +arguments reasonable. + +Signed-off-by: Ido Schimmel +Reviewed-by: Jiri Pirko +Signed-off-by: David S. Miller +--- + drivers/net/ethernet/mellanox/mlxsw/spectrum.c | 8 ++++---- + include/net/psample.h | 14 +++++++++----- + net/psample/psample.c | 6 ++++-- + net/sched/act_sample.c | 16 ++++++---------- + 4 files changed, 23 insertions(+), 21 deletions(-) + +diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +index 1a9978f50..323857943 100644 +--- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c ++++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +@@ -2167,7 +2167,7 @@ void mlxsw_sp_sample_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb, + { + struct mlxsw_sp_port *mlxsw_sp_port = mlxsw_sp->ports[local_port]; + struct mlxsw_sp_port_sample *sample; +- u32 size; ++ struct psample_metadata md = {}; + + if (unlikely(!mlxsw_sp_port)) { + dev_warn_ratelimited(mlxsw_sp->bus_info->dev, "Port %d: sample skb received for non-existent port\n", +@@ -2179,9 +2179,9 @@ void mlxsw_sp_sample_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb, + sample = rcu_dereference(mlxsw_sp_port->sample); + if (!sample) + goto out_unlock; +- size = sample->truncate ? sample->trunc_size : skb->len; +- psample_sample_packet(sample->psample_group, skb, size, +- mlxsw_sp_port->dev->ifindex, 0, sample->rate); ++ md.trunc_size = sample->truncate ? sample->trunc_size : skb->len; ++ md.in_ifindex = mlxsw_sp_port->dev->ifindex; ++ psample_sample_packet(sample->psample_group, skb, sample->rate, &md); + out_unlock: + rcu_read_unlock(); + out: +diff --git a/include/net/psample.h b/include/net/psample.h +index 68ae16bb0..ac6dbfb38 100644 +--- a/include/net/psample.h ++++ b/include/net/psample.h +@@ -14,6 +14,12 @@ struct psample_group { + struct rcu_head rcu; + }; + ++struct psample_metadata { ++ u32 trunc_size; ++ int in_ifindex; ++ int out_ifindex; ++}; ++ + struct psample_group *psample_group_get(struct net *net, u32 group_num); + void psample_group_take(struct psample_group *group); + void psample_group_put(struct psample_group *group); +@@ -21,15 +27,13 @@ void psample_group_put(struct psample_group *group); + #if IS_ENABLED(CONFIG_PSAMPLE) + + void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, +- u32 trunc_size, int in_ifindex, int out_ifindex, +- u32 sample_rate); ++ u32 sample_rate, const struct psample_metadata *md); + + #else + + static inline void psample_sample_packet(struct psample_group *group, +- struct sk_buff *skb, u32 trunc_size, +- int in_ifindex, int out_ifindex, +- u32 sample_rate) ++ struct sk_buff *skb, u32 sample_rate, ++ const struct psample_metadata *md) + { + } + +diff --git a/net/psample/psample.c b/net/psample/psample.c +index 482c07f27..065bc887d 100644 +--- a/net/psample/psample.c ++++ b/net/psample/psample.c +@@ -356,9 +356,11 @@ static int psample_tunnel_meta_len(struct ip_tunnel_info *tun_info) + #endif + + void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, +- u32 trunc_size, int in_ifindex, int out_ifindex, +- u32 sample_rate) ++ u32 sample_rate, const struct psample_metadata *md) + { ++ int out_ifindex = md->out_ifindex; ++ int in_ifindex = md->in_ifindex; ++ u32 trunc_size = md->trunc_size; + #ifdef CONFIG_INET + struct ip_tunnel_info *tun_info; + #endif +diff --git a/net/sched/act_sample.c b/net/sched/act_sample.c +index 3ebf9ede3..2fece01f2 100644 +--- a/net/sched/act_sample.c ++++ b/net/sched/act_sample.c +@@ -158,10 +158,8 @@ static int tcf_sample_act(struct sk_buff *skb, const struct tc_action *a, + { + struct tcf_sample *s = to_sample(a); + struct psample_group *psample_group; ++ struct psample_metadata md = {}; + int retval; +- int size; +- int iif; +- int oif; + + tcf_lastuse_update(&s->tcf_tm); + bstats_cpu_update(this_cpu_ptr(s->common.cpu_bstats), skb); +@@ -172,20 +170,18 @@ static int tcf_sample_act(struct sk_buff *skb, const struct tc_action *a, + /* randomly sample packets according to rate */ + if (psample_group && (prandom_u32() % s->rate == 0)) { + if (!skb_at_tc_ingress(skb)) { +- iif = skb->skb_iif; +- oif = skb->dev->ifindex; ++ md.in_ifindex = skb->skb_iif; ++ md.out_ifindex = skb->dev->ifindex; + } else { +- iif = skb->dev->ifindex; +- oif = 0; ++ md.in_ifindex = skb->dev->ifindex; + } + + /* on ingress, the mac header gets popped, so push it back */ + if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev)) + skb_push(skb, skb->mac_len); + +- size = s->truncate ? s->trunc_size : skb->len; +- psample_sample_packet(psample_group, skb, size, iif, oif, +- s->rate); ++ md.trunc_size = s->truncate ? s->trunc_size : skb->len; ++ psample_sample_packet(psample_group, skb, s->rate, &md); + + if (skb_at_tc_ingress(skb) && tcf_sample_dev_ok_push(skb->dev)) + skb_pull(skb, skb->mac_len); +-- +2.17.1 + diff --git a/patch/0002-psample-Add-additional-metadata-attributes.patch b/patch/0002-psample-Add-additional-metadata-attributes.patch new file mode 100644 index 000000000..defaf45c6 --- /dev/null +++ b/patch/0002-psample-Add-additional-metadata-attributes.patch @@ -0,0 +1,136 @@ +From d025a830ef465ea7b560742028b46dfc5c334cf1 Mon Sep 17 00:00:00 2001 +From: Ido Schimmel +Date: Sun, 14 Mar 2021 14:19:31 +0200 +Subject: [PATCH 2/3] psample: Add additional metadata attributes + +Extend psample to report the following attributes when available: + +* Output traffic class as a 16-bit value +* Output traffic class occupancy in bytes as a 64-bit value +* End-to-end latency of the packet in nanoseconds resolution +* Software timestamp in nanoseconds resolution (always available) +* Packet's protocol. Needed for packet dissection in user space (always + available) + +Signed-off-by: Ido Schimmel +Reviewed-by: Jiri Pirko +Signed-off-by: David S. Miller +--- + include/net/psample.h | 7 +++++++ + include/uapi/linux/psample.h | 7 +++++++ + net/psample/psample.c | 39 +++++++++++++++++++++++++++++++++++- + 3 files changed, 52 insertions(+), 1 deletion(-) + +diff --git a/include/net/psample.h b/include/net/psample.h +index ac6dbfb38..e328c5127 100644 +--- a/include/net/psample.h ++++ b/include/net/psample.h +@@ -18,6 +18,13 @@ struct psample_metadata { + u32 trunc_size; + int in_ifindex; + int out_ifindex; ++ u16 out_tc; ++ u64 out_tc_occ; /* bytes */ ++ u64 latency; /* nanoseconds */ ++ u8 out_tc_valid:1, ++ out_tc_occ_valid:1, ++ latency_valid:1, ++ unused:5; + }; + + struct psample_group *psample_group_get(struct net *net, u32 group_num); +diff --git a/include/uapi/linux/psample.h b/include/uapi/linux/psample.h +index bff5032c9..0521691b6 100644 +--- a/include/uapi/linux/psample.h ++++ b/include/uapi/linux/psample.h +@@ -13,6 +13,13 @@ enum { + PSAMPLE_ATTR_GROUP_REFCOUNT, + PSAMPLE_ATTR_TUNNEL, + ++ PSAMPLE_ATTR_PAD, ++ PSAMPLE_ATTR_OUT_TC, /* u16 */ ++ PSAMPLE_ATTR_OUT_TC_OCC, /* u64, bytes */ ++ PSAMPLE_ATTR_LATENCY, /* u64, nanoseconds */ ++ PSAMPLE_ATTR_TIMESTAMP, /* u64, nanoseconds */ ++ PSAMPLE_ATTR_PROTO, /* u16 */ ++ + __PSAMPLE_ATTR_MAX + }; + +diff --git a/net/psample/psample.c b/net/psample/psample.c +index 065bc887d..118d5d2a8 100644 +--- a/net/psample/psample.c ++++ b/net/psample/psample.c +@@ -8,6 +8,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -358,6 +359,7 @@ static int psample_tunnel_meta_len(struct ip_tunnel_info *tun_info) + void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, + u32 sample_rate, const struct psample_metadata *md) + { ++ ktime_t tstamp = ktime_get_real(); + int out_ifindex = md->out_ifindex; + int in_ifindex = md->in_ifindex; + u32 trunc_size = md->trunc_size; +@@ -372,10 +374,15 @@ void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, + + meta_len = (in_ifindex ? nla_total_size(sizeof(u16)) : 0) + + (out_ifindex ? nla_total_size(sizeof(u16)) : 0) + ++ (md->out_tc_valid ? nla_total_size(sizeof(u16)) : 0) + ++ (md->out_tc_occ_valid ? nla_total_size_64bit(sizeof(u64)) : 0) + ++ (md->latency_valid ? nla_total_size_64bit(sizeof(u64)) : 0) + + nla_total_size(sizeof(u32)) + /* sample_rate */ + nla_total_size(sizeof(u32)) + /* orig_size */ + nla_total_size(sizeof(u32)) + /* group_num */ +- nla_total_size(sizeof(u32)); /* seq */ ++ nla_total_size(sizeof(u32)) + /* seq */ ++ nla_total_size_64bit(sizeof(u64)) + /* timestamp */ ++ nla_total_size(sizeof(u16)); /* protocol */ + + #ifdef CONFIG_INET + tun_info = skb_tunnel_info(skb); +@@ -425,6 +432,36 @@ void psample_sample_packet(struct psample_group *group, struct sk_buff *skb, + if (unlikely(ret < 0)) + goto error; + ++ if (md->out_tc_valid) { ++ ret = nla_put_u16(nl_skb, PSAMPLE_ATTR_OUT_TC, md->out_tc); ++ if (unlikely(ret < 0)) ++ goto error; ++ } ++ ++ if (md->out_tc_occ_valid) { ++ ret = nla_put_u64_64bit(nl_skb, PSAMPLE_ATTR_OUT_TC_OCC, ++ md->out_tc_occ, PSAMPLE_ATTR_PAD); ++ if (unlikely(ret < 0)) ++ goto error; ++ } ++ ++ if (md->latency_valid) { ++ ret = nla_put_u64_64bit(nl_skb, PSAMPLE_ATTR_LATENCY, ++ md->latency, PSAMPLE_ATTR_PAD); ++ if (unlikely(ret < 0)) ++ goto error; ++ } ++ ++ ret = nla_put_u64_64bit(nl_skb, PSAMPLE_ATTR_TIMESTAMP, ++ ktime_to_ns(tstamp), PSAMPLE_ATTR_PAD); ++ if (unlikely(ret < 0)) ++ goto error; ++ ++ ret = nla_put_u16(nl_skb, PSAMPLE_ATTR_PROTO, ++ be16_to_cpu(skb->protocol)); ++ if (unlikely(ret < 0)) ++ goto error; ++ + if (data_len) { + int nla_len = nla_total_size(data_len); + struct nlattr *nla; +-- +2.17.1 + diff --git a/patch/0003-psample-added-define-PSAMPLE_MD_EXTENDED_ATTR.patch b/patch/0003-psample-added-define-PSAMPLE_MD_EXTENDED_ATTR.patch new file mode 100644 index 000000000..54b1e3823 --- /dev/null +++ b/patch/0003-psample-added-define-PSAMPLE_MD_EXTENDED_ATTR.patch @@ -0,0 +1,26 @@ +From 7dbf2689eb841c51dca4dad51b0941c06aa09e26 Mon Sep 17 00:00:00 2001 +From: Vadym Hlushko +Date: Mon, 11 Apr 2022 15:41:46 +0000 +Subject: [PATCH 3/3] psample: added define PSAMPLE_MD_EXTENDED_ATTR + +Signed-off-by: Vadym Hlushko +--- + include/net/psample.h | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/include/net/psample.h b/include/net/psample.h +index e328c5127..b7c79f634 100644 +--- a/include/net/psample.h ++++ b/include/net/psample.h +@@ -14,6 +14,8 @@ struct psample_group { + struct rcu_head rcu; + }; + ++#define PSAMPLE_MD_EXTENDED_ATTR 1 ++ + struct psample_metadata { + u32 trunc_size; + int in_ifindex; +-- +2.17.1 + diff --git a/patch/series b/patch/series index 70441ce3f..a8e17dd69 100755 --- a/patch/series +++ b/patch/series @@ -140,6 +140,11 @@ cisco-Enable-static-memory-reservation-for-OIRable-PCIe-de.patch cisco-npu-disable-other-bars.patch cisco-hwmon-pmbus_core-pec-support-check.patch +# sFlow + dropmon support +0001-psample-Encapsulate-packet-metadata-in-a-struct.patch +0002-psample-Add-additional-metadata-attributes.patch +0003-psample-added-define-PSAMPLE_MD_EXTENDED_ATTR.patch + # # Marvell platform patches for 4.19 armhf_secondary_boot_online.patch From a403431f49a500df99ddabaed5ff7cf4a7ef7cf6 Mon Sep 17 00:00:00 2001 From: Vadym Hlushko Date: Wed, 20 Apr 2022 11:42:34 +0300 Subject: [PATCH 2/2] [sflow + dropmon] fixed review comments - removed unnecessary patch, added upstream commit id to description Signed-off-by: Vadym Hlushko --- ...apsulate-packet-metadata-in-a-struct.patch | 5 +++- ...e-Add-additional-metadata-attributes.patch | 5 +++- ...dded-define-PSAMPLE_MD_EXTENDED_ATTR.patch | 26 ------------------- patch/series | 1 - 4 files changed, 8 insertions(+), 29 deletions(-) delete mode 100644 patch/0003-psample-added-define-PSAMPLE_MD_EXTENDED_ATTR.patch diff --git a/patch/0001-psample-Encapsulate-packet-metadata-in-a-struct.patch b/patch/0001-psample-Encapsulate-packet-metadata-in-a-struct.patch index 7688c96fd..47d71b973 100644 --- a/patch/0001-psample-Encapsulate-packet-metadata-in-a-struct.patch +++ b/patch/0001-psample-Encapsulate-packet-metadata-in-a-struct.patch @@ -1,7 +1,10 @@ From ab65c38369aec72cbaac3e1c9d6731804edfc5b4 Mon Sep 17 00:00:00 2001 From: Ido Schimmel Date: Sun, 14 Mar 2021 14:19:30 +0200 -Subject: [PATCH 1/3] psample: Encapsulate packet metadata in a struct + +[backport of upstream commit a03e99d39f1943ec88f6fd3b0b9f34c20663d401] + +Subject: [PATCH 1/2] psample: Encapsulate packet metadata in a struct Currently, callers of psample_sample_packet() pass three metadata attributes: Ingress port, egress port and truncated size. Subsequent diff --git a/patch/0002-psample-Add-additional-metadata-attributes.patch b/patch/0002-psample-Add-additional-metadata-attributes.patch index defaf45c6..b64fcdd75 100644 --- a/patch/0002-psample-Add-additional-metadata-attributes.patch +++ b/patch/0002-psample-Add-additional-metadata-attributes.patch @@ -1,7 +1,10 @@ From d025a830ef465ea7b560742028b46dfc5c334cf1 Mon Sep 17 00:00:00 2001 From: Ido Schimmel Date: Sun, 14 Mar 2021 14:19:31 +0200 -Subject: [PATCH 2/3] psample: Add additional metadata attributes + +[backport of upstream commit 07e1a5809b595df6e125504dff6245cb2c8ed3de] + +Subject: [PATCH 2/2] psample: Add additional metadata attributes Extend psample to report the following attributes when available: diff --git a/patch/0003-psample-added-define-PSAMPLE_MD_EXTENDED_ATTR.patch b/patch/0003-psample-added-define-PSAMPLE_MD_EXTENDED_ATTR.patch deleted file mode 100644 index 54b1e3823..000000000 --- a/patch/0003-psample-added-define-PSAMPLE_MD_EXTENDED_ATTR.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 7dbf2689eb841c51dca4dad51b0941c06aa09e26 Mon Sep 17 00:00:00 2001 -From: Vadym Hlushko -Date: Mon, 11 Apr 2022 15:41:46 +0000 -Subject: [PATCH 3/3] psample: added define PSAMPLE_MD_EXTENDED_ATTR - -Signed-off-by: Vadym Hlushko ---- - include/net/psample.h | 2 ++ - 1 file changed, 2 insertions(+) - -diff --git a/include/net/psample.h b/include/net/psample.h -index e328c5127..b7c79f634 100644 ---- a/include/net/psample.h -+++ b/include/net/psample.h -@@ -14,6 +14,8 @@ struct psample_group { - struct rcu_head rcu; - }; - -+#define PSAMPLE_MD_EXTENDED_ATTR 1 -+ - struct psample_metadata { - u32 trunc_size; - int in_ifindex; --- -2.17.1 - diff --git a/patch/series b/patch/series index a8e17dd69..b20ace6bf 100755 --- a/patch/series +++ b/patch/series @@ -143,7 +143,6 @@ cisco-hwmon-pmbus_core-pec-support-check.patch # sFlow + dropmon support 0001-psample-Encapsulate-packet-metadata-in-a-struct.patch 0002-psample-Add-additional-metadata-attributes.patch -0003-psample-added-define-PSAMPLE_MD_EXTENDED_ATTR.patch # # Marvell platform patches for 4.19