From patchwork Mon Nov 23 20:49:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 7686111 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3A99E9F4F5 for ; Mon, 23 Nov 2015 20:52:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4391420806 for ; Mon, 23 Nov 2015 20:52:44 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 133762073F for ; Mon, 23 Nov 2015 20:52:43 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1a0y4G-00057U-Hv; Mon, 23 Nov 2015 20:50:32 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1a0y41-0003u7-QB for linux-arm-kernel@lists.infradead.org; Mon, 23 Nov 2015 20:50:19 +0000 Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id DAFC214013A; Mon, 23 Nov 2015 20:49:56 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 486) id BD163140140; Mon, 23 Nov 2015 20:49:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from localhost (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: sboyd@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id BC9C214013A; Mon, 23 Nov 2015 20:49:55 +0000 (UTC) Date: Mon, 23 Nov 2015 12:49:55 -0800 From: Stephen Boyd To: =?iso-8859-1?Q?M=E5ns_Rullg=E5rd?= Subject: Re: [RFC/PATCH 3/3] ARM: Replace calls to __aeabi_{u}idiv with udiv/sdiv instructions Message-ID: <20151123204955.GC19156@codeaurora.org> References: <1448068997-26631-1-git-send-email-sboyd@codeaurora.org> <1448068997-26631-4-git-send-email-sboyd@codeaurora.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151123_125017_986249_A35515A6 X-CRM114-Status: GOOD ( 24.14 ) X-Spam-Score: -3.2 (---) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Arnd Bergmann , Nicolas Pitre , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, Steven Rostedt , 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 On 11/21, Måns Rullgård wrote: > Stephen Boyd writes: > > > +static int module_patch_aeabi_uidiv(unsigned long loc, const Elf32_Sym *sym) > > +{ > > + extern char __aeabi_uidiv[], __aeabi_idiv[]; > > + unsigned long udiv_addr = (unsigned long)__aeabi_uidiv; > > + unsigned long sdiv_addr = (unsigned long)__aeabi_idiv; > > + unsigned int udiv_insn, sdiv_insn, mask; > > + > > + if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) { > > + mask = HWCAP_IDIVT; > > + udiv_insn = __opcode_to_mem_thumb32(0xfbb0f0f1); > > + sdiv_insn = __opcode_to_mem_thumb32(0xfb90f0f1); > > + } else { > > + mask = HWCAP_IDIVA; > > + udiv_insn = __opcode_to_mem_arm(0xe730f110); > > + sdiv_insn = __opcode_to_mem_arm(0xe710f110); > > + } > > + > > + if (elf_hwcap & mask) { > > + if (sym->st_value == udiv_addr) { > > + *(u32 *)loc = udiv_insn; > > + return 1; > > + } else if (sym->st_value == sdiv_addr) { > > + *(u32 *)loc = sdiv_insn; > > + return 1; > > + } > > + } > > + > > + return 0; > > +} > > [...] > > > +static void __init patch_aeabi_uidiv(void) > > +{ > > + extern unsigned long *__start_udiv_loc[], *__stop_udiv_loc[]; > > + extern unsigned long *__start_idiv_loc[], *__stop_idiv_loc[]; > > + unsigned long **p; > > + unsigned int udiv_insn, sdiv_insn, mask; > > + > > + if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) { > > + mask = HWCAP_IDIVT; > > + udiv_insn = __opcode_to_mem_thumb32(0xfbb0f0f1); > > + sdiv_insn = __opcode_to_mem_thumb32(0xfb90f0f1); > > + } else { > > + mask = HWCAP_IDIVA; > > + udiv_insn = __opcode_to_mem_arm(0xe730f110); > > + sdiv_insn = __opcode_to_mem_arm(0xe710f110); > > + } > > + > > + if (elf_hwcap & mask) { > > + for (p = __start_udiv_loc; p < __stop_udiv_loc; p++) { > > + unsigned long *inst = *p; > > + *inst = udiv_insn; > > + } > > + for (p = __start_idiv_loc; p < __stop_idiv_loc; p++) { > > + unsigned long *inst = *p; > > + *inst = sdiv_insn; > > + } > > + } > > +} > > These functions are rather similar. Perhaps they could be combined > somehow. > Yes. I have this patch on top, just haven't folded it in because it doesn't reduce the lines of code. ----8<---- From: Stephen Boyd Subject: [PATCH] consolidate with module code Signed-off-by: Stephen Boyd --- arch/arm/include/asm/setup.h | 3 +++ arch/arm/kernel/module.c | 16 +++++-------- arch/arm/kernel/setup.c | 54 +++++++++++++++++++++++++++----------------- 3 files changed, 42 insertions(+), 31 deletions(-) diff --git a/arch/arm/include/asm/setup.h b/arch/arm/include/asm/setup.h index e0adb9f1bf94..3f251cdb94ef 100644 --- a/arch/arm/include/asm/setup.h +++ b/arch/arm/include/asm/setup.h @@ -25,4 +25,7 @@ extern int arm_add_memory(u64 start, u64 size); extern void early_print(const char *str, ...); extern void dump_machine_table(void); +extern void patch_uidiv(void *addr, size_t size); +extern void patch_idiv(void *addr, size_t size); + #endif diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c index 064e6ae60e08..684a68f1085b 100644 --- a/arch/arm/kernel/module.c +++ b/arch/arm/kernel/module.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -58,24 +59,19 @@ static int module_patch_aeabi_uidiv(unsigned long loc, const Elf32_Sym *sym) extern char __aeabi_uidiv[], __aeabi_idiv[]; unsigned long udiv_addr = (unsigned long)__aeabi_uidiv; unsigned long sdiv_addr = (unsigned long)__aeabi_idiv; - unsigned int udiv_insn, sdiv_insn, mask; + unsigned int mask; - if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) { + if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) mask = HWCAP_IDIVT; - udiv_insn = __opcode_to_mem_thumb32(0xfbb0f0f1); - sdiv_insn = __opcode_to_mem_thumb32(0xfb90f0f1); - } else { + else mask = HWCAP_IDIVA; - udiv_insn = __opcode_to_mem_arm(0xe730f110); - sdiv_insn = __opcode_to_mem_arm(0xe710f110); - } if (elf_hwcap & mask) { if (sym->st_value == udiv_addr) { - *(u32 *)loc = udiv_insn; + patch_uidiv(&loc, sizeof(loc)); return 1; } else if (sym->st_value == sdiv_addr) { - *(u32 *)loc = sdiv_insn; + patch_idiv(&loc, sizeof(loc)); return 1; } } diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c index d2a3d165dcae..cb86012c47d1 100644 --- a/arch/arm/kernel/setup.c +++ b/arch/arm/kernel/setup.c @@ -376,33 +376,45 @@ void __init early_print(const char *str, ...) } #ifdef CONFIG_ARM_PATCH_UIDIV +static void __init_or_module patch(u32 **addr, size_t count, u32 insn) +{ + for (; count != 0; count -= 4) + **addr++ = insn; +} + +void __init_or_module patch_uidiv(void *addr, size_t size) +{ + if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) + patch(addr, size, __opcode_to_mem_thumb32(0xfbb0f0f1)); + else + patch(addr, size, __opcode_to_mem_arm(0xe730f110)); + +} + +void __init_or_module patch_idiv(void *addr, size_t size) +{ + if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) + patch(addr, size, __opcode_to_mem_thumb32(0xfb90f0f1)); + else + patch(addr, size, __opcode_to_mem_arm(0xe710f110)); +} + static void __init patch_aeabi_uidiv(void) { - extern unsigned long *__start_udiv_loc[], *__stop_udiv_loc[]; - extern unsigned long *__start_idiv_loc[], *__stop_idiv_loc[]; - unsigned long **p; - unsigned int udiv_insn, sdiv_insn, mask; + extern char __start_udiv_loc[], __stop_udiv_loc[]; + extern char __start_idiv_loc[], __stop_idiv_loc[]; + unsigned int mask; - if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) { + if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) mask = HWCAP_IDIVT; - udiv_insn = __opcode_to_mem_thumb32(0xfbb0f0f1); - sdiv_insn = __opcode_to_mem_thumb32(0xfb90f0f1); - } else { + else mask = HWCAP_IDIVA; - udiv_insn = __opcode_to_mem_arm(0xe730f110); - sdiv_insn = __opcode_to_mem_arm(0xe710f110); - } - if (elf_hwcap & mask) { - for (p = __start_udiv_loc; p < __stop_udiv_loc; p++) { - unsigned long *inst = *p; - *inst = udiv_insn; - } - for (p = __start_idiv_loc; p < __stop_idiv_loc; p++) { - unsigned long *inst = *p; - *inst = sdiv_insn; - } - } + if (!(elf_hwcap & mask)) + return; + + patch_uidiv(__start_udiv_loc, __stop_udiv_loc - __start_udiv_loc); + patch_idiv(__start_idiv_loc, __stop_idiv_loc - __start_idiv_loc); } #else static void __init patch_aeabi_uidiv(void) { }