Skip to contentSkip to conversation

batman-adv: Support for complex compat patches

PATCH Applied Sven Eckelmann 2 participants 10 messages Oct 18, 2016 – Oct 24, 2016

Subsystems (2)
lore
Share & tools
lore

Sven Eckelmann

author maintainer
#0 lore raw

v3 cover batman-adv: Support for complex compat patches

Hi,

here is the updated patchset to get complex compat patches support in batman- adv. The initial three patches of the last patchset [1] are already part of batman-adv.git next. This part is mostly about getting coccinelle/spatch to work.

Changes in v3:

- rebased to get it working on top of current master
- use __genl_const for batadv_netlink_ops to keep it in ro memory for kernel >= 3.13

Kind regards,
Sven

[1] https://lists.open-mesh.org/pipermail/b.a.t.m.a.n/2016-October/016375.html

author maintainer
#1 lore raw

PATCH v3 1/8 batman-adv: Mark batadv_netlink_ops as const

The genl_ops don't need to be written by anyone and thus can be moved in a ro memory range.

---
v3:
- use __genl_const to keep it in ro memory for kernel >= 3.13
v2:
- new patch

---
 compat-patches/replacements.sh | 1 +
 net/batman-adv/netlink.c       | 2 +-
 2 files changed, 2 insertions(+), 1 deletion(-)
compat-patches/replacements.sh +1 -0
index 669b0ff..7dcb953 100755
@@ -5,4 +5,5 @@ set -e
 # for kernel < 3.13 to make netlink compat code work
 sed -i \
 	-e 's/^static const struct genl_multicast_group batadv_netlink_mcgrps/static __genl_const struct genl_multicast_group batadv_netlink_mcgrps/' \
+	-e 's/^static const struct genl_ops batadv_netlink_ops/static __genl_const struct genl_ops batadv_netlink_ops/' \
 	build/net/batman-adv/netlink.c
net/batman-adv/netlink.c +1 -1
index 64cb6ac..aee20a3 100644
@@ -534,7 +534,7 @@ batadv_netlink_dump_hardifs(struct sk_buff *msg, struct netlink_callback *cb)
 	return msg->len;
 }
 
