Received: by 2002:a05:7412:da14:b0:e2:908c:2ebd with SMTP id fe20csp507713rdb; Fri, 6 Oct 2023 09:39:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE4DE6dsZO3kxY+K5uj4NQhPKAJ149LpE/SAGnyX7PdFfCiFfOlZlzTs5w1b7aXsWcHdnrY X-Received: by 2002:a17:903:2282:b0:1c7:562d:9b16 with SMTP id b2-20020a170903228200b001c7562d9b16mr10734587plh.24.1696610393326; Fri, 06 Oct 2023 09:39:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696610393; cv=none; d=google.com; s=arc-20160816; b=ZZ6M4KemvuwY26/+V0lPnPPuG70CkL3+sXCiXokoO+qvAc4wwPTBiyfbzZTYowaVll EnjkKXrHSCrmCOWkqVx9psdd2C4Gd6sO7aGNw0wwaCufNn5z6lLTaTBppNz4SRi7XfKu XLAwud6/pkQyOU0wVAd+aVUzajHhrxXaBDjw1NgZhNDICGoc5G9aY0DUPiBPrfsXn4sd NPwoBtXmtg7mAen5K1ZcN+mCdRHwaK5DJMxLDogAZJTCp+fNZqUVidFuyKl7QuqW+wFa nBV/OO5gvvh7aFsZBmv4DOPZ5cmqqNT3x2geRAD3U5CEnT8ziD29mNc3hja3XKo2MViE 7KKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=9YzQCmKvO5tSOSdFz4LvmqIh9CyzLcIKseY+JLRSBqw=; fh=KBy80kAou9uqpSn04UKtB5oSkzbZkkANAFJvHVZ+Mfo=; b=Ce9V0vCwrAUFxHyohBHU88ANWfqP4l8jkOCHvTFML8bmLVtDtllNSNnivnWPDkiJqt 0uVw3NcZ7h1ucZRAJqAEXHKv5NlvBeF7LlLhRMPil/neUmGxsfRwgjeVSUdWCp7dSFCo 0SU5q1QSO8XcZQBVXlJkFOi0v/PZdcBU1/fz2PDMKVfckDKFvIrb6jidm5SemlWrHrvG gSWsS/G4nVB5a0DJuVbezGur5ys6k0+oZ7dJXI3E6u046C+SrV2SLdEl7IMgA74rv8sB OppfF7Tv1k6d13r/ioGpVRcb1IjPdJcKbxbXMGU5aYyjWOIWjL+gCAGTFHQrIy1xqyfP 1cbg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id j17-20020a170902da9100b001c3a06b4fd7si4170817plx.561.2023.10.06.09.39.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 Oct 2023 09:39:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 8ECBF80755D0; Fri, 6 Oct 2023 09:39:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232829AbjJFQjk (ORCPT + 99 others); Fri, 6 Oct 2023 12:39:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232496AbjJFQjj (ORCPT ); Fri, 6 Oct 2023 12:39:39 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8E666AD for ; Fri, 6 Oct 2023 09:39:38 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C7730C433C8; Fri, 6 Oct 2023 16:39:36 +0000 (UTC) From: Catalin Marinas To: linux-mm@kvack.org, Andrew Morton Cc: linux-kernel@vger.kernel.org, Mark Rutland , Vlastimil Babka , Peter Collingbourne Subject: [RESEND PATCH] mm: slab: Do not create kmalloc caches smaller than arch_slab_minalign() Date: Fri, 6 Oct 2023 17:39:34 +0100 Message-Id: <20231006163934.3273940-1-catalin.marinas@arm.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Fri, 06 Oct 2023 09:39:52 -0700 (PDT) Commit b035f5a6d852 ("mm: slab: reduce the kmalloc() minimum alignment if DMA bouncing possible") allows architectures with non-coherent DMA to define a small ARCH_KMALLOC_MINALIGN (e.g. sizeof(unsigned long long)) and this has been enabled on arm64. With KASAN_HW_TAGS enabled, however, ARCH_SLAB_MINALIGN becomes 16 on arm64 (arch_slab_minalign() dynamically selects it since commit d949a8155d13 ("mm: make minimum slab alignment a runtime property")). This can lead to a situation where kmalloc-8 caches are attempted to be created with a kmem_caches.size aligned to 16. When the cache is mergeable, it can lead to kernel warnings like: sysfs: cannot create duplicate filename '/kernel/slab/:d-0000016' CPU: 0 PID: 1 Comm: swapper/0 Not tainted 6.6.0-rc1-00001-gda98843cd306-dirty #5 Hardware name: QEMU QEMU Virtual Machine, BIOS 0.0.0 02/06/2015 Call trace: dump_backtrace+0x90/0xe8 show_stack+0x18/0x24 dump_stack_lvl+0x48/0x60 dump_stack+0x18/0x24 sysfs_warn_dup+0x64/0x80 sysfs_create_dir_ns+0xe8/0x108 kobject_add_internal+0x98/0x264 kobject_init_and_add+0x8c/0xd8 sysfs_slab_add+0x12c/0x248 slab_sysfs_init+0x98/0x14c do_one_initcall+0x6c/0x1b0 kernel_init_freeable+0x1c0/0x288 kernel_init+0x24/0x1e0 ret_from_fork+0x10/0x20 kobject: kobject_add_internal failed for :d-0000016 with -EEXIST, don't try to register things with the same name in the same directory. SLUB: Unable to add boot slab dma-kmalloc-8 to sysfs Limit the __kmalloc_minalign() return value (used to create the kmalloc-* caches) to arch_slab_minalign() so that kmalloc-8 caches are skipped when KASAN_HW_TAGS is enabled (both config and runtime). Fixes: b035f5a6d852 ("mm: slab: reduce the kmalloc() minimum alignment if DMA bouncing possible") Signed-off-by: Catalin Marinas Reported-by: Mark Rutland Cc: Andrew Morton Cc: Vlastimil Babka Cc: Peter Collingbourne Cc: # 6.5.x --- The previous post was messed up by my git send-email configuration, so sending it again. Also cc'ing Vlastimil since he reviewed the previous slab changes for ARCH_KMALLOC_MINALIGN. Thanks. mm/slab_common.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/slab_common.c b/mm/slab_common.c index cd71f9581e67..8b45922ed295 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -895,10 +895,13 @@ void __init setup_kmalloc_cache_index_table(void) static unsigned int __kmalloc_minalign(void) { + unsigned int minalign = dma_get_cache_alignment(); + if (IS_ENABLED(CONFIG_DMA_BOUNCE_UNALIGNED_KMALLOC) && is_swiotlb_allocated()) - return ARCH_KMALLOC_MINALIGN; - return dma_get_cache_alignment(); + minalign = ARCH_KMALLOC_MINALIGN; + + return ALIGN(minalign, arch_slab_minalign()); } void __init