Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5175320pxj; Wed, 26 May 2021 04:48:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycB0NmTsCNPPJ7hyEfEKPsxZD5IcZAhsDbmJDTUVvdtFAto4xTuZLLCy9YniOYjDbhusqH X-Received: by 2002:a92:cec5:: with SMTP id z5mr26320201ilq.110.1622029702991; Wed, 26 May 2021 04:48:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622029702; cv=none; d=google.com; s=arc-20160816; b=HoBMhejXufU4pJKVdC4GzY4cshy7RK1lnxcDBGUag0sBe+bm9hxnokysF5mVnXGhp/ 6WFaBlsEKSim+5nxLX8on0s+RMtf8TYFMXTROvj2ApBSymTrpguVdnnN0SEiHOu4bMSk uK/4RXUEHT70QXnvCVqbFtntnltkJKRaOY1ZC0uKy25XOPfJ4ghhmiZYUUCZYOvQGZgr GwmtcUXcnqILNqN6E0VWICVlZThYKzT7wCXYxSinGa5kdM8bsIqNZMAXmoQ8ryN9kLGK /5FarWCcjS7slmd4ZH3rzyOnIeUDC60mjolIGpxSRXHf3qmk3VohSpVFYDGh/sS71l16 jkyA== 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=97d306/K1Fv/W2CUXkHQgohRmw/Zngu3UXDJ/K6tFuc=; b=zRE3HLup3+/bMf/3Ny9haAwqTE+8FXAYNPrN/pGk4vJIpbHJRZiGgEm0BdNe6t5tWs u1aqzoYNYlzs3IxQ3U/13IK1gn69DNQpK5LGo6muVgcZYhK4NBbG7L6DPgDh1FrbEzv1 46JYEQNWeLhSzIIieWwYIz7KNAQahiAHZ2kQiIaDrXR8oNMpnJDDW14lqj+ie/L24yeA 5dKdzs3Zo10nZk4D2p0UH5/6Ldwh1CuEqrij8bjttNPbgaFXb5NJ5elpk4/uTbcRQ0Q/ l1e7Eo1LRzA7xLetjx22zEXv8HVqgFor7vH1JyqhlqQjkPzYxsJRH2HZgu5k9gH2QTtZ FLtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nc33AMMF; 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 m5si14564631jat.27.2021.05.26.04.48.05; Wed, 26 May 2021 04:48:22 -0700 (PDT) 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=nc33AMMF; 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 S233133AbhEZIEm (ORCPT + 99 others); Wed, 26 May 2021 04:04:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:39798 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233221AbhEZIEg (ORCPT ); Wed, 26 May 2021 04:04:36 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id B0B46613E6; Wed, 26 May 2021 08:03:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622016185; bh=5U6gnRUEzaqQIkCP8wcc1KtYEL1lDPSvMCtG2RgQz88=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nc33AMMFESxZKrv9ARLJmoycJenzTlk0F/V/siGES0Msaxp4qmzb4TjkzvWn4KPPN 28dCwK3LA4KaAxgDO5snTBMaEMHYIZPaQlUNuG9biJgN7eJu/+RmMOmxRUnAd+y+n1 6fcI0TfoRQQPDo8oblQBzLiJEd0FD2rhd/xATn8z9Nk2nLhPM+Xr+hopkgvBUc5W3H HlvtLRmKv0tkcUe9Lzn21C1eIPP/GNVOpo6O0Y4D+FVJQA48hhFnD8ghG5UJPYJe/A qoeiktG9bBgXm+/x+NWonjw660oOekukxrxBlE/I0qAaaDheyPcl2E7BTJYYZncNhn uv1uWwr/HTazw== 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 , linux-ia64@vger.kernel.org, Abhishek Sagar , Andrii Nakryiko Subject: [PATCH -tip v6 05/13] x86/kprobes: Add UNWIND_HINT_FUNC on kretprobe_trampoline code Date: Wed, 26 May 2021 17:03:00 +0900 Message-Id: <162201618061.278331.13571474279522709453.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <162201612941.278331.5293566981784464165.stgit@devnote2> References: <162201612941.278331.5293566981784464165.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 From: Josh Poimboeuf Add UNWIND_HINT_FUNC on kretporbe_trampoline code so that ORC information is generated on the kretprobe_trampoline correctly. Note that when the CONFIG_FRAME_POINTER=y, since the kretprobe_trampoline skips updating frame pointer, the stack frame of the kretprobe_trampoline seems non-standard. So this marks it is STACK_FRAME_NON_STANDARD() and undefine UNWIND_HINT_FUNC. Anyway, with the frame pointer, FP unwinder can unwind the stack frame correctly without that hint. Signed-off-by: Josh Poimboeuf Signed-off-by: Masami Hiramatsu --- Changes in v4: - Apply UNWIND_HINT_FUNC only if CONFIG_FRAME_POINTER=n. --- arch/x86/include/asm/unwind_hints.h | 5 +++++ arch/x86/kernel/kprobes/core.c | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/arch/x86/include/asm/unwind_hints.h b/arch/x86/include/asm/unwind_hints.h index 8e574c0afef8..8b33674288ea 100644 --- a/arch/x86/include/asm/unwind_hints.h +++ b/arch/x86/include/asm/unwind_hints.h @@ -52,6 +52,11 @@ UNWIND_HINT sp_reg=ORC_REG_SP sp_offset=8 type=UNWIND_HINT_TYPE_FUNC .endm +#else + +#define UNWIND_HINT_FUNC \ + UNWIND_HINT(ORC_REG_SP, 8, UNWIND_HINT_TYPE_FUNC, 0) + #endif /* __ASSEMBLY__ */ #endif /* _ASM_X86_UNWIND_HINTS_H */ diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c index d32b09ca3221..9a6763fd066e 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -1019,6 +1019,19 @@ int kprobe_int3_handler(struct pt_regs *regs) } NOKPROBE_SYMBOL(kprobe_int3_handler); +#ifdef CONFIG_FRAME_POINTER +/* + * kretprobe_trampoline skips updating frame pointer. The frame pointer + * saved in trampoline_handler points to the real caller function's + * frame pointer. Thus the kretprobe_trampoline doesn't seems to have a + * standard stack frame with CONFIG_FRAME_POINTER=y. + * Let's mark it non-standard function. Anyway, FP unwinder can correctly + * unwind without the hint. + */ +STACK_FRAME_NON_STANDARD(kretprobe_trampoline); +#undef UNWIND_HINT_FUNC +#define UNWIND_HINT_FUNC +#endif /* * When a retprobed function returns, this code saves registers and * calls trampoline_handler() runs, which calls the kretprobe's handler. @@ -1031,6 +1044,7 @@ asm( /* We don't bother saving the ss register */ #ifdef CONFIG_X86_64 " pushq %rsp\n" + UNWIND_HINT_FUNC " pushfq\n" SAVE_REGS_STRING " movq %rsp, %rdi\n" @@ -1041,6 +1055,7 @@ asm( " popfq\n" #else " pushl %esp\n" + UNWIND_HINT_FUNC " pushfl\n" SAVE_REGS_STRING " movl %esp, %eax\n" @@ -1054,8 +1069,6 @@ asm( ".size kretprobe_trampoline, .-kretprobe_trampoline\n" ); NOKPROBE_SYMBOL(kretprobe_trampoline); -STACK_FRAME_NON_STANDARD(kretprobe_trampoline); - /* * Called from kretprobe_trampoline