-static struct genl_ops batadv_netlink_ops[] = {
+static const struct genl_ops batadv_netlink_ops[] = {
 	{
 		.cmd = BATADV_CMD_GET_MESH_INFO,
 		.flags = GENL_ADMIN_PERM,
Signature · 1 line
2.9.3
author maintainer
#2 lore raw

PATCH v3 2/8 batman-adv: Add support for coccinelle in compat-patches

In reply to Sven Eckelmann

The kernel and backports already uses spatch from coccinelle for development and backporting purposes. Thus we can cleanup many current hacks using semantic patches. These are also a lot less frail than traditional unified diffs.

---
v3:
- no changes
v2:
- new patch

---
 Makefile | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
Makefile +18 -5
index 7ef2569..99e67da 100644
@@ -40,11 +40,19 @@ ifeq ($(shell cd $(KERNELPATH) && pwd),)
 $(warning $(KERNELPATH) is missing, please set KERNELPATH)
 endif
 
+ifeq ($(origin SPATCH), undefined)
+  SPATCH = spatch
+  ifeq ($(shell which $(SPATCH) 2>/dev/null),)
+    $(error $(SPATCH) (coccinelle) not found)
+  endif
+endif
+
 export KERNELPATH
 RM ?= rm -f
 MKDIR := mkdir -p
 PATCH_FLAGS = --batch --fuzz=0 --forward --strip=1 --unified --version-control=never -g0 --remove-empty-files --no-backup-if-mismatch --reject-file=-
 PATCH := patch $(PATCH_FLAGS) -i
+SPATCH_FLAGS := --in-place --relax-include-path --use-coccigrep
 CP := cp -fpR
 
 SOURCE = $(wildcard net/batman-adv/*.[ch]) net/batman-adv/Makefile
@@ -104,12 +112,17 @@ $(SOURCE_STAMP): $(SOURCE) compat-patches/* compat-patches/replacements.sh
 	@$(RM) $(SOURCE_BUILD)
 	@$(CP) $(SOURCE) $(BUILD_DIR)/net/batman-adv/
 	@set -e; \
-	patches="$$(ls -1 compat-patches/|grep '.patch$$'|sort)"; \
+	patches="$$(ls -1 compat-patches/|grep -e '.patch$$' -e '.cocci$$'|sort)"; \
 	for i in $${patches}; do \
-		echo '  COMPAT_PATCH '$${i};\
-		cd $(BUILD_DIR); \
-		$(PATCH) ../compat-patches/$${i}; \
-		cd - > /dev/null; \
+		echo '  COMPAT_PATCH '$${i}; \
+		if echo $${i}|grep '.patch$$'; then \
+			cd $(BUILD_DIR); \
+			$(PATCH) ../compat-patches/$${i}; \
+			cd - > /dev/null; \
+		fi; \
+		if echo $${i}|grep '.cocci$$'; then echo $$(pwd); \
+			$(SPATCH) $(SPATCH_FLAGS) --dir $(BUILD_DIR) --sp-file compat-patches/$${i} > /dev/null; \
+		fi; \
 	done
 	compat-patches/replacements.sh
 	touch $(SOURCE_STAMP)
Signature · 1 line
2.9.3
author maintainer
#3 lore raw

PATCH v3 3/8 batman-adv: compat: Port netlink port hack to coccinelle

In reply to Sven Eckelmann

---
v3:
- no changes
v2:
- new patch

---
 compat-include/linux/netlink.h           | 20 +++++++-------------
 compat-include/net/genetlink.h           | 11 +++++++++++
 compat-patches/0001-netlink-portid.cocci | 17 +++++++++++++++++
 compat.h                                 |  6 ------
 4 files changed, 35 insertions(+), 19 deletions(-)
 create mode 100644 compat-patches/0001-netlink-portid.cocci
compat-include/linux/netlink.h +7 -13
index 4f2185d..ca2bdf0 100644
@@ -26,19 +26,13 @@
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)
 
-#include <net/scm.h>
-
-struct batadv_netlink_skb_parms {
-	struct ucred		creds;		/* Skb credentials	*/
-	union {
-		__u32		portid;
-		__u32		pid;
-	};
-	__u32			dst_group;
-};
-
-#undef NETLINK_CB
-#define NETLINK_CB(skb) (*(struct batadv_netlink_skb_parms *)&((skb)->cb))
+#define netlink_notify_portid(__notify) (__notify->pid)
+#define NETLINK_CB_PORTID(__skb) NETLINK_CB(__skb).pid
+
+#else
+
+#define netlink_notify_portid(__notify) (__notify->portid)
+#define NETLINK_CB_PORTID(__skb) NETLINK_CB(__skb).portid
 
 #endif /* < KERNEL_VERSION(3, 7, 0) */
 
compat-include/net/genetlink.h +11 -0
index 72a8991..6a287e6 100644
@@ -24,6 +24,17 @@
 #include <linux/version.h>
 #include_next <net/genetlink.h>
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)
+
+#define genl_info_snd_portid(__genl_info) (__genl_info->snd_pid)
+
+#else
+
+#define genl_info_snd_portid(__genl_info) (__genl_info->snd_portid)
+
+#endif /* < KERNEL_VERSION(3, 7, 0) */
+
+
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0)
 
 #include <linux/export.h>
compat-patches/0001-netlink-portid.cocci new file +17 -0
new file mode 100644
index 0000000..5fc504e
@@ -0,0 +1,17 @@
+@@
+struct netlink_notify *notify;
+@@
+-notify->portid
++netlink_notify_portid(notify)
+
+@@
+struct genl_info *info;
+@@
+-info->snd_portid
++genl_info_snd_portid(info)
+
+@@
+expression skb;
+@@
+-NETLINK_CB(skb).portid
++NETLINK_CB_PORTID(skb)
compat.h +0 -6
index d987577..78de7ea 100644
@@ -67,12 +67,6 @@ static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\
 
 #endif /* < KERNEL_VERSION(3, 3, 0) */
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 7, 0)
-
-#define snd_portid snd_pid
-
-#endif /* < KERNEL_VERSION(3, 7, 0) */
-
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
 
 #define batadv_interface_set_mac_addr(x, y) \
Signature · 1 line
2.9.3
author maintainer
#4 lore raw

PATCH v3 4/8 batman-adv: compat: Move netlink const compat to coccinelle

