Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2456339rdb; Fri, 8 Dec 2023 08:36:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IGPZo3YjLJ3BFX6z1xgAVB77m8y0IoZQLIQpAjMopopvbHmMFapidf2GW76AnwFjfDiAkeE X-Received: by 2002:a17:90b:696:b0:285:a118:3431 with SMTP id m22-20020a17090b069600b00285a1183431mr520242pjz.8.1702053390746; Fri, 08 Dec 2023 08:36:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702053390; cv=none; d=google.com; s=arc-20160816; b=l1hh8LRIFRbS4COCIZbD2IZdJpn2ygsafOVmuCMxacaEWh1IezQLuyuXGUi1NYStV1 N1Xwn1jW9JflMpqlEeOp/GTnzc0ti2oQMTMIbh+i7s+5+oPQhcMHH45wsKZaNRoFukQH X3+rLjp30pwyhHXLHWqLob92FJJ+REH4GE/CvYrzMkIuafN7N1iY3ooJrfxXvcF1Y4CN 4oaJL95c2ISxxpOC/sXtfXAJaJtJkvdFzH9X/aSM+iTIkQPpcY1pMjId/7K/uRmWrC2T chyGFKZjxgCEeO+7AxGPyD2l4H8XVH7hX+xrI65mKK9njKzU5CG1SoZd9NA801G1mbw+ Prqw== 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:date:subject:cc:to:from :dkim-signature; bh=/o2cJh1rTiYxtffqCudXBJvjuX1Lwij5lIhxMrzmiqY=; fh=hPWrg32dlFKNN5MdTsgIUJTVaEJ0Jhxi8OfbSIPXQ0A=; b=mRV9lyNe1SLwHItmc06l3RPlM1MJ7ne/xx12eim8orkLeoWUvaaO+PpiQxOdHZyq+0 0y0T1he4SCF9v/72d+2tZ+7RmHsqBmFXnE3rrB4Qd5UYX5JfNoyJNBeSFXgJkEsJgjMs PE3GOSng4zbVxp6ZGvktjKzQosGqi7nzmLiURTwpcnzlUSYezRngEe7xzXcdN7O+zOTg fzkdtLEEatzkHkSWbVQbq5GgkiGltX9n3jS2xoZ17Oix9lYhPp9r9vf44lL8Kxcy2mf/ QUYj+7MFjzfnf/TXIvrxb+QiKDmW/rtC1npR7U04E6Fq2hN3B9WvFFoLIDVeWYxzrPLz YOmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qErDFEmo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id d14-20020a17090ad98e00b00286a9eefa53si3214827pjv.80.2023.12.08.08.36.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 08:36:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qErDFEmo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 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 fry.vger.email (Postfix) with ESMTP id C737481BFBB2; Fri, 8 Dec 2023 08:36:26 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1574462AbjLHQfb (ORCPT + 99 others); Fri, 8 Dec 2023 11:35:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41482 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235959AbjLHQfY (ORCPT ); Fri, 8 Dec 2023 11:35:24 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 969311995 for ; Fri, 8 Dec 2023 08:35:22 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3D15C433CA; Fri, 8 Dec 2023 16:35:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702053322; bh=Z4H+/v658tdpIUS/M5eM4mkmmspGMz1KhbqU6pOZF5M=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qErDFEmodD4DDHqqZIhdZcw0R/xgNXnvkXsREwRbPKKokGq2qG2xZUkfREtkgqGnA 4g84nEMw28/wbN9hRCzkZPhe6Y5ZKK3qerh7amZTHf9IZt+IiARhqVLNQC5j6Z8LoG F1Smct9Ycj0BSKp8chdrfrR9LExLy9vL0FIz1AvGHUJb4Dw9KnAlIkDzfl+sELiG3+ B43QVHxSh3P4pn4Epgg+Cvx/CPHy4DBXdlZkgSFdGN3u8Q+2DjbVyjdupIX7QmqBdV Z8klsrgLmfc8dE0QjCKTTOeln31fMuYCkbfVP3mZDbMPdKhvUQ89P81GHQAuV2t2HA Vx0ZkALRS12pA== From: Naveen N Rao To: , Cc: Michael Ellerman , Nicholas Piggin , Christophe Leroy , "Aneesh Kumar K.V" , Steven Rostedt , Mark Rutland , Florent Revest , Masami Hiramatsu Subject: [RFC PATCH 5/9] powerpc/kprobes: Use ftrace to determine if a probe is at function entry Date: Fri, 8 Dec 2023 22:00:44 +0530 Message-ID: <15f0b3a2e72326423cfb4ce4e89afff540042245.1702045299.git.naveen@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, 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 fry.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 (fry.vger.email [0.0.0.0]); Fri, 08 Dec 2023 08:36:27 -0800 (PST) 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. 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