Skip to contentSkip to conversation

net: ptp: move PTP classifier in its own file

PATCH In review Daniel Borkmann 3 participants 3 messages Apr 1, 2014

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: ptp: move PTP classifier in its own file

This commit fixes a build error reported by Fengguang, that is triggered when CONFIG_NETWORK_PHY_TIMESTAMPING is not set:

ERROR: "ptp_classify_raw" [drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe.ko] undefined!

The fix is to introduce its own file for the PTP BPF classifier, so that PTP_1588_CLOCK and/or NETWORK_PHY_TIMESTAMPING can select it independently from each other. IXP4xx driver on ARM needs to select it as well since it does not seem to select PTP_1588_CLOCK or similar that would pull it in automatically.

This also allows for hiding all of the internals of the BPF PTP program inside that file, and only exporting relevant API bits to drivers.

This patch also adds a kdoc documentation of ptp_classify_raw() API to make it clear that it can return PTP_CLASS_* defines. Also, the BPF program has been translated into bpf_asm code, so that it can be more easily read and altered (extensively documented in [1]).

In the kernel tree under tools/net/ we have bpf_asm and bpf_dbg tools, so the commented program can simply be translated via ./bpf_asm -c prog where prog is a file that contains the commented code. This makes it easily readable/verifiable and when there's a need to change something, jump offsets etc do not need to be replaced manually which can be very error prone. Instead, a newly translated version via bpf_asm can simply replace the old code. I have checked opcode diffs before/after and it's the very same filter.

[1] Documentation/networking/filter.txt

Fixes 164d8c666521 ("net: ptp: do not reimplement PTP/BPF classifier")
Cc Richard Cochran <[email protected]>
Cc Jiri Benc <[email protected]>

---
(Fix applies to net-next tree.)

 drivers/net/ethernet/xscale/Kconfig |   1 +
 drivers/net/phy/dp83640.c           |   1 +
 drivers/ptp/Kconfig                 |   1 +
 include/linux/ptp_classify.h        |  95 ++++++------------------
 include/linux/skbuff.h              |   2 -
 net/Kconfig                         |   4 +
 net/core/Makefile                   |   1 +
 net/core/ptp_classifier.c           | 141 ++++++++++++++++++++++++++++++++++++
 net/core/timestamping.c             |  18 -----
 net/socket.c                        |   5 +-
 10 files changed, 173 insertions(+), 96 deletions(-)
 create mode 100644 net/core/ptp_classifier.c
drivers/net/ethernet/xscale/Kconfig +1 -0
index 3f43101..b81bc9f 100644
@@ -23,6 +23,7 @@ config IXP4XX_ETH
 	tristate "Intel IXP4xx Ethernet support"
 	depends on ARM && ARCH_IXP4XX && IXP4XX_NPE && IXP4XX_QMGR
 	select PHYLIB
+	select NET_PTP_CLASSIFY
 	---help---
 	  Say Y here if you want to use built-in Ethernet ports
 	  on IXP4xx processor.
drivers/net/phy/dp83640.c +1 -0
index 352c5e4..6a999e6 100644
@@ -27,6 +27,7 @@
 #include <linux/module.h>
 #include <linux/net_tstamp.h>
 #include <linux/netdevice.h>
+#include <linux/if_vlan.h>
 #include <linux/phy.h>
 #include <linux/ptp_classify.h>
 #include <linux/ptp_clock_kernel.h>
drivers/ptp/Kconfig +1 -0
index 5a7910e..6963bdf 100644
@@ -7,6 +7,7 @@ menu "PTP clock support"
 config PTP_1588_CLOCK
 	tristate "PTP clock support"
 	select PPS
+	select NET_PTP_CLASSIFY
 	help
 	  The IEEE 1588 standard defines a method to precisely
 	  synchronize distributed clocks over Ethernet networks. The
include/linux/ptp_classify.h +22 -73

122 lines not on this page · raw message

include/linux/skbuff.h +0 -2
index 18ef022..31edf63 100644
@@ -2630,8 +2630,6 @@ static inline ktime_t net_invalid_timestamp(void)
 	return ktime_set(0, 0);
 }
 
-void skb_timestamping_init(void);
-
 #ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
 
 void skb_clone_tx_timestamp(struct sk_buff *skb);
net/Kconfig +4 -0
index e411046..d1f6f96 100644
@@ -89,8 +89,12 @@ config NETWORK_SECMARK
 	  to nfmark, but designated for security purposes.
 	  If you are unsure how to answer this question, answer N.
 
+config NET_PTP_CLASSIFY
+	def_bool n
+
 config NETWORK_PHY_TIMESTAMPING
 	bool "Timestamping in PHY devices"
+	select NET_PTP_CLASSIFY
 	help
 	  This allows timestamping of network packets by PHYs with
 	  hardware timestamping capabilities. This option adds some
