mbox series

[v3,0/4] linux-user: select CPU type according ELF header values

Message ID 20180116222212.1266-1-laurent@vivier.eu
Headers show
Series linux-user: select CPU type according ELF header values | expand

Message

Laurent Vivier Jan. 16, 2018, 10:22 p.m. UTC
This idea has been suggested to me before by Philippe
Mathieu-Daudé, and recently YunQiang Su has proposed a
patch to manage the MIPS r6 case.

Based on this, this series tries to clean-up the original
patch, and introduces the use for m68k architecture and
port the patch from YunQiang Su.

v3: fix code indent problem reported by patchew
    remove useless "!= 0"
    check for EF_M68K_M68000
    add EF_M68K_* flags in elf.h
    set 680x0 default CPU to m68040
    change "#if ... #endif" structure for ppc
v2: move cpu_model selection to linux-user/*/target_elf.h
    provide eflags to cpu_get_model() instead of fd
    (and modify other patches accordingly)

Laurent Vivier (2):
  linux-user: Move CPU type name selection to a function
  linux-user,m68k: select CPU according to ELF header values

YunQiang Su (2):
  linux-user: introduce functions to detect CPU type
  linux-user: MIPS set cpu to r6 CPU if binary is R6

 include/elf.h                      | 32 +++++++++++++++++++++
 linux-user/aarch64/target_elf.h    | 14 +++++++++
 linux-user/alpha/target_elf.h      | 14 +++++++++
 linux-user/arm/target_elf.h        | 14 +++++++++
 linux-user/cris/target_elf.h       | 14 +++++++++
 linux-user/elfload.c               | 35 ++++++++++++++++++++++
 linux-user/hppa/target_elf.h       | 14 +++++++++
 linux-user/i386/target_elf.h       | 14 +++++++++
 linux-user/m68k/target_elf.h       | 20 +++++++++++++
 linux-user/main.c                  | 59 +++++++-------------------------------
 linux-user/microblaze/target_elf.h | 14 +++++++++
 linux-user/mips/target_elf.h       | 17 +++++++++++
 linux-user/mips64/target_elf.h     | 17 +++++++++++
 linux-user/nios2/target_elf.h      | 14 +++++++++
 linux-user/openrisc/target_elf.h   | 14 +++++++++
 linux-user/ppc/target_elf.h        | 18 ++++++++++++
 linux-user/qemu.h                  |  1 +
 linux-user/s390x/target_elf.h      | 14 +++++++++
 linux-user/sh4/target_elf.h        | 14 +++++++++
 linux-user/sparc/target_elf.h      | 14 +++++++++
 linux-user/sparc64/target_elf.h    | 14 +++++++++
 linux-user/tilegx/target_elf.h     | 14 +++++++++
 linux-user/unicore32/target_elf.h  | 14 +++++++++
 linux-user/x86_64/target_elf.h     | 14 +++++++++
 24 files changed, 375 insertions(+), 48 deletions(-)
 create mode 100644 linux-user/aarch64/target_elf.h
 create mode 100644 linux-user/alpha/target_elf.h
 create mode 100644 linux-user/arm/target_elf.h
 create mode 100644 linux-user/cris/target_elf.h
 create mode 100644 linux-user/hppa/target_elf.h
 create mode 100644 linux-user/i386/target_elf.h
 create mode 100644 linux-user/m68k/target_elf.h
 create mode 100644 linux-user/microblaze/target_elf.h
 create mode 100644 linux-user/mips/target_elf.h
 create mode 100644 linux-user/mips64/target_elf.h
 create mode 100644 linux-user/nios2/target_elf.h
 create mode 100644 linux-user/openrisc/target_elf.h
 create mode 100644 linux-user/ppc/target_elf.h
 create mode 100644 linux-user/s390x/target_elf.h
 create mode 100644 linux-user/sh4/target_elf.h
 create mode 100644 linux-user/sparc/target_elf.h
 create mode 100644 linux-user/sparc64/target_elf.h
 create mode 100644 linux-user/tilegx/target_elf.h
 create mode 100644 linux-user/unicore32/target_elf.h
 create mode 100644 linux-user/x86_64/target_elf.h

Comments

Igor Mammedov Jan. 17, 2018, 3:49 p.m. UTC | #1
On Tue, 16 Jan 2018 23:22:08 +0100
Laurent Vivier <laurent@vivier.eu> wrote:

> This idea has been suggested to me before by Philippe
> Mathieu-Daudé, and recently YunQiang Su has proposed a
> patch to manage the MIPS r6 case.
> 
> Based on this, this series tries to clean-up the original
> patch, and introduces the use for m68k architecture and
> port the patch from YunQiang Su.
> 
> v3: fix code indent problem reported by patchew
>     remove useless "!= 0"
>     check for EF_M68K_M68000
>     add EF_M68K_* flags in elf.h
>     set 680x0 default CPU to m68040
>     change "#if ... #endif" structure for ppc
> v2: move cpu_model selection to linux-user/*/target_elf.h
>     provide eflags to cpu_get_model() instead of fd
>     (and modify other patches accordingly)
Sorry for not noticing it earlier, but could you please
fix series to use cpu type names instead of cpu_model?

I've just posted series that completes cpu_model refactoring
  [PATCH 00/24] generalize parsing of cpu_model (part 4)
which removes remnants of the code using cpu_model to
instantiate CPUs, including reworking how default
cpu type for *-user is picked up.

After that cpu_model shouldn't be used anywhere in the code
except of routines that process "-cpu" CLI and cpu types
should be used directly.

So you might not need 1/4 after that or it would have
to be reworked and probably other patches where where
cpu_model is used.


> Laurent Vivier (2):
>   linux-user: Move CPU type name selection to a function
>   linux-user,m68k: select CPU according to ELF header values
> 
> YunQiang Su (2):
>   linux-user: introduce functions to detect CPU type
>   linux-user: MIPS set cpu to r6 CPU if binary is R6
> 
>  include/elf.h                      | 32 +++++++++++++++++++++
>  linux-user/aarch64/target_elf.h    | 14 +++++++++
>  linux-user/alpha/target_elf.h      | 14 +++++++++
>  linux-user/arm/target_elf.h        | 14 +++++++++
>  linux-user/cris/target_elf.h       | 14 +++++++++
>  linux-user/elfload.c               | 35 ++++++++++++++++++++++
>  linux-user/hppa/target_elf.h       | 14 +++++++++
>  linux-user/i386/target_elf.h       | 14 +++++++++
>  linux-user/m68k/target_elf.h       | 20 +++++++++++++
>  linux-user/main.c                  | 59 +++++++-------------------------------
>  linux-user/microblaze/target_elf.h | 14 +++++++++
>  linux-user/mips/target_elf.h       | 17 +++++++++++
>  linux-user/mips64/target_elf.h     | 17 +++++++++++
>  linux-user/nios2/target_elf.h      | 14 +++++++++
>  linux-user/openrisc/target_elf.h   | 14 +++++++++
>  linux-user/ppc/target_elf.h        | 18 ++++++++++++
>  linux-user/qemu.h                  |  1 +
>  linux-user/s390x/target_elf.h      | 14 +++++++++
>  linux-user/sh4/target_elf.h        | 14 +++++++++
>  linux-user/sparc/target_elf.h      | 14 +++++++++
>  linux-user/sparc64/target_elf.h    | 14 +++++++++
>  linux-user/tilegx/target_elf.h     | 14 +++++++++
>  linux-user/unicore32/target_elf.h  | 14 +++++++++
>  linux-user/x86_64/target_elf.h     | 14 +++++++++
>  24 files changed, 375 insertions(+), 48 deletions(-)
>  create mode 100644 linux-user/aarch64/target_elf.h
>  create mode 100644 linux-user/alpha/target_elf.h
>  create mode 100644 linux-user/arm/target_elf.h
>  create mode 100644 linux-user/cris/target_elf.h
>  create mode 100644 linux-user/hppa/target_elf.h
>  create mode 100644 linux-user/i386/target_elf.h
>  create mode 100644 linux-user/m68k/target_elf.h
>  create mode 100644 linux-user/microblaze/target_elf.h
>  create mode 100644 linux-user/mips/target_elf.h
>  create mode 100644 linux-user/mips64/target_elf.h
>  create mode 100644 linux-user/nios2/target_elf.h
>  create mode 100644 linux-user/openrisc/target_elf.h
>  create mode 100644 linux-user/ppc/target_elf.h
>  create mode 100644 linux-user/s390x/target_elf.h
>  create mode 100644 linux-user/sh4/target_elf.h
>  create mode 100644 linux-user/sparc/target_elf.h
>  create mode 100644 linux-user/sparc64/target_elf.h
>  create mode 100644 linux-user/tilegx/target_elf.h
>  create mode 100644 linux-user/unicore32/target_elf.h
>  create mode 100644 linux-user/x86_64/target_elf.h
>
Laurent Vivier Jan. 17, 2018, 4:15 p.m. UTC | #2
Le 17/01/2018 à 16:49, Igor Mammedov a écrit :
> On Tue, 16 Jan 2018 23:22:08 +0100
> Laurent Vivier <laurent@vivier.eu> wrote:
> 
>> This idea has been suggested to me before by Philippe
>> Mathieu-Daudé, and recently YunQiang Su has proposed a
>> patch to manage the MIPS r6 case.
>>
>> Based on this, this series tries to clean-up the original
>> patch, and introduces the use for m68k architecture and
>> port the patch from YunQiang Su.
>>
>> v3: fix code indent problem reported by patchew
>>     remove useless "!= 0"
>>     check for EF_M68K_M68000
>>     add EF_M68K_* flags in elf.h
>>     set 680x0 default CPU to m68040
>>     change "#if ... #endif" structure for ppc
>> v2: move cpu_model selection to linux-user/*/target_elf.h
>>     provide eflags to cpu_get_model() instead of fd
>>     (and modify other patches accordingly)
> Sorry for not noticing it earlier, but could you please
> fix series to use cpu type names instead of cpu_model?
> 
> I've just posted series that completes cpu_model refactoring
>   [PATCH 00/24] generalize parsing of cpu_model (part 4)
> which removes remnants of the code using cpu_model to
> instantiate CPUs, including reworking how default
> cpu type for *-user is picked up.
> 
> After that cpu_model shouldn't be used anywhere in the code
> except of routines that process "-cpu" CLI and cpu types
> should be used directly.
> 
> So you might not need 1/4 after that or it would have
> to be reworked and probably other patches where where
> cpu_model is used.

If I understand correctly, in linux-user/main.c we have to use
cpu_create() instead of cpu_init(), and provide the cpu_type instead of
the cpu_model?

In linux-user/main.c, How can I detect we want to use the default one
(we were relying on "cpu_model == NULL" until now) to be able to compute
the default one from the ELF header?

Thanks,
Laurent
Igor Mammedov Jan. 18, 2018, 1:17 p.m. UTC | #3
On Wed, 17 Jan 2018 17:15:38 +0100
Laurent Vivier <laurent@vivier.eu> wrote:

> Le 17/01/2018 à 16:49, Igor Mammedov a écrit :
> > On Tue, 16 Jan 2018 23:22:08 +0100
> > Laurent Vivier <laurent@vivier.eu> wrote:
> >   
> >> This idea has been suggested to me before by Philippe
> >> Mathieu-Daudé, and recently YunQiang Su has proposed a
> >> patch to manage the MIPS r6 case.
> >>
> >> Based on this, this series tries to clean-up the original
> >> patch, and introduces the use for m68k architecture and
> >> port the patch from YunQiang Su.
> >>
> >> v3: fix code indent problem reported by patchew
> >>     remove useless "!= 0"
> >>     check for EF_M68K_M68000
> >>     add EF_M68K_* flags in elf.h
> >>     set 680x0 default CPU to m68040
> >>     change "#if ... #endif" structure for ppc
> >> v2: move cpu_model selection to linux-user/*/target_elf.h
> >>     provide eflags to cpu_get_model() instead of fd
> >>     (and modify other patches accordingly)  
> > Sorry for not noticing it earlier, but could you please
> > fix series to use cpu type names instead of cpu_model?
> > 
> > I've just posted series that completes cpu_model refactoring
> >   [PATCH 00/24] generalize parsing of cpu_model (part 4)
> > which removes remnants of the code using cpu_model to
> > instantiate CPUs, including reworking how default
> > cpu type for *-user is picked up.
> > 
> > After that cpu_model shouldn't be used anywhere in the code
> > except of routines that process "-cpu" CLI and cpu types
> > should be used directly.
> > 
> > So you might not need 1/4 after that or it would have
> > to be reworked and probably other patches where where
> > cpu_model is used.  
> 
> If I understand correctly, in linux-user/main.c we have to use
> cpu_create() instead of cpu_init(), and provide the cpu_type instead of
> the cpu_model?
yes, that's what my series does.

> In linux-user/main.c, How can I detect we want to use the default one
> (we were relying on "cpu_model == NULL" until now) to be able to compute
> the default one from the ELF header?
maybe something along this lines would do the job:

diff --git a/linux-user/main.c b/linux-user/main.c
index 4624cc9..c5d567f 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -43,6 +43,7 @@ static const char *filename;
 static const char *argv0;
 static int gdbstub_port;
 static envlist_t *envlist;
+/* default type in case it's not possible to deduce from program */
 static const char *cpu_type = TARGET_DEFAULT_CPU_TYPE;
 unsigned long mmap_min_addr;
 unsigned long guest_base;
@@ -4250,6 +4251,12 @@ static int parse_args(int argc, char **argv)
     }
 
     filename = argv[optind];
+    if (cpu_type is not set by user) {
+        /* override default type if we can get it from executable */
+        override_cpu_type = cpu_get_type(filename)
+        if (override_cpu_type)
+           cpu_type = override_cpu_type
+    }
     exec_path = argv[optind];
 
> Thanks,
> Laurent
Laurent Vivier Jan. 18, 2018, 1:33 p.m. UTC | #4
Le 18/01/2018 à 14:17, Igor Mammedov a écrit :
> On Wed, 17 Jan 2018 17:15:38 +0100
> Laurent Vivier <laurent@vivier.eu> wrote:
> 
>> Le 17/01/2018 à 16:49, Igor Mammedov a écrit :
>>> On Tue, 16 Jan 2018 23:22:08 +0100
>>> Laurent Vivier <laurent@vivier.eu> wrote:
>>>   
>>>> This idea has been suggested to me before by Philippe
>>>> Mathieu-Daudé, and recently YunQiang Su has proposed a
>>>> patch to manage the MIPS r6 case.
>>>>
>>>> Based on this, this series tries to clean-up the original
>>>> patch, and introduces the use for m68k architecture and
>>>> port the patch from YunQiang Su.
>>>>
>>>> v3: fix code indent problem reported by patchew
>>>>     remove useless "!= 0"
>>>>     check for EF_M68K_M68000
>>>>     add EF_M68K_* flags in elf.h
>>>>     set 680x0 default CPU to m68040
>>>>     change "#if ... #endif" structure for ppc
>>>> v2: move cpu_model selection to linux-user/*/target_elf.h
>>>>     provide eflags to cpu_get_model() instead of fd
>>>>     (and modify other patches accordingly)  
>>> Sorry for not noticing it earlier, but could you please
>>> fix series to use cpu type names instead of cpu_model?
>>>
>>> I've just posted series that completes cpu_model refactoring
>>>   [PATCH 00/24] generalize parsing of cpu_model (part 4)
>>> which removes remnants of the code using cpu_model to
>>> instantiate CPUs, including reworking how default
>>> cpu type for *-user is picked up.
>>>
>>> After that cpu_model shouldn't be used anywhere in the code
>>> except of routines that process "-cpu" CLI and cpu types
>>> should be used directly.
>>>
>>> So you might not need 1/4 after that or it would have
>>> to be reworked and probably other patches where where
>>> cpu_model is used.  
>>
>> If I understand correctly, in linux-user/main.c we have to use
>> cpu_create() instead of cpu_init(), and provide the cpu_type instead of
>> the cpu_model?
> yes, that's what my series does.
> 
>> In linux-user/main.c, How can I detect we want to use the default one
>> (we were relying on "cpu_model == NULL" until now) to be able to compute
>> the default one from the ELF header?
> maybe something along this lines would do the job:
> 
> diff --git a/linux-user/main.c b/linux-user/main.c
> index 4624cc9..c5d567f 100644
> --- a/linux-user/main.c
> +++ b/linux-user/main.c
> @@ -43,6 +43,7 @@ static const char *filename;
>  static const char *argv0;
>  static int gdbstub_port;
>  static envlist_t *envlist;
> +/* default type in case it's not possible to deduce from program */
>  static const char *cpu_type = TARGET_DEFAULT_CPU_TYPE;
>  unsigned long mmap_min_addr;
>  unsigned long guest_base;
> @@ -4250,6 +4251,12 @@ static int parse_args(int argc, char **argv)
>      }
>  
>      filename = argv[optind];
> +    if (cpu_type is not set by user) {
> +        /* override default type if we can get it from executable */
> +        override_cpu_type = cpu_get_type(filename)
> +        if (override_cpu_type)
> +           cpu_type = override_cpu_type
> +    }
>      exec_path = argv[optind];
>  

No, because the fd can be provided by the kernel (with binfmt and
"open-binary" attribute, provided by getauxval(AT_EXECFD)), but I think
we can manage this in linux-user/main.c:main() by setting cpu_type to
NULL and calling cpu_get_type() to set it in this case.

Thanks,
Laurent
Laurent Vivier Jan. 19, 2018, 1:56 p.m. UTC | #5
Le 17/01/2018 à 16:49, Igor Mammedov a écrit :
> On Tue, 16 Jan 2018 23:22:08 +0100
> Laurent Vivier <laurent@vivier.eu> wrote:
> 
>> This idea has been suggested to me before by Philippe
>> Mathieu-Daudé, and recently YunQiang Su has proposed a
>> patch to manage the MIPS r6 case.
>>
>> Based on this, this series tries to clean-up the original
>> patch, and introduces the use for m68k architecture and
>> port the patch from YunQiang Su.
>>
>> v3: fix code indent problem reported by patchew
>>     remove useless "!= 0"
>>     check for EF_M68K_M68000
>>     add EF_M68K_* flags in elf.h
>>     set 680x0 default CPU to m68040
>>     change "#if ... #endif" structure for ppc
>> v2: move cpu_model selection to linux-user/*/target_elf.h
>>     provide eflags to cpu_get_model() instead of fd
>>     (and modify other patches accordingly)
> Sorry for not noticing it earlier, but could you please
> fix series to use cpu type names instead of cpu_model?

As your series is not ready for inclusion, perhaps we can take my series
first?

I'll happily help you to adapt your series on top of this one if you need.

Thanks,
Laurent
Igor Mammedov Jan. 19, 2018, 2:33 p.m. UTC | #6
On Fri, 19 Jan 2018 14:56:53 +0100
Laurent Vivier <laurent@vivier.eu> wrote:

> Le 17/01/2018 à 16:49, Igor Mammedov a écrit :
> > On Tue, 16 Jan 2018 23:22:08 +0100
> > Laurent Vivier <laurent@vivier.eu> wrote:
> > 
> >> This idea has been suggested to me before by Philippe
> >> Mathieu-Daudé, and recently YunQiang Su has proposed a
> >> patch to manage the MIPS r6 case.
> >>
> >> Based on this, this series tries to clean-up the original
> >> patch, and introduces the use for m68k architecture and
> >> port the patch from YunQiang Su.
> >>
> >> v3: fix code indent problem reported by patchew
> >>     remove useless "!= 0"
> >>     check for EF_M68K_M68000
> >>     add EF_M68K_* flags in elf.h
> >>     set 680x0 default CPU to m68040
> >>     change "#if ... #endif" structure for ppc
> >> v2: move cpu_model selection to linux-user/*/target_elf.h
> >>     provide eflags to cpu_get_model() instead of fd
> >>     (and modify other patches accordingly)
> > Sorry for not noticing it earlier, but could you please
> > fix series to use cpu type names instead of cpu_model?
> 
> As your series is not ready for inclusion, perhaps we can take my series
> first?
> 
> I'll happily help you to adapt your series on top of this one if you need.
It wasn't about whose series goes first (I don't really care as I can rebase),

suggestion was about using cpu types instead of cpu models
which you are adding/moving into linux-user/*/target_elf.h

Otherwise we would need immediately to have a patch on top that
replaces them in linux-user/*/target_elf.h with cpu types.

So I'd rather amend this series so that it would use cpu types
from the start instead of doing refactoring on top which just
doubles amount of touched lines.



> Thanks,
> Laurent
>