From patchwork Fri Feb 2 12:30:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiaxun Yang X-Patchwork-Id: 13542888 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id D780EC47DB3 for ; Fri, 2 Feb 2024 12:30:42 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 13C8C6B0075; Fri, 2 Feb 2024 07:30:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0D69B6B007E; Fri, 2 Feb 2024 07:30:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D1A3B6B0078; Fri, 2 Feb 2024 07:30:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id B4C226B0074 for ; Fri, 2 Feb 2024 07:30:40 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 6F74CC0F4E for ; Fri, 2 Feb 2024 12:30:40 +0000 (UTC) X-FDA: 81746797440.20.B3DFF5F Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) by imf18.hostedemail.com (Postfix) with ESMTP id 42E751C0024 for ; Fri, 2 Feb 2024 12:30:37 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=flygoat.com header.s=fm1 header.b="fEI1zv/+"; dkim=pass header.d=messagingengine.com header.s=fm3 header.b="G M6TVMH"; dmarc=pass (policy=none) header.from=flygoat.com; spf=pass (imf18.hostedemail.com: domain of jiaxun.yang@flygoat.com designates 66.111.4.28 as permitted sender) smtp.mailfrom=jiaxun.yang@flygoat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706877037; a=rsa-sha256; cv=none; b=XDT4NnAevGWHzPMWlRNqDYXXiuRXF54Bbkk0CHVQ2q1su/E/wpeK7IHasRGpjMLPuELMkb 4FRgjmRjseOJz3DY1lFVmMLOVdvSqkdtAvcBhM4ErRvlfYJEfBo2VwKuLmUzo0AmiTaaID RXYIoRuVrmoQp67DI1JoL1kxVK8H35A= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=flygoat.com header.s=fm1 header.b="fEI1zv/+"; dkim=pass header.d=messagingengine.com header.s=fm3 header.b="G M6TVMH"; dmarc=pass (policy=none) header.from=flygoat.com; spf=pass (imf18.hostedemail.com: domain of jiaxun.yang@flygoat.com designates 66.111.4.28 as permitted sender) smtp.mailfrom=jiaxun.yang@flygoat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706877037; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3C5bFwJv9LWEX7uXH9OhbPn6aVzr7qyWAUolJmL7emQ=; b=d+Cj+AOZ5bU1cGFbMifOEIqq8mJbMFnmJmujunl4lJiUHhPJzCJMF++k+BlRciwxwNqLAz urLA+teqC9SFUpZNAAFPHSwExpyuhQsQAGlraifIts+a80OS3wHBNAaTi8Utjr1fR7q50Y RyPQRNTlTmhbg8l6FWpyigtKUcmHPhQ= Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 8CDF65C0160; Fri, 2 Feb 2024 07:30:36 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Fri, 02 Feb 2024 07:30:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h= cc:cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm1; t=1706877036; x=1706963436; bh=3C5bFwJv9LWEX7uXH9OhbPn6aVzr7qyWAUolJmL7emQ=; b= fEI1zv/+ZvFpkfpFRiLTSbFcBisWuJ2q1jjScOxUaTFUrgkBaxR7Dx3eZf25cfK3 CCgcfDN0Mp+DmtIBGMvaBhPgFah6cUtlcaagGHlj97CLyV1V3p/5jw7OtwdFh64a HMQa5y/m/fAdJjMEvV/Q0eZ89mcIVI1Riga2COWISSsrwMoXl1biAun7d9Iem3JM EJsIIbsWbJqGq5yN4S1pDLjjeDsbBOGGag/1fMXqkCs/ScLMbRqeJdXOG6T/rZGC s00KA5riqpXZZ/sqaaNNV9dRJ0lagWb/DXUyBPlGEwCHFFKUDNZtGujoWsr2NybD eYv4M7t3bTg1agwJRceaIQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1706877036; x= 1706963436; bh=3C5bFwJv9LWEX7uXH9OhbPn6aVzr7qyWAUolJmL7emQ=; b=G M6TVMHqdzw6Ad4JtN7ng9dTBDFr/eJ0ih2VN0pFcxFRMqVse9IA4ZgGzwjEuvCz8 ZYuIoiL2km7nIa+V2fNKiCBS3hXbwKYKgfKJABkZ3O58hAPcwy3AmQvvJx5xoy6/ w6Yew322XWxbcGUF9VqlbmHmtI/kQqZFxP/WHKzEIwgIg1+Luc8NEAHeVxPuGU+E ztCrKwLNLAlHT2j+alLLJ/jtu4feGjNtgYQTtunDXjuJxRD/O1ZNDNPRq2r4o1Jh AZ1h8rdIffPFFY6kjHi7iGxfFTjq2U4DpsBRuyMgjprKJ6be/BB/h/kEbM00rSgp jgGUDqGGjalnzB+Cei1Nw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrfedugedgfeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdejnecuhfhrohhmpeflihgr gihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhihgohgrthdrtghomheqne cuggftrfgrthhtvghrnhepvedujefhfffhveekhfffkeetvefgteejkeeutdduieehieeg feejtdelveejtedunecuffhomhgrihhnpehkvghrnhgvlhdrohhrghenucevlhhushhtvg hrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehjihgrgihunhdrhigrnhhg sehflhihghhorghtrdgtohhm X-ME-Proxy: Feedback-ID: ifd894703:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 2 Feb 2024 07:30:34 -0500 (EST) From: Jiaxun Yang Date: Fri, 02 Feb 2024 12:30:26 +0000 Subject: [PATCH v2 1/3] ptrace: Introduce exception_ip arch hook MIME-Version: 1.0 Message-Id: <20240202-exception_ip-v2-1-e6894d5ce705@flygoat.com> References: <20240202-exception_ip-v2-0-e6894d5ce705@flygoat.com> In-Reply-To: <20240202-exception_ip-v2-0-e6894d5ce705@flygoat.com> To: Oleg Nesterov , Thomas Bogendoerfer , Andrew Morton , Ben Hutchings Cc: linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linux-mm@kvack.org, Jiaxun Yang X-Mailer: b4 0.12.4 X-Developer-Signature: v=1; a=openpgp-sha256; l=2422; i=jiaxun.yang@flygoat.com; h=from:subject:message-id; bh=jqYI8HbcM9CNa56K9MGaAYkP5szfqvwINyuXO+HntBI=; b=owGbwMvMwCXmXMhTe71c8zDjabUkhtQ9D9L/qG88d2+OlHtP+o78T0s3chUbPZ8Uvzbu8jpWN g75zrbzHaUsDGJcDLJiiiwhAkp9GxovLrj+IOsPzBxWJpAhDFycAjCRVzMYGR6pPn00Z3LOVYMf +pd5H13RYA/4m6B+6ezjTK8Z5rkHPioy/FMONNv9ubG3cWFPxtH1qnK6706VPv38t/CF1H4RHyU PKx4A X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp; fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 42E751C0024 X-Stat-Signature: rtsxmpmgqfhd4j9theyo6za73mw7shtf X-HE-Tag: 1706877037-817679 X-HE-Meta: U2FsdGVkX1/KcY8C2SPpPbauKHzx0CUnb57Ts80liJU27ssJrNmTbnYNRt7MGBAm2JbBXmRISSzFgg5nirbkvqRGy2eRAGfJ0A7PdPwBhxcFpES8TWYMoC8hGmlgoLxLZzrJaqcYWYKoiIE+hqbUJ4njungl3P8jZb2/R1uL5LUZFHM7IZ9X7dAafWObDGYwRY+lVliqPXF/Vm72+jzQr24qVijrYx2EnzBRVGG9Ds4vA/OBKUHUzkDgbuOKuLnjRq4oYAp7NAkkEXt4RJ8Dr/YO1iMzFXE+tDIq6Q5Oxq6wCpMGDAWuL5+BGEzLMU7M3cFgYLFZxvUGdYkqpcG8adjpUJOSeEJYiCM1fThZKnu/IguM5Qqi/PCiQygZji+k6Kf6g2kB0UvecSBUw7FeamWvTHbE9+nWbybJjkCMPBTtM3/h54Ifr/kCFdQlHUlvAbUWUDsBuf4JSbcat1X9Kc+gOilRwJZ8RfOvcA3FwGNnFD9ARXTC8EJXmQzUnjlA2l+Aq8twLB/HKE7JiSKODuqSvfkYCyBv/ep3d5VBe0u0Sx6CyuBHkPwmWl7LvVSf5ZAKooP65HdoPwYbIKm/3WsMgn0WI5Te9eVPsFjZrq+G/4F9/ckcWGgV1VzPXeq0f5HA3ozJk2RB4XN9ojwkITQYu/AG2RQ/4DHULnNPnMDVuMWtMwbFi0OHbu3iILSRa+09Tinpq6tqQ5QY7xoGI3ICru9JQbGC1izL6RTQ5/U/3RDWgGNG/OwRmuWO7ufxylqNgklX5KUKb2FgY88vwIniko/E66AKPSLwDGY/I8oXMp0NwoQ3SE3X20t6bOHE2+r1Hy4MRBB8ZaE/rfvdlRD87JXbx6ZuU4AnamylcIr27mJniJzZDGAqlD4BwMVo+eNje3Cat8f8GZeXaZMBx4ljrHZP98ssMuGaoBTvolGnC5RcFePp8s+64xZ+liOTviOJBfNvqoS4+8hAWzp wwtpAKSR 8vi6mE8abiEGLFD6ZJTsh0HPsi0jVjl7U6Sl/jKO+t4JG5Y79pgJbxCb9QZ88s4c8jJjZNejdI/GEGco8qNP74RvjNpt4YZajyoRnurDMiIGAiyLHyye5Ku71VX5Mqdh5q6ryB3fFtpAYLtsLnJ4Hk6yA3ZbpKNCXCprgu1GTXs6fWar80WtxnMoY1GRQMroWJvzIZ2pZqbSASlERq+Qsvg2TCX8cSL8nQvOrkMphzsXIT9U01z0qE0fp3920v5sLcRw/8Rhd9gfjtlb7pQfs1QeiebRv3S6dN4/Rfud04UgkC7MOKiqePfdZEsilJxtQUFgYOc2caViN98N777myQvk+q+B1jqTSCAmzhUCaIRCXZqxX2Izkx5KWu0+gQuwRFonoiaZ73SeH8SDhvEL8GyB5XzZF820tkFDcMT3nTiGuDZZmhhSVpC5Uoq/kXriXgr8N76oCcnLSw2p8+gB3XiTvPpxK0L+igy1hGlPuLaI27uzDxtvIHNbBZg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On architectures with delay slot, architecture level instruction pointer (or program counter) in pt_regs may differ from where exception was triggered. Introduce exception_ip hook to invoke architecture code and determine actual instruction pointer to the exception. Link: https://lore.kernel.org/lkml/00d1b813-c55f-4365-8d81-d70258e10b16@app.fastmail.com/ Signed-off-by: Jiaxun Yang --- arch/mips/include/asm/ptrace.h | 2 ++ arch/mips/kernel/ptrace.c | 7 +++++++ include/linux/ptrace.h | 4 ++++ 3 files changed, 13 insertions(+) diff --git a/arch/mips/include/asm/ptrace.h b/arch/mips/include/asm/ptrace.h index daf3cf244ea9..701a233583c2 100644 --- a/arch/mips/include/asm/ptrace.h +++ b/arch/mips/include/asm/ptrace.h @@ -154,6 +154,8 @@ static inline long regs_return_value(struct pt_regs *regs) } #define instruction_pointer(regs) ((regs)->cp0_epc) +extern unsigned long exception_ip(struct pt_regs *regs); +#define exception_ip(regs) exception_ip(regs) #define profile_pc(regs) instruction_pointer(regs) extern asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall); diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c index d9df543f7e2c..59288c13b581 100644 --- a/arch/mips/kernel/ptrace.c +++ b/arch/mips/kernel/ptrace.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -48,6 +49,12 @@ #define CREATE_TRACE_POINTS #include +unsigned long exception_ip(struct pt_regs *regs) +{ + return exception_epc(regs); +} +EXPORT_SYMBOL(exception_ip); + /* * Called by kernel/ptrace.c when detaching.. * diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h index eaaef3ffec22..90507d4afcd6 100644 --- a/include/linux/ptrace.h +++ b/include/linux/ptrace.h @@ -393,6 +393,10 @@ static inline void user_single_step_report(struct pt_regs *regs) #define current_user_stack_pointer() user_stack_pointer(current_pt_regs()) #endif +#ifndef exception_ip +#define exception_ip(x) instruction_pointer(x) +#endif + extern int task_current_syscall(struct task_struct *target, struct syscall_info *info); extern void sigaction_compat_abi(struct k_sigaction *act, struct k_sigaction *oact);