Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2783215rdb; Mon, 12 Feb 2024 17:17:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXs6I7OFa1kdTa+Ko5rxyfaXpkgF972rP+g2tae1ucHHJ56fvkkBX2TaQZcALmrK1M7JR9NAqYYtOWe39G+9KfPFQZl7a+PJmRCbE3QsA== X-Google-Smtp-Source: AGHT+IH22OkPk8G9bmeVGqILnjazcuvgF3YHrnckf+5RjIURQiUCKauKetxowJpD9nXVkgsWzies X-Received: by 2002:a05:622a:13d2:b0:42c:6103:13bc with SMTP id p18-20020a05622a13d200b0042c610313bcmr11535325qtk.38.1707787036114; Mon, 12 Feb 2024 17:17:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707787036; cv=pass; d=google.com; s=arc-20160816; b=zbXfIbbOzYFg2He6dGWqJAaVr8EpBOmZeuAf/oZmLH/GIE21cFouK2v41wznH0myoz /8YcWCFZcnXAckJ+w9lGrjtwZmOejF1WLoJ/B8khLzTKrlLO8KnQUdh1yA8NLjTKaCYn QdV9WXfSl1kqHBohy/R3JiqtqlPHbG2Pw3e0Y8RkKiO+jBcoe5lQH5WhSQBwxNmEiAX9 PY1eunr7cixC3wE3udDgYmQzqy7WphhaFo/kzFqErt3jzNj05VgeZcAnyLncD1WalWrv yEauE7gUvuqtMA7HCR9wHAuir1jc8fqdMj2ANdudd/poBN4YjrjK79QKIptNpOujD9Kb cL1w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=6sfE4CKDsYgzSNtG/2Z/eISWKsnaJqJipJlJ0mll8gM=; fh=2i94mwSlwGJbBUt7l24GoPnqaD+1v88lxhHrJqE7b5g=; b=rw8MM+uxcN9Cltj6x1h71xFrV6Bj96Ao3ltdxo3xNzHBhvTA2K+KKvfHzbMofDVpbX QTc39BmiDJxN6BMG6rWVDduOlzV9lm0Fbt0Sclyw0ZizJ8261uDZOLGzvPswWqZ+CU7C QGaIsTMn3pfeksNs9uPop4FyEn4/FazSWYBrl1S9ps+lJmjEm7mRQ4YWMog/pbnLtk0W 4YA1B5XMPWVYHj5nOSnNqttu6N9HQKm974x9/q8G1R68ZDkcpe3b1C7e2Zd3Mbwjjsai +LewTtgZMXnmyQGTEXRfp3oXBlxWAu4/zoZKz8hjwp2c4PVC2G/yM+qa4a5bD3H5OPKg EcyA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=fyfumgKA; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-62772-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62772-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCV2OHMMSB8j5M3MY73Eo0SshYxuzfzKkFeKotwnwCgZcaUAzgK8xPtDOvGYoUw7+f+Ogil4VkDFStk71PqTDm3rR5zT18PAm7EGttbiYQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id f35-20020a05622a1a2300b0042c11e50969si1947483qtb.753.2024.02.12.17.17.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 17:17:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62772-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=fyfumgKA; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-62772-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62772-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id CC48A1C23FA3 for ; Tue, 13 Feb 2024 01:17:15 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C9CEE1B7EB; Tue, 13 Feb 2024 00:47:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="fyfumgKA" Received: from mail-yb1-f172.google.com (mail-yb1-f172.google.com [209.85.219.172]) (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 DFF9118EC0 for ; Tue, 13 Feb 2024 00:47:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785239; cv=none; b=n9zgrejiL+9z8S2cXWZc8VyNdSKRiz8bsDXq0iAghp5mvxI1MUisHf/Zd1AjX/k6/M6t4vwma5H3H7kjU62YAvnU5jMyqu4xzQEJGxgRW4I7QVY+Gge3VnIc+KuvG+SKzS+hSrkfAW571kHDQQcr0ZqL7VrRdKIzpiId8ar21aw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707785239; c=relaxed/simple; bh=vhshgUQEMVOYmzGB73Sv6P0idtfPu8TvDbWS2Ao2ViM=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=FRzOG5xl5S4p4KAjSnOB1ib7EOAhBZkG6P3gXC+wxsgwud6Nz/XfZUvu0dGOm9kdFPN3ypW436r/0g4QqgvKlfY+ZtC167/UwrH6NeHwnn+va00vRorrxxhRT9vSZX3MPW1Jpry/JQ2z1Ji/8QOVxgDWHCY4WOeptb6p/loG/bg= ARC-Authentication-Results:i=1; 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=fyfumgKA; arc=none smtp.client-ip=209.85.219.172 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 Received: by mail-yb1-f172.google.com with SMTP id 3f1490d57ef6-dcc80d6004bso125223276.0 for ; Mon, 12 Feb 2024 16:47:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707785237; x=1708390037; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=6sfE4CKDsYgzSNtG/2Z/eISWKsnaJqJipJlJ0mll8gM=; b=fyfumgKA94Kgr5KyPD1Vrqt0YbS0rqT8sOp1pFHm9s8Pxeq4CntxOuztXKMBlSddTe 9w9NRxkP/t724Ws90+hC9Ec2T56g3ZCmgr+/M+7a8i+a3+basEH7KIZfrooeNBQbkztP W9cmzqhXfhcDQSgcO8Ht52/qdDmpQAraZqqZexkKMINS06ryY2yf8SfbRmTSqfTogAZt R8Eq414Pt7FHMMQDSBLVL07sNjXU1xBuCVTWm2bFuxiiphDwenEE3+FKpP4D+q6oGTWU Vrbp5OU656s710gCp+2yaZTU2NCVsDVRqEV9VPdHFDT8k66AbHrYx6MDnM8tqqrjeolD WvdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707785237; x=1708390037; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6sfE4CKDsYgzSNtG/2Z/eISWKsnaJqJipJlJ0mll8gM=; b=mokk5VmZKulpv1mqPuOzuwedQVvlS0Et0k87/JdTFwXJipZk9cGY3uB/NOkTPdaVqu jUUP0fhMhaRTtK1B/sZPNCw3LEyh3rt6F+sg14bxp0TR9nbhHC8erHkVoairjFbSACaf O1HNR+0hKGTEgAgR5v46TaoYMpUzkN11R3lhyw7oKNhk7AFd4KeYXYE74ZOhq9Xc0Wcc f/5CCN9u8PjQKoNGntm0l9BLjuNMfakUtMLF8xSt1aZmwp3HTKFga2AANcGPyA4ggwE8 RjhPgzRAT/N6oSRypTghl21xfnlfR7pyMBpwzY7huYHGFcrKgQcuHMgLFNjTgpDPsqFe v5yA== X-Forwarded-Encrypted: i=1; AJvYcCUxSgdl4O3A9/nObtayAyPlX6qleDQNUw1henqqTKVcc5bQ/4fpRkf1HPwLghn3lO28MJCk3NCdM8gyZ7X6mFSvUWp7+dScZO+eZUqf X-Gm-Message-State: AOJu0Yz2PCDglFxDJPvmevRXIe+iVjVtdVcc+aodQ8LK2UUrn5hbUhOX lL1cf+y5e7saXw1oz2r8/pdSmmk5QNDsdivF27sEwTVkNCi51lGe0rREiJKzJrTsR60Of/EkooR 1hyk+xhI7iLG77lG5Ty1P9yYuogK+pFQEZ/F9 X-Received: by 2002:a25:848d:0:b0:dc2:50ca:7d03 with SMTP id v13-20020a25848d000000b00dc250ca7d03mr6944337ybk.1.1707785236496; Mon, 12 Feb 2024 16:47:16 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240212213922.783301-1-surenb@google.com> <202402121602.CC62228@keescook> In-Reply-To: <202402121602.CC62228@keescook> From: Suren Baghdasaryan Date: Mon, 12 Feb 2024 16:47:05 -0800 Message-ID: Subject: Re: [PATCH v3 00/35] Memory allocation profiling To: Kees Cook Cc: akpm@linux-foundation.org, kent.overstreet@linux.dev, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, roman.gushchin@linux.dev, mgorman@suse.de, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, corbet@lwn.net, void@manifault.com, peterz@infradead.org, juri.lelli@redhat.com, catalin.marinas@arm.com, will@kernel.org, arnd@arndb.de, tglx@linutronix.de, mingo@redhat.com, dave.hansen@linux.intel.com, x86@kernel.org, peterx@redhat.com, david@redhat.com, axboe@kernel.dk, mcgrof@kernel.org, masahiroy@kernel.org, nathan@kernel.org, dennis@kernel.org, tj@kernel.org, muchun.song@linux.dev, rppt@kernel.org, paulmck@kernel.org, pasha.tatashin@soleen.com, yosryahmed@google.com, yuzhao@google.com, dhowells@redhat.com, hughd@google.com, andreyknvl@gmail.com, ndesaulniers@google.com, vvvvvv@google.com, gregkh@linuxfoundation.org, ebiggers@google.com, ytcoode@gmail.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, bristot@redhat.com, vschneid@redhat.com, cl@linux.com, penberg@kernel.org, iamjoonsoo.kim@lge.com, 42.hyeyoo@gmail.com, glider@google.com, elver@google.com, dvyukov@google.com, shakeelb@google.com, songmuchun@bytedance.com, jbaron@akamai.com, rientjes@google.com, minchan@google.com, kaleshsingh@google.com, kernel-team@android.com, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux.dev, linux-arch@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-modules@vger.kernel.org, kasan-dev@googlegroups.com, cgroups@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Mon, Feb 12, 2024 at 4:29=E2=80=AFPM Kees Cook w= rote: > > On Mon, Feb 12, 2024 at 01:38:46PM -0800, Suren Baghdasaryan wrote: > > Low overhead [1] per-callsite memory allocation profiling. Not just for= debug > > kernels, overhead low enough to be deployed in production. > > What's the plan for things like devm_kmalloc() and similar relatively > simple wrappers? I was thinking it would be possible to reimplement at > least devm_kmalloc() with size and flags changing helper a while back: > > https://lore.kernel.org/all/202309111428.6F36672F57@keescook/ > > I suspect it could be possible to adapt the alloc_hooks wrapper in this > series similarly: > > #define alloc_hooks_prep(_do_alloc, _do_prepare, _do_finish, \ > ctx, size, flags) \ > ({ \ > typeof(_do_alloc) _res; \ > DEFINE_ALLOC_TAG(_alloc_tag, _old); \ > ssize_t _size =3D (size); = \ > size_t _usable =3D _size; = \ > gfp_t _flags =3D (flags); = \ > \ > _res =3D _do_prepare(ctx, &_size, &_flags); = \ > if (!IS_ERR_OR_NULL(_res) \ > _res =3D _do_alloc(_size, _flags); = \ > if (!IS_ERR_OR_NULL(_res) \ > _res =3D _do_finish(ctx, _usable, _size, _flags, _res); = \ > _res; \ > }) > > #define devm_kmalloc(dev, size, flags) \ > alloc_hooks_prep(kmalloc, devm_alloc_prep, devm_alloc_finish, \ > dev, size, flags) > > And devm_alloc_prep() and devm_alloc_finish() adapted from the URL > above. > > And _do_finish instances could be marked with __realloc_size(2) devm_kmalloc() is definitely a great candidate to account separately. Looks like it's currently using alloc_dr()->kmalloc_node_track_caller(), so this series will account the internal kmalloc_node_track_caller() allocation. We can easily apply alloc_hook to devm_kmalloc() and friends and replace the kmalloc_node_track_caller() call inside alloc_dr() with kmalloc_node_track_caller_noprof(). That will move accounting directly to devm_kmalloc(). > > -Kees > > -- > Kees Cook