From: Emil Renner Berthing <kernel@esmil.dk>
To: linux-riscv@lists.infradead.org
Cc: Emil Renner Berthing <kernel@esmil.dk>,
Paul Walmsley <paul.walmsley@sifive.com>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Peter Zijlstra <peterz@infradead.org>,
Josh Poimboeuf <jpoimboe@redhat.com>,
Jason Baron <jbaron@akamai.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ard Biesheuvel <ardb@kernel.org>, Alexandre Ghiti <alex@ghiti.fr>,
Jisheng Zhang <jszhang@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH v2 1/7] riscv: Remove unneeded definitions from asm/module.h
Date: Mon, 31 Jan 2022 19:27:14 +0100 [thread overview]
Message-ID: <20220131182720.236065-2-kernel@esmil.dk> (raw)
In-Reply-To: <20220131182720.236065-1-kernel@esmil.dk>
The inline functions previously defined here are only ever
used in kernel/module-sections.c, so there is no need to
include them in every user of asm/module.h. Through
linux/module.h this is just about every driver.
Now that these functions are static in a single file
remove the inline marker to allow the compiler to make
its own decisions.
Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
---
arch/riscv/include/asm/module.h | 87 ----------------------------
arch/riscv/kernel/module-sections.c | 90 +++++++++++++++++++++++++++++
2 files changed, 90 insertions(+), 87 deletions(-)
diff --git a/arch/riscv/include/asm/module.h b/arch/riscv/include/asm/module.h
index 76aa96a9fc08..570cd025f220 100644
--- a/arch/riscv/include/asm/module.h
+++ b/arch/riscv/include/asm/module.h
@@ -22,93 +22,6 @@ struct mod_arch_specific {
struct mod_section plt;
struct mod_section got_plt;
};
-
-struct got_entry {
- unsigned long symbol_addr; /* the real variable address */
-};
-
-static inline struct got_entry emit_got_entry(unsigned long val)
-{
- return (struct got_entry) {val};
-}
-
-static inline struct got_entry *get_got_entry(unsigned long val,
- const struct mod_section *sec)
-{
- struct got_entry *got = (struct got_entry *)(sec->shdr->sh_addr);
- int i;
- for (i = 0; i < sec->num_entries; i++) {
- if (got[i].symbol_addr == val)
- return &got[i];
- }
- return NULL;
-}
-
-struct plt_entry {
- /*
- * Trampoline code to real target address. The return address
- * should be the original (pc+4) before entring plt entry.
- */
- u32 insn_auipc; /* auipc t0, 0x0 */
- u32 insn_ld; /* ld t1, 0x10(t0) */
- u32 insn_jr; /* jr t1 */
-};
-
-#define OPC_AUIPC 0x0017
-#define OPC_LD 0x3003
-#define OPC_JALR 0x0067
-#define REG_T0 0x5
-#define REG_T1 0x6
-
-static inline struct plt_entry emit_plt_entry(unsigned long val,
- unsigned long plt,
- unsigned long got_plt)
-{
- /*
- * U-Type encoding:
- * +------------+----------+----------+
- * | imm[31:12] | rd[11:7] | opc[6:0] |
- * +------------+----------+----------+
- *
- * I-Type encoding:
- * +------------+------------+--------+----------+----------+
- * | imm[31:20] | rs1[19:15] | funct3 | rd[11:7] | opc[6:0] |
- * +------------+------------+--------+----------+----------+
- *
- */
- unsigned long offset = got_plt - plt;
- u32 hi20 = (offset + 0x800) & 0xfffff000;
- u32 lo12 = (offset - hi20);
- return (struct plt_entry) {
- OPC_AUIPC | (REG_T0 << 7) | hi20,
- OPC_LD | (lo12 << 20) | (REG_T0 << 15) | (REG_T1 << 7),
- OPC_JALR | (REG_T1 << 15)
- };
-}
-
-static inline int get_got_plt_idx(unsigned long val, const struct mod_section *sec)
-{
- struct got_entry *got_plt = (struct got_entry *)sec->shdr->sh_addr;
- int i;
- for (i = 0; i < sec->num_entries; i++) {
- if (got_plt[i].symbol_addr == val)
- return i;
- }
- return -1;
-}
-
-static inline struct plt_entry *get_plt_entry(unsigned long val,
- const struct mod_section *sec_plt,
- const struct mod_section *sec_got_plt)
-{
- struct plt_entry *plt = (struct plt_entry *)sec_plt->shdr->sh_addr;
- int got_plt_idx = get_got_plt_idx(val, sec_got_plt);
- if (got_plt_idx >= 0)
- return plt + got_plt_idx;
- else
- return NULL;
-}
-
#endif /* CONFIG_MODULE_SECTIONS */
#endif /* _ASM_RISCV_MODULE_H */
diff --git a/arch/riscv/kernel/module-sections.c b/arch/riscv/kernel/module-sections.c
index e264e59e596e..39d4ac681c2a 100644
--- a/arch/riscv/kernel/module-sections.c
+++ b/arch/riscv/kernel/module-sections.c
@@ -10,6 +10,28 @@
#include <linux/module.h>
#include <linux/moduleloader.h>
+struct got_entry {
+ unsigned long symbol_addr; /* the real variable address */
+};
+
+static struct got_entry emit_got_entry(unsigned long val)
+{
+ return (struct got_entry) {val};
+}
+
+static struct got_entry *get_got_entry(unsigned long val,
+ const struct mod_section *sec)
+{
+ struct got_entry *got = (struct got_entry *)(sec->shdr->sh_addr);
+ int i;
+
+ for (i = 0; i < sec->num_entries; i++) {
+ if (got[i].symbol_addr == val)
+ return &got[i];
+ }
+ return NULL;
+}
+
unsigned long module_emit_got_entry(struct module *mod, unsigned long val)
{
struct mod_section *got_sec = &mod->arch.got;
@@ -29,6 +51,74 @@ unsigned long module_emit_got_entry(struct module *mod, unsigned long val)
return (unsigned long)&got[i];
}
+struct plt_entry {
+ /*
+ * Trampoline code to real target address. The return address
+ * should be the original (pc+4) before entring plt entry.
+ */
+ u32 insn_auipc; /* auipc t0, 0x0 */
+ u32 insn_ld; /* ld t1, 0x10(t0) */
+ u32 insn_jr; /* jr t1 */
+};
+
+#define OPC_AUIPC 0x0017
+#define OPC_LD 0x3003
+#define OPC_JALR 0x0067
+#define REG_T0 0x5
+#define REG_T1 0x6
+
+static struct plt_entry emit_plt_entry(unsigned long val,
+ unsigned long plt,
+ unsigned long got_plt)
+{
+ /*
+ * U-Type encoding:
+ * +------------+----------+----------+
+ * | imm[31:12] | rd[11:7] | opc[6:0] |
+ * +------------+----------+----------+
+ *
+ * I-Type encoding:
+ * +------------+------------+--------+----------+----------+
+ * | imm[31:20] | rs1[19:15] | funct3 | rd[11:7] | opc[6:0] |
+ * +------------+------------+--------+----------+----------+
+ *
+ */
+ unsigned long offset = got_plt - plt;
+ u32 hi20 = (offset + 0x800) & 0xfffff000;
+ u32 lo12 = (offset - hi20);
+
+ return (struct plt_entry) {
+ OPC_AUIPC | (REG_T0 << 7) | hi20,
+ OPC_LD | (lo12 << 20) | (REG_T0 << 15) | (REG_T1 << 7),
+ OPC_JALR | (REG_T1 << 15)
+ };
+}
+
+static int get_got_plt_idx(unsigned long val, const struct mod_section *sec)
+{
+ struct got_entry *got_plt = (struct got_entry *)sec->shdr->sh_addr;
+ int i;
+
+ for (i = 0; i < sec->num_entries; i++) {
+ if (got_plt[i].symbol_addr == val)
+ return i;
+ }
+ return -1;
+}
+
+static struct plt_entry *get_plt_entry(unsigned long val,
+ const struct mod_section *sec_plt,
+ const struct mod_section *sec_got_plt)
+{
+ struct plt_entry *plt = (struct plt_entry *)sec_plt->shdr->sh_addr;
+ int got_plt_idx = get_got_plt_idx(val, sec_got_plt);
+
+ if (got_plt_idx >= 0)
+ return plt + got_plt_idx;
+ else
+ return NULL;
+}
+
unsigned long module_emit_plt_entry(struct module *mod, unsigned long val)
{
struct mod_section *got_plt_sec = &mod->arch.got_plt;
--
2.35.1
_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv
next prev parent reply other threads:[~2022-01-31 18:27 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-31 18:27 [PATCH v2 0/7] Module relocation fixes and asm/insn.h header Emil Renner Berthing
2022-01-31 18:27 ` Emil Renner Berthing [this message]
2022-01-31 18:27 ` [PATCH v2 2/7] riscv: Avoid unaligned access when relocating modules Emil Renner Berthing
2022-01-31 18:27 ` [PATCH v2 3/7] riscv: Fix auipc+jalr relocation range checks Emil Renner Berthing
2022-01-31 18:27 ` [PATCH v2 4/7] riscv: Add asm/insn.h header Emil Renner Berthing
2022-01-31 18:27 ` [PATCH v2 5/7] riscv: Use asm/insn.h for module relocations Emil Renner Berthing
2022-02-01 1:13 ` kernel test robot
2022-01-31 18:27 ` [PATCH v2 6/7] riscv: Use asm/insn.h to generate plt entries Emil Renner Berthing
2022-01-31 18:27 ` [PATCH v2 7/7] riscv: Use asm/insn.h for jump labels Emil Renner Berthing
2022-01-31 23:31 ` kernel test robot
2022-01-31 23:31 ` kernel test robot
2022-02-22 23:15 ` [PATCH v2 0/7] Module relocation fixes and asm/insn.h header Palmer Dabbelt
2022-02-23 15:53 ` Emil Renner Berthing
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220131182720.236065-2-kernel@esmil.dk \
--to=kernel@esmil.dk \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=ardb@kernel.org \
--cc=jbaron@akamai.com \
--cc=jpoimboe@redhat.com \
--cc=jszhang@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=palmer@dabbelt.com \
--cc=paul.walmsley@sifive.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).