Re: [kvm-unit-tests PATCH] s390x: Add specification exception test

Cornelia Huck
2021-07-09T09:22:59Z

On Tue, Jul 06 2021, Janis Schoetterl-Glausch <scgl@linux.ibm.com> wrote:

> Generate specification exceptions and check that they occur.
> Also generate specification exceptions during a transaction,
> which results in another interruption code.
> With the iterations argument one can check if specification
> exception interpretation occurs, e.g. by using a high value and
> checking that the debugfs counters are substantially lower.
> The argument is also useful for estimating the performance benefit
> of interpretation.
>
> Signed-off-by: Janis Schoetterl-Glausch <scgl@linux.ibm.com>
> ---
> s390x/Makefile | 1 +
> lib/s390x/asm/arch_def.h | 1 +
> s390x/spec_ex.c | 344 +++++++++++++++++++++++++++++++++++++++
> s390x/unittests.cfg | 3 +
> 4 files changed, 349 insertions(+)
> create mode 100644 s390x/spec_ex.c

(...)

> +static void lpsw(uint64_t psw)

Maybe call this load_psw(), as you do a bit more than a simple lpsw?

> +{
> + uint32_t *high, *low;
> + uint64_t r0 = 0, r1 = 0;
> +
> + high = (uint32_t *) &fixup_early_pgm_psw.mask;
> + low = high + 1;
> +
> + asm volatile (
> + " epsw %0,%1\n"
> + " st %0,%[high]\n"
> + " st %1,%[low]\n"
> + " larl %0,nop%=\n"
> + " stg %0,%[addr]\n"
> + " lpsw %[psw]\n"
> + "nop%=: nop\n"
> + : "+&r"(r0), "+&a"(r1), [high] "=&R"(*high), [low] "=&R"(*low)
> + , [addr] "=&R"(fixup_early_pgm_psw.addr)
> + : [psw] "Q"(psw)
> + : "cc", "memory"
> + );
> +}

(...)

> +static void test_spec_ex(struct args *args,
> + const struct spec_ex_trigger *trigger)
> +{
> + uint16_t expected_pgm = PGM_INT_CODE_SPECIFICATION;
> + uint16_t pgm;
> + unsigned int i;
> +
> + register_pgm_cleanup_func(trigger->fixup);
> + for (i = 0; i < args->iterations; i++) {
> + expect_pgm_int();
> + trigger->func();
> + pgm = clear_pgm_int();
> + if (pgm != expected_pgm) {
> + report(0,
> + "Program interrupt: expected(%d) == received(%d)",
> + expected_pgm,
> + pgm);

The indentation looks a bit funny here.

> + return;
> + }
> + }
> + report(1,
> + "Program interrupt: always expected(%d) == received(%d)",
> + expected_pgm,
> + expected_pgm);

Here as well.

> +}

(...)

> +#define report_info_if(cond, fmt, ...) \
> + do { \
> + if (cond) { \
> + report_info(fmt, ##__VA_ARGS__);\
> + } \
> + } while (0)

I'm wondering whether such a wrapper function could be generally useful.