Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2235468imu; Thu, 24 Jan 2019 09:20:08 -0800 (PST) X-Google-Smtp-Source: ALg8bN6NOXQ1A6s2LIO0817WKxys2dmY2Y6tfQUXbNhdahN8iv2tpoesm7ET6dJ2c9M12CAwM6cu X-Received: by 2002:a63:4f20:: with SMTP id d32mr6661499pgb.47.1548350408777; Thu, 24 Jan 2019 09:20:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548350408; cv=none; d=google.com; s=arc-20160816; b=OAJYvYKmbhE9Vlr9h3aBrw7wB6A6Ae8BtPCuDMVC+AOAKJEZ53WX7lh0y4IfK3bC61 u+Yt5GwipYHfKriR9aT5VhOZZ6b0pqneHSxeHgPUNr5PHPAFo2D2YE0rP1CbMz6ULBVr TvuWnEv9rWSvTLXe1+ZBVEpGge5ik4pZRcZM2+ONitWmy1In7a6ORqrrvYaWHxgh71NJ cKCvk0dqJ8wkp+C3mByJb4nl1rqBNyff441cMvMBCA5E7WrIl327k9rBSP2X17ihx5yH Y6BQqqnBpIAsp5jS4bPQcwWUXrtW5lESam4zZDm6MJ80wO1PeqnnB8KraWXTMGqDQmNc pBog== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=K6F5hDs14vSQiSxWAHEiq19VMOP5cy6L20lsfmgERjY=; b=Ir6On6xvYLzzCYwSKiKd2tPeqIiNrrTb2gVvoDOTKRgrawcXlOef3JoKgbO4qqhOAJ lc1VlXX90Tk+MJK6xCUsD/lKTu1RybuI9x/0TCA5aK96s8kVDoUAsDRLayV1KvPaVpRH 1B1Hh+PTKxjoVVXYrQg9eFhhxmZxH92Pr+Ui63KEm3J9TxrAexL0GYoTm76kfDi6v3ZL tF0UMh6HhmL8JqbhcXTJGtYxpuRF2/IH68q8sZa7nt9I6K8iJvGu6FRHT4cLce8kSHj3 S/2J7Ohni/P1y/9r52DkDyCYzyIiv6hniRDSM9GfxZzh5rHELZ8XBNsdTtNaCswTRsOo izDg== 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 w16si16924904plp.321.2019.01.24.09.19.52; Thu, 24 Jan 2019 09:20:08 -0800 (PST) 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 S1728955AbfAXRST (ORCPT + 99 others); Thu, 24 Jan 2019 12:18:19 -0500 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:32992 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727573AbfAXRST (ORCPT ); Thu, 24 Jan 2019 12:18:19 -0500 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 20877A78; Thu, 24 Jan 2019 09:18:19 -0800 (PST) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9A9253F5AF; Thu, 24 Jan 2019 09:18:17 -0800 (PST) Date: Thu, 24 Jan 2019 17:18:15 +0000 From: Mark Rutland To: Christophe Leroy Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Nicholas Piggin , Mike Rapoport , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: Re: [PATCH v14 07/12] powerpc: Activate CONFIG_THREAD_INFO_IN_TASK Message-ID: <20190124171814.GD5531@lakrids.cambridge.arm.com> References: <067ad3f669bdf5ad562186e9875b588f25732406.1548346225.git.christophe.leroy@c-s.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <067ad3f669bdf5ad562186e9875b588f25732406.1548346225.git.christophe.leroy@c-s.fr> User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 24, 2019 at 04:19:43PM +0000, Christophe Leroy wrote: > This patch activates CONFIG_THREAD_INFO_IN_TASK which > moves the thread_info into task_struct. > > Moving thread_info into task_struct has the following advantages: > - It protects thread_info from corruption in the case of stack > overflows. > - Its address is harder to determine if stack addresses are > leaked, making a number of attacks more difficult. > > This has the following consequences: > - thread_info is now located at the beginning of task_struct. > - The 'cpu' field is now in task_struct, and only exists when > CONFIG_SMP is active. > - thread_info doesn't have anymore the 'task' field. > > This patch: > - Removes all recopy of thread_info struct when the stack changes. > - Changes the CURRENT_THREAD_INFO() macro to point to current. > - Selects CONFIG_THREAD_INFO_IN_TASK. > - Modifies raw_smp_processor_id() to get ->cpu from current without > including linux/sched.h to avoid circular inclusion and without > including asm/asm-offsets.h to avoid symbol names duplication > between ASM constants and C constants. > - Modifies klp_init_thread_info() to take a task_struct pointer > argument. > > Signed-off-by: Christophe Leroy > Reviewed-by: Nicholas Piggin [...] > +ifdef CONFIG_SMP > +prepare: task_cpu_prepare > + > +task_cpu_prepare: prepare0 > + $(eval KBUILD_CFLAGS += -D_TASK_CPU=$(shell awk '{if ($$2 == "TI_CPU") print $$3;}' include/generated/asm-offsets.h)) > +endif [...] > -#define raw_smp_processor_id() (current_thread_info()->cpu) > +/* > + * This is particularly ugly: it appears we can't actually get the definition > + * of task_struct here, but we need access to the CPU this task is running on. > + * Instead of using task_struct we're using _TASK_CPU which is extracted from > + * asm-offsets.h by kbuild to get the current processor ID. > + * > + * This also needs to be safeguarded when building asm-offsets.s because at > + * that time _TASK_CPU is not defined yet. It could have been guarded by > + * _TASK_CPU itself, but we want the build to fail if _TASK_CPU is missing > + * when building something else than asm-offsets.s > + */ > +#ifdef GENERATING_ASM_OFFSETS > +#define raw_smp_processor_id() (0) > +#else > +#define raw_smp_processor_id() (*(unsigned int *)((void *)current + _TASK_CPU)) > +#endif > #define hard_smp_processor_id() (smp_hw_index[smp_processor_id()]) On arm64 we have the per-cpu offset in a CPU register (TPIDR_EL1), so we can do: DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number); #define raw_smp_processor_id() (*raw_cpu_ptr(&cpu_number)) ... but I guess that's not possible on PPC for some reason? I think I asked that before, but I couldn't find the thread. Otherwise, this all looks sound to me, but I don't know much about PPC. Thanks, Mark.