All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/3] netns: add dummy struct inside "struct net_generic"
@ 2016-12-02  1:12 Alexey Dobriyan
  2016-12-02  5:42 ` Cong Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Alexey Dobriyan @ 2016-12-02  1:12 UTC (permalink / raw)
  To: davem; +Cc: netdev, xemul

This is precursor to fixing "[id - 1]" bloat inside net_generic().

Name "s" is chosen to complement name "u" often used for dummy unions.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---

 include/net/netns/generic.h |    6 ++++--
 net/core/net_namespace.c    |    8 ++++----
 2 files changed, 8 insertions(+), 6 deletions(-)

--- a/include/net/netns/generic.h
+++ b/include/net/netns/generic.h
@@ -25,8 +25,10 @@
  */
 
 struct net_generic {
-	unsigned int len;
-	struct rcu_head rcu;
+	struct {
+		unsigned int len;
+		struct rcu_head rcu;
+	} s;
 
 	void *ptr[0];
 };
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -50,7 +50,7 @@ static struct net_generic *net_alloc_generic(void)
 
 	ng = kzalloc(generic_size, GFP_KERNEL);
 	if (ng)
-		ng->len = max_gen_ptrs;
+		ng->s.len = max_gen_ptrs;
 
 	return ng;
 }
@@ -64,7 +64,7 @@ static int net_assign_generic(struct net *net, unsigned int id, void *data)
 
 	old_ng = rcu_dereference_protected(net->gen,
 					   lockdep_is_held(&net_mutex));
-	if (old_ng->len >= id) {
+	if (old_ng->s.len >= id) {
 		old_ng->ptr[id - 1] = data;
 		return 0;
 	}
@@ -84,11 +84,11 @@ static int net_assign_generic(struct net *net, unsigned int id, void *data)
 	 * the old copy for kfree after a grace period.
 	 */
 
-	memcpy(&ng->ptr, &old_ng->ptr, old_ng->len * sizeof(void*));
+	memcpy(&ng->ptr, &old_ng->ptr, old_ng->s.len * sizeof(void*));
 	ng->ptr[id - 1] = data;
 
 	rcu_assign_pointer(net->gen, ng);
-	kfree_rcu(old_ng, rcu);
+	kfree_rcu(old_ng, s.rcu);
 	return 0;
 }
 

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

* Re: [PATCH 2/3] netns: add dummy struct inside "struct net_generic"
  2016-12-02  1:12 [PATCH 2/3] netns: add dummy struct inside "struct net_generic" Alexey Dobriyan
@ 2016-12-02  5:42 ` Cong Wang
  2016-12-02  6:53   ` Cong Wang
  0 siblings, 1 reply; 3+ messages in thread
From: Cong Wang @ 2016-12-02  5:42 UTC (permalink / raw)
  To: Alexey Dobriyan
  Cc: David Miller, Linux Kernel Network Developers, Pavel Emelyanov

On Thu, Dec 1, 2016 at 5:12 PM, Alexey Dobriyan <adobriyan@gmail.com> wrote:
>  struct net_generic {
> -       unsigned int len;
> -       struct rcu_head rcu;
> +       struct {
> +               unsigned int len;
> +               struct rcu_head rcu;
> +       } s;
>
>         void *ptr[0];
>  };

I think you can put them in a union, since rcu is only used
for kfree_rcu() where len is not needed and rcu_head doesn't
need to be initialized by callers.

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

* Re: [PATCH 2/3] netns: add dummy struct inside "struct net_generic"
  2016-12-02  5:42 ` Cong Wang
@ 2016-12-02  6:53   ` Cong Wang
  0 siblings, 0 replies; 3+ messages in thread
From: Cong Wang @ 2016-12-02  6:53 UTC (permalink / raw)
  To: Alexey Dobriyan
  Cc: David Miller, Linux Kernel Network Developers, Pavel Emelyanov

On Thu, Dec 1, 2016 at 9:42 PM, Cong Wang <xiyou.wangcong@gmail.com> wrote:
> On Thu, Dec 1, 2016 at 5:12 PM, Alexey Dobriyan <adobriyan@gmail.com> wrote:
>>  struct net_generic {
>> -       unsigned int len;
>> -       struct rcu_head rcu;
>> +       struct {
>> +               unsigned int len;
>> +               struct rcu_head rcu;
>> +       } s;
>>
>>         void *ptr[0];
>>  };
>
> I think you can put them in a union, since rcu is only used
> for kfree_rcu() where len is not needed and rcu_head doesn't
> need to be initialized by callers.

Never mind, readers could be still reading ->len while we modify
->rcu. So they can't be in a union.

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

end of thread, other threads:[~2016-12-02  6:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-02  1:12 [PATCH 2/3] netns: add dummy struct inside "struct net_generic" Alexey Dobriyan
2016-12-02  5:42 ` Cong Wang
2016-12-02  6:53   ` Cong Wang

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.