Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1650772

Re: [PATCH 02/20] ipc: merge ipc_rcu and kern_ipc_perm

Path csiph.com!news.mixmin.net!aioe.org!bofh.it!news.nic.it!robomod
From Kees Cook <keescook@chromium.org>
Newsgroups linux.kernel
Subject Re: [PATCH 02/20] ipc: merge ipc_rcu and kern_ipc_perm
Date Thu, 25 May 2017 21:40:01 +0200
Message-ID <tL6M1-3Ub-7@gated-at.bofh.it> (permalink)
References <tEZke-1sP-3@gated-at.bofh.it> <tL69k-3pt-3@gated-at.bofh.it> <tL69k-3pt-15@gated-at.bofh.it>
X-Original-To Manfred Spraul <manfred@colorfullife.com>
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=6Ac0IUi08hxH6BxnNH9FndvPPQHIG1B7WjD9VX21Q0w=; b=gwYmCwRcNsxQ4iE1HB2v2RZu62KZI3tJA1aXP1NWHUj3Df4eFCMJMYOIKKMyec2raT w7vn1hFclmAzcBBjuENPbdI0CdGj4tu6iE0FGNxS6EjMChEpqGDVHwa2/qrcMCqqxkZa PbSvqSxMx7br2kFpYgmd5y0uQpiZNBd96TExWTL/UpUAAZT8m+UyFMTlE3TbBtwTyIYJ T5eAgILq4itaYT/eI9EaGSzXbM0NyCvuji2uXwZKKAQkCKpoj9s0ohmGml9+6Zb4KRRB yVIOHWA1As6D1FNgx+wg1/eArGaSjnkJgYgy8H2O+y0zRR/RLyjX4eLbTjM+hVnAJdwN 2vNA==
Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=6Ac0IUi08hxH6BxnNH9FndvPPQHIG1B7WjD9VX21Q0w=; b=S+hbiwSl8rmSyY0g2xrt9gCSCGHJUPiETcV1QNJPU2zK9ZroSh0Drzf14nSRSVd+3r zylXFtiDErVoIimuv7T/xFyuwmnfEamraF3bWSf8GMRPN7ozzzFksjKwzkmInQOpEpdF N7/dkZMmu/udvnbJBdEPRHYWX+Ki4dTjYMwYc=
X-Google-Dkim-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=6Ac0IUi08hxH6BxnNH9FndvPPQHIG1B7WjD9VX21Q0w=; b=J5XrwLallJ1aOCkjFz9/dR/Hwqpp5q9VvEw6oO7ClXxxgs/b8V/qI+8c2Qm7vDaIjX ytNpNFCcbGnW8sLzT2rWQQENzk7MWWv6cJUusFblpmM8L5ayhXIZduqM/INMw2QWONSE zS314t62KzOv/itaZ6NY0ml6xkkAUpe9u1cvjIOsDywPp+TX93gVig4AyMSf1Ih1J+we HTqPb82G5z/H30/GQ+V+l+ijyPTcykFSl7B6M8Y4nsvT1wGRRaDYSaTTysfVnZQVVU2q 1dODlUX+ys82qrTR1UENOs55n6QyP1RzCBiLTuAam7vuHPF2oojkIjzL1L815Z8g2U8e dqCg==
X-Gm-Message-State AODbwcA19e3YfFQW/X1JvHIQwRFbrpr5GkU3AziRoTx3o5q/dxyzrcpp /WtwvsrUl14XXQV8pFO4KXUzpMbbb2U+
X-Received by 10.107.84.1 with SMTP id i1mr13436314iob.72.1495740893544; Thu, 25 May 2017 12:34:53 -0700 (PDT)
MIME-Version 1.0
X-Google-Sender-Auth dUqpZ4wzRlgN_vDqXZzdPd6eOoQ
Content-Type text/plain; charset="UTF-8"
Sender robomod@news.nic.it
List-ID <linux-kernel.vger.kernel.org>
X-Mailing-List linux-kernel@vger.kernel.org
Approved robomod@news.nic.it
Lines 85
Organization linux.* mail to news gateway
X-Original-Cc Michael Kerrisk <mtk.manpages@gmail.com>, Andrew Morton <akpm@linux-foundation.org>, LKML <linux-kernel@vger.kernel.org>, 1vier1@web.de, Davidlohr Bueso <dave@stgolabs.net>, Ingo Molnar <mingo@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Fabian Frederick <fabf@skynet.be>
X-Original-Date Thu, 25 May 2017 12:34:52 -0700
X-Original-Message-ID <CAGXu5jJT9uC5DqcLzp8Bz_YjHMN-hk+Rz_qGWeu+EAOG13wk-A@mail.gmail.com>
X-Original-References <20170508222345.GA52073@beast> <20170525185107.12869-1-manfred@colorfullife.com> <20170525185107.12869-3-manfred@colorfullife.com>
X-Original-Sender linux-kernel-owner@vger.kernel.org
Xref csiph.com linux.kernel:1650772

Show key headers only | View raw


On Thu, May 25, 2017 at 11:50 AM, Manfred Spraul
<manfred@colorfullife.com> wrote:
> 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.

I don't see this change in the code, only the removal of sem's
memset(..., 0, ...)?

> diff --git a/ipc/sem.c b/ipc/sem.c
> index fff8337..bdff6d9 100644
> --- a/ipc/sem.c
> +++ b/ipc/sem.c
> @@ -469,20 +469,20 @@ static int newary(struct ipc_namespace *ns, struct ipc_params *params)
>         if (ns->used_sems + nsems > ns->sc_semmns)
>                 return -ENOSPC;
>
> +       BUILD_BUG_ON(offsetof(struct sem_array, sem_perm) != 0);
> +
>         size = sizeof(*sma) + nsems * sizeof(sma->sems[0]);
> -       sma = ipc_rcu_alloc(size);
> +       sma = container_of(ipc_rcu_alloc(size), struct sem_array, sem_perm);
>         if (!sma)
>                 return -ENOMEM;
>
> -       memset(sma, 0, size);
> -
>         sma->sem_perm.mode = (semflg & S_IRWXUGO);
>         sma->sem_perm.key = key;
>
>         sma->sem_perm.security = NULL;
>         retval = security_sem_alloc(sma);
>         if (retval) {
> -               ipc_rcu_putref(sma, ipc_rcu_free);
> +               ipc_rcu_putref(&sma->sem_perm, ipc_rcu_free);
>                 return retval;
>         }
>
> [...]
> diff --git a/ipc/util.c b/ipc/util.c
> index caec7b1..9dcc08b 100644
> --- a/ipc/util.c
> +++ b/ipc/util.c
> @@ -418,46 +418,43 @@ 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;
>         atomic_set(&out->refcount, 1);
> -       return out + 1;
> +       return out;
>  }

-Kees

-- 
Kees Cook
Pixel Security

Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH 02/20] ipc: merge ipc_rcu and kern_ipc_perm Manfred Spraul <manfred@colorfullife.com> - 2017-05-25 21:00 +0200
  Re: [PATCH 02/20] ipc: merge ipc_rcu and kern_ipc_perm Kees Cook <keescook@chromium.org> - 2017-05-25 21:40 +0200
    Re: [PATCH 02/20] ipc: merge ipc_rcu and kern_ipc_perm Kees Cook <keescook@chromium.org> - 2017-05-26 05:40 +0200

csiph-web