linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christophe LEROY <christophe.leroy@c-s.fr>
To: Nicholas Piggin <npiggin@gmail.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Michael Ellerman <mpe@ellerman.id.au>,
	aneesh.kumar@linux.vnet.ibm.com, linux-kernel@vger.kernel.org,
	linuxppc-dev@lists.ozlabs.org
Subject: Re: [RFC PATCH v3 3/7] powerpc: Activate CONFIG_THREAD_INFO_IN_TASK
Date: Wed, 3 Oct 2018 07:47:05 +0200	[thread overview]
Message-ID: <c1b9f2db-ebca-4a2d-4f91-2dce84da31f2@c-s.fr> (raw)
In-Reply-To: <20181003153025.35b2dd5e@roar.ozlabs.ibm.com>



Le 03/10/2018 à 07:30, Nicholas Piggin a écrit :
> On Mon,  1 Oct 2018 12:30:23 +0000 (UTC)
> Christophe Leroy <christophe.leroy@c-s.fr> 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 top of task_struct.
> 
> "top"... I got confused for a minute thinking high address and
> wondering how you can change CURRENT_THREAD_INFO just to point
> to current :)

Would 'beginning' be less confusing ?

> 
> 
> 
>> diff --git a/arch/powerpc/Makefile b/arch/powerpc/Makefile
>> index 07d9dce7eda6..4e98989b5512 100644
>> --- a/arch/powerpc/Makefile
>> +++ b/arch/powerpc/Makefile
>> @@ -422,3 +422,9 @@ checkbin:
>>   
>>   CLEAN_FILES += $(TOUT)
>>   
>> +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
>> diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h
>> index 447cbd1bee99..3a7e5561630b 100644
>> --- a/arch/powerpc/include/asm/ptrace.h
>> +++ b/arch/powerpc/include/asm/ptrace.h
>> @@ -120,7 +120,7 @@ extern int ptrace_put_reg(struct task_struct *task, int regno,
>>   			  unsigned long data);
>>   
>>   #define current_pt_regs() \
>> -	((struct pt_regs *)((unsigned long)current_thread_info() + THREAD_SIZE) - 1)
>> +	((struct pt_regs *)((unsigned long)task_stack_page(current) + THREAD_SIZE) - 1)
>>   /*
>>    * We use the least-significant bit of the trap field to indicate
>>    * whether we have saved the full set of registers, or only a
>> diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
>> index 95b66a0c639b..df519b7322e5 100644
>> --- a/arch/powerpc/include/asm/smp.h
>> +++ b/arch/powerpc/include/asm/smp.h
>> @@ -83,7 +83,13 @@ int is_cpu_dead(unsigned int cpu);
>>   /* 32-bit */
>>   extern int smp_hw_index[];
>>   
>> -#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.
>> + */
>> +#define raw_smp_processor_id()		(*(unsigned int*)((void*)current + _TASK_CPU))
> 
> This is clever but yes ugly. Can't you include asm-offsets.h? riscv
> seems to.

riscv has a clean asm-offsets.h . Our's defines constant with the same 
name as those defined in other headers which are included in C files. So 
including asm-offsets in C files does create conflicts like:

./include/generated/asm-offsets.h:71:0: warning: "TASK_SIZE" redefined
  #define TASK_SIZE -2147483648 /* TASK_SIZE */
./arch/powerpc/include/asm/processor.h:95:0: note: this is the location 
of the previous definition
  #define TASK_SIZE (CONFIG_TASK_SIZE)

./include/generated/asm-offsets.h:98:0: warning: "NSEC_PER_SEC" redefined
  #define NSEC_PER_SEC 1000000000 /* NSEC_PER_SEC */
./include/linux/time64.h:36:0: note: this is the location of the 
previous definition
  #define NSEC_PER_SEC 1000000000L

./arch/powerpc/include/asm/nohash/32/pgtable.h:34:0: warning: 
"PGD_TABLE_SIZE" redefined
  #define PGD_TABLE_SIZE (sizeof(pgd_t) << PGD_INDEX_SIZE)
./include/generated/asm-offsets.h:101:0: note: this is the location of 
the previous definition
  #define PGD_TABLE_SIZE 256 /* PGD_TABLE_SIZE */

...

In v2, I had a patch to fix those redundancies 
(https://patchwork.ozlabs.org/patch/974363/) but I found it unconvenient.

> 
> I'm not 100% sure on kgdb and kexec stuff but I think it seems okay.
> Looks like a pretty nice cleanup too aside from the features it brings,
> thanks for working on it.

Thanks for reviewing it.

> 
> Reviewed-by: Nicholas Piggin <npiggin@gmail.com>
> 

Christophe

  reply	other threads:[~2018-10-03  5:47 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-01 12:30 [RFC PATCH v3 0/7] powerpc: Switch to CONFIG_THREAD_INFO_IN_TASK Christophe Leroy
2018-10-01 12:30 ` [RFC PATCH v3 1/7] book3s/64: avoid circular header inclusion in mmu-hash.h Christophe Leroy
2018-10-03  4:24   ` Nicholas Piggin
2018-10-04  8:20     ` Christophe LEROY
2018-10-04  8:23       ` Aneesh Kumar K.V
2018-10-04  8:32         ` Christophe LEROY
2018-10-01 12:30 ` [RFC PATCH v3 2/7] powerpc: Prepare for moving thread_info into task_struct Christophe Leroy
2018-10-03  5:02   ` Nicholas Piggin
2018-10-03  5:49     ` Christophe LEROY
2018-10-03  5:57       ` Nicholas Piggin
2018-10-04 14:29       ` Christophe LEROY
2018-10-01 12:30 ` [RFC PATCH v3 3/7] powerpc: Activate CONFIG_THREAD_INFO_IN_TASK Christophe Leroy
2018-10-03  5:30   ` Nicholas Piggin
2018-10-03  5:47     ` Christophe LEROY [this message]
2018-10-03  5:52       ` Nicholas Piggin
2018-10-03  6:04         ` Christophe LEROY
2018-10-03  6:23           ` Nicholas Piggin
2018-10-01 12:30 ` [RFC PATCH v3 4/7] powerpc: regain entire stack space Christophe Leroy
2018-10-03  5:34   ` Nicholas Piggin
2018-10-03  5:52     ` Christophe LEROY
2018-10-03  6:30       ` Nicholas Piggin
2018-10-03  6:45         ` Christophe LEROY
2018-10-03  7:07           ` Nicholas Piggin
2018-10-03  9:30             ` Christophe LEROY
2018-10-01 12:30 ` [RFC PATCH v3 5/7] powerpc: 'current_set' is now a table of task_struct pointers Christophe Leroy
2018-10-03  5:41   ` Nicholas Piggin
2018-10-03  6:00     ` Christophe LEROY
2018-10-03  6:09       ` Nicholas Piggin
2018-10-01 12:30 ` [RFC PATCH v3 6/7] powerpc/32: Remove CURRENT_THREAD_INFO and rename TI_CPU Christophe Leroy
2018-10-01 12:30 ` [RFC PATCH v3 7/7] powerpc/64: Modify CURRENT_THREAD_INFO() Christophe Leroy
2018-10-03  5:44   ` Nicholas Piggin
2018-10-03  6:01     ` Christophe LEROY

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=c1b9f2db-ebca-4a2d-4f91-2dce84da31f2@c-s.fr \
    --to=christophe.leroy@c-s.fr \
    --cc=aneesh.kumar@linux.vnet.ibm.com \
    --cc=benh@kernel.crashing.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=npiggin@gmail.com \
    --cc=paulus@samba.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).