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=-14.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable 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 C840BC433DF for ; Fri, 9 Oct 2020 10:26:08 +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 610A92226B for ; Fri, 9 Oct 2020 10:26:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="DWEpSE/7" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 610A92226B Authentication-Results: mail.kernel.org; dmarc=fail (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: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=+TyMDxJ4OJ5v4H1OFz0LDwvE9Yfe1XSe0cnr94xJgMM=; b=DWEpSE/7YL7R+Bzn60fNtBLRY RNj0J+SkryzUaS2b88YsPEHGH10aRfmYOg7+B5gmVMZhh0XTb2C+VdePyDPvA+YvVrCYFENYNAcsU AfwAyRI7nlKhDnevV9w+HpmmRazLzuFJo/CPwVsyYDSkHx4ArKioVk6zRky1BQadY8cV0EuC2kJig MXkuHwpaUtlHu5GsjKjPJA0HhGd1rVd/GKzkntCNjdadsBuUs82sTEyxZ7F8vCbzzqTuH7GBQb2wZ P+r7HKjQ1/TSR/oWNzf0b3SdXqKXlZhrT5i4wZKpyrRRKsGhpwm/9eyYR8QsPPkKaD4f2J2lp3CBC 5liF2vxYQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kQpZw-0001tC-Se; Fri, 09 Oct 2020 10:24:48 +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 1kQpZs-0001rD-TP for linux-arm-kernel@lists.infradead.org; Fri, 09 Oct 2020 10:24:47 +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 6CCC2D6E; Fri, 9 Oct 2020 03:24:43 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [10.57.51.22]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 759393F66B; Fri, 9 Oct 2020 03:24:41 -0700 (PDT) Date: Fri, 9 Oct 2020 11:24:38 +0100 From: Mark Rutland To: Will Deacon Subject: Re: [PATCHv2] arm64: initialize per-cpu offsets earlier Message-ID: <20201009102438.GB87530@C02TD0UTHF1T.local> References: <20201005164303.21389-1-mark.rutland@arm.com> <711bc57a314d8d646b41307008db2845b7537b3d.camel@redhat.com> <20201009085115.GC29594@willie-the-truck> <20201009094318.GA87530@C02TD0UTHF1T.local> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201009094318.GA87530@C02TD0UTHF1T.local> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201009_062445_089761_B6315F20 X-CRM114-Status: GOOD ( 36.81 ) 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: Stephen Rothwell , Qian Cai , Catalin Marinas , Linux Kernel Mailing List , Linux Next Mailing List , James Morse , linux-arm-kernel@lists.infradead.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 On Fri, Oct 09, 2020 at 10:43:18AM +0100, Mark Rutland wrote: > Hi Qian, > > On Fri, Oct 09, 2020 at 09:51:15AM +0100, Will Deacon wrote: > > On Thu, Oct 08, 2020 at 09:18:24PM -0400, Qian Cai wrote: > > > On Mon, 2020-10-05 at 17:43 +0100, Mark Rutland wrote: > > > > The current initialization of the per-cpu offset register is difficult > > > > to follow and this initialization is not always early enough for > > > > upcoming instrumentation with KCSAN, where the instrumentation callbacks > > > > use the per-cpu offset. > > > > > > > > To make it possible to support KCSAN, and to simplify reasoning about > > > > early bringup code, let's initialize the per-cpu offset earlier, before > > > > we run any C code that may consume it. To do so, this patch adds a new > > > > init_this_cpu_offset() helper that's called before the usual > > > > primary/secondary start functions. For consistency, this is also used to > > > > re-initialize the per-cpu offset after the runtime per-cpu areas have > > > > been allocated (which can change CPU0's offset). > > > > > > > > So that init_this_cpu_offset() isn't subject to any instrumentation that > > > > might consume the per-cpu offset, it is marked with noinstr, preventing > > > > instrumentation. > > > > > > > > Signed-off-by: Mark Rutland > > > > Cc: Catalin Marinas > > > > Cc: James Morse > > > > Cc: Will Deacon > > > > > > Reverting this commit on the top of today's linux-next fixed an issue that > > > Thunder X2 is unable to boot: > > > > > > .config: https://gitlab.com/cailca/linux-mm/-/blob/master/arm64.config > > Sorry about this. :/ > > Will, to save you reading all the below, I think the right thing to do > for now is to revert this. > Looking at the assembly, task_cpu() gets instrumented (which puts this > patch on dodgy ground generally and I think warrants the revert), but as > it's instrumented with KASAN_INLINE that doesn't immediately explain the > issue since the shadow should be up and so we shouldn't call the report > function. I'll dig into this some more. Ok; that's my fault due to trying to do this before kasan_early_init. I see what's going on now. If you're happy to take a fixup instead of a revert, patch below. Otherwise I'll a complete patch atop of the revert after rc1. Thanks, Mark. ---->8---- >From e93fcb9649c9ccfbea9a6f17b68280420685ddc5 Mon Sep 17 00:00:00 2001 From: Mark Rutland Date: Fri, 9 Oct 2020 11:06:32 +0100 Subject: [PATCH] arm64: fix per-cpu offset initialization Qian sees a boot-time hang introduced by commit: 353e228eb355be5a ("arm64: initialize per-cpu offsets earlier") ... which happens because task_cpu() can be instrumented by KASAN, and we call init_this_cpu_offset() before we've performed the early KASAN initialization. We don't need to initialize the per-cpu offset before the early KASAN initialization runs (and we didn't prior to the patch in question), so we can avoid bothering with that. However, were task_cpu() instrumented with something else, this could cause similar issues, so let's also open-code that within init_this_cpu_offset() to avoid that possibility. It's also possible that set_my_cpu_offset() gets instrumented in future, so let's avoid that by marking it __always_inline. It's only used by init_this_cpu_offset(), so this doesn't matter for any other code. Finally, per_cpu_offset(x) is a macro expanding to __per_cpu_offset[x], which is inlined and not instrumented. Fixes: 353e228eb355be5a ("arm64: initialize per-cpu offsets earlier") Signed-off-by: Mark Rutland Reported-by: Qian Cai Cc: Catalin Marinas Cc: Will Deacon --- arch/arm64/include/asm/percpu.h | 2 +- arch/arm64/kernel/head.S | 2 -- arch/arm64/kernel/setup.c | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/percpu.h b/arch/arm64/include/asm/percpu.h index 0b6409b89e5e0..0c347d3faf55c 100644 --- a/arch/arm64/include/asm/percpu.h +++ b/arch/arm64/include/asm/percpu.h @@ -11,7 +11,7 @@ #include #include -static inline void set_my_cpu_offset(unsigned long off) +static __always_inline void set_my_cpu_offset(unsigned long off) { asm volatile(ALTERNATIVE("msr tpidr_el1, %0", "msr tpidr_el2, %0", diff --git a/arch/arm64/kernel/head.S b/arch/arm64/kernel/head.S index e28c9d4e5278c..9bbea14a9ca3f 100644 --- a/arch/arm64/kernel/head.S +++ b/arch/arm64/kernel/head.S @@ -448,8 +448,6 @@ SYM_FUNC_START_LOCAL(__primary_switched) bl __pi_memset dsb ishst // Make zero page visible to PTW - bl init_this_cpu_offset - #ifdef CONFIG_KASAN bl kasan_early_init #endif diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c index 005171972764b..161eaa83264ea 100644 --- a/arch/arm64/kernel/setup.c +++ b/arch/arm64/kernel/setup.c @@ -278,7 +278,7 @@ EXPORT_SYMBOL_GPL(cpu_logical_map); void noinstr init_this_cpu_offset(void) { - unsigned int cpu = task_cpu(current); + unsigned int cpu = current->cpu; set_my_cpu_offset(per_cpu_offset(cpu)); } -- 2.11.0 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel