Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp1124943pxv; Fri, 9 Jul 2021 18:44:18 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNjpXb0AINVCHe+im7RdU9gUngPHMiFfk8QQ0U4mLf/Rymk56eQXEwVjFTCVhFKl5UGjtT X-Received: by 2002:a92:c5c8:: with SMTP id s8mr26611829ilt.38.1625881458215; Fri, 09 Jul 2021 18:44:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1625881458; cv=none; d=google.com; s=arc-20160816; b=CmYTqPpif4XqDTzttsatPT/wj7itXPKofrxdyY9O7me4chRn/FDK86pODKz6VpcBqR xi1+8pjMKNLDBWtVeFiiam1fyFNoB2GsJqnIdEtms0H6YvKFmSCb3qfo6Yollx8gk4Sz IqLeBd6YLhCYuAXXwwkUu1L/D4HKDZnTFhrjOnlbbqp1Rq13V2zWgYe6NFITg5T5F3RH K4NfeIH59WPIGwFUgZr+etMJBRklhRI/sIKFx4e4kgBbfN+lTfU46kN4L5IOdqcgXmBu NTrGtOfAPdz6Sy3Acxm7j91f/+5QptA0lfG302KY+nTOA+zYiDcLQ4eHZ8iX1VSivwRk pShA== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=iCXZ96ry1I/wZoDXOkSe2sC0rw4AuQLOD/ul749nj3c=; b=th0O9b4xYBvOSjGebcAZxsG9I8D7RNIlTGk4dB8lAtBD+4T11+sVf7spLUQC55XiGX IwT4sgQvXp4Yc+ie319X6YK/bikN3+CqPBXToHy0oBaAIyW4S4t1BZleW9Wul25uqdb8 QxZzMFV7ZzoUql21R3rNpkPNxVhAy9wN0sTzs4Z83e0U05QWkey00t3e3u5VFW5avh7s umH4juyygluO73WaIBrP98Y3el2Vz0bqcczrwK6qrn+0Q1RE8dcVle0bc5JBCqeCNUgq QvQFIp8tolK/Qmj7/ksn27QNYpYDSOCmOApB3IR5DSqZlm7U5wxcM9016biN+ZkOglzP 250g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KG6Vl4zF; 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 v14si7880694iom.9.2021.07.09.18.44.04; Fri, 09 Jul 2021 18:44:18 -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=KG6Vl4zF; 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 S231253AbhGJBny (ORCPT + 99 others); Fri, 9 Jul 2021 21:43:54 -0400 Received: from mail.kernel.org ([198.145.29.99]:35054 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229703AbhGJBnx (ORCPT ); Fri, 9 Jul 2021 21:43:53 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id A544661369; Sat, 10 Jul 2021 01:41:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1625881269; bh=+B762d+bq/P3YApL0HbKAGd5FC2iONbt41tss4/+kfQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=KG6Vl4zFwfbbLHLcv3xNyv4CShhXLOO7so/wCHH00D8DMcYkEfz0l6nr+gc5K/rbB IIZ3PVZ4oS1pINjm8s+1l4XO6U0H+8tHNCFqQYY8hJF6I586MK06gj8We90aOlgvfv cQz+Y5wStzh2h5/z09Ctx60/c6Tig9yeGEWgzKFzh0u6y9m2wyW1i+guN71WcaoL2f T9C4CdO8kQp/mvIGzalEj96Ss/m82rgdX/wAWh/vRUtikASYmsAUcKmn6R4mpwTibO XT0dJuyuT/8yTk33dSnhhbevsjx++a6V6eDJKy5EQl/tgsfBhss8lYC7+JU8HgSaZb yKmD/DJL0AsIQ== Date: Sat, 10 Jul 2021 10:41:04 +0900 From: Masami Hiramatsu To: Josh Poimboeuf , Ingo Molnar Cc: Steven Rostedt , X86 ML , 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 , Masami Hiramatsu Subject: Re: [PATCH -tip v8 05/13] x86/kprobes: Add UNWIND_HINT_FUNC on kretprobe_trampoline code Message-Id: <20210710104104.3a270168811ac38420093276@kernel.org> In-Reply-To: <20210710003140.8e561ad33d42f9ac78de6a15@kernel.org> References: <162399992186.506599.8457763707951687195.stgit@devnote2> <162399996966.506599.810050095040575221.stgit@devnote2> <20210710003140.8e561ad33d42f9ac78de6a15@kernel.org> 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: linux-kernel@vger.kernel.org Hi Ingo and Josh, On Sat, 10 Jul 2021 00:31:40 +0900 Masami Hiramatsu wrote: > > > +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" > > > > Why not provide an appropriate annotation method in , > > so that other future code can use it too instead of reinventing the wheel? I think I got what you meant. Let me summarize the issue. In case of CONFIG_FRAME_POINTER=n, it is OK just adding UNWIND_HINT_FUNC. In case of CONFIG_FRAME_POINTER=y, without STACK_FRAME_NON_STANDARD(), the objtool complains that a CALL instruction without the frame pointer. --- arch/x86/kernel/kprobes/core.o: warning: objtool: __kretprobe_trampoline()+0x25: call without frame pointer save/setup --- If we just add STACK_FRAME_NON_STANDARD() with UNWIND_HINT_FUNC macro, the objtool complains that non-standard function has unwind hint. --- arch/x86/kernel/kprobes/core.o: warning: objtool: __kretprobe_trampoline()+0x1: BUG: why am I validating an ignored function? --- Thus, add STACK_FRAME_NON_STANDARD() and undefine UNWIND_HINT_FUNC macro, the objtool doesn't complain. This means that the STACK_FRAME_NON_STANDARD() and UNWIND_HINT_FUNC macro are mutually exclusive. However, those macros are used different way. The STACK_FRAME_NON_STANDARD() will have the target symbol and the UNWIND_HINT_FUNC needs to be embedded in the target code. Thus we can not combine them in general. If we can have something like UNWIND_HINT_FUNC_NO_FP, it may solve this issue without ugly #ifdef and #undef. Is that correct? Maybe I can add UNWIND_HINT_TYPE_FUNC_NO_FP for UNWIND_HINT and make objtool ignore the call without frame pointer. This makes an exception that the kretprobe_trampoline will be noted in '.discard.unwind_hints' section instead of '.discard.func_stack_frame_non_standard' section. Or another idea is to introduce ANNOTATE_NO_FP_FUNCTION_CALL with a new '.discard.no_fp_function_calls' section. What do you think these ideas? Thank you, -- Masami Hiramatsu