From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A12F4C433ED for ; Thu, 1 Apr 2021 01:55:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 62B9561078 for ; Thu, 1 Apr 2021 01:55:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232565AbhDAByp (ORCPT ); Wed, 31 Mar 2021 21:54:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:51618 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230284AbhDABy1 (ORCPT ); Wed, 31 Mar 2021 21:54:27 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3FD9960FE9; Thu, 1 Apr 2021 01:54:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617242067; bh=I1Vutxd2fotaDN7XIHIAgeH4hifd8ayloeGtrgZkmYA=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=SR0DLDz8rzxeAm6JtFEUCiI7DD/4GT105sl02Mca6xlyT0K2U8VPNqZsol4Bxs97I S5nxB805BmRc/5fzQDrwxoFqc0TO+Q9n3pRAuMn2acus98Tb3mZwyqct21bo3obZUK dZ4CjzvSsjyTUINQjCe0hD/6QA9HZrSu+6ku9KaOoMrmR8wDJIK/XHTDHpQxvwa8Ik a4L8qAqwjDg1747HFbW8qSdDr/aAeUswb9spPTYOna2HSt4oNcjk6oOAVn+LbRgomC sNBs6WHIJAzj9cU+hXuvNJwtHI+urYJvJVvdQHrdi+AjWq3/Yp8+6wGFqFBY+AuT7G enOv3lhHiQpnA== Date: Thu, 1 Apr 2021 10:54:22 +0900 From: Masami Hiramatsu To: Masami Hiramatsu Cc: Josh Poimboeuf , Ingo Molnar , X86 ML , Daniel Xu , linux-kernel@vger.kernel.org, bpf@vger.kernel.org, kuba@kernel.org, mingo@redhat.com, ast@kernel.org, tglx@linutronix.de, kernel-team@fb.com, yhs@fb.com, Steven Rostedt Subject: Re: [RFC PATCH -tip 3/3] x86/kprobes,orc: Unwind optprobe trampoline correctly Message-Id: <20210401105422.bc7953889a2e0aaf03201b92@kernel.org> In-Reply-To: <161716949640.721514.14252504351086671126.stgit@devnote2> References: <161716946413.721514.4057380464113663840.stgit@devnote2> <161716949640.721514.14252504351086671126.stgit@devnote2> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On Wed, 31 Mar 2021 14:44:56 +0900 Masami Hiramatsu wrote: > +#ifdef CONFIG_UNWINDER_ORC > +unsigned long recover_optprobe_trampoline(unsigned long addr, unsigned long *sp) > +{ > + unsigned long offset, entry, probe_addr; > + struct optimized_kprobe *op; > + struct orc_entry *orc; > + > + entry = find_kprobe_optinsn_slot_entry(addr); > + if (!entry) > + return addr; > + > + offset = addr - entry; > + > + /* Decode arg1 and get the optprobe */ > + op = (void *)extract_set_arg1((void *)(entry + TMPL_MOVE_IDX)); > + if (!op) > + return addr; > + > + probe_addr = (unsigned long)op->kp.addr; > + > + if (offset < TMPL_END_IDX) { Maybe I should add a comment here. /* * Since this is on the trampoline code based on the template code, * ORC information on the template code can be used for adjusting * stack pointer. The template code may change the stack pointer to * store pt_regs. */ > + orc = orc_find((unsigned long)optprobe_template_func + offset); > + if (!orc || orc->sp_reg != ORC_REG_SP) > + return addr; > + /* > + * Since optprobe trampoline doesn't push caller on the stack, > + * need to decrement 1 stack entry size > + */ > + *sp += orc->sp_offset - sizeof(long); > + return probe_addr; > + } else { /* * In this case, the address is on the instruction copied from probed * address, and jump instruction. Here the stack pointer is exactly * the same as the value where it was copied by the kprobes. */ > + return probe_addr + offset - TMPL_END_IDX; > + } > +} > +#endif > + Thank you, -- Masami Hiramatsu