Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2744920rdb; Mon, 12 Feb 2024 15:33:33 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVNk5Fng9yzoYCYDvxkWGBf1De7Xf9XAD/mTX/j3V4cMu4Y8lv42jjWHOQHCG0wq3iFQTPGLl5rRFU01lBxCpfPbZN2i1hgtZSGHbaTTg== X-Google-Smtp-Source: AGHT+IGspcV0S9FcRM8nGNUKrW0ljZC4Tuy2B244qBGk4tp1hGEHmZZIt53UKpmc58ttDbocSN9N X-Received: by 2002:a17:906:b208:b0:a3c:bb37:a676 with SMTP id p8-20020a170906b20800b00a3cbb37a676mr833825ejz.9.1707780813632; Mon, 12 Feb 2024 15:33:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707780813; cv=pass; d=google.com; s=arc-20160816; b=DxzhALc3/3txwzj/2zjdc3l3Gu5PeUViW7L88jnDGK4bnaT87f3cxRCWwDM/b/5CDr SG0rRdD1+apxGefGxmlImiDe8dRHvUxfTos/ITGoQC8SBmRYqx5c2HDZwm5k4kTNOE/v tO/Ecj/Djngkl4uM6e05mLnvEsi/ttFi+w/ky2PZKBcmJkJa2Rd+7H8yxXDSzjy8fK/0 u5lVwrxB2324jYD0qEtErm2PTzpUz3x23PZvVM1zHs/OI/n0cJJ5LkzLXiLj+XXSu/Mg 8hjWFXb5tiSQ4NFtipQ5fSYDapq4nAUDpGycmo9gZO3bPvTV+kothNLAutuaUsp+Aduc 2TCQ== 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=bRP88klJzxAt+kVvOlVZRMOyebtISu2xVf1f4LuZAGI=; fh=A9RkBkZOg7hAmuv6yit1ajggO/5zot/8ItYhXRucYyE=; b=rjwCw9RXnh90bpfgg59uY89FCiYnyo5AZpXXoFgx8RAopMuffgeVOlq0XNKxzec7Vq EF11DCDxc8r2byqvUqrS5kH9dyu7LhL4/Dha2E5olX1CDzfxDGv7OGM1XKu4SAIljqF+ xNOdExFX5zeCosH7zf0+MPhpl4mgdvtY05z16nh4eckvrHsr10lzPyjAqcdqzxYvazic 6rMGD8iJ2JsAx6tWqEsIlOnetzobkPP1atEaTzLri1WeUmsAQ9OvYxDzP3dEeAxGHcTc 862K4zr1dccltGHJiBW+sT/n3cJnhXe8v6oWcyy4b//5FM+LtWNVwpUztLSOsJo0GeUy IS4w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=np8KwOMt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-62541-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62541-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; AJvYcCW2MfmvsEMrTtKxELxr0SwwzvEInefIy/AtWFs8wK0/nJSQ6nONE/ase5JbIHAMqZq6NMG42QhJ/Gu+ezj+jEsh2oV7aec3RXSW3nOi4g== Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id oq4-20020a170906cc8400b00a38604897bcsi626177ejb.742.2024.02.12.15.33.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 15:33:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62541-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=np8KwOMt; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-62541-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62541-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 628061F23989 for ; Mon, 12 Feb 2024 23:33:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC9C64F8BD; Mon, 12 Feb 2024 23:33:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="np8KwOMt" 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 D10B84F5FE; Mon, 12 Feb 2024 23:33:24 +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=1707780804; cv=none; b=qmXZAtfZnJBI8UySkwDoUodco4/jh19gYd7P+HNlzjbSCSLZnI97MC9xjak5Q++K99p9fOyuKvA8mP1D6vIFjdWKn6a338kaKMvOxj5DClLC40vg7Oh681sg39qHW4LX7TvtsxzQdf2fLRP3fhDzF6j7MK/9VZWQlf0hvcXrMjs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707780804; c=relaxed/simple; bh=f+WQOpFf8Q6j7gyAcUMEvgt2grnf1Lmgn20YVuov3JI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Azys0bxMgl7JBqeLIyvd3YtjbzEv4tZh3eV8F0AaWGCecJNLuoiHqGUbiBMHORROAMPcnuYpK4U8g8QPPQxxkVjas5xrpfvG1Neqs06gR4gv+lj0mubv3q6Us7OHi+rJgBLZrkj2PtsZHhOGyp2Q3UDedlq++QdOUyG2nqjppEU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=np8KwOMt; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id C8032C433F1; Mon, 12 Feb 2024 23:33:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707780804; bh=f+WQOpFf8Q6j7gyAcUMEvgt2grnf1Lmgn20YVuov3JI=; h=From:To:Cc:Subject:Date:From; b=np8KwOMtCy2fO+orYiTn3Ep1+jt5Bv2nJ58MKS4wd/+XvniMf2x6InAWrwKv3kcPf fA+e42TZXRLYYd16MifLWB9lfoJCuufMCUOn48Agy++a2zT/5yiJrTetG6BOJU+4Op k1LV0bxFSaG6YvJvF0XqG8ms1DEbjqg8R2vKofiXuOS0iljhplswKMRtGd5aZwguzh FMhAENPKcE4rRDHmxZVjYZqdTREcB7aC/vnbFpODSgFOTx8XMijy2hc2FoYPZnkr0a PwzO1/wx0B7oYnX37+lFfq9IJUaZhwpuHBJzAKBp2ctmSfTBN3jRgmDaONJ9P3RrWd rVTYejPs5+dZA== 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, Leo Yan , Will Deacon , Mark Rutland , John Garry , Mike Leach Subject: [PATCH] perf tools: Fixup module symbol end address properly Date: Mon, 12 Feb 2024 15:33:22 -0800 Message-ID: <20240212233322.1855161-1-namhyung@kernel.org> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit I got a strange error on ARM to fail on processing FINISHED_ROUND record. It turned out that it was failing in symbol__alloc_hist() because the symbol size is too big. When a sample is captured on a specific BPF program, it failed. I've added a debug code and found the end address of the symbol is from the next module which is placed far way. ffff800008795778-ffff80000879d6d8: bpf_prog_1bac53b8aac4bc58_netcg_sock [bpf] ffff80000879d6d8-ffff80000ad656b4: bpf_prog_76867454b5944e15_netcg_getsockopt [bpf] ffff80000ad656b4-ffffd69b7af74048: bpf_prog_1d50286d2eb1be85_hn_egress [bpf] <---------- here ffffd69b7af74048-ffffd69b7af74048: $x.5 [sha3_generic] ffffd69b7af74048-ffffd69b7af740b8: crypto_sha3_init [sha3_generic] ffffd69b7af740b8-ffffd69b7af741e0: crypto_sha3_update [sha3_generic] The logic in symbols__fixup_end() just uses curr->start to update the prev->end. But in this case, it won't work as it's too different. I think ARM has a different kernel memory layout for modules and BPF than on x86. Actually there's a logic to handle kernel and module boundary. Let's do the same for symbols between different modules. Signed-off-by: Namhyung Kim --- tools/perf/util/symbol.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tools/perf/util/symbol.c b/tools/perf/util/symbol.c index 35975189999b..9ebdb8e13c0b 100644 --- a/tools/perf/util/symbol.c +++ b/tools/perf/util/symbol.c @@ -248,14 +248,31 @@ void symbols__fixup_end(struct rb_root_cached *symbols, bool is_kallsyms) * segment is very big. Therefore do not fill this gap and do * not assign it to the kernel dso map (kallsyms). * + * Also BPF code can be allocated separately from text segments + * and modules. So the last entry in a module should not fill + * the gap too. + * * In kallsyms, it determines module symbols using '[' character * like in: * ffffffffc1937000 T hdmi_driver_init [snd_hda_codec_hdmi] */ if (prev->end == prev->start) { + const char *prev_mod; + const char *curr_mod; + + if (!is_kallsyms) { + prev->end = curr->start; + continue; + } + + prev_mod = strchr(prev->name, '['); + curr_mod = strchr(curr->name, '['); + /* Last kernel/module symbol mapped to end of page */ - if (is_kallsyms && (!strchr(prev->name, '[') != - !strchr(curr->name, '['))) + if (!prev_mod != !curr_mod) + prev->end = roundup(prev->end + 4096, 4096); + /* Last symbol in the previous module */ + else if (prev_mod && strcmp(prev_mod, curr_mod)) prev->end = roundup(prev->end + 4096, 4096); else prev->end = curr->start; -- 2.43.0.687.g38aa6559b0-goog