Re: [Qemu-discuss] s390x user-mode working example

2017-11-24 Thread Alex Kashchenko

On 11/24/2017 12:52 PM, Thomas Huth wrote:

On 24.11.2017 12:19, Alex Kashchenko wrote:

Unfortunately, I just found that OpenJDK's JIT requires newer
instruction set than z900:

$ ./s390x-linux-user/qemu-s390x
~/jdk9/build/linux-s390x-normal-server-release/images/jdk/bin/java -version
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (vm_version_s390.hpp:367), pid=26037, tid=26039
#  guarantee((_features[0] & GnrlInstrExtFacilityMask) ==
GnrlInstrExtFacilityMask) failed: We no more support older than z10.


That looks like it is missing the so-called "general instruction
extension facility". You might be lucky - that's one of the extensions
that can already be enabled for testing purposes with the "qemu" CPU:
Try to start QEMU with the "-cpu qemu,ginste=true" parameter.
If it then still complains about missing facilities, try "-cpu help" to
list all recognized feature flags.


"-cpu qemu,ginste=true" helps to pass the check from previous email.



The following features can already be enabled with the "qemu" CPU (list
has been copy-n-pasted from the sources, but I hope you'll be able to
map it to the output of "-cpu help", too):

S390_FEAT_DAT_ENH,
S390_FEAT_IDTE_SEGMENT,
S390_FEAT_STFLE,
S390_FEAT_EXTENDED_IMMEDIATE,
S390_FEAT_EXTENDED_TRANSLATION_2,
S390_FEAT_EXTENDED_TRANSLATION_3,
S390_FEAT_LONG_DISPLACEMENT,
S390_FEAT_LONG_DISPLACEMENT_FAST,
S390_FEAT_ETF2_ENH,
S390_FEAT_STORE_CLOCK_FAST,
S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
S390_FEAT_ETF3_ENH,
S390_FEAT_COMPARE_AND_SWAP_AND_STORE,
S390_FEAT_COMPARE_AND_SWAP_AND_STORE_2,
S390_FEAT_GENERAL_INSTRUCTIONS_EXT,
S390_FEAT_EXECUTE_EXT,
S390_FEAT_FLOATING_POINT_SUPPPORT_ENH,
S390_FEAT_STFLE_45,
S390_FEAT_STFLE_49,
S390_FEAT_LOCAL_TLB_CLEARING,
S390_FEAT_STFLE_53,


Applying all the options from this list:

-cpu 
qemu,ginste=true,dateh=true,idtes=true,stfle=true,eimm=true,etf2=true,etf3=true,ldisp=true,ldisphp=true,etf3eh=true,etf3eh=true,csst=true,csst2=true,ginste=true,exrl=true,fpseh=true,stfle45=true,stfle49=true,ltlbc=true,stfle53=true


still causes the SIGILL during the JVM init though.

Thanks for the list! At least I know now that the problem is not caused 
by some local misconfiguration.


--
-Alex



Re: [Qemu-discuss] s390x user-mode working example

2017-11-24 Thread Thomas Huth
On 24.11.2017 12:19, Alex Kashchenko wrote:
> Unfortunately, I just found that OpenJDK's JIT requires newer
> instruction set than z900:
> 
> $ ./s390x-linux-user/qemu-s390x
> ~/jdk9/build/linux-s390x-normal-server-release/images/jdk/bin/java -version
> #
> # A fatal error has been detected by the Java Runtime Environment:
> #
> #  Internal Error (vm_version_s390.hpp:367), pid=26037, tid=26039
> #  guarantee((_features[0] & GnrlInstrExtFacilityMask) ==
> GnrlInstrExtFacilityMask) failed: We no more support older than z10.

That looks like it is missing the so-called "general instruction
extension facility". You might be lucky - that's one of the extensions
that can already be enabled for testing purposes with the "qemu" CPU:
Try to start QEMU with the "-cpu qemu,ginste=true" parameter.
If it then still complains about missing facilities, try "-cpu help" to
list all recognized feature flags.

The following features can already be enabled with the "qemu" CPU (list
has been copy-n-pasted from the sources, but I hope you'll be able to
map it to the output of "-cpu help", too):

