Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp3833193imm; Mon, 1 Oct 2018 05:21:55 -0700 (PDT) X-Google-Smtp-Source: ACcGV62JMraFKInLamANCykvEJfQCjBQSmEnvxho2RfD2SZixgAVII6nBmmvV4prKbJLZ9pxm07s X-Received: by 2002:a17:902:aa47:: with SMTP id c7-v6mr11862919plr.100.1538396515898; Mon, 01 Oct 2018 05:21:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538396515; cv=none; d=google.com; s=arc-20160816; b=eE5eDqJdYVj6vV+LoYK7WXQdUk2DbZXn6rAdC1UuQpzu8YNU3PUoHIoLI5PvfiBB1S 3XQMKCLsijq/Jbqc0t0wPWogoyLRG2pGWF2nqVqWEi2Ec+5+dNYKolN9XeQaqKKKMFmk IJ49Yc0He5uTzdk22Srp7G/GvXdcxUCXX//W9/7mUzrHL4N5sQ+/RydELh8CuX40GR5d 9qtfhA7OQ5DlxFi1zIMY9HcYf9IO+r3euY/2U1UxWBd1a1ESlBZXMsZ17tOPWTGFYcJ9 qJQD235Ls9ox7sE9OjPQPPPJNBYbL0Qdd0SbvULrjBMO6CmNe4n6M0HuYPWXou0ecedd jLvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:cc:to:subject:from:message-id; bh=QZDXJ3xmHc1PBFY1RfjYkBvHxMKWobOoHBzHAkZhQkE=; b=mPgxG+cle/OEPPVk+oM6VEqnmIvoefuPrx1xBfTSvEjkmaw14OX80wlBnQZVmIqbgN 1QlEJTatcQybXAOUOOBtykjBYw47SnRVTfjsdwCWFlBcArR4+j4dHqQ16qwaZ2Wvz4RZ 3q65tDmPKZr0eLipzfYLg56ewOcSStlTBaUNshR6Ldw7Dz+VM93aSkybwisn4BS01Wv8 unoq60KjJlVwexQubjDOZ0ODXnV3hprRhBVSel8COq9Vm9vdru9KezJV4q41Ac3uEN91 oM6/pUfS7PR73pcIHCZZxlZAm74W32H2TvAjCR5QrnQcvCRYKXO5KkTuQingUgQieYmh G5nw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u9-v6si13499582plm.499.2018.10.01.05.21.41; Mon, 01 Oct 2018 05:21:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729377AbeJAS6p (ORCPT + 99 others); Mon, 1 Oct 2018 14:58:45 -0400 Received: from pegase1.c-s.fr ([93.17.236.30]:40013 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729099AbeJAS6p (ORCPT ); Mon, 1 Oct 2018 14:58:45 -0400 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 42P1bN2fYwz9ttBw; Mon, 1 Oct 2018 14:21:04 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id t48jS16Cu-_L; Mon, 1 Oct 2018 14:21:04 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 42P1bN22sqz9ttBl; Mon, 1 Oct 2018 14:21:04 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 7B8638B96B; Mon, 1 Oct 2018 14:21:11 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id RSRckGY-HKbw; Mon, 1 Oct 2018 14:21:11 +0200 (CEST) Received: from pc16082vm.idsi0.si.c-s.fr (po15451.idsi0.si.c-s.fr [172.25.231.3]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 43CE78B968; Mon, 1 Oct 2018 14:21:11 +0200 (CEST) Received: by pc16082vm.idsi0.si.c-s.fr (Postfix, from userid 0) id 13FB46F36D; Mon, 1 Oct 2018 12:21:10 +0000 (UTC) Message-Id: <6acad0a13b7f6c2845b2022737c6a11a445ed3c2.1538394860.git.christophe.leroy@c-s.fr> From: Christophe Leroy Subject: [PATCH] powerpc/lib: fix book3s/32 boot failure due to code patching To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Michael Neuling Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Date: Mon, 1 Oct 2018 12:21:10 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 51c3c62b58b3 ("powerpc: Avoid code patching freed init sections") accesses 'init_mem_is_free' flag too early, before the kernel is relocated. This provokes early boot failure (before the console is active). As it is not necessary to do this verification that early, this patch moves the test into patch_instruction() instead of __patch_instruction(). This modification also has the advantage of avoiding unnecessary remappings. Fixes: 51c3c62b58b3 ("powerpc: Avoid code patching freed init sections") Signed-off-by: Christophe Leroy --- arch/powerpc/lib/code-patching.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c index 6ae2777c220d..5ffee298745f 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -28,12 +28,6 @@ static int __patch_instruction(unsigned int *exec_addr, unsigned int instr, { int err; - /* Make sure we aren't patching a freed init section */ - if (init_mem_is_free && init_section_contains(exec_addr, 4)) { - pr_debug("Skipping init section patching addr: 0x%px\n", exec_addr); - return 0; - } - __put_user_size(instr, patch_addr, 4, err); if (err) return err; @@ -148,7 +142,7 @@ static inline int unmap_patch_area(unsigned long addr) return 0; } -int patch_instruction(unsigned int *addr, unsigned int instr) +static int do_patch_instruction(unsigned int *addr, unsigned int instr) { int err; unsigned int *patch_addr = NULL; @@ -188,12 +182,22 @@ int patch_instruction(unsigned int *addr, unsigned int instr) } #else /* !CONFIG_STRICT_KERNEL_RWX */ -int patch_instruction(unsigned int *addr, unsigned int instr) +static int do_patch_instruction(unsigned int *addr, unsigned int instr) { return raw_patch_instruction(addr, instr); } #endif /* CONFIG_STRICT_KERNEL_RWX */ + +int patch_instruction(unsigned int *addr, unsigned int instr) +{ + /* Make sure we aren't patching a freed init section */ + if (init_mem_is_free && init_section_contains(addr, 4)) { + pr_debug("Skipping init section patching addr: 0x%px\n", addr); + return 0; + } + return do_patch_instruction(addr, instr); +} NOKPROBE_SYMBOL(patch_instruction); int patch_branch(unsigned int *addr, unsigned long target, int flags) -- 2.13.3