From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752284AbdKVLtB convert rfc822-to-8bit (ORCPT ); Wed, 22 Nov 2017 06:49:01 -0500 Received: from ozlabs.org ([103.22.144.67]:45045 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752131AbdKVLtA (ORCPT ); Wed, 22 Nov 2017 06:49:00 -0500 From: Michael Ellerman To: Christophe LEROY , Balbir Singh Cc: Benjamin Herrenschmidt , Paul Mackerras , Scott Wood , Meelis Roos , "linux-kernel\@vger.kernel.org" , "open list\:LINUX FOR POWERPC \(32-BIT AND 64-BIT\)" Subject: Re: [PATCH v2] powerpc: fix boot on BOOK3S_32 with CONFIG_STRICT_KERNEL_RWX In-Reply-To: <141a04c4-a236-430d-f346-ad31252e146a@c-s.fr> References: <20171121142820.C744F6BB8F@po15668-vm-win7.idsi0.si.c-s.fr> <141a04c4-a236-430d-f346-ad31252e146a@c-s.fr> Date: Wed, 22 Nov 2017 22:48:57 +1100 Message-ID: <87h8tm355i.fsf@concordia.ellerman.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Christophe LEROY writes: > Le 22/11/2017 à 00:07, Balbir Singh a écrit : >> On Wed, Nov 22, 2017 at 1:28 AM, Christophe Leroy >> wrote: >>> On powerpc32, patch_instruction() is called by apply_feature_fixups() >>> which is called from early_init() >>> >>> There is the following note in front of early_init(): >>> * Note that the kernel may be running at an address which is different >>> * from the address that it was linked at, so we must use RELOC/PTRRELOC >>> * to access static data (including strings). -- paulus >>> >>> Therefore, slab_is_available() cannot be called yet, and >>> text_poke_area must be addressed with PTRRELOC() >>> >>> Fixes: 37bc3e5fd764f ("powerpc/lib/code-patching: Use alternate map >>> for patch_instruction()") >>> Reported-by: Meelis Roos >>> Cc: Balbir Singh >>> Signed-off-by: Christophe Leroy >>> --- >>> v2: Added missing asm/setup.h >>> >>> arch/powerpc/lib/code-patching.c | 6 ++---- >>> 1 file changed, 2 insertions(+), 4 deletions(-) >>> >>> diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c >>> index c9de03e0c1f1..d469224c4ada 100644 >>> --- a/arch/powerpc/lib/code-patching.c >>> +++ b/arch/powerpc/lib/code-patching.c >>> @@ -21,6 +21,7 @@ >>> #include >>> #include >>> #include >>> +#include >>> >>> static int __patch_instruction(unsigned int *addr, unsigned int instr) >>> { >>> @@ -146,11 +147,8 @@ int patch_instruction(unsigned int *addr, unsigned int instr) >>> * During early early boot patch_instruction is called >>> * when text_poke_area is not ready, but we still need >>> * to allow patching. We just do the plain old patching >>> - * We use slab_is_available and per cpu read * via this_cpu_read >>> - * of text_poke_area. Per-CPU areas might not be up early >>> - * this can create problems with just using this_cpu_read() >>> */ >>> - if (!slab_is_available() || !this_cpu_read(text_poke_area)) >>> + if (!this_cpu_read(*PTRRELOC(&text_poke_area))) >>> return __patch_instruction(addr, instr); >> >> On ppc64, we call apply_feature_fixups() in early_setup() after we've >> relocated ourselves. Sorry for missing the ppc32 case. I would like to >> avoid PTRRELOC when unnecessary. > > What do you suggest then ? > > Some #ifdef PPC32 around that ? No I don't think that improves anything. I think the comment about per-cpu not being up is wrong, you'll just get the static version of text_poke_area, which should be NULL. So we don't need the slab_available() check anyway. So I'll take this as-is. Having said that I absolutely hate PTRRELOC, so if it starts spreading we will have to come up with something less bug prone. cheers