S390_FEAT_DAT_ENH,
S390_FEAT_IDTE_SEGMENT,
S390_FEAT_STFLE,
S390_FEAT_EXTENDED_IMMEDIATE,
S390_FEAT_EXTENDED_TRANSLATION_2,
S390_FEAT_EXTENDED_TRANSLATION_3,
S390_FEAT_LONG_DISPLACEMENT,
S390_FEAT_LONG_DISPLACEMENT_FAST,
S390_FEAT_ETF2_ENH,
S390_FEAT_STORE_CLOCK_FAST,
S390_FEAT_MOVE_WITH_OPTIONAL_SPEC,
S390_FEAT_ETF3_ENH,
S390_FEAT_COMPARE_AND_SWAP_AND_STORE,
S390_FEAT_COMPARE_AND_SWAP_AND_STORE_2,
S390_FEAT_GENERAL_INSTRUCTIONS_EXT,
S390_FEAT_EXECUTE_EXT,
S390_FEAT_FLOATING_POINT_SUPPPORT_ENH,
S390_FEAT_STFLE_45,
S390_FEAT_STFLE_49,
S390_FEAT_LOCAL_TLB_CLEARING,
S390_FEAT_STFLE_53,

 HTH,
  Thomas



Re: [Qemu-discuss] s390x user-mode working example

2017-11-24 Thread Peter Maydell
On 24 November 2017 at 11:16, Alex Kashchenko  wrote:
>> Is your target binary statically linked? If not you'll need
>> to tell QEMU where the libraries are, or run it in a chroot
>> with the s390x libraries etc.
>
>
> No, it is not statically linked, on ubuntu I am installing multiarch packet
> libc6:s390x (goes to /lib/s390x-linux-gnu/libc.so.6 ) for it as a
> dependency.

You will need to tell QEMU -L /usr/s390x-linux-gnu so it
can find the dynamic libraries.

>> (You'll also need to make sure
>> it doesn't pick up the x86 /etc/ld.so.cache, because a glibc
>> bug means a bigendian dynamic linker crashes when it finds
>> a littleendian ld.so.cache, whereas same-endian-wrong-arch
>> just ignores it.)
>
>
> That was it

> Simple example now works fine for me if I delete /etc/ld.so.cache before
> running it.

If you're passing QEMU a -L argument you can just create an
empty /lib/s390x-linux-gnu/etc/ld.so.cache   which will then
take precedence over the host's file. That way you don't have
to lose the benefits of ld.so.cache for the host system.

thanks
-- PMM



Re: [Qemu-discuss] s390x user-mode working example

2017-11-24 Thread Alex Kashchenko

On 11/24/2017 05:57 AM, Thomas Huth wrote:

On 23.11.2017 22:00, Alex Kashchenko wrote:

Hi,

I am trying to build qemu-s390x-user static binary to run a hello-world
program cross-compiled with gcc-s390x-linux-gnu on linux_x86_64.

I am building qemu with:

./configure --static --disable-werror --target-list=s390x-linux-user
make

and running example with:

QEMU_STRACE=1 ./s390x-linux-user/qemu-s390x path/to/s390x-hello

I tried latest git and a number of v2.x releases without success. Can
see either hang (on first brk call) or various errors for newer versions
and "Illegal instruction" for older ones. Tried on ubuntu 16.04 and
17.10 without success.

The same steps worked for me for ppc64le hello-world.

Any help on this is highly appreciated.


How did you cross-compile your s390x binary? QEMU's CPU emulation only
fully supports the z900 so far (more support is being worked on), so you
should make sure that your program has been compiled for that CPU
architecture, i.e. add "-m64 -march=z900" to your CFLAGS. Does that help?


Thanks for suggestion! I was cross-compiling the example using 
s390x-linux-gnu-gcc without additional flags, but it seems that 
march=z900 is a default for this gcc build. I was able to run simple 
example successfully (with git master build) after deleting 
/etc/ld.so.cache .


My ultimate goal was to cross-compile OpenJDK for s390x and run it 
locally with QEMU-user to be able to smoke-test s390x OpenJDK builds for 
fedora (I am using ubuntu for experiments because of very convenient 
multiarch support in it).


Unfortunately, I just found that OpenJDK's JIT requires newer 
instruction set than z900:


$ ./s390x-linux-user/qemu-s390x 
~/jdk9/build/linux-s390x-normal-server-release/images/jdk/bin/java -version

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  Internal Error (vm_version_s390.hpp:367), pid=26037, tid=26039
#  guarantee((_features[0] & GnrlInstrExtFacilityMask) == 
GnrlInstrExtFacilityMask) failed: We no more support older than z10.

#
# JRE version:  (9.0) (build )
# Java VM: OpenJDK 64-Bit Server VM (9-internal+0-adhoc.u1804.jdk9, 
mixed mode, tiered, compressed oops, g1 gc, linux-s390x)


--
-Alex



Re: [Qemu-discuss] s390x user-mode working example

2017-11-24 Thread Alex Kashchenko

On 11/24/2017 10:14 AM, Peter Maydell wrote:

On 23 November 2017 at 21:00, Alex Kashchenko  wrote:

Hi,

I am trying to build qemu-s390x-user static binary to run a hello-world
program cross-compiled with gcc-s390x-linux-gnu on linux_x86_64.

I am building qemu with:

./configure --static --disable-werror --target-list=s390x-linux-user
make

and running example with:

QEMU_STRACE=1 ./s390x-linux-user/qemu-s390x path/to/s390x-hello

I tried latest git and a number of v2.x releases without success. Can see
either hang (on first brk call) or various errors for newer versions and
"Illegal instruction" for older ones. Tried on ubuntu 16.04 and 17.10
without success.

The same steps worked for me for ppc64le hello-world.

Any help on this is highly appreciated.


Is your target binary statically linked? If not you'll need
to tell QEMU where the libraries are, or run it in a chroot
with the s390x libraries etc.


No, it is not statically linked, on ubuntu I am installing multiarch 
packet libc6:s390x (goes to /lib/s390x-linux-gnu/libc.so.6 ) for it as a 
dependency.



(You'll also need to make sure
it doesn't pick up the x86 /etc/ld.so.cache, because a glibc
bug means a bigendian dynamic linker crashes when it finds
a littleendian ld.so.cache, whereas same-endian-wrong-arch
just ignores it.)


That was it, on a git master build:

$ QEMU_STRACE=1 ./qemu/s390x-linux-user/qemu-s390x ./a.out
4654 brk(NULL) = 0x00403000
4654 uname(0x4000803102) = 0
4654 access("/etc/ld.so.nohwcap",F_OK) = -1 errno=2 (No such file or 
directory)
4654 
mmap(0x0040008030e8,8192,PROT_READ|PROT_WRITE,MAP_PRIVATE|MAP_ANONYMOUS,-1,0x82a168) 
= 0x00400082b000
4654 access("/etc/ld.so.preload",R_OK) = -1 errno=2 (No such file or 
directory)

4654 open("/etc/ld.so.cache",O_RDONLY|O_CLOEXEC) = 3
4654 fstat(3,0x0040008027d0) = 0
4654 mmap(0x0040008026f8,25873,PROT_READ,MAP_PRIVATE,3,0x829098) = 
0x00400082d000

4654 close(3) = 0
--- SIGSEGV {si_signo=SIGSEGV, si_code=1, si_addr=0x00409088d000} ---
Segmentation fault (core dumped)


Simple example now works fine for me if I delete /etc/ld.so.cache before 
running it.


Thanks for your help!

--
-Alex



Re: [Qemu-discuss] s390x user-mode working example

2017-11-24 Thread Peter Maydell
On 23 November 2017 at 21:00, Alex Kashchenko  wrote:
> Hi,
>
> I am trying to build qemu-s390x-user static binary to run a hello-world
> program cross-compiled with gcc-s390x-linux-gnu on linux_x86_64.
>
> I am building qemu with:
>
> ./configure --static --disable-werror --target-list=s390x-linux-user
> make
>
> and running example with:
>
> QEMU_STRACE=1 ./s390x-linux-user/qemu-s390x path/to/s390x-hello
>
> I tried latest git and a number of v2.x releases without success. Can see
> either hang (on first brk call) or various errors for newer versions and
> "Illegal instruction" for older ones. Tried on ubuntu 16.04 and 17.10
> without success.
>
> The same steps worked for me for ppc64le hello-world.
>
> Any help on this is highly appreciated.

Is your target binary statically linked? If not you'll need
to tell QEMU where the libraries are, or run it in a chroot
with the s390x libraries etc. (You'll also need to make sure
it doesn't pick up the x86 /etc/ld.so.cache, because a glibc
bug means a bigendian dynamic linker crashes when it finds
a littleendian ld.so.cache, whereas same-endian-wrong-arch
just ignores it.)

thanks
-- PMM



Re: [Qemu-discuss] s390x user-mode working example

2017-11-23 Thread Thomas Huth
On 23.11.2017 22:00, Alex Kashchenko wrote:
> Hi,
> 
> I am trying to build qemu-s390x-user static binary to run a hello-world
> program cross-compiled with gcc-s390x-linux-gnu on linux_x86_64.
> 
> I am building qemu with:
> 
> ./configure --static --disable-werror --target-list=s390x-linux-user
> make
> 
> and running example with:
> 
> QEMU_STRACE=1 ./s390x-linux-user/qemu-s390x path/to/s390x-hello
> 
> I tried latest git and a number of v2.x releases without success. Can
> see either hang (on first brk call) or various errors for newer versions
> and "Illegal instruction" for older ones. Tried on ubuntu 16.04 and
> 17.10 without success.
> 
> The same steps worked for me for ppc64le hello-world.
> 
> Any help on this is highly appreciated.

How did you cross-compile your s390x binary? QEMU's CPU emulation only
fully supports the z900 so far (more support is being worked on), so you
should make sure that your program has been compiled for that CPU
architecture, i.e. add "-m64 -march=z900" to your CFLAGS. Does that help?

 Thomas