In reply to Sven Eckelmann

---
v3:
- removed compat-include/linux/netlink.h changes which are already in master
v2:
- new patch

---
 compat-patches/0002-genl-const.INFO  | 15 +++++++++++++++
 compat-patches/0002-genl-const.cocci | 10 ++++++++++
 compat-patches/replacements.sh       |  6 ------
 3 files changed, 25 insertions(+), 6 deletions(-)
 create mode 100644 compat-patches/0002-genl-const.INFO
 create mode 100644 compat-patches/0002-genl-const.cocci
compat-patches/0002-genl-const.INFO new file +15 -0
new file mode 100644
index 0000000..192c5c6
@@ -0,0 +1,15 @@
+Newer kernels make generic netlink ops and multicast groups
+const, but older can't have that. We therefore introduce
+__genl_const, which can be defined depending on the kernel.
+
+What kernel versions require this?
+
+XXX: try to SmPLify
+
+The struct genl_ops gave the *option* to make it const via:
+mcgrof@ergon ~/linux (git::master)$ git describe --contains f84f771d9
+v3.13-rc1~33^2~32^2~2
+
+The struct genl_multicast_group was *forced* to be const via:
+mcgrof@ergon ~/linux (git::master)$ git describe --contains 2a94fe48f
+v3.13-rc1~33^2^2
compat-patches/0002-genl-const.cocci new file +10 -0
new file mode 100644
index 0000000..36c71d6
@@ -0,0 +1,10 @@
+@@
+attribute __genl_const;
+@@
+(
+-const struct genl_multicast_group
++__genl_const struct genl_multicast_group
+|
+-const struct genl_ops
++__genl_const struct genl_ops
+)
compat-patches/replacements.sh +0 -6
index 7dcb953..c7875c0 100755
@@ -1,9 +1,3 @@
 #! /bin/sh
 
 set -e
-
-# for kernel < 3.13 to make netlink compat code work
-sed -i \
-	-e 's/^static const struct genl_multicast_group batadv_netlink_mcgrps/static __genl_const struct genl_multicast_group batadv_netlink_mcgrps/' \
-	-e 's/^static const struct genl_ops batadv_netlink_ops/static __genl_const struct genl_ops batadv_netlink_ops/' \
-	build/net/batman-adv/netlink.c
Signature · 1 line
2.9.3
author maintainer
#5 lore raw

PATCH v3 5/8 batman-adv: Remove replacement compat script

In reply to Sven Eckelmann

---
v3:
- no changes
v2:
- new patch

---
 Makefile                       | 3 +--
 compat-patches/replacements.sh | 3 ---
 2 files changed, 1 insertion(+), 5 deletions(-)
 delete mode 100755 compat-patches/replacements.sh
Makefile +1 -2
index 99e67da..7eea0ab 100644
@@ -107,7 +107,7 @@ install: config $(SOURCE_STAMP)
 config:
 	$(PWD)/gen-compat-autoconf.sh $(PWD)/compat-autoconf.h
 
-$(SOURCE_STAMP): $(SOURCE) compat-patches/* compat-patches/replacements.sh
+$(SOURCE_STAMP): $(SOURCE) compat-patches/*
 	$(MKDIR) $(BUILD_DIR)/net/batman-adv/
 	@$(RM) $(SOURCE_BUILD)
 	@$(CP) $(SOURCE) $(BUILD_DIR)/net/batman-adv/
@@ -124,7 +124,6 @@ $(SOURCE_STAMP): $(SOURCE) compat-patches/* compat-patches/replacements.sh
 			$(SPATCH) $(SPATCH_FLAGS) --dir $(BUILD_DIR) --sp-file compat-patches/$${i} > /dev/null; \
 		fi; \
 	done
-	compat-patches/replacements.sh
 	touch $(SOURCE_STAMP)
 
 .PHONY: all clean install config
compat-patches/replacements.sh deleted +0 -3
deleted file mode 100755
index c7875c0..0000000
@@ -1,3 +0,0 @@
-#! /bin/sh
-
-set -e
Signature · 1 line
2.9.3
author maintainer
#6 lore raw

PATCH v3 6/8 batman-adv: compat: Replace IFF_NO_QUEUE with coccinelle

In reply to Sven Eckelmann

---
v3:
- no changes
v2:
- new patch

---
 compat-patches/0003-iff-no-queue.cocci | 9 +++++++++
 compat.h                               | 6 ------
 2 files changed, 9 insertions(+), 6 deletions(-)
 create mode 100644 compat-patches/0003-iff-no-queue.cocci
compat-patches/0003-iff-no-queue.cocci new file +9 -0
new file mode 100644
index 0000000..9c95b85
@@ -0,0 +1,9 @@
+@@
+expression E;
+@@
+
++#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,3,0)
+ E->priv_flags |= IFF_NO_QUEUE;
++#else
++E->tx_queue_len = 0;
++#endif
compat.h +0 -6
index 78de7ea..245621f 100644
@@ -152,10 +152,4 @@ static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\
 
 #endif /* < KERNEL_VERSION(4, 0, 0) */
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0)
-
-#define IFF_NO_QUEUE	0; dev->tx_queue_len = 0
-
-#endif /* < KERNEL_VERSION(4, 3, 0) */
-
 #endif /* _NET_BATMAN_ADV_COMPAT_H_ */
