Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 343B6C433EF for ; Thu, 6 Jan 2022 08:31:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236734AbiAFIbs (ORCPT ); Thu, 6 Jan 2022 03:31:48 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:32923 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236658AbiAFIbp (ORCPT ); Thu, 6 Jan 2022 03:31:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1641457905; 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=iD73kWNijA1U4uWtuCWW0P+JxmH4hSDMGlp1iBsoK5c=; b=eSjxYFkUVWVjwqzsAmnBuVW8yG1e0f75R70ckuGbXSfMlnHt7z8DszRN5ODwEksrpKzScS BBeweHsQnZtxnbNFkqQSePEClTHGT03IyCxJC72vLk04M7QEIjwrTWoroXXad3/a7Ah+0U gaZUQyCK3gZuagAq2quGcZ8eowU/cpM= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-643-5k2N2p4vNF2oZbQq-pmPMA-1; Thu, 06 Jan 2022 03:31:44 -0500 X-MC-Unique: 5k2N2p4vNF2oZbQq-pmPMA-1 Received: by mail-wm1-f69.google.com with SMTP id az9-20020a05600c600900b0034692565ca8so1687671wmb.9 for ; Thu, 06 Jan 2022 00:31:43 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=iD73kWNijA1U4uWtuCWW0P+JxmH4hSDMGlp1iBsoK5c=; b=Rf8mSx1/FeyxuBJ/e2qbW9lZcnGwLaNtxUdOsCeTKmRnjlD+dScquU8Z4jxj4CrzcF QP0vKB9/UHsz3JX3GU3MGEQYayYJZHODP+4E31elcMWJqLESV5pWiifgOq8Dl1aE/APK imZSTvPGIkXfdEmuL9ix1qXX1sJ5F3BSdfiQ2EuW5VgaoZN8dk7ML3Vm6jZy2KoLSiY3 ZqN7/eP9XzBosOogx9UqfObAu29q2rmyswX/okGLgp6XWY+nkVFjjvZ/QG0x4pfYoQJG yG2y2uNyh8t7jSAq0fl1LcI2mqM+fLx4VtTJBJy/6dANm0eAutJtsOe3q/KHtkUPMLrD odzQ== X-Gm-Message-State: AOAM533pxRROadM1hV25p6F777S6JrN9iMSI83jEsHTnVV1hHvRSfxNy jCZoUxpOattXBAFje/COdKiyt6X+vkqW0iKTx+kVurfhYS6joI5VugdvSda3qbobCeXm+W6kGhM Fp9VQYqHzDd0f25QH4n33ZDai X-Received: by 2002:adf:f24e:: with SMTP id b14mr49092630wrp.612.1641457902837; Thu, 06 Jan 2022 00:31:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJyenm8i9TvSQ1ak4sztO2YCOXtuNWaef/xxLjvTDwVneO0lGa1kAWmVlbRDNshxtQOXDKlWKg== X-Received: by 2002:adf:f24e:: with SMTP id b14mr49092617wrp.612.1641457902678; Thu, 06 Jan 2022 00:31:42 -0800 (PST) Received: from krava (nat-pool-brq-u.redhat.com. [213.175.37.12]) by smtp.gmail.com with ESMTPSA id l6sm1843686wry.18.2022.01.06.00.31.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jan 2022 00:31:42 -0800 (PST) Date: Thu, 6 Jan 2022 09:31:40 +0100 From: Jiri Olsa To: Andrii Nakryiko Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Masami Hiramatsu , Networking , bpf , lkml , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Steven Rostedt , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" Subject: Re: [PATCH 02/13] kprobe: Keep traced function address Message-ID: References: <20220104080943.113249-1-jolsa@kernel.org> <20220104080943.113249-3-jolsa@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jan 05, 2022 at 08:30:48PM -0800, Andrii Nakryiko wrote: > On Tue, Jan 4, 2022 at 12:10 AM Jiri Olsa wrote: > > > > The bpf_get_func_ip_kprobe helper should return traced function > > address, but it's doing so only for kprobes that are placed on > > the function entry. > > > > If kprobe is placed within the function, bpf_get_func_ip_kprobe > > returns that address instead of function entry. > > > > Storing the function entry directly in kprobe object, so it could > > be used in bpf_get_func_ip_kprobe helper. > > > > Signed-off-by: Jiri Olsa > > --- > > include/linux/kprobes.h | 3 +++ > > kernel/kprobes.c | 12 ++++++++++++ > > kernel/trace/bpf_trace.c | 2 +- > > tools/testing/selftests/bpf/progs/get_func_ip_test.c | 4 ++-- > > 4 files changed, 18 insertions(+), 3 deletions(-) > > > > diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h > > index 8c8f7a4d93af..a204df4fef96 100644 > > --- a/include/linux/kprobes.h > > +++ b/include/linux/kprobes.h > > @@ -74,6 +74,9 @@ struct kprobe { > > /* Offset into the symbol */ > > unsigned int offset; > > > > + /* traced function address */ > > + unsigned long func_addr; > > + > > keep in mind that we'll also need (maybe in a follow up series) to > store bpf_cookie somewhere close to this func_addr as well. Just > mentioning to keep in mind as you decide with Masami where to put it. ok SNIP > > diff --git a/kernel/trace/bpf_trace.c b/kernel/trace/bpf_trace.c > > index 21aa30644219..25631253084a 100644 > > --- a/kernel/trace/bpf_trace.c > > +++ b/kernel/trace/bpf_trace.c > > @@ -1026,7 +1026,7 @@ BPF_CALL_1(bpf_get_func_ip_kprobe, struct pt_regs *, regs) > > { > > struct kprobe *kp = kprobe_running(); > > > > - return kp ? (uintptr_t)kp->addr : 0; > > + return kp ? (uintptr_t)kp->func_addr : 0; > > } > > > > static const struct bpf_func_proto bpf_get_func_ip_proto_kprobe = { > > diff --git a/tools/testing/selftests/bpf/progs/get_func_ip_test.c b/tools/testing/selftests/bpf/progs/get_func_ip_test.c > > index a587aeca5ae0..e988aefa567e 100644 > > --- a/tools/testing/selftests/bpf/progs/get_func_ip_test.c > > +++ b/tools/testing/selftests/bpf/progs/get_func_ip_test.c > > @@ -69,7 +69,7 @@ int test6(struct pt_regs *ctx) > > { > > __u64 addr = bpf_get_func_ip(ctx); > > > > - test6_result = (const void *) addr == &bpf_fentry_test6 + 5; > > + test6_result = (const void *) addr == &bpf_fentry_test6; > > return 0; > > } > > > > @@ -79,6 +79,6 @@ int test7(struct pt_regs *ctx) > > { > > __u64 addr = bpf_get_func_ip(ctx); > > > > - test7_result = (const void *) addr == &bpf_fentry_test7 + 5; > > + test7_result = (const void *) addr == &bpf_fentry_test7; > > we can treat this as a bug fix for bpf_get_func_ip() for kprobes, > right? I think "Fixes: " tag is in order then. true, will add that in next version thanks, jirka