From patchwork Sun Aug 4 21:28:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Falcato X-Patchwork-Id: 13752725 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 94772C3DA7F for ; Sun, 4 Aug 2024 21:29:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6E87D6B007B; Sun, 4 Aug 2024 17:28:59 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 671916B0082; Sun, 4 Aug 2024 17:28:59 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4EA476B0085; Sun, 4 Aug 2024 17:28:59 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 2C9986B007B for ; Sun, 4 Aug 2024 17:28:59 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 72E6B141B63 for ; Sun, 4 Aug 2024 21:28:58 +0000 (UTC) X-FDA: 82415853156.12.4F0DB29 Received: from mail-wr1-f43.google.com (mail-wr1-f43.google.com [209.85.221.43]) by imf29.hostedemail.com (Postfix) with ESMTP id B1B31120008 for ; Sun, 4 Aug 2024 21:28:56 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YUkUtkjT; spf=pass (imf29.hostedemail.com: domain of pedro.falcato@gmail.com designates 209.85.221.43 as permitted sender) smtp.mailfrom=pedro.falcato@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1722806906; a=rsa-sha256; cv=none; b=bpdYAzyPdf9+mD5x/QKjDik4HyOELXiIhWo3pzmO5/Sr3VZUDR7LV1ZKAMkHmchLwY0cO0 w9+q1spGIJbKlwr+b+yowQVGZzFNySqYh9BWn8EHdfcTIyV3wXfutE8sLjb8ttc4E2BbW7 MASi6ZvSN+QsxS6JEsl+RxwWK6CN14Y= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YUkUtkjT; spf=pass (imf29.hostedemail.com: domain of pedro.falcato@gmail.com designates 209.85.221.43 as permitted sender) smtp.mailfrom=pedro.falcato@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1722806906; 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:dkim-signature; bh=o49KYqt93PDS8OfT34m5foHhWrJofzPvrqhq7NoC4u8=; b=dU7GwR7P2J+upLWsX0l8jxjIS8bMwaui25brTg0degDGWukfWx9ZyveafICKdsQ/hXMqfn F8F5xRaq/9N/ExGQVo5Z6lRN+6bphK9uEBoZMa9goSSPBQUezHIo+06LdtqtF2SseAaVM7 +lHP/+phgRyYuToyhuguPbOIDOyf+Ro= Received: by mail-wr1-f43.google.com with SMTP id ffacd0b85a97d-36844375001so4580636f8f.0 for ; Sun, 04 Aug 2024 14:28:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1722806935; x=1723411735; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=o49KYqt93PDS8OfT34m5foHhWrJofzPvrqhq7NoC4u8=; b=YUkUtkjTdIn7uPuL8pM6G1J5OB0PhHRhvpYAxqZs3+NlzihATWbV2QK/bfrnj36RUD oMMFEAtTTj7yYZB84/7KCtkJ1DRZo0FGr/ivQm7W+eznSKB6mylJg+urYquXL7beWppo QR1P+mzkdFvl4o9X3OAb2gquKkfHFljOk56BgiHlBlamgiK1jciSAwwA+/8lLbw1MCUs 6JI5vivLO71DAWhxfOWptxOlWYWCvTV0gEj6BAFYMzoLApX3hXdiYzIHfAmY07ik0/N2 OF0IxLSN6Podrf3vlpfbzt8VrdlojgtVQd4SnEIf50v1XRDrKgAIigCdW9SCQ9+U/KSg 7a9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722806935; x=1723411735; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=o49KYqt93PDS8OfT34m5foHhWrJofzPvrqhq7NoC4u8=; b=Ru7nWXg10DZCqhy4e07dKdatH0wkho2GRui+0PBpb3chnlB2VtdK4AMEEaJv8zLlyL Cb0v5WfpUeE/sv0eR4NhnltyCv8XxPFQmIykNBscwKK5M9l2l8FGpGgsxwbCt0TDIQhi 4+rkD6ffCn9kP+C+7uS5QlcdUWuFi3diOJiV0lR8RVyH9ADJw3UitMfbJVCTuJ1TTudh ho8B/pH1HkA34kB631J/4hd26+ckohXIP3v+5GdIPXobRRrLP67U7bvvHrGm2jXd1xA+ qnSDdre71zCHXeajckQbonK8RBqu4lTg/3Dpf6WWMFySWQxpnSogHtDknnnRtmsso/d/ UWbA== X-Forwarded-Encrypted: i=1; AJvYcCX4Ze4m91AsnvwKmrQQeRZ26gwViXhnQe7JeMdFC4n3KmpzSZfpnjzseLzBtqg8SSKhU4bfpyCk9iX5HVfvtJGDpO0= X-Gm-Message-State: AOJu0YwUtRwSxnxBh/2bQCuF45xQZnCiXQYt4dwAUDevh7bu/kFmnSXs Jm2heRvvk/U81p2WOssv6Bw2wbor5ghHwm3ByHgJzlUd7MlINh3PviDWrw== X-Google-Smtp-Source: AGHT+IF53ItQ0F9ASbLyWQSTd8/tD+i/q+Bav/qFx41EVaOBhLalec4gMVsrkRgYnkgFe/bCYL3HEA== X-Received: by 2002:a5d:6b09:0:b0:36b:8f4c:71d4 with SMTP id ffacd0b85a97d-36bbc0e6360mr6439167f8f.28.1722806934774; Sun, 04 Aug 2024 14:28:54 -0700 (PDT) Received: from PC-PEDRO-ARCH.lan ([2001:818:e92f:6400:96b:aa92:afc0:2d3d]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36bbcf0c309sm7846383f8f.20.2024.08.04.14.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Aug 2024 14:28:54 -0700 (PDT) From: Pedro Falcato To: Christoph Lameter , Pekka Enberg , David Rientjes , Joonsoo Kim , Andrew Morton , Vlastimil Babka Cc: Roman Gushchin , Hyeonggon Yoo <42.hyeyoo@gmail.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Pedro Falcato Subject: [PATCH] slab: Error out on duplicate cache names when DEBUG_VM=y Date: Sun, 4 Aug 2024 22:28:39 +0100 Message-ID: <20240804212839.685795-1-pedro.falcato@gmail.com> X-Mailer: git-send-email 2.46.0 MIME-Version: 1.0 X-Stat-Signature: 6ibh33j8iyu6ypuwxq53eea4hn97ojo8 X-Rspamd-Queue-Id: B1B31120008 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1722806936-298742 X-HE-Meta: U2FsdGVkX18SWDDEZgnOoCv8myLwt0X8UPMdJha2A8P76zP9PS1frecXf1ujq+zpumWc6BpMa3rkam1EcZTnSR7BcfVTLE64sbifpNFCLTw14mJajwSn7gBxcF6GMAdxrJ7XsmwJAmqS647KuCyvwDqKY48+R6S4daCm5WYoqzubqc1rNyHE0htgNZj+vSRKa4xHNrzV0a5WR4ZTZPX4UllF1uKbarJXbHT7emQrDaDIF6NN2GQZXfXDSUrK/0Smz9cNF1ekndktpNxsH18PRuV7lEavWbY9qI3Q0YvDOWMAP9iqVAnk+pl/YdXH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XP8xNmzioIQMd76+OV0rqPSAHVDkxzWbaCp8a16VhGLuBvATDpPKePgxX2M72sumg7Z/yRPRJXHZLJh+xXFC7omK953WM2ZGdSc6jyuPitTeEybw3+rO8DDw2jncrAfKi7Kg0LIgGR7e3UIbcmTF4h5Zjlz+oR/OR/DbZ4REvkEr8E+cWkMEymw0a7t/wFGyKdo6ijGt7+7Z6+R/geyKK4kThut1OPgv+f 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: Duplicate slab cache names can create havoc for userspace tooling that expects slab cache names to be unique. This is a reasonable expectation. Link: https://lore.kernel.org/linux-fsdevel/2d1d053da1cafb3e7940c4f25952da4f0af34e38.1722293276.git.osandov@fb.com/ Signed-off-by: Pedro Falcato --- mm/slab_common.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/mm/slab_common.c b/mm/slab_common.c index 40b582a014b..c4f31c887f9 100644 --- a/mm/slab_common.c +++ b/mm/slab_common.c @@ -88,6 +88,19 @@ unsigned int kmem_cache_size(struct kmem_cache *s) EXPORT_SYMBOL(kmem_cache_size); #ifdef CONFIG_DEBUG_VM + +static bool kmem_cache_is_duplicate_name(const char *name) +{ + struct kmem_cache *s; + + list_for_each_entry(s, &slab_caches, list) { + if (!strcmp(s->name, name)) + return true; + } + + return false; +} + static int kmem_cache_sanity_check(const char *name, unsigned int size) { if (!name || in_interrupt() || size > KMALLOC_MAX_SIZE) { @@ -95,6 +108,12 @@ static int kmem_cache_sanity_check(const char *name, unsigned int size) return -EINVAL; } + if (kmem_cache_is_duplicate_name(name)) { + /* Duplicate names will confuse slabtop, et al */ + pr_err("%s: name %s already exists as a cache\n", __func__, name); + return -EINVAL; + } + WARN_ON(strchr(name, ' ')); /* It confuses parsers */ return 0; }