2016-04-25 03:43:48

by Zeng Tao

[permalink] [raw]
Subject: [PATCH] arm64: fix /proc/cpuinfo for elf32

For elf32 thread, personality is used for arm32,
and thread_flag for arm64.

Here personality is used for arm64, so fix it.

Signed-off-by: Zeng Tao <[email protected]>
---
arch/arm64/kernel/cpuinfo.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c
index 84c8684..f739398 100644
--- a/arch/arm64/kernel/cpuinfo.c
+++ b/arch/arm64/kernel/cpuinfo.c
@@ -126,7 +126,7 @@ static int c_show(struct seq_file *m, void *v)
* software which does already (at least for 32-bit).
*/
seq_puts(m, "Features\t:");
- if (personality(current->personality) == PER_LINUX32) {
+ if (test_thread_flag(TIF_32BIT)) {
#ifdef CONFIG_COMPAT
for (j = 0; compat_hwcap_str[j]; j++)
if (compat_elf_hwcap & (1 << j))
--
1.9.1


2016-04-25 09:12:45

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH] arm64: fix /proc/cpuinfo for elf32

On Mon, Apr 25, 2016 at 11:37:33AM +0800, Zeng Tao wrote:
> For elf32 thread, personality is used for arm32,
> and thread_flag for arm64.
>
> Here personality is used for arm64, so fix it.
>
> Signed-off-by: Zeng Tao <[email protected]>
> ---
> arch/arm64/kernel/cpuinfo.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c
> index 84c8684..f739398 100644
> --- a/arch/arm64/kernel/cpuinfo.c
> +++ b/arch/arm64/kernel/cpuinfo.c
> @@ -126,7 +126,7 @@ static int c_show(struct seq_file *m, void *v)
> * software which does already (at least for 32-bit).
> */
> seq_puts(m, "Features\t:");
> - if (personality(current->personality) == PER_LINUX32) {
> + if (test_thread_flag(TIF_32BIT)) {
> #ifdef CONFIG_COMPAT
> for (j = 0; compat_hwcap_str[j]; j++)
> if (compat_elf_hwcap & (1 << j))

We discussed this some time ago and we decided against it. One reason
was scripts where you may or may not end up with the desired cpuinfo
(e.g. grep being 64-bit invoked by a 32-bit bash). The personality at
least is inherited by child processes.

--
Catalin

2016-04-26 02:09:29

by Zengtao (B)

[permalink] [raw]
Subject: Re: [PATCH] arm64: fix /proc/cpuinfo for elf32

On 2016-04-25 09:12, Catalin Marinas wrote:
> On Mon, Apr 25, 2016 at 11:37:33AM +0800, Zeng Tao wrote:
> > For elf32 thread, personality is used for arm32,
> > and thread_flag for arm64.
> >
> > Here personality is used for arm64, so fix it.
> >
> > Signed-off-by: Zeng Tao <[email protected]>
> > ---
> > arch/arm64/kernel/cpuinfo.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
>
> We discussed this some time ago and we decided against it. One reason
> was scripts where you may or may not end up with the desired cpuinfo
> (e.g. grep being 64-bit invoked by a 32-bit bash). The personality at
> least is inherited by child processes.
>
So you mean the 64-bit grep should see the same cpuinfo as 32-bit bash as
It is the child process?
But currently we have same 32-bit application which don't have their
personality set, so they get the wrong cpuinfo.
How to fix, call the personality syscall?

> --
> Catalin
>
> _______________________________________________
> linux-arm-kernel mailing list
> [email protected]
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>
>

2016-04-26 02:21:42

by Zengtao (B)

[permalink] [raw]
Subject: RE: [PATCH] arm64: fix /proc/cpuinfo for elf32

> -----Original Message-----
> From: Catalin Marinas [mailto:[email protected]]
> Sent: Monday, April 25, 2016 5:13 PM
> To: Zengtao (B)
> Cc: [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]; [email protected]
> Subject: Re: [PATCH] arm64: fix /proc/cpuinfo for elf32
>
> On Mon, Apr 25, 2016 at 11:37:33AM +0800, Zeng Tao wrote:
> > For elf32 thread, personality is used for arm32,
> > and thread_flag for arm64.
> >
> > Here personality is used for arm64, so fix it.
> >
> > Signed-off-by: Zeng Tao <[email protected]>
> > ---
> > arch/arm64/kernel/cpuinfo.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/arch/arm64/kernel/cpuinfo.c b/arch/arm64/kernel/cpuinfo.c
> > index 84c8684..f739398 100644
> > --- a/arch/arm64/kernel/cpuinfo.c
> > +++ b/arch/arm64/kernel/cpuinfo.c
> > @@ -126,7 +126,7 @@ static int c_show(struct seq_file *m, void *v)
> > * software which does already (at least for 32-bit).
> > */
> > seq_puts(m, "Features\t:");
> > - if (personality(current->personality) == PER_LINUX32) {
> > + if (test_thread_flag(TIF_32BIT)) {
> > #ifdef CONFIG_COMPAT
> > for (j = 0; compat_hwcap_str[j]; j++)
> > if (compat_elf_hwcap & (1 << j))
>
> We discussed this some time ago and we decided against it. One reason
> was scripts where you may or may not end up with the desired cpuinfo
> (e.g. grep being 64-bit invoked by a 32-bit bash). The personality at
> least is inherited by child processes.

So you mean the 64-bit grep should see the same cpuinfo as its father process
which is 32-bit?

For 32-bit process running on 64-bit kernel, we have to explicitly call the personality
syscall to get the right cpuinfo, but how to deal with the old 32-bit binaries?


>
> --
> Catalin

2016-04-26 09:20:58

by Suzuki K Poulose

[permalink] [raw]
Subject: Re: [PATCH] arm64: fix /proc/cpuinfo for elf32

On 26/04/16 03:21, Zengtao (B) wrote:
>
> So you mean the 64-bit grep should see the same cpuinfo as its father process
> which is 32-bit?
>
> For 32-bit process running on 64-bit kernel, we have to explicitly call the personality
> syscall to get the right cpuinfo, but how to deal with the old 32-bit binaries?

Yes, you could use the syscall to switch the personality. Alternately, you could run
"linux32" command to switch the personality to PER_LINUX32 and then execute
64/32 bit applications.

Suzuki



2016-04-27 02:13:53

by Zengtao (B)

[permalink] [raw]
Subject: RE: [PATCH] arm64: fix /proc/cpuinfo for elf32

> -----Original Message-----
> From: Suzuki K Poulose [mailto:[email protected]]
> Sent: Tuesday, April 26, 2016 5:21 PM
> To: Zengtao (B); Catalin Marinas
> Cc: [email protected]; [email protected]; [email protected];
> [email protected]; [email protected];
> [email protected]
> Subject: Re: [PATCH] arm64: fix /proc/cpuinfo for elf32
>
> On 26/04/16 03:21, Zengtao (B) wrote:
> >
> > So you mean the 64-bit grep should see the same cpuinfo as its father process
> > which is 32-bit?
> >
> > For 32-bit process running on 64-bit kernel, we have to explicitly call the
> personality
> > syscall to get the right cpuinfo, but how to deal with the old 32-bit binaries?
>
> Yes, you could use the syscall to switch the personality. Alternately, you could
> run
> "linux32" command to switch the personality to PER_LINUX32 and then
> execute
> 64/32 bit applications.
>

Any plan to place the personality syscall in libc? It is not nessary for each 32-bit process
to do the personality syscall or linux32 command.

> Suzuki
>
>

2016-04-27 10:24:29

by Catalin Marinas

[permalink] [raw]
Subject: Re: [PATCH] arm64: fix /proc/cpuinfo for elf32

On Wed, Apr 27, 2016 at 02:13:01AM +0000, Zengtao (B) wrote:
> Suzuki K Poulose wrote:
> > On 26/04/16 03:21, Zengtao (B) wrote:
> > > So you mean the 64-bit grep should see the same cpuinfo as its father process
> > > which is 32-bit?
> > >
> > > For 32-bit process running on 64-bit kernel, we have to explicitly
> > > call the personality syscall to get the right cpuinfo, but how to
> > > deal with the old 32-bit binaries?
> >
> > Yes, you could use the syscall to switch the personality.
> > Alternately, you could run "linux32" command to switch the
> > personality to PER_LINUX32 and then execute 64/32 bit applications.
>
> Any plan to place the personality syscall in libc? It is not nessary
> for each 32-bit process to do the personality syscall or linux32
> command.

The problem is that the personality will be inherited by child
processes, so any 64-bit process started by a 32-bit one would get the
wrong /proc/cpuinfo. In some cases this is desirable (e.g. system(3)
invoking grep to parse /proc/cpuinfo) while in others not (predominantly
32-bit system with a few 64-bit applications).

Reading /proc/cpuinfo from application is wrong in general but I think
it's too late to do anything about it now.

Anyway, some past discussion here:

http://lists.infradead.org/pipermail/linux-arm-kernel/2014-November/300400.html

The decision at the time was for /proc/cpuinfo to mimic the "uname -m"
behaviour, IOW always reporting "aarch64" unless you set PER_LINUX32.
What you are proposing now is point (c) in the thread above.

We could propose another option (combination of (c) and (d)) but it
requires wider discussion:

[e] Print different hwcaps for compat *or* PER_LINUX32 tasks

This way unmodified compat tasks can be invoked directly (without
linux32) and get the 32-bit hwcaps. For trickier uses like system("grep
/proc/cpuinfo") I don't see any other way than setting PER_LINUX32.

--
Catalin