Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp124821rdh; Tue, 13 Feb 2024 11:17:16 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUZfu9OEXEvmbnFI1anIaGG0kIN34VvxeT9AyluytjdI2jWptH1bXJVvA5UmyzaGlHGitbMJZWA9JcfL2gZ612XYLWZ1qtdPSfjJ3SGOQ== X-Google-Smtp-Source: AGHT+IEma5yiRbasn4LaixScFOwIvLYLwEiJnFeOgHSCLukPrH+VU7xorpk9I659TCqElcWMFNFU X-Received: by 2002:a17:90a:6c47:b0:298:a3b7:ee64 with SMTP id x65-20020a17090a6c4700b00298a3b7ee64mr428285pjj.22.1707851836559; Tue, 13 Feb 2024 11:17:16 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707851836; cv=pass; d=google.com; s=arc-20160816; b=U4v3Il8uqOutHGsRipas0CdNkkX7uQFwnGtPMmxWE6QBfh6dF6EgvVNdheOIfQoaSS keCYPw+Kj8FWYgRjD3SczhffBiJbIDMPqIAHU40z4igBWEYDFTEMGsLk8q6Peft2HRyW 4qwMkOIfydCEfGAsP2TP8/EPl5wVQHW/rQrFgci24K4phBm/8FLSRRL/f9MDfUkkzj0z 0Tjq00IZXLYMwCdU1lZ/k+epY5/4WtV2cZwnb919IUuQEk8lBRL6AFweSev2H4zmVQ/Q U89rU/3dmqzWY0spDRJq8mcqYeydAk05bCRF0tt6IeuSS8zBLpeBm4/5327yOxKx2GwQ A0DA== 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; bh=qXLJHoa2vhCu44dDFGcocGPGteAYTMOAGH0dmFHydLs=; fh=alZiYoi36G4ko5dI9Q9envZlFBEP4SDpaLqXSKiYOZU=; b=b3ov/AfFw3dHl82S8UFqsnOVkWTrWksdtMNWm8BVIWDTyxQqoATh5kjnCEjwXdP3mN 4Ye4oEbazddu3CLXV9B+t9OyOCBCL0ivYpnjoUn8/0DQNHVbgeoWXW99hlQru4jSzp/B XmUMuATJuIy+3yL672ou6FiHLvUgxuyPYFlXaIW4z4VZwRw1GyBoRPI1p0XSQa1XK/kK SCkfdsIoVRbffmzxr2RkZXDRkpkI4BbM25jCZMTjFTy4axVcnFOY6pTB7mwrCMI6pZgB 94Ml79WOi2oYx8djqOdnWi9zlQQgBMM7sbyRbxpfl4ARw1bAKKJMGAoQw2d862O2bH/V LDMA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-64118-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64118-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; AJvYcCWuNORf6AvSMoiVrLFGF2le+rR8OKC3RVWXgztrbZncsjijzxbvatu0LYyBtBPWFyAE9wyV5ao0PF5ax9Piw8ankcOo94UiUatO9OJXEg== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id qd3-20020a17090b3cc300b002962d390c0dsi2385802pjb.152.2024.02.13.11.17.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 11:17:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64118-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; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-64118-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64118-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id AE8A6B28901 for ; Tue, 13 Feb 2024 18:51:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39A2260BBF; Tue, 13 Feb 2024 18:49:09 +0000 (UTC) Received: from mail-vk1-f175.google.com (mail-vk1-f175.google.com [209.85.221.175]) (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 E1AD060BB6; Tue, 13 Feb 2024 18:49:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707850148; cv=none; b=B9bZ9soJYyncy6j1iHs7aSlXofNLjf/ciYBZEdcLsLuGXQ3af5N1SgJilnknw/F6tCoLh56QubV2vho4ctMOnoSs1hKDcvfr7MA4/wUJF+bjuB9GaMMg0EpLSyEsMtBuMAMK1d9Hi0DZgm4WqkH4Uz7PXNtXBe9dLHGV3dH4EO4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707850148; c=relaxed/simple; bh=ePfBqnMY7g041J1LiUVXprEqQZe9Slt4ncaJ/PtpmbQ=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Bk3cPv7OMImF9yZsdaC8Msfr2r7jiUcV1kcpvWTtkIJxbhzF2m6DjHwjhuA3p2AqE8O66pL5f/SimCNZsM8f+ZY/kTuCu3Ef6NU2RVMsRIr/HRbXuXDJu3so5VmjJGHr303bs9mcbsIpjxtw9tXTXilRdwqbFqyNqdrWLObFQBk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.221.175 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-vk1-f175.google.com with SMTP id 71dfb90a1353d-4c0819c604cso482019e0c.2; Tue, 13 Feb 2024 10:49:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707850146; x=1708454946; 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=qXLJHoa2vhCu44dDFGcocGPGteAYTMOAGH0dmFHydLs=; b=dxonKOFhlTpJtsj3imQC6qNzif3PRdnDEMBJ2yL3esFXVPSvWwhRKBfqJ9hBEnjROF 0pCkX9gmkAL0jY9x08nce0V0KEl5d9QNzFD1tB91gcPQs4skVqHobqKRvPklvE/NFCgc n6N0dqsmNadtv6uBy8jz4cO6x1hkOS41O63XoHBLkXsXUiyXY0f8fPuQtZSF+YcZTD3l 7qAnKtnQyo+vK+F7Ak8VK4Vgj/PXTeH9qNxk8MGzSGKqCxqXDndidOcs//fuobhYjFaM ej1bw/ypA8MwDrpUxR/BUeGRtK+vqbTCPeF4B3cFlM+Ld8lvq5db/UbR1Da2axIViyb6 qKmQ== X-Forwarded-Encrypted: i=1; AJvYcCUrMEf5r3439LNm6XWlVtrKPqgg3EPy5knit15klj/rSOaooJX8dT7T0vCTuKQXIJ9d7Is2rOnrzaF7OvzCMHPJf/d1RZ88eeAmVNvAWwcfBuoKxlNelRsgwTH6wx1TNeSdxM2Di/Z0xWRLdTn4rA== X-Gm-Message-State: AOJu0YwraVY7vAXqf3YN6zmFRKm1sDkprKIqLe5b/H3s99X5sAye7gho YKSGG+mw24rILcOs9vjAd7aGrgiqm9rHcICTl8nuSE056+vPHF08LDnRLs1qRcx+49KNUjq/+i8 D+q4zC2zZNC1ogNKj8E9a/fdt3pw= X-Received: by 2002:a1f:c7c5:0:b0:4c0:1918:27de with SMTP id x188-20020a1fc7c5000000b004c0191827demr513195vkf.16.1707850145639; Tue, 13 Feb 2024 10:49:05 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240212233322.1855161-1-namhyung@kernel.org> <20240213033954.GB81405@debian-dev> In-Reply-To: <20240213033954.GB81405@debian-dev> From: Namhyung Kim Date: Tue, 13 Feb 2024 10:48:53 -0800 Message-ID: Subject: Re: [PATCH] perf tools: Fixup module symbol end address properly To: Leo Yan 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 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Leo, Thanks for your review! On Mon, Feb 12, 2024 at 7:40=E2=80=AFPM Leo Yan wrote: > > 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_so= ck [bpf] > > ffff80000879d6d8-ffff80000ad656b4: bpf_prog_76867454b5944e15_netcg_ge= tsockopt [bpf] > > ffff80000ad656b4-ffffd69b7af74048: bpf_prog_1d50286d2eb1be85_hn_egres= s [bpf] <---------- here > > ffffd69b7af74048-ffffd69b7af74048: $x.5 [sha3_generic] > > ffffd69b7af74048-ffffd69b7af740b8: crypto_sha3_init [sha3_gene= ric] > > ffffd69b7af740b8-ffffd69b7af741e0: crypto_sha3_update [sha3_gene= ric] > > > > 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. Ok, so chances are they can fall out far away right? > > > 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 *sy= mbols, bool is_kallsyms) > > * segment is very big. Therefore do not fill this gap a= nd do > > * not assign it to the kernel dso map (kallsyms). > > * > > + * Also BPF code can be allocated separately from text se= gments > > + * and modules. So the last entry in a module should not= fill > > + * the gap too. > > + * > > * In kallsyms, it determines module symbols using '[' ch= aracter > > * like in: > > * ffffffffc1937000 T hdmi_driver_init [snd_hda_codec_= hdmi] > > */ > > if (prev->end =3D=3D prev->start) { > > + const char *prev_mod; > > + const char *curr_mod; > > + > > + if (!is_kallsyms) { > > + prev->end =3D curr->start; > > + continue; > > + } > > + > > + prev_mod =3D strchr(prev->name, '['); > > + curr_mod =3D strchr(curr->name, '['); > > + > > /* Last kernel/module symbol mapped to end of pag= e */ > > - if (is_kallsyms && (!strchr(prev->name, '[') !=3D > > - !strchr(curr->name, '['))) > > + if (!prev_mod !=3D !curr_mod) > > + prev->end =3D roundup(prev->end + 4096, 4= 096); > > + /* 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 as= sign > 'prev->end =3D curr->start' for two two consecutive moudles. Yeah I thought about that case but I believe they would be on separate pages (hopefully there's a page gap between them). So I think it should not overlap. But if you really care we can check it explicitly like this: prev->end =3D min(roundup(...), curr->start); > > 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"))) I suspect it can happen on any module boundary so better to handle it in a more general way. Thanks, Namhyung > > > prev->end =3D roundup(prev->end + 4096, 4= 096); > > else > > prev->end =3D curr->start; > > -- > > 2.43.0.687.g38aa6559b0-goog > >