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.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, 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 D6300C433DF for ; Thu, 9 Jul 2020 12:45:02 +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 A19AD2076A for ; Thu, 9 Jul 2020 12:45:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="JUzq7cZ9"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="GHvbwErO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A19AD2076A Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org 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:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Ym9MnCea4BGKxxlWKIMd7FOLzdY52gPnQtss9qiFRdY=; b=JUzq7cZ9bHyOm4GAwOcdwCi0a 9ZH0HulDo4MY/YgIWo0mJM+qBei6VwBeUY6VR3yKHTbvNnvUwFGeNvUxcQ3ErVzMUjT8DLD138oCl tSp0bPMy6Oa9kZTPHnmM1QAJEKrO4ZDVItuWeACCTjzoxa+suye7xDhGOOPOIsc+Cqrh0ylLCMWq+ 9DlsAAPeTWhi8ru4sKP3M7G5M2dnBFpMxnqhNv2uE77JgBxaGlbsm9288CPUO0t2yy56OK8CVsrAN ph0Q1D9USIGHhelseM8LukRXtxOVmf2Md6LqzfnyfvHRxdiM767EU7b9J1h6kwobtkMhb1NpuQ0OI ykT8MaZBQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jtVu3-0006Mb-2g; Thu, 09 Jul 2020 12:43:51 +0000 Received: from mail.kernel.org ([198.145.29.99]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jtVu0-0006MD-QQ for linux-arm-kernel@lists.infradead.org; Thu, 09 Jul 2020 12:43:49 +0000 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0A9B52076A; Thu, 9 Jul 2020 12:43:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1594298627; bh=mtUkDhUm1w87ZGyVpISh1ruBKEOyUceLdANrHh+nf78=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=GHvbwErOri4pTAIBD/lCAAdD2nBIGr3mLzp5S2+IjChiOhHTQP06CYKWSygD7hGvs 1lmm5pKzDz2+USHHd4RI2AF/xT3JMdAu9q2mcEmwxWjfP4dqf2gQ/TCJTXIqSo7U5s lQmvZrmlXr2N6/Jparhcws6O3rtRVdv2rNM+3+hI= Date: Thu, 9 Jul 2020 13:43:42 +0100 From: Will Deacon To: Ard Biesheuvel Subject: Re: [PATCH] arm64/alternatives: use subsections for replacement sequences Message-ID: <20200709124342.GA28772@willie-the-truck> References: <20200630081921.13443-1-ardb@kernel.org> <45e53113-75bb-9e7b-cd81-72d782bbb57d@arm.com> <7b503f04-f4fd-54a8-db42-fcf927ee96fa@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200709_084348_994690_004B04DE X-CRM114-Status: GOOD ( 23.36 ) 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 , Alexandru Elisei , 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 On Thu, Jul 09, 2020 at 03:39:53PM +0300, Ard Biesheuvel wrote: > On Thu, 9 Jul 2020 at 15:31, Ard Biesheuvel wrote: > > 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; That looks better than the revert to me. Alex -- can you give it a spin with your setup, please? Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel