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 BF14FC2D0CD for ; Thu, 15 May 2025 17:34:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 34B386B00A4; Thu, 15 May 2025 13:34:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2FB186B00A6; Thu, 15 May 2025 13:34:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1C3476B00A7; Thu, 15 May 2025 13:34:52 -0400 (EDT) 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 F2BB66B00A4 for ; Thu, 15 May 2025 13:34:51 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id AA3BF58E6B for ; Thu, 15 May 2025 17:34:53 +0000 (UTC) X-FDA: 83445842466.05.E33AFA7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 40AA4C0012 for ; Thu, 15 May 2025 17:34:51 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=facQrcDD; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of jkangas@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=jkangas@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1747330491; a=rsa-sha256; cv=none; b=1Wm2nDLQgNtMD7PnoJgprZ6V3dRFxsBjUpxzwtEyVSoafSiyCki2xdEYRwj6ZezPEGoZSv METTV+1SZfDn1Ied5QXhMJ/GhwrL78J/C/pGM1RjnOz2Q1RZg3C6XAU1gzxS2RidOLRYVB 2x2Qrp03+bxcUzGallWwLcuzWHUdhnc= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=facQrcDD; dmarc=pass (policy=quarantine) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of jkangas@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=jkangas@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1747330491; 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:dkim-signature; bh=JzW1ncmGIssHd/HfDZiOZGsvu/9kuBuxxssqGBqcsRw=; b=Opw4UswJfeXsdnN2LxGFmv7/Ge5Cnvh65VRC0eQWsIArwSEF2kljVbOD2PDYU38s+zj3Se 3lXZA2DQfvQvgi0ikdAz3/0wzoXnsxH1R5hr4v0tPjUGv2k17rTIofD6RpuZdBb5PHrfXe saxOaRj6Fpaaj8oQ92w+Fm4ghR0GC+4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1747330490; h=from:from: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=JzW1ncmGIssHd/HfDZiOZGsvu/9kuBuxxssqGBqcsRw=; b=facQrcDDp6j9RJqzVBf4LAdTZ1N1VnlbM+eSuqgoRdd5KoaUNS82cI8vmW4mEwbuWTjTM4 N88V08zlVFNayVIrEbMHFYGFmh5d4rNV3D6fHChKS455fAPSD3O9CK2EbF9OpoqUCC7i9/ bD4QmfFKLUcbKZkLLpBeB5xm2Z82kqc= Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-125-Kd9WEfd2OzqVivdsnlKzAA-1; Thu, 15 May 2025 13:34:49 -0400 X-MC-Unique: Kd9WEfd2OzqVivdsnlKzAA-1 X-Mimecast-MFC-AGG-ID: Kd9WEfd2OzqVivdsnlKzAA_1747330488 Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-22fba2426f5so10935135ad.3 for ; Thu, 15 May 2025 10:34:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747330488; x=1747935288; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=JzW1ncmGIssHd/HfDZiOZGsvu/9kuBuxxssqGBqcsRw=; b=weAWqiA202AG0BaBt4uXm4Me8BH2wP0kPHD9Q5ChQ4m/28YwhJPc2DjEux6Qn4dUqH o8CbfklxBjDU5XLwHPouco1zQ20WHzB8mbJge0k6fMtQxbf3P++tnHuDdc5nJFVPAW/n dbUmH0b3f+yI53aI8rKqx5LxczJRJCzUfQvsPYJiid+Syl5hBilU7WeT2+7z5TO9y7tR 9IU7EXmxnqlYL/0qg1tHfTTjrJCjsRTgrWggM1kjEkiNHd6dT3IFwXJHQdfyIAtQlZYf WQWSb83Kg34mLV640QgiZbJ7ULvJj1tb6EjljgTNe9gUPlZtmN/HXZmefSyv2Xa/06pP RuNA== X-Forwarded-Encrypted: i=1; AJvYcCXv02FzalOs+h+e+7BJ1a9lMykejZTCVh/NwZZoCpyFoYOyeN8bOhdg/SHBClDXGEqHO6ePmemiGQ==@kvack.org X-Gm-Message-State: AOJu0YzGMgsMEO5OEC5IGRGDi0bzrj4ph1QpikW0vDb9qIvluP/Cc4X3 lLD35cQFQ9vHHUfXcEGnnfm7UJoFOiK+CaZZSm0TtMvJI5rqdvoCMxw7yW7tyfZg/SdYPYpWo5m gVqiouNCZlZUau4JGADXUMeifrRrdXvUEjabmRSkKocWiAq0nnLRv X-Gm-Gg: ASbGncs6wtdRp86DRhKQ3T7k2eFIx38CX4/0cL37IfMxHx4a2m16ZBk4QsiqvF2PxaS POWhuhyHsSt9E+EvUuUhy3X3223OGc3EYyLnJCkPiAvvdbr78N777QhlSxqmZlToilZGa0B00Te Npd51mXrv3rqYo34aREdXcvvuRof+GzWm9WQbMXjQTgbaoJLXZV++gKy2tuYmzXrvK1v9jHGV+p YE5DgOfbGe9kCaawGclrFV4NG2shvOIan92eQk5YdENDu1LXml4kmuZaL4pJOkL9Y755CUmDUYA H0yzCuxhggHSwnNncg2UZK3Ls/zCuN+NgBuohuNDmnM= X-Received: by 2002:a17:902:da82:b0:22e:4db1:bab6 with SMTP id d9443c01a7336-231d4393f02mr4180845ad.7.1747330488254; Thu, 15 May 2025 10:34:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFBe+Ke/qwyU6fFT7oBxlEVHfXyA2MrJZn7X/qjBoNpqR62jEkXEDjFmblbWpUDJxPVZ8WEsQ== X-Received: by 2002:a17:902:da82:b0:22e:4db1:bab6 with SMTP id d9443c01a7336-231d4393f02mr4180605ad.7.1747330487850; Thu, 15 May 2025 10:34:47 -0700 (PDT) Received: from jkangas-thinkpadp1gen3.rmtuswa.csb ([2601:1c2:4301:5e20:98fe:4ecb:4f14:576b]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-231d4ac9fbdsm566145ad.50.2025.05.15.10.34.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 May 2025 10:34:47 -0700 (PDT) Date: Thu, 15 May 2025 10:34:45 -0700 From: Jared Kangas To: Lorenzo Stoakes Cc: willy@infradead.org, akpm@linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Liam Howlett , Sidhartha Kumar Subject: Re: [PATCH] XArray: fix kmemleak false positive in xas_shrink() Message-ID: References: <20250512191707.245153-1-jkangas@redhat.com> <053ad5f9-3eee-486e-ac29-3104517b674a@lucifer.local> MIME-Version: 1.0 In-Reply-To: <053ad5f9-3eee-486e-ac29-3104517b674a@lucifer.local> X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Cs9nzjcfEUeDYn2TpGpq7CCmSiF7P2b2UqNdFqHdx_o_1747330488 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Stat-Signature: ai5hz3owwzx1y4y6f6th5hp8hfmjbwd1 X-Rspam-User: X-Rspamd-Queue-Id: 40AA4C0012 X-Rspamd-Server: rspam06 X-HE-Tag: 1747330491-761876 X-HE-Meta: U2FsdGVkX18oHLfxLhUIAwtovmObdNx1mKquESOhd0kxhDb4Fj02RxEmb3nDx0/8LKRkW0ZJOgFXUkI+2GaLokRNclbrcK0vFO0+qyELFS+CFKyikhEJexuUrWdEebhOhb64oomw/sRuFrVOlWRHQv/5LxfBdCuHhHEcTZBQ/IXGGiL57DBeBjLGRYqhi+F19qZuFj1eLThWbuOszAXyyz0xasaqzZDIoyoitg3g08KYWf/9WKAWBBV7eDmfWE7BVaNV1NJAi0waK7J9I/TF5LYkX5/hiJBrI8KxUzIJYGCXaBMp+EYiAR1BVxabMSl7amn+Gwrg7et9zqv4LxM4rECcXhCoSxGv/7YaMSE2lJOtyB3ZilaKyo+RMQodXxYmMrPaL4oj7UEvYAL12pMqv8m4niPzWHJ1nKcNlALkQdGOEDPHvWfSkbkuMJ1ep0EAj+FLyTn2tholGO54wgy/s+O15JB3ETsjRJIVtVLGMcFxGLdIcWxGTP6I0leixr7GwaDZFhSRSMJHWoMLwULL0/y7G25H4c+YlSpIAa5cMUqrZRfdlxeZerSk7PBJMvzrVXDCe40NgdXp6aaWYZ6AfQEbUdkn2tos0hPGdKaTlz+dqLvPoB55a+sMR+69q/+i/gK6DnBCy5PZ08yaTfhTBCOSlS6z5XERu/ibEZH/IyZdAxOlyHYP2JlgfIlGt7tjoqBYjr+G2l50asvw/ULFrRMjtUt8P7MsuN2IZuQ+/NGRiDBLyakAZT9iX3wY0FggfcLY1DrY3jZiM5qPzlQvaK0l7h6OeMakHb0Z07Vz1qDREQnpSaXdZLwElkh98iYAGNOlLCHE58nW+v9hR1LgDf/087+DECJE7DpcrQ9wfPn8HOCxUBdmragVr+rDjfhT1JoL9HBp8yU+u/oNu0xp4loz2TCiAF6GYvvnKYvNOmzYhyeo7INwq1PvEIwx8L4BoA12I6XR0aM9v0Gppf0 NDRDL5Pm aB7GsIZRjPjFeWjlBGZFFkMT0wGd4bpR+UA1dX8Unw+GHk8pexHDZ5jvpkY4Fi71rM+4uw3Ug6AVxz2lG4zRghBvZUEooXzq13UNDXPwxC4kLi/88DfVUWbxs3mJoABqG3yJQjmPBEEuks46FjeyYcx7FhHwkjJC+R8kvy3Xq/xco8FJb0PscakVRqk3cMopR3n/tGdjfbg1j8+2a3mzKahTKQHP1iZyCwmSjASRTHDJ4sQ19TGJn2ritISIdLtEko21waEuUQHXWQ6XCqx30rf8pF4vlQv59mBl1wrEJirm24fgP7XUrkMeaaOFrNzw+DrPxFLkPxNNc4IpgYoLuJf4zHIuIqWmQQA9AIh4CsMR+ZgTvEIH1GnJbupSBdpCgtlDPRJI1NqLjT66R6HZu//pGMLNcBCXh8hHQTbGX85EAn/x8aeAtceh0hhmnO3WHPs5F 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 Lorenzo, On Thu, May 15, 2025 at 03:01:56PM +0100, Lorenzo Stoakes wrote: > +cc Liam, Sid. > > Andrew - please drop this patch until this is fixed. > > Hi Jared, > > This breaks the xarray and vma userland testing. Please ensure that any > required stub are set up there to allow for your fix to work correctly. > > Once moved to mm-unstable, or at least -next this would get caught by bots > (hopefully :) so this is a mandatory pre-requisite to this being merged. Ouch, my bad! I'll make sure this is covered in v2. Thanks for catching that. Jared > > Cheers, Lorenzo > > P.S. Liam, Sid - do you think it might be useful to add us 3 as reviewers > to the xarray entry in MAINTAINERS so we pick up on this sooner? > > $ cd tools/testing/radix-tree > $ make > cp ../shared/autoconf.h generated/autoconf.h > cc -I../shared -I. -I../../include -I../../../lib -g -Og -Wall -D_LGPL_SOURCE -fsanitize=address -fsanitize=undefined -c -o main.o main.c > cc -c -I../shared -I. -I../../include -I../../../lib -g -Og -Wall -D_LGPL_SOURCE -fsanitize=address -fsanitize=undefined ../shared/xarray-shared.c -o xarray-shared.o > In file included from ../shared/xarray-shared.c:5: > ../shared/../../../lib/xarray.c: In function ‘xas_shrink’: > ../shared/../../../lib/xarray.c:480:17: error: implicit declaration of function ‘kmemleak_transient_leak’ [-Wimplicit-function-declaration] > 480 | kmemleak_transient_leak(node); > | ^~~~~~~~~~~~~~~~~~~~~~~ > make: *** [../shared/shared.mk:37: xarray-shared.o] Error 1 > $ cd ../vma > $ make > cc -c -I../shared -I. -I../../include -I../../../lib -g -Og -Wall -D_LGPL_SOURCE -fsanitize=address -fsanitize=undefined ../shared/xarray-shared.c -o xarray-shared.o > In file included from ../shared/xarray-shared.c:5: > ../shared/../../../lib/xarray.c: In function ‘xas_shrink’: > ../shared/../../../lib/xarray.c:480:17: error: implicit declaration of function ‘kmemleak_transient_leak’ [-Wimplicit-function-declaration] > 480 | kmemleak_transient_leak(node); > | ^~~~~~~~~~~~~~~~~~~~~~~ > make: *** [../shared/shared.mk:37: xarray-shared.o] Error 1 > > On Mon, May 12, 2025 at 12:17:07PM -0700, Jared Kangas wrote: > > Kmemleak periodically produces a false positive report that resembles > > the following: > > > > unreferenced object 0xffff0000c105ed08 (size 576): > > comm "swapper/0", pid 1, jiffies 4294937478 > > hex dump (first 32 bytes): > > 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ > > d8 e7 0a 8b 00 80 ff ff 20 ed 05 c1 00 00 ff ff ........ ....... > > backtrace (crc 69e99671): > > kmemleak_alloc+0xb4/0xc4 > > kmem_cache_alloc_lru+0x1f0/0x244 > > xas_alloc+0x2a0/0x3a0 > > xas_expand.constprop.0+0x144/0x4dc > > xas_create+0x2b0/0x484 > > xas_store+0x60/0xa00 > > __xa_alloc+0x194/0x280 > > __xa_alloc_cyclic+0x104/0x2e0 > > dev_index_reserve+0xd8/0x18c > > register_netdevice+0x5e8/0xf90 > > register_netdev+0x28/0x50 > > loopback_net_init+0x68/0x114 > > ops_init+0x90/0x2c0 > > register_pernet_operations+0x20c/0x554 > > register_pernet_device+0x3c/0x8c > > net_dev_init+0x5cc/0x7d8 > > > > This transient leak can be traced to xas_shrink(): when the xarray's > > head is reassigned, kmemleak may have already started scanning the > > xarray. When this happens, if kmemleak fails to scan the new xa_head > > before it moves, kmemleak will see it as a leak until the xarray is > > scanned again. > > > > The report can be reproduced by running the xdp_bonding BPF selftest, > > although it doesn't appear consistently due to the bug's transience. > > In my testing, the following script has reliably triggered the report in > > under an hour on a debug kernel with kmemleak enabled, where KSELFTESTS > > is set to the install path for the kernel selftests: > > > > #!/bin/sh > > set -eu > > > > echo 1 >/sys/module/kmemleak/parameters/verbose > > echo scan=1 >/sys/kernel/debug/kmemleak > > > > while :; do > > $KSELFTESTS/bpf/test_progs -t xdp_bonding > > done > > > > To prevent this false positive report, mark the new xa_head in > > xas_shrink() as a transient leak. > > > > Signed-off-by: Jared Kangas > > --- > > lib/xarray.c | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/lib/xarray.c b/lib/xarray.c > > index 9644b18af18d1..51314fa157b31 100644 > > --- a/lib/xarray.c > > +++ b/lib/xarray.c > > @@ -8,6 +8,7 @@ > > > > #include > > #include > > +#include > > #include > > #include > > #include > > @@ -476,6 +477,7 @@ static void xas_shrink(struct xa_state *xas) > > break; > > node = xa_to_node(entry); > > node->parent = NULL; > > + kmemleak_transient_leak(node); > > } > > } > > > > -- > > 2.49.0 > > > > > > >