Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp4712929pxb; Tue, 25 Jan 2022 17:18:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJzR5HO3I048IeYad//g/JnMLF7R++9GDtvbEfG99AjC/NBIxwxMlsOzVQSWh5UK1AUSRlH6 X-Received: by 2002:a05:6402:524f:: with SMTP id t15mr8642198edd.276.1643159922778; Tue, 25 Jan 2022 17:18:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643159922; cv=none; d=google.com; s=arc-20160816; b=nqT49hCm7lF8xgSfh1oxc+7ou2x1xUrm5ZJ8oIvWAhcHksgZvBob6E7qpluJo8Czh7 nO26dBuWHSm3ngJgcy689ve6AnS1djecnC2LCz/RB9h7OpCfaHZlBqdETesM+/T7b32f lkMP7UfIDjLhlh6rZRWGobsHByju9CnQH1bCA12aMOlUBOWzjTHHlrDUC+yRP1S8P0Kp IoWJJGrHILsoN7+dGVmkrnZ1NZWvTKH6JnEY/CM9CeyYUFYambQB/i0V8Gy9ji6rKeQ1 Ircd9qR7NMJF7xFB429HnyIRh2wiKIWnhNVHN2sQoA4y45havBgYwoBFYcX+qo5D/lck 3+Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=GbY3XP61M3uD9sP2FFUZOwoizO9Z7SgKKtfr4x3BErc=; b=nojIsBzU2oRFrSSwlA0WKJBQmV/cb8DAJuuR4Gqm4svNgRjqrkxZPoVQOJ5qHamKDD +IG5ZwcwLuYnl5d2p5cBt4KmB+IYdu4aCxfR9/rUbU3J85ZQ0LT5K+6Z8lPukcw9aW6D PF2AR+Gcj6dsTJS/yr0HhvN8daZChocvo1vbQlrtkZ4i5S5oIwAxNTUg6V7u0z76TynB i/aoPt4zZbaawwDBbixix3rdF9X41EFDP2tPC99ojxyo/kgdq3sdCH0FKIxIFHkB14hJ JwYvQggqKIdetpRDbFtmdTh2/Qs82FYwvISRZhsse4PSwFzgtWJRM89qQlU1VP946a07 dw/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JcuEmNEH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 23si10185866ejf.53.2022.01.25.17.18.18; Tue, 25 Jan 2022 17:18:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JcuEmNEH; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1584761AbiAYQou (ORCPT + 99 others); Tue, 25 Jan 2022 11:44:50 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:33454 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1585111AbiAYQl2 (ORCPT ); Tue, 25 Jan 2022 11:41:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643128888; 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=GbY3XP61M3uD9sP2FFUZOwoizO9Z7SgKKtfr4x3BErc=; b=JcuEmNEHhX3Lsr5Bq7eKJGS+nXPeuky2yjqW85AGn4JuG1ja8e0uP3Psy9i/mPA7HiTzV2 aqaMuqkhened1AL3gXHidVXGIjrCNgAdL3Qs6kbHKef6BEVUPsPEAgSGglMVEA75tNIeOC TpD0R7Hx1gdasdxWYerojXLbO5SUVeo= Received: from mail-ej1-f69.google.com (mail-ej1-f69.google.com [209.85.218.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-300-PKz8F_BmM4KgvKXt6bWuLg-1; Tue, 25 Jan 2022 11:41:26 -0500 X-MC-Unique: PKz8F_BmM4KgvKXt6bWuLg-1 Received: by mail-ej1-f69.google.com with SMTP id v2-20020a1709062f0200b006a5f725efc1so3663436eji.23 for ; Tue, 25 Jan 2022 08:41:26 -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=GbY3XP61M3uD9sP2FFUZOwoizO9Z7SgKKtfr4x3BErc=; b=rgDSg9VFjG4zZxfz0Zlslf3SZlZq4sP0RvF2suL94Rq0Os6vKJfjoIdaAWb1XqzwwZ 8IldeL+aWTwlh7wmMFq+b3MrWZVruCddatTXxP4Gw/QTAmwgdvp6Fg0QIwDjYEYmIgC3 aPFELorDQB3euODta1A1NMP6HhIcdDkd4NCBA+u3x28lLhi/L5jDfpC/y/yUu/5eSTHp kU/a7uIWfBHt7CzB+49A25LHJj5+hO+J1pksxn1cetn9FRUtMzNK6XwOvZqeZgnw4WUm /In2wy7rS+GLX+f8LSMAPwNVZ9KCxkaydjzjJpP6e1T+OD/QRtsbbWrzBY+zuv4AH4qF BPpg== X-Gm-Message-State: AOAM530opxOJ738lrI3R+05bC1q0U5UuECjDFcXvqEM+3GysvOTqAL2l AfsiS3kln+oCc6R9C5r7tF5GoKOozftdvkOGf2p3Co8eoxXse4MhNEXoDVGAfaYxTykJ+fxVqHc HcBTLBUh1tZcNbZJ/eeNxdwE8 X-Received: by 2002:a17:907:3f29:: with SMTP id hq41mr6272871ejc.358.1643128884403; Tue, 25 Jan 2022 08:41:24 -0800 (PST) X-Received: by 2002:a17:907:3f29:: with SMTP id hq41mr6272861ejc.358.1643128884190; Tue, 25 Jan 2022 08:41:24 -0800 (PST) Received: from krava (nat-pool-brq-u.redhat.com. [213.175.37.12]) by smtp.gmail.com with ESMTPSA id a14sm8449020edx.96.2022.01.25.08.41.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 08:41:23 -0800 (PST) Date: Tue, 25 Jan 2022 17:41:21 +0100 From: Jiri Olsa To: Masami Hiramatsu Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , netdev@vger.kernel.org, bpf@vger.kernel.org, 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 v5 2/9] fprobe: Add ftrace based probe APIs Message-ID: References: <164311269435.1933078.6963769885544050138.stgit@devnote2> <164311271777.1933078.9066058105807126444.stgit@devnote2> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <164311271777.1933078.9066058105807126444.stgit@devnote2> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 25, 2022 at 09:11:57PM +0900, Masami Hiramatsu wrote: SNIP > + > +/* Convert ftrace location address from symbols */ > +static int convert_func_addresses(struct fprobe *fp) > +{ > + unsigned long addr, size; > + unsigned int i; > + > + /* Convert symbols to symbol address */ > + if (fp->syms) { > + fp->addrs = kcalloc(fp->nentry, sizeof(*fp->addrs), GFP_KERNEL); > + if (!fp->addrs) > + return -ENOMEM; > + > + for (i = 0; i < fp->nentry; i++) { > + fp->addrs[i] = kallsyms_lookup_name(fp->syms[i]); > + if (!fp->addrs[i]) /* Maybe wrong symbol */ > + goto error; > + } > + } > + > + /* Convert symbol address to ftrace location. */ > + for (i = 0; i < fp->nentry; i++) { > + if (!kallsyms_lookup_size_offset(fp->addrs[i], &size, NULL)) > + size = MCOUNT_INSN_SIZE; > + addr = ftrace_location_range(fp->addrs[i], fp->addrs[i] + size); you need to substract 1 from 'end' in here, as explained in __within_notrace_func comment: /* * Since ftrace_location_range() does inclusive range check, we need * to subtract 1 byte from the end address. */ like in the patch below also this convert is for archs where address from kallsyms does not match the real attach addresss, like for arm you mentioned earlier, right? could we have that arch specific, so we don't have extra heavy search loop for archs that do not need it? thanks, jirka --- diff --git a/kernel/trace/fprobe.c b/kernel/trace/fprobe.c index 4d089dda89c2..7970418820e7 100644 --- a/kernel/trace/fprobe.c +++ b/kernel/trace/fprobe.c @@ -91,7 +91,7 @@ static int convert_func_addresses(struct fprobe *fp) for (i = 0; i < fp->nentry; i++) { if (!kallsyms_lookup_size_offset(fp->addrs[i], &size, NULL)) size = MCOUNT_INSN_SIZE; - addr = ftrace_location_range(fp->addrs[i], fp->addrs[i] + size); + addr = ftrace_location_range(fp->addrs[i], fp->addrs[i] + size - 1); if (!addr) /* No dynamic ftrace there. */ goto error; fp->addrs[i] = addr;