From patchwork Thu Aug 17 07:17:11 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: 9905117 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 778F960386 for ; Thu, 17 Aug 2017 07:19:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 695B528A77 for ; Thu, 17 Aug 2017 07:19:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5DDE028ABF; Thu, 17 Aug 2017 07:19:50 +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 DA83228A77 for ; Thu, 17 Aug 2017 07:19:49 +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=EY7CTTXpLUhJhMuwUlXLAY9eYxhruRNOWonYq2jimC4=; b=N79xz8V7A6J2vM aQBsDCaWYwvPZ2YSE/vU0pSvAT27G+W/NxcBrJMLgJOscCCG6t9CLSYhUUlruLON/TgYr2gbVdMwD 79pUOotWtRyEs2XszPwCpQh/92Xd9lRfAET7NJbA7CsxgqgNqB+FCoIEUdnBp+Pr4Iy1uya6Mox3k SiTPxFc+N0NmpLhiEVwSa0zLFd/Itnjmaz4YgDUdXEyQjzBPR2K88+oe3R+s2swcx/+Zzc5qsRZql h+CrtopLEXUw4/5B9rJAqKFjl1gUVSOetnOWfA/LXwv0xhF0tZapiSM6x+4ZNgTDnMqHYOPj5AGtZ qBEENEcJ02gtBXBLbdaA==; 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 1diF5i-0001HQ-HY; Thu, 17 Aug 2017 07:19:42 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1diF4Q-0008Ps-Ec for linux-arm-kernel@lists.infradead.org; Thu, 17 Aug 2017 07:18:30 +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 7602122BE7; Thu, 17 Aug 2017 07:17:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7602122BE7 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 4/4] extable: kallsyms: Add in_init_text() and in_core_text() helper Date: Thu, 17 Aug 2017 16:17:11 +0900 Message-Id: <150295422137.14424.6418378586511440462.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_001822_745110_07B44E01 X-CRM114-Status: GOOD ( 15.97 ) 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_init_text() and in_core_text() helper to check the address is in between _sinittext and _einittext, and in between _stext and _etext correspondingly. This changes extable.c and kallsyms.c to use these helpers and memory_contains() helper. Signed-off-by: Masami Hiramatsu --- BTW, is_kernel_text() and core_kernel_text() seem different. is_kernel_text() checks arch dependent area and in_gate_area_no_mm(), but core_kernel_text() doesn't. Can we ignore this differences? --- include/asm-generic/sections.h | 24 ++++++++++++++++++++++++ kernel/extable.c | 18 ++++-------------- kernel/kallsyms.c | 14 +++----------- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h index e5da44eddd2f..25ef53fc594c 100644 --- a/include/asm-generic/sections.h +++ b/include/asm-generic/sections.h @@ -135,4 +135,28 @@ static inline bool init_section_intersects(void *virt, size_t size) return memory_intersects(__init_begin, __init_end, virt, size); } +/** + * in_init_text - check if an address is in between _sinittext and _einittext. + * @addr: virtual address to be checked + * + * Returns: true if the address specified by @addr is in between _sinittext + * and _einittext, false otherwise. + */ +static inline bool in_init_text(unsigned long addr) +{ + return memory_contains(_sinittext, _einittext, (void *)addr, 0); +} + +/** + * in_core_text - check if an address is in between _stext and _etext. + * @addr: virtual address to be checked + * + * Returns: true if the address specified by @addr is in between _stext + * and _etext, false otherwise. + */ +static inline bool in_core_text(unsigned long addr) +{ + return memory_contains(_stext, _etext, (void *)addr, 0); +} + #endif /* _ASM_GENERIC_SECTIONS_H_ */ diff --git a/kernel/extable.c b/kernel/extable.c index 38c2412401a1..d8b365c8c916 100644 --- a/kernel/extable.c +++ b/kernel/extable.c @@ -62,22 +62,13 @@ const struct exception_table_entry *search_exception_tables(unsigned long addr) return e; } -static inline int init_kernel_text(unsigned long addr) -{ - if (addr >= (unsigned long)_sinittext && - addr < (unsigned long)_einittext) - return 1; - return 0; -} - int notrace core_kernel_text(unsigned long addr) { - if (addr >= (unsigned long)_stext && - addr < (unsigned long)_etext) + if (in_core_text(addr)) return 1; if (system_state < SYSTEM_RUNNING && - init_kernel_text(addr)) + in_init_text(addr)) return 1; return 0; } @@ -94,8 +85,7 @@ int notrace core_kernel_text(unsigned long addr) */ int core_kernel_data(unsigned long addr) { - if (addr >= (unsigned long)_sdata && - addr < (unsigned long)_edata) + if (memory_contains(_sdata, _edata, (void *)addr, 0)) return 1; return 0; } @@ -120,7 +110,7 @@ int __kernel_text_address(unsigned long addr) * Since we are after the module-symbols check, there's * no danger of address overlap: */ - if (init_kernel_text(addr)) + if (in_init_text(addr)) return 1; return 0; } diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index 127e7cfafa55..b1443e845dbd 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -51,17 +51,9 @@ extern const u16 kallsyms_token_index[] __weak; extern const unsigned long kallsyms_markers[] __weak; -static inline int is_kernel_inittext(unsigned long addr) -{ - if (addr >= (unsigned long)_sinittext - && addr <= (unsigned long)_einittext) - return 1; - return 0; -} - static inline int is_kernel_text(unsigned long addr) { - if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) || + if (in_core_text(addr) || arch_is_kernel_text(addr)) return 1; return in_gate_area_no_mm(addr); @@ -79,7 +71,7 @@ static int is_ksym_addr(unsigned long addr) if (IS_ENABLED(CONFIG_KALLSYMS_ALL)) return is_kernel(addr); - return is_kernel_text(addr) || is_kernel_inittext(addr); + return is_kernel_text(addr) || in_init_text(addr); } /* @@ -272,7 +264,7 @@ static unsigned long get_symbol_pos(unsigned long addr, /* If we found no next symbol, we use the end of the section. */ if (!symbol_end) { - if (is_kernel_inittext(addr)) + if (in_init_text(addr)) symbol_end = (unsigned long)_einittext; else if (IS_ENABLED(CONFIG_KALLSYMS_ALL)) symbol_end = (unsigned long)_end;