From patchwork Wed Dec 5 15:39:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 10714443 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 92D46109C for ; Wed, 5 Dec 2018 15:41:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 830862D668 for ; Wed, 5 Dec 2018 15:41:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8154A2D66C; Wed, 5 Dec 2018 15:41:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D922C2D668 for ; Wed, 5 Dec 2018 15:40:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727309AbeLEPk6 (ORCPT ); Wed, 5 Dec 2018 10:40:58 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:34260 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728237AbeLEPk4 (ORCPT ); Wed, 5 Dec 2018 10:40:56 -0500 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wB5Fe97Q078565 for ; Wed, 5 Dec 2018 10:40:55 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2p6e3jb8re-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 05 Dec 2018 10:40:55 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 5 Dec 2018 15:40:53 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 5 Dec 2018 15:40:50 -0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wB5FenTt51577076 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 5 Dec 2018 15:40:49 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 389CDA405F; Wed, 5 Dec 2018 15:40:49 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 06E1EA405C; Wed, 5 Dec 2018 15:40:49 +0000 (GMT) Received: from s38lp20.lnxne.boe (unknown [9.152.224.44]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 5 Dec 2018 15:40:48 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, david@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH v2 1/6] s390x: Cleanup sclp-ascii.c and add sigp order definitions Date: Wed, 5 Dec 2018 16:39:13 +0100 X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181205153918.29480-1-frankja@linux.ibm.com> References: <20181205153918.29480-1-frankja@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18120515-0012-0000-0000-000002D4FFF6 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18120515-0013-0000-0000-0000210A6171 Message-Id: <20181205153918.29480-2-frankja@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-12-05_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812050139 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Let's fix sclp-ascii.c indentation and rename it to sclp-console.c Also adding sigp order codes to remove magic numbers from io.c. Signed-off-by: Janosch Frank Reviewed-by: David Hildenbrand Reviewed-by: Thomas Huth --- lib/s390x/asm/arch_def.h | 18 ++++++++++++++ lib/s390x/io.c | 5 ++-- lib/s390x/{sclp-ascii.c => sclp-console.c} | 38 +++++++++++++++--------------- lib/s390x/sclp.h | 2 +- s390x/Makefile | 2 +- 5 files changed, 42 insertions(+), 23 deletions(-) rename lib/s390x/{sclp-ascii.c => sclp-console.c} (54%) diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h index d2cd727..d2d6e02 100644 --- a/lib/s390x/asm/arch_def.h +++ b/lib/s390x/asm/arch_def.h @@ -10,6 +10,24 @@ #ifndef _ASM_S390X_ARCH_DEF_H_ #define _ASM_S390X_ARCH_DEF_H_ +/* SIGP order codes */ +#define SIGP_SENSE 1 +#define SIGP_EXTERNAL_CALL 2 +#define SIGP_EMERGENCY_SIGNAL 3 +#define SIGP_START 4 +#define SIGP_STOP 5 +#define SIGP_RESTART 6 +#define SIGP_STOP_AND_STORE_STATUS 9 +#define SIGP_INITIAL_CPU_RESET 11 +#define SIGP_CPU_RESET 12 +#define SIGP_SET_PREFIX 13 +#define SIGP_STORE_STATUS_AT_ADDRESS 14 +#define SIGP_SET_ARCHITECTURE 18 +#define SIGP_COND_EMERGENCY_SIGNAL 19 +#define SIGP_SENSE_RUNNING 21 +#define SIGP_SET_MULTI_THREADING 22 +#define SIGP_STORE_ADDITIONAL_STATUS 23 + struct psw { uint64_t mask; uint64_t addr; diff --git a/lib/s390x/io.c b/lib/s390x/io.c index 7bca637..05a0765 100644 --- a/lib/s390x/io.c +++ b/lib/s390x/io.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "sclp.h" extern char ipl_args[]; @@ -37,14 +38,14 @@ static void sigp_stop(void) asm volatile( " sigp %0,%1,0(%2)\n" - : "+d" (status) : "d" (cpu), "d" (5) : "cc"); + : "+d" (status) : "d" (cpu), "d" (SIGP_STOP) : "cc"); } void setup(void) { setup_args_progname(ipl_args); setup_facilities(); - sclp_ascii_setup(); + sclp_console_setup(); sclp_memory_setup(); } diff --git a/lib/s390x/sclp-ascii.c b/lib/s390x/sclp-console.c similarity index 54% rename from lib/s390x/sclp-ascii.c rename to lib/s390x/sclp-console.c index 893ca17..deacbde 100644 --- a/lib/s390x/sclp-ascii.c +++ b/lib/s390x/sclp-console.c @@ -35,34 +35,34 @@ int sclp_service_call(unsigned int command, void *sccb) static void sclp_set_write_mask(void) { - WriteEventMask *sccb = (void *)_sccb; + WriteEventMask *sccb = (void *)_sccb; - sccb->h.length = sizeof(WriteEventMask); - sccb->mask_length = sizeof(unsigned int); - sccb->receive_mask = SCLP_EVENT_MASK_MSG_ASCII; - sccb->cp_receive_mask = SCLP_EVENT_MASK_MSG_ASCII; - sccb->send_mask = SCLP_EVENT_MASK_MSG_ASCII; - sccb->cp_send_mask = SCLP_EVENT_MASK_MSG_ASCII; + sccb->h.length = sizeof(WriteEventMask); + sccb->mask_length = sizeof(unsigned int); + sccb->receive_mask = SCLP_EVENT_MASK_MSG_ASCII; + sccb->cp_receive_mask = SCLP_EVENT_MASK_MSG_ASCII; + sccb->send_mask = SCLP_EVENT_MASK_MSG_ASCII; + sccb->cp_send_mask = SCLP_EVENT_MASK_MSG_ASCII; - sclp_service_call(SCLP_CMD_WRITE_EVENT_MASK, sccb); + sclp_service_call(SCLP_CMD_WRITE_EVENT_MASK, sccb); } -void sclp_ascii_setup(void) +void sclp_console_setup(void) { - sclp_set_write_mask(); + sclp_set_write_mask(); } void sclp_print(const char *str) { - int len = strlen(str); - WriteEventData *sccb = (void *)_sccb; + int len = strlen(str); + WriteEventData *sccb = (void *)_sccb; - sccb->h.length = sizeof(WriteEventData) + len; - sccb->h.function_code = SCLP_FC_NORMAL_WRITE; - sccb->ebh.length = sizeof(EventBufferHeader) + len; - sccb->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA; - sccb->ebh.flags = 0; - memcpy(sccb->data, str, len); + sccb->h.length = sizeof(WriteEventData) + len; + sccb->h.function_code = SCLP_FC_NORMAL_WRITE; + sccb->ebh.length = sizeof(EventBufferHeader) + len; + sccb->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA; + sccb->ebh.flags = 0; + memcpy(sccb->data, str, len); - sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb); + sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb); } diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h index 21d482b..e008932 100644 --- a/lib/s390x/sclp.h +++ b/lib/s390x/sclp.h @@ -207,7 +207,7 @@ typedef struct ReadEventData { uint32_t mask; } __attribute__((packed)) ReadEventData; -void sclp_ascii_setup(void); +void sclp_console_setup(void); void sclp_print(const char *str); extern char _sccb[]; int sclp_service_call(unsigned int command, void *sccb); diff --git a/s390x/Makefile b/s390x/Makefile index 8ba2b92..ede2961 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -38,7 +38,7 @@ cflatobjs += lib/alloc_phys.o cflatobjs += lib/s390x/io.o cflatobjs += lib/s390x/stack.o cflatobjs += lib/s390x/sclp.o -cflatobjs += lib/s390x/sclp-ascii.o +cflatobjs += lib/s390x/sclp-console.o cflatobjs += lib/s390x/interrupt.o cflatobjs += lib/s390x/mmu.o From patchwork Wed Dec 5 15:39:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 10714455 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E8501731 for ; Wed, 5 Dec 2018 15:41:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EF052D64E for ; Wed, 5 Dec 2018 15:41:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D3392D624; Wed, 5 Dec 2018 15:41:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EA61B2D651 for ; Wed, 5 Dec 2018 15:41:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728302AbeLEPlI (ORCPT ); Wed, 5 Dec 2018 10:41:08 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:45766 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728241AbeLEPk6 (ORCPT ); Wed, 5 Dec 2018 10:40:58 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wB5FdBQB049739 for ; Wed, 5 Dec 2018 10:40:57 -0500 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0b-001b2d01.pphosted.com with ESMTP id 2p6g73cys1-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 05 Dec 2018 10:40:56 -0500 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 5 Dec 2018 15:40:54 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 5 Dec 2018 15:40:51 -0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wB5FeoT659244716 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 5 Dec 2018 15:40:50 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 773DEA405F; Wed, 5 Dec 2018 15:40:50 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 43FBAA405B; Wed, 5 Dec 2018 15:40:50 +0000 (GMT) Received: from s38lp20.lnxne.boe (unknown [9.152.224.44]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 5 Dec 2018 15:40:50 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, david@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH v2 2/6] s390x: Make tests bootable from disk Date: Wed, 5 Dec 2018 16:39:14 +0100 X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181205153918.29480-1-frankja@linux.ibm.com> References: <20181205153918.29480-1-frankja@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18120515-0028-0000-0000-00000326771E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18120515-0029-0000-0000-000023E284B4 Message-Id: <20181205153918.29480-3-frankja@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-12-05_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=877 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812050139 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently tests are run with the --kernel option of Qemu, which will load the ELF file and jump to the start address. When booting from disk, we need to specify a start address. This is done by setting the initial short PSW at 0x0. Signed-off-by: Janosch Frank --- s390x/cstart64.S | 9 ++++++++- s390x/flat.lds | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/s390x/cstart64.S b/s390x/cstart64.S index dc7ddd6..d382497 100644 --- a/s390x/cstart64.S +++ b/s390x/cstart64.S @@ -14,9 +14,16 @@ .section .init -/* entry point - for KVM + TCG we directly start in 64 bit mode */ +/* + * Short init between 0x10000 and 0x10480 and then jump to 0x11000. + * 0x10480 - 0x11000 are written to by bootloader. + * + * For KVM and TCG kernel boot we are in 64 bit z/Arch mode. + * When booting from disk the initial short psw is in 31 bit mode. + */ .globl start start: + sam64 # Set addressing mode to 64 bit /* setup stack */ larl %r15, stackptr /* setup initial PSW mask + control registers*/ diff --git a/s390x/flat.lds b/s390x/flat.lds index b6e2172..7cfd9f9 100644 --- a/s390x/flat.lds +++ b/s390x/flat.lds @@ -1,10 +1,16 @@ SECTIONS { + .lowcore : { + . = 0; + LONG(0x00080000) + LONG(0x80010000) + } + . = 0x10000; .text : { *(.init) . = 0x480; ipl_args = .; - . = 0x600; + . = 0x1000; *(.text) *(.text.*) } From patchwork Wed Dec 5 15:39:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 10714445 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 83C10109C for ; Wed, 5 Dec 2018 15:41:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 756962D64D for ; Wed, 5 Dec 2018 15:41:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 739B92D643; Wed, 5 Dec 2018 15:41:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 129D32D64E for ; Wed, 5 Dec 2018 15:41:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728254AbeLEPlA (ORCPT ); Wed, 5 Dec 2018 10:41:00 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:38274 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728245AbeLEPk7 (ORCPT ); Wed, 5 Dec 2018 10:40:59 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wB5FdOGS043543 for ; Wed, 5 Dec 2018 10:40:58 -0500 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0a-001b2d01.pphosted.com with ESMTP id 2p6har0shx-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 05 Dec 2018 10:40:57 -0500 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 5 Dec 2018 15:40:55 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 5 Dec 2018 15:40:52 -0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wB5FepEw59703436 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 5 Dec 2018 15:40:51 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B2647A4068; Wed, 5 Dec 2018 15:40:51 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 82130A4067; Wed, 5 Dec 2018 15:40:51 +0000 (GMT) Received: from s38lp20.lnxne.boe (unknown [9.152.224.44]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 5 Dec 2018 15:40:51 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, david@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH v2 3/6] s390x: Switch to z/Arch if needed Date: Wed, 5 Dec 2018 16:39:15 +0100 X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181205153918.29480-1-frankja@linux.ibm.com> References: <20181205153918.29480-1-frankja@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18120515-0016-0000-0000-000002327506 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18120515-0017-0000-0000-0000328A872C Message-Id: <20181205153918.29480-4-frankja@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-12-05_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=786 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812050139 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP LPAR and z/VM start in esam mode depending on the hardware, so we need to switch to z/Arch and set 64 bit addressing. Under Qemu/KVM we already start out with both when being run with the Qemu --kernel argument or we lack 64 bit when booting from disk because of the initial psw specifying 31 bit for z/VM and lpar compatibility. Signed-off-by: Janosch Frank Reviewed-by: David Hildenbrand --- s390x/cstart64.S | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/s390x/cstart64.S b/s390x/cstart64.S index d382497..7886f35 100644 --- a/s390x/cstart64.S +++ b/s390x/cstart64.S @@ -20,9 +20,17 @@ * * For KVM and TCG kernel boot we are in 64 bit z/Arch mode. * When booting from disk the initial short psw is in 31 bit mode. + * When running under LPAR or z/VM, we might start in 31 bit and esam mode. */ .globl start start: + /* Switch to z/Architecture mode and 64-bit */ + slr %r0, %r0 # Set cpuid to zero + lhi %r1, 2 # mode 2 = esame + sigp %r1, %r0, 0x12 # sigp set arch + bras %r13,0f # Jump over zero area + .fill 16,4,0x0 # Zero area for lmh +0: lmh %r0,%r15,0(%r13) # Clear high-order half of gprs sam64 # Set addressing mode to 64 bit /* setup stack */ larl %r15, stackptr From patchwork Wed Dec 5 15:39:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 10714447 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5A17D17DB for ; Wed, 5 Dec 2018 15:41:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 49F192D617 for ; Wed, 5 Dec 2018 15:41:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 483782D665; Wed, 5 Dec 2018 15:41:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DA1412D62C for ; Wed, 5 Dec 2018 15:41:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728260AbeLEPlB (ORCPT ); Wed, 5 Dec 2018 10:41:01 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:60664 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728011AbeLEPlA (ORCPT ); Wed, 5 Dec 2018 10:41:00 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wB5FelGw113325 for ; Wed, 5 Dec 2018 10:40:59 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2p6hhf00b0-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 05 Dec 2018 10:40:58 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 5 Dec 2018 15:40:56 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 5 Dec 2018 15:40:53 -0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wB5Ferfk9437668 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 5 Dec 2018 15:40:53 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E7E7EA4064; Wed, 5 Dec 2018 15:40:52 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BDC38A405B; Wed, 5 Dec 2018 15:40:52 +0000 (GMT) Received: from s38lp20.lnxne.boe (unknown [9.152.224.44]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 5 Dec 2018 15:40:52 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, david@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH v2 4/6] s390x: Add BSS clearing for non ELF boot Date: Wed, 5 Dec 2018 16:39:16 +0100 X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181205153918.29480-1-frankja@linux.ibm.com> References: <20181205153918.29480-1-frankja@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18120515-0012-0000-0000-000002D4FFF8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18120515-0013-0000-0000-0000210A6174 Message-Id: <20181205153918.29480-5-frankja@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-12-05_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812050139 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When doing an IPL normal the memory will not be zeroed and hence the BSS section can have any value. We need to clear it by ourselves. Signed-off-by: Janosch Frank --- s390x/cstart64.S | 23 ++++++++++++++++++++++- s390x/flat.lds | 2 ++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/s390x/cstart64.S b/s390x/cstart64.S index 7886f35..0246e18 100644 --- a/s390x/cstart64.S +++ b/s390x/cstart64.S @@ -37,6 +37,24 @@ start: /* setup initial PSW mask + control registers*/ larl %r1, initial_psw lpswe 0(%r1) +init_clear_bss: + larl %r2, __bss_start + larl %r3, __bss_end + slgr %r3, %r2 # Get sizeof bss + ltgr %r3,%r3 # bss empty? + jz init_psw_cont # Yes, jump to init_psw_cont + aghi %r3,-1 + srlg %r4,%r3,8 # Calc number of 256 byte chunks + ltgr %r4,%r4 + lgr %r1,%r2 + jz remainder # If none, clear remaining bytes +loop: + xc 0(256,%r1), 0(%r1) # Clear 256 byte chunks via xor + la %r1, 256(%r1) + brctg %r4, loop +remainder: + larl %r2, memsetxc + ex %r3, 0(%r2) init_psw_cont: /* setup pgm interrupt handler */ larl %r1, pgm_int_psw @@ -69,6 +87,9 @@ init_psw_cont: /* call exit() */ j exit +memsetxc: + xc 0(1,%r1),0(%r1) + .macro SAVE_REGS /* save grs 0-15 */ stmg %r0, %r15, GEN_LC_SW_INT_GRS @@ -157,7 +178,7 @@ svc_int: .align 8 initial_psw: - .quad 0x0000000180000000, init_psw_cont + .quad 0x0000000180000000, init_clear_bss pgm_int_psw: .quad 0x0000000180000000, pgm_int ext_int_psw: diff --git a/s390x/flat.lds b/s390x/flat.lds index 7cfd9f9..fb229ce 100644 --- a/s390x/flat.lds +++ b/s390x/flat.lds @@ -35,7 +35,9 @@ SECTIONS . = ALIGN(16); .rodata : { *(.rodata) *(.rodata.*) } . = ALIGN(16); + __bss_start = .; .bss : { *(.bss) } + __bss_end = .; . = ALIGN(64K); edata = .; . += 64K; From patchwork Wed Dec 5 15:39:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 10714449 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 708B81731 for ; Wed, 5 Dec 2018 15:41:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60A822D62D for ; Wed, 5 Dec 2018 15:41:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5DA992D617; Wed, 5 Dec 2018 15:41:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AB1552D655 for ; Wed, 5 Dec 2018 15:41:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728256AbeLEPlC (ORCPT ); Wed, 5 Dec 2018 10:41:02 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:45472 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728255AbeLEPlC (ORCPT ); Wed, 5 Dec 2018 10:41:02 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wB5FdQ2b126160 for ; Wed, 5 Dec 2018 10:41:01 -0500 Received: from e06smtp04.uk.ibm.com (e06smtp04.uk.ibm.com [195.75.94.100]) by mx0b-001b2d01.pphosted.com with ESMTP id 2p6fqcx7p6-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 05 Dec 2018 10:41:00 -0500 Received: from localhost by e06smtp04.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 5 Dec 2018 15:40:57 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp04.uk.ibm.com (192.168.101.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 5 Dec 2018 15:40:55 -0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wB5FespW61473020 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 5 Dec 2018 15:40:54 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3DACBA405B; Wed, 5 Dec 2018 15:40:54 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 091ADA405C; Wed, 5 Dec 2018 15:40:54 +0000 (GMT) Received: from s38lp20.lnxne.boe (unknown [9.152.224.44]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 5 Dec 2018 15:40:53 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, david@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH v2 5/6] s390x: Use interrupts in SCLP Date: Wed, 5 Dec 2018 16:39:17 +0100 X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181205153918.29480-1-frankja@linux.ibm.com> References: <20181205153918.29480-1-frankja@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18120515-0016-0000-0000-000002327507 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18120515-0017-0000-0000-0000328A872D Message-Id: <20181205153918.29480-6-frankja@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-12-05_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812050139 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We need to properly implement interrupt handling for SCLP, because on z/VM and LPAR SCLP calls are not synchronous! Signed-off-by: Janosch Frank --- lib/s390x/asm/arch_def.h | 1 + lib/s390x/asm/interrupt.h | 2 ++ lib/s390x/interrupt.c | 12 ++++++++++-- lib/s390x/io.c | 2 +- lib/s390x/sclp-console.c | 29 +++++++++-------------------- lib/s390x/sclp.c | 42 ++++++++++++++++++++++++++++++++++++++++++ lib/s390x/sclp.h | 4 +++- 7 files changed, 68 insertions(+), 24 deletions(-) diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h index d2d6e02..27c6b85 100644 --- a/lib/s390x/asm/arch_def.h +++ b/lib/s390x/asm/arch_def.h @@ -33,6 +33,7 @@ struct psw { uint64_t addr; }; +#define PSW_MASK_EXT 0x0100000000000000UL #define PSW_MASK_DAT 0x0400000000000000UL #define PSW_MASK_PSTATE 0x0001000000000000UL diff --git a/lib/s390x/asm/interrupt.h b/lib/s390x/asm/interrupt.h index 013709f..de15d9e 100644 --- a/lib/s390x/asm/interrupt.h +++ b/lib/s390x/asm/interrupt.h @@ -11,6 +11,8 @@ #define _ASMS390X_IRQ_H_ #include +#define EXT_IRQ_SERVICE_SIG 0x2401 + void handle_pgm_int(void); void handle_ext_int(void); void handle_mcck_int(void); diff --git a/lib/s390x/interrupt.c b/lib/s390x/interrupt.c index cf0a794..7118577 100644 --- a/lib/s390x/interrupt.c +++ b/lib/s390x/interrupt.c @@ -12,6 +12,7 @@ #include #include #include +#include static bool pgm_int_expected; static struct lowcore *lc; @@ -107,8 +108,15 @@ void handle_pgm_int(void) void handle_ext_int(void) { - report_abort("Unexpected external call interrupt: at %#lx", - lc->ext_old_psw.addr); + if (lc->ext_int_code != EXT_IRQ_SERVICE_SIG) + report_abort("Unexpected external call interrupt: at %#lx", + lc->ext_old_psw.addr); + else { + lc->ext_old_psw.mask &= ~PSW_MASK_EXT; + lc->sw_int_cr0 &= ~(1UL << 9); + sclp_handle_ext(); + lc->ext_int_code = 0; + } } void handle_mcck_int(void) diff --git a/lib/s390x/io.c b/lib/s390x/io.c index 05a0765..7294165 100644 --- a/lib/s390x/io.c +++ b/lib/s390x/io.c @@ -45,8 +45,8 @@ void setup(void) { setup_args_progname(ipl_args); setup_facilities(); - sclp_console_setup(); sclp_memory_setup(); + sclp_console_setup(); } void exit(int code) diff --git a/lib/s390x/sclp-console.c b/lib/s390x/sclp-console.c index deacbde..13ab03d 100644 --- a/lib/s390x/sclp-console.c +++ b/lib/s390x/sclp-console.c @@ -13,30 +13,13 @@ #include #include "sclp.h" -char _sccb[PAGE_SIZE] __attribute__((__aligned__(4096))); - -/* Perform service call. Return 0 on success, non-zero otherwise. */ -int sclp_service_call(unsigned int command, void *sccb) -{ - int cc; - - asm volatile( - " .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */ - " ipm %0\n" - " srl %0,28" - : "=&d" (cc) : "d" (command), "a" (__pa(sccb)) - : "cc", "memory"); - if (cc == 3) - return -1; - if (cc == 2) - return -1; - return 0; -} - static void sclp_set_write_mask(void) { WriteEventMask *sccb = (void *)_sccb; + while (sclp_busy) + /* Wait for SCLP request to complete */; + sclp_busy = true; sccb->h.length = sizeof(WriteEventMask); sccb->mask_length = sizeof(unsigned int); sccb->receive_mask = SCLP_EVENT_MASK_MSG_ASCII; @@ -57,6 +40,9 @@ void sclp_print(const char *str) int len = strlen(str); WriteEventData *sccb = (void *)_sccb; + while (sclp_busy) + /* Wait for SCLP request to complete */; + sclp_busy = true; sccb->h.length = sizeof(WriteEventData) + len; sccb->h.function_code = SCLP_FC_NORMAL_WRITE; sccb->ebh.length = sizeof(EventBufferHeader) + len; @@ -65,4 +51,7 @@ void sclp_print(const char *str) memcpy(sccb->data, str, len); sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb); + while (sclp_busy) + /* Wait for SCLP request to complete */; + } diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c index 1d4a010..cd0e5e5 100644 --- a/lib/s390x/sclp.c +++ b/lib/s390x/sclp.c @@ -23,6 +23,9 @@ static uint64_t storage_increment_size; static uint64_t max_ram_size; static uint64_t ram_size; +char _sccb[PAGE_SIZE] __attribute__((__aligned__(4096))); +volatile bool sclp_busy = false; + static void mem_init(phys_addr_t mem_end) { phys_addr_t freemem_start = (phys_addr_t)&stacktop; @@ -30,6 +33,42 @@ static void mem_init(phys_addr_t mem_end) phys_alloc_init(freemem_start, mem_end - freemem_start); } +static void sclp_setup_int(void) +{ + uint64_t mask; + + ctl_set_bit(0, 9); + + mask = extract_psw_mask(); + mask |= PSW_MASK_EXT; + load_psw_mask(mask); +} + +void sclp_handle_ext(void) +{ + ctl_clear_bit(0, 9); + sclp_busy = false; +} + +/* Perform service call. Return 0 on success, non-zero otherwise. */ +int sclp_service_call(unsigned int command, void *sccb) +{ + int cc; + + sclp_setup_int(); + asm volatile( + " .insn rre,0xb2200000,%1,%2\n" /* servc %1,%2 */ + " ipm %0\n" + " srl %0,28" + : "=&d" (cc) : "d" (command), "a" (__pa(sccb)) + : "cc", "memory"); + if (cc == 3) + return -1; + if (cc == 2) + return -1; + return 0; +} + void sclp_memory_setup(void) { ReadInfo *ri = (void *)_sccb; @@ -37,7 +76,10 @@ void sclp_memory_setup(void) int cc; ri->h.length = SCCB_SIZE; + sclp_busy = true; sclp_service_call(SCLP_CMDW_READ_SCP_INFO_FORCED, ri); + while (sclp_busy) + /* Wait for SCLP request to complete */; /* calculate the storage increment size */ rnsize = ri->rnsize; diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h index e008932..a91aad1 100644 --- a/lib/s390x/sclp.h +++ b/lib/s390x/sclp.h @@ -207,9 +207,11 @@ typedef struct ReadEventData { uint32_t mask; } __attribute__((packed)) ReadEventData; +extern char _sccb[]; +volatile bool sclp_busy; +void sclp_handle_ext(void); void sclp_console_setup(void); void sclp_print(const char *str); -extern char _sccb[]; int sclp_service_call(unsigned int command, void *sccb); void sclp_memory_setup(void); From patchwork Wed Dec 5 15:39:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 10714451 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A3700109C for ; Wed, 5 Dec 2018 15:41:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 92B302D62A for ; Wed, 5 Dec 2018 15:41:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 909432D677; Wed, 5 Dec 2018 15:41:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A8E812D60D for ; Wed, 5 Dec 2018 15:41:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728255AbeLEPlE (ORCPT ); Wed, 5 Dec 2018 10:41:04 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:36943 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728245AbeLEPlC (ORCPT ); Wed, 5 Dec 2018 10:41:02 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id wB5Fd9mR049549 for ; Wed, 5 Dec 2018 10:41:00 -0500 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0b-001b2d01.pphosted.com with ESMTP id 2p6g73cyur-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 05 Dec 2018 10:41:00 -0500 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 5 Dec 2018 15:40:58 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Wed, 5 Dec 2018 15:40:56 -0000 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id wB5Fetd364421950 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 5 Dec 2018 15:40:55 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7D3A7A4060; Wed, 5 Dec 2018 15:40:55 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 49141A405B; Wed, 5 Dec 2018 15:40:55 +0000 (GMT) Received: from s38lp20.lnxne.boe (unknown [9.152.224.44]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 5 Dec 2018 15:40:55 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, david@redhat.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH v2 6/6] s390x: Add linemode console Date: Wed, 5 Dec 2018 16:39:18 +0100 X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181205153918.29480-1-frankja@linux.ibm.com> References: <20181205153918.29480-1-frankja@linux.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18120515-0028-0000-0000-000003267721 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18120515-0029-0000-0000-000023E284B5 Message-Id: <20181205153918.29480-7-frankja@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-12-05_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=848 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1812050139 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP z/VM isn't fond of vt220, so we need line mode when running under z/VM. Signed-off-by: Janosch Frank --- lib/s390x/sclp-console.c | 199 ++++++++++++++++++++++++++++++++++++++++++----- lib/s390x/sclp.h | 67 ++++++++++++++++ 2 files changed, 245 insertions(+), 21 deletions(-) diff --git a/lib/s390x/sclp-console.c b/lib/s390x/sclp-console.c index 13ab03d..c31e178 100644 --- a/lib/s390x/sclp-console.c +++ b/lib/s390x/sclp-console.c @@ -11,23 +11,183 @@ #include #include #include +#include +#include #include "sclp.h" -static void sclp_set_write_mask(void) +/* + * ASCII (IBM PC 437) -> EBCDIC 037 + */ +static uint8_t _ascebc[256] = +{ + /*00 NUL SOH STX ETX EOT ENQ ACK BEL */ + 0x00, 0x01, 0x02, 0x03, 0x37, 0x2D, 0x2E, 0x2F, + /*08 BS HT LF VT FF CR SO SI */ + /* ->NL */ + 0x16, 0x05, 0x15, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + /*10 DLE DC1 DC2 DC3 DC4 NAK SYN ETB */ + 0x10, 0x11, 0x12, 0x13, 0x3C, 0x3D, 0x32, 0x26, + /*18 CAN EM SUB ESC FS GS RS US */ + /* ->IGS ->IRS ->IUS */ + 0x18, 0x19, 0x3F, 0x27, 0x22, 0x1D, 0x1E, 0x1F, + /*20 SP ! " # $ % & ' */ + 0x40, 0x5A, 0x7F, 0x7B, 0x5B, 0x6C, 0x50, 0x7D, + /*28 ( ) * + , - . / */ + 0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61, + /*30 0 1 2 3 4 5 6 7 */ + 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, + /*38 8 9 : ; < = > ? */ + 0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F, + /*40 @ A B C D E F G */ + 0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, + /*48 H I J K L M N O */ + 0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, + /*50 P Q R S T U V W */ + 0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, + /*58 X Y Z [ \ ] ^ _ */ + 0xE7, 0xE8, 0xE9, 0xBA, 0xE0, 0xBB, 0xB0, 0x6D, + /*60 ` a b c d e f g */ + 0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, + /*68 h i j k l m n o */ + 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, + /*70 p q r s t u v w */ + 0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, + /*78 x y z { | } ~ DL */ + 0xA7, 0xA8, 0xA9, 0xC0, 0x4F, 0xD0, 0xA1, 0x07, + /*80*/ + 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, + /*88*/ + 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, + /*90*/ + 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, + /*98*/ + 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, + /*A0*/ + 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, + /*A8*/ + 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, + /*B0*/ + 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, + /*B8*/ + 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, + /*C0*/ + 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, + /*C8*/ + 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, + /*D0*/ + 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, + /*D8*/ + 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, + /*E0 sz */ + 0x3F, 0x59, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, + /*E8*/ + 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, + /*F0*/ + 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, + /*F8*/ + 0x90, 0x3F, 0x3F, 0x3F, 0x3F, 0xEA, 0x3F, 0xFF +}; + +static bool initialized = false; + +static void sclp_print_ascii(const char *str) +{ + int len = strlen(str); + WriteEventData *sccb = (void *)_sccb; + + while (sclp_busy) + /* Wait for SCLP request to complete */; + sclp_busy = true; + memset(sccb, 0, sizeof(*sccb)); + sccb->h.length = sizeof(WriteEventData) + len; + sccb->h.function_code = SCLP_FC_NORMAL_WRITE; + sccb->ebh.length = sizeof(EventBufferHeader) + len; + sccb->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA; + memcpy(sccb->data, str, len); + + sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb); +} + +static void sclp_print_lm(const char *str) +{ + unsigned char *ptr, *end, ch; + unsigned int count, offset, len; + struct write_sccb *sccb; + struct msg_buf *msg; + struct mdb *mdb; + struct mto *mto; + struct go *go; + + while (sclp_busy) + /* Wait for SCLP request to complete */; + sclp_busy = true; + sccb = (struct write_sccb *) _sccb; + end = (unsigned char *) sccb + 4096 - 1; + memset(sccb, 0, sizeof(*sccb)); + ptr = (unsigned char *) &sccb->msg.mdb.mto; + len = strlen(str); + offset = 0; + do { + for (count = sizeof(*mto); offset < len; count++) { + ch = str[offset++]; + if ((ch == 0x0a) || (ptr + count > end)) + break; + ptr[count] = _ascebc[ch]; + } + mto = (struct mto *) ptr; + memset(mto, 0, sizeof(*mto)); + mto->length = count; + mto->type = 4; + mto->line_type_flags = LNTPFLGS_ENDTEXT; + ptr += count; + } while ((offset < len) && (ptr + sizeof(*mto) <= end)); + len = ptr - (unsigned char *) sccb; + sccb->header.length = len - offsetof(struct write_sccb, header); + msg = &sccb->msg; + msg->header.type = EVTYP_MSG; + msg->header.length = len - offsetof(struct write_sccb, msg.header); + mdb = &msg->mdb; + mdb->header.type = 1; + mdb->header.tag = 0xD4C4C240; + mdb->header.revision_code = 1; + mdb->header.length = len - offsetof(struct write_sccb, msg.mdb.header); + go = &mdb->go; + go->length = sizeof(*go); + go->type = 1; + sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb); +} + +/* + * SCLP needs to be initialized by setting a send and receive mask, + * indicating which messages the control program (we) want(s) to + * send/receive. + */ +static bool sclp_set_write_mask(void) { WriteEventMask *sccb = (void *)_sccb; while (sclp_busy) /* Wait for SCLP request to complete */; sclp_busy = true; + memset(_sccb, 0, sizeof(*sccb)); sccb->h.length = sizeof(WriteEventMask); - sccb->mask_length = sizeof(unsigned int); - sccb->receive_mask = SCLP_EVENT_MASK_MSG_ASCII; - sccb->cp_receive_mask = SCLP_EVENT_MASK_MSG_ASCII; - sccb->send_mask = SCLP_EVENT_MASK_MSG_ASCII; - sccb->cp_send_mask = SCLP_EVENT_MASK_MSG_ASCII; + sccb->h.function_code = 0; + sccb->mask_length = sizeof(sccb_mask_t); + + /* For now we don't process sclp input. */ + sccb->cp_receive_mask = 0; + /* We send ASCII and line mode. */ + sccb->cp_send_mask = SCLP_EVENT_MASK_MSG_ASCII | SCLP_EVENT_MASK_MSG; sclp_service_call(SCLP_CMD_WRITE_EVENT_MASK, sccb); + while (sclp_busy) { + } + if (sccb->h.response_code != SCLP_RC_NORMAL_COMPLETION) + return false; + else { + initialized = true; + return true; + } } void sclp_console_setup(void) @@ -37,21 +197,18 @@ void sclp_console_setup(void) void sclp_print(const char *str) { - int len = strlen(str); - WriteEventData *sccb = (void *)_sccb; - + if (!initialized) + return; + /* + * z/VM advertises a vt220 console which is not functional: + * (response code 05F0, "not active because of the state of + * the machine"). Hence testing the masks would only work if + * we also use stsi data to distinguish z/VM. + * + * Let's rather print on all available consoles. + */ + sclp_print_ascii(str); + sclp_print_lm(str); while (sclp_busy) /* Wait for SCLP request to complete */; - sclp_busy = true; - sccb->h.length = sizeof(WriteEventData) + len; - sccb->h.function_code = SCLP_FC_NORMAL_WRITE; - sccb->ebh.length = sizeof(EventBufferHeader) + len; - sccb->ebh.type = SCLP_EVENT_ASCII_CONSOLE_DATA; - sccb->ebh.flags = 0; - memcpy(sccb->data, str, len); - - sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb); - while (sclp_busy) - /* Wait for SCLP request to complete */; - } diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h index a91aad1..6174451 100644 --- a/lib/s390x/sclp.h +++ b/lib/s390x/sclp.h @@ -174,6 +174,7 @@ typedef struct SCCB { /* SCLP event masks */ #define SCLP_EVENT_MASK_SIGNAL_QUIESCE 0x00000008 #define SCLP_EVENT_MASK_MSG_ASCII 0x00000040 +#define SCLP_EVENT_MASK_MSG 0x40000000 #define SCLP_UNCONDITIONAL_READ 0x00 #define SCLP_SELECTIVE_READ 0x01 @@ -207,6 +208,72 @@ typedef struct ReadEventData { uint32_t mask; } __attribute__((packed)) ReadEventData; +#define MDBTYP_GO 0x0001 +#define MDBTYP_MTO 0x0004 +#define EVTYP_MSG 0x02 +#define LNTPFLGS_CNTLTEXT 0x8000 +#define LNTPFLGS_LABELTEXT 0x4000 +#define LNTPFLGS_DATATEXT 0x2000 +#define LNTPFLGS_ENDTEXT 0x1000 +#define LNTPFLGS_PROMPTTEXT 0x0800 + +typedef uint32_t sccb_mask_t; + +/* SCLP line mode console related structures. */ + +struct mto { + u16 length; + u16 type; + u16 line_type_flags; + u8 alarm_control; + u8 _reserved[3]; +} __attribute__((packed)); + +struct go { + u16 length; + u16 type; + u32 domid; + u8 hhmmss_time[8]; + u8 th_time[3]; + u8 reserved_0; + u8 dddyyyy_date[7]; + u8 _reserved_1; + u16 general_msg_flags; + u8 _reserved_2[10]; + u8 originating_system_name[8]; + u8 job_guest_name[8]; +} __attribute__((packed)); + +struct mdb_header { + u16 length; + u16 type; + u32 tag; + u32 revision_code; +} __attribute__((packed)); + +struct mdb { + struct mdb_header header; + struct go go; + struct mto mto; +} __attribute__((packed)); + +struct evbuf_header { + u16 length; + u8 type; + u8 flags; + u16 _reserved; +} __attribute__((packed)); + +struct msg_buf { + struct evbuf_header header; + struct mdb mdb; +} __attribute__((packed)); + +struct write_sccb { + struct SCCBHeader header; + struct msg_buf msg; +} __packed; + extern char _sccb[]; volatile bool sclp_busy; void sclp_handle_ext(void);