Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2826093rdb; Mon, 12 Feb 2024 19:44:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEHWIi/OMUZbQHzJ6wPMibCF7YZdQg4XVRGHeebruDyYc2D162LTvip8QNBX8RcR/VyFH2E X-Received: by 2002:a05:6a20:9e4b:b0:19e:a85b:854b with SMTP id mt11-20020a056a209e4b00b0019ea85b854bmr6830905pzb.48.1707795858120; Mon, 12 Feb 2024 19:44:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707795858; cv=pass; d=google.com; s=arc-20160816; b=dIJ5Y4Li/6yLbk4O8xB54ctACnhi7ag/OKmH/+uOvmhYrZUZkFBWtR9dBgGnLbSDCc +kUo/R5tRYGhsB9QLGDcSkHMRQeKiX+u3RuCrFOJerGKRElIQrHe9YEV+6+oDQdDed/n wsx0PDKGwHIGBcxz1Kx6dPiw9kA8Tahb03HEc3tA62H9ZK6YGQee1B0mLmN5TQ9PMyx9 I2gtr5svgOZi/E/5kEn5CDftfqNT6wqQkrsoUa1vEwgRQeAaR0LigYsccsjMfpAhprVx QNm1gD32woh9kRnX4qx+rziWjHKHNHGlv8FqX8U5Op9/HSWYvgWGh8nVOIKEt6smeHvt sp5g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:dkim-signature:date; bh=LzrWm/uZNgee7Q71WecGWdzqs9MQq9878fLRObFe0wU=; fh=agk/l3pFK0L+wcP4PMF6ZNk40vuV8GipnMXjpkHi2C8=; b=Pf7bJtMBbfOl5oJR5ax53ce1CX8DUWmnemfBM8g+ugP1ABc8V5ld8Zktmf6UAzr5l5 7T6P9xPmN1vUB55tHXr22/CkBuJJqTHlAnHDB9F27olhb8n5jTvog0n6E8laBqToM8AR FaJ6MLvgYAslfVZPuhkVcoEX9HEvb6HZnNSqlas5f+GSNMOOrhfrTvom1eps4OqzW+IM sb7/EFPIfVzDbGFlR91JuodmqzixiiYb4D9iOdD1a0XGDDk5fdRO5ole4X3DTqo0miV1 NAKdjhiway6QD2UgQzbnSxg5utdunS2jpm0FFpMFo0ewMj7oVmP0HalH5Ra5eBqY1WPE CE7Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=S1z3oMWG; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-62918-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62918-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev X-Forwarded-Encrypted: i=2; AJvYcCWPWIUYcTSTkrxMWuio/kSOeGiDERJZjnXxA4z5JP66wZ7WLbNx5sABCEdnMmY+NXLHKR3bhYPoz9PYjeH0hLJPY2E9SsHNjmHPPkQxsA== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id ha12-20020a17090af3cc00b00298a093c7ddsi659850pjb.142.2024.02.12.19.44.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 19:44:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62918-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=S1z3oMWG; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-62918-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62918-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev 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 sy.mirrors.kernel.org (Postfix) with ESMTPS id D6BB9B244CA for ; Tue, 13 Feb 2024 03:40:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 927FA8F77; Tue, 13 Feb 2024 03:40:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="S1z3oMWG" Received: from out-184.mta0.migadu.com (out-184.mta0.migadu.com [91.218.175.184]) (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 604B7A939 for ; Tue, 13 Feb 2024 03:40:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.184 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707795632; cv=none; b=eYwef8rdP4NqCBJ0yIXIpwmoO4mRDIHWXHFOSo3NyhNjueYDdxZQ7F+O5/Y7Nz4o9ufI0ZVU9qNzwEoLXjT545MewWYvaXngDNVNr6dRHlrW8JAvsDblAGLcXzPx7qRdyh620hqqIfmWyCMt5JXqc+RoKb+aZOEKfjC27+NXS0Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707795632; c=relaxed/simple; bh=o+bnbxJt2/ISJQVFBr+Zlv2HapBYYYq1ZQj6Gv8FlKA=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=LUOZmES+qkuq2tT6YNRaYVql//Ngy/rfvkptyth/N7GP2Khzo8a1UW/c3vyu+ktrK1w/GpSQ5vwgKMtLoGlD0tpuAZ/8zl9eZZxL/JPRNNdREu35Q0zlBim0Jg/Xx4YY3cHFdGvIc3ICRcBRZC7yzR95gZoc0YLqSgimF+3GGVo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=S1z3oMWG; arc=none smtp.client-ip=91.218.175.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Date: Tue, 13 Feb 2024 11:39:54 +0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707795628; 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: in-reply-to:in-reply-to:references:references; bh=LzrWm/uZNgee7Q71WecGWdzqs9MQq9878fLRObFe0wU=; b=S1z3oMWGwkXXzGknMuLKsQvbnQEoHi1RHTzZVbpv3wnw6FyixHdnmAdwGiiE6oKbKhOwPF vw2RbOyLQhNPaUOfNjzsFoFtG8XHOmQMO0XseaIUDoV/BkXQgvr1YUX6gvb0pP0mCm/fr9 JjUnrTLvQFFHoRM55+3ot7yh0Dld2ag= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Leo Yan To: Namhyung Kim Cc: Arnaldo Carvalho de Melo , Ian Rogers , Jiri Olsa , Adrian Hunter , Peter Zijlstra , Ingo Molnar , LKML , linux-perf-users@vger.kernel.org, Will Deacon , Mark Rutland , John Garry , Mike Leach Subject: Re: [PATCH] perf tools: Fixup module symbol end address properly Message-ID: <20240213033954.GB81405@debian-dev> References: <20240212233322.1855161-1-namhyung@kernel.org> 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=us-ascii Content-Disposition: inline In-Reply-To: <20240212233322.1855161-1-namhyung@kernel.org> X-Migadu-Flow: FLOW_OUT On Mon, Feb 12, 2024 at 03:33:22PM -0800, Namhyung Kim wrote: > 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. Even Arm32 and Arm64 kernel have different memory layout for modules and kernel image. eBPF program (JITed) should be allocated from the vmalloc region, for Arm64, see bpf_jit_alloc_exec() in arch/arm64/net/bpf_jit_comp.c. > 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)) Should two consecutive moudles fall into this case? I think we need to assign 'prev->end = curr->start' for two two consecutive moudles. If so, we should use a specific checking for eBPF program, e.g.: else if (prev_mod && strcmp(prev_mod, curr_mod) && (!strcmp(prev->name, "bpf") || !strcmp(curr->name, "bpf"))) Thanks, Leo > prev->end = roundup(prev->end + 4096, 4096); > else > prev->end = curr->start; > -- > 2.43.0.687.g38aa6559b0-goog >