From patchwork Wed Aug 17 11:59:34 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 74057 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp2471020qga; Wed, 17 Aug 2016 05:02:21 -0700 (PDT) X-Received: by 10.98.69.201 with SMTP id n70mr4121672pfi.64.1471435341562; Wed, 17 Aug 2016 05:02:21 -0700 (PDT) Return-Path: Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id c9si28497587pav.143.2016.08.17.05.02.21 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Aug 2016 05:02:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) client-ip=2001:1868:205::9; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) smtp.mailfrom=linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bZzX3-0005wb-Pr; Wed, 17 Aug 2016 12:01:17 +0000 Received: from mail-wm0-x234.google.com ([2a00:1450:400c:c09::234]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bZzWA-0003e0-JD for linux-arm-kernel@lists.infradead.org; Wed, 17 Aug 2016 12:00:48 +0000 Received: by mail-wm0-x234.google.com with SMTP id i5so227398210wmg.0 for ; Wed, 17 Aug 2016 04:59:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=8scsndMIkuUi/TBBkMl8QK1S1+Fyw5FWolyxo6Hv7gg=; b=ZbRkBk+RJoe6bbDKi7YM1XAKo5srG5q6imRVzB3TlnbnCnv0Q9ZmczJOmzbPemd4ki LCS2YTPitgGBgB+Tmv5rxBkSikJTaMrOiz8LdQDabeFkLpXHDNuH4bpdUAZxSO0dzY1V unpxSXdlPVqSVAJfcSwa8eM5LjgxYr3qahmVs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8scsndMIkuUi/TBBkMl8QK1S1+Fyw5FWolyxo6Hv7gg=; b=jF/ZyMsZNcXj0plNqg2hJREvjjB4aDa1+wK5RN79klWf3ofKJ1LwBIsEfAtZ5l2POA 1A0kR41sOraq6VWfwEj14haJmwu7FR4wzBA+erGeMp3pR3/EZbxXzY01/rSNtncc/8qM kGZbtB4W7MLuLuiEBizWT4EypmfLtr0DLpacbIaIpqZJ7hdFaclVzSHOHA+MDmW+IoAu qB3GgMqI3I9VNUmpkS0UqIja5NlhHrm5+giMaykQ/AF+QjyXeo3+EnjrdaaiW2X6voeV kZUqT+0FRMrzH9sJgNrw85W5pJOXxzP1MY5P7CJJfGmU1QsyrRs6PORS1oW+XMExSQMZ +Y0Q== X-Gm-Message-State: AEkoous3fRCMva6FKHgw6PeyWPV3sS8JpqlabkgUGzcbgUPfXi2CQwa9HywgX9QcEcIs9Cks X-Received: by 10.194.240.4 with SMTP id vw4mr41306287wjc.134.1471435197708; Wed, 17 Aug 2016 04:59:57 -0700 (PDT) Received: from localhost.localdomain (46.red-81-37-107.dynamicip.rima-tde.net. [81.37.107.46]) by smtp.gmail.com with ESMTPSA id e65sm26320844wmg.3.2016.08.17.04.59.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 17 Aug 2016 04:59:57 -0700 (PDT) From: Ard Biesheuvel To: linux-arm-kernel@lists.infradead.org, linux@arm.linux.org.uk, dave.martin@arm.com Subject: [PATCH v2 1/3] ARM: kernel: merge core and init PLTs Date: Wed, 17 Aug 2016 13:59:34 +0200 Message-Id: <1471435176-13146-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1471435176-13146-1-git-send-email-ard.biesheuvel@linaro.org> References: <1471435176-13146-1-git-send-email-ard.biesheuvel@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160817_050023_839424_B1135FD5 X-CRM114-Status: GOOD ( 18.86 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:234 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 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: namhyung.kim@lge.com, youngho.shin@lge.com, arnd@arndb.de, Ard Biesheuvel , neidhard.kim@lge.com, chanho.min@lge.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org The PLT code uses a separate .init.plt section to allocate PLT entries for jump and call instructions in __init code. However, even for fairly sizable modules like mac80211.ko, we only end up with a couple of PLT entries in the .init section, and so we can simplify the code significantly by emitting all PLT entries into the same section. Signed-off-by: Ard Biesheuvel --- arch/arm/include/asm/module.h | 6 +- arch/arm/kernel/module-plts.c | 68 +++++++------------- arch/arm/kernel/module.lds | 3 +- 3 files changed, 25 insertions(+), 52 deletions(-) -- 2.7.4 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel diff --git a/arch/arm/include/asm/module.h b/arch/arm/include/asm/module.h index e358b7966c06..464748b9fd7d 100644 --- a/arch/arm/include/asm/module.h +++ b/arch/arm/include/asm/module.h @@ -23,10 +23,8 @@ struct mod_arch_specific { struct unwind_table *unwind[ARM_SEC_MAX]; #endif #ifdef CONFIG_ARM_MODULE_PLTS - struct elf32_shdr *core_plt; - struct elf32_shdr *init_plt; - int core_plt_count; - int init_plt_count; + struct elf32_shdr *plt; + int plt_count; #endif }; diff --git a/arch/arm/kernel/module-plts.c b/arch/arm/kernel/module-plts.c index 0c7efc3446c0..6832d1d6444e 100644 --- a/arch/arm/kernel/module-plts.c +++ b/arch/arm/kernel/module-plts.c @@ -30,28 +30,16 @@ struct plt_entries { u32 lit[PLT_ENT_COUNT]; }; -static bool in_init(const struct module *mod, u32 addr) -{ - return addr - (u32)mod->init_layout.base < mod->init_layout.size; -} - u32 get_module_plt(struct module *mod, unsigned long loc, Elf32_Addr val) { struct plt_entries *plt, *plt_end; - int c, *count; - - if (in_init(mod, loc)) { - plt = (void *)mod->arch.init_plt->sh_addr; - plt_end = (void *)plt + mod->arch.init_plt->sh_size; - count = &mod->arch.init_plt_count; - } else { - plt = (void *)mod->arch.core_plt->sh_addr; - plt_end = (void *)plt + mod->arch.core_plt->sh_size; - count = &mod->arch.core_plt_count; - } + int c; + + plt = (void *)mod->arch.plt->sh_addr; + plt_end = (void *)plt + mod->arch.plt->sh_size; /* Look for an existing entry pointing to 'val' */ - for (c = *count; plt < plt_end; c -= PLT_ENT_COUNT, plt++) { + for (c = mod->arch.plt_count; plt < plt_end; c -= PLT_ENT_COUNT, plt++) { int i; if (!c) { @@ -60,13 +48,13 @@ u32 get_module_plt(struct module *mod, unsigned long loc, Elf32_Addr val) { [0 ... PLT_ENT_COUNT - 1] = PLT_ENT_LDR, }, { val, } }; - ++*count; + mod->arch.plt_count++; return (u32)plt->ldr; } for (i = 0; i < PLT_ENT_COUNT; i++) { if (!plt->lit[i]) { plt->lit[i] = val; - ++*count; + mod->arch.plt_count++; } if (plt->lit[i] == val) return (u32)&plt->ldr[i]; @@ -132,21 +120,19 @@ static unsigned int count_plts(Elf32_Addr base, const Elf32_Rel *rel, int num) int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings, struct module *mod) { - unsigned long core_plts = 0, init_plts = 0; + unsigned long plts = 0; Elf32_Shdr *s, *sechdrs_end = sechdrs + ehdr->e_shnum; /* * To store the PLTs, we expand the .text section for core module code - * and the .init.text section for initialization code. + * and for initialization code. */ for (s = sechdrs; s < sechdrs_end; ++s) - if (strcmp(".core.plt", secstrings + s->sh_name) == 0) - mod->arch.core_plt = s; - else if (strcmp(".init.plt", secstrings + s->sh_name) == 0) - mod->arch.init_plt = s; + if (strcmp(".plt", secstrings + s->sh_name) == 0) + mod->arch.plt = s; - if (!mod->arch.core_plt || !mod->arch.init_plt) { - pr_err("%s: sections missing\n", mod->name); + if (!mod->arch.plt) { + pr_err("%s: module PLT section missing\n", mod->name); return -ENOEXEC; } @@ -158,26 +144,16 @@ int module_frob_arch_sections(Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, if (s->sh_type != SHT_REL) continue; - if (strstr(secstrings + s->sh_name, ".init")) - init_plts += count_plts(dstsec->sh_addr, rels, numrels); - else - core_plts += count_plts(dstsec->sh_addr, rels, numrels); + plts += count_plts(dstsec->sh_addr, rels, numrels); } - mod->arch.core_plt->sh_type = SHT_NOBITS; - mod->arch.core_plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC; - mod->arch.core_plt->sh_addralign = L1_CACHE_BYTES; - mod->arch.core_plt->sh_size = round_up(core_plts * PLT_ENT_SIZE, - sizeof(struct plt_entries)); - mod->arch.core_plt_count = 0; - - mod->arch.init_plt->sh_type = SHT_NOBITS; - mod->arch.init_plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC; - mod->arch.init_plt->sh_addralign = L1_CACHE_BYTES; - mod->arch.init_plt->sh_size = round_up(init_plts * PLT_ENT_SIZE, - sizeof(struct plt_entries)); - mod->arch.init_plt_count = 0; - pr_debug("%s: core.plt=%x, init.plt=%x\n", __func__, - mod->arch.core_plt->sh_size, mod->arch.init_plt->sh_size); + mod->arch.plt->sh_type = SHT_NOBITS; + mod->arch.plt->sh_flags = SHF_EXECINSTR | SHF_ALLOC; + mod->arch.plt->sh_addralign = L1_CACHE_BYTES; + mod->arch.plt->sh_size = round_up(plts * PLT_ENT_SIZE, + sizeof(struct plt_entries)); + mod->arch.plt_count = 0; + + pr_debug("%s: plt=%x\n", __func__, mod->arch.plt->sh_size); return 0; } diff --git a/arch/arm/kernel/module.lds b/arch/arm/kernel/module.lds index 3682fa107918..05881e2b414c 100644 --- a/arch/arm/kernel/module.lds +++ b/arch/arm/kernel/module.lds @@ -1,4 +1,3 @@ SECTIONS { - .core.plt : { BYTE(0) } - .init.plt : { BYTE(0) } + .plt : { BYTE(0) } }