Re: [kvm-unit-tests PATCH v2 2/7] s390x: Consolidate sclp read info

Thomas Huth
2020-11-27T13:59:17Z

On 27/11/2020 14.06, Janosch Frank wrote:
> Let's only read the information once and pass a pointer to it instead
> of calling sclp multiple times.
>
> Signed-off-by: Janosch Frank <frankja@linux.ibm.com>
> Reviewed-by: Cornelia Huck <cohuck@redhat.com>
> ---
> lib/s390x/io.c | 1 +
> lib/s390x/sclp.c | 29 +++++++++++++++++++++++------
> lib/s390x/sclp.h | 3 +++
> lib/s390x/smp.c | 28 +++++++++++-----------------
> 4 files changed, 38 insertions(+), 23 deletions(-)
...
> diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c
> index 4e2ac18..ff56c44 100644
> --- a/lib/s390x/sclp.c
> +++ b/lib/s390x/sclp.c
> @@ -25,6 +25,8 @@ extern unsigned long stacktop;
> static uint64_t storage_increment_size;
> static uint64_t max_ram_size;
> static uint64_t ram_size;
> +char _read_info[PAGE_SIZE] __attribute__((__aligned__(4096)));
> +static ReadInfo *read_info;
>
> char _sccb[PAGE_SIZE] __attribute__((__aligned__(4096)));
> static volatile bool sclp_busy;
> @@ -110,6 +112,22 @@ static void sclp_read_scp_info(ReadInfo *ri, int length)
> report_abort("READ_SCP_INFO failed");
> }
>
> +void sclp_read_info(void)
> +{
> + sclp_read_scp_info((void *)_read_info, SCCB_SIZE);
> + read_info = (ReadInfo *)_read_info;
> +}
> +
> +int sclp_get_cpu_num(void)
> +{

I forgot to say: Maybe add a

assert(read_info);

here, just in case? (since we can dereference the NULL pointer in the k-u-t)

> + return read_info->entries_cpu;
> +}
> +
> +CPUEntry *sclp_get_cpu_entries(void)
> +{

dito.

> + return (void *)read_info + read_info->offset_cpu;
> +}

Thomas