Received: by 2002:ab2:620c:0:b0:1ef:ffd0:ce49 with SMTP id o12csp666517lqt; Mon, 18 Mar 2024 22:51:31 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVQe+IXn73QpBNiQ5sfTqyxOwRas6RKwBS0EkoZMrUkuIDeaeH7E/YyM24lRUaDei4jg3sUFojxz8IeMn7l6lOspjzyr5UFTlEcoOXtQw== X-Google-Smtp-Source: AGHT+IF3TcizmcCBfRvqBqx31E2MI5Xz0EqaBqeZhziRBJScuYcGdDC6Lg6pj2dxR9oOa7jKWfFt X-Received: by 2002:a0c:8e0c:0:b0:691:59ad:ff46 with SMTP id v12-20020a0c8e0c000000b0069159adff46mr12838855qvb.30.1710827490964; Mon, 18 Mar 2024 22:51:30 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1710827490; cv=pass; d=google.com; s=arc-20160816; b=wlMx3tjFQPibREyrM0Dy60vSigZPJ5G2pftZP4aTtRPihkJKsxcvm9TC5uvTLksVgS XZheoufHr8Sy7rmixhgO0I2U4PJ5R931/Oedcosyn1ejDb7ceWJc57+9TaK0VqGu2YNd A6zWoeL7SCElhijwi8VPXiZlX6vvgU1AiaGg6uwy8GolXbFtJacMlmZIIhpJnz2tF0l/ k5K0S2oXtNNn4n8BP3f1G2AYlUFDqc7ku8BAuGTN5tuq2e7JNMCQwLRTe4yfWt5I6RwC LgS6ZwFqSnkxfLM++JLbrwWlsTxFd6qcEcYMViSYJ1a0rVlxPb5A3oyWRmc6Rf1pbTl6 vwAQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=l1MxdmlatAoYEWNgyo71mDl7V9f2kazWCwOQJH8hVGI=; fh=d5BdAY2v/rFdRp9B3LkIhhdCAkT9Zb5EQPowOeF1NFs=; b=fLvMEOScuXu7hdfUvUzp+SHq1qE9Yc57c6kxd1cZZP6fIsJinIVdfNyh1n98/F03/E 3zUBwHajFgUozPZdYfofbmgXl8zSVf088NL9CgrZ30XnEIRzfReEkglIpzf4YGAJo6AU tCdocqsW5W6lQ7V4p6GFnfHMrMneMyAGnZawTWN1lyVwQinZIByg21ie37Qoy7m7jMrb 9LkJqiUymYeT/Qkrd8XhsUrgEVgd0XsgkeXNpXVG2xQrxMkZxZShIkT47BI4XfbjlXGV jo7Yf+MHWIeCRFKvtWGEa5zbtoqpWJ1RUKVg3lZVIqRxFltToUVHbjV26KQc455HZyoy Z0ig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XciRp+eJ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-107026-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107026-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id dv3-20020ad44ee3000000b0069615ae66cfsi4058817qvb.311.2024.03.18.22.51.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Mar 2024 22:51:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-107026-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XciRp+eJ; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-107026-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-107026-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id A16451C20A70 for ; Tue, 19 Mar 2024 05:51:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B8EB44654B; Tue, 19 Mar 2024 05:51:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="XciRp+eJ" 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 B4B773BBE6; Tue, 19 Mar 2024 05:51:17 +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=1710827477; cv=none; b=IsmfvSwTOHaEInEQBmK+WGUuTRcvA0kIfxHMP/f70q0H+HKA0ZW9gayW3e7T+QcabBYl8/uUCcxmmp4Hr3gj9Y9lgg+tx5kgtOeHQyu8c+zsEyuTzX0HJtRkcKdBLPbdb+JWGtViQ2XsK5A3jmpFAffpghgMQxQwDevAAigCwp4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710827477; c=relaxed/simple; bh=Bwl3wVxI2jAUzS6Vvv2sxEob6eMMWXHwYnXX5VZoPI0=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=B5Bubagoc1C0NBVsokDa/YG5rVvuTvGg4ltwvsvEV+TzuQ8aSw3PsGAoNEChX63F6aTabjbJy27pTK2uoX6c38CBv3yWwMYZz4Z/fxcPb0LfUa+FM/zXj8f0I+8FUs3HIpRgYV3xRAbPjau0y5zEbHyEcSNrfthEydkzaMNP9T8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XciRp+eJ; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 70166C433C7; Tue, 19 Mar 2024 05:51:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1710827477; bh=Bwl3wVxI2jAUzS6Vvv2sxEob6eMMWXHwYnXX5VZoPI0=; h=From:To:Cc:Subject:Date:From; b=XciRp+eJ8D1bYPVelwmFVzS8GxJHG0VaUFmCTc/uegbNKrHV3NbNLzAyuxcou9iPd VDjjf9gBAMMualFdWhQ1W9A7ruY8xsO1jhDilKwQStTsHxMkd8tgDPJcBChcotICMj gwSJ2IqA1WSV4iOQ2QVOxvQm/dKjl80Aw21KV2UY528n+4eIf9Dscusu9NNb97Rac7 uVxJrko6WSBgS273xzl+XU7qoAaIPQUOBkNAOmJnf/yN4oq85eqre9hJftrWFE8erq enykkmLokLufo4wwev9yDODieaJ9fTorgDTWdzVGlS5JW0lN8xpo5QjvAsEe+DLuv4 gBB+5+eu/WvIg== From: Namhyung Kim To: Arnaldo Carvalho de Melo , Ian Rogers Cc: Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Linus Torvalds , Stephane Eranian , Masami Hiramatsu , linux-toolchains@vger.kernel.org, linux-trace-devel@vger.kernel.org, Ben Woodard , Joe Mario , Kees Cook , David Blaikie , Xu Liu , Kan Liang , Ravi Bangoria , Mark Wielaard , Jason Merrill , "Jose E . Marchesi" , William Huang Subject: [PATCHSET 00/23] Remaining bits of data type profiling (v7) Date: Mon, 18 Mar 2024 22:50:52 -0700 Message-ID: <20240319055115.4063940-1-namhyung@kernel.org> X-Mailer: git-send-email 2.44.0.291.gc1ea87d7ee-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hello, This is the last part of the data type profiling series. So far we added the basic pointer variable support, and direct access to global/local variables. Now it's time to add instruction tracking. :) For the history and background, you can refer to the previous version [1] and the LWN article [2]. * Changes from v6 - add a new debug option for data type profiling - fix return value look up for function calls - handle general per-cpu access (by tracking ADD instructions) - add cache for global variables - fail insn tracking early when no further info is expected - and more small bug fixes * Changes from v5 - rename register state from scratch to caller_saved - change comment in map__objdump_2rip() Basically it needs to track variable (and its type) assignment to get a type of memory access at the sampled instruction. Compilers don't generate DWARF information for every memory accesses so it cannot find all the necessary information from DWARF. Therefore, it follows the path to the sample in the function, and update type information at each location when the instruction moves it. For the DWARF search, it has a list of scope entries (subroutines or blocks) that covers the sample already. So it can use the scopes to find the shortest path to the sample instruction. Let's say we have this. It got 5 scopes but couldn't find a matching variable for the sample. +---------------- scope[0] subprogram | | +-------------- scope[1] lexical_block | | | | +------------ scope[2] inlined_subroutine | | | | | | +---------- scope[3] inlined_subroutine | | | | | | | | +-------- scope[4] lexical_block | | | | | | | | | | *** target instruction ... Then it starts with the closest scope (at index 4), and find the shortest path from the start of the scope to the target instruction. Along the way, it updates type information in the scope and see if the location at the target instruction has the type. If so, it can return with the type. Otherwise, it goes to the scope[3] and find the shortest path from the start of scope[3] to the start of scope[4]. And then it can combine the existing shortest path from the scope[4] to the target with the new path. Now it can start from the scope[3] with new variables and types. It can repeat this algorithm for the outer scopes. I did it this way because mostly it was able to find a type in the closest scope. So it can avoid unnecessary work for outer scopes. And it added a basic per-cpu variable support for this CPU on x86_64 which uses %gs segment register. Also it can detect the stack-canary pattern which is added by compiler to detect stack overflow. The code is available at 'perf/data-profile-v7' branch in the tree below. I've dropped the debug patch at the end in this series but you can find it in the git branch. git://git.kernel.org/pub/scm/linux/kernel/git/namhyung/linux-perf.git Thanks, Namhyung Cc: Ben Woodard Cc: Joe Mario CC: Kees Cook Cc: David Blaikie Cc: Xu Liu Cc: Kan Liang Cc: Ravi Bangoria Cc: Mark Wielaard Cc: Jason Merrill Cc: Jose E. Marchesi Cc: William Huang [1] https://lore.kernel.org/linux-perf-users/20231110000012.3538610-1-namhyung@kernel.org/ [2] https://lwn.net/Articles/955709/ Namhyung Kim (23): perf dwarf-aux: Remove unused pc argument perf dwarf-aux: Add die_collect_vars() perf dwarf-aux: Handle type transfer for memory access perf dwarf-aux: Add die_find_func_rettype() perf map: Add map__objdump_2rip() perf annotate-data: Introduce struct data_loc_info perf annotate: Add annotate_get_basic_blocks() perf annotate-data: Add debug messages perf annotate-data: Maintain variable type info perf annotate-data: Add update_insn_state() perf annotate-data: Add get_global_var_type() perf annotate-data: Handle global variable access perf annotate-data: Handle call instructions perf annotate-data: Implement instruction tracking perf annotate-data: Check register state for type perf annotate: Parse x86 segment register location perf annotate-data: Handle this-cpu variables in kernel perf annotate-data: Track instructions with a this-cpu variable perf annotate-data: Support general per-cpu access perf annotate-data: Handle ADD instructions perf annotate-data: Add stack canary type perf annotate-data: Add a cache for global variable types perf annotate-data: Do not retry for invalid types tools/perf/builtin-annotate.c | 1 + tools/perf/util/annotate-data.c | 1320 +++++++++++++++++++++++++++++-- tools/perf/util/annotate-data.h | 52 +- tools/perf/util/annotate.c | 334 +++++++- tools/perf/util/annotate.h | 31 + tools/perf/util/debug.c | 3 + tools/perf/util/debug.h | 1 + tools/perf/util/dso.c | 2 + tools/perf/util/dso.h | 6 +- tools/perf/util/dwarf-aux.c | 282 ++++++- tools/perf/util/dwarf-aux.h | 33 +- tools/perf/util/map.c | 17 + tools/perf/util/map.h | 3 + 13 files changed, 1955 insertions(+), 130 deletions(-) base-commit: 2ebf53c2894623d1ef3bcecf1464dbcc3fe1cb72 -- 2.44.0.291.gc1ea87d7ee-goog