From patchwork Fri Nov 27 13:06:23 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 11936289 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 70E8FC64E8A for ; Fri, 27 Nov 2020 13:09:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3546E22248 for ; Fri, 27 Nov 2020 13:09:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="QV8EeyFG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730148AbgK0NJK (ORCPT ); Fri, 27 Nov 2020 08:09:10 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:65496 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730066AbgK0NJK (ORCPT ); Fri, 27 Nov 2020 08:09:10 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0ARCVY6M187796; Fri, 27 Nov 2020 08:09:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=7PLA+wHiCZwtzEzklzXSMkA9+LdthVygMLRoFoRGCeM=; b=QV8EeyFGapY7OtJk/21AsjJKk5FBhveHtQ9f2KYGBRy4s/2iotjnMnZFSzF7sRHN5862 FEBFSYZn8jj1P2D+UFwmOj5hgBFFlWFVvVo7S2+XOqlbUCqi8o5O7y8qIpA7WI+gPcdv Ix8Ews7RDitrC1gFG0xw8CMPsq5Mhg4bxb1jwrC8u/i8xtoNBelvc3iG/oxNWNjzvQnd BnpnV14WP6KYoGGQqFOovL7qv3MEv2QGtO2sSpRfQBvLu4Hw6IRbuG8UiGlvtkF4nRZq Ti8ZEaOKFWZpfuY8/9SYN/0lUFKf2r+TQGfJXAKJEOGPTgGCec2CRpNsN+DCZxugpVlZ Eg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 352we6r3fm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 08:09:09 -0500 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0ARCVnHt189080; Fri, 27 Nov 2020 08:09:08 -0500 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 352we6r3f3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 08:09:08 -0500 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0ARCSREc024095; Fri, 27 Nov 2020 13:09:07 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma03fra.de.ibm.com with ESMTP id 352jgsh05b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 13:09:06 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0ARD6YlR58655066 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Nov 2020 13:06:34 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0F3B54C071; Fri, 27 Nov 2020 13:06:34 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4B53C4C046; Fri, 27 Nov 2020 13:06:33 +0000 (GMT) Received: from linux01.pok.stglabs.ibm.com (unknown [9.114.17.81]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 27 Nov 2020 13:06:33 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: thuth@redhat.com, david@redhat.com, borntraeger@de.ibm.com, imbrenda@linux.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org Subject: [kvm-unit-tests PATCH v2 1/7] s390x: Add test_bit to library Date: Fri, 27 Nov 2020 08:06:23 -0500 Message-Id: <20201127130629.120469-2-frankja@linux.ibm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201127130629.120469-1-frankja@linux.ibm.com> References: <20201127130629.120469-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-27_05:2020-11-26,2020-11-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 adultscore=0 bulkscore=0 mlxlogscore=999 lowpriorityscore=0 malwarescore=0 clxscore=1015 suspectscore=1 mlxscore=0 spamscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011270076 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Query/feature bits are commonly tested via MSB bit numbers on s390. Let's add test bit functions, so we don't need to copy code to test query bits. The test_bit code has been taken from the kernel since most s390x KVM unit test developers are used to them. Signed-off-by: Janosch Frank Reviewed-by: Cornelia Huck Reviewed-by: Thomas Huth --- lib/s390x/asm/bitops.h | 26 ++++++++++++++++++++++++++ lib/s390x/asm/facility.h | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/s390x/asm/bitops.h b/lib/s390x/asm/bitops.h index e7cdda9..792881e 100644 --- a/lib/s390x/asm/bitops.h +++ b/lib/s390x/asm/bitops.h @@ -1,3 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Bitops taken from the kernel as most developers are already used + * to them. + * + * Copyright IBM Corp. 1999,2013 + * + * Author(s): Martin Schwidefsky , + * + */ #ifndef _ASMS390X_BITOPS_H_ #define _ASMS390X_BITOPS_H_ @@ -7,4 +17,20 @@ #define BITS_PER_LONG 64 +static inline bool test_bit(unsigned long nr, + const volatile unsigned long *ptr) +{ + const volatile unsigned char *addr; + + addr = ((const volatile unsigned char *)ptr); + addr += (nr ^ (BITS_PER_LONG - 8)) >> 3; + return (*addr >> (nr & 7)) & 1; +} + +static inline bool test_bit_inv(unsigned long nr, + const volatile unsigned long *ptr) +{ + return test_bit(nr ^ (BITS_PER_LONG - 1), ptr); +} + #endif diff --git a/lib/s390x/asm/facility.h b/lib/s390x/asm/facility.h index def2705..5593c2d 100644 --- a/lib/s390x/asm/facility.h +++ b/lib/s390x/asm/facility.h @@ -13,13 +13,14 @@ #include #include #include +#include #define NB_STFL_DOUBLEWORDS 32 extern uint64_t stfl_doublewords[]; static inline bool test_facility(int nr) { - return stfl_doublewords[nr / 64] & (0x8000000000000000UL >> (nr % 64)); + return test_bit_inv(nr, stfl_doublewords); } static inline void stfl(void) From patchwork Fri Nov 27 13:06:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 11936279 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C3E1C64E75 for ; Fri, 27 Nov 2020 13:06:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E44F021D7A for ; Fri, 27 Nov 2020 13:06:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="CUDDFd3C" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729957AbgK0NGm (ORCPT ); Fri, 27 Nov 2020 08:06:42 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:23226 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729913AbgK0NGm (ORCPT ); Fri, 27 Nov 2020 08:06:42 -0500 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0ARCXRx2157382; Fri, 27 Nov 2020 08:06:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=gnA6VjrfI7l5pN7+f9zxBkVs77NSTk5PQT8xijBl3H4=; b=CUDDFd3CU+AsDW/qdbioQewLvoqlLiGvhtp+W+wGpmJyhkVwT3lKPzTVOWnO2elCmIpC Y7VlfWT86CRyfJC+yj7wFgIOn711Iu6BURn/ShhqAvhtaHJrahrjfOYZKBpn8qo+yEpP OXK5ot6qdW8nyN36Mjp8SoVxq/d3VPVRtRne90uEETGA+y9jOp6v+lr6N3bb8Vhh6DMu 8TI9qCTEyONyZoiZxqlalhwx6wphHTUzOHDlI1dULs3JVXuoAp4/KtFUFrdu6TAZgGUY y1DM6Go0EHnUV57H0jP2/rMGVwm/kpEPhf1nYpUw+Vqpb9zZzhEF3BHbhHOojIE2dKlK GA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 352wxxy1sw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 08:06:40 -0500 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0ARCY3id163002; Fri, 27 Nov 2020 08:06:40 -0500 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 352wxxy1rg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 08:06:40 -0500 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0ARCSREO024095; Fri, 27 Nov 2020 13:06:38 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma03fra.de.ibm.com with ESMTP id 352jgsh028-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 13:06:37 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0ARD6ZB11835584 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Nov 2020 13:06:35 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F06A64C04A; Fri, 27 Nov 2020 13:06:34 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 36D214C046; Fri, 27 Nov 2020 13:06:34 +0000 (GMT) Received: from linux01.pok.stglabs.ibm.com (unknown [9.114.17.81]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 27 Nov 2020 13:06:34 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: thuth@redhat.com, david@redhat.com, borntraeger@de.ibm.com, imbrenda@linux.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org Subject: [kvm-unit-tests PATCH v2 2/7] s390x: Consolidate sclp read info Date: Fri, 27 Nov 2020 08:06:24 -0500 Message-Id: <20201127130629.120469-3-frankja@linux.ibm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201127130629.120469-1-frankja@linux.ibm.com> References: <20201127130629.120469-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-27_06:2020-11-26,2020-11-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 priorityscore=1501 suspectscore=1 phishscore=0 malwarescore=0 mlxlogscore=999 impostorscore=0 adultscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011270078 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Let's only read the information once and pass a pointer to it instead of calling sclp multiple times. Signed-off-by: Janosch Frank Reviewed-by: Cornelia Huck --- 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/io.c b/lib/s390x/io.c index c0f0bf7..e19a1f3 100644 --- a/lib/s390x/io.c +++ b/lib/s390x/io.c @@ -36,6 +36,7 @@ void setup(void) { setup_args_progname(ipl_args); setup_facilities(); + sclp_read_info(); sclp_console_setup(); sclp_memory_setup(); smp_setup(); 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) +{ + return read_info->entries_cpu; +} + +CPUEntry *sclp_get_cpu_entries(void) +{ + return (void *)read_info + read_info->offset_cpu; +} + /* Perform service call. Return 0 on success, non-zero otherwise. */ int sclp_service_call(unsigned int command, void *sccb) { @@ -127,23 +145,22 @@ int sclp_service_call(unsigned int command, void *sccb) void sclp_memory_setup(void) { - ReadInfo *ri = (void *)_sccb; uint64_t rnmax, rnsize; int cc; - sclp_read_scp_info(ri, SCCB_SIZE); + assert(read_info); /* calculate the storage increment size */ - rnsize = ri->rnsize; + rnsize = read_info->rnsize; if (!rnsize) { - rnsize = ri->rnsize2; + rnsize = read_info->rnsize2; } storage_increment_size = rnsize << 20; /* calculate the maximum memory size */ - rnmax = ri->rnmax; + rnmax = read_info->rnmax; if (!rnmax) { - rnmax = ri->rnmax2; + rnmax = read_info->rnmax2; } max_ram_size = rnmax * storage_increment_size; diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h index 675f07e..6620531 100644 --- a/lib/s390x/sclp.h +++ b/lib/s390x/sclp.h @@ -271,6 +271,9 @@ void sclp_wait_busy(void); void sclp_mark_busy(void); void sclp_console_setup(void); void sclp_print(const char *str); +void sclp_read_info(void); +int sclp_get_cpu_num(void); +CPUEntry *sclp_get_cpu_entries(void); int sclp_service_call(unsigned int command, void *sccb); void sclp_memory_setup(void); uint64_t get_ram_size(void); diff --git a/lib/s390x/smp.c b/lib/s390x/smp.c index 77d80ca..f77ad1e 100644 --- a/lib/s390x/smp.c +++ b/lib/s390x/smp.c @@ -25,7 +25,6 @@ #include "smp.h" #include "sclp.h" -static char cpu_info_buffer[PAGE_SIZE] __attribute__((__aligned__(4096))); static struct cpu *cpus; static struct cpu *cpu0; static struct spinlock lock; @@ -34,8 +33,7 @@ extern void smp_cpu_setup_state(void); int smp_query_num_cpus(void) { - struct ReadCpuInfo *info = (void *)cpu_info_buffer; - return info->nr_configured; + return sclp_get_cpu_num(); } struct cpu *smp_cpu_from_addr(uint16_t addr) @@ -228,10 +226,10 @@ void smp_teardown(void) { int i = 0; uint16_t this_cpu = stap(); - struct ReadCpuInfo *info = (void *)cpu_info_buffer; + int num = smp_query_num_cpus(); spin_lock(&lock); - for (; i < info->nr_configured; i++) { + for (; i < num; i++) { if (cpus[i].active && cpus[i].addr != this_cpu) { sigp_retry(cpus[i].addr, SIGP_STOP, 0, NULL); @@ -245,22 +243,18 @@ extern uint64_t *stackptr; void smp_setup(void) { int i = 0; + int num = smp_query_num_cpus(); unsigned short cpu0_addr = stap(); - struct ReadCpuInfo *info = (void *)cpu_info_buffer; + struct CPUEntry *entry = sclp_get_cpu_entries(); - spin_lock(&lock); - sclp_mark_busy(); - info->h.length = PAGE_SIZE; - sclp_service_call(SCLP_READ_CPU_INFO, cpu_info_buffer); + if (num > 1) + printf("SMP: Initializing, found %d cpus\n", num); - if (smp_query_num_cpus() > 1) - printf("SMP: Initializing, found %d cpus\n", info->nr_configured); - - cpus = calloc(info->nr_configured, sizeof(cpus)); - for (i = 0; i < info->nr_configured; i++) { - cpus[i].addr = info->entries[i].address; + cpus = calloc(num, sizeof(cpus)); + for (i = 0; i < num; i++) { + cpus[i].addr = entry[i].address; cpus[i].active = false; - if (info->entries[i].address == cpu0_addr) { + if (entry[i].address == cpu0_addr) { cpu0 = &cpus[i]; cpu0->stack = stackptr; cpu0->lowcore = (void *)0; From patchwork Fri Nov 27 13:06:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 11936291 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C181BC71155 for ; Fri, 27 Nov 2020 13:09:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6E69221D7A for ; Fri, 27 Nov 2020 13:09:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="KVlhn2is" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730211AbgK0NJM (ORCPT ); Fri, 27 Nov 2020 08:09:12 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:57406 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729874AbgK0NJM (ORCPT ); Fri, 27 Nov 2020 08:09:12 -0500 Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0ARCWh9D181417; Fri, 27 Nov 2020 08:09:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=dCuRmNlHkF7zTHmbcinSmdJygmI/9pM6oX0ohxvH4xQ=; b=KVlhn2isSdR8xmLep68aSTbW0KnPElcoeM4AAXwtv4Dc7sEKxkvNvwCYu4S04KOwC6bT CBS+ddsos27MIrJH5Hjok9ICC2CTXjReQKWYaSPDSjTOSubr4otHM3XgOZkAgEvrwwfs ScxpQKPTPX4yUfUF9U4beWfV+N9VymONIa1F3r4cD+baa+eK+Lz/AHkw9hEuB/v5Y0mO Y/oHiL85g62Fes56UrYF4r0fiW1GDSuulFEi2ulhtv6SDuWRPM45c65Ajpvndn7/hU9r BOFDbvrIwQ0q7fjLg+QW38w8Nsp6r9GmdkNZjw5EhDn5yyunmr709c02Ks4cIY/I9cvV HA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3530kaacnx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 08:09:11 -0500 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0ARCWoLa181744; Fri, 27 Nov 2020 08:09:11 -0500 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 3530kaacn1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 08:09:10 -0500 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0ARCSOvs024042; Fri, 27 Nov 2020 13:09:08 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma03fra.de.ibm.com with ESMTP id 352jgsh05c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 13:09:08 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0ARD6ZH144433898 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Nov 2020 13:06:36 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD5B34C05E; Fri, 27 Nov 2020 13:06:35 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 24C8F4C046; Fri, 27 Nov 2020 13:06:35 +0000 (GMT) Received: from linux01.pok.stglabs.ibm.com (unknown [9.114.17.81]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 27 Nov 2020 13:06:35 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: thuth@redhat.com, david@redhat.com, borntraeger@de.ibm.com, imbrenda@linux.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org Subject: [kvm-unit-tests PATCH v2 3/7] s390x: SCLP feature checking Date: Fri, 27 Nov 2020 08:06:25 -0500 Message-Id: <20201127130629.120469-4-frankja@linux.ibm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201127130629.120469-1-frankja@linux.ibm.com> References: <20201127130629.120469-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-27_06:2020-11-26,2020-11-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 lowpriorityscore=0 phishscore=0 mlxlogscore=999 suspectscore=1 spamscore=0 clxscore=1015 mlxscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011270076 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Availability of SIE is announced via a feature bit in a SCLP info CPU entry. Let's add a framework that allows us to easily check for such facilities. Signed-off-by: Janosch Frank Reviewed-by: Thomas Huth Reviewed-by: Cornelia Huck --- lib/s390x/io.c | 1 + lib/s390x/sclp.c | 19 +++++++++++++++++++ lib/s390x/sclp.h | 13 ++++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/s390x/io.c b/lib/s390x/io.c index e19a1f3..e843601 100644 --- a/lib/s390x/io.c +++ b/lib/s390x/io.c @@ -37,6 +37,7 @@ void setup(void) setup_args_progname(ipl_args); setup_facilities(); sclp_read_info(); + sclp_facilities_setup(); sclp_console_setup(); sclp_memory_setup(); smp_setup(); diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c index ff56c44..68833b5 100644 --- a/lib/s390x/sclp.c +++ b/lib/s390x/sclp.c @@ -11,6 +11,7 @@ */ #include +#include #include #include #include @@ -27,6 +28,7 @@ static uint64_t max_ram_size; static uint64_t ram_size; char _read_info[PAGE_SIZE] __attribute__((__aligned__(4096))); static ReadInfo *read_info; +struct sclp_facilities sclp_facilities; char _sccb[PAGE_SIZE] __attribute__((__aligned__(4096))); static volatile bool sclp_busy; @@ -128,6 +130,23 @@ CPUEntry *sclp_get_cpu_entries(void) return (void *)read_info + read_info->offset_cpu; } +void sclp_facilities_setup(void) +{ + unsigned short cpu0_addr = stap(); + CPUEntry *cpu; + int i; + + assert(read_info); + + cpu = (void *)read_info + read_info->offset_cpu; + for (i = 0; i < read_info->entries_cpu; i++, cpu++) { + if (cpu->address == cpu0_addr) { + sclp_facilities.has_sief2 = cpu->feat_sief2; + break; + } + } +} + /* Perform service call. Return 0 on success, non-zero otherwise. */ int sclp_service_call(unsigned int command, void *sccb) { diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h index 6620531..e18f7e6 100644 --- a/lib/s390x/sclp.h +++ b/lib/s390x/sclp.h @@ -95,12 +95,22 @@ typedef struct SCCBHeader { typedef struct CPUEntry { uint8_t address; uint8_t reserved0; - uint8_t features[SCCB_CPU_FEATURE_LEN]; + uint8_t : 4; + uint8_t feat_sief2 : 1; + uint8_t : 3; + uint8_t features_res2 [SCCB_CPU_FEATURE_LEN - 1]; uint8_t reserved2[6]; uint8_t type; uint8_t reserved1; } __attribute__((packed)) CPUEntry; +extern struct sclp_facilities sclp_facilities; + +struct sclp_facilities { + uint64_t has_sief2 : 1; + uint64_t : 63; +}; + typedef struct ReadInfo { SCCBHeader h; uint16_t rnmax; @@ -274,6 +284,7 @@ void sclp_print(const char *str); void sclp_read_info(void); int sclp_get_cpu_num(void); CPUEntry *sclp_get_cpu_entries(void); +void sclp_facilities_setup(void); int sclp_service_call(unsigned int command, void *sccb); void sclp_memory_setup(void); uint64_t get_ram_size(void); From patchwork Fri Nov 27 13:06:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 11936287 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF71AC64E75 for ; Fri, 27 Nov 2020 13:08:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6F7652225B for ; Fri, 27 Nov 2020 13:08:05 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="GCOhijU3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730064AbgK0NH7 (ORCPT ); Fri, 27 Nov 2020 08:07:59 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:2306 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730060AbgK0NH6 (ORCPT ); Fri, 27 Nov 2020 08:07:58 -0500 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0ARCo6oY126760; Fri, 27 Nov 2020 08:07:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=TjpqIpFT92oiZXjBwSIu2a2tuu65TkmNzn2630bO6eI=; b=GCOhijU3F9Ny8Y37KlpQfTYRyupvKsqg0cQ69NxM/1efv5NgRWjgzCxX1j7gJm4pJtT2 PUfElBOLqaIUpGFJpvjpUzKn4qZydjFV0KSgtZBtJb/61pHLfhg0+K1XhZWGjZsYUWim ZKMapAaMA2lmDbmsBfxY9coyME7YU/hhYhnxHZeGpcDoMPddcNRVE9++r+WnkGxTtPxn xxpFDE9RUb/a7gcmUF8lXJkYWHdHyCD53VTjxVPnBdUQErkSy4c4V3qOKUEXaZEil99Y Ku2W3XITvtggMOMSiXfkwwqZ/cLfxCzTswZEUlkGYuT4aFM5jC3HC04Jgi9wUyjtu8Cs 8A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3531tf0j8e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 08:07:56 -0500 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0ARCvX4h149805; Fri, 27 Nov 2020 08:07:56 -0500 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 3531tf0j7r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 08:07:56 -0500 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0ARCSOvk024042; Fri, 27 Nov 2020 13:07:54 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma03fra.de.ibm.com with ESMTP id 352jgsh03u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 13:07:54 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0ARD6aui9831020 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Nov 2020 13:06:37 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C74DB4C05E; Fri, 27 Nov 2020 13:06:36 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0FCAB4C052; Fri, 27 Nov 2020 13:06:36 +0000 (GMT) Received: from linux01.pok.stglabs.ibm.com (unknown [9.114.17.81]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 27 Nov 2020 13:06:35 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: thuth@redhat.com, david@redhat.com, borntraeger@de.ibm.com, imbrenda@linux.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org Subject: [kvm-unit-tests PATCH v2 4/7] s390x: sie: Add SIE to lib Date: Fri, 27 Nov 2020 08:06:26 -0500 Message-Id: <20201127130629.120469-5-frankja@linux.ibm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201127130629.120469-1-frankja@linux.ibm.com> References: <20201127130629.120469-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-27_06:2020-11-26,2020-11-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 adultscore=0 spamscore=0 malwarescore=0 mlxlogscore=906 lowpriorityscore=0 bulkscore=0 phishscore=0 mlxscore=0 suspectscore=1 clxscore=1015 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011270076 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This commit adds the definition of the SIE control block struct and the assembly to execute SIE and save/restore guest registers. Signed-off-by: Janosch Frank --- lib/s390x/asm-offsets.c | 13 +++ lib/s390x/asm/arch_def.h | 7 ++ lib/s390x/interrupt.c | 7 ++ lib/s390x/sie.h | 197 +++++++++++++++++++++++++++++++++++++++ s390x/cstart64.S | 56 +++++++++++ 5 files changed, 280 insertions(+) create mode 100644 lib/s390x/sie.h diff --git a/lib/s390x/asm-offsets.c b/lib/s390x/asm-offsets.c index 61d2658..1ebfc8f 100644 --- a/lib/s390x/asm-offsets.c +++ b/lib/s390x/asm-offsets.c @@ -10,6 +10,7 @@ #include #include #include +#include int main(void) { @@ -71,6 +72,18 @@ int main(void) OFFSET(GEN_LC_ARS_SA, lowcore, ars_sa); OFFSET(GEN_LC_CRS_SA, lowcore, crs_sa); OFFSET(GEN_LC_PGM_INT_TDB, lowcore, pgm_int_tdb); + OFFSET(__SF_GPRS, stack_frame, gprs); + OFFSET(__SF_SIE_CONTROL, stack_frame, empty1[0]); + OFFSET(__SF_SIE_SAVEAREA, stack_frame, empty1[1]); + OFFSET(__SF_SIE_REASON, stack_frame, empty1[2]); + OFFSET(__SF_SIE_FLAGS, stack_frame, empty1[3]); + OFFSET(SIE_SAVEAREA_HOST_GRS, vm_save_area, host.grs[0]); + OFFSET(SIE_SAVEAREA_HOST_FPRS, vm_save_area, host.fprs[0]); + OFFSET(SIE_SAVEAREA_HOST_FPC, vm_save_area, host.fpc); + OFFSET(SIE_SAVEAREA_GUEST_GRS, vm_save_area, guest.grs[0]); + OFFSET(SIE_SAVEAREA_GUEST_FPRS, vm_save_area, guest.fprs[0]); + OFFSET(SIE_SAVEAREA_GUEST_FPC, vm_save_area, guest.fpc); + return 0; } diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h index edc06ef..2cd3fc7 100644 --- a/lib/s390x/asm/arch_def.h +++ b/lib/s390x/asm/arch_def.h @@ -10,6 +10,13 @@ #ifndef _ASM_S390X_ARCH_DEF_H_ #define _ASM_S390X_ARCH_DEF_H_ +struct stack_frame { + unsigned long back_chain; + unsigned long empty1[5]; + unsigned long gprs[10]; + unsigned int empty2[8]; +}; + struct psw { uint64_t mask; uint64_t addr; diff --git a/lib/s390x/interrupt.c b/lib/s390x/interrupt.c index a074505..4b9a640 100644 --- a/lib/s390x/interrupt.c +++ b/lib/s390x/interrupt.c @@ -13,6 +13,7 @@ #include #include #include +#include static bool pgm_int_expected; static bool ext_int_expected; @@ -59,6 +60,12 @@ void register_pgm_cleanup_func(void (*f)(void)) static void fixup_pgm_int(void) { + /* If we have an error on SIE we directly move to sie_exit */ + if (lc->pgm_old_psw.addr >= (uint64_t)&sie_entry && + lc->pgm_old_psw.addr <= (uint64_t)&sie_entry + 10) { + lc->pgm_old_psw.addr = (uint64_t)&sie_exit; + } + switch (lc->pgm_int_code) { case PGM_INT_CODE_PRIVILEGED_OPERATION: /* Normal operation is in supervisor state, so this exception diff --git a/lib/s390x/sie.h b/lib/s390x/sie.h new file mode 100644 index 0000000..b00bdf4 --- /dev/null +++ b/lib/s390x/sie.h @@ -0,0 +1,197 @@ +#ifndef SIE_H +#define SIE_H + +#define CPUSTAT_STOPPED 0x80000000 +#define CPUSTAT_WAIT 0x10000000 +#define CPUSTAT_ECALL_PEND 0x08000000 +#define CPUSTAT_STOP_INT 0x04000000 +#define CPUSTAT_IO_INT 0x02000000 +#define CPUSTAT_EXT_INT 0x01000000 +#define CPUSTAT_RUNNING 0x00800000 +#define CPUSTAT_RETAINED 0x00400000 +#define CPUSTAT_TIMING_SUB 0x00020000 +#define CPUSTAT_SIE_SUB 0x00010000 +#define CPUSTAT_RRF 0x00008000 +#define CPUSTAT_SLSV 0x00004000 +#define CPUSTAT_SLSR 0x00002000 +#define CPUSTAT_ZARCH 0x00000800 +#define CPUSTAT_MCDS 0x00000100 +#define CPUSTAT_KSS 0x00000200 +#define CPUSTAT_SM 0x00000080 +#define CPUSTAT_IBS 0x00000040 +#define CPUSTAT_GED2 0x00000010 +#define CPUSTAT_G 0x00000008 +#define CPUSTAT_GED 0x00000004 +#define CPUSTAT_J 0x00000002 +#define CPUSTAT_P 0x00000001 + +struct kvm_s390_sie_block { + uint32_t cpuflags; /* 0x0000 */ + uint32_t : 1; /* 0x0004 */ + uint32_t prefix : 18; + uint32_t : 1; + uint32_t ibc : 12; + uint8_t reserved08[4]; /* 0x0008 */ +#define PROG_IN_SIE (1<<0) + uint32_t prog0c; /* 0x000c */ + uint8_t reserved10[16]; /* 0x0010 */ +#define PROG_BLOCK_SIE (1<<0) +#define PROG_REQUEST (1<<1) + uint32_t prog20; /* 0x0020 */ + uint8_t reserved24[4]; /* 0x0024 */ + uint64_t cputm; /* 0x0028 */ + uint64_t ckc; /* 0x0030 */ + uint64_t epoch; /* 0x0038 */ + uint32_t svcc; /* 0x0040 */ +#define LCTL_CR0 0x8000 +#define LCTL_CR6 0x0200 +#define LCTL_CR9 0x0040 +#define LCTL_CR10 0x0020 +#define LCTL_CR11 0x0010 +#define LCTL_CR14 0x0002 + uint16_t lctl; /* 0x0044 */ + int16_t icpua; /* 0x0046 */ +#define ICTL_OPEREXC 0x80000000 +#define ICTL_PINT 0x20000000 +#define ICTL_LPSW 0x00400000 +#define ICTL_STCTL 0x00040000 +#define ICTL_ISKE 0x00004000 +#define ICTL_SSKE 0x00002000 +#define ICTL_RRBE 0x00001000 +#define ICTL_TPROT 0x00000200 + uint32_t ictl; /* 0x0048 */ +#define ECA_CEI 0x80000000 +#define ECA_IB 0x40000000 +#define ECA_SIGPI 0x10000000 +#define ECA_MVPGI 0x01000000 +#define ECA_AIV 0x00200000 +#define ECA_VX 0x00020000 +#define ECA_PROTEXCI 0x00002000 +#define ECA_APIE 0x00000008 +#define ECA_SII 0x00000001 + uint32_t eca; /* 0x004c */ +#define ICPT_INST 0x04 +#define ICPT_PROGI 0x08 +#define ICPT_INSTPROGI 0x0C +#define ICPT_EXTREQ 0x10 +#define ICPT_EXTINT 0x14 +#define ICPT_IOREQ 0x18 +#define ICPT_WAIT 0x1c +#define ICPT_VALIDITY 0x20 +#define ICPT_STOP 0x28 +#define ICPT_OPEREXC 0x2C +#define ICPT_PARTEXEC 0x38 +#define ICPT_IOINST 0x40 +#define ICPT_KSS 0x5c + uint8_t icptcode; /* 0x0050 */ + uint8_t icptstatus; /* 0x0051 */ + uint16_t ihcpu; /* 0x0052 */ + uint8_t reserved54[2]; /* 0x0054 */ + uint16_t ipa; /* 0x0056 */ + uint32_t ipb; /* 0x0058 */ + uint32_t scaoh; /* 0x005c */ +#define FPF_BPBC 0x20 + uint8_t fpf; /* 0x0060 */ +#define ECB_GS 0x40 +#define ECB_TE 0x10 +#define ECB_SRSI 0x04 +#define ECB_HOSTPROTINT 0x02 + uint8_t ecb; /* 0x0061 */ +#define ECB2_CMMA 0x80 +#define ECB2_IEP 0x20 +#define ECB2_PFMFI 0x08 +#define ECB2_ESCA 0x04 + uint8_t ecb2; /* 0x0062 */ +#define ECB3_DEA 0x08 +#define ECB3_AES 0x04 +#define ECB3_RI 0x01 + uint8_t ecb3; /* 0x0063 */ + uint32_t scaol; /* 0x0064 */ + uint8_t reserved68; /* 0x0068 */ + uint8_t epdx; /* 0x0069 */ + uint8_t reserved6a[2]; /* 0x006a */ + uint32_t todpr; /* 0x006c */ +#define GISA_FORMAT1 0x00000001 + uint32_t gd; /* 0x0070 */ + uint8_t reserved74[12]; /* 0x0074 */ + uint64_t mso; /* 0x0080 */ + uint64_t msl; /* 0x0088 */ + struct psw gpsw; /* 0x0090 */ + uint64_t gg14; /* 0x00a0 */ + uint64_t gg15; /* 0x00a8 */ + uint8_t reservedb0[8]; /* 0x00b0 */ +#define HPID_KVM 0x4 +#define HPID_VSIE 0x5 + uint8_t hpid; /* 0x00b8 */ + uint8_t reservedb9[11]; /* 0x00b9 */ + uint16_t extcpuaddr; /* 0x00c4 */ + uint16_t eic; /* 0x00c6 */ + uint32_t reservedc8; /* 0x00c8 */ + uint16_t pgmilc; /* 0x00cc */ + uint16_t iprcc; /* 0x00ce */ + uint32_t dxc; /* 0x00d0 */ + uint16_t mcn; /* 0x00d4 */ + uint8_t perc; /* 0x00d6 */ + uint8_t peratmid; /* 0x00d7 */ + uint64_t peraddr; /* 0x00d8 */ + uint8_t eai; /* 0x00e0 */ + uint8_t peraid; /* 0x00e1 */ + uint8_t oai; /* 0x00e2 */ + uint8_t armid; /* 0x00e3 */ + uint8_t reservede4[4]; /* 0x00e4 */ + uint64_t tecmc; /* 0x00e8 */ + uint8_t reservedf0[12]; /* 0x00f0 */ +#define CRYCB_FORMAT_MASK 0x00000003 +#define CRYCB_FORMAT0 0x00000000 +#define CRYCB_FORMAT1 0x00000001 +#define CRYCB_FORMAT2 0x00000003 + uint32_t crycbd; /* 0x00fc */ + uint64_t gcr[16]; /* 0x0100 */ + uint64_t gbea; /* 0x0180 */ + uint8_t reserved188[8]; /* 0x0188 */ + uint64_t sdnxo; /* 0x0190 */ + uint8_t reserved198[8]; /* 0x0198 */ + uint32_t fac; /* 0x01a0 */ + uint8_t reserved1a4[20]; /* 0x01a4 */ + uint64_t cbrlo; /* 0x01b8 */ + uint8_t reserved1c0[8]; /* 0x01c0 */ +#define ECD_HOSTREGMGMT 0x20000000 +#define ECD_MEF 0x08000000 +#define ECD_ETOKENF 0x02000000 +#define ECD_ECC 0x00200000 + uint32_t ecd; /* 0x01c8 */ + uint8_t reserved1cc[18]; /* 0x01cc */ + uint64_t pp; /* 0x01de */ + uint8_t reserved1e6[2]; /* 0x01e6 */ + uint64_t itdba; /* 0x01e8 */ + uint64_t riccbd; /* 0x01f0 */ + uint64_t gvrd; /* 0x01f8 */ +} __attribute__((packed)); + +struct vm_save_regs { + u64 grs[16]; + u64 fprs[16]; + u32 fpc; +}; + +/* We might be able to nestle all of this into the stack frame. But + * having a dedicated save area that saves more than the s390 ELF ABI + * defines leaves us more freedom in the implementation. +*/ +struct vm_save_area { + struct vm_save_regs guest; + struct vm_save_regs host; +}; + +struct vm { + struct kvm_s390_sie_block *sblk; + struct vm_save_area save_area; + /* Ptr to first guest page */ + u8 *guest_mem; +}; + +extern u64 sie_entry; +extern u64 sie_exit; +extern void sie64a(struct kvm_s390_sie_block *sblk, struct vm_save_area *save_area); + +#endif /* SIE_H */ diff --git a/s390x/cstart64.S b/s390x/cstart64.S index 4e51150..2711018 100644 --- a/s390x/cstart64.S +++ b/s390x/cstart64.S @@ -203,6 +203,62 @@ smp_cpu_setup_state: /* If the function returns, just loop here */ 0: j 0 +/* + * sie64a calling convention: + * %r2 pointer to sie control block + * %r3 guest register save area + */ +.globl sie64a +sie64a: + # Save host grs, fprs, fpc + stmg %r0,%r14,SIE_SAVEAREA_HOST_GRS(%r3) # save kernel registers + .irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 + std \i, \i * 8 + SIE_SAVEAREA_HOST_FPRS(%r3) + .endr + stfpc SIE_SAVEAREA_HOST_FPC(%r3) + + # Store scb and save_area pointer into stack frame + stg %r2,__SF_SIE_CONTROL(%r15) # save control block pointer + stg %r3,__SF_SIE_SAVEAREA(%r15) # save guest register save area + + # Load guest's gprs, fprs and fpc + lmg %r0,%r13,SIE_SAVEAREA_GUEST_GRS(%r3) + .irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 + ld \i, \i * 8 + SIE_SAVEAREA_GUEST_FPRS(%r3) + .endr + lfpc SIE_SAVEAREA_GUEST_FPC(%r3) + + # Move scb ptr into r14 for the sie instruction + lg %r14,__SF_SIE_CONTROL(%r15) + +.globl sie_entry +sie_entry: + sie 0(%r14) + nopr 7 + nopr 7 + nopr 7 + +.globl sie_exit +sie_exit: + # Load guest register save area + lg %r14,__SF_SIE_SAVEAREA(%r15) + + # Store guest's gprs, fprs and fpc + stmg %r0,%r13,SIE_SAVEAREA_GUEST_GRS(%r14) # save guest gprs 0-13 + .irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 + std \i, \i * 8 + SIE_SAVEAREA_GUEST_FPRS(%r14) + .endr + stfpc SIE_SAVEAREA_GUEST_FPC(%r14) + + # Restore host's gprs, fprs and fpc + .irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 + ld \i, \i * 8 + SIE_SAVEAREA_HOST_FPRS(%r14) + .endr + lfpc SIE_SAVEAREA_HOST_FPC(%r14) + lmg %r0,%r14,SIE_SAVEAREA_HOST_GRS(%r14) # restore kernel registers + + br %r14 + pgm_int: SAVE_REGS brasl %r14, handle_pgm_int From patchwork Fri Nov 27 13:06:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 11936285 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89C3CC63798 for ; Fri, 27 Nov 2020 13:06:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4869220B80 for ; Fri, 27 Nov 2020 13:06:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="qUILGXGf" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729989AbgK0NGo (ORCPT ); Fri, 27 Nov 2020 08:06:44 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:24766 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729913AbgK0NGn (ORCPT ); Fri, 27 Nov 2020 08:06:43 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0ARCWU4g077744; Fri, 27 Nov 2020 08:06:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=TZb3+25OYPpC7CLJUMjw3gAGF4D7izfHewrWqwJu1Yg=; b=qUILGXGfk9m+tD7n+KpY2Wt0XLdfwcdpwg38v+C0qrRzZ76JPJ5Uau68x9g8i04GaMu/ ZBHeZCrPcOpIU0IKcZKQS3wQEcDPhvKMedL8pH60g31W75EkXiIu8Jf/Mzl6hZL3T9Ny ZJLiatVg39P03/qa4tKXxcz4MbKr/As8r+01v7PsjfsRyX6WtG+cbG3uU0GQEF8i+653 s/zzyaZYQ0gkWrY3wbp0KqyaJ+iF5W9L4w7e0GRBzOV5oRUyVHrrYHw4Wbr6csW3lztk JjyvbdKUYgvqiMCdfYq6oq6zJYIO/A9cvrqPqHhcwPseRwuJhS1av4fHQKOce3TqJSai 4g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 352y6ud17u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 08:06:43 -0500 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0ARCXqkJ082005; Fri, 27 Nov 2020 08:06:42 -0500 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 352y6ud172-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 08:06:42 -0500 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0ARCRJXv028518; Fri, 27 Nov 2020 13:06:40 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma06ams.nl.ibm.com with ESMTP id 352kgk8mq7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 13:06:40 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0ARD6bQB39518700 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Nov 2020 13:06:37 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B260D4C046; Fri, 27 Nov 2020 13:06:37 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EE2984C071; Fri, 27 Nov 2020 13:06:36 +0000 (GMT) Received: from linux01.pok.stglabs.ibm.com (unknown [9.114.17.81]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 27 Nov 2020 13:06:36 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: thuth@redhat.com, david@redhat.com, borntraeger@de.ibm.com, imbrenda@linux.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org Subject: [kvm-unit-tests PATCH v2 5/7] s390x: sie: Add first SIE test Date: Fri, 27 Nov 2020 08:06:27 -0500 Message-Id: <20201127130629.120469-6-frankja@linux.ibm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201127130629.120469-1-frankja@linux.ibm.com> References: <20201127130629.120469-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-27_06:2020-11-26,2020-11-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 impostorscore=0 malwarescore=0 suspectscore=1 mlxscore=0 phishscore=0 priorityscore=1501 clxscore=1015 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011270076 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Let's check if we get the correct interception data on a few diags. This commit is more of an addition of boilerplate code than a real test. Signed-off-by: Janosch Frank --- s390x/Makefile | 1 + s390x/sie.c | 125 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 3 ++ 3 files changed, 129 insertions(+) create mode 100644 s390x/sie.c diff --git a/s390x/Makefile b/s390x/Makefile index b079a26..7a95092 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -19,6 +19,7 @@ tests += $(TEST_DIR)/smp.elf tests += $(TEST_DIR)/sclp.elf tests += $(TEST_DIR)/css.elf tests += $(TEST_DIR)/uv-guest.elf +tests += $(TEST_DIR)/sie.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) ifneq ($(HOST_KEY_DOCUMENT),) diff --git a/s390x/sie.c b/s390x/sie.c new file mode 100644 index 0000000..41b429a --- /dev/null +++ b/s390x/sie.c @@ -0,0 +1,125 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static u8 *guest; +static u8 *guest_instr; +static struct vm vm; + +static void handle_validity(struct vm *vm) +{ + report(0, "VALIDITY: %x", vm->sblk->ipb >> 16); +} + +static void sie(struct vm *vm) +{ + while (vm->sblk->icptcode == 0) { + sie64a(vm->sblk, &vm->save_area); + if (vm->sblk->icptcode == 32) + handle_validity(vm); + } + vm->save_area.guest.grs[14] = vm->sblk->gg14; + vm->save_area.guest.grs[15] = vm->sblk->gg15; +} + +static void sblk_cleanup(struct vm *vm) +{ + vm->sblk->icptcode = 0; +} + +static void intercept_diag_10(void) +{ + u32 instr = 0x83020010; + + vm.sblk->gpsw.addr = PAGE_SIZE * 2; + vm.sblk->gpsw.mask = 0x0000000180000000ULL; + + memset(guest_instr, 0, PAGE_SIZE); + memcpy(guest_instr, &instr, 4); + sie(&vm); + report(vm.sblk->icptcode == 4 && vm.sblk->ipa == 0x8302 && vm.sblk->ipb == 0x100000, + "Diag 10 intercept"); + sblk_cleanup(&vm); +} + +static void intercept_diag_44(void) +{ + u32 instr = 0x83020044; + + vm.sblk->gpsw.addr = PAGE_SIZE * 2; + vm.sblk->gpsw.mask = 0x0000000180000000ULL; + + memset(guest_instr, 0, PAGE_SIZE); + memcpy(guest_instr, &instr, 4); + sie(&vm); + report(vm.sblk->icptcode == 4 && vm.sblk->ipa == 0x8302 && vm.sblk->ipb == 0x440000, + "Diag 44 intercept"); + sblk_cleanup(&vm); +} + +static void intercept_diag_9c(void) +{ + u32 instr = 0x8302009c; + + vm.sblk->gpsw.addr = PAGE_SIZE * 2; + vm.sblk->gpsw.mask = 0x0000000180000000ULL; + + memset(guest_instr, 0, PAGE_SIZE); + memcpy(guest_instr, &instr, 4); + sie(&vm); + report(vm.sblk->icptcode == 4 && vm.sblk->ipa == 0x8302 && vm.sblk->ipb == 0x9c0000, + "Diag 9c intercept"); + sblk_cleanup(&vm); +} + +static void setup_guest(void) +{ + setup_vm(); + + /* Allocate 1MB as guest memory */ + guest = alloc_pages(8); + /* The first two pages are the lowcore */ + guest_instr = guest + PAGE_SIZE * 2; + + vm.sblk = alloc_page(); + + vm.sblk->cpuflags = CPUSTAT_ZARCH | CPUSTAT_RUNNING; + vm.sblk->prefix = 0; + /* + * Pageable guest with the same ASCE as the test programm, but + * the guest memory 0x0 is offset to start at the allocated + * guest pages and end after 1MB. + * + * It's not pretty but faster and easier than managing guest ASCEs. + */ + vm.sblk->mso = (u64)guest; + vm.sblk->msl = (u64)guest; + vm.sblk->ihcpu = 0xffff; + + vm.sblk->crycbd = (uint64_t)alloc_page(); +} + +int main(void) +{ + report_prefix_push("sie"); + if (!sclp_facilities.has_sief2) { + report_skip("SIEF2 facility unavailable"); + goto done; + } + + setup_guest(); + intercept_diag_10(); + intercept_diag_44(); + intercept_diag_9c(); +done: + report_prefix_pop(); + return report_summary(); +} diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index 3feb8bc..2298be6 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -96,3 +96,6 @@ smp = 2 [uv-guest] file = uv-guest.elf + +[sie] +file = sie.elf From patchwork Fri Nov 27 13:06:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 11936281 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E32C6C64E7C for ; Fri, 27 Nov 2020 13:06:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A065F20B80 for ; Fri, 27 Nov 2020 13:06:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="En2zJeHb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730008AbgK0NGr (ORCPT ); Fri, 27 Nov 2020 08:06:47 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:49862 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729991AbgK0NGr (ORCPT ); Fri, 27 Nov 2020 08:06:47 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0ARCWUT2077747; Fri, 27 Nov 2020 08:06:46 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=otOPIVL6wXaFKs7fAhnMzKLeGNNpFhm5Si9btVRI3zI=; b=En2zJeHb05lPw0/bJqmGX9F9nPLOwu/v/O9PYtX17e27KL8u1D7fwTj5yF7qhoCWnoDc 7LW3yi/it9x2nx96aQpGIw26s7VLfmhukOH1YtEvXEFWjdMffbxQPaa5rbvU5BhGy90A TIOh4DzfKxHd+v6Nkb2Mg5Efol5DpouvKgqSce2ZVTVtKNfsbzG/2gxBAxwy3Da5zRdz CxP8FI+QjgfhaT/rx21RZSVAwYrur1hMQUpvMuC9jA7WhMWwRpO5GhIHwFvYqvKbqY/2 L+6W7odaAL6PJlXX/Ll2dTmXNJbA6yafcliVVY2Tj9d0apuimcnTTOb1Gc+8xun1Ed0Z lQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 352y6ud191-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 08:06:46 -0500 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0ARCmeg9130634; Fri, 27 Nov 2020 08:06:46 -0500 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 352y6ud17d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 08:06:46 -0500 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0ARCRgAg028933; Fri, 27 Nov 2020 13:06:41 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma06ams.nl.ibm.com with ESMTP id 352kgk8mq8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 13:06:41 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0ARD6cKU63963582 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Nov 2020 13:06:38 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9C4AC4C046; Fri, 27 Nov 2020 13:06:38 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D93044C063; Fri, 27 Nov 2020 13:06:37 +0000 (GMT) Received: from linux01.pok.stglabs.ibm.com (unknown [9.114.17.81]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 27 Nov 2020 13:06:37 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: thuth@redhat.com, david@redhat.com, borntraeger@de.ibm.com, imbrenda@linux.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org Subject: [kvm-unit-tests PATCH v2 6/7] s390x: Add diag318 intercept test Date: Fri, 27 Nov 2020 08:06:28 -0500 Message-Id: <20201127130629.120469-7-frankja@linux.ibm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201127130629.120469-1-frankja@linux.ibm.com> References: <20201127130629.120469-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-27_06:2020-11-26,2020-11-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 lowpriorityscore=0 adultscore=0 spamscore=0 impostorscore=0 malwarescore=0 suspectscore=1 mlxscore=0 phishscore=0 priorityscore=1501 clxscore=1015 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011270076 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Not much to test except for the privilege and specification exceptions. Signed-off-by: Janosch Frank Reviewed-by: Thomas Huth Reviewed-by: Cornelia Huck --- lib/s390x/sclp.c | 2 ++ lib/s390x/sclp.h | 6 +++++- s390x/intercept.c | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c index 68833b5..3966086 100644 --- a/lib/s390x/sclp.c +++ b/lib/s390x/sclp.c @@ -138,6 +138,8 @@ void sclp_facilities_setup(void) assert(read_info); + sclp_facilities.has_diag318 = read_info->byte_134_diag318; + cpu = (void *)read_info + read_info->offset_cpu; for (i = 0; i < read_info->entries_cpu; i++, cpu++) { if (cpu->address == cpu0_addr) { diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h index e18f7e6..4e564dd 100644 --- a/lib/s390x/sclp.h +++ b/lib/s390x/sclp.h @@ -108,7 +108,8 @@ extern struct sclp_facilities sclp_facilities; struct sclp_facilities { uint64_t has_sief2 : 1; - uint64_t : 63; + uint64_t has_diag318 : 1; + uint64_t : 62; }; typedef struct ReadInfo { @@ -133,6 +134,9 @@ typedef struct ReadInfo { uint16_t highest_cpu; uint8_t _reserved5[124 - 122]; /* 122-123 */ uint32_t hmfai; + uint8_t reserved7[134 - 128]; + uint8_t byte_134_diag318 : 1; + uint8_t : 7; struct CPUEntry entries[0]; } __attribute__((packed)) ReadInfo; diff --git a/s390x/intercept.c b/s390x/intercept.c index 2e38257..615f0a0 100644 --- a/s390x/intercept.c +++ b/s390x/intercept.c @@ -10,6 +10,7 @@ * under the terms of the GNU Library General Public License version 2. */ #include +#include #include #include #include @@ -154,6 +155,23 @@ static void test_testblock(void) check_pgm_int_code(PGM_INT_CODE_ADDRESSING); } +static void test_diag318(void) +{ + expect_pgm_int(); + enter_pstate(); + asm volatile("diag %0,0,0x318\n" : : "d" (0x42)); + check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION); + + if (!sclp_facilities.has_diag318) + expect_pgm_int(); + + asm volatile("diag %0,0,0x318\n" : : "d" (0x42)); + + if (!sclp_facilities.has_diag318) + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + +} + struct { const char *name; void (*func)(void); @@ -164,6 +182,7 @@ struct { { "stap", test_stap, false }, { "stidp", test_stidp, false }, { "testblock", test_testblock, false }, + { "diag318", test_diag318, false }, { NULL, NULL, false } }; From patchwork Fri Nov 27 13:06:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 11936283 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAE17C64E7A for ; Fri, 27 Nov 2020 13:06:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7605821D7A for ; Fri, 27 Nov 2020 13:06:56 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="pP/8Vhg4" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730001AbgK0NGr (ORCPT ); Fri, 27 Nov 2020 08:06:47 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:62784 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729913AbgK0NGq (ORCPT ); Fri, 27 Nov 2020 08:06:46 -0500 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0ARCXS2Z157483; Fri, 27 Nov 2020 08:06:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=psnrGpvE5+ZfvWd0iHip9AuUYAu4ouSuW6RdDCK4JcQ=; b=pP/8Vhg4hfXZSMx+MCLsCBzsocQU35/u6LSl6YUi+RPN6tk17bpiuOF6Y/hleZU60KO0 UF6p3sFunPrsAlngd4UjBN3KRZ3yWsBwdo1H3XfzNxInAF3tHX/orBRcrilvMTnH5Dhf P+EFc0Im708NHt2JFndb2Rl3dRZZD+K+eXMdhN/Cl9fV+Dfm+CM7n7Jp7v+3+oO2j34b JG0UABpTYElaIzsktKF7GZPPFGv9M+hjtxIn4nrkohgSgitXErljutFpErvMddxxgjDT J61CQOTuZl6AXXHmOneUfKeg/UVYJQCDNGwxQVOcRzFLBjXIef6IyoT/zsR6UWUFWmUY JQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 352wxxy1v2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 08:06:44 -0500 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 0ARCXpFY158940; Fri, 27 Nov 2020 08:06:44 -0500 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com with ESMTP id 352wxxy1ub-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 08:06:44 -0500 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 0ARCRLVE028523; Fri, 27 Nov 2020 13:06:42 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma06ams.nl.ibm.com with ESMTP id 352kgk8mq9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Nov 2020 13:06:42 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 0ARD6duo61211134 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Nov 2020 13:06:39 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 87F424C04A; Fri, 27 Nov 2020 13:06:39 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C46364C046; Fri, 27 Nov 2020 13:06:38 +0000 (GMT) Received: from linux01.pok.stglabs.ibm.com (unknown [9.114.17.81]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 27 Nov 2020 13:06:38 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: thuth@redhat.com, david@redhat.com, borntraeger@de.ibm.com, imbrenda@linux.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org Subject: [kvm-unit-tests PATCH v2 7/7] s390x: Fix sclp.h style issues Date: Fri, 27 Nov 2020 08:06:29 -0500 Message-Id: <20201127130629.120469-8-frankja@linux.ibm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201127130629.120469-1-frankja@linux.ibm.com> References: <20201127130629.120469-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.312,18.0.737 definitions=2020-11-27_06:2020-11-26,2020-11-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 priorityscore=1501 suspectscore=1 phishscore=0 malwarescore=0 mlxlogscore=999 impostorscore=0 adultscore=0 lowpriorityscore=0 bulkscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2011270078 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Fix indentation Signed-off-by: Janosch Frank Acked-by: Thomas Huth Reviewed-by: Cornelia Huck --- lib/s390x/sclp.h | 172 +++++++++++++++++++++++------------------------ 1 file changed, 86 insertions(+), 86 deletions(-) diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h index 4e564dd..dd01f03 100644 --- a/lib/s390x/sclp.h +++ b/lib/s390x/sclp.h @@ -82,10 +82,10 @@ #define SCCB_SIZE 4096 typedef struct SCCBHeader { - uint16_t length; - uint8_t function_code; - uint8_t control_mask[3]; - uint16_t response_code; + uint16_t length; + uint8_t function_code; + uint8_t control_mask[3]; + uint16_t response_code; } __attribute__((packed)) SCCBHeader; #define SCCB_DATA_LEN (SCCB_SIZE - sizeof(SCCBHeader)) @@ -93,15 +93,15 @@ typedef struct SCCBHeader { /* CPU information */ typedef struct CPUEntry { - uint8_t address; - uint8_t reserved0; - uint8_t : 4; - uint8_t feat_sief2 : 1; - uint8_t : 3; - uint8_t features_res2 [SCCB_CPU_FEATURE_LEN - 1]; - uint8_t reserved2[6]; - uint8_t type; - uint8_t reserved1; + uint8_t address; + uint8_t reserved0; + uint8_t : 4; + uint8_t feat_sief2 : 1; + uint8_t : 3; + uint8_t features_res2 [SCCB_CPU_FEATURE_LEN - 1]; + uint8_t reserved2[6]; + uint8_t type; + uint8_t reserved1; } __attribute__((packed)) CPUEntry; extern struct sclp_facilities sclp_facilities; @@ -113,77 +113,77 @@ struct sclp_facilities { }; typedef struct ReadInfo { - SCCBHeader h; - uint16_t rnmax; - uint8_t rnsize; - uint8_t _reserved1[16 - 11]; /* 11-15 */ - uint16_t entries_cpu; /* 16-17 */ - uint16_t offset_cpu; /* 18-19 */ - uint8_t _reserved2[24 - 20]; /* 20-23 */ - uint8_t loadparm[8]; /* 24-31 */ - uint8_t _reserved3[48 - 32]; /* 32-47 */ - uint64_t facilities; /* 48-55 */ - uint8_t _reserved0[76 - 56]; /* 56-75 */ - uint32_t ibc_val; - uint8_t conf_char[99 - 80]; /* 80-98 */ - uint8_t mha_pow; - uint32_t rnsize2; - uint64_t rnmax2; - uint8_t _reserved6[116 - 112]; /* 112-115 */ - uint8_t conf_char_ext[120 - 116]; /* 116-119 */ - uint16_t highest_cpu; - uint8_t _reserved5[124 - 122]; /* 122-123 */ - uint32_t hmfai; - uint8_t reserved7[134 - 128]; - uint8_t byte_134_diag318 : 1; - uint8_t : 7; - struct CPUEntry entries[0]; + SCCBHeader h; + uint16_t rnmax; + uint8_t rnsize; + uint8_t _reserved1[16 - 11]; /* 11-15 */ + uint16_t entries_cpu; /* 16-17 */ + uint16_t offset_cpu; /* 18-19 */ + uint8_t _reserved2[24 - 20]; /* 20-23 */ + uint8_t loadparm[8]; /* 24-31 */ + uint8_t _reserved3[48 - 32]; /* 32-47 */ + uint64_t facilities; /* 48-55 */ + uint8_t _reserved0[76 - 56]; /* 56-75 */ + uint32_t ibc_val; + uint8_t conf_char[99 - 80]; /* 80-98 */ + uint8_t mha_pow; + uint32_t rnsize2; + uint64_t rnmax2; + uint8_t _reserved6[116 - 112]; /* 112-115 */ + uint8_t conf_char_ext[120 - 116]; /* 116-119 */ + uint16_t highest_cpu; + uint8_t _reserved5[124 - 122]; /* 122-123 */ + uint32_t hmfai; + uint8_t reserved7[134 - 128]; + uint8_t byte_134_diag318 : 1; + uint8_t : 7; + struct CPUEntry entries[0]; } __attribute__((packed)) ReadInfo; typedef struct ReadCpuInfo { - SCCBHeader h; - uint16_t nr_configured; /* 8-9 */ - uint16_t offset_configured; /* 10-11 */ - uint16_t nr_standby; /* 12-13 */ - uint16_t offset_standby; /* 14-15 */ - uint8_t reserved0[24-16]; /* 16-23 */ - struct CPUEntry entries[0]; + SCCBHeader h; + uint16_t nr_configured; /* 8-9 */ + uint16_t offset_configured; /* 10-11 */ + uint16_t nr_standby; /* 12-13 */ + uint16_t offset_standby; /* 14-15 */ + uint8_t reserved0[24-16]; /* 16-23 */ + struct CPUEntry entries[0]; } __attribute__((packed)) ReadCpuInfo; typedef struct ReadStorageElementInfo { - SCCBHeader h; - uint16_t max_id; - uint16_t assigned; - uint16_t standby; - uint8_t _reserved0[16 - 14]; /* 14-15 */ - uint32_t entries[0]; + SCCBHeader h; + uint16_t max_id; + uint16_t assigned; + uint16_t standby; + uint8_t _reserved0[16 - 14]; /* 14-15 */ + uint32_t entries[0]; } __attribute__((packed)) ReadStorageElementInfo; typedef struct AttachStorageElement { - SCCBHeader h; - uint8_t _reserved0[10 - 8]; /* 8-9 */ - uint16_t assigned; - uint8_t _reserved1[16 - 12]; /* 12-15 */ - uint32_t entries[0]; + SCCBHeader h; + uint8_t _reserved0[10 - 8]; /* 8-9 */ + uint16_t assigned; + uint8_t _reserved1[16 - 12]; /* 12-15 */ + uint32_t entries[0]; } __attribute__((packed)) AttachStorageElement; typedef struct AssignStorage { - SCCBHeader h; - uint16_t rn; + SCCBHeader h; + uint16_t rn; } __attribute__((packed)) AssignStorage; typedef struct IoaCfgSccb { - SCCBHeader header; - uint8_t atype; - uint8_t reserved1; - uint16_t reserved2; - uint32_t aid; + SCCBHeader header; + uint8_t atype; + uint8_t reserved1; + uint16_t reserved2; + uint32_t aid; } __attribute__((packed)) IoaCfgSccb; typedef struct SCCB { - SCCBHeader h; - char data[SCCB_DATA_LEN]; - } __attribute__((packed)) SCCB; + SCCBHeader h; + char data[SCCB_DATA_LEN]; +} __attribute__((packed)) SCCB; /* SCLP event types */ #define SCLP_EVENT_ASCII_CONSOLE_DATA 0x1a @@ -198,13 +198,13 @@ typedef struct SCCB { #define SCLP_SELECTIVE_READ 0x01 typedef struct WriteEventMask { - SCCBHeader h; - uint16_t _reserved; - uint16_t mask_length; - uint32_t cp_receive_mask; - uint32_t cp_send_mask; - uint32_t send_mask; - uint32_t receive_mask; + SCCBHeader h; + uint16_t _reserved; + uint16_t mask_length; + uint32_t cp_receive_mask; + uint32_t cp_send_mask; + uint32_t send_mask; + uint32_t receive_mask; } __attribute__((packed)) WriteEventMask; #define MDBTYP_GO 0x0001 @@ -257,25 +257,25 @@ struct mdb { } __attribute__((packed)); typedef struct EventBufferHeader { - uint16_t length; - uint8_t type; - uint8_t flags; - uint16_t _reserved; + uint16_t length; + uint8_t type; + uint8_t flags; + uint16_t _reserved; } __attribute__((packed)) EventBufferHeader; typedef struct WriteEventData { - SCCBHeader h; - EventBufferHeader ebh; - union { - char data[0]; - struct mdb mdb; - } msg; + SCCBHeader h; + EventBufferHeader ebh; + union { + char data[0]; + struct mdb mdb; + } msg; } __attribute__((packed)) WriteEventData; typedef struct ReadEventData { - SCCBHeader h; - EventBufferHeader ebh; - uint32_t mask; + SCCBHeader h; + EventBufferHeader ebh; + uint32_t mask; } __attribute__((packed)) ReadEventData; extern char _sccb[];