Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp689100ybv; Thu, 13 Feb 2020 07:48:43 -0800 (PST) X-Google-Smtp-Source: APXvYqzngKo0JcO7IQZwDsn1PZikwYefEBfekpn2bJ4xQDj0nDnKiYwERuMfAYRYwdULaEs7iRge X-Received: by 2002:aca:dc04:: with SMTP id t4mr3193594oig.51.1581608923591; Thu, 13 Feb 2020 07:48:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581608923; cv=none; d=google.com; s=arc-20160816; b=UOrVqKea07tQ+oXJ8mM7bxob/C8H/eCBIgV7gSUuFaG98Km0rKxyTv5kzKaLuRbRMU VE0eLFNEJLTtw0cYrlH/DfgdRdl5W8L2a6r5a+WcgEl5nJHDjhjPGpKfhi4+zd04lWe6 aqMoBElf8uGg7XCj6q+BJ0HiXg4nDaVqhaAatBUEpD++hjSnYA4nyvO+CGDsjQroIAbw 02A5/eBpoyQyvtlllCZSJ5mr0j/HACnrmxF/tIanF6S2ziYJ8Sq1YLG+VJgW7M9bOdBD +v4mbYpIdC/atRzCZYzMiROgwKBvNOcu9u7tF3JltXSX7pW299zdSERrI4a4VpCl25sl BACw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9LutolyAOq0MonDyXSivvU6qZixm2LsDT/L/Jq99wOw=; b=hqS5JRG3Kceev00Jk47+8ejRjvitNiQhW3895u6uXSOH7C9l+8fnUG5pew5wJ4U8yU 0ptFJELVFeUFI5tm++kYRAp+u/7tOrOJT0qlQqQbMw94u5SRflNNqJi96Z/xDRk0irnE F83o+arHPAYdAAQjcAeaHiy53eOQmpIT39Csh3y35e9BqEXAG1wLzoXkz1IesfxqS/T2 eeqdiDBK+nB0Co3dhHHcgYoqQRhscI7YDWsTInPPwsE8sWCReYYcSMK5YDUuzi/nDpAu S/yWuLIw/ZomebCklMzf8n1OHIoVMV/h7PKiR1HJ2msXdqJ2CWbuk+c9MnztAKlI09/H 1LbQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="eI/shsGz"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l10si1289367oth.243.2020.02.13.07.48.29; Thu, 13 Feb 2020 07:48:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b="eI/shsGz"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729313AbgBMPsZ (ORCPT + 99 others); Thu, 13 Feb 2020 10:48:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:47872 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729295AbgBMP04 (ORCPT ); Thu, 13 Feb 2020 10:26:56 -0500 Received: from localhost (unknown [104.132.1.104]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EFA0B206DB; Thu, 13 Feb 2020 15:26:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581607615; bh=dVJglPzkGQNWLRZbvnUE/tGiFH6lQqO/45Lkw0Kd2MA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eI/shsGzg4Pn+ydIjDTWZSfig+al9DF8B8yJgI8IBFXpJNILRE55fvJd+RC+EmZCY drKSf2ZrTRM7gia74hc7JwOfHPZfrVeipKYC5V4a7oORy1wBNmiXj5KFQtAa53WgXR YZicYS2KYT3Mh0eNBhDe2Llb0UBRpbdPhpUKIOxA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, "Peter Zijlstra (Intel)" , Josh Poimboeuf , Linus Torvalds , Thomas Gleixner , Ingo Molnar , Dmitry Safonov Subject: [PATCH 4.19 51/52] x86/stackframe: Move ENCODE_FRAME_POINTER to asm/frame.h Date: Thu, 13 Feb 2020 07:21:32 -0800 Message-Id: <20200213151830.764945877@linuxfoundation.org> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200213151810.331796857@linuxfoundation.org> References: <20200213151810.331796857@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peter Zijlstra commit a9b3c6998d4a7d53a787cf4d0fd4a4c11239e517 upstream. In preparation for wider use, move the ENCODE_FRAME_POINTER macros to a common header and provide inline asm versions. These macros are used to encode a pt_regs frame for the unwinder; see unwind_frame.c:decode_frame_pointer(). Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Josh Poimboeuf Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Signed-off-by: Ingo Molnar Signed-off-by: Dmitry Safonov Signed-off-by: Greg Kroah-Hartman --- arch/x86/entry/calling.h | 15 ------------- arch/x86/entry/entry_32.S | 16 -------------- arch/x86/include/asm/frame.h | 49 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 31 deletions(-) --- a/arch/x86/entry/calling.h +++ b/arch/x86/entry/calling.h @@ -172,21 +172,6 @@ For 32-bit we have the following convent .endif .endm -/* - * This is a sneaky trick to help the unwinder find pt_regs on the stack. The - * frame pointer is replaced with an encoded pointer to pt_regs. The encoding - * is just setting the LSB, which makes it an invalid stack address and is also - * a signal to the unwinder that it's a pt_regs pointer in disguise. - * - * NOTE: This macro must be used *after* PUSH_AND_CLEAR_REGS because it corrupts - * the original rbp. - */ -.macro ENCODE_FRAME_POINTER ptregs_offset=0 -#ifdef CONFIG_FRAME_POINTER - leaq 1+\ptregs_offset(%rsp), %rbp -#endif -.endm - #ifdef CONFIG_PAGE_TABLE_ISOLATION /* --- a/arch/x86/entry/entry_32.S +++ b/arch/x86/entry/entry_32.S @@ -245,22 +245,6 @@ .Lend_\@: .endm -/* - * This is a sneaky trick to help the unwinder find pt_regs on the stack. The - * frame pointer is replaced with an encoded pointer to pt_regs. The encoding - * is just clearing the MSB, which makes it an invalid stack address and is also - * a signal to the unwinder that it's a pt_regs pointer in disguise. - * - * NOTE: This macro must be used *after* SAVE_ALL because it corrupts the - * original rbp. - */ -.macro ENCODE_FRAME_POINTER -#ifdef CONFIG_FRAME_POINTER - mov %esp, %ebp - andl $0x7fffffff, %ebp -#endif -.endm - .macro RESTORE_INT_REGS popl %ebx popl %ecx --- a/arch/x86/include/asm/frame.h +++ b/arch/x86/include/asm/frame.h @@ -22,6 +22,35 @@ pop %_ASM_BP .endm +#ifdef CONFIG_X86_64 +/* + * This is a sneaky trick to help the unwinder find pt_regs on the stack. The + * frame pointer is replaced with an encoded pointer to pt_regs. The encoding + * is just setting the LSB, which makes it an invalid stack address and is also + * a signal to the unwinder that it's a pt_regs pointer in disguise. + * + * NOTE: This macro must be used *after* PUSH_AND_CLEAR_REGS because it corrupts + * the original rbp. + */ +.macro ENCODE_FRAME_POINTER ptregs_offset=0 + leaq 1+\ptregs_offset(%rsp), %rbp +.endm +#else /* !CONFIG_X86_64 */ +/* + * This is a sneaky trick to help the unwinder find pt_regs on the stack. The + * frame pointer is replaced with an encoded pointer to pt_regs. The encoding + * is just clearing the MSB, which makes it an invalid stack address and is also + * a signal to the unwinder that it's a pt_regs pointer in disguise. + * + * NOTE: This macro must be used *after* SAVE_ALL because it corrupts the + * original ebp. + */ +.macro ENCODE_FRAME_POINTER + mov %esp, %ebp + andl $0x7fffffff, %ebp +.endm +#endif /* CONFIG_X86_64 */ + #else /* !__ASSEMBLY__ */ #define FRAME_BEGIN \ @@ -30,12 +59,32 @@ #define FRAME_END "pop %" _ASM_BP "\n" +#ifdef CONFIG_X86_64 +#define ENCODE_FRAME_POINTER \ + "lea 1(%rsp), %rbp\n\t" +#else /* !CONFIG_X86_64 */ +#define ENCODE_FRAME_POINTER \ + "movl %esp, %ebp\n\t" \ + "andl $0x7fffffff, %ebp\n\t" +#endif /* CONFIG_X86_64 */ + #endif /* __ASSEMBLY__ */ #define FRAME_OFFSET __ASM_SEL(4, 8) #else /* !CONFIG_FRAME_POINTER */ +#ifdef __ASSEMBLY__ + +.macro ENCODE_FRAME_POINTER ptregs_offset=0 +.endm + +#else /* !__ASSEMBLY */ + +#define ENCODE_FRAME_POINTER + +#endif + #define FRAME_BEGIN #define FRAME_END #define FRAME_OFFSET 0