From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3638DC433E0 for ; Thu, 9 Jul 2020 12:49:33 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F3CEB2076A for ; Thu, 9 Jul 2020 12:49:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="Sln7aKpD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F3CEB2076A Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Pv7AIP8lm/JQov5sph9e7PtGPE5lL+yFUQ/2vlecvpU=; b=Sln7aKpDAb2KzY0JovjY3FRDk AjH14m3HKLHOfd4Du0MJbHJVsAxGkXmLi5lakrLhRNV8Xyz76lgTuc2KYIJ4m7/nTN1C2Emy6ELvX gxgvjf9BtVtyIsibUFN288C7QDXdTI4YWcV+TDoq+ntA/M+X2ZqwuenAU9jQWlHIAW//tYK/4Z4sL uUvdEqt+86AacUPvKfRZlNk3hGyrri34FmDfnj66yLBistsOpjVEcqq1C4dms3/HqFT1OSs6ZbzRE zv5/d+BA6m4nZscwM7Er2Y6lPxAIyRF3WX8eL/dC02zQZ1+bWoZVQ2Afm6gB2mIWtm+Kh0Ghhwpdx zWNCc1yQQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jtVyR-0007CA-IS; Thu, 09 Jul 2020 12:48:23 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jtVyO-0007Bg-Uj for linux-arm-kernel@lists.infradead.org; Thu, 09 Jul 2020 12:48:21 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6D5061045; Thu, 9 Jul 2020 05:48:20 -0700 (PDT) Received: from [192.168.0.110] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 142783F71E; Thu, 9 Jul 2020 05:48:18 -0700 (PDT) Subject: Re: [PATCH] arm64/alternatives: use subsections for replacement sequences To: Ard Biesheuvel , Will Deacon References: <20200630081921.13443-1-ardb@kernel.org> <45e53113-75bb-9e7b-cd81-72d782bbb57d@arm.com> <7b503f04-f4fd-54a8-db42-fcf927ee96fa@arm.com> From: Alexandru Elisei Message-ID: <8ba13abc-5253-5486-9d4d-f654421334bd@arm.com> Date: Thu, 9 Jul 2020 13:48:51 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200709_084821_111304_5BF6BA1C X-CRM114-Status: GOOD ( 26.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Anders Roxell , Arnd Bergmann , Suzuki K Poulose , Catalin Marinas , James Morse , Andre Przywara , Dave P Martin , Linux ARM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Ard, Thank you so much for your quick reply! On 7/9/20 1:39 PM, Ard Biesheuvel wrote: > On Thu, 9 Jul 2020 at 15:31, Ard Biesheuvel wrote: >> On Thu, 9 Jul 2020 at 14:11, Alexandru Elisei wrote: >>> Hi, >>> >> Hi Alex, >> >> Apologies for the breakage. >> >> >>> I should post the entire boot log: >> ... >>> [ 0.002204] pc : work_pending+0x32c/0x348 >> This suggests that you ended executing directly from the alternatives >> replacement section that gets appended to the end of work_pending (and >> therefore gets mistaken for being part of it) >> >> It appears that the following code in alternatives.c >> >> static bool branch_insn_requires_update(struct alt_instr *alt, unsigned long pc) >> { >> unsigned long replptr; >> >> if (kernel_text_address(pc)) >> return true; >> >> returns true inadvertently for the branch in this piece of code in entry.S >> >> alternative_if ARM64_HAS_IRQ_PRIO_MASKING >> ldr x20, [sp, #S_PMR_SAVE] >> msr_s SYS_ICC_PMR_EL1, x20 >> mrs_s x21, SYS_ICC_CTLR_EL1 >> tbz x21, #6, .L__skip_pmr_sync\@ // Check for ICC_CTLR_EL1.PMHE >> dsb sy // Ensure priority change is seen by redistributor >> .L__skip_pmr_sync\@: >> >> >> due to the fact that kernel_text_address() has no way of >> distinguishing branches inside the subsection from branches that >> require updating. So the alternatives patching code dutifully updates >> the tbz opcode and points it to its original target in the subsection. >> >> This is going to be rather tricky to fix, unless we special case >> tbz/cbz branches and other branches with limited range that would >> never have worked before anyway. >> >> For now, better to just revert it and revisit it later. >> > ... unless we decide to fix up all branches pointing outside the > replacement sequence, which is not an entirely unreasonable thing to > do: > > diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c > index d1757ef1b1e7..7c205f9202a3 100644 > --- a/arch/arm64/kernel/alternative.c > +++ b/arch/arm64/kernel/alternative.c > @@ -45,18 +45,11 @@ > { > unsigned long replptr; > > - if (kernel_text_address(pc)) > - return true; > - > replptr = (unsigned long)ALT_REPL_PTR(alt); > if (pc >= replptr && pc <= (replptr + alt->alt_len)) > return false; > > - /* > - * Branching into *another* alternate sequence is doomed, and > - * we're not even trying to fix it up. > - */ > - BUG(); > + return true; > } Both fixes work for me. I've been running some tests on my rockpro64 with your patch reverted, so that definitely fixes the issue. With the above diff applied, I was able to boot and run some PMU tests using NMIs. Thanks, Alex _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel