From patchwork Thu Aug 17 07:13:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Masami Hiramatsu (Google)" X-Patchwork-Id: 9905089 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7625960244 for ; Thu, 17 Aug 2017 07:15:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 67CB528ABC for ; Thu, 17 Aug 2017 07:15:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5C88328AC0; Thu, 17 Aug 2017 07:15:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_LOW autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DE66F28ABC for ; Thu, 17 Aug 2017 07:15:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=SaiHo2S6DFJTWuZnkOOuaj+9LKLY19N47H4yPfFgTRM=; b=R56fWEw2cygNEE xNAjcEwiV5DJK93Wt56rvNxNL5JOtFMJaCpwKt4mIFvmRh6iYqwHWGnKUPiXi0InHzXXdBiyImTWb 4WBsLrOWKgsaGXejpERf8NYxJtFKWuAoWIjQ9oNQGmN1oU4vlZuAlLexeVtZTziu6OMcCRBFWnmcR Q4yyRz0+mLsy5H+cpZEjtciWKJJZrQyKLfMhwljK2VOxp3XZTxm/oGYqioZVVilNaFrFl8BdordNs oJoDSbsicasxA0uzsDGV4Td/8zodFLwErywuOlrhwOgkn7Gf7eQkCbpXu2jotuQNJ841vuIczu/GU FwGGOe4Gn2JtGcbPXmDA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1diF1J-0005j9-Ly; Thu, 17 Aug 2017 07:15:09 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1diF1F-0004vr-LE for linux-arm-kernel@lists.infradead.org; Thu, 17 Aug 2017 07:15:07 +0000 Received: from localhost.localdomain (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (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 1C9A32170E; Thu, 17 Aug 2017 07:14:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1C9A32170E Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=mhiramat@kernel.org From: Masami Hiramatsu To: Ingo Molnar Subject: [PATCH -tip 1/4] x86: Add in_entry_text() helper function Date: Thu, 17 Aug 2017 16:13:55 +0900 Message-Id: <150295402564.14424.15300433101224423177.stgit@devbox> X-Mailer: git-send-email 2.13.4 In-Reply-To: <150295395797.14424.968407208436624832.stgit@devbox> References: <150295395797.14424.968407208436624832.stgit@devbox> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170817_001505_878425_38AD2AD3 X-CRM114-Status: GOOD ( 14.88 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Arnd Bergmann , Peter Zijlstra , Catalin Marinas , x86@kernel.org, Will Deacon , Russell King , linux-kernel@vger.kernel.org, Ingo Molnar , Masami Hiramatsu , "H . Peter Anvin" , Thomas Gleixner , Thierry Reding , Andrew Morton , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add in_entry_text() helper function to cleanup entry/irqentry section checking code in kprobes and unwind_frame. Signed-off-by: Masami Hiramatsu --- arch/x86/include/asm/sections.h | 15 +++++++++++++++ arch/x86/kernel/kprobes/opt.c | 5 +---- arch/x86/kernel/unwind_frame.c | 15 +-------------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/arch/x86/include/asm/sections.h b/arch/x86/include/asm/sections.h index 2f75f30cb2f6..bb72ea0f4367 100644 --- a/arch/x86/include/asm/sections.h +++ b/arch/x86/include/asm/sections.h @@ -11,4 +11,19 @@ extern struct exception_table_entry __stop___ex_table[]; extern char __end_rodata_hpage_align[]; #endif +/** + * in_entry_text - check if an address is in entry_text or irqentry_text + * @addr: virtual address to be checked + * + * Returns: true if the address specified by @addr is in the entry_text or + * irqentry_text, false otherwise. + */ +static inline bool in_entry_text(unsigned long addr) +{ + return memory_contains(__entry_text_start, __entry_text_end, + (void *)addr, 0) || + memory_contains(__irqentry_text_start, __irqentry_text_end, + (void *)addr, 0); +} + #endif /* _ASM_X86_SECTIONS_H */ diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c index 4f98aad38237..74c5ad55ba6a 100644 --- a/arch/x86/kernel/kprobes/opt.c +++ b/arch/x86/kernel/kprobes/opt.c @@ -254,10 +254,7 @@ static int can_optimize(unsigned long paddr) * Do not optimize in the entry code due to the unstable * stack handling and registers setup. */ - if (((paddr >= (unsigned long)__entry_text_start) && - (paddr < (unsigned long)__entry_text_end)) || - ((paddr >= (unsigned long)__irqentry_text_start) && - (paddr < (unsigned long)__irqentry_text_end))) + if (in_entry_text(paddr)) return 0; /* Check there is enough space for a relative jump. */ diff --git a/arch/x86/kernel/unwind_frame.c b/arch/x86/kernel/unwind_frame.c index d145a0b1f529..508cef8904f4 100644 --- a/arch/x86/kernel/unwind_frame.c +++ b/arch/x86/kernel/unwind_frame.c @@ -77,19 +77,6 @@ static size_t regs_size(struct pt_regs *regs) return sizeof(*regs); } -static bool in_entry_code(unsigned long ip) -{ - char *addr = (char *)ip; - - if (addr >= __entry_text_start && addr < __entry_text_end) - return true; - - if (addr >= __irqentry_text_start && addr < __irqentry_text_end) - return true; - - return false; -} - static inline unsigned long *last_frame(struct unwind_state *state) { return (unsigned long *)task_pt_regs(state->task) - 2; @@ -321,7 +308,7 @@ bool unwind_next_frame(struct unwind_state *state) * Don't warn if the unwinder got lost due to an interrupt in entry * code or in the C handler before the first frame pointer got set up: */ - if (state->got_irq && in_entry_code(state->ip)) + if (state->got_irq && in_entry_text(state->ip)) goto the_end; if (state->regs && state->regs->sp >= (unsigned long)last_aligned_frame(state) &&