Skip to content

Commit

Permalink
[sflow + dropmon] added patches for the sFlow + dropmon feature. (son…
Browse files Browse the repository at this point in the history
…ic-net#276)

* [sflow + dropmon] added patches for the sFlow dropmon feature

Signed-off-by: Vadym Hlushko <[email protected]>

* [sflow + dropmon] fixed review comments - removed unnecessary patch, added upstream commit id to description

Signed-off-by: Vadym Hlushko <[email protected]>
  • Loading branch information
vadymhlushko-mlnx authored Apr 20, 2022
1 parent b9083b1 commit 1f83896
Show file tree
Hide file tree
Showing 3 changed files with 294 additions and 0 deletions.
151 changes: 151 additions & 0 deletions patch/0001-psample-Encapsulate-packet-metadata-in-a-struct.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
From ab65c38369aec72cbaac3e1c9d6731804edfc5b4 Mon Sep 17 00:00:00 2001
From: Ido Schimmel <[email protected]>
Date: Sun, 14 Mar 2021 14:19:30 +0200

[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
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 <[email protected]>
Reviewed-by: Jiri Pirko <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
---
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

139 changes: 139 additions & 0 deletions patch/0002-psample-Add-additional-metadata-attributes.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
From d025a830ef465ea7b560742028b46dfc5c334cf1 Mon Sep 17 00:00:00 2001
From: Ido Schimmel <[email protected]>
Date: Sun, 14 Mar 2021 14:19:31 +0200

[backport of upstream commit 07e1a5809b595df6e125504dff6245cb2c8ed3de]

Subject: [PATCH 2/2] 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 <[email protected]>
Reviewed-by: Jiri Pirko <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
---
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 <linux/kernel.h>
#include <linux/skbuff.h>
#include <linux/module.h>
+#include <linux/timekeeping.h>
#include <net/net_namespace.h>
#include <net/sock.h>
#include <net/netlink.h>
@@ -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

4 changes: 4 additions & 0 deletions patch/series
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ 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

#
# Marvell platform patches for 4.19
armhf_secondary_boot_online.patch
Expand Down

0 comments on commit 1f83896

Please sign in to comment.