Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1011539pxf; Thu, 11 Mar 2021 22:51:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJyM6aaWiWRdhb0k3by3USVTbigFz5yqHc643atWcodC79JSif4f4ly/5gZuT+sSQZbwFWxq X-Received: by 2002:a17:906:6a06:: with SMTP id o6mr6777744ejr.306.1615531869011; Thu, 11 Mar 2021 22:51:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615531869; cv=none; d=google.com; s=arc-20160816; b=uxwH5uJF0oHfLZPkCF1M8G7qPrIMX+9RDEosqPZo1im0s4JLgincOxapRovIqwWPvf 4sfZa2MuCwj40bl7g09iV63AzQDIswX1/cllc2Ur749HSpzMYOnBicNn+u0LY25oqe00 IV3RZ6o/D03nQDkpdqcO6JvHyYjs2qIGCmNQAtql8Q/L7XbAk9OCFxHq7naya1xfIcm1 ZvVe72R96JM+ynba2lRntj8UtBG1p4RkwSN+o3ym4Zxf0dKKrul0rEVqXXyrppo1HwQn r5bznz4xFUk9/acGIsCM7dvYSyfMYFVWxj/Ef7WsKfwEL9F1uE3PMaP4QhkyqDUHIzEf JhGw== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hxqX33CaNQfM9lmlWEA60XjxI2T+SrP9oAaZzFfO198=; b=z+/hJAbHojoP59HCybBcQz7MyJwlQDtWdTGJ3/k3v6osUtgmq0YvrmOMKVFonxne3p ngFzy8T+vDXIUvzJs9+uwS6J4N8t8+dq7LfxkGh/RnHLKviJiIMST9YW3HZyjRUlaeXW gnsHM7nwszq1GJTyJld1XGL2BXkEDe94f6thm15XxchDrosKfyg6ivRe5AcyYLUgl3AD 1/C+klZysJ3YwcxNbAKbBcLGLgdKUpQZAvPCz6WdH+5l0AuMvIHtc6LQBU+/k4aZ1ks4 GQ8tuEO/vrVj59D5FKaO4MpuYNrO5cIG5GzoAVXqkGxGQPPTowTyMC1xhQDlplQ0eRwN K5mA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=opD0oKMo; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o5si3408592ejn.708.2021.03.11.22.50.46; Thu, 11 Mar 2021 22:51:09 -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=@kernel.org header.s=k20201202 header.b=opD0oKMo; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232003AbhCLGoD (ORCPT + 99 others); Fri, 12 Mar 2021 01:44:03 -0500 Received: from mail.kernel.org ([198.145.29.99]:44634 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231455AbhCLGn3 (ORCPT ); Fri, 12 Mar 2021 01:43:29 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id EC47464EB6; Fri, 12 Mar 2021 06:43:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1615531408; bh=mpvxBHYBzRcmD/WHhPgUBtQsJ0SZN+lEfVNGaJSdsC4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=opD0oKMoenMnstmi+aFhU1o4daS4YOaELLEXNbtYLDQg8S9yRH4Mgd0d4k96XszVO aqyB8j0Dd8jUGJnaJ6QKcAVBYdiEfaxwzs79+F7SYIHhGTqrpAK55YZRF5/fti9FEw 7aDT83k7/ScNEbLxuRXWRXtBvXWfHUkgGBHCw91P8brHCGi4Hs6omP2dPyc6enrfH7 rrmnT+v0pHn9Ig44TAD2dTFfEoM8oA+c886g1VxFz8VmccUodmtct8Msf1vXNO7oPs ezUkSLA9A+xLMWqX1gTUnI82I/t2foaE3+bEdtcv8tVS4UodonkQ7tnn2cU8HETWg8 CW9q+v5bzPYxQ== From: Masami Hiramatsu To: Steven Rostedt , Ingo Molnar Cc: X86 ML , Masami Hiramatsu , 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, Josh Poimboeuf Subject: [PATCH -tip v2 09/10] x86/unwind/orc: Fixup kretprobe trampoline entry Date: Fri, 12 Mar 2021 15:43:23 +0900 Message-Id: <161553140351.1038734.4282308401106671492.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <161553130371.1038734.7661319550287837734.stgit@devnote2> References: <161553130371.1038734.7661319550287837734.stgit@devnote2> User-Agent: StGit/0.19 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since the kretprobe replaces the function return address with the kretprobe_trampoline on the stack, the ORC unwinder can not continue the stack unwinding at that point. To fix this issue, correct state->ip as like as function-graph tracer in the unwind_next_frame(). Signed-off-by: Masami Hiramatsu --- Changes in v2: - Remove kretprobe wrapper functions from unwind_orc.c - Do not fixup state->ip when unwinding with regs because kretprobe fixup instruction pointer before calling handler. --- arch/x86/include/asm/unwind.h | 4 ++++ arch/x86/kernel/unwind_orc.c | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/arch/x86/include/asm/unwind.h b/arch/x86/include/asm/unwind.h index 70fc159ebe69..ab5e45b848d5 100644 --- a/arch/x86/include/asm/unwind.h +++ b/arch/x86/include/asm/unwind.h @@ -4,6 +4,7 @@ #include #include +#include #include #include @@ -20,6 +21,9 @@ struct unwind_state { bool signal, full_regs; unsigned long sp, bp, ip; struct pt_regs *regs, *prev_regs; +#if defined(CONFIG_KRETPROBES) + struct llist_node *kr_iter; +#endif #elif defined(CONFIG_UNWINDER_FRAME_POINTER) bool got_irq; unsigned long *bp, *orig_sp, ip; diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c index 2a1d47f47eee..1d1b9388a1b1 100644 --- a/arch/x86/kernel/unwind_orc.c +++ b/arch/x86/kernel/unwind_orc.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -536,6 +537,21 @@ bool unwind_next_frame(struct unwind_state *state) state->ip = ftrace_graph_ret_addr(state->task, &state->graph_idx, state->ip, (void *)ip_p); + /* + * When the stack unwinder is called from the kretprobe handler + * or the interrupt handler which occurs in the kretprobe + * trampoline code, %sp is shown on the stack instead of the + * return address because kretprobe_trampoline() does + * "push %sp" at first. + * And also the unwinder may find the kretprobe_trampoline + * instead of the real return address on stack. + * In those cases, find the correct return address from + * task->kretprobe_instances list. + */ + if (state->ip == sp || + is_kretprobe_trampoline(state->ip)) + state->ip = kretprobe_find_ret_addr(state->task, + &state->kr_iter); state->sp = sp; state->regs = NULL;