lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAGudoHEjjuGOwf=KkZjNUTPXSr6E8w8Dvz6=_CiKVHsUOY8KeA@mail.gmail.com>
Date: Fri, 23 Aug 2024 14:33:05 +0200
From: Mateusz Guzik <mjguzik@...il.com>
To: Linus Torvalds <torvalds@...ux-foundation.org>
Cc: paul@...l-moore.com, linux-security-module@...r.kernel.org, 
	linux-kernel@...r.kernel.org
Subject: Re: [RESEND PATCH] cred: separate the refcount from frequently read fields

On Fri, Aug 23, 2024 at 2:06 AM Linus Torvalds
<torvalds@...ux-foundation.org> wrote:
>
> On Thu, 22 Aug 2024 at 21:15, Mateusz Guzik <mjguzik@...il.com> wrote:
> >
> > The refcount shares the cacheline with uid, gid and other frequently
> > read fields.
>
> So moving the refcount around looks sensible, but I don't see why you
> moved 'non_rcu' away from the rcu head union.
>
> Isn't 'non_rcu' accessed exactly when the refcount is accessed too? So
> putting it in the same cacheline with ->usage would seem to make
> sense, and you literally moved the RCU head there.
>
> Why not move it as a union, and keep the non-rcu bit with the RCU head?
>
> Yes, it is rarely actually written to and as such can be "mostly
> read-only", but since it is both read and written next to refcounts,
> why do that?
>
> Did I miss some common use?
>

It gets looked at every time you grab a ref.

The layout with the change is this:
        /* --- cacheline 1 boundary (64 bytes) --- */
        kuid_t                     uid
__attribute__((__aligned__(64))); /*    64     4 */
        kgid_t                     gid;                  /*    68     4 */
        kuid_t                     suid;                 /*    72     4 */
        kgid_t                     sgid;                 /*    76     4 */
        kuid_t                     euid;                 /*    80     4 */
        kgid_t                     egid;                 /*    84     4 */
        kuid_t                     fsuid;                /*    88     4 */
        kgid_t                     fsgid;                /*    92     4 */
        unsigned int               securebits;           /*    96     4 */
        bool                       non_rcu;              /*   100     1 */

        /* XXX 3 bytes hole, try to pack */

        kernel_cap_t               cap_inheritable;      /*   104     8 */
        kernel_cap_t               cap_permitted;        /*   112     8 */
        kernel_cap_t               cap_effective;        /*   120     8 */
        /* --- cacheline 2 boundary (128 bytes) --- */

Thus consumers which grab the ref and then look at the most commonly
used fields get the non_rcu + rest combo "for free".

consumers which already had a ref don't suffer any extra misses

-- 
Mateusz Guzik <mjguzik gmail.com>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