Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp761134rdh; Wed, 14 Feb 2024 10:28:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCU7ac0k/QyvmXhcfy90I9Cp8rtGWfCSX/55GH2HVW8VeG2J2aMpfs2vfAONGXPzaomCnWbXP8fP0ptBCkz07q+kdkWUJXpb2ghv7ZNFBQ== X-Google-Smtp-Source: AGHT+IFTmhWPpEFegwz1zHDXXJh9R4KmOp8007+/0XVDTxuAJXgpGh+mGJHXH8O1pQN2CCOUD5G2 X-Received: by 2002:a05:6a21:3512:b0:19e:cd5d:88f6 with SMTP id zc18-20020a056a21351200b0019ecd5d88f6mr4419754pzb.53.1707935304929; Wed, 14 Feb 2024 10:28:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707935304; cv=pass; d=google.com; s=arc-20160816; b=zSc+bEA6EIOSnrhQIr2xZg76zieia92d3KR5LZE9/Q5tEg8GB35ljmB9NmX2Tj9r0U G63xS8WA3C7zO2UWfqkhmsSoKoqNwB0+phPyTAfQ65HQNGgKq6Zv/+XrIKUgJzGoGbCY 5rUr18FnMd1IBvfzCbZL9Q262UQq2fwhqF6rGO4hu2FTcfziU33nXfac7wsv+HeNI1De Dw18YM2oNQkbysat7GdGDs9UFY3temqHF0HWxwzQxMKyyLs9SgsXeq6YlYS5KplnZNTV WAfrpo0VGJybmQVX0FNP99yrG8AitSAKlWuk3qCsRMlnEydkUl0NT9CmSML3rZtC57Ps VXtQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:message-id:in-reply-to:date:references:subject:cc:to :from:dkim-signature; bh=1wpfSmNCRJGnXMGHp7jL+pzhEKESjRZOHpBteD2SxAM=; fh=zJ8wZ5AIRRTk0Wg2yjrXoGG/VGDfC2LPPXJ7jcuF+hg=; b=DhOYvPp06izJKJY1j0tRs+Pt7oseTRD25mHR1WOmEBic/zArd1biu3zA57RTWnuSqw vd9RSMiw1LHaDlY3WBjmuUQwjiG5K2e2lKLpbemk1GGfwF8kMhdRTl5yrO5kZUPd4l/y 23+QKseLx2JMcX1EwaKRlHVs1ehmiDVCmYgIppofDa8F2PPg9vUA1tzda/VxhFX1iaEU vaaHmkTqDTEcjcw7Jsu1epRl6gkUuvLB+lCirbY6oUZjt5EjBamWtA9y4d6N3h1d6G5Q 2WcfRpPoqsmKt0sRYHzZ1yV7W5KJ56ov2zdtX8ogXUKcy5+0d8cm8r61KHjk/9WQ5CDi ZEDQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f5CIfjXE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-65796-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65796-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=2; AJvYcCWnjnkFwvRnHjtYIgs9P2D9/xW4NZnWY2/1nFK4OSccz8QlX9Q+IxvfPkjs9xNSg9gs07aDICnIFR6W2iTaOp+is1Fxb2YuVJZiT6opVQ== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id q19-20020a656853000000b005dc427abe3bsi4125801pgt.356.2024.02.14.10.28.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Feb 2024 10:28:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-65796-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=f5CIfjXE; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-65796-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-65796-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 3098A284FE0 for ; Wed, 14 Feb 2024 18:20:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 927A3127B74; Wed, 14 Feb 2024 18:20:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="f5CIfjXE" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BF5AB126F3E; Wed, 14 Feb 2024 18:20:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707934825; cv=none; b=dlQCG1zLvILkf6dOP2C/5uoX0xV+VgH1ZILQSV5rNSXVuNuTn7xs/SiVYM0kzETXaYcGYJStZ7D7+qLe1DgXA+Qmlxm5X0PinbXJxiG27PYz1Cif23S4U0c2n50A6vDBLzEm52vPNLOZ7xDpJRXdeL3whk4n/CTJ3NAP8/qJy1Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707934825; c=relaxed/simple; bh=PTX79Fr3Yf/DKhXSG/icIh5ogvuh9dWkZkc8teuKW4E=; h=From:To:Cc:Subject:References:Date:In-Reply-To:Message-ID: MIME-Version:Content-Type; b=kqHtY5lKxoeC+jbiG2OY49JkLrXD0vx9qb6lyvkzb4NjblK2CvDWaKQMnmRLZDVGqXxknpI9uCz9abQZpXkkWIA1unVyNM9QRMHRRmfpMd+NvdM6tyksSAcU/BxklSx2a5/qUnNFOF+OkAiAH3zz7QXtoPrengIpBfkwShF8U2Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=f5CIfjXE; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4C2B9C433F1; Wed, 14 Feb 2024 18:20:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707934825; bh=PTX79Fr3Yf/DKhXSG/icIh5ogvuh9dWkZkc8teuKW4E=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=f5CIfjXEf/R3e29WGZgQL5Ic1GDWj9c9ATaExeXZTj1Z1BIbKf1vaupXlV0iZDvJu iSnhd5pygx5Rp9TkwUbMyUKk66RGhwUMhbfVUrrizT93QVLfxmTBfe4bA8DUF+t2nG 2BMSD0wJRhr3W4jVBzjRLr0QBRMCA4PIBozcoRao9S0TSwt95rWk4452JQDJILgjKS jBGMddxBwpqjnqv1svtf7bbVhAenqlbtMqp8EQPRT5YQyqukTsZj3IUFCrwim5aTDb ser88cs2bmUhM08+gXSdG7iT7L0rMGsQsEmBB6cLEKUCpkPdrBik3pD7l8I7tXXCbj /zlg3wHVpeMKg== From: Kalle Valo To: Steven Rostedt Cc: LKML , Linux Trace Kernel , Masami Hiramatsu , Mathieu Desnoyers , Catalin Marinas Subject: Re: [PATCH v2] tracing: Inform kmemleak of saved_cmdlines allocation References: <20240214112046.09a322d6@gandalf.local.home> Date: Wed, 14 Feb 2024 20:20:22 +0200 In-Reply-To: <20240214112046.09a322d6@gandalf.local.home> (Steven Rostedt's message of "Wed, 14 Feb 2024 11:20:46 -0500") Message-ID: <87h6iaewm1.fsf@kernel.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain Steven Rostedt writes: > From: "Steven Rostedt (Google)" > > The allocation of the struct saved_cmdlines_buffer structure changed from: > > s = kmalloc(sizeof(*s), GFP_KERNEL); > s->saved_cmdlines = kmalloc_array(TASK_COMM_LEN, val, GFP_KERNEL); > > to: > > orig_size = sizeof(*s) + val * TASK_COMM_LEN; > order = get_order(orig_size); > size = 1 << (order + PAGE_SHIFT); > page = alloc_pages(GFP_KERNEL, order); > if (!page) > return NULL; > > s = page_address(page); > memset(s, 0, sizeof(*s)); > > s->saved_cmdlines = kmalloc_array(TASK_COMM_LEN, val, GFP_KERNEL); > > Where that s->saved_cmdlines allocation looks to be a dangling allocation > to kmemleak. That's because kmemleak only keeps track of kmalloc() > allocations. For allocations that use page_alloc() directly, the kmemleak > needs to be explicitly informed about it. > > Add kmemleak_alloc() and kmemleak_free() around the page allocation so > that it doesn't give the following false positive: > > unreferenced object 0xffff8881010c8000 (size 32760): > comm "swapper", pid 0, jiffies 4294667296 > hex dump (first 32 bytes): > ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ > ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ................ > backtrace (crc ae6ec1b9): > [] kmemleak_alloc+0x45/0x80 > [] __kmalloc_large_node+0x10d/0x190 > [] __kmalloc+0x3b1/0x4c0 > [] allocate_cmdlines_buffer+0x113/0x230 > [] tracer_alloc_buffers.isra.0+0x124/0x460 > [] early_trace_init+0x14/0xa0 > [] start_kernel+0x12e/0x3c0 > [] x86_64_start_reservations+0x18/0x30 > [] x86_64_start_kernel+0x7b/0x80 > [] secondary_startup_64_no_verify+0x15e/0x16b > > Link: https://lore.kernel.org/linux-trace-kernel/87r0hfnr9r.fsf@kernel.org/ > > Fixes: 44dc5c41b5b1 ("tracing: Fix wasted memory in saved_cmdlines logic") > Reported-by: Kalle Valo > Tested-by: Kalle Valo > Signed-off-by: Steven Rostedt (Google) Applies cleanly to v6.8-rc4 and I don't see the leak anymore, thank you for fixing it so quickly! Tested-by: Kalle Valo -- https://patchwork.kernel.org/project/linux-wireless/list/ https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches