Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1490344 > unrolled thread

[PATCH] thread_info: use unsigned long for flags

Started byMark Rutland <mark.rutland@arm.com>
First post2016-09-23 19:30 +0200
Last post2016-09-24 18:40 +0200
Articles 4 — 3 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] thread_info: use unsigned long for flags Mark Rutland <mark.rutland@arm.com> - 2016-09-23 19:30 +0200
    Re: [PATCH] thread_info: use unsigned long for flags Andy Lutomirski <luto@amacapital.net> - 2016-09-23 20:10 +0200
      Re: [PATCH] thread_info: use unsigned long for flags Mark Rutland <mark.rutland@arm.com> - 2016-09-24 01:50 +0200
    [tip:x86/asm] thread_info: Use unsigned long for flags tip-bot for Mark Rutland <tipbot@zytor.com> - 2016-09-24 18:40 +0200

#1490344 — [PATCH] thread_info: use unsigned long for flags

FromMark Rutland <mark.rutland@arm.com>
Date2016-09-23 19:30 +0200
Subject[PATCH] thread_info: use unsigned long for flags
Message-ID<skCsp-6Lq-11@gated-at.bofh.it>
The generic THREAD_INFO_IN_TASK definition of thread_info::flags is a
u32, matching x86 prior to the introduction of THREAD_INFO_IN_TASK.

However, common helpers like test_ti_thread_flag() implicitly assume
that thread_info::flags has at least the size and alignment of unsigned
long, and relying on padding and alignment provided by other elements of
task_struct is somewhat fragile. Additionally, some architectures use
more that 32 bits for thread_info::flags, and others may need to in
future.

With THREAD_INFO_IN_TASK, task struct follows thread_info with a long
field, and thus we no longer save any space as we did back in commit
affa219b60a11b32 ("x86: change thread_info's flag field back to 32
bits").

Given all this, it makes more sense for the generic thread_info::flags
to be an unsigned long. Make it so.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Kees Cook <keescook@chromium.org>
Cc: linux-kernel@vger.kernel.org
---
 include/linux/thread_info.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

As discussed in the arm64 RFC.

Andy, I'm assuming that as with affa219b60a11b32 no x86 assembly fixups are
required. An x86_64 defconfig built fine for me.

I've based this on your x86/vmap_stack branch. I'm not sure what the plan is
for merging that. If I should be using a different branch to base the arm64
work atop of, please let me know!

Thanks,
Mark.

diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index f3837c7..a2c2f88 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -13,7 +13,7 @@
 
 #ifdef CONFIG_THREAD_INFO_IN_TASK
 struct thread_info {
-	u32			flags;		/* low level flags */
+	unsigned long		flags;		/* low level flags */
 };
 
 #define INIT_THREAD_INFO(tsk)			\
-- 
1.9.1

[toc] | [next] | [standalone]


#1490369

FromAndy Lutomirski <luto@amacapital.net>
Date2016-09-23 20:10 +0200
Message-ID<skD58-7dw-25@gated-at.bofh.it>
In reply to#1490344
On Fri, Sep 23, 2016 at 10:24 AM, Mark Rutland <mark.rutland@arm.com> wrote:
> The generic THREAD_INFO_IN_TASK definition of thread_info::flags is a
> u32, matching x86 prior to the introduction of THREAD_INFO_IN_TASK.
>
> However, common helpers like test_ti_thread_flag() implicitly assume
> that thread_info::flags has at least the size and alignment of unsigned
> long, and relying on padding and alignment provided by other elements of
> task_struct is somewhat fragile. Additionally, some architectures use
> more that 32 bits for thread_info::flags, and others may need to in
> future.
>
> With THREAD_INFO_IN_TASK, task struct follows thread_info with a long
> field, and thus we no longer save any space as we did back in commit
> affa219b60a11b32 ("x86: change thread_info's flag field back to 32
> bits").
>
> Given all this, it makes more sense for the generic thread_info::flags
> to be an unsigned long. Make it so.

I have only one problem with this, and it's a general objection that's
mostly off topic: why the [expletive] do the arch-independent bitfield
helpers think in units of variable size?  It's *absurd*, especially on
big-endian architectures.

Now that that's out of my system, I think this patch is fine.
Big-endian arches that opt in will have to deal with it somehow, but I
don't see why making it 'unsigned long' is worse than anything else.
x86 is fine with this change.

Acked-by: Andy Lutomirski <luto@kernel.org>

Ingo, can you apply this for 4.9 so that we can make this change
before other arches might start depending on the field being u32?

--Andy

[toc] | [prev] | [next] | [standalone]


#1490503

FromMark Rutland <mark.rutland@arm.com>
Date2016-09-24 01:50 +0200
Message-ID<skIo9-1T3-5@gated-at.bofh.it>
In reply to#1490369
[Adding Ingo, so this doesn't get lost -- please see the end of the mail]

On Fri, Sep 23, 2016 at 11:08:46AM -0700, Andy Lutomirski wrote:
> On Fri, Sep 23, 2016 at 10:24 AM, Mark Rutland <mark.rutland@arm.com> wrote:
> > The generic THREAD_INFO_IN_TASK definition of thread_info::flags is a
> > u32, matching x86 prior to the introduction of THREAD_INFO_IN_TASK.
> >
> > However, common helpers like test_ti_thread_flag() implicitly assume
> > that thread_info::flags has at least the size and alignment of unsigned
> > long, and relying on padding and alignment provided by other elements of
> > task_struct is somewhat fragile. Additionally, some architectures use
> > more that 32 bits for thread_info::flags, and others may need to in
> > future.
> >
> > With THREAD_INFO_IN_TASK, task struct follows thread_info with a long
> > field, and thus we no longer save any space as we did back in commit
> > affa219b60a11b32 ("x86: change thread_info's flag field back to 32
> > bits").
> >
> > Given all this, it makes more sense for the generic thread_info::flags
> > to be an unsigned long. Make it so.
> 
> I have only one problem with this, and it's a general objection that's
> mostly off topic: why the [expletive] do the arch-independent bitfield
> helpers think in units of variable size?  It's *absurd*, especially on
> big-endian architectures.
> 
> Now that that's out of my system, I think this patch is fine.
> Big-endian arches that opt in will have to deal with it somehow, but I
> don't see why making it 'unsigned long' is worse than anything else.
> x86 is fine with this change.

FWIW, given <linux/thread_info.h> contains/uses the helpers mentioned above, BE
arches *must* use unsigned long (or something of the same size) today, or they
wouldn't work. In v4.8-rc7 that is the case:

$ ls -l arch | wc -l
33

# Note the above includes Kconfig, so there are 32 to consider

$ git grep -W 'struct thread_info {' -- arch/*/include | \
  grep flags | grep 'unsigned long\s\+flags' | wc -l       
29

$ git grep -W 'struct thread_info {' -- arch/*/include | \
  grep flags | grep 'int\s\+flags'
arch/alpha/include/asm/thread_info.h-   unsigned int            flags;          /* low level flags */

$ git grep -W 'struct thread_info {' -- arch/*/include | \
  grep flags | grep 'u32\s\+flags' 
arch/ia64/include/asm/thread_info.h-    __u32 flags;                    /* thread_info flags (see TIF_*) */
arch/x86/include/asm/thread_info.h-     __u32                   flags;          /* low level flags */

> Acked-by: Andy Lutomirski <luto@kernel.org>
> 
> Ingo, can you apply this for 4.9 so that we can make this change
> before other arches might start depending on the field being u32?
> 
> --Andy

Thanks,
Mark.

[toc] | [prev] | [next] | [standalone]


#1490677 — [tip:x86/asm] thread_info: Use unsigned long for flags

Fromtip-bot for Mark Rutland <tipbot@zytor.com>
Date2016-09-24 18:40 +0200
Subject[tip:x86/asm] thread_info: Use unsigned long for flags
Message-ID<skY9z-3kN-9@gated-at.bofh.it>
In reply to#1490344
Commit-ID:  907241dccb4ce5d9413cf3c030b32b0cfc184914
Gitweb:     http://git.kernel.org/tip/907241dccb4ce5d9413cf3c030b32b0cfc184914
Author:     Mark Rutland <mark.rutland@arm.com>
AuthorDate: Fri, 23 Sep 2016 18:24:07 +0100
Committer:  Ingo Molnar <mingo@kernel.org>
CommitDate: Sat, 24 Sep 2016 09:35:06 +0200

thread_info: Use unsigned long for flags

The generic THREAD_INFO_IN_TASK definition of thread_info::flags is a
u32, matching x86 prior to the introduction of THREAD_INFO_IN_TASK.

However, common helpers like test_ti_thread_flag() implicitly assume
that thread_info::flags has at least the size and alignment of unsigned
long, and relying on padding and alignment provided by other elements of
task_struct is somewhat fragile. Additionally, some architectures use
more that 32 bits for thread_info::flags, and others may need to in
future.

With THREAD_INFO_IN_TASK, task struct follows thread_info with a long
field, and thus we no longer save any space as we did back in commit:

  affa219b60a11b32 ("x86: change thread_info's flag field back to 32 bits")

Given all this, it makes more sense for the generic thread_info::flags
to be an unsigned long.

In fact given <linux/thread_info.h> contains/uses the helpers mentioned
above, BE arches *must* use unsigned long (or something of the same size)
today, or they wouldn't work.

Make it so.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: http://lkml.kernel.org/r/1474651447-30447-1-git-send-email-mark.rutland@arm.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
 include/linux/thread_info.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
index e2d0fd8..45f004e 100644
--- a/include/linux/thread_info.h
+++ b/include/linux/thread_info.h
@@ -15,7 +15,7 @@ struct compat_timespec;
 
 #ifdef CONFIG_THREAD_INFO_IN_TASK
 struct thread_info {
-	u32			flags;		/* low level flags */
+	unsigned long		flags;		/* low level flags */
 };
 
 #define INIT_THREAD_INFO(tsk)			\

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web