Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp738428pxb; Tue, 14 Sep 2021 07:44:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzq+lEKZ9esusTgBeHbQ/QxrrpzOHsih+NB82o6JWj5MHo0p4mGAP4/E6BXfi8DvbRuwah3 X-Received: by 2002:a17:906:130a:: with SMTP id w10mr19802119ejb.87.1631630668441; Tue, 14 Sep 2021 07:44:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631630668; cv=none; d=google.com; s=arc-20160816; b=jm/DUkw55iwJEEIpMwOVVs7cy7AyQxPUX+HmMj1jhA2GGLVWEgLDx3mwuLstwrMPEv g6kw5ouzEjkK6X1qtHOsH5gRXh3tEJte2BhNlH/IcklkL7AIQ42CmYobeQu7r5ir1gIv 7pwC97aV73q7RvYlITbnwUsp+Ymwck/s4CUnXgBlFHGz1n07Ywb4/1CEF2PujNQc9Uii 7A+1wdqXC5ySjm/QbtJN2JVb+ZSujPCwne8Zckg19NAM7Fh5pLCeNkMWOxws1dbC998r DpOuHGlYtY+VFg9CbOIlBQMyyJgmYw9j23D7LeG+haDkwvflNMGA16zTOFDpR4rdmtM6 W7HQ== 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=l4kqfHIHYYrQCGhXVOmFT2UR5oPzlmECRyJYQEOX79M=; b=Gnn9hMZuWg0SSrucmoQjDe9HdokjsY7JPGThaxIg6NYEE4fCOD5BEj/qUWZjZFgSZX 83NUqUgpPghlw5WnrHiYPkgaHc7nQy0lTTzp6TezgHtNz60QuPKkkVlvNF+64Y+bZ+rZ uBqV6pI9qciFS6jSxri5suUi8+A29eoq1UyRMx/QeSoV0eMDlccC799GK6bnmFkPIE7K VtjZhugZRfOqnNsyITKSCmRAtnX5GcNHiQXm7ZMWVO6LNnHCkpCuJ3wNT5O3NVFObK/3 bFMBFnvxegZ7R1IbXcLNEPT0hdSUdGMQH7Ln81/ltUvz7COddJ0UzniC7O5WvoLPPrR0 oQBA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=vHG+giDP; 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 hc43si3722337ejc.87.2021.09.14.07.44.03; Tue, 14 Sep 2021 07:44:28 -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=vHG+giDP; 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 S233562AbhINOnp (ORCPT + 99 others); Tue, 14 Sep 2021 10:43:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:36810 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234420AbhINOmx (ORCPT ); Tue, 14 Sep 2021 10:42:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id E254F603E8; Tue, 14 Sep 2021 14:41:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1631630496; bh=Rdr5qCe1gNFYBhdSCbvzhAs4VdI1+Mgp+bv4Bzlp+MA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vHG+giDP/dbUyac5wxc/wk2mx/ILtd1Htz1XmZB6NiW73iFZjLUoWsEP0hiJl2iPk eggeks+/ndGy5u9EglW237kI/e2TRDxpzjOdYUqTLNC93CzVJs0hLtXAaee9ScMcIE 59ijkYdFS9xo3/79kCaR4DVycu9TDbFFpOp5IjK5YN/HysIXj5j2kGEIaQyKujTJaS 43Xz2KVo0m5PuNJJuhOLV6fqvXtnE/JgDniwFkHEq/30j5a6xzJnn/IOgrJP+VlBD1 4rP5LlmjMQSIztoUY3aw+Zf5wMCs8BmM2/lz6tTsef5c8O70nBjerXB31dQJp9ESrN 4Bw+j8nEj0FPg== From: Masami Hiramatsu To: Steven Rostedt , Josh Poimboeuf , 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, Thomas Gleixner , Borislav Petkov , Peter Zijlstra , kernel-team@fb.com, yhs@fb.com, linux-ia64@vger.kernel.org, Abhishek Sagar , Andrii Nakryiko , Paul McKenney Subject: [PATCH -tip v11 19/27] x86/kprobes: Add UNWIND_HINT_FUNC on kretprobe_trampoline() Date: Tue, 14 Sep 2021 23:41:32 +0900 Message-Id: <163163049242.489837.11970969750993364293.stgit@devnote2> X-Mailer: git-send-email 2.25.1 In-Reply-To: <163163030719.489837.2236069935502195491.stgit@devnote2> References: <163163030719.489837.2236069935502195491.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 __kretprobe_trampoline() code so that ORC information is generated on the __kretprobe_trampoline() correctly. Also, this uses STACK_FRAME_NON_STANDARD_FP(), CONFIG_FRAME_POINTER- -specific version of STACK_FRAME_NON_STANDARD(). Signed-off-by: Josh Poimboeuf Signed-off-by: Masami Hiramatsu Tested-by: Andrii Nakryiko --- Changes in v9: - Update changelog and fix comment. - Use STACK_FRAME_NON_STANDARD_FP(). 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 | 13 +++++++++++-- 2 files changed, 16 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 79cd23dba5b5..d1436d7463fd 100644 --- a/arch/x86/kernel/kprobes/core.c +++ b/arch/x86/kernel/kprobes/core.c @@ -1025,6 +1025,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" @@ -1035,6 +1036,7 @@ asm( " popfq\n" #else " pushl %esp\n" + UNWIND_HINT_FUNC " pushfl\n" SAVE_REGS_STRING " movl %esp, %eax\n" @@ -1048,8 +1050,15 @@ asm( ".size __kretprobe_trampoline, .-__kretprobe_trampoline\n" ); NOKPROBE_SYMBOL(__kretprobe_trampoline); -STACK_FRAME_NON_STANDARD(__kretprobe_trampoline); - +/* + * __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 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_FP(__kretprobe_trampoline); /* * Called from __kretprobe_trampoline