From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 513D3D63935 for ; Wed, 20 Nov 2024 12:48:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CDEBD6B0099; Wed, 20 Nov 2024 07:48:25 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C8E086B009A; Wed, 20 Nov 2024 07:48:25 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B55D06B009B; Wed, 20 Nov 2024 07:48:25 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9AA0F6B0099 for ; Wed, 20 Nov 2024 07:48:25 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 2F5CB140951 for ; Wed, 20 Nov 2024 12:48:25 +0000 (UTC) X-FDA: 82806450132.10.7D5800B Received: from mail-yw1-f181.google.com (mail-yw1-f181.google.com [209.85.128.181]) by imf20.hostedemail.com (Postfix) with ESMTP id EAE181C0005 for ; Wed, 20 Nov 2024 12:47:18 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf20.hostedemail.com: domain of geert.uytterhoeven@gmail.com designates 209.85.128.181 as permitted sender) smtp.mailfrom=geert.uytterhoeven@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732106718; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2E0lxeHc7zWSGry84JM/MNKrxDd/HDpJgzw+Kihiymw=; b=xKgHWlHQk1+5lNl3FaoGbeachu7UQDDbvHtfJKINbMTg/tZ34cnWNHM/D8Qt4LdmwVYbzL Nbof2zg1wrYG0CeIx9lBnf9pDC39K8MqXa7dQTB3o+w0zQY1hz79BMprMwIIpehs5Ac6gZ 2rOAjNfrazFASCE95MNtBAJtU5B798Q= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf20.hostedemail.com: domain of geert.uytterhoeven@gmail.com designates 209.85.128.181 as permitted sender) smtp.mailfrom=geert.uytterhoeven@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732106718; a=rsa-sha256; cv=none; b=kZw+AKhZQ5dQRAdHCl8sUV/3bUSb5s84l7+6559mgds/ei4e7eqmIDTqo8d09JoLXaprI+ UV1TXw8mR0fe8SpjsxvwnPITZkeL9ctYLIns54adQH2su4WE5XHGQVXi7a9es+/acCq5jx 5JHbQDJmsroc4s9Kl0R3bBJ7a6eZNfg= Received: by mail-yw1-f181.google.com with SMTP id 00721157ae682-6eeca160f14so320487b3.2 for ; Wed, 20 Nov 2024 04:48:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732106900; x=1732711700; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=2E0lxeHc7zWSGry84JM/MNKrxDd/HDpJgzw+Kihiymw=; b=xNwMADWa3IO1gQHtxo3GBRrCtDlpmNCmQtMyRGpEiCkJQnTg+NjHwi8nBz5R9LkmLf CMVfW8Wpzts3JYriQymkFcLPNLLhQhBAdKlClpng6JYUA/lLhXOkgs7CTRgG/uyeCLts EjVJ5aF+LyfbWqN/ALE8fIT3kQFPcz2hqMIJ9hdbu16SZokPvQcVaVhMg1Lv2fXuUR9p CDZuIjNQNkD0+qwn/+0M/qZVq05cM2tUrYb8OAT12W1ygoYAnbkiqSlvCHWchk0rsy0l u6xIFyduuASB9EXRSFzW4f4duawL63PZA3JyGQ6olBjDpKCjvHPT5w+iufiFMqZq/Cd8 m/dg== X-Forwarded-Encrypted: i=1; AJvYcCV+emSk0Sdk8dQMF9zVmrRTGAWc0EGjcqUjgDaB4tj4QSyLT8ShZKt/FrPAZ0yURVmTdAR0a0rqKg==@kvack.org X-Gm-Message-State: AOJu0YzWvtdXtidGZMyv9Bji56gg2SpZPt/1KjfHX0WTYiCFClOmyvHY pbgV8ujA2cOuDcdZSLl9nWG061UmkrfZ1oTHc3RaAor+yqKVk6z8AQmvXkYU X-Google-Smtp-Source: AGHT+IGTv9eJUd6X/u5OQnkZ2PH741zoaS7+fc9sLgvz9K51q0Q/w5u5bYhg9YT0nQm/M5h8wsY1Rg== X-Received: by 2002:a05:690c:46c9:b0:6ee:781a:a29 with SMTP id 00721157ae682-6eebd2e458amr37299387b3.35.1732106900363; Wed, 20 Nov 2024 04:48:20 -0800 (PST) Received: from mail-yw1-f175.google.com (mail-yw1-f175.google.com. [209.85.128.175]) by smtp.gmail.com with ESMTPSA id 00721157ae682-6eeaf0bcaeesm7125827b3.109.2024.11.20.04.48.18 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 20 Nov 2024 04:48:19 -0800 (PST) Received: by mail-yw1-f175.google.com with SMTP id 00721157ae682-6eeca160f14so319627b3.2 for ; Wed, 20 Nov 2024 04:48:18 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXWIREw4k4p1HFI9DwMygPDKxHBUtGJ7EDq48LZ7QeCr9PZGFXdcAl3wL8bUyoico2Mm0l2w8AYuQ==@kvack.org X-Received: by 2002:a05:690c:688c:b0:6e7:e3b1:8cc7 with SMTP id 00721157ae682-6eebd17fe40mr29088887b3.22.1732106898570; Wed, 20 Nov 2024 04:48:18 -0800 (PST) MIME-Version: 1.0 References: <20241029152249.667290-1-axboe@kernel.dk> <5a7528c4-4391-4bd9-bbdb-a0247f3c76a9@kernel.dk> <5851cd28-b369-4c09-876c-62c4a47c5982@kernel.dk> <358710e8-a826-46df-9846-5a9e0f7c6851@kernel.dk> <82b97543-ad01-4e42-b79c-12d97c1df194@kernel.dk> <4623f30c-a12e-4ba6-ad99-835764611c67@kernel.dk> <47a16a83-52c7-4779-9ed3-f16ea547b9f0@roeck-us.net> <6c3d73a5-b5ef-455f-92db-e6b96ef22fba@kernel.dk> <8b95a694-ecd4-4b6d-8032-049894dec2c1@suse.cz> In-Reply-To: From: Geert Uytterhoeven Date: Wed, 20 Nov 2024 13:48:06 +0100 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 03/14] io_uring: specify freeptr usage for SLAB_TYPESAFE_BY_RCU io_kiocb cache To: Vlastimil Babka Cc: Kees Cook , Jens Axboe , Jann Horn , Guenter Roeck , io-uring@vger.kernel.org, linux-m68k , Christian Brauner , Linux MM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: EAE181C0005 X-Stat-Signature: gq1z7yo5gqau8c583e7yn6ukfu68t98z X-Rspam-User: X-HE-Tag: 1732106838-865316 X-HE-Meta: U2FsdGVkX19lyS1saTDkSl7covhPFQVO1/Xd1l0woUfkvDc3VltG5eJ/MIFmnHWPNge/2yTYJvhl8MLLh21X2nN3seckiDUNGrTEBEbHFr8D1S1BmyI5yHBMvm4mXswoGlOA+x5DZKELWkdCE0kQsfwzipwomTT0w1v5JVie3ICPcFZercX6UDpyEs8zXLduq0bBwjLMfTOQkT9aktL2yRrODwhBlfIr3rXYhReqejEJxzr8BISb9etGRrEWzJiYxOcSDYSdZo1gG46d2oHEip5It3poNOYor+9ny67QijUaiZNVvkL6dryp3xPPflBWqD8xMC3CEa3HrbpC8FVT1ATtR02fteEbTrNu1WYx1skvGnYSXx83CXjB60VqqisyKHOO7f2f1m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x6JgLcpdHXkb2vYROS8PbnpxoejicWUkq5xnkkb6fLHx7ELktkDGmjdJI93OqXre X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Hi Vlastimil, On Wed, Nov 20, 2024 at 10:37=E2=80=AFAM Vlastimil Babka w= rote: > On 11/20/24 10:07, Geert Uytterhoeven wrote: > >> >> diff --git a/include/linux/io_uring_types.h b/include/linux/io_urin= g_types.h > >> >> index 593c10a02144..8ed9c6923668 100644 > >> >> --- a/include/linux/io_uring_types.h > >> >> +++ b/include/linux/io_uring_types.h > >> >> @@ -674,7 +674,11 @@ struct io_kiocb { > >> >> struct io_kiocb *link; > >> >> /* custom credentials, valid IFF REQ_F_CREDS is set */ > >> >> const struct cred *creds; > >> >> - struct io_wq_work work; > >> >> + > >> >> + union { > >> >> + struct io_wq_work work; > >> >> + freeptr_t freeptr __aligned(sizeof(fr= eeptr_t)); > >> > > >> > I'd rather add the __aligned() to the definition of freeptr_t, so it > >> > applies to all (future) users. > >> > > >> > But my main question stays: why is the slab code checking > >> > IS_ALIGNED(args->freeptr_offset, sizeof(freeptr_t)? > >> > >> I believe it's to match how SLUB normally calculates the offset if no > >> explicit one is given, in calculate_sizes(): > >> > >> s->offset =3D ALIGN_DOWN(s->object_size / 2, sizeof(void *)); > >> > >> Yes there's a sizeof(void *) because freepointer used to be just that = and we > >> forgot to update this place when freepointer_t was introduced (by Jann= in > >> 44f6a42d49350) for handling CONFIG_SLAB_FREELIST_HARDENED. In > >> get_freepointer() you can see how there's a cast to a pointer eventual= ly. > >> > >> Does m68k have different alignment for pointer and unsigned long or bo= th are > >> 2 bytes? Or any other arch, i.e. should get_freepointer be a union wit= h > >> unsigned long and void * instead? (or it doesn't matter?) > > > > The default alignment for int, long, and pointer is 2 on m68k. > > On CRIS (no longer supported by Linux), it was 1, IIRC. > > So the union won't make a difference. > > > >> > Perhaps that was just intended to be __alignof__ instead of sizeof()= ? > >> > >> Would it do the right thing everywhere, given the explanation above? > > > > It depends. Does anything rely on the offset being a multiple of (at > > least) 4? > > E.g. does anything counts in multiples of longs (hi BCPL! ;-), or are > > the 2 LSB used for a special purpose? (cfr. maple_tree, which uses > > bit 0 (https://elixir.bootlin.com/linux/v6.12/source/include/linux/mapl= e_tree.h#L46)? > > AFAIK no, the goal was just to prevent misaligned accesses. Kees added th= e: > > s->offset =3D ALIGN_DOWN(s->object_size / 2, sizeof(void *)); > > so maybe he had something else in mind. But I suspect it was just because > the code already used it elsewhere. > > So we might want something like this? But that would be safer for 6.14 so > I'd suggest the io_uring specific fix meanwhile. Or maybe just add the un= ion > with freeptr_t but without __aligned plus the part below that changes > mm/slab_common.c only, as the 6.13 io_uring fix? As it seems to work fine with s/sizeof/__alignof/, I have submitted a patch to just make that change https://lore.kernel.org/80c767a5d5927c099aea5178fbf2c897b459fa90.1732106544= .git.geert@linux-m68k.org Gr{oetje,eeting}s, Geert --=20 Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k= .org In personal conversations with technical people, I call myself a hacker. Bu= t when I'm talking to journalists I just say "programmer" or something like t= hat. -- Linus Torvalds