summaryrefslogtreecommitdiff
path: root/ipc/util.c
diff options
context:
space:
mode:
authorManfred Spraul <manfred@colorfullife.com>2017-07-13 00:34:41 +0300
committerLinus Torvalds <torvalds@linux-foundation.org>2017-07-13 02:26:01 +0300
commitdba4cdd39e698d8dcdad0656825423052ac90ccd (patch)
tree908f984f4652a42f603aac8f2db4edd059d11256 /ipc/util.c
parent1a23395672658969a4035dcc518ea6cab835c579 (diff)
downloadlinux-dba4cdd39e698d8dcdad0656825423052ac90ccd.tar.xz
ipc: merge ipc_rcu and kern_ipc_perm
ipc has two management structures that exist for every id: - struct kern_ipc_perm, it contains e.g. the permissions. - struct ipc_rcu, it contains the rcu head for rcu handling and the refcount. The patch merges both structures. As a bonus, we may save one cacheline, because both structures are cacheline aligned. In addition, it reduces the number of casts, instead most codepaths can use container_of. To simplify code, the ipc_rcu_alloc initializes the allocation to 0. [manfred@colorfullife.com: really include the memset() into ipc_alloc_rcu()] Link: http://lkml.kernel.org/r/564f8612-0601-b267-514f-a9f650ec9b32@colorfullife.com Link: http://lkml.kernel.org/r/20170525185107.12869-3-manfred@colorfullife.com Signed-off-by: Manfred Spraul <manfred@colorfullife.com> Cc: Davidlohr Bueso <dave@stgolabs.net> Cc: Kees Cook <keescook@chromium.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'ipc/util.c')
-rw-r--r--ipc/util.c35
1 files changed, 17 insertions, 18 deletions
diff --git a/ipc/util.c b/ipc/util.c
index caec7b1bfaa3..5d1ff1035efe 100644
--- a/ipc/util.c
+++ b/ipc/util.c
@@ -418,46 +418,45 @@ void ipc_free(void *ptr)
}
/**
- * ipc_rcu_alloc - allocate ipc and rcu space
+ * ipc_rcu_alloc - allocate ipc space
* @size: size desired
*
- * Allocate memory for the rcu header structure + the object.
- * Returns the pointer to the object or NULL upon failure.
+ * Allocate memory for an ipc object.
+ * The first member must be struct kern_ipc_perm.
*/
-void *ipc_rcu_alloc(int size)
+struct kern_ipc_perm *ipc_rcu_alloc(int size)
{
/*
* We prepend the allocation with the rcu struct
*/
- struct ipc_rcu *out = ipc_alloc(sizeof(struct ipc_rcu) + size);
+ struct kern_ipc_perm *out = ipc_alloc(size);
if (unlikely(!out))
return NULL;
+
+ memset(out, 0, size);
atomic_set(&out->refcount, 1);
- return out + 1;
+ return out;
}
-int ipc_rcu_getref(void *ptr)
+int ipc_rcu_getref(struct kern_ipc_perm *ptr)
{
- struct ipc_rcu *p = ((struct ipc_rcu *)ptr) - 1;
-
- return atomic_inc_not_zero(&p->refcount);
+ return atomic_inc_not_zero(&ptr->refcount);
}
-void ipc_rcu_putref(void *ptr, void (*func)(struct rcu_head *head))
+void ipc_rcu_putref(struct kern_ipc_perm *ptr,
+ void (*func)(struct rcu_head *head))
{
- struct ipc_rcu *p = ((struct ipc_rcu *)ptr) - 1;
-
- if (!atomic_dec_and_test(&p->refcount))
+ if (!atomic_dec_and_test(&ptr->refcount))
return;
- call_rcu(&p->rcu, func);
+ call_rcu(&ptr->rcu, func);
}
-void ipc_rcu_free(struct rcu_head *head)
+void ipc_rcu_free(struct rcu_head *h)
{
- struct ipc_rcu *p = container_of(head, struct ipc_rcu, rcu);
+ struct kern_ipc_perm *ptr = container_of(h, struct kern_ipc_perm, rcu);
- kvfree(p);
+ kvfree(ptr);
}
/**