From patchwork Wed Nov 20 12:46:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 13881124 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 C0645D63933 for ; Wed, 20 Nov 2024 12:46:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F1CC6B0099; Wed, 20 Nov 2024 07:46:38 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A1CB6B009A; Wed, 20 Nov 2024 07:46:38 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 169E96B009B; Wed, 20 Nov 2024 07:46:38 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id ECEA86B0099 for ; Wed, 20 Nov 2024 07:46:37 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 74F961C71BF for ; Wed, 20 Nov 2024 12:46:37 +0000 (UTC) X-FDA: 82806446730.29.86A9354 Received: from michel.telenet-ops.be (michel.telenet-ops.be [195.130.137.88]) by imf12.hostedemail.com (Postfix) with ESMTP id 917814001D for ; Wed, 20 Nov 2024 12:46:12 +0000 (UTC) Authentication-Results: imf12.hostedemail.com; dkim=none; spf=none (imf12.hostedemail.com: domain of geert@linux-m68k.org has no SPF policy when checking 195.130.137.88) smtp.mailfrom=geert@linux-m68k.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1732106703; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=vM8Sh/ukEl6HwD21Qo/Zj5fQFuyTX3xsCGgKtfV0M5Y=; b=BjMn0sMXvH3HxkpnpYSuD9h6BYDjFoNtnaAG3L5biZL0PAR9+kA7ktDnEu91s33UbWZXkv jcPNExlg/3xhpZfWqyR8e6UkK/olj6SfwKyIrm5PPN/epMGVNnGyJgLLQBt2OAr/iP71VT 1flUzL1pSotJJye58xizImTS8WTXtCk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1732106703; a=rsa-sha256; cv=none; b=ar2BsW5+gTzevtY6iizumCFiEzu+TJYuoTopx6l5b8pb/0pULfftZbgPpE31HWUK9gperD yePAxr/LLqzCIr7fwr8HBMn0d2mDQ02csTq8j536V7dVeBjd5elLoYH9vZVgpzPySklRRH P3/4ziAnsboi77UsXH5GLW5m6ZjMlGU= ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=none; spf=none (imf12.hostedemail.com: domain of geert@linux-m68k.org has no SPF policy when checking 195.130.137.88) smtp.mailfrom=geert@linux-m68k.org; dmarc=none Received: from ramsan.of.borg ([IPv6:2a02:1810:ac12:ed80:35da:ab43:467b:7991]) by michel.telenet-ops.be with cmsmtp id f0mP2D00H3gUftr060mPnS; Wed, 20 Nov 2024 13:46:34 +0100 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.95) (envelope-from ) id 1tDk5o-007c0T-5O; Wed, 20 Nov 2024 13:46:23 +0100 Received: from geert by rox.of.borg with local (Exim 4.95) (envelope-from ) id 1tDk6B-009N9j-E0; Wed, 20 Nov 2024 13:46:23 +0100 From: Geert Uytterhoeven To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka , Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, Jens Axboe , Pavel Begunkov , Mike@rox.of.borg, Rapoport@rox.of.borg, Christian Brauner , Guenter Roeck , Kees Cook , Jann Horn Cc: linux-mm@kvack.org, io-uring@vger.kernel.org, linux-m68k@vger.kernel.org, linux-kernel@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH] slab: Fix too strict alignment check in create_cache() Date: Wed, 20 Nov 2024 13:46:21 +0100 Message-Id: <80c767a5d5927c099aea5178fbf2c897b459fa90.1732106544.git.geert@linux-m68k.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspamd-Server: rspam10 X-Stat-Signature: s6ktcbojgh9nh97ehcdngijunnfa19j1 X-Rspamd-Queue-Id: 917814001D X-Rspam-User: X-HE-Tag: 1732106772-135682 X-HE-Meta: U2FsdGVkX1/JXd6/eY2YURaRKNS29KWuqiNRDIfDrlN6Y1dE144Rk1NatNqtIT+V+lMFod4hsZkZV48dP3Gxn4X0zVy6oS0dkpt+NbgqTaFlN/fghhMNYekdRyyaGA7YLsP+quGmt9cs2bAAw6dP9rmrOROnk9yxX3DKg7uTcx25qqq7TF4MEriKudSryRFUZrWljuA9KJF/tlalb4OX1eJUAKxptG69hoCLxLgRwvFOMXLzzO10ZMsIyaKFtooYthbfiknITsBM6tk+PqprujQmmXkooAJT1rxgi43hz8Ms2A5jzR2tKxhDFjBRXmg3R7qP56gKGvRLgydcX8XZ+QJhLENtLuILoPYRlUZv+zpa/snIMIpLJwGffEKwxUxtWl4/Pnw4/HxfuksFRY4FxReHDVDZFRTOltYtYmkD+6/KH89/PtR9oypgzereqKNFvnfIhkDDJWlJZVgzttHrQ5hK0Jc6ymGXw4X3M2Qx40dLY21a9zmZUxivN5PNt4S2Q6Z5iFivLOcenkk5fUDvfzhvqbEU9i4pgU964DUGFLODnuXSCEaB0ZGJoTNahXWdfm9agMamu/PJ0X06OvIEZv+xuI6o/vLzr0u1NKFIpy+r7IvtY5AOO/1zuV9crRY81jBhw43FcUD0m8UQM3ArUKyiGrIPDNZHfeeheUNKqmRW0JWb50FvOfzVHrqeXK/anBSpNeN7vvz8SCIvYR0fMrmMZK9auXfa/vhb6yVPn8cc1Thsv0XAIlANCz6sL2ubll8GLX0lmTTWYRy3MbjQOquEwri5Q5wuZnwnIG69HV+cA1Pa/sA/CmOy8//DO2tRqgsZHjCoNlJmQogef8rJB89xNYI2T9ZE1dohuU0LHYbB7m6vLoRpbPhXLL5xEAVveBcRRmXwgYOgvVW1eiz1TrY7BsLTmQNAY3JXuI2DEGRdbic00Lbtsvq7IRCV6AefejDLqRmkKwKsfRfk8q3 X6j55u2u TgZQifFaesf3Q7Oq1+B351zLITRwmmvLS04jNruA3or8anFcZMHIeoMVdSP8/TCJUl5RFW0uac4hLx65h1PN7clGG2SfJUfd6gG07cX6P/EVVuqAXSUT/6iek1jZKnx12AmehAm9U1RWnGCCwUgs2T3IurxIEIxCdTY/LgIGRn8ZymlU/IyKnyPekq9z2e01ChokyNrZ38ilnUez3P65jBBb92ZzKwzppvl29/L8IOUOvMsz0WpdR/tyT0BtD+Rdsfnd+SSTYzT7QQFlkDUFJZOOOal9Rz8BDXVovYLrCIyOsZbA= 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: On m68k, where the minimum alignment of unsigned long is 2 bytes: Kernel panic - not syncing: __kmem_cache_create_args: Failed to create slab 'io_kiocb'. Error -22 CPU: 0 UID: 0 PID: 1 Comm: swapper Not tainted 6.12.0-atari-03776-g7eaa1f99261a #1783 Stack from 0102fe5c: 0102fe5c 00514a2b 00514a2b ffffff00 00000001 0051f5ed 00425e78 00514a2b 0041eb74 ffffffea 00000310 0051f5ed ffffffea ffffffea 00601f60 00000044 0102ff20 000e7a68 0051ab8e 004383b8 0051f5ed ffffffea 000000b8 00000007 01020c00 00000000 000e77f0 0041e5f0 005f67c0 0051f5ed 000000b6 0102fef4 00000310 0102fef4 00000000 00000016 005f676c 0060a34c 00000010 00000004 00000038 0000009a 01000000 000000b8 005f668e 0102e000 00001372 0102ff88 Call Trace: [<00425e78>] dump_stack+0xc/0x10 [<0041eb74>] panic+0xd8/0x26c [<000e7a68>] __kmem_cache_create_args+0x278/0x2e8 [<000e77f0>] __kmem_cache_create_args+0x0/0x2e8 [<0041e5f0>] memset+0x0/0x8c [<005f67c0>] io_uring_init+0x54/0xd2 The minimal alignment of an integral type may differ from its size, hence is not safe to assume that an arbitrary freeptr_t (which is basically an unsigned long) is always aligned to 4 or 8 bytes. As nothing seems to require the additional alignment, it is safe to fix this by relaxing the check to the actual minimum alignment of freeptr_t. Fixes: aaa736b186239b7d ("io_uring: specify freeptr usage for SLAB_TYPESAFE_BY_RCU io_kiocb cache") Fixes: d345bd2e9834e2da ("mm: add kmem_cache_create_rcu()") Reported-by: Guenter Roeck Closes: https://lore.kernel.org/37c588d4-2c32-4aad-a19e-642961f200d7@roeck-us.net Signed-off-by: Geert Uytterhoeven Tested-by: Guenter Roeck Reviewed-by: Jens Axboe Reviewed-by: Christian Brauner --- mm/slab_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index 893d320599151845..f2f201d865c108bd 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -230,7 +230,7 @@ static struct kmem_cache *create_cache(const char *name, if (args->use_freeptr_offset && (args->freeptr_offset >= object_size || !(flags & SLAB_TYPESAFE_BY_RCU) || - !IS_ALIGNED(args->freeptr_offset, sizeof(freeptr_t)))) + !IS_ALIGNED(args->freeptr_offset, __alignof(freeptr_t)))) goto out; err = -ENOMEM;