All of lore.kernel.org
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: genetlink: no longer support using static family IDs
@ 2016-10-29  8:03 Sven Eckelmann
  2016-10-29  8:03 ` [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: genetlink: statically initialize families Sven Eckelmann
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Sven Eckelmann @ 2016-10-29  8:03 UTC (permalink / raw)
  To: b.a.t.m.a.n

From: Johannes Berg <johannes.berg@intel.com>

Static family IDs have never really been used, the only
use case was the workaround I introduced for those users
that assumed their family ID was also their multicast
group ID.

Additionally, because static family IDs would never be
reserved by the generic netlink code, using a relatively
low ID would only work for built-in families that can be
registered immediately after generic netlink is started,
which is basically only the control family (apart from
the workaround code, which I also had to add code for so
it would reserve those IDs)

Thus, anything other than GENL_ID_GENERATE is flawed and
luckily not used except in the cases I mentioned. Move
those workarounds into a few lines of code, and then get
rid of GENL_ID_GENERATE entirely, making it more robust.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
Patch already in net-next

 net/batman-adv/netlink.c | 1 -
 1 file changed, 1 deletion(-)

diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c
index aee20a3..a951e02 100644
--- a/net/batman-adv/netlink.c
+++ b/net/batman-adv/netlink.c
@@ -49,7 +49,6 @@
 #include "translation-table.h"
 
 struct genl_family batadv_netlink_family = {
-	.id = GENL_ID_GENERATE,
 	.hdrsize = 0,
 	.name = BATADV_NL_NAME,
 	.version = 1,
-- 
2.10.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: genetlink: statically initialize families
  2016-10-29  8:03 [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: genetlink: no longer support using static family IDs Sven Eckelmann
@ 2016-10-29  8:03 ` Sven Eckelmann
  2016-11-01  7:30   ` [B.A.T.M.A.N.] [2/3] " Sven Eckelmann
  2016-10-29  8:03 ` [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: genetlink: mark families as __ro_after_init Sven Eckelmann
  2016-11-01  7:29 ` [B.A.T.M.A.N.] [1/3] batman-adv: genetlink: no longer support using static family IDs Sven Eckelmann
  2 siblings, 1 reply; 6+ messages in thread
From: Sven Eckelmann @ 2016-10-29  8:03 UTC (permalink / raw)
  To: b.a.t.m.a.n

From: Johannes Berg <johannes.berg@intel.com>

Instead of providing macros/inline functions to initialize
the families, make all users initialize them statically and
get rid of the macros.

This reduces the kernel code size by about 1.6k on x86-64
(with allyesconfig).

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
[sven@narfation.org: adjust compat code]
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
Patch already in net-next

 compat-include/net/genetlink.h | 21 ++-------------------
 net/batman-adv/netlink.c       | 25 +++++++++++++++----------
 2 files changed, 17 insertions(+), 29 deletions(-)

diff --git a/compat-include/net/genetlink.h b/compat-include/net/genetlink.h
index 6a287e6..b057e6c 100644
--- a/compat-include/net/genetlink.h
+++ b/compat-include/net/genetlink.h
@@ -96,11 +96,6 @@ batadv_genlmsg_multicast_netns(struct batadv_genl_family *family,
 #define genl_unregister_family(_family) \
 	genl_unregister_family(&(_family)->family)
 
-#define genl_register_family_with_ops_groups(family, ops, grps) \
-	batadv_genl_register_family_with_ops_grps((family), \
-						  (ops), ARRAY_SIZE(ops), \
-						  (grps), ARRAY_SIZE(grps))
-
 static inline int batadv_genl_register_family(struct genl_family *family)
 {
 	unsigned int i;
@@ -148,20 +143,8 @@ static inline int batadv_genl_register_family(struct genl_family *family)
 	return ret;
 }
 
-static inline int
-batadv_genl_register_family_with_ops_grps(struct genl_family *family,
-					  struct genl_ops *ops, size_t n_ops,
-					  struct genl_multicast_group *mcgrps,
-					  size_t n_mcgrps)
-{
-	family->ops = ops;
-	family->n_ops = n_ops;
-	family->mcgrps = mcgrps;
-	family->n_mcgrps = n_mcgrps;
-	family->module = THIS_MODULE;
-
-	return batadv_genl_register_family(family);
-}
+#define genl_register_family(family) \
+	batadv_genl_register_family((family))
 
 #define __genl_const
 
diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c
index a951e02..5dfc5c4 100644
--- a/net/batman-adv/netlink.c
+++ b/net/batman-adv/netlink.c
@@ -48,13 +48,7 @@
 #include "tp_meter.h"
 #include "translation-table.h"
 
-struct genl_family batadv_netlink_family = {
-	.hdrsize = 0,
-	.name = BATADV_NL_NAME,
-	.version = 1,
-	.maxattr = BATADV_ATTR_MAX,
-	.netnsok = true,
-};
+struct genl_family batadv_netlink_family;
 
 /* multicast groups */
 enum batadv_netlink_multicast_groups {
@@ -609,6 +603,19 @@ static const struct genl_ops batadv_netlink_ops[] = {
 
 };
 
+struct genl_family batadv_netlink_family = {
+	.hdrsize = 0,
+	.name = BATADV_NL_NAME,
+	.version = 1,
+	.maxattr = BATADV_ATTR_MAX,
+	.netnsok = true,
+	.module = THIS_MODULE,
+	.ops = batadv_netlink_ops,
+	.n_ops = ARRAY_SIZE(batadv_netlink_ops),
+	.mcgrps = batadv_netlink_mcgrps,
+	.n_mcgrps = ARRAY_SIZE(batadv_netlink_mcgrps),
+};
+
 /**
  * batadv_netlink_register - register batadv genl netlink family
  */
@@ -616,9 +623,7 @@ void __init batadv_netlink_register(void)
 {
 	int ret;
 
-	ret = genl_register_family_with_ops_groups(&batadv_netlink_family,
-						   batadv_netlink_ops,
-						   batadv_netlink_mcgrps);
+	ret = genl_register_family(&batadv_netlink_family);
 	if (ret)
 		pr_warn("unable to register netlink family");
 }
-- 
2.10.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: genetlink: mark families as __ro_after_init
  2016-10-29  8:03 [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: genetlink: no longer support using static family IDs Sven Eckelmann
  2016-10-29  8:03 ` [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: genetlink: statically initialize families Sven Eckelmann
@ 2016-10-29  8:03 ` Sven Eckelmann
  2016-11-01  7:30   ` [B.A.T.M.A.N.] [3/3] " Sven Eckelmann
  2016-11-01  7:29 ` [B.A.T.M.A.N.] [1/3] batman-adv: genetlink: no longer support using static family IDs Sven Eckelmann
  2 siblings, 1 reply; 6+ messages in thread
From: Sven Eckelmann @ 2016-10-29  8:03 UTC (permalink / raw)
  To: b.a.t.m.a.n

From: Johannes Berg <johannes.berg@intel.com>

Now genl_register_family() is the only thing (other than the
users themselves, perhaps, but I didn't find any doing that)
writing to the family struct.

In all families that I found, genl_register_family() is only
called from __init functions (some indirectly, in which case
I've add __init annotations to clarifly things), so all can
actually be marked __ro_after_init.

This protects the data structure from accidental corruption.

Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
[sven@narfation.org: Add compat code]
Signed-off-by: Sven Eckelmann <sven@narfation.org>
---
Patch already in net-next

 compat-include/linux/cache.h | 35 +++++++++++++++++++++++++++++++++++
 net/batman-adv/netlink.c     |  2 +-
 2 files changed, 36 insertions(+), 1 deletion(-)
 create mode 100644 compat-include/linux/cache.h

diff --git a/compat-include/linux/cache.h b/compat-include/linux/cache.h
new file mode 100644
index 0000000..93dff58
--- /dev/null
+++ b/compat-include/linux/cache.h
@@ -0,0 +1,35 @@
+/* Copyright (C) 2007-2016 B.A.T.M.A.N. contributors:
+ *
+ * Marek Lindner, Simon Wunderlich
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of version 2 of the GNU General Public
+ * License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * This file contains macros for maintaining compatibility with older versions
+ * of the Linux kernel.
+ */
+
+#ifndef _NET_BATMAN_ADV_COMPAT_LINUX_CACHE_H
+#define _NET_BATMAN_ADV_COMPAT_LINUX_CACHE_H
+
+#include <linux/version.h>
+#include_next <linux/cache.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 6, 0)
+
+#ifndef __ro_after_init
+#define __ro_after_init
+#endif
+
+#endif /* < KERNEL_VERSION(4, 6, 0) */
+
+#endif /* _NET_BATMAN_ADV_COMPAT_LINUX_CACHE_H */
diff --git a/net/batman-adv/netlink.c b/net/batman-adv/netlink.c
index 5dfc5c4..5d38c77 100644
--- a/net/batman-adv/netlink.c
+++ b/net/batman-adv/netlink.c
@@ -603,7 +603,7 @@ static const struct genl_ops batadv_netlink_ops[] = {
 
 };
 
-struct genl_family batadv_netlink_family = {
+struct genl_family batadv_netlink_family __ro_after_init = {
 	.hdrsize = 0,
 	.name = BATADV_NL_NAME,
 	.version = 1,
-- 
2.10.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [B.A.T.M.A.N.] [1/3] batman-adv: genetlink: no longer support using static family IDs
  2016-10-29  8:03 [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: genetlink: no longer support using static family IDs Sven Eckelmann
  2016-10-29  8:03 ` [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: genetlink: statically initialize families Sven Eckelmann
  2016-10-29  8:03 ` [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: genetlink: mark families as __ro_after_init Sven Eckelmann
@ 2016-11-01  7:29 ` Sven Eckelmann
  2 siblings, 0 replies; 6+ messages in thread
From: Sven Eckelmann @ 2016-11-01  7:29 UTC (permalink / raw)
  To: b.a.t.m.a.n

[-- Attachment #1: Type: text/plain, Size: 1372 bytes --]

On Samstag, 29. Oktober 2016 10:03:26 CET Sven Eckelmann wrote:
> From: Johannes Berg <johannes.berg@intel.com>
> 
> Static family IDs have never really been used, the only
> use case was the workaround I introduced for those users
> that assumed their family ID was also their multicast
> group ID.
> 
> Additionally, because static family IDs would never be
> reserved by the generic netlink code, using a relatively
> low ID would only work for built-in families that can be
> registered immediately after generic netlink is started,
> which is basically only the control family (apart from
> the workaround code, which I also had to add code for so
> it would reserve those IDs)
> 
> Thus, anything other than GENL_ID_GENERATE is flawed and
> luckily not used except in the cases I mentioned. Move
> those workarounds into a few lines of code, and then get
> rid of GENL_ID_GENERATE entirely, making it more robust.
> 
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
> Signed-off-by: David S. Miller <davem@davemloft.net>
> Signed-off-by: Sven Eckelmann <sven@narfation.org>
> ---
> Patch already in net-next
> 
>  net/batman-adv/netlink.c | 1 -
>  1 file changed, 1 deletion(-)

Applied in 83e3cb32617d07a33fb43faa0957b91b3ac622c5 [1].

Kind regards,
        Sven

[1] https://git.open-mesh.org/batman-adv.git/commit/83e3cb32617d07a33fb43faa0957b91b3ac622c5

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [B.A.T.M.A.N.] [2/3] batman-adv: genetlink: statically initialize families
  2016-10-29  8:03 ` [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: genetlink: statically initialize families Sven Eckelmann
@ 2016-11-01  7:30   ` Sven Eckelmann
  0 siblings, 0 replies; 6+ messages in thread
From: Sven Eckelmann @ 2016-11-01  7:30 UTC (permalink / raw)
  To: b.a.t.m.a.n

[-- Attachment #1: Type: text/plain, Size: 957 bytes --]

On Samstag, 29. Oktober 2016 10:03:27 CET Sven Eckelmann wrote:
> From: Johannes Berg <johannes.berg@intel.com>
> 
> Instead of providing macros/inline functions to initialize
> the families, make all users initialize them statically and
> get rid of the macros.
> 
> This reduces the kernel code size by about 1.6k on x86-64
> (with allyesconfig).
> 
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
> Signed-off-by: David S. Miller <davem@davemloft.net>
> [sven@narfation.org: adjust compat code]
> Signed-off-by: Sven Eckelmann <sven@narfation.org>
> ---
> Patch already in net-next
> 
>  compat-include/net/genetlink.h | 21 ++-------------------
>  net/batman-adv/netlink.c       | 25 +++++++++++++++----------
>  2 files changed, 17 insertions(+), 29 deletions(-)

Applied in f0f80621705b629aa04ca90411633b9b3dd3c61f [1].

Kind regards,
        Sven

[1] https://git.open-mesh.org/batman-adv.git/commit/f0f80621705b629aa04ca90411633b9b3dd3c61f

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [B.A.T.M.A.N.] [3/3] batman-adv: genetlink: mark families as __ro_after_init
  2016-10-29  8:03 ` [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: genetlink: mark families as __ro_after_init Sven Eckelmann
@ 2016-11-01  7:30   ` Sven Eckelmann
  0 siblings, 0 replies; 6+ messages in thread
From: Sven Eckelmann @ 2016-11-01  7:30 UTC (permalink / raw)
  To: b.a.t.m.a.n

[-- Attachment #1: Type: text/plain, Size: 1208 bytes --]

On Samstag, 29. Oktober 2016 10:03:28 CET Sven Eckelmann wrote:
> From: Johannes Berg <johannes.berg@intel.com>
> 
> Now genl_register_family() is the only thing (other than the
> users themselves, perhaps, but I didn't find any doing that)
> writing to the family struct.
> 
> In all families that I found, genl_register_family() is only
> called from __init functions (some indirectly, in which case
> I've add __init annotations to clarifly things), so all can
> actually be marked __ro_after_init.
> 
> This protects the data structure from accidental corruption.
> 
> Signed-off-by: Johannes Berg <johannes.berg@intel.com>
> Signed-off-by: David S. Miller <davem@davemloft.net>
> [sven@narfation.org: Add compat code]
> Signed-off-by: Sven Eckelmann <sven@narfation.org>
> ---
> Patch already in net-next
> 
>  compat-include/linux/cache.h | 35 +++++++++++++++++++++++++++++++++++
>  net/batman-adv/netlink.c     |  2 +-
>  2 files changed, 36 insertions(+), 1 deletion(-)
>  create mode 100644 compat-include/linux/cache.h

Applied in c776b4a071d82f8ad0e35d1b9472758ecf69a75e [1].

Kind regards,
        Sven

[1] https://git.open-mesh.org/batman-adv.git/commit/c776b4a071d82f8ad0e35d1b9472758ecf69a75e

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 801 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-11-01  7:30 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-29  8:03 [B.A.T.M.A.N.] [PATCH 1/3] batman-adv: genetlink: no longer support using static family IDs Sven Eckelmann
2016-10-29  8:03 ` [B.A.T.M.A.N.] [PATCH 2/3] batman-adv: genetlink: statically initialize families Sven Eckelmann
2016-11-01  7:30   ` [B.A.T.M.A.N.] [2/3] " Sven Eckelmann
2016-10-29  8:03 ` [B.A.T.M.A.N.] [PATCH 3/3] batman-adv: genetlink: mark families as __ro_after_init Sven Eckelmann
2016-11-01  7:30   ` [B.A.T.M.A.N.] [3/3] " Sven Eckelmann
2016-11-01  7:29 ` [B.A.T.M.A.N.] [1/3] batman-adv: genetlink: no longer support using static family IDs Sven Eckelmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.