From: Thomas Huth <thuth@redhat.com>
To: David Hildenbrand <david@redhat.com>,
Claudio Imbrenda <imbrenda@linux.ibm.com>,
kvm@vger.kernel.org
Cc: linux-s390@vger.kernel.org, borntraeger@de.ibm.com,
frankja@linux.ibm.com
Subject: Re: [kvm-unit-tests PATCH v8 6/6] s390x: SCLP unit test
Date: Wed, 22 Jan 2020 11:31:37 +0100 [thread overview]
Message-ID: <e406268e-7881-f5c3-7b28-70e355765539@redhat.com> (raw)
In-Reply-To: <42c5b040-733d-4e5b-0276-5b94315336bb@redhat.com>
On 22/01/2020 11.22, David Hildenbrand wrote:
> On 22.01.20 11:10, David Hildenbrand wrote:
>> On 20.01.20 19:42, Claudio Imbrenda wrote:
>>> SCLP unit test. Testing the following:
>>>
>>> * Correctly ignoring instruction bits that should be ignored
>>> * Privileged instruction check
>>> * Check for addressing exceptions
>>> * Specification exceptions:
>>> - SCCB size less than 8
>>> - SCCB unaligned
>>> - SCCB overlaps prefix or lowcore
>>> - SCCB address higher than 2GB
>>> * Return codes for
>>> - Invalid command
>>> - SCCB too short (but at least 8)
>>> - SCCB page boundary violation
>>>
>>> Signed-off-by: Claudio Imbrenda <imbrenda@linux.ibm.com>
>>> Reviewed-by: Thomas Huth <thuth@redhat.com>
>>> Acked-by: Janosch Frank <frankja@linux.ibm.com>
>>> ---
>>> s390x/Makefile | 1 +
>>> s390x/sclp.c | 474 ++++++++++++++++++++++++++++++++++++++++++++
>>> s390x/unittests.cfg | 8 +
>>> 3 files changed, 483 insertions(+)
>>> create mode 100644 s390x/sclp.c
>>>
>>> diff --git a/s390x/Makefile b/s390x/Makefile
>>> index 3744372..ddb4b48 100644
>>> --- a/s390x/Makefile
>>> +++ b/s390x/Makefile
>>> @@ -16,6 +16,7 @@ tests += $(TEST_DIR)/diag288.elf
>>> tests += $(TEST_DIR)/stsi.elf
>>> tests += $(TEST_DIR)/skrf.elf
>>> tests += $(TEST_DIR)/smp.elf
>>> +tests += $(TEST_DIR)/sclp.elf
>>> tests_binary = $(patsubst %.elf,%.bin,$(tests))
>>>
>>> all: directories test_cases test_cases_binary
>>> diff --git a/s390x/sclp.c b/s390x/sclp.c
>>> new file mode 100644
>>> index 0000000..215347e
>>> --- /dev/null
>>> +++ b/s390x/sclp.c
>>> @@ -0,0 +1,474 @@
>>> +/*
>>> + * Service Call tests
>>> + *
>>> + * Copyright (c) 2019 IBM Corp
>>> + *
>>> + * Authors:
>>> + * Claudio Imbrenda <imbrenda@linux.ibm.com>
>>> + *
>>> + * This code is free software; you can redistribute it and/or modify it
>>> + * under the terms of the GNU General Public License version 2.
>>> + */
>>> +
>>> +#include <libcflat.h>
>>> +#include <asm/page.h>
>>> +#include <asm/asm-offsets.h>
>>> +#include <asm/interrupt.h>
>>> +#include <sclp.h>
>>> +
>>> +#define PGM_NONE 1
>>> +#define PGM_BIT_SPEC (1ULL << PGM_INT_CODE_SPECIFICATION)
>>> +#define PGM_BIT_ADDR (1ULL << PGM_INT_CODE_ADDRESSING)
>>> +#define PGM_BIT_PRIV (1ULL << PGM_INT_CODE_PRIVILEGED_OPERATION)
>>> +#define MKPTR(x) ((void *)(uint64_t)(x))
>>> +
>>> +#define LC_SIZE (2 * PAGE_SIZE)
>>> +
>>> +static uint8_t pagebuf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* scratch pages used for some tests */
>>> +static uint8_t prefix_buf[LC_SIZE] __attribute__((aligned(LC_SIZE))); /* temporary lowcore for test_sccb_prefix */
>>> +static uint8_t sccb_template[PAGE_SIZE]; /* SCCB template to be used */
>>> +static uint32_t valid_code; /* valid command code for READ SCP INFO */
>>> +static struct lowcore *lc;
>>> +
>>> +/**
>>> + * Perform one service call, handling exceptions and interrupts.
>>> + */
>>> +static int sclp_service_call_test(unsigned int command, void *sccb)
>>> +{
>>> + int cc;
>>> +
>>> + sclp_mark_busy();
>>> + sclp_setup_int();
>>> + cc = servc(command, __pa(sccb));
>>> + if (lc->pgm_int_code) {
>>> + sclp_handle_ext();
>>> + return 0;
>>> + }
>>> + if (!cc)
>>> + sclp_wait_busy();
>>> + return cc;
>>> +}
>>> +
>>> +/**
>>> + * Perform one test at the given address, optionally using the SCCB template,
>>> + * checking for the expected program interrupts and return codes.
>>> + *
>>> + * The parameter buf_len indicates the number of bytes of the template that
>>> + * should be copied to the test address, and should be 0 when the test
>>> + * address is invalid, in which case nothing is copied.
>>> + *
>>> + * The template is used to simplify tests where the same buffer content is
>>> + * used many times in a row, at different addresses.
>>> + *
>>> + * Returns true in case of success or false in case of failure
>>> + */
>>> +static bool test_one_sccb(uint32_t cmd, uint8_t *addr, uint16_t buf_len, uint64_t exp_pgm, uint16_t exp_rc)
>>> +{
>>> + SCCBHeader *h = (SCCBHeader *)addr;
>>> + int res, pgm;
>>> +
>>> + /* Copy the template to the test address if needed */
>>> + if (buf_len)
>>> + memcpy(addr, sccb_template, buf_len);
>>> + if (exp_pgm != PGM_NONE)
>>> + expect_pgm_int();
>>> + /* perform the actual call */
>>> + res = sclp_service_call_test(cmd, h);
>>> + if (res) {
>>> + report_info("SCLP not ready (command %#x, address %p, cc %d)", cmd, addr, res);
>>> + return false;
>>> + }
>>> + pgm = clear_pgm_int();
>>> + /* Check if the program exception was one of the expected ones */
>>> + if (!((1ULL << pgm) & exp_pgm)) {
>>> + report_info("First failure at addr %p, buf_len %d, cmd %#x, pgm code %d",
>>> + addr, buf_len, cmd, pgm);
>>> + return false;
>>> + }
>>> + /* Check if the response code is the one expected */
>>> + if (exp_rc && exp_rc != h->response_code) {
>>> + report_info("First failure at addr %p, buf_len %d, cmd %#x, resp code %#x",
>>> + addr, buf_len, cmd, h->response_code);
>>> + return false;
>>> + }
>>> + return true;
>>> +}
>>> +
>>> +/**
>>> + * Wrapper for test_one_sccb to be used when the template should not be
>>> + * copied and the memory address should not be touched.
>>> + */
>>> +static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_t exp_rc)
>>> +{
>>> + return test_one_sccb(cmd, addr, 0, exp_pgm, exp_rc);
>>> +}
>>> +
>>> +/**
>>> + * Wrapper for test_one_sccb to set up a simple SCCB template.
>>> + *
>>> + * The parameter sccb_len indicates the value that will be saved in the SCCB
>>> + * length field of the SCCB, buf_len indicates the number of bytes of
>>> + * template that need to be copied to the actual test address. In many cases
>>> + * it's enough to clear/copy the first 8 bytes of the buffer, while the SCCB
>>> + * itself can be larger.
>>> + *
>>> + * Returns true in case of success or false in case of failure
>>> + */
>>> +static bool test_one_simple(uint32_t cmd, uint8_t *addr, uint16_t sccb_len,
>>> + uint16_t buf_len, uint64_t exp_pgm, uint16_t exp_rc)
>>> +{
>>> + memset(sccb_template, 0, sizeof(sccb_template));
>>> + ((SCCBHeader *)sccb_template)->length = sccb_len;
>>> + return test_one_sccb(cmd, addr, buf_len, exp_pgm, exp_rc);
>>
>> Doing a fresh ./configure + make on RHEL7 gives me
>>
>> [linux1@rhkvm01 kvm-unit-tests]$ make
>> gcc -std=gnu99 -ffreestanding -I /home/linux1/git/kvm-unit-tests/lib -I /home/linux1/git/kvm-unit-tests/lib/s390x -I lib -O2 -march=zEC12 -fno-delete-null-pointer-checks -g -MMD -MF s390x/.sclp.d -Wall -Wwrite-strings -Wempty-body -Wuninitialized -Wignored-qualifiers -Werror -fomit-frame-pointer -Wno-frame-address -fno-pic -Wclobbered -Wunused-but-set-parameter -Wmissing-parameter-type -Wold-style-declaration -Woverride-init -Wmissing-prototypes -Wstrict-prototypes -c -o s390x/sclp.o s390x/sclp.c
>> s390x/sclp.c: In function 'test_one_simple':
>> s390x/sclp.c:121:2: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
>> ((SCCBHeader *)sccb_template)->length = sccb_len;
>> ^
>> s390x/sclp.c: At top level:
>> cc1: error: unrecognized command line option "-Wno-frame-address" [-Werror]
>> cc1: all warnings being treated as errors
>> make: *** [s390x/sclp.o] Error 1
>
> The following makes it work:
>
>
> diff --git a/s390x/sclp.c b/s390x/sclp.c
> index c13fa60..0b8117a 100644
> --- a/s390x/sclp.c
> +++ b/s390x/sclp.c
> @@ -117,8 +117,10 @@ static bool test_one_ro(uint32_t cmd, uint8_t *addr, uint64_t exp_pgm, uint16_t
> static bool test_one_simple(uint32_t cmd, uint8_t *addr, uint16_t sccb_len,
> uint16_t buf_len, uint64_t exp_pgm, uint16_t exp_rc)
> {
> + SCCBHeader *header = (void *)sccb_template;
> +
> memset(sccb_template, 0, sizeof(sccb_template));
> - ((SCCBHeader *)sccb_template)->length = sccb_len;
> + header->length = sccb_len;
While that might silence the compiler warning, we still might get
aliasing problems here, I think.
The right way to solve this problem is to turn sccb_template into a
union of the various structs/arrays that you want to use and then access
the fields through the union instead ("type-punning through union").
Thomas
next prev parent reply other threads:[~2020-01-22 10:31 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-20 18:42 [kvm-unit-tests PATCH v8 0/6] s390x: SCLP Unit test Claudio Imbrenda
2020-01-20 18:42 ` [kvm-unit-tests PATCH v8 1/6] s390x: export sclp_setup_int Claudio Imbrenda
2020-01-20 18:42 ` [kvm-unit-tests PATCH v8 2/6] s390x: sclp: add service call instruction wrapper Claudio Imbrenda
2020-01-20 18:42 ` [kvm-unit-tests PATCH v8 3/6] s390x: lib: fix stfl wrapper asm Claudio Imbrenda
2020-01-21 6:15 ` Thomas Huth
2020-01-21 9:17 ` David Hildenbrand
2020-01-21 12:42 ` Janosch Frank
2020-01-20 18:42 ` [kvm-unit-tests PATCH v8 4/6] s390x: lib: add SPX and STPX instruction wrapper Claudio Imbrenda
2020-01-20 18:42 ` [kvm-unit-tests PATCH v8 5/6] s390x: lib: fix program interrupt handler if sclp_busy was set Claudio Imbrenda
2020-01-21 6:19 ` Thomas Huth
2020-01-21 9:18 ` David Hildenbrand
2020-01-20 18:42 ` [kvm-unit-tests PATCH v8 6/6] s390x: SCLP unit test Claudio Imbrenda
2020-01-22 9:55 ` David Hildenbrand
2020-01-22 10:10 ` David Hildenbrand
2020-01-22 10:22 ` David Hildenbrand
2020-01-22 10:31 ` Thomas Huth [this message]
2020-01-22 10:32 ` David Hildenbrand
2020-01-22 10:39 ` Thomas Huth
2020-01-22 10:40 ` David Hildenbrand
2020-01-22 11:20 ` David Hildenbrand
2020-01-22 12:13 ` Thomas Huth
2020-01-22 12:16 ` Thomas Huth
2020-01-22 14:15 ` strict aliasing in kvm-unit-tests (was: Re: [kvm-unit-tests PATCH v8 6/6] s390x: SCLP unit test) Thomas Huth
2020-01-22 14:42 ` Paolo Bonzini
2020-01-22 15:01 ` Laurent Vivier
2020-01-22 9:55 ` [kvm-unit-tests PATCH v8 0/6] s390x: SCLP Unit test David Hildenbrand
2020-01-22 10:02 ` David Hildenbrand
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e406268e-7881-f5c3-7b28-70e355765539@redhat.com \
--to=thuth@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=david@redhat.com \
--cc=frankja@linux.ibm.com \
--cc=imbrenda@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=linux-s390@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).