mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-20 14:13:16 +00:00
4e0c54bc5b
The following patches were removed because they are integrated in the upstream kernel 5.4: * backport-5.4/047-v4.21-mtd-keep-original-flags-for-every-struct-mtd_info.patch * backport-5.4/048-v4.21-mtd-improve-calculating-partition-boundaries-when-ch.patch * backport-5.4/080-v5.1-0001-bcma-keep-a-direct-pointer-to-the-struct-device.patch * backport-5.4/080-v5.1-0002-bcma-use-dev_-printing-functions.patch * backport-5.4/095-Allow-class-e-address-assignment-via-ifconfig-ioctl.patch * backport-5.4/101-arm-cns3xxx-use-actual-size-reads-for-PCIe.patch * backport-5.4/200-v5.2-usb-dwc2-Set-lpm-mode-parameters-depend-on-HW-configuration.patch * backport-5.4/210-arm64-sve-Disentangle-uapi-asm-ptrace.h-from-uapi-as.patch * backport-5.4/380-v5.3-net-sched-Introduce-act_ctinfo-action.patch * backport-5.4/450-v5.0-mtd-spinand-winbond-Add-support-for-W25N01GV.patch * backport-5.4/451-v5.0-mtd-spinand-Add-initial-support-for-Toshiba-TC58CVG2.patch * backport-5.4/452-v5.0-mtd-spinand-add-support-for-GigaDevice-GD5FxGQ4xA.patch * backport-5.4/455-v5.1-mtd-spinand-Add-support-for-all-Toshiba-Memory-produ.patch * backport-5.4/456-v5.1-mtd-spinand-Add-support-for-GigaDevice-GD5F1GQ4UExxG.patch * backport-5.4/460-v5.0-mtd-spi-nor-Add-support-for-mx25u12835f.patch * backport-5.4/460-v5.3-mtd-spinand-Define-macros-for-page-read-ops-with-thr.patch * backport-5.4/461-v5.3-mtd-spinand-Add-support-for-two-byte-device-IDs.patch * backport-5.4/462-v5.3-mtd-spinand-Add-support-for-GigaDevice-GD5F1GQ4UFxxG.patch * backport-5.4/463-v5.3-mtd-spinand-Add-initial-support-for-Paragon-PN26G0xA.patch * backport-5.4/700-v5.1-net-phylink-only-call-mac_config-during-resolve-when.patch * backport-5.4/701-v5.2-net-phylink-ensure-inband-AN-works-correctly.patch * backport-5.4/702-v4.20-net-ethernet-Add-helper-for-MACs-which-support-asym-.patch * backport-5.4/703-v4.20-net-ethernet-Add-helper-for-set_pauseparam-for-Asym-.patch * backport-5.4/704-v4.20-net-phy-Stop-with-excessive-soft-reset.patch * backport-5.4/705-v5.1-net-phy-provide-full-set-of-accessor-functions-to-MM.patch * backport-5.4/706-v5.1-net-phy-add-register-modifying-helpers-returning-1-o.patch * backport-5.4/707-v5.1-net-phy-add-genphy_c45_check_and_restart_aneg.patch * backport-5.4/708-v5.3-net-phylink-remove-netdev-from-phylink-mii-ioctl-emu.patch * backport-5.4/709-v5.3-net-phylink-support-for-link-gpio-interrupt.patch * backport-5.4/710-v5.3-net-phy-allow-Clause-45-access-via-mii-ioctl.patch * backport-5.4/711-v5.3-net-sfp-add-mandatory-attach-detach-methods-for-sfp-.patch * backport-5.4/712-v5.3-net-sfp-remove-sfp-bus-use-of-netdevs.patch * backport-5.4/713-v5.2-net-phylink-avoid-reducing-support-mask.patch * backport-5.4/714-v5.3-net-sfp-Stop-SFP-polling-and-interrupt-handling-duri.patch * backport-5.4/715-v5.3-net-phylink-don-t-start-and-stop-SGMII-PHYs-in-SFP-m.patch * backport-5.4/740-v5.5-net-phy-avoid-matching-all-ones-clause-45-PHY-IDs.patch * backport-5.4/741-v5.5-net-phylink-fix-link-mode-modification-in-PHY-mode.patch * pending-5.4/103-MIPS-perf-ath79-Fix-perfcount-IRQ-assignment.patch * pending-5.4/131-spi-use-gpio_set_value_cansleep-for-setting-chipsele.patch * pending-5.4/132-spi-spi-gpio-fix-crash-when-num-chipselects-is-0.patch * pending-5.4/220-optimize_inlining.patch * pending-5.4/341-MIPS-mm-remove-no-op-dma_map_ops-where-possible.patch * pending-5.4/475-mtd-spi-nor-Add-Winbond-w25q128jv-support.patch * pending-5.4/477-mtd-add-spi-nor-add-mx25u3235f.patch * pending-5.4/479-mtd-spi-nor-add-eon-en25qh64.patch Some bigger changes were done to this feature and we did not port this patch yet: * hack-5.4/207-disable-modorder.patch This depends on BOOTMEM which was removed from the kernel, this needs some bigger changes: * hack-5.4/930-crashlog.patch A different version of the FPU disable patch was merged upstream, OpenWrt needs some adaptations. * pending-5.4/304-mips_disable_fpu.patch - no crashlog support yet as a required file got deleted upstream - Removed patch below, which is now seen as a recursive dependency [1] - Removed patch below due to build error [2] - fix still required to avoid identical function def [3] - Fixes included from Blocktrron - Fixes included from Chunkeey - Fix included from nbd regarding "dst leak in Flow Offload" [1] target/linux/generic/hack-5.4/260-crypto_test_dependencies.patch [2] target/linux/generic/hack-5.4/207-disable-modorder.patch [3] target/linux/generic/pending-5.4/613-netfilter_optional_tcp_window_check.patch Signed-off-by: Koen Vandeputte <koen.vandeputte@ncentric.com> Signed-off-by: David Bauer <mail@david-bauer.net> Signed-off-by: Christian Lamparter <chunkeey@gmail.com> Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com> Signed-off-by: Robert Marko <robimarko@gmail.com> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
372 lines
9.2 KiB
Diff
372 lines
9.2 KiB
Diff
From: Felix Fietkau <nbd@nbd.name>
|
|
Subject: mips: replace -mlong-calls with -mno-long-calls to make function calls faster in kernel modules to achieve this, try to
|
|
|
|
lede-commit: 3b3d64743ba2a874df9d70cd19e242205b0a788c
|
|
Signed-off-by: Felix Fietkau <nbd@nbd.name>
|
|
---
|
|
arch/mips/Makefile | 5 +
|
|
arch/mips/include/asm/module.h | 5 +
|
|
arch/mips/kernel/module.c | 279 ++++++++++++++++++++++++++++++++++++++++-
|
|
3 files changed, 284 insertions(+), 5 deletions(-)
|
|
|
|
--- a/arch/mips/Makefile
|
|
+++ b/arch/mips/Makefile
|
|
@@ -95,8 +95,18 @@ all-$(CONFIG_SYS_SUPPORTS_ZBOOT)+= vmlin
|
|
cflags-y += -G 0 -mno-abicalls -fno-pic -pipe -mno-branch-likely
|
|
cflags-y += -msoft-float
|
|
LDFLAGS_vmlinux += -G 0 -static -n -nostdlib
|
|
+ifdef CONFIG_64BIT
|
|
KBUILD_AFLAGS_MODULE += -mlong-calls
|
|
KBUILD_CFLAGS_MODULE += -mlong-calls
|
|
+else
|
|
+ ifdef CONFIG_DYNAMIC_FTRACE
|
|
+ KBUILD_AFLAGS_MODULE += -mlong-calls
|
|
+ KBUILD_CFLAGS_MODULE += -mlong-calls
|
|
+ else
|
|
+ KBUILD_AFLAGS_MODULE += -mno-long-calls
|
|
+ KBUILD_CFLAGS_MODULE += -mno-long-calls
|
|
+ endif
|
|
+endif
|
|
|
|
ifeq ($(CONFIG_RELOCATABLE),y)
|
|
LDFLAGS_vmlinux += --emit-relocs
|
|
--- a/arch/mips/include/asm/module.h
|
|
+++ b/arch/mips/include/asm/module.h
|
|
@@ -12,6 +12,11 @@ struct mod_arch_specific {
|
|
const struct exception_table_entry *dbe_start;
|
|
const struct exception_table_entry *dbe_end;
|
|
struct mips_hi16 *r_mips_hi16_list;
|
|
+
|
|
+ void *phys_plt_tbl;
|
|
+ void *virt_plt_tbl;
|
|
+ unsigned int phys_plt_offset;
|
|
+ unsigned int virt_plt_offset;
|
|
};
|
|
|
|
typedef uint8_t Elf64_Byte; /* Type for a 8-bit quantity. */
|
|
--- a/arch/mips/kernel/module.c
|
|
+++ b/arch/mips/kernel/module.c
|
|
@@ -32,14 +32,221 @@ struct mips_hi16 {
|
|
static LIST_HEAD(dbe_list);
|
|
static DEFINE_SPINLOCK(dbe_lock);
|
|
|
|
-#ifdef MODULE_START
|
|
+/*
|
|
+ * Get the potential max trampolines size required of the init and
|
|
+ * non-init sections. Only used if we cannot find enough contiguous
|
|
+ * physically mapped memory to put the module into.
|
|
+ */
|
|
+static unsigned int
|
|
+get_plt_size(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs,
|
|
+ const char *secstrings, unsigned int symindex, bool is_init)
|
|
+{
|
|
+ unsigned long ret = 0;
|
|
+ unsigned int i, j;
|
|
+ Elf_Sym *syms;
|
|
+
|
|
+ /* Everything marked ALLOC (this includes the exported symbols) */
|
|
+ for (i = 1; i < hdr->e_shnum; ++i) {
|
|
+ unsigned int info = sechdrs[i].sh_info;
|
|
+
|
|
+ if (sechdrs[i].sh_type != SHT_REL
|
|
+ && sechdrs[i].sh_type != SHT_RELA)
|
|
+ continue;
|
|
+
|
|
+ /* Not a valid relocation section? */
|
|
+ if (info >= hdr->e_shnum)
|
|
+ continue;
|
|
+
|
|
+ /* Don't bother with non-allocated sections */
|
|
+ if (!(sechdrs[info].sh_flags & SHF_ALLOC))
|
|
+ continue;
|
|
+
|
|
+ /* If it's called *.init*, and we're not init, we're
|
|
+ not interested */
|
|
+ if ((strstr(secstrings + sechdrs[i].sh_name, ".init") != 0)
|
|
+ != is_init)
|
|
+ continue;
|
|
+
|
|
+ syms = (Elf_Sym *) sechdrs[symindex].sh_addr;
|
|
+ if (sechdrs[i].sh_type == SHT_REL) {
|
|
+ Elf_Mips_Rel *rel = (void *) sechdrs[i].sh_addr;
|
|
+ unsigned int size = sechdrs[i].sh_size / sizeof(*rel);
|
|
+
|
|
+ for (j = 0; j < size; ++j) {
|
|
+ Elf_Sym *sym;
|
|
+
|
|
+ if (ELF_MIPS_R_TYPE(rel[j]) != R_MIPS_26)
|
|
+ continue;
|
|
+
|
|
+ sym = syms + ELF_MIPS_R_SYM(rel[j]);
|
|
+ if (!is_init && sym->st_shndx != SHN_UNDEF)
|
|
+ continue;
|
|
+
|
|
+ ret += 4 * sizeof(int);
|
|
+ }
|
|
+ } else {
|
|
+ Elf_Mips_Rela *rela = (void *) sechdrs[i].sh_addr;
|
|
+ unsigned int size = sechdrs[i].sh_size / sizeof(*rela);
|
|
+
|
|
+ for (j = 0; j < size; ++j) {
|
|
+ Elf_Sym *sym;
|
|
+
|
|
+ if (ELF_MIPS_R_TYPE(rela[j]) != R_MIPS_26)
|
|
+ continue;
|
|
+
|
|
+ sym = syms + ELF_MIPS_R_SYM(rela[j]);
|
|
+ if (!is_init && sym->st_shndx != SHN_UNDEF)
|
|
+ continue;
|
|
+
|
|
+ ret += 4 * sizeof(int);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ return ret;
|
|
+}
|
|
+
|
|
+#ifndef MODULE_START
|
|
+static void *alloc_phys(unsigned long size)
|
|
+{
|
|
+ unsigned order;
|
|
+ struct page *page;
|
|
+ struct page *p;
|
|
+
|
|
+ size = PAGE_ALIGN(size);
|
|
+ order = get_order(size);
|
|
+
|
|
+ page = alloc_pages(GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN |
|
|
+ __GFP_THISNODE, order);
|
|
+ if (!page)
|
|
+ return NULL;
|
|
+
|
|
+ split_page(page, order);
|
|
+
|
|
+ /* mark all pages except for the last one */
|
|
+ for (p = page; p + 1 < page + (size >> PAGE_SHIFT); ++p)
|
|
+ set_bit(PG_owner_priv_1, &p->flags);
|
|
+
|
|
+ for (p = page + (size >> PAGE_SHIFT); p < page + (1 << order); ++p)
|
|
+ __free_page(p);
|
|
+
|
|
+ return page_address(page);
|
|
+}
|
|
+#endif
|
|
+
|
|
+static void free_phys(void *ptr)
|
|
+{
|
|
+ struct page *page;
|
|
+ bool free;
|
|
+
|
|
+ page = virt_to_page(ptr);
|
|
+ do {
|
|
+ free = test_and_clear_bit(PG_owner_priv_1, &page->flags);
|
|
+ __free_page(page);
|
|
+ page++;
|
|
+ } while (free);
|
|
+}
|
|
+
|
|
+
|
|
void *module_alloc(unsigned long size)
|
|
{
|
|
+#ifdef MODULE_START
|
|
return __vmalloc_node_range(size, 1, MODULE_START, MODULE_END,
|
|
GFP_KERNEL, PAGE_KERNEL, 0, NUMA_NO_NODE,
|
|
__builtin_return_address(0));
|
|
+#else
|
|
+ void *ptr;
|
|
+
|
|
+ if (size == 0)
|
|
+ return NULL;
|
|
+
|
|
+ ptr = alloc_phys(size);
|
|
+
|
|
+ /* If we failed to allocate physically contiguous memory,
|
|
+ * fall back to regular vmalloc. The module loader code will
|
|
+ * create jump tables to handle long jumps */
|
|
+ if (!ptr)
|
|
+ return vmalloc(size);
|
|
+
|
|
+ return ptr;
|
|
+#endif
|
|
}
|
|
+
|
|
+static inline bool is_phys_addr(void *ptr)
|
|
+{
|
|
+#ifdef CONFIG_64BIT
|
|
+ return (KSEGX((unsigned long)ptr) == CKSEG0);
|
|
+#else
|
|
+ return (KSEGX(ptr) == KSEG0);
|
|
#endif
|
|
+}
|
|
+
|
|
+/* Free memory returned from module_alloc */
|
|
+void module_memfree(void *module_region)
|
|
+{
|
|
+ if (is_phys_addr(module_region))
|
|
+ free_phys(module_region);
|
|
+ else
|
|
+ vfree(module_region);
|
|
+}
|
|
+
|
|
+static void *__module_alloc(int size, bool phys)
|
|
+{
|
|
+ void *ptr;
|
|
+
|
|
+ if (phys)
|
|
+ ptr = kmalloc(size, GFP_KERNEL);
|
|
+ else
|
|
+ ptr = vmalloc(size);
|
|
+ return ptr;
|
|
+}
|
|
+
|
|
+static void __module_free(void *ptr)
|
|
+{
|
|
+ if (is_phys_addr(ptr))
|
|
+ kfree(ptr);
|
|
+ else
|
|
+ vfree(ptr);
|
|
+}
|
|
+
|
|
+int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
|
|
+ char *secstrings, struct module *mod)
|
|
+{
|
|
+ unsigned int symindex = 0;
|
|
+ unsigned int core_size, init_size;
|
|
+ int i;
|
|
+
|
|
+ mod->arch.phys_plt_offset = 0;
|
|
+ mod->arch.virt_plt_offset = 0;
|
|
+ mod->arch.phys_plt_tbl = NULL;
|
|
+ mod->arch.virt_plt_tbl = NULL;
|
|
+
|
|
+ if (IS_ENABLED(CONFIG_64BIT))
|
|
+ return 0;
|
|
+
|
|
+ for (i = 1; i < hdr->e_shnum; i++)
|
|
+ if (sechdrs[i].sh_type == SHT_SYMTAB)
|
|
+ symindex = i;
|
|
+
|
|
+ core_size = get_plt_size(hdr, sechdrs, secstrings, symindex, false);
|
|
+ init_size = get_plt_size(hdr, sechdrs, secstrings, symindex, true);
|
|
+
|
|
+ if ((core_size + init_size) == 0)
|
|
+ return 0;
|
|
+
|
|
+ mod->arch.phys_plt_tbl = __module_alloc(core_size + init_size, 1);
|
|
+ if (!mod->arch.phys_plt_tbl)
|
|
+ return -ENOMEM;
|
|
+
|
|
+ mod->arch.virt_plt_tbl = __module_alloc(core_size + init_size, 0);
|
|
+ if (!mod->arch.virt_plt_tbl) {
|
|
+ __module_free(mod->arch.phys_plt_tbl);
|
|
+ mod->arch.phys_plt_tbl = NULL;
|
|
+ return -ENOMEM;
|
|
+ }
|
|
+
|
|
+ return 0;
|
|
+}
|
|
|
|
static int apply_r_mips_none(struct module *me, u32 *location,
|
|
u32 base, Elf_Addr v, bool rela)
|
|
@@ -55,9 +262,40 @@ static int apply_r_mips_32(struct module
|
|
return 0;
|
|
}
|
|
|
|
+static Elf_Addr add_plt_entry_to(unsigned *plt_offset,
|
|
+ void *start, Elf_Addr v)
|
|
+{
|
|
+ unsigned *tramp = start + *plt_offset;
|
|
+ *plt_offset += 4 * sizeof(int);
|
|
+
|
|
+ /* adjust carry for addiu */
|
|
+ if (v & 0x00008000)
|
|
+ v += 0x10000;
|
|
+
|
|
+ tramp[0] = 0x3c190000 | (v >> 16); /* lui t9, hi16 */
|
|
+ tramp[1] = 0x27390000 | (v & 0xffff); /* addiu t9, t9, lo16 */
|
|
+ tramp[2] = 0x03200008; /* jr t9 */
|
|
+ tramp[3] = 0x00000000; /* nop */
|
|
+
|
|
+ return (Elf_Addr) tramp;
|
|
+}
|
|
+
|
|
+static Elf_Addr add_plt_entry(struct module *me, void *location, Elf_Addr v)
|
|
+{
|
|
+ if (is_phys_addr(location))
|
|
+ return add_plt_entry_to(&me->arch.phys_plt_offset,
|
|
+ me->arch.phys_plt_tbl, v);
|
|
+ else
|
|
+ return add_plt_entry_to(&me->arch.virt_plt_offset,
|
|
+ me->arch.virt_plt_tbl, v);
|
|
+
|
|
+}
|
|
+
|
|
static int apply_r_mips_26(struct module *me, u32 *location,
|
|
u32 base, Elf_Addr v, bool rela)
|
|
{
|
|
+ u32 ofs = base & 0x03ffffff;
|
|
+
|
|
if (v % 4) {
|
|
pr_err("module %s: dangerous R_MIPS_26 relocation\n",
|
|
me->name);
|
|
@@ -65,13 +303,17 @@ static int apply_r_mips_26(struct module
|
|
}
|
|
|
|
if ((v & 0xf0000000) != (((unsigned long)location + 4) & 0xf0000000)) {
|
|
- pr_err("module %s: relocation overflow\n",
|
|
- me->name);
|
|
- return -ENOEXEC;
|
|
+ v = add_plt_entry(me, location, v + (ofs << 2));
|
|
+ if (!v) {
|
|
+ pr_err("module %s: relocation overflow\n",
|
|
+ me->name);
|
|
+ return -ENOEXEC;
|
|
+ }
|
|
+ ofs = 0;
|
|
}
|
|
|
|
*location = (*location & ~0x03ffffff) |
|
|
- ((base + (v >> 2)) & 0x03ffffff);
|
|
+ ((ofs + (v >> 2)) & 0x03ffffff);
|
|
|
|
return 0;
|
|
}
|
|
@@ -447,9 +689,36 @@ int module_finalize(const Elf_Ehdr *hdr,
|
|
list_add(&me->arch.dbe_list, &dbe_list);
|
|
spin_unlock_irq(&dbe_lock);
|
|
}
|
|
+
|
|
+ /* Get rid of the fixup trampoline if we're running the module
|
|
+ * from physically mapped address space */
|
|
+ if (me->arch.phys_plt_offset == 0) {
|
|
+ __module_free(me->arch.phys_plt_tbl);
|
|
+ me->arch.phys_plt_tbl = NULL;
|
|
+ }
|
|
+ if (me->arch.virt_plt_offset == 0) {
|
|
+ __module_free(me->arch.virt_plt_tbl);
|
|
+ me->arch.virt_plt_tbl = NULL;
|
|
+ }
|
|
+
|
|
return 0;
|
|
}
|
|
|
|
+void module_arch_freeing_init(struct module *mod)
|
|
+{
|
|
+ if (mod->state == MODULE_STATE_LIVE)
|
|
+ return;
|
|
+
|
|
+ if (mod->arch.phys_plt_tbl) {
|
|
+ __module_free(mod->arch.phys_plt_tbl);
|
|
+ mod->arch.phys_plt_tbl = NULL;
|
|
+ }
|
|
+ if (mod->arch.virt_plt_tbl) {
|
|
+ __module_free(mod->arch.virt_plt_tbl);
|
|
+ mod->arch.virt_plt_tbl = NULL;
|
|
+ }
|
|
+}
|
|
+
|
|
void module_arch_cleanup(struct module *mod)
|
|
{
|
|
spin_lock_irq(&dbe_lock);
|