From: Patrick McHardy <kaber@trash.net>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: David Miller <davem@davemloft.net>,
netdev@vger.kernel.org, Zhang Rui <rui.zhang@intel.com>,
jamal <hadi@cyberus.ca>
Subject: Re: [patch 1/3] netlink: allocate group bitmaps dynamically
Date: Tue, 17 Jul 2007 17:45:53 +0200 [thread overview]
Message-ID: <469CE431.9070705@trash.net> (raw)
In-Reply-To: <20070717123642.918587000@sipsolutions.net>
Johannes Berg wrote:
> Allow changing the number of groups for a netlink family
> after it has been created, use RCU to protect the listeners
> bitmap keeping netlink_has_listeners() lock-free.
>
> Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
>
> ---
> include/linux/netlink.h | 1
> net/netlink/af_netlink.c | 86 +++++++++++++++++++++++++++++++++++------------
> 2 files changed, 66 insertions(+), 21 deletions(-)
>
> --- wireless-dev.orig/net/netlink/af_netlink.c 2007-07-17 14:05:30.210964463 +0200
> +++ wireless-dev/net/netlink/af_netlink.c 2007-07-17 14:05:30.720964463 +0200
> -static int netlink_alloc_groups(struct sock *sk)
> +static int netlink_realloc_groups(struct sock *sk)
> {
> struct netlink_sock *nlk = nlk_sk(sk);
> unsigned int groups;
> + unsigned long *new_groups;
> int err = 0;
>
> netlink_lock_table();
This is actually a bug in the current code I think, netlink_lock_table
is a reader lock.
> groups = nl_table[sk->sk_protocol].groups;
> if (!nl_table[sk->sk_protocol].registered)
> err = -ENOENT;
> - netlink_unlock_table();
>
> if (err)
> - return err;
> + goto out_unlock;
>
> - nlk->groups = kzalloc(NLGRPSZ(groups), GFP_KERNEL);
> - if (nlk->groups == NULL)
> - return -ENOMEM;
> + if (nlk->ngroups >= groups)
> + goto out_unlock;
> +
> + new_groups = krealloc(nlk->groups, NLGRPSZ(groups), GFP_KERNEL);
> + if (new_groups == NULL) {
> + err = -ENOMEM;
> + goto out_unlock;
> + }
> + memset((char*)new_groups + NLGRPSZ(nlk->ngroups), 0,
> + NLGRPSZ(groups) - NLGRPSZ(nlk->ngroups));
> +
> + nlk->groups = new_groups;
> nlk->ngroups = groups;
> - return 0;
> + out_unlock:
> + netlink_unlock_table();
> + return err;
> }
> +int netlink_change_ngroups(int unit, unsigned int groups)
I think it would be more consistent to pass the kernel socket
instead of the unit.
> +{
> + unsigned long *listeners, old = NULL;
> + int err = 0;
> +
> + netlink_table_grab();
> + if (NLGRPSZ(nl_table[unit].groups) < NLGRPSZ(groups)) {
> + listeners = kzalloc(NLGRPSZ(groups), GFP_ATOMIC);
> + if (!listeners) {
> + err = -ENOMEM;
> + goto out_ungrab;
> + }
> + old = nl_table[unit].listeners;
> + memcpy(listeners, old, NLGRPSZ(nl_table[unit].groups));
> + rcu_assign_pointer(nl_table[unit].listeners, listeners);
> + }
> + nl_table[unit].groups = groups;
This might set the group to a value < 32. I don't expect it matters,
but when I changed to old code to support > 32 groups I enforced
a minimum of 32 so anything outside the kernel multicasting on them
would still work (even though its a really stupid idea). So for
consistency this should probably also use a minimum of 32.
next prev parent reply other threads:[~2007-07-17 15:46 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-07-17 12:27 [patch 0/3] dynamic generic netlink multicast Johannes Berg
2007-07-17 12:27 ` [patch 1/3] netlink: allocate group bitmaps dynamically Johannes Berg
2007-07-17 15:45 ` Patrick McHardy [this message]
2007-07-18 13:34 ` Johannes Berg
2007-07-17 12:27 ` [patch 2/3] netlink: allow removing multicast groups Johannes Berg
2007-07-17 15:50 ` Patrick McHardy
2007-07-18 13:35 ` Johannes Berg
2007-07-17 12:27 ` [patch 3/3] generic netlink: dynamic " Johannes Berg
2007-07-18 13:37 ` [PATCH v2 2/3] netlink: allow removing " Johannes Berg
2007-07-18 22:30 ` David Miller
2007-07-18 14:34 ` [PATCH v2 1/3] netlink: allocate group bitmaps dynamically Johannes Berg
2007-07-18 16:30 ` Patrick McHardy
2007-07-18 22:34 ` David Miller
2007-07-19 10:08 ` Johannes Berg
2007-07-18 15:05 ` [PATCH v2 3/3] generic netlink: dynamic multicast groups Johannes Berg
2007-07-19 10:39 ` [patch 0/3] dynamic generic netlink multicast Johannes Berg
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=469CE431.9070705@trash.net \
--to=kaber@trash.net \
--cc=davem@davemloft.net \
--cc=hadi@cyberus.ca \
--cc=johannes@sipsolutions.net \
--cc=netdev@vger.kernel.org \
--cc=rui.zhang@intel.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).