net/core/Makefile +1 -0
index 9628c20..826b925 100644
@@ -21,5 +21,6 @@ obj-$(CONFIG_FIB_RULES) += fib_rules.o
 obj-$(CONFIG_TRACEPOINTS) += net-traces.o
 obj-$(CONFIG_NET_DROP_MONITOR) += drop_monitor.o
 obj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += timestamping.o
+obj-$(CONFIG_NET_PTP_CLASSIFY) += ptp_classifier.o
 obj-$(CONFIG_CGROUP_NET_PRIO) += netprio_cgroup.o
 obj-$(CONFIG_CGROUP_NET_CLASSID) += netclassid_cgroup.o
net/core/ptp_classifier.c new file +141 -0

141 lines not on this page · raw message

net/core/timestamping.c +0 -18
index 9ff26b3..6521dfd 100644
@@ -23,14 +23,6 @@
 #include <linux/skbuff.h>
 #include <linux/export.h>
 
-static struct sk_filter *ptp_insns __read_mostly;
-
-unsigned int ptp_classify_raw(const struct sk_buff *skb)
-{
-	return SK_RUN_FILTER(ptp_insns, skb);
-}
-EXPORT_SYMBOL_GPL(ptp_classify_raw);
-
 static unsigned int classify(const struct sk_buff *skb)
 {
 	if (likely(skb->dev && skb->dev->phydev &&
@@ -140,13 +132,3 @@ bool skb_defer_rx_timestamp(struct sk_buff *skb)
 	return false;
 }
 EXPORT_SYMBOL_GPL(skb_defer_rx_timestamp);
-
-void __init skb_timestamping_init(void)
-{
-	static struct sock_filter ptp_filter[] = { PTP_FILTER };
-	struct sock_fprog ptp_prog = {
-		.len = ARRAY_SIZE(ptp_filter), .filter = ptp_filter,
-	};
-
-	BUG_ON(sk_unattached_filter_create(&ptp_insns, &ptp_prog));
-}
net/socket.c +2 -3
index f25eaa3..1b1e7e6 100644
@@ -72,6 +72,7 @@
 #include <linux/if_bridge.h>
 #include <linux/if_frad.h>
 #include <linux/if_vlan.h>
+#include <linux/ptp_classify.h>
 #include <linux/init.h>
 #include <linux/poll.h>
 #include <linux/cache.h>
@@ -2685,9 +2686,7 @@ static int __init sock_init(void)
 		goto out;
 #endif
 
-#ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
-	skb_timestamping_init();
-#endif
+	ptp_classifier_init();
 
 out:
 	return err;
Signature · 1 line
1.7.11.7
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · Daniel Borkmann

In the kernel tree under tools/net/ we have bpf_asm and bpf_dbg tools, so the commented program can simply be translated via ./bpf_asm -c prog where prog is a file that contains the commented code. This makes it easily readable/verifiable and when there's a need to change something, jump offsets etc do not need to be replaced manually which can be very error prone. Instead, a newly translated version via bpf_asm can simply replace the old code. I have checked opcode diffs before/after and it's the very same filter.

I'll take your word for it.

#2 lore raw
In reply to Daniel Borkmann

From: Daniel Borkmann <[email protected]>
Date: Tue, 1 Apr 2014 16:20:23 +0200

Quoted 30 lines

This commit fixes a build error reported by Fengguang, that is triggered when CONFIG_NETWORK_PHY_TIMESTAMPING is not set:

ERROR: "ptp_classify_raw" [drivers/net/ethernet/oki-semi/pch_gbe/pch_gbe.ko] undefined!

The fix is to introduce its own file for the PTP BPF classifier, so that PTP_1588_CLOCK and/or NETWORK_PHY_TIMESTAMPING can select it independently from each other. IXP4xx driver on ARM needs to select it as well since it does not seem to select PTP_1588_CLOCK or similar that would pull it in automatically.

This also allows for hiding all of the internals of the BPF PTP program inside that file, and only exporting relevant API bits to drivers.

This patch also adds a kdoc documentation of ptp_classify_raw() API to make it clear that it can return PTP_CLASS_* defines. Also, the BPF program has been translated into bpf_asm code, so that it can be more easily read and altered (extensively documented in [1]).

In the kernel tree under tools/net/ we have bpf_asm and bpf_dbg tools, so the commented program can simply be translated via ./bpf_asm -c prog where prog is a file that contains the commented code. This makes it easily readable/verifiable and when there's a need to change something, jump offsets etc do not need to be replaced manually which can be very error prone. Instead, a newly translated version via bpf_asm can simply replace the old code. I have checked opcode diffs before/after and it's the very same filter.

Quoted 6 lines

[1] Documentation/networking/filter.txt

Fixes 164d8c666521 ("net: ptp: do not reimplement PTP/BPF classifier")

Looks good, applied, thanks Daniel.