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=-16.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,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 8A48EC433F5 for ; Sun, 19 Sep 2021 13:40:19 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 323C26101C for ; Sun, 19 Sep 2021 13:40:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 323C26101C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:Cc:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qcdk4COjceCKLuhr1ZRYOF+GAvgPaIeVYmrcLIpO3E0=; b=fHKHLLpU9s1h9Ov2HwChRJ/7xg 8zCQ7LN0BUI9ei83yrhNuDLdhafBEGPOorspdwovRSqu3uyLB1TJ4K1YMtQNAgSeQOvufmGDuuMRU oHw7yY8+gksCPFcfLPRXrv/IHg9I7U4KrZMbSGbs6/XgTkY22uMx4jvEhAStSbrjRXEsZpdZd4Fy/ z8GeaygcYsDBH28At/jbFMCI5ONryi6U9PTIRI0Jbw/mHAKR5822yvoEA62+bknSnYYi9aNPaWCCR pJ8cHxJ/ukJFGHxhEB3AJ6IywFqV1xdV96XoXg1nF8io//gqMVOK13tByQoOBOSe6IZSNGll8/Y4y BO8BYlgA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRx1Q-00HLMq-SY; Sun, 19 Sep 2021 13:38:21 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRx1M-00HLKo-AB for linux-arm-kernel@lists.infradead.org; Sun, 19 Sep 2021 13:38:18 +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 E4174101E; Sun, 19 Sep 2021 06:38:09 -0700 (PDT) Received: from [10.163.43.58] (unknown [10.163.43.58]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 62E713F5A1; Sun, 19 Sep 2021 06:38:07 -0700 (PDT) Subject: Re: [PATCH v5 5/5] ARM: smp: Enable THREAD_INFO_IN_TASK To: Ard Biesheuvel , linux-arm-kernel@lists.infradead.org Cc: Keith Packard , Russell King , Kees Cook , Arnd Bergmann , Linus Walleij References: <20210918084438.3288002-1-ardb@kernel.org> <20210918084438.3288002-6-ardb@kernel.org> From: Amit Kachhap Message-ID: <16509479-e683-3221-dd93-826a0ab4e8cf@arm.com> Date: Sun, 19 Sep 2021 19:08:07 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.8.0 MIME-Version: 1.0 In-Reply-To: <20210918084438.3288002-6-ardb@kernel.org> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210919_063816_512151_613D8F99 X-CRM114-Status: GOOD ( 33.44 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 9/18/21 2:14 PM, Ard Biesheuvel wrote: > Now that we no longer rely on thread_info living at the base of the task > stack to be able to access the 'current' pointer, we can wire up the > generic support for moving thread_info into the task struct itself. > > Note that this requires us to update the cpu field in thread_info > explicitly, now that the core code no longer does so. Ideally, we would > switch the percpu code to access the cpu field in task_struct instead, > but this unleashes #include circular dependency hell. > > Co-developed-by: Keith Packard > Signed-off-by: Keith Packard > Signed-off-by: Ard Biesheuvel > --- > arch/arm/Kconfig | 1 + > arch/arm/include/asm/assembler.h | 5 +++++ > arch/arm/include/asm/switch_to.h | 14 ++++++++++++++ > arch/arm/include/asm/thread_info.h | 10 +++++++++- > arch/arm/kernel/asm-offsets.c | 2 ++ > arch/arm/kernel/entry-armv.S | 2 +- > arch/arm/kernel/smp.c | 3 +++ > 7 files changed, 35 insertions(+), 2 deletions(-) > > diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig > index cd195e6f4ea6..4f61c9789e7f 100644 > --- a/arch/arm/Kconfig > +++ b/arch/arm/Kconfig > @@ -125,6 +125,7 @@ config ARM > select PERF_USE_VMALLOC > select RTC_LIB > select SYS_SUPPORTS_APM_EMULATION > + select THREAD_INFO_IN_TASK if CURRENT_POINTER_IN_TPIDRURO > select TRACE_IRQFLAGS_SUPPORT if !CPU_V7M > # Above selects are sorted alphabetically; please add new ones > # according to that. Thanks. > diff --git a/arch/arm/include/asm/assembler.h b/arch/arm/include/asm/assembler.h > index c1551dee28be..7d23d4bb2168 100644 > --- a/arch/arm/include/asm/assembler.h > +++ b/arch/arm/include/asm/assembler.h > @@ -227,10 +227,15 @@ > * Get current thread_info. > */ > .macro get_thread_info, rd > +#ifdef CONFIG_THREAD_INFO_IN_TASK > + /* thread_info is the first member of struct task_struct */ > + get_current \rd I have a minor review comment here, By looking at the this code it looks like get_thread_info calls get_current and get_current again calls get_thread_info. Probably recursion may never happen due to config dependency order. But this can be simplified by doing something like below. +#ifdef CONFIG_CURRENT_POINTER_IN_TPIDRURO +mrc p15, 0, \rd, c13, c0, 3 @ get TPIDRURO register +#else Thanks, Amit Daniel > +#else > ARM( mov \rd, sp, lsr #THREAD_SIZE_ORDER + PAGE_SHIFT ) > THUMB( mov \rd, sp ) > THUMB( lsr \rd, \rd, #THREAD_SIZE_ORDER + PAGE_SHIFT ) > mov \rd, \rd, lsl #THREAD_SIZE_ORDER + PAGE_SHIFT > +#endif > .endm > > /* > diff --git a/arch/arm/include/asm/switch_to.h b/arch/arm/include/asm/switch_to.h > index 61e4a3c4ca6e..b55c7b2755e4 100644 > --- a/arch/arm/include/asm/switch_to.h > +++ b/arch/arm/include/asm/switch_to.h > @@ -23,9 +23,23 @@ > */ > extern struct task_struct *__switch_to(struct task_struct *, struct thread_info *, struct thread_info *); > > +static inline void set_ti_cpu(struct task_struct *p) > +{ > +#ifdef CONFIG_THREAD_INFO_IN_TASK > + /* > + * The core code no longer maintains the thread_info::cpu field once > + * CONFIG_THREAD_INFO_IN_TASK is in effect, but we rely on it for > + * raw_smp_processor_id(), which cannot access struct task_struct* > + * directly for reasons of circular #inclusion hell. > + */ > + task_thread_info(p)->cpu = task_cpu(p); > +#endif > +} > + > #define switch_to(prev,next,last) \ > do { \ > __complete_pending_tlbi(); \ > + set_ti_cpu(next); \ > if (IS_ENABLED(CONFIG_CURRENT_POINTER_IN_TPIDRURO)) \ > __this_cpu_write(__entry_task, next); \ > last = __switch_to(prev,task_thread_info(prev), task_thread_info(next)); \ > diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h > index 76b6fbd5540c..787511396f3f 100644 > --- a/arch/arm/include/asm/thread_info.h > +++ b/arch/arm/include/asm/thread_info.h > @@ -54,7 +54,9 @@ struct cpu_context_save { > struct thread_info { > unsigned long flags; /* low level flags */ > int preempt_count; /* 0 => preemptable, <0 => bug */ > +#ifndef CONFIG_THREAD_INFO_IN_TASK > struct task_struct *task; /* main task structure */ > +#endif > __u32 cpu; /* cpu */ > __u32 cpu_domain; /* cpu domain */ > struct cpu_context_save cpu_context; /* cpu context */ > @@ -70,11 +72,16 @@ struct thread_info { > > #define INIT_THREAD_INFO(tsk) \ > { \ > - .task = &tsk, \ > + INIT_THREAD_INFO_TASK(tsk) \ > .flags = 0, \ > .preempt_count = INIT_PREEMPT_COUNT, \ > } > > +#ifdef CONFIG_THREAD_INFO_IN_TASK > +#define INIT_THREAD_INFO_TASK(tsk) > +#else > +#define INIT_THREAD_INFO_TASK(tsk) .task = &(tsk), > + > /* > * how to get the thread information struct from C > */ > @@ -85,6 +92,7 @@ static inline struct thread_info *current_thread_info(void) > return (struct thread_info *) > (current_stack_pointer & ~(THREAD_SIZE - 1)); > } > +#endif > > #define thread_saved_pc(tsk) \ > ((unsigned long)(task_thread_info(tsk)->cpu_context.pc)) > diff --git a/arch/arm/kernel/asm-offsets.c b/arch/arm/kernel/asm-offsets.c > index 9c864ee76107..645845e4982a 100644 > --- a/arch/arm/kernel/asm-offsets.c > +++ b/arch/arm/kernel/asm-offsets.c > @@ -43,7 +43,9 @@ int main(void) > BLANK(); > DEFINE(TI_FLAGS, offsetof(struct thread_info, flags)); > DEFINE(TI_PREEMPT, offsetof(struct thread_info, preempt_count)); > +#ifndef CONFIG_THREAD_INFO_IN_TASK > DEFINE(TI_TASK, offsetof(struct thread_info, task)); > +#endif > DEFINE(TI_CPU, offsetof(struct thread_info, cpu)); > DEFINE(TI_CPU_DOMAIN, offsetof(struct thread_info, cpu_domain)); > DEFINE(TI_CPU_SAVE, offsetof(struct thread_info, cpu_context)); > diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S > index 7263a45abf3d..a54b5044d406 100644 > --- a/arch/arm/kernel/entry-armv.S > +++ b/arch/arm/kernel/entry-armv.S > @@ -765,7 +765,7 @@ ENTRY(__switch_to) > .endif > ldr r7, [r7, #TSK_STACK_CANARY & IMM12_MASK] > #elif defined(CONFIG_CURRENT_POINTER_IN_TPIDRURO) > - ldr r7, [r2, #TI_TASK] > + mov r7, r2 @ Preserve 'next' > #endif > #ifdef CONFIG_CPU_USE_DOMAINS > mcr p15, 0, r6, c3, c0, 0 @ Set domain register > diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c > index 97ee6b1567e9..cde5b6d8bac5 100644 > --- a/arch/arm/kernel/smp.c > +++ b/arch/arm/kernel/smp.c > @@ -154,6 +154,9 @@ int __cpu_up(unsigned int cpu, struct task_struct *idle) > secondary_data.swapper_pg_dir = get_arch_pgd(swapper_pg_dir); > #endif > secondary_data.task = idle; > + if (IS_ENABLED(CONFIG_THREAD_INFO_IN_TASK)) > + task_thread_info(idle)->cpu = cpu; > + > sync_cache_w(&secondary_data); > > /* > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel