From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1947065AbcHRNLn (ORCPT ); Thu, 18 Aug 2016 09:11:43 -0400 Received: from foss.arm.com ([217.140.101.70]:58295 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754046AbcHRNK4 (ORCPT ); Thu, 18 Aug 2016 09:10:56 -0400 From: Suzuki K Poulose To: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org, will.deacon@arm.com, catalin.marinas@arm.com, mark.rutland@arm.com, andre.przywara@arm.com, Suzuki K Poulose , Marc Zyngier Subject: [PATCH 5/8] arm64: alternative: Add support for patching adrp instructions Date: Thu, 18 Aug 2016 14:10:29 +0100 Message-Id: <1471525832-21209-6-git-send-email-suzuki.poulose@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1471525832-21209-1-git-send-email-suzuki.poulose@arm.com> References: <1471525832-21209-1-git-send-email-suzuki.poulose@arm.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Cc: Marc Zyngier Cc: Andre Przywara Cc: Mark Rutland Signed-off-by: Suzuki K Poulose --- 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); + insn = aarch64_insn_adrp_set_offset(insn, new_offset); } return insn; -- 2.7.4