mbox series

[risu,0/4] Add support for s390x to RISU

Message ID 20230904140040.33153-1-thuth@redhat.com
Headers show
Series Add support for s390x to RISU | expand

Message

Thomas Huth Sept. 4, 2023, 2 p.m. UTC
Hi Peter!

Here are some patches that add basic support for s390x to RISU.
It's still quite limited, e.g. no support for load/store memory
operations yet, but the basics with simple 16-bit or 32-bit
instructions work already fine.

(In the long run, we'd need to support instructions with 48-bit
length on s390x, too, since most newer "interesting" instructions
like e.g. vector SIMD instructions are encoded with 48 bit. This
will require modifications to the generic code, too, so I limited
my initial implementation to 16-bit and 32-bit instruction length
support to keep the code self-contained in the s390x architecture
specific files)

Thomas Huth (4):
  s390x: Add basic s390x support to the C code
  s390x: Add simple s390x.risu file
  s390x: Add basic risugen perl module for s390x
  s390x: Update the configure script for s390x support

 configure            |   4 +-
 risu_reginfo_s390x.c | 142 +++++++++++++++++++++++++++++++
 risu_reginfo_s390x.h |  23 +++++
 risu_s390x.c         |  48 +++++++++++
 risugen_s390x.pm     | 194 +++++++++++++++++++++++++++++++++++++++++++
 s390x.risu           |  48 +++++++++++
 test_s390x.S         |  32 +++++++
 7 files changed, 490 insertions(+), 1 deletion(-)
 create mode 100644 risu_reginfo_s390x.c
 create mode 100644 risu_reginfo_s390x.h
 create mode 100644 risu_s390x.c
 create mode 100644 risugen_s390x.pm
 create mode 100644 s390x.risu
 create mode 100644 test_s390x.S

Comments

Ilya Leoshkevich Sept. 4, 2023, 2:30 p.m. UTC | #1
On Mon, 2023-09-04 at 16:00 +0200, Thomas Huth wrote:
>  Hi Peter!
> 
> Here are some patches that add basic support for s390x to RISU.
> It's still quite limited, e.g. no support for load/store memory
> operations yet, but the basics with simple 16-bit or 32-bit
> instructions work already fine.
> 
> (In the long run, we'd need to support instructions with 48-bit
> length on s390x, too, since most newer "interesting" instructions
> like e.g. vector SIMD instructions are encoded with 48 bit. This
> will require modifications to the generic code, too, so I limited
> my initial implementation to 16-bit and 32-bit instruction length
> support to keep the code self-contained in the s390x architecture
> specific files)

What's also interesting about SIMD, is that floating-point instructions
clobber the upper parts of vector registers. I wonder if there is a way
to systematically solve this? In my scripts the solution isn't pretty:

            insn = gdb.execute("x/i $pc", to_string=True)
            print(insn)
            gdb.execute("stepi")
            if "%f" in insn:
               [ Skip comparison ]

I think there are also a few cases in non-SIMD areas, where PoP
basically says "if conditions X and Y hold, the output is
unpredictable".


One other thing - for not-so-near future - is it possible to integrate
this with coverage-based fuzzers? I.e., somehow generate the
instructions based on the coverage signal. Maybe even make sure that
the signal comes from JITed code too. I wanted to try AFLplusplus in
QEMU mode for this purpose (which would ultimately run QEMU in QEMU),
but never found the time.

[...]
Thomas Huth Sept. 5, 2023, noon UTC | #2
On 04/09/2023 16.30, Ilya Leoshkevich wrote:
> On Mon, 2023-09-04 at 16:00 +0200, Thomas Huth wrote:
>>   Hi Peter!
>>
>> Here are some patches that add basic support for s390x to RISU.
>> It's still quite limited, e.g. no support for load/store memory
>> operations yet, but the basics with simple 16-bit or 32-bit
>> instructions work already fine.
>>
>> (In the long run, we'd need to support instructions with 48-bit
>> length on s390x, too, since most newer "interesting" instructions
>> like e.g. vector SIMD instructions are encoded with 48 bit. This
>> will require modifications to the generic code, too, so I limited
>> my initial implementation to 16-bit and 32-bit instruction length
>> support to keep the code self-contained in the s390x architecture
>> specific files)
> 
> What's also interesting about SIMD, is that floating-point instructions
> clobber the upper parts of vector registers. I wonder if there is a way
> to systematically solve this?#

No clue yet, so far the code does not support the extended vector registers 
yet (since the weren't part of the information that is provided by the 
ucontext.h header file).

I guess it should be OK to check only the floating point part for the 
registers where it overlaps, and only check the full vector register if the 
register does not overlap ... I don't expect much difference for a vector 
instruction when it executes with register 0 - 15 compared to when it 
executes with register 16 - 31, so skipping half of the check for register 0 
- 15 shouldn't be too bad.

> One other thing - for not-so-near future - is it possible to integrate
> this with coverage-based fuzzers? I.e., somehow generate the
> instructions based on the coverage signal. Maybe even make sure that
> the signal comes from JITed code too. I wanted to try AFLplusplus in
> QEMU mode for this purpose (which would ultimately run QEMU in QEMU),
> but never found the time.

I don't think this is possible yet, but maybe it's be possible to write a 
TCG plugin for QEMU to dump the executed instructions into an input file for 
risu?

  Thomas