From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 42BF52D9EDC for ; Mon, 13 Jul 2026 15:31:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.208.51 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783956666; cv=pass; b=T7Ob5mQO7usTQ12F2qw/alCInqzqwKy6E14WgTdSjhaaf4nvFr9gxMO93R+mAMWxpgvwU0pRXNvmcskuYnVystZofzIxLOyqN6NfKoURWd/BHxPRo6RwXf5emFQGsbj2b7+QiYhy1DbzVBH55qMEeDe5+tWcsGLY0HPzD/KAfAo= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783956666; c=relaxed/simple; bh=dWFj4wREswixPsuVWe0/st2YgEmkKiwnB7JmjWUogNU=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=ekl4Qpm4p5Yet/eAncWYHjCHyabXtwKv4HSOoF6NVvbTRIyDNwuEMNUyhGG45HmRkvc8J04SxVFQvWcICQ5JtZMuT6LrQ5bLcyiVSzgL77AwoPhcTQ/UGxEohsoZX9ZcZMqYkAvI0cvMax2JdPwlLL1WkkYC+HoTrbJV6rSG8FI= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=Jfy4hIOL; arc=pass smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="Jfy4hIOL" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-698411099d6so22220a12.0 for ; Mon, 13 Jul 2026 08:31:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1783956664; cv=none; d=google.com; s=arc-20260327; b=BOXc7U9vV3qadcGTREXOEFYdjGZIxU8MJa8g+GiodrTWcFrnX68xC/DG7SMk5La/9A SUmLdA2bRdyAQn/RYGct9PkYJaz4c1Q8996bvEXL/Mq9woyliMPtNq24SdKaRvNFVg3d L2EUQ9mHG/0DrIGJL2fJZfqDCE7qVmcEERbDKtcnBmDBgU0CXbOQfGyL3a0YNL2gsQNO A7gWlhjcE81henqRDmZCJ3Za+nHDbrpjqclfOR2cHfsYcL/oPcdz9NBa2VxWknMVEPZ6 yibv3IzqtoAqGBv08cK6xqEzkLrtbGUR+JqtRk4C4a0xf+UIaItCX1WJLX7b1yoeif2o S9sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=qbt5BRPE2/VNpMrqU9PmvR5KvhJPvU8lbEOiFn703D4=; fh=TeD7o6+nqGQT1+K5BbZEQlySAFcLDRTT6uMebIziOyw=; b=PRfZ4vcA+JPgnMKDW85xO9hnSlNB5lWxl7+Rue/BE4mWqxTKWLR9XwB/035rdXvUvf iw4AXi/MrPhOyBo3fmBUBrI7wQRpwUcsi0HFDPxtED4izUhnfc9bSsBUoXUI/XQntq26 4KYvlo/wgvQbRJsHqTav7sFl2h6PkI+DbFJgNuhUsfnBqlWum54/O5CEDMVG4VfkFnLZ 7/9qLAVhdHHoFVtHBLsOiuXWGxIFGEgrXEWvW/4fnrADFwcXlo7IvTR3f/UBoA/FgytI O0ALG/m2jGf5UB9PDAWcnaJMVHMGoboktdaRFM/WPVkRSS8qfu4Sii3hWL2cwUmJOT4Q 0aiQ==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1783956664; x=1784561464; darn=vger.kernel.org; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:from:to:cc:subject :date:message-id:reply-to:content-type; bh=qbt5BRPE2/VNpMrqU9PmvR5KvhJPvU8lbEOiFn703D4=; b=Jfy4hIOLGkdHzAtSzm9pCMYS2D/JRSeqCiER4GUbI7VjHugsIM2jm5y+/slNiA0cxC RM8m8Tloqz1G0a1kocXwgQ1vct7r3iXvk87lvIZUvI+wPGnUk8WrG4wP4xkYGWhvaO0f uy6RWSdO1FCO+Ktwu6bOf9lKo9Mc4JflxLfVVIZgyw6Vg9qgHaOfJqN0uzDhoP10iB06 X/JrKLrwwXB9iv32nFV6wIWq7TLAYshXfvLkaShtWqKYN2xkRLbXx/JLgIRH3YTWh0jV PnMi4f6fSXwHuYFdMVR8HVVF050CxgrXWL7ZHdp5lumVv0RwqRylu4b8dpVnhzFICyEp qz8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783956664; x=1784561464; h=content-transfer-encoding:content-type:cc:to:subject:message-id :date:from:in-reply-to:references:mime-version:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=qbt5BRPE2/VNpMrqU9PmvR5KvhJPvU8lbEOiFn703D4=; b=AlFWxht3UETc+buBTERrAlzAn6OQi0My9YVoy4jWACaFBHHZFhoFnfVZElNC9gbtPl sM7UM8KAd5uNfgSCwtxuhTuXJ5riCppJQVQtYpoXExu3+pyczuZTxmKpyEEKJMNDKHlQ CRY1oNif4r/RZ9UZA8Hi6BZmTH16ar+tcCv30j0We54j1WIYyLjqfL2Z/YwB1udMpIVy d8zxoa+TL1vSEYzxCiLpJ6q5IdElOWO6LklJSXnHril+cTQfxE8jEb7MqCObEXRSi4MU ESvJGw+ULZN8cnLzs4AMurrASMYf5QPb61HwsXJ4pgeTNNpKr/Wmv3M+3Pzcu+e3Lb2b 9GNg== X-Forwarded-Encrypted: i=1; AHgh+Row+o8KwSNQgGf03cdrEVf8zLs9+lIhlyRK/ejdm7X/Qe0JXkmtJSEDtTmA+pRgkpH0Z9fCWqmA0/y18zo=@vger.kernel.org X-Gm-Message-State: AOJu0YxWcsuXxrl8j9FnpszozfcD/fWo9SRGCIRT0MroTqDmoaOfxmSi r7awwH91GyrOx2iAsuTFvc7Vh41TE7hSjhSMVDUrF1xLg31AKz7Y0668jIVrGXTx2S7SfpaWL2s HpYg0FOX2arWFJMGi36MfEPJ5DzRAM0VMtwgZYybn X-Gm-Gg: AfdE7cnVkSuSoXj9WUZOcECrr3OHbFhdDzArNlpv4l2I2a1FdtKZpSqeClONs05iOyl tOj6AK71bowe0NGnEs3B1afb4dzoGXdYavbodg8/CLxrtzHVodstIK0bBzVm/7/u8xH0VU4ULne 7aqdgLooIzC2I4sGLCiSjZbiQVzSeOFufT44nkyDrxrApwK3ybe8YuV3nJkI+OgY09D+ZVAkeFj f0cCeZVvj/5/dPDDystPXpSe8WLbecaH7MlcBGKDOa1o1sKF8BuB9Q9fKOw4ajndJ1c/1U= X-Received: by 2002:a05:6402:1299:b0:69a:df95:f1f8 with SMTP id 4fb4d7f45d1cf-69ccf043065mr29225a12.2.1783956663191; Mon, 13 Jul 2026 08:31:03 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20260713-kmalloc-no-objext-v3-0-47c7bd138de7@kernel.org> <20260713-kmalloc-no-objext-v3-1-47c7bd138de7@kernel.org> In-Reply-To: <20260713-kmalloc-no-objext-v3-1-47c7bd138de7@kernel.org> From: Suren Baghdasaryan Date: Mon, 13 Jul 2026 08:30:49 -0700 X-Gm-Features: AUfX_mwtwntOQ1FE8zxpHTirJrWk6btBrdGwgD-u1-yJBAH5BNHYFtYPFrBZOt4 Message-ID: Subject: Re: [PATCH slab/for-next-fixes v3 1/4] mm/slab: fix a memory leak due to bootstrapping sheaves twice To: "Harry Yoo (Oracle)" Cc: Vlastimil Babka , Andrew Morton , Hao Li , Christoph Lameter , David Rientjes , Roman Gushchin , "Liam R. Howlett" , Hao Ge , Kees Cook , Pedro Falcato , Shakeel Butt , Danielle Constantino , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Jul 13, 2026 at 7:29=E2=80=AFAM Harry Yoo (Oracle) wrote: > > When kmalloc caches are aliased, multiple cache pointers reference > the same kmem_cache. As a result, iterating over kmalloc indices and > bootstrapping sheaves can bootstrap the same cache more than once and > leak memory. > > Currently, this could happen when the architecture specifies > minimum alignment for slab caches that is larger than > ARCH_KMALLOC_MINALIGN. > > Bootstrap sheaves only when the cache does not have them already. > Add a warning when bootstrap_cache_sheaves() is called for a cache > that already has sheaves enabled. > > Cc: stable@vger.kernel.org > Fixes: 913ffd3a1bf5 ("slab: handle kmalloc sheaves bootstrap") > Signed-off-by: Harry Yoo (Oracle) nit: Don't know if we really need a warning... I would just do an early return from bootstrap_cache_sheaves() if cache_has_sheaves() is true. But that's not critical. Reviewed-by: Suren Baghdasaryan > --- > mm/slub.c | 9 +++++++-- > 1 file changed, 7 insertions(+), 2 deletions(-) > > diff --git a/mm/slub.c b/mm/slub.c > index 65febe957886..f9461a0c47d3 100644 > --- a/mm/slub.c > +++ b/mm/slub.c > @@ -8497,6 +8497,8 @@ static void __init bootstrap_cache_sheaves(struct k= mem_cache *s) > bool failed =3D false; > int node, cpu; > > + VM_WARN_ON_ONCE(cache_has_sheaves(s)); > + > capacity =3D calculate_sheaf_capacity(s, &empty_args); > > /* capacity can be 0 due to debugging or SLUB_TINY */ > @@ -8548,8 +8550,11 @@ static void __init bootstrap_kmalloc_sheaves(void) > > for (type =3D KMALLOC_NORMAL; type <=3D KMALLOC_PARTITION_END; ty= pe++) { > for (int idx =3D 0; idx < KMALLOC_SHIFT_HIGH + 1; idx++) = { > - if (kmalloc_caches[type][idx]) > - bootstrap_cache_sheaves(kmalloc_caches[ty= pe][idx]); > + struct kmem_cache *s =3D kmalloc_caches[type][idx= ]; > + > + /* Do not bootstrap twice when caches are aliased= */ > + if (s && !cache_has_sheaves(s)) > + bootstrap_cache_sheaves(s); > } > } > } > > -- > 2.53.0 >