From: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
To: xen-devel@lists.xenproject.org, konrad@kernel.org,
sstabellini@kernel.org, julien.grall@arm.com
Cc: Ross Lagerwall <ross.lagerwall@citrix.com>,
Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Subject: [Very RFC PATCH 2/3] insn: Add arch64_insn_gen_branch_imm to generate branch
Date: Tue, 9 Aug 2016 00:18:59 -0400 [thread overview]
Message-ID: <1470716340-24474-3-git-send-email-konrad.wilk@oracle.com> (raw)
In-Reply-To: <1470716340-24474-1-git-send-email-konrad.wilk@oracle.com>
We copied from Linux code (v4.7) the code that generates
the unconditional branch instructions. This is mostly
from Linux commit c0cafbae20d2878883ec3c06d6ea30ff38a6bf92
"arm64: introduce aarch64_insn_gen_branch_reg()"
However the branch-link instructions was omitted, only
the branch instruction is generated.
This lays the groundwork for Livepatch to generate the
trampoline to jump to the new replacement function.
Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
--
Cc: Ross Lagerwall <ross.lagerwall@citrix.com>
Cc: Stefano Stabellini <sstabellini@kernel.org>
Cc: Julien Grall <julien.grall@arm.com>
---
xen/arch/arm/arm64/insn.c | 41 ++++++++++++++++++++++++++++++++++++++++
xen/include/asm-arm/arm64/insn.h | 2 ++
2 files changed, 43 insertions(+)
diff --git a/xen/arch/arm/arm64/insn.c b/xen/arch/arm/arm64/insn.c
index 12b4d96..15dd7bc 100644
--- a/xen/arch/arm/arm64/insn.c
+++ b/xen/arch/arm/arm64/insn.c
@@ -209,6 +209,47 @@ u32 aarch64_set_branch_offset(u32 insn, s32 offset)
BUG();
}
+static inline long branch_imm_common(unsigned long pc, unsigned long addr,
+ long range)
+{
+ long offset;
+
+ if ((pc & 0x3) || (addr & 0x3)) {
+ pr_err("%s: A64 instructions must be word aligned\n", __func__);
+ return range;
+ }
+
+ offset = ((long)addr - (long)pc);
+
+ if (offset < -range || offset >= range) {
+ pr_err("%s: offset out of range\n", __func__);
+ return range;
+ }
+
+ return offset;
+}
+
+u32 __kprobes aarch64_insn_gen_branch_imm(unsigned long pc, unsigned long addr)
+{
+ u32 insn;
+ long offset;
+
+ /*
+ * B/BL support [-128M, 128M) offset
+ * ARM64 virtual address arrangement guarantees all kernel and module
+ * texts are within +/-128M.
+ */
+ offset = branch_imm_common(pc, addr, SZ_128M);
+ if (offset >= SZ_128M)
+ return AARCH64_BREAK_FAULT;
+
+ insn = aarch64_insn_get_b_value();
+
+ return aarch64_insn_encode_immediate(AARCH64_INSN_IMM_26, insn,
+ offset >> 2);
+}
+
+
/*
* Local variables:
* mode: C
diff --git a/xen/include/asm-arm/arm64/insn.h b/xen/include/asm-arm/arm64/insn.h
index 6ce37be..378ba11 100644
--- a/xen/include/asm-arm/arm64/insn.h
+++ b/xen/include/asm-arm/arm64/insn.h
@@ -61,6 +61,8 @@ u32 aarch64_insn_encode_immediate(enum aarch64_insn_imm_type type,
s32 aarch64_get_branch_offset(u32 insn);
u32 aarch64_set_branch_offset(u32 insn, s32 offset);
+u32 aarch64_insn_gen_branch_imm(unsigned long pc, unsigned long addr);
+
/* Wrapper for common code */
static inline bool insn_is_branch_imm(u32 insn)
{
--
2.4.11
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2016-08-09 4:19 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-09 4:18 [Very RFC PATCH] Livepatch - initial ARM64/32 support Konrad Rzeszutek Wilk
2016-08-09 4:18 ` [Very RFC PATCH 1/3] mm/arm: Introduce modify_xen_mappings Konrad Rzeszutek Wilk
2016-08-09 4:18 ` Konrad Rzeszutek Wilk [this message]
2016-08-11 16:03 ` [Very RFC PATCH 2/3] insn: Add arch64_insn_gen_branch_imm to generate branch Julien Grall
2016-08-09 4:19 ` [Very RFC PATCH 3/3] livepatch: Initial ARM32/64 support Konrad Rzeszutek Wilk
2016-08-12 15:00 ` Julien Grall
2016-08-12 20:50 ` Konrad Rzeszutek Wilk
2016-08-15 13:27 ` Julien Grall
2016-08-15 15:04 ` Konrad Rzeszutek Wilk
2016-08-09 4:24 ` [Very RFC PATCH] Livepatch - initial ARM64/32 support Konrad Rzeszutek Wilk
2016-08-11 16:28 ` Julien Grall
2016-08-11 19:05 ` Stefano Stabellini
2016-08-11 23:08 ` Konrad Rzeszutek Wilk
2016-08-12 8:08 ` Julien Grall
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=1470716340-24474-3-git-send-email-konrad.wilk@oracle.com \
--to=konrad.wilk@oracle.com \
--cc=julien.grall@arm.com \
--cc=konrad@kernel.org \
--cc=ross.lagerwall@citrix.com \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.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).