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=-8.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,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 57B39C433E0 for ; Thu, 9 Jul 2020 13:14:46 +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 20A232077D for ; Thu, 9 Jul 2020 13:14:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="On2S6Sjl" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 20A232077D 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=EIj4qyJuUhML0afgNE30K0O4IuGDi1YBFj5fJ2zs09Y=; b=On2S6Sjll09lNbLsY0A+o9MC8 KfH3Ko7d7uTxaWmTqZr+M2xYm4jS1Z+eTI4AgNLkgXuZJOo3Lrfu+QveJvvsK5Up2YmSE6aS6v8po vEtdq+kSjr7fvt58hMUtzP0sVXig/wO3YFcVcgCCKIq6+mcexOF1i9Y8a9pUXYMxL4iubhnXy2wHV VbU/PTdOsd7Ecqd3w9rujfVInzlxe+v3YervwuINdeCyN9x3+cOXkc9kLFFq8vmNKLYHJja99ENrr JSitqVWBVh9FEowWkk2DdeT8PgYN8MDNnE8rWAL9BaMaCGtfahwI2NyHt59s6NQrfUx7SPWUnD35R R4cgHwI0Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jtWMs-0003LD-6C; Thu, 09 Jul 2020 13:13:38 +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 1jtWMp-0003KJ-Ec for linux-arm-kernel@lists.infradead.org; Thu, 09 Jul 2020 13:13:36 +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 480C61FB; Thu, 9 Jul 2020 06:13:30 -0700 (PDT) Received: from [10.37.8.195] (unknown [10.37.8.195]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7B9EA3FA00; Thu, 9 Jul 2020 06:13:29 -0700 (PDT) Subject: Re: [PATCH] arm64/alternatives: don't patch up internal branches To: Ard Biesheuvel , linux-arm-kernel@lists.infradead.org References: <20200709125953.30918-1-ardb@kernel.org> From: Alexandru Elisei Message-ID: <6b57e66e-1eac-358e-7e87-b158a3f8496e@arm.com> Date: Thu, 9 Jul 2020 14:14:15 +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: <20200709125953.30918-1-ardb@kernel.org> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200709_091335_549308_A37C2FE8 X-CRM114-Status: GOOD ( 22.21 ) 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: catalin.marinas@arm.com, will@kernel.org 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, On 7/9/20 1:59 PM, Ard Biesheuvel wrote: > Commit f7b93d429 ("arm64/alternatives: use subsections for replacement > sequences") moved the alternatives replacement sequences into subsections, > in order to keep the as close as possible to the code that they replace. > > Unfortunately, this broke the logic in branch_insn_requires_update, > which assumed that any branch into kernel executable code was a branch > that required updating, which is no longer the case now that the code > sequences that are patched in are in the same section as the patch site > itself. > > So the only way to discriminate branches that require updating and ones > that don't is to check whether the branch targets the replacement sequence > itself, and so we can drop the call to kernel_text_address() entirely. > > Signed-off-by: Ard Biesheuvel > --- > arch/arm64/kernel/alternative.c | 12 +----------- > 1 file changed, 1 insertion(+), 11 deletions(-) > > diff --git a/arch/arm64/kernel/alternative.c b/arch/arm64/kernel/alternative.c > index d1757ef1b1e7..5711adda14bb 100644 > --- a/arch/arm64/kernel/alternative.c > +++ b/arch/arm64/kernel/alternative.c > @@ -45,18 +45,8 @@ static bool branch_insn_requires_update(struct alt_instr *alt, unsigned long pc) > { > 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 !(pc >= replptr && pc <= (replptr + alt->alt_len)); > } > > #define align_down(x, a) ((unsigned long)(x) & ~(((unsigned long)(a)) - 1)) Ran some perf tests on the model and rockpro64 using the PMU interrupt as an NMI, everything works as expected: Tested-by: Alexandru Elisei Thanks, Alex _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel