Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp3769211rdb; Sun, 10 Dec 2023 21:40:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhIDUA2YANuuStEWb+ILlvbI0iSUeVxLxY+VBbAor39x6i5uKuGuvW6fLgDvhK9udmF2/t X-Received: by 2002:a05:6e02:1a41:b0:35d:a037:3980 with SMTP id u1-20020a056e021a4100b0035da0373980mr4460306ilv.26.1702273216566; Sun, 10 Dec 2023 21:40:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702273216; cv=none; d=google.com; s=arc-20160816; b=zI5Gsl+aEdEMTyIohevv9R/XYILOvDaNc6YD1jAv+dY6llr2DhPWEvrNhP5uE9bCth DFki7VqAozSFVl00c0ctnNTX+zAUHHI+6hIgkpieHfH9FWZjf8ziJwfqS0iqr523DLRN 0MrFomcztR5gRFHlZ/jXHQNbaTRu+spXyES0Zrz36TYAgCUYPaSx4ZomEV0SFWOyuYsK 39rbl3oPOs2TUKEriBIdjJxIVKeDn8BIn4EzHKzPYpHz5wQ8L8uZk25ZI3cE0fUJFGXF o7IW6O8k++n5XpLJnl+4oRU+5s745xNg+VDdPOiPKjfmlKsyxlxHjA5AdktRjXIBPa6N EWsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=+OaT+AxX1zn1RQqHUYjcL+NsOehyLpO/8/doFfh1DaI=; fh=mFEgeu/2hcqxev0vo15utTQ2ITovOKqA75UwExNmw4o=; b=B0IaEPVxX43pbMTMNaQnzwVnx9R8eMLrBxwJJ+af6XmGsM23eY9no/F8jIapZo7HEI ZOOJVzK8Cp/zi83U04ybN5yPVdD2G6iqf91d3A0QkKMP8+20bsXddH5FtaqPyY6tpm+B Fs+ScdqmrGguEbeZ9ZROhLFtqvHZnmuIb8BpIj048lROBYfK57Y3+DEn1Xr8L9GlVG2n QdI1Yuow9fr1aMCbu23n4uRQ5/+KWfb2kIMkjUgifkFZu6I2IeSThTv80eCHm2D/Mwk5 Ke4l+XiGQ9LGvpz+y/bxzVaN6aRv1qaOkmuw7PHk6vAPdrg3EAC1LCNefz/ml6QyQq4e gwmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rZ4neWCT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [2620:137:e000::3:3]) by mx.google.com with ESMTPS id q9-20020a63f949000000b00565360714f0si5360190pgk.902.2023.12.10.21.40.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Dec 2023 21:40:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) client-ip=2620:137:e000::3:3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=rZ4neWCT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:3 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 2E22A8077FEC; Sun, 10 Dec 2023 21:40:14 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229610AbjLKFjw (ORCPT + 99 others); Mon, 11 Dec 2023 00:39:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229478AbjLKFjv (ORCPT ); Mon, 11 Dec 2023 00:39:51 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52CCDD9 for ; Sun, 10 Dec 2023 21:39:56 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3CDEDC433C7; Mon, 11 Dec 2023 05:39:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702273195; bh=pXkGuPEWqJcgOs6ijfV32w7ZZV3pIr0foEoCn6cP/+c=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=rZ4neWCTUFGh1Y+953GYlVN2hnNOeL71TAYRdsHCd7Jk+zhyeZRMkMX4QL4UlFjPa DU8eBc8rFP8uMdvg0IoEazbkZS8MIFjx2HeskY6O2qS21h5tlb/PWQdo0rvmP1+7t7 ObHCEOH/35CFjFP0DL+z8Lnh6be/Jmsf2g5Q7Hng329CKXKqZsGR9PwBgkCaqRh8KC KrpZKo4SLGo25yHGtRKqk//4MuoszNSOYv77wubakdw41SGYJ3m3brJf7jMPrvO50M UIefKNDhmr4bhUu8zjWSGJ1Rql78fOVBKwdnFvBAFwCIIzONdg8LahcFp6d814eX2F Lgh4qWviAbKPA== Date: Mon, 11 Dec 2023 14:39:50 +0900 From: Masami Hiramatsu (Google) To: Naveen N Rao Cc: , , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , Steven Rostedt , Mark Rutland , Florent Revest , Masami Hiramatsu Subject: Re: [RFC PATCH 5/9] powerpc/kprobes: Use ftrace to determine if a probe is at function entry Message-Id: <20231211143950.980b4ab4e11b71de04332540@kernel.org> In-Reply-To: <15f0b3a2e72326423cfb4ce4e89afff540042245.1702045299.git.naveen@kernel.org> References: <15f0b3a2e72326423cfb4ce4e89afff540042245.1702045299.git.naveen@kernel.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.1 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Sun, 10 Dec 2023 21:40:14 -0800 (PST) On Fri, 8 Dec 2023 22:00:44 +0530 Naveen N Rao wrote: > Rather than hard-coding the offset into a function to be used to > determine if a kprobe is at function entry, use ftrace_location() to > determine the ftrace location within the function and categorize all > instructions till that offset to be function entry. > > For functions that cannot be traced, we fall back to using a fixed > offset of 8 (two instructions) to categorize a probe as being at > function entry for 64-bit elfv2. > OK, so this can cover both KPROBES_ON_FTRACE=y/n cases and the function is traced by ftrace or not. Looks good to me. Acked-by: Masami Hiramatsu (Google) Thanks, > Signed-off-by: Naveen N Rao > --- > arch/powerpc/kernel/kprobes.c | 18 ++++++++---------- > 1 file changed, 8 insertions(+), 10 deletions(-) > > diff --git a/arch/powerpc/kernel/kprobes.c b/arch/powerpc/kernel/kprobes.c > index b20ee72e873a..42665dfab59e 100644 > --- a/arch/powerpc/kernel/kprobes.c > +++ b/arch/powerpc/kernel/kprobes.c > @@ -105,24 +105,22 @@ kprobe_opcode_t *kprobe_lookup_name(const char *name, unsigned int offset) > return addr; > } > > -static bool arch_kprobe_on_func_entry(unsigned long offset) > +static bool arch_kprobe_on_func_entry(unsigned long addr, unsigned long offset) > { > -#ifdef CONFIG_PPC64_ELF_ABI_V2 > -#ifdef CONFIG_KPROBES_ON_FTRACE > - return offset <= 16; > -#else > - return offset <= 8; > -#endif > -#else > + unsigned long ip = ftrace_location(addr); > + > + if (ip) > + return offset <= (ip - addr); > + if (IS_ENABLED(CONFIG_PPC64_ELF_ABI_V2)) > + return offset <= 8; > return !offset; > -#endif > } > > /* XXX try and fold the magic of kprobe_lookup_name() in this */ > kprobe_opcode_t *arch_adjust_kprobe_addr(unsigned long addr, unsigned long offset, > bool *on_func_entry) > { > - *on_func_entry = arch_kprobe_on_func_entry(offset); > + *on_func_entry = arch_kprobe_on_func_entry(addr, offset); > return (kprobe_opcode_t *)(addr + offset); > } > > -- > 2.43.0 > -- Masami Hiramatsu (Google)