From: Chris Mi <cmi@nvidia.com>
To: netdev@vger.kernel.org
Cc: kuba@kernel.org, jiri@nvidia.com, saeedm@nvidia.com,
Chris Mi <cmi@nvidia.com>, kernel test robot <lkp@intel.com>
Subject: [PATCH net-next v4] net: psample: Introduce stubs to remove NIC driver dependency
Date: Thu, 28 Jan 2021 09:45:43 +0800 [thread overview]
Message-ID: <20210128014543.521151-1-cmi@nvidia.com> (raw)
In order to send sampled packets to userspace, NIC driver calls
psample api directly. But it creates a hard dependency on module
psample. Introduce psample_ops to remove the hard dependency.
It is initialized when psample module is loaded and set to NULL
when the module is unloaded.
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Chris Mi <cmi@nvidia.com>
Reviewed-by: Jiri Pirko <jiri@nvidia.com>
---
v1->v2:
- fix sparse errors
v2->v3:
- remove inline
v3->v4:
- add inline back
include/net/psample.h | 27 +++++++++++++++++++++++++++
net/psample/psample.c | 13 ++++++++++++-
net/sched/Makefile | 2 +-
net/sched/psample_stub.c | 7 +++++++
4 files changed, 47 insertions(+), 2 deletions(-)
create mode 100644 net/sched/psample_stub.c
diff --git a/include/net/psample.h b/include/net/psample.h
index 68ae16bb0a4a..e6a73128de59 100644
--- a/include/net/psample.h
+++ b/include/net/psample.h
@@ -4,6 +4,7 @@
#include <uapi/linux/psample.h>
#include <linux/list.h>
+#include <linux/skbuff.h>
struct psample_group {
struct list_head list;
@@ -14,6 +15,15 @@ struct psample_group {
struct rcu_head rcu;
};
+struct psample_ops {
+ void (*sample_packet)(struct psample_group *group, struct sk_buff *skb,
+ u32 trunc_size, int in_ifindex, int out_ifindex,
+ u32 sample_rate);
+
+};
+
+extern const struct psample_ops __rcu *psample_ops __read_mostly;
+
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);
@@ -35,4 +45,21 @@ static inline void psample_sample_packet(struct psample_group *group,
#endif
+static inline void
+psample_nic_sample_packet(struct psample_group *group,
+ struct sk_buff *skb, u32 trunc_size,
+ int in_ifindex, int out_ifindex,
+ u32 sample_rate)
+{
+ const struct psample_ops *ops;
+
+ rcu_read_lock();
+ ops = rcu_dereference(psample_ops);
+ if (ops)
+ ops->sample_packet(group, skb, trunc_size,
+ in_ifindex, out_ifindex,
+ sample_rate);
+ rcu_read_unlock();
+}
+
#endif /* __NET_PSAMPLE_H */
diff --git a/net/psample/psample.c b/net/psample/psample.c
index 33e238c965bd..2a9fbfe09395 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/rcupdate.h>
#include <net/net_namespace.h>
#include <net/sock.h>
#include <net/netlink.h>
@@ -35,6 +36,10 @@ static const struct genl_multicast_group psample_nl_mcgrps[] = {
static struct genl_family psample_nl_family __ro_after_init;
+static const struct psample_ops psample_sample_ops = {
+ .sample_packet = psample_sample_packet,
+};
+
static int psample_group_nl_fill(struct sk_buff *msg,
struct psample_group *group,
enum psample_command cmd, u32 portid, u32 seq,
@@ -456,11 +461,17 @@ EXPORT_SYMBOL_GPL(psample_sample_packet);
static int __init psample_module_init(void)
{
- return genl_register_family(&psample_nl_family);
+ int ret;
+
+ ret = genl_register_family(&psample_nl_family);
+ if (!ret)
+ RCU_INIT_POINTER(psample_ops, &psample_sample_ops);
+ return ret;
}
static void __exit psample_module_exit(void)
{
+ RCU_INIT_POINTER(psample_ops, NULL);
genl_unregister_family(&psample_nl_family);
}
diff --git a/net/sched/Makefile b/net/sched/Makefile
index dd14ef413fda..0d92bb98bb26 100644
--- a/net/sched/Makefile
+++ b/net/sched/Makefile
@@ -3,7 +3,7 @@
# Makefile for the Linux Traffic Control Unit.
#
-obj-y := sch_generic.o sch_mq.o
+obj-y := sch_generic.o sch_mq.o psample_stub.o
obj-$(CONFIG_INET) += sch_frag.o
obj-$(CONFIG_NET_SCHED) += sch_api.o sch_blackhole.o
diff --git a/net/sched/psample_stub.c b/net/sched/psample_stub.c
new file mode 100644
index 000000000000..0615a7b64000
--- /dev/null
+++ b/net/sched/psample_stub.c
@@ -0,0 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB
+/* Copyright (c) 2021 Mellanox Technologies. */
+
+#include <net/psample.h>
+
+const struct psample_ops __rcu *psample_ops __read_mostly;
+EXPORT_SYMBOL_GPL(psample_ops);
--
2.26.2
next reply other threads:[~2021-01-28 1:46 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-28 1:45 Chris Mi [this message]
2021-01-29 5:14 ` [PATCH net-next v4] net: psample: Introduce stubs to remove NIC driver dependency Cong Wang
2021-01-29 6:08 ` Chris Mi
2021-01-29 20:30 ` Jakub Kicinski
2021-01-29 20:44 ` Saeed Mahameed
2021-01-29 21:47 ` Jakub Kicinski
2021-01-30 14:42 ` Ido Schimmel
2021-02-01 1:37 ` Chris Mi
2021-02-01 18:08 ` Ido Schimmel
2021-02-08 7:03 ` Leon Romanovsky
2021-02-08 8:57 ` Ido Schimmel
2021-02-08 9:07 ` Leon Romanovsky
2021-02-08 17:07 ` Ido Schimmel
2021-02-09 6:47 ` Leon Romanovsky
2021-02-09 9:25 ` Or Gerlitz
2021-02-09 10:01 ` Leon Romanovsky
2021-02-09 10:49 ` Or Gerlitz
2021-02-11 5:09 ` Saeed Mahameed
2021-02-11 21:59 ` Ido Schimmel
2021-02-12 0:41 ` Saeed Mahameed
2021-01-29 21:50 ` Jakub Kicinski
2021-01-30 2:35 ` Chris Mi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210128014543.521151-1-cmi@nvidia.com \
--to=cmi@nvidia.com \
--cc=jiri@nvidia.com \
--cc=kuba@kernel.org \
--cc=lkp@intel.com \
--cc=netdev@vger.kernel.org \
--cc=saeedm@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).