Signature · 1 line
2.9.3
author maintainer
#7 lore raw

PATCH v3 7/8 batman-adv: compat: Move get_link_net patch to coccinelle

In reply to Sven Eckelmann

---
v3:
- no changes
v2:
- new patch

---
 compat-patches/0004-get_link_net.cocci | 13 +++++++++++++
 compat.h                               |  7 -------
 2 files changed, 13 insertions(+), 7 deletions(-)
 create mode 100644 compat-patches/0004-get_link_net.cocci
compat-patches/0004-get_link_net.cocci new file +13 -0
new file mode 100644
index 0000000..1ae3192
@@ -0,0 +1,13 @@
+@@
+identifier netdev, fallback_net;
+@@
+
+ static const struct net *batadv_getlink_net(const struct net_device *netdev,
+ 				             const struct net *fallback_net)
+ {
++#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
++	return fallback_net;
++#else
+ ...
++#endif
+ }
compat.h +0 -7
index 245621f..2865eeb 100644
@@ -145,11 +145,4 @@ static int __batadv_interface_kill_vid(struct net_device *dev, __be16 proto,\
 
 #endif /* < KERNEL_VERSION(3, 15, 0) */
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 0, 0)
-
-/* WARNING for batadv_getlink_net */
-#define get_link_net get_xstats_size || 1 || netdev->rtnl_link_ops->get_xstats_size
-
-#endif /* < KERNEL_VERSION(4, 0, 0) */
-
 #endif /* _NET_BATMAN_ADV_COMPAT_H_ */
Signature · 1 line
2.9.3
author maintainer
#8 lore raw

PATCH v3 8/8 batman-adv: compat: Move vid api wrapper to coccinelle

In reply to Sven Eckelmann

---
v3:
- no changes
v2:
- new patch

---
 compat-include/linux/netdevice.h        |  6 +++
 compat-patches/0005-vid-callbacks.cocci | 74 +++++++++++++++++++++++++++++++++
 compat.h                                | 54 ------------------------
 3 files changed, 80 insertions(+), 54 deletions(-)
 create mode 100644 compat-patches/0005-vid-callbacks.cocci
compat-include/linux/netdevice.h +6 -0
index fb5b519..0de9d78 100644
@@ -28,6 +28,12 @@
 
 #include <linux/netdev_features.h>
 
+#define __vid_api_returntype void
+
+#else
+
+#define __vid_api_returntype int
+
 #endif /* < KERNEL_VERSION(3, 3, 0) */
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 9, 0)
compat-patches/0005-vid-callbacks.cocci new file +74 -0

74 lines not on this page · raw message

compat.h +0 -54

66 lines not on this page · raw message

Signature · 1 line
2.9.3
maintainer Applied
#9 lore raw
In reply to Sven Eckelmann
Quoted 8 lines · CEST Sven Eckelmann

Hi,

here is the updated patchset to get complex compat patches support in batman- adv. The initial three patches of the last patchset [1] are already part of batman-adv.git next. This part is mostly about getting coccinelle/spatch to work.

Changes in v3:

Applied in d4d360d..7f40f38

Thanks,
Simon