From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12B63C433E0 for ; Sun, 7 Mar 2021 11:15:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D44C465128 for ; Sun, 7 Mar 2021 11:15:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230406AbhCGLMu (ORCPT ); Sun, 7 Mar 2021 06:12:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:30626 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231703AbhCGLMq (ORCPT ); Sun, 7 Mar 2021 06:12:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615115565; 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=r9PFTq8BUDKVO428yQixr9bwpENpUHQxDq5isnXpbB8=; b=ONrBEVfVac1zBlRgXbKlbVUgic/mQZv+dgcMnPtpyiEQG9/l0MBMViR8qOsaavh3NFv5DU RTYwohKUIEsQ8/eGozX7n/On/p5+H991PxJkDl/vdN3/axYt0bjbnfCIgJJmsjwQmzGjmL eI0KN/RKfO2hHadyA9s0LjeOSx/VFCA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-117-i81ex38JNDyE8YSwE66DXw-1; Sun, 07 Mar 2021 06:12:41 -0500 X-MC-Unique: i81ex38JNDyE8YSwE66DXw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1B95D81431C; Sun, 7 Mar 2021 11:12:39 +0000 (UTC) Received: from krava (unknown [10.40.192.72]) by smtp.corp.redhat.com (Postfix) with SMTP id 8604C19D9B; Sun, 7 Mar 2021 11:12:32 +0000 (UTC) Date: Sun, 7 Mar 2021 12:12:31 +0100 From: Jiri Olsa To: Andrii Nakryiko Cc: Jiri Olsa , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Michael Ellerman , "Naveen N . Rao" , Networking , bpf , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Toke =?iso-8859-1?Q?H=F8iland-J=F8rgensen?= , Yauheni Kaliuta Subject: Re: [PATCHv2 bpf-next] selftests/bpf: Fix test_attach_probe for powerpc uprobes Message-ID: References: <20210305134050.139840-1-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Sat, Mar 06, 2021 at 07:13:17PM -0800, Andrii Nakryiko wrote: > On Fri, Mar 5, 2021 at 5:42 AM Jiri Olsa wrote: > > > > When testing uprobes we the test gets GEP (Global Entry Point) > > address from kallsyms, but then the function is called locally > > so the uprobe is not triggered. > > > > Fixing this by adjusting the address to LEP (Local Entry Point) > > for powerpc arch plus instruction check stolen from ppc_function_entry > > function pointed out and explained by Michael and Naveen. > > > > Cc: Michael Ellerman > > Cc: Naveen N. Rao > > Signed-off-by: Jiri Olsa > > --- > > .../selftests/bpf/prog_tests/attach_probe.c | 40 ++++++++++++++++++- > > 1 file changed, 39 insertions(+), 1 deletion(-) > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/attach_probe.c b/tools/testing/selftests/bpf/prog_tests/attach_probe.c > > index a0ee87c8e1ea..9dc4e3dfbcf3 100644 > > --- a/tools/testing/selftests/bpf/prog_tests/attach_probe.c > > +++ b/tools/testing/selftests/bpf/prog_tests/attach_probe.c > > @@ -2,6 +2,44 @@ > > #include > > #include "test_attach_probe.skel.h" > > > > +#if defined(__powerpc64__) && defined(_CALL_ELF) && _CALL_ELF == 2 > > + > > +#define OP_RT_RA_MASK 0xffff0000UL > > +#define LIS_R2 0x3c400000UL > > +#define ADDIS_R2_R12 0x3c4c0000UL > > +#define ADDI_R2_R2 0x38420000UL > > + > > +static ssize_t get_offset(ssize_t addr, ssize_t base) > > +{ > > + u32 *insn = (u32 *) addr; > > + > > + /* > > + * A PPC64 ABIv2 function may have a local and a global entry > > + * point. We need to use the local entry point when patching > > + * functions, so identify and step over the global entry point > > + * sequence. > > + * > > + * The global entry point sequence is always of the form: > > + * > > + * addis r2,r12,XXXX > > + * addi r2,r2,XXXX > > + * > > + * A linker optimisation may convert the addis to lis: > > + * > > + * lis r2,XXXX > > + * addi r2,r2,XXXX > > + */ > > + if ((((*insn & OP_RT_RA_MASK) == ADDIS_R2_R12) || > > + ((*insn & OP_RT_RA_MASK) == LIS_R2)) && > > + ((*(insn + 1) & OP_RT_RA_MASK) == ADDI_R2_R2)) > > + return (ssize_t)(insn + 2) - base; > > + else > > + return addr - base; > > +} > > +#else > > +#define get_offset(addr, base) (addr - base) > > I turned this into a static function, not sure why you preferred seemed simple enough to be dealt with in preprocessor, why bother compiler ;-) > #define here. Applied to bpf-next. thanks, jirka