lkml.org 
[lkml]   [2016]   [Aug]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH 5/8] arm64: alternative: Add support for patching adrp instructions
On Thu, Aug 18, 2016 at 02:10:29PM +0100, Suzuki K Poulose wrote:
> adrp uses PC-relative address offset to a page (of 4K size) of
> a symbol. If it appears in an alternative code patched in, we
> should adjust the offset to reflect the address where it will
> be run from. This patch adds support for fixing the offset
> for adrp instructions.
>
> Cc: Will Deacon <will.deacon@arm.com>
> Cc: Marc Zyngier <marc.zyngier@arm.com>
> Cc: Andre Przywara <andre.przywara@arm.com>
> Cc: Mark Rutland <mark.rutland@arm.com>
> Signed-off-by: Suzuki K Poulose <suzuki.poulose@arm.com>
> ---
> arch/arm64/kernel/alternative.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c
> index d2ee1b2..71c6962 100644
> --- a/arch/arm64/kernel/alternative.c
> +++ b/arch/arm64/kernel/alternative.c
> @@ -80,6 +80,19 @@ static u32 get_alt_insn(struct alt_instr *alt, u32 *insnptr, u32 *altinsnptr)
> offset = target - (unsigned long)insnptr;
> insn = aarch64_set_branch_offset(insn, offset);
> }
> + } else if (aarch64_insn_is_adrp(insn)) {
> + s32 orig_offset, new_offset;
> + unsigned long target;
> +
> + /*
> + * If we're replacing an adrp instruction, which uses PC-relative
> + * immediate addressing, adjust the offset to reflect the new
> + * PC. adrp operates on 4K aligned addresses.
> + */
> + orig_offset = aarch64_insn_adrp_get_offset(insn);
> + target = ((unsigned long)altinsnptr & ~0xfffUL) + orig_offset;
> + new_offset = target - ((unsigned long)insnptr & ~0xfffUL);

The masking with ~0xfffUL might be nicer if you write it as
align_down(ptr, SZ_4K);

> + insn = aarch64_insn_adrp_set_offset(insn, new_offset);
> }
>
> return insn;

I wonder if we shouldn't have a catch-all for any instructions performing
PC-relative operations here, because silent corruption of the instruction
stream is pretty horrible. What other instructions are there? ADR, LDR
(literal), ... ?

Will

\
 
 \ /
  Last update: 2016-09-17 09:57    [W:3.554 / U:0.004 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site