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 v1 6/7] riscv: Use asm/insn.h for jump labels
Date: Mon, 31 Jan 2022 19:21:44 +0100 [thread overview]
Message-ID: <20220131182145.236005-7-kernel@esmil.dk> (raw)
In-Reply-To: <20220131182145.236005-1-kernel@esmil.dk>
This converts kernel/jump_label.c to use asm/insn.h to generate the
jump/nop instructions.
Signed-off-by: Emil Renner Berthing <kernel@esmil.dk>
---
arch/riscv/kernel/jump_label.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/arch/riscv/kernel/jump_label.c b/arch/riscv/kernel/jump_label.c
index 20e09056d141..b5b4892c3e9e 100644
--- a/arch/riscv/kernel/jump_label.c
+++ b/arch/riscv/kernel/jump_label.c
@@ -9,11 +9,9 @@
#include <linux/memory.h>
#include <linux/mutex.h>
#include <asm/bug.h>
+#include <asm/insn.h>
#include <asm/patch.h>
-#define RISCV_INSN_NOP 0x00000013U
-#define RISCV_INSN_JAL 0x0000006fU
-
void arch_jump_label_transform(struct jump_entry *entry,
enum jump_label_type type)
{
@@ -23,14 +21,10 @@ void arch_jump_label_transform(struct jump_entry *entry,
if (type == JUMP_LABEL_JMP) {
long offset = jump_entry_target(entry) - jump_entry_code(entry);
- if (WARN_ON(offset & 1 || offset < -524288 || offset >= 524288))
+ if (WARN_ON(!riscv_insn_valid_20bit_offset(offset)))
return;
- insn = RISCV_INSN_JAL |
- (((u32)offset & GENMASK(19, 12)) << (12 - 12)) |
- (((u32)offset & GENMASK(11, 11)) << (20 - 11)) |
- (((u32)offset & GENMASK(10, 1)) << (21 - 1)) |
- (((u32)offset & GENMASK(20, 20)) << (31 - 20));
+ insn = RISCV_INSN_JAL | riscv_insn_j_imm(offset);
} else {
insn = RISCV_INSN_NOP;
}
--
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:22 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-31 18:21 [PATCH v1 0/7] Module relocation fixes and asm/insn.h header Emil Renner Berthing
2022-01-31 18:21 ` [PATCH v1 1/7] riscv: Avoid unaligned access when relocating modules Emil Renner Berthing
2022-01-31 18:21 ` [PATCH v1 2/7] riscv: Fix auipc+jalr relocation range checks Emil Renner Berthing
2022-01-31 18:21 ` [PATCH v1 3/7] riscv: Add asm/insn.h header Emil Renner Berthing
2022-01-31 18:21 ` [PATCH v1 4/7] riscv: Use asm/insn.h for module relocations Emil Renner Berthing
2022-01-31 18:21 ` [PATCH v1 5/7] riscv: Use asm/insn.h to generate plt entries Emil Renner Berthing
2022-01-31 18:21 ` Emil Renner Berthing [this message]
2022-01-31 18:21 ` [PATCH v1 7/7] riscv: kernel/modules.c simplification 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=20220131182145.236005-7-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).