From: David Brazdil <dbrazdil@google.com>
To: kvmarm@lists.cs.columbia.edu
Cc: linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, Marc Zyngier <maz@kernel.org>,
James Morse <james.morse@arm.com>,
Julien Thierry <julien.thierry.kdev@gmail.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>,
Mark Rutland <mark.rutland@arm.com>,
Andrew Scull <ascull@google.com>,
Ard Biesheuvel <ardb@kernel.org>,
kernel-team@android.com, David Brazdil <dbrazdil@google.com>
Subject: [RFC PATCH 3/6] kvm: arm64: Fix up RELR relocation in hyp code/data
Date: Thu, 19 Nov 2020 16:25:40 +0000 [thread overview]
Message-ID: <20201119162543.78001-4-dbrazdil@google.com> (raw)
In-Reply-To: <20201119162543.78001-1-dbrazdil@google.com>
The arm64 kernel also supports packing of relocation data using the RELR
format. Implement a parser of RELR data and fixup the relocations using
the same infra as RELA relocs.
Signed-off-by: David Brazdil <dbrazdil@google.com>
---
arch/arm64/kvm/va_layout.c | 41 ++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
diff --git a/arch/arm64/kvm/va_layout.c b/arch/arm64/kvm/va_layout.c
index b80fab974896..7f45a98eacfd 100644
--- a/arch/arm64/kvm/va_layout.c
+++ b/arch/arm64/kvm/va_layout.c
@@ -145,6 +145,43 @@ static void __fixup_hyp_rela(void)
__fixup_hyp_rel(rel[i].r_offset);
}
+#ifdef CONFIG_RELR
+static void __fixup_hyp_relr(void)
+{
+ u64 *rel, *end;
+
+ rel = (u64*)(kimage_vaddr + __load_elf_u64(__relr_offset));
+ end = rel + (__load_elf_u64(__relr_size) / sizeof(*rel));
+
+ while (rel < end) {
+ unsigned n;
+ u64 addr = *(rel++);
+
+ /* Address must not have the LSB set. */
+ BUG_ON(addr & BIT(0));
+
+ /* Fix up the first address of the chain. */
+ __fixup_hyp_rel(addr);
+
+ /*
+ * Loop over bitmaps, i.e. as long as words' LSB is 1.
+ * Each bit (ordered from LSB to MSB) represents one word from
+ * the last full address (exclusive). If the corresponding bit
+ * is 1, there is a relative relocation on that word.
+ */
+ for (n = 0; rel < end && (*rel & BIT(0)); n++) {
+ unsigned i;
+ u64 bitmap = *(rel++);
+
+ for (i = 1; i < 64; ++i) {
+ if ((bitmap & BIT(i)))
+ __fixup_hyp_rel(addr + 8 * (63 * n + i));
+ }
+ }
+ }
+}
+#endif
+
/*
* The kernel relocated pointers to kernel VA. Iterate over relocations in
* the hypervisor ELF sections and convert them to hyp VA. This avoids the
@@ -156,6 +193,10 @@ __init void kvm_fixup_hyp_relocations(void)
return;
__fixup_hyp_rela();
+
+#ifdef CONFIG_RELR
+ __fixup_hyp_relr();
+#endif
}
static u32 compute_instruction(int n, u32 rd, u32 rn)
--
2.29.2.299.gdc1121823c-goog
next prev parent reply other threads:[~2020-11-19 16:26 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-19 16:25 [RFC PATCH 0/6] kvm: arm64: Fix up hyp relocations David Brazdil
2020-11-19 16:25 ` [RFC PATCH 1/6] kvm: arm64: Set up .hyp.rodata ELF section David Brazdil
2020-11-24 13:35 ` Ard Biesheuvel
2020-11-19 16:25 ` [RFC PATCH 2/6] kvm: arm64: Fix up RELA relocations in hyp code/data David Brazdil
2020-11-24 13:09 ` Marc Zyngier
2020-11-24 13:45 ` Ard Biesheuvel
2020-11-19 16:25 ` David Brazdil [this message]
2020-11-24 13:24 ` [RFC PATCH 3/6] kvm: arm64: Fix up RELR relocation " Marc Zyngier
2020-11-24 14:02 ` Ard Biesheuvel
2020-11-19 16:25 ` [RFC PATCH 4/6] kvm: arm64: Remove patching of fn pointers in hyp David Brazdil
2020-11-24 14:03 ` Ard Biesheuvel
2020-11-19 16:25 ` [RFC PATCH 5/6] kvm: arm64: Fix constant-pool users " David Brazdil
2020-11-24 14:08 ` Ard Biesheuvel
2020-12-09 13:01 ` David Brazdil
2020-11-19 16:25 ` [RFC PATCH 6/6] kvm: arm64: Remove hyp_symbol_addr David Brazdil
2020-11-24 14:08 ` Ard Biesheuvel
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=20201119162543.78001-4-dbrazdil@google.com \
--to=dbrazdil@google.com \
--cc=ardb@kernel.org \
--cc=ascull@google.com \
--cc=catalin.marinas@arm.com \
--cc=james.morse@arm.com \
--cc=julien.thierry.kdev@gmail.com \
--cc=kernel-team@android.com \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=suzuki.poulose@arm.com \
--cc=will@kernel.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).