s390x linux-user assertion fires in vector asm on master

Host environment

  • Operating system: Ubuntu 20.04
  • OS/kernel version: Linux ja-x-2004-qemu1 5.4.0-74-generic #83-Ubuntu SMP Sat May 8 02:35:39 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux
  • Architecture: amd64
  • QEMU flavor: qemu-user
  • QEMU version: master (3593b8e0)
  • QEMU command line:
qemu-s390x-static -E PATH=/home/jalbrecht/s390x/15/go/bin -L /usr/s390x-linux-gnu /home/jalbrecht/s390x/15/go/bin/go run ecdsaexample.go

Emulated/Virtualized environment

  • Operating system:
  • OS/kernel version:
  • Architecture: s390x

Description of problem

Seeing a assert being fired when running this go program that executes vector instructions:

ecdsaexample.go

qemu-s390x-static: ../qemu/target/s390x/translate.c:1063: get_field1: Assertion `have_field1(s, o)' failed.
SIGABRT: abort
PC=0x5b660 m=0 sigcode=4294967290

goroutine 1 [running]:
runtime.sigpanic()
        /home/jalbrecht/s390x/15/go/src/runtime/signal_unix.go:723 fp=0xc000198998 sp=0xc000198998 pc=0x5b660
crypto/elliptic.p256SqrInternalVMSL()
        /home/jalbrecht/s390x/15/go/src/crypto/elliptic/p256_asm_s390x.s:1488 fp=0xc0001989a0 sp=0xc0001989a0 pc=0xda600
p256SqrInternal()
        /home/jalbrecht/s390x/15/go/src/crypto/elliptic/p256_asm_s390x.s:1695 +0x18 fp=0xc0001989d8 sp=0xc0001989a0 pc=0xd95b8
crypto/elliptic.p256SqrAsm(0xc000198bc0, 0x20, 0x20, 0xc000198ce0, 0x20, 0x20, 0x0, 0xc, 0x30, 0x4000802560, ...)
        /home/jalbrecht/s390x/15/go/src/crypto/elliptic/p256_asm_s390x.s:1849 +0x3c fp=0xc0001989e0 sp=0xc0001989d8 pc=0xdaa6c
crypto/elliptic.p256Sqr(...)
        /home/jalbrecht/s390x/15/go/src/crypto/elliptic/p256_s390x.go:81
crypto/elliptic.p256Inverse(0xc000198bc0, 0x20, 0x20, 0xc000198ce0, 0x20, 0x20)
        /home/jalbrecht/s390x/15/go/src/crypto/elliptic/p256_s390x.go:324 +0x66 fp=0xc000198b28 sp=0xc0001989e0 pc=0xd7da6
crypto/elliptic.initTable()
        /home/jalbrecht/s390x/15/go/src/crypto/elliptic/p256_s390x.go:436 +0x192 fp=0xc000198d00 sp=0xc000198b28 pc=0xd87d2
crypto/elliptic.initP256Arch(...)
        /home/jalbrecht/s390x/15/go/src/crypto/elliptic/p256_s390x.go:57
crypto/elliptic.initP256()
        /home/jalbrecht/s390x/15/go/src/crypto/elliptic/p256.go:40 +0x2c0 fp=0xc000198d38 sp=0xc000198d00 pc=0xd2960
crypto/elliptic.initAll()
        /home/jalbrecht/s390x/15/go/src/crypto/elliptic/elliptic.go:397 +0x24 fp=0xc000198d40 sp=0xc000198d38 pc=0xd1ab4
sync.(*Once).doSlow(0x2168e8, 0x122be8)
        /home/jalbrecht/s390x/15/go/src/sync/once.go:66 +0x12c fp=0xc000198d98 sp=0xc000198d40 pc=0x7ee5c
sync.(*Once).Do(...)
        /home/jalbrecht/s390x/15/go/src/sync/once.go:57
crypto/elliptic.P256(...)
        /home/jalbrecht/s390x/15/go/src/crypto/elliptic/elliptic.go:433
main.main()
        /home/jalbrecht/s390x/ecdsaexample.go:17 +0x7de fp=0xc000198f80 sp=0xc000198d98 pc=0xe4a2e
runtime.main()
        /home/jalbrecht/s390x/15/go/src/runtime/proc.go:204 +0x214 fp=0xc000198fd8 sp=0xc000198f80 pc=0x472e4
runtime.goexit()
        /home/jalbrecht/s390x/15/go/src/runtime/asm_s390x.s:779 +0x2 fp=0xc000198fd8 sp=0xc000198fd8 pc=0x77c52

r0   0x0        r1   0xc000198bc0
r2   0xc000198ce0       r3   0xc000198ce0
r4   0x1401a0   r5   0xc000198be0
r6   0xc000198bc0       r7   0x1c00f0
r8   0xda600    r9   0xc0001989a8
r10  0x217810   r11  0x0
r12  0x4000800378       r13  0xc000000180
r14  0xda600    r15  0xc000198998
pc   0x5b660    link 0xda600
exit status 2

Steps to reproduce

On an amd64 linux host:

  1. Download attached ecdsaexample.go file
  2. Download and untar an s390x go distro (1.15 and 1.16 both show this issue): https://golang.org/dl/go1.15.13.linux-s390x.tar.gz
  3. Build a qemu-s390x-static from current master
  4. qemu-s390x-static -E PATH=/path/to/s390x/15/go/bin -L /usr/s390x-linux-gnu /path/to/s390x/15/go/bin/go run ecdsaexample.go

Additional information

@davidhildenbrand could you have a look? I tracked it down to this series of patches: https://lore.kernel.org/qemu-devel/20210608092337.12221-1-david@redhat.com/. I tried reverting just this series from current master and then the program runs with no issues.

This crash is seen whenever eg. certificates are checked when connecting via https so it is likely to happen in real programs.

cc: @ruixinbao

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information