From patchwork Wed Sep 25 16:36:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161109 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D44D1747 for ; Wed, 25 Sep 2019 16:37:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E0B7C21D7F for ; Wed, 25 Sep 2019 16:37:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390629AbfIYQh0 (ORCPT ); Wed, 25 Sep 2019 12:37:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47622 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389105AbfIYQhZ (ORCPT ); Wed, 25 Sep 2019 12:37:25 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B2A733091786; Wed, 25 Sep 2019 16:37:25 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 99E4060BF1; Wed, 25 Sep 2019 16:37:22 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 01/17] s390x: Support PSW restart boot Date: Wed, 25 Sep 2019 18:36:58 +0200 Message-Id: <20190925163714.27519-2-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 25 Sep 2019 16:37:25 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank Add a boot PSW to PSW restart new, so we can also boot via a PSW restart. Signed-off-by: Janosch Frank Reviewed-by: Thomas Huth Reviewed-by: David Hildenbrand Message-Id: <20190826163502.1298-2-frankja@linux.ibm.com> Signed-off-by: Thomas Huth --- s390x/flat.lds | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/s390x/flat.lds b/s390x/flat.lds index 403d967..86dffac 100644 --- a/s390x/flat.lds +++ b/s390x/flat.lds @@ -1,14 +1,18 @@ SECTIONS { - /* - * Initial short psw for disk boot, with 31 bit addressing for - * non z/Arch environment compatibility and the instruction - * address 0x10000 (cstart64.S .init). - */ .lowcore : { + /* + * Initial short psw for disk boot, with 31 bit addressing for + * non z/Arch environment compatibility and the instruction + * address 0x10000 (cstart64.S .init). + */ . = 0; LONG(0x00080000) LONG(0x80010000) + /* Restart new PSW for booting via PSW restart. */ + . = 0x1a0; + QUAD(0x0000000180000000) + QUAD(0x0000000000010000) } . = 0x10000; .text : { From patchwork Wed Sep 25 16:36:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161111 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 15DF4112B for ; Wed, 25 Sep 2019 16:37:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F250B21D7B for ; Wed, 25 Sep 2019 16:37:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391596AbfIYQh2 (ORCPT ); Wed, 25 Sep 2019 12:37:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:41018 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728465AbfIYQh1 (ORCPT ); Wed, 25 Sep 2019 12:37:27 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 83E4D10C030D; Wed, 25 Sep 2019 16:37:27 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1C58F60BF1; Wed, 25 Sep 2019 16:37:25 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 02/17] s390x: Diag288 test Date: Wed, 25 Sep 2019 18:36:59 +0200 Message-Id: <20190925163714.27519-3-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.65]); Wed, 25 Sep 2019 16:37:27 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank A small test for the watchdog via diag288. Minimum timer value is 15 (seconds) and the only supported action with QEMU is restart. Signed-off-by: Janosch Frank Reviewed-by: Thomas Huth Message-Id: <20190827074631.7184-1-frankja@linux.ibm.com> Signed-off-by: Thomas Huth --- lib/s390x/asm/arch_def.h | 1 + s390x/Makefile | 1 + s390x/diag288.c | 114 +++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 ++ 4 files changed, 120 insertions(+) create mode 100644 s390x/diag288.c diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h index d2cd727..4bbb428 100644 --- a/lib/s390x/asm/arch_def.h +++ b/lib/s390x/asm/arch_def.h @@ -15,6 +15,7 @@ struct psw { uint64_t addr; }; +#define PSW_MASK_EXT 0x0100000000000000UL #define PSW_MASK_DAT 0x0400000000000000UL #define PSW_MASK_PSTATE 0x0001000000000000UL diff --git a/s390x/Makefile b/s390x/Makefile index 574a9a2..3453373 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -12,6 +12,7 @@ tests += $(TEST_DIR)/vector.elf tests += $(TEST_DIR)/gs.elf tests += $(TEST_DIR)/iep.elf tests += $(TEST_DIR)/cpumodel.elf +tests += $(TEST_DIR)/diag288.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binary diff --git a/s390x/diag288.c b/s390x/diag288.c new file mode 100644 index 0000000..b4934bf --- /dev/null +++ b/s390x/diag288.c @@ -0,0 +1,114 @@ +/* + * Timer Event DIAG288 test + * + * Copyright (c) 2019 IBM Corp + * + * Authors: + * Janosch Frank + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU Library General Public License version 2. + */ + +#include +#include +#include + +struct lowcore *lc = (struct lowcore *)0x0; + +#define CODE_INIT 0 +#define CODE_CHANGE 1 +#define CODE_CANCEL 2 + +#define ACTION_RESTART 0 + +static inline void diag288(unsigned long code, unsigned long time, + unsigned long action) +{ + register unsigned long fc asm("0") = code; + register unsigned long tm asm("1") = time; + register unsigned long ac asm("2") = action; + + asm volatile("diag %0,%2,0x288" + : : "d" (fc), "d" (tm), "d" (ac)); +} + +static void test_specs(void) +{ + report_prefix_push("specification"); + + report_prefix_push("uneven"); + expect_pgm_int(); + asm volatile("diag 1,2,0x288"); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_push("unsupported action"); + expect_pgm_int(); + diag288(CODE_INIT, 15, 42); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_push("unsupported function"); + expect_pgm_int(); + diag288(42, 15, ACTION_RESTART); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_push("no init"); + expect_pgm_int(); + diag288(CODE_CANCEL, 15, ACTION_RESTART); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_push("min timer"); + expect_pgm_int(); + diag288(CODE_INIT, 14, ACTION_RESTART); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_pop(); +} + +static void test_priv(void) +{ + report_prefix_push("privileged"); + expect_pgm_int(); + enter_pstate(); + diag288(CODE_INIT, 15, ACTION_RESTART); + check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION); + report_prefix_pop(); +} + +static void test_bite(void) +{ + uint64_t mask, time; + + /* If watchdog doesn't bite, the cpu timer does */ + asm volatile("stck %0" : "=Q" (time) : : "cc"); + time += (uint64_t)(16000 * 1000) << 12; + asm volatile("sckc %0" : : "Q" (time)); + ctl_set_bit(0, 11); + mask = extract_psw_mask(); + mask |= PSW_MASK_EXT; + load_psw_mask(mask); + + /* Arm watchdog */ + lc->restart_new_psw.mask = extract_psw_mask() & ~PSW_MASK_EXT; + diag288(CODE_INIT, 15, ACTION_RESTART); + asm volatile(" larl %r0, 1f\n" + " stg %r0, 424\n" + "0: nop\n" + " j 0b\n" + "1:"); + report("restart", true); +} + +int main(void) +{ + report_prefix_push("diag288"); + test_priv(); + test_specs(); + test_bite(); + return report_summary(); +} diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index db58bad..9dd288a 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -64,3 +64,7 @@ file = iep.elf [cpumodel] file = cpumodel.elf + +[diag288] +file = diag288.elf +extra_params=-device diag288,id=watchdog0 --watchdog-action inject-nmi From patchwork Wed Sep 25 16:37:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161113 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DB710112B for ; Wed, 25 Sep 2019 16:37:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B5BDA21D7C for ; Wed, 25 Sep 2019 16:37:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2501893AbfIYQhb (ORCPT ); Wed, 25 Sep 2019 12:37:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53802 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391644AbfIYQhb (ORCPT ); Wed, 25 Sep 2019 12:37:31 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5AC67796FC; Wed, 25 Sep 2019 16:37:31 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDB8F60BF1; Wed, 25 Sep 2019 16:37:27 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 03/17] s390x: Move stsi to library Date: Wed, 25 Sep 2019 18:37:00 +0200 Message-Id: <20190925163714.27519-4-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Wed, 25 Sep 2019 16:37:31 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank It's needed in multiple tests now. Return value changes from 0/-1 to the cc. Signed-off-by: Janosch Frank Reviewed-by: David Hildenbrand Reviewed-by: Thomas Huth Message-Id: <20190826163502.1298-4-frankja@linux.ibm.com> Signed-off-by: Thomas Huth --- lib/s390x/asm/arch_def.h | 16 ++++++++++++++++ s390x/skey.c | 18 ------------------ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h index 4bbb428..5f8f45e 100644 --- a/lib/s390x/asm/arch_def.h +++ b/lib/s390x/asm/arch_def.h @@ -240,4 +240,20 @@ static inline void enter_pstate(void) load_psw_mask(mask); } +static inline int stsi(void *addr, int fc, int sel1, int sel2) +{ + register int r0 asm("0") = (fc << 28) | sel1; + register int r1 asm("1") = sel2; + int cc; + + asm volatile( + "stsi 0(%3)\n" + "ipm %[cc]\n" + "srl %[cc],28\n" + : "+d" (r0), [cc] "=d" (cc) + : "d" (r1), "a" (addr) + : "cc", "memory"); + return cc; +} + #endif diff --git a/s390x/skey.c b/s390x/skey.c index b1e11af..fd4fcc7 100644 --- a/s390x/skey.c +++ b/s390x/skey.c @@ -70,24 +70,6 @@ static void test_set(void) skey.str.acc == ret.str.acc && skey.str.fp == ret.str.fp); } -static inline int stsi(void *addr, int fc, int sel1, int sel2) -{ - register int r0 asm("0") = (fc << 28) | sel1; - register int r1 asm("1") = sel2; - int rc = 0; - - asm volatile( - " stsi 0(%3)\n" - " jz 0f\n" - " lhi %1,-1\n" - "0:\n" - : "+d" (r0), "+d" (rc) - : "d" (r1), "a" (addr) - : "cc", "memory"); - - return rc; -} - /* Returns true if we are running under z/VM 6.x */ static bool check_for_zvm6(void) { From patchwork Wed Sep 25 16:37:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161115 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF43417D4 for ; Wed, 25 Sep 2019 16:37:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A6AA321D7A for ; Wed, 25 Sep 2019 16:37:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2502115AbfIYQhm (ORCPT ); Wed, 25 Sep 2019 12:37:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47738 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2501978AbfIYQhm (ORCPT ); Wed, 25 Sep 2019 12:37:42 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 82726316D76A; Wed, 25 Sep 2019 16:37:42 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id B5B5260C5D; Wed, 25 Sep 2019 16:37:31 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 04/17] s390x: STSI tests Date: Wed, 25 Sep 2019 18:37:01 +0200 Message-Id: <20190925163714.27519-5-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.41]); Wed, 25 Sep 2019 16:37:42 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank For now let's concentrate on the error conditions. Signed-off-by: Janosch Frank Message-Id: <20190826163502.1298-5-frankja@linux.ibm.com> Reviewed-by: David Hildenbrand [thuth: Replaced a "%3" in inline assembly with "%[addr]"] Signed-off-by: Thomas Huth --- s390x/Makefile | 1 + s390x/stsi.c | 84 +++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 3 ++ 3 files changed, 88 insertions(+) create mode 100644 s390x/stsi.c diff --git a/s390x/Makefile b/s390x/Makefile index 3453373..76db0bb 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -13,6 +13,7 @@ tests += $(TEST_DIR)/gs.elf tests += $(TEST_DIR)/iep.elf tests += $(TEST_DIR)/cpumodel.elf tests += $(TEST_DIR)/diag288.elf +tests += $(TEST_DIR)/stsi.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binary diff --git a/s390x/stsi.c b/s390x/stsi.c new file mode 100644 index 0000000..7232cb0 --- /dev/null +++ b/s390x/stsi.c @@ -0,0 +1,84 @@ +/* + * Store System Information tests + * + * Copyright (c) 2019 IBM Corp + * + * Authors: + * Janosch Frank + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU Library General Public License version 2. + */ + +#include +#include +#include +#include + +static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE * 2))); + +static void test_specs(void) +{ + report_prefix_push("specification"); + + report_prefix_push("inv r0"); + expect_pgm_int(); + stsi(pagebuf, 0, 1 << 8, 0); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_push("inv r1"); + expect_pgm_int(); + stsi(pagebuf, 1, 0, 1 << 16); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_push("unaligned"); + expect_pgm_int(); + stsi(pagebuf + 42, 1, 0, 0); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_pop(); +} + +static void test_priv(void) +{ + report_prefix_push("privileged"); + expect_pgm_int(); + enter_pstate(); + stsi(pagebuf, 0, 0, 0); + check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION); + report_prefix_pop(); +} + +static inline unsigned long stsi_get_fc(void *addr) +{ + register unsigned long r0 asm("0") = 0; + register unsigned long r1 asm("1") = 0; + int cc; + + asm volatile("stsi 0(%[addr])\n" + "ipm %[cc]\n" + "srl %[cc],28\n" + : "+d" (r0), [cc] "=d" (cc) + : "d" (r1), [addr] "a" (addr) + : "cc", "memory"); + assert(!cc); + return r0 >> 28; +} + +static void test_fc(void) +{ + report("invalid fc", stsi(pagebuf, 7, 0, 0) == 3); + report("query fc >= 2", stsi_get_fc(pagebuf) >= 2); +} + +int main(void) +{ + report_prefix_push("stsi"); + test_priv(); + test_specs(); + test_fc(); + return report_summary(); +} diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index 9dd288a..cc79a4e 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -68,3 +68,6 @@ file = cpumodel.elf [diag288] file = diag288.elf extra_params=-device diag288,id=watchdog0 --watchdog-action inject-nmi + +[stsi] +file = stsi.elf From patchwork Wed Sep 25 16:37:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161117 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 508C31747 for ; Wed, 25 Sep 2019 16:37:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 38E4821D7C for ; Wed, 25 Sep 2019 16:37:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2504890AbfIYQhu (ORCPT ); Wed, 25 Sep 2019 12:37:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55160 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2501978AbfIYQhu (ORCPT ); Wed, 25 Sep 2019 12:37:50 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D65CD307D989; Wed, 25 Sep 2019 16:37:49 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id DD98B60E1C; Wed, 25 Sep 2019 16:37:42 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 05/17] s390x: Add diag308 subcode 0 testing Date: Wed, 25 Sep 2019 18:37:02 +0200 Message-Id: <20190925163714.27519-6-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 25 Sep 2019 16:37:49 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank By adding a load reset routine to cstart.S we can also test the clear reset done by subcode 0, as we now can restore our registers again. Signed-off-by: Janosch Frank Reviewed-by: Thomas Huth Message-Id: <20190826163502.1298-6-frankja@linux.ibm.com> Signed-off-by: Thomas Huth --- s390x/cstart64.S | 27 +++++++++++++++++++++++++++ s390x/diag308.c | 31 ++++++++++--------------------- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/s390x/cstart64.S b/s390x/cstart64.S index dedfe80..36f7cab 100644 --- a/s390x/cstart64.S +++ b/s390x/cstart64.S @@ -145,6 +145,33 @@ memsetxc: .endm .section .text +/* + * load_reset calling convention: + * %r2 subcode (0 or 1) + */ +.globl diag308_load_reset +diag308_load_reset: + SAVE_REGS + /* Save the first PSW word to the IPL PSW */ + epsw %r0, %r1 + st %r0, 0 + /* Store the address and the bit for 31 bit addressing */ + larl %r0, 0f + oilh %r0, 0x8000 + st %r0, 0x4 + /* Do the reset */ + diag %r0,%r2,0x308 + /* Failure path */ + xgr %r2, %r2 + br %r14 + /* Success path */ + /* We lost cr0 due to the reset */ +0: larl %r1, initial_cr0 + lctlg %c0, %c0, 0(%r1) + RESTORE_REGS + lhi %r2, 1 + br %r14 + pgm_int: SAVE_REGS brasl %r14, handle_pgm_int diff --git a/s390x/diag308.c b/s390x/diag308.c index f085b1a..6b4ffa6 100644 --- a/s390x/diag308.c +++ b/s390x/diag308.c @@ -21,32 +21,20 @@ static void test_priv(void) check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION); } + /* - * Check that diag308 with subcode 1 loads the PSW at address 0, i.e. + * Check that diag308 with subcode 0 and 1 loads the PSW at address 0, i.e. * that we can put a pointer into address 4 which then gets executed. */ +extern int diag308_load_reset(u64); +static void test_subcode0(void) +{ + report("load modified clear done", diag308_load_reset(0)); +} + static void test_subcode1(void) { - uint64_t saved_psw = *(uint64_t *)0; - long subcode = 1; - long ret, tmp; - - asm volatile ( - " epsw %0,%1\n" - " st %0,0\n" - " larl %0,0f\n" - " oilh %0,0x8000\n" - " st %0,4\n" - " diag 0,%2,0x308\n" - " lghi %0,0\n" - " j 1f\n" - "0: lghi %0,1\n" - "1:" - : "=&d"(ret), "=&d"(tmp) : "d"(subcode) : "memory"); - - *(uint64_t *)0 = saved_psw; - - report("load normal reset done", ret == 1); + report("load normal reset done", diag308_load_reset(1)); } /* Expect a specification exception when using an uneven register */ @@ -107,6 +95,7 @@ static struct { void (*func)(void); } tests[] = { { "privileged", test_priv }, + { "subcode 0", test_subcode0 }, { "subcode 1", test_subcode1 }, { "subcode 5", test_subcode5 }, { "subcode 6", test_subcode6 }, From patchwork Wed Sep 25 16:37:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161119 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D11E5112B for ; Wed, 25 Sep 2019 16:37:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B94D521D7C for ; Wed, 25 Sep 2019 16:37:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2505116AbfIYQh5 (ORCPT ); Wed, 25 Sep 2019 12:37:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54010 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728465AbfIYQh5 (ORCPT ); Wed, 25 Sep 2019 12:37:57 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4182620F1; Wed, 25 Sep 2019 16:37:57 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E33B60F88; Wed, 25 Sep 2019 16:37:50 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 06/17] s390x: Move pfmf to lib and make address void Date: Wed, 25 Sep 2019 18:37:03 +0200 Message-Id: <20190925163714.27519-7-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.71]); Wed, 25 Sep 2019 16:37:57 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank It's needed by other tests soon. Signed-off-by: Janosch Frank Reviewed-by: Thomas Huth Message-Id: <20190828113615.4769-2-frankja@linux.ibm.com> Signed-off-by: Thomas Huth --- lib/s390x/asm/mem.h | 31 ++++++++++++++++++++++++ s390x/pfmf.c | 57 +++++++++++---------------------------------- 2 files changed, 44 insertions(+), 44 deletions(-) diff --git a/lib/s390x/asm/mem.h b/lib/s390x/asm/mem.h index 75bd778..9b8fd70 100644 --- a/lib/s390x/asm/mem.h +++ b/lib/s390x/asm/mem.h @@ -54,4 +54,35 @@ static inline unsigned char get_storage_key(unsigned long addr) asm volatile("iske %0,%1" : "=d" (skey) : "a" (addr)); return skey; } + +#define PFMF_FSC_4K 0 +#define PFMF_FSC_1M 1 +#define PFMF_FSC_2G 2 + +union pfmf_r1 { + struct { + unsigned long pad0 : 32; + unsigned long pad1 : 12; + unsigned long pad_fmfi : 2; + unsigned long sk : 1; /* set key*/ + unsigned long cf : 1; /* clear frame */ + unsigned long ui : 1; /* usage indication */ + unsigned long fsc : 3; + unsigned long pad2 : 1; + unsigned long mr : 1; + unsigned long mc : 1; + unsigned long pad3 : 1; + unsigned long key : 8; /* storage keys */ + } reg; + unsigned long val; +}; + +static inline void *pfmf(unsigned long r1, void *paddr) +{ + register void * addr asm("1") = paddr; + + asm volatile(".insn rre,0xb9af0000,%[r1],%[addr]" + : [addr] "+a" (addr) : [r1] "d" (r1) : "memory"); + return addr; +} #endif diff --git a/s390x/pfmf.c b/s390x/pfmf.c index 9bf434a..9986624 100644 --- a/s390x/pfmf.c +++ b/s390x/pfmf.c @@ -16,60 +16,29 @@ #include #include -#define FSC_4K 0 -#define FSC_1M 1 -#define FSC_2G 2 - -union r1 { - struct { - unsigned long pad0 : 32; - unsigned long pad1 : 12; - unsigned long pad_fmfi : 2; - unsigned long sk : 1; /* set key*/ - unsigned long cf : 1; /* clear frame */ - unsigned long ui : 1; /* usage indication */ - unsigned long fsc : 3; - unsigned long pad2 : 1; - unsigned long mr : 1; - unsigned long mc : 1; - unsigned long pad3 : 1; - unsigned long key : 8; /* storage keys */ - } reg; - unsigned long val; -}; - static uint8_t pagebuf[PAGE_SIZE * 256] __attribute__((aligned(PAGE_SIZE * 256))); -static inline unsigned long pfmf(unsigned long r1, unsigned long paddr) -{ - register uint64_t addr asm("1") = paddr; - - asm volatile(".insn rre,0xb9af0000,%[r1],%[addr]" - : [addr] "+a" (addr) : [r1] "d" (r1) : "memory"); - return addr; -} - static void test_priv(void) { report_prefix_push("privileged"); expect_pgm_int(); enter_pstate(); - pfmf(0, (unsigned long) pagebuf); + pfmf(0, pagebuf); check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION); report_prefix_pop(); } static void test_4k_key(void) { - union r1 r1; + union pfmf_r1 r1; union skey skey; report_prefix_push("4K"); r1.val = 0; r1.reg.sk = 1; - r1.reg.fsc = FSC_4K; + r1.reg.fsc = PFMF_FSC_4K; r1.reg.key = 0x30; - pfmf(r1.val, (unsigned long) pagebuf); + pfmf(r1.val, pagebuf); skey.val = get_storage_key((unsigned long) pagebuf); skey.val &= SKEY_ACC | SKEY_FP; report("set storage keys", skey.val == 0x30); @@ -80,15 +49,15 @@ static void test_1m_key(void) { int i; bool rp = true; - union r1 r1; + union pfmf_r1 r1; union skey skey; report_prefix_push("1M"); r1.val = 0; r1.reg.sk = 1; - r1.reg.fsc = FSC_1M; + r1.reg.fsc = PFMF_FSC_1M; r1.reg.key = 0x30; - pfmf(r1.val, (unsigned long) pagebuf); + pfmf(r1.val, pagebuf); for (i = 0; i < 256; i++) { skey.val = get_storage_key((unsigned long) pagebuf + i * PAGE_SIZE); skey.val &= SKEY_ACC | SKEY_FP; @@ -103,15 +72,15 @@ static void test_1m_key(void) static void test_4k_clear(void) { - union r1 r1; + union pfmf_r1 r1; r1.val = 0; r1.reg.cf = 1; - r1.reg.fsc = FSC_4K; + r1.reg.fsc = PFMF_FSC_4K; report_prefix_push("4K"); memset(pagebuf, 42, PAGE_SIZE); - pfmf(r1.val, (unsigned long) pagebuf); + pfmf(r1.val, pagebuf); report("clear memory", !memcmp(pagebuf, pagebuf + PAGE_SIZE, PAGE_SIZE)); report_prefix_pop(); } @@ -119,16 +88,16 @@ static void test_4k_clear(void) static void test_1m_clear(void) { int i; - union r1 r1; + union pfmf_r1 r1; unsigned long sum = 0; r1.val = 0; r1.reg.cf = 1; - r1.reg.fsc = FSC_1M; + r1.reg.fsc = PFMF_FSC_1M; report_prefix_push("1M"); memset(pagebuf, 42, PAGE_SIZE * 256); - pfmf(r1.val, (unsigned long) pagebuf); + pfmf(r1.val, pagebuf); for (i = 0; i < PAGE_SIZE * 256; i++) sum |= pagebuf[i]; report("clear memory", !sum); From patchwork Wed Sep 25 16:37:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161121 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 696F0112B for ; Wed, 25 Sep 2019 16:38:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 520A821D7B for ; Wed, 25 Sep 2019 16:38:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2439693AbfIYQiH (ORCPT ); Wed, 25 Sep 2019 12:38:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56692 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439641AbfIYQiH (ORCPT ); Wed, 25 Sep 2019 12:38:07 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D67333003AFE; Wed, 25 Sep 2019 16:38:06 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9772160E1C; Wed, 25 Sep 2019 16:37:57 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 07/17] s390x: Storage key library functions now take void ptr addresses Date: Wed, 25 Sep 2019 18:37:04 +0200 Message-Id: <20190925163714.27519-8-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 25 Sep 2019 16:38:06 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank Now all mem.h functions are consistent in how they take a memory address. Also we have less casting in the future. Signed-off-by: Janosch Frank Reviewed-by: Thomas Huth Message-Id: <20190828113615.4769-3-frankja@linux.ibm.com> Signed-off-by: Thomas Huth --- lib/s390x/asm/mem.h | 9 +++------ s390x/pfmf.c | 4 ++-- s390x/skey.c | 24 +++++++++++------------- 3 files changed, 16 insertions(+), 21 deletions(-) diff --git a/lib/s390x/asm/mem.h b/lib/s390x/asm/mem.h index 9b8fd70..c78bfa2 100644 --- a/lib/s390x/asm/mem.h +++ b/lib/s390x/asm/mem.h @@ -26,9 +26,7 @@ union skey { uint8_t val; }; -static inline void set_storage_key(unsigned long addr, - unsigned char skey, - int nq) +static inline void set_storage_key(void *addr, unsigned char skey, int nq) { if (nq) asm volatile(".insn rrf,0xb22b0000,%0,%1,8,0" @@ -37,8 +35,7 @@ static inline void set_storage_key(unsigned long addr, asm volatile("sske %0,%1" : : "d" (skey), "a" (addr)); } -static inline unsigned long set_storage_key_mb(unsigned long addr, - unsigned char skey) +static inline void *set_storage_key_mb(void *addr, unsigned char skey) { assert(test_facility(8)); @@ -47,7 +44,7 @@ static inline unsigned long set_storage_key_mb(unsigned long addr, return addr; } -static inline unsigned char get_storage_key(unsigned long addr) +static inline unsigned char get_storage_key(void *addr) { unsigned char skey; diff --git a/s390x/pfmf.c b/s390x/pfmf.c index 9986624..0b3e70b 100644 --- a/s390x/pfmf.c +++ b/s390x/pfmf.c @@ -39,7 +39,7 @@ static void test_4k_key(void) r1.reg.fsc = PFMF_FSC_4K; r1.reg.key = 0x30; pfmf(r1.val, pagebuf); - skey.val = get_storage_key((unsigned long) pagebuf); + skey.val = get_storage_key(pagebuf); skey.val &= SKEY_ACC | SKEY_FP; report("set storage keys", skey.val == 0x30); report_prefix_pop(); @@ -59,7 +59,7 @@ static void test_1m_key(void) r1.reg.key = 0x30; pfmf(r1.val, pagebuf); for (i = 0; i < 256; i++) { - skey.val = get_storage_key((unsigned long) pagebuf + i * PAGE_SIZE); + skey.val = get_storage_key(pagebuf + i * PAGE_SIZE); skey.val &= SKEY_ACC | SKEY_FP; if (skey.val != 0x30) { rp = false; diff --git a/s390x/skey.c b/s390x/skey.c index fd4fcc7..efc4eca 100644 --- a/s390x/skey.c +++ b/s390x/skey.c @@ -18,14 +18,12 @@ static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE * 2))); -const unsigned long page0 = (unsigned long)pagebuf; -const unsigned long page1 = (unsigned long)(pagebuf + PAGE_SIZE); static void test_set_mb(void) { union skey skey, ret1, ret2; - unsigned long addr = 0x10000 - 2 * PAGE_SIZE; - unsigned long end = 0x10000; + void *addr = (void *)0x10000 - 2 * PAGE_SIZE; + void *end = (void *)0x10000; /* Multi block support came with EDAT 1 */ if (!test_facility(8)) @@ -46,10 +44,10 @@ static void test_chg(void) union skey skey1, skey2; skey1.val = 0x30; - set_storage_key(page0, skey1.val, 0); - skey1.val = get_storage_key(page0); + set_storage_key(pagebuf, skey1.val, 0); + skey1.val = get_storage_key(pagebuf); pagebuf[0] = 3; - skey2.val = get_storage_key(page0); + skey2.val = get_storage_key(pagebuf); report("chg bit test", !skey1.str.ch && skey2.str.ch); } @@ -58,9 +56,9 @@ static void test_set(void) union skey skey, ret; skey.val = 0x30; - ret.val = get_storage_key(page0); - set_storage_key(page0, skey.val, 0); - ret.val = get_storage_key(page0); + ret.val = get_storage_key(pagebuf); + set_storage_key(pagebuf, skey.val, 0); + ret.val = get_storage_key(pagebuf); /* * For all set tests we only test the ACC and FP bits. RF and * CH are set by the machine for memory references and changes @@ -103,11 +101,11 @@ static void test_priv(void) report_prefix_push("sske"); expect_pgm_int(); enter_pstate(); - set_storage_key(page0, 0x30, 0); + set_storage_key(pagebuf, 0x30, 0); check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION); report_prefix_pop(); - skey.val = get_storage_key(page0); + skey.val = get_storage_key(pagebuf); report("skey did not change on exception", skey.str.acc != 3); report_prefix_push("iske"); @@ -117,7 +115,7 @@ static void test_priv(void) } else { expect_pgm_int(); enter_pstate(); - get_storage_key(page0); + get_storage_key(pagebuf); check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION); } report_prefix_pop(); From patchwork Wed Sep 25 16:37:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161123 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5103A1747 for ; Wed, 25 Sep 2019 16:38:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3989A21D7B for ; Wed, 25 Sep 2019 16:38:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2501933AbfIYQiO (ORCPT ); Wed, 25 Sep 2019 12:38:14 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36086 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2439662AbfIYQiO (ORCPT ); Wed, 25 Sep 2019 12:38:14 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4311089AC2; Wed, 25 Sep 2019 16:38:14 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2E49D60CD0; Wed, 25 Sep 2019 16:38:07 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 08/17] s390x: Bump march to zEC12 Date: Wed, 25 Sep 2019 18:37:05 +0200 Message-Id: <20190925163714.27519-9-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 25 Sep 2019 16:38:14 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank TCG has majored a lot and can now support many newer instructions, so there's no need to compile with the ancient march z900. Signed-off-by: Janosch Frank Tested-by: Thomas Huth Message-Id: <20190828113615.4769-4-frankja@linux.ibm.com> Signed-off-by: Thomas Huth --- s390x/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/s390x/Makefile b/s390x/Makefile index 76db0bb..07bd353 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -25,7 +25,7 @@ CFLAGS += -std=gnu99 CFLAGS += -ffreestanding CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/s390x -I lib CFLAGS += -O2 -CFLAGS += -march=z900 +CFLAGS += -march=zEC12 CFLAGS += -fno-delete-null-pointer-checks LDFLAGS += -nostdlib -Wl,--build-id=none From patchwork Wed Sep 25 16:37:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161125 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0DFB3112B for ; Wed, 25 Sep 2019 16:38:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EA92D21D7C for ; Wed, 25 Sep 2019 16:38:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2505135AbfIYQiU (ORCPT ); Wed, 25 Sep 2019 12:38:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36104 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2501919AbfIYQiU (ORCPT ); Wed, 25 Sep 2019 12:38:20 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 475E389AC6; Wed, 25 Sep 2019 16:38:19 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 948C160CD0; Wed, 25 Sep 2019 16:38:14 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 09/17] s390x: Add storage key removal facility Date: Wed, 25 Sep 2019 18:37:06 +0200 Message-Id: <20190925163714.27519-10-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 25 Sep 2019 16:38:19 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank The storage key removal facility (stfle bit 169) makes all key related instructions result in a special operation exception if they handle a key. Let's make sure that the skey and pfmf tests only run non key code (pfmf) or not at all (skey). Also let's test this new facility. As lots of instructions are affected by this, only some of them are tested for now. Signed-off-by: Janosch Frank Message-Id: <20190828113615.4769-5-frankja@linux.ibm.com> Signed-off-by: Thomas Huth --- s390x/Makefile | 1 + s390x/pfmf.c | 10 ++++ s390x/skey.c | 5 ++ s390x/skrf.c | 128 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 s390x/skrf.c diff --git a/s390x/Makefile b/s390x/Makefile index 07bd353..96033dd 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -14,6 +14,7 @@ tests += $(TEST_DIR)/iep.elf tests += $(TEST_DIR)/cpumodel.elf tests += $(TEST_DIR)/diag288.elf tests += $(TEST_DIR)/stsi.elf +tests += $(TEST_DIR)/skrf.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binary diff --git a/s390x/pfmf.c b/s390x/pfmf.c index 0b3e70b..e81f7c5 100644 --- a/s390x/pfmf.c +++ b/s390x/pfmf.c @@ -34,6 +34,10 @@ static void test_4k_key(void) union skey skey; report_prefix_push("4K"); + if (test_facility(169)) { + report_skip("storage key removal facility is active"); + goto out; + } r1.val = 0; r1.reg.sk = 1; r1.reg.fsc = PFMF_FSC_4K; @@ -42,6 +46,7 @@ static void test_4k_key(void) skey.val = get_storage_key(pagebuf); skey.val &= SKEY_ACC | SKEY_FP; report("set storage keys", skey.val == 0x30); +out: report_prefix_pop(); } @@ -53,6 +58,10 @@ static void test_1m_key(void) union skey skey; report_prefix_push("1M"); + if (test_facility(169)) { + report_skip("storage key removal facility is active"); + goto out; + } r1.val = 0; r1.reg.sk = 1; r1.reg.fsc = PFMF_FSC_1M; @@ -67,6 +76,7 @@ static void test_1m_key(void) } } report("set storage keys", rp); +out: report_prefix_pop(); } diff --git a/s390x/skey.c b/s390x/skey.c index efc4eca..5020e99 100644 --- a/s390x/skey.c +++ b/s390x/skey.c @@ -126,10 +126,15 @@ static void test_priv(void) int main(void) { report_prefix_push("skey"); + if (test_facility(169)) { + report_skip("storage key removal facility is active"); + goto done; + } test_priv(); test_set(); test_set_mb(); test_chg(); +done: report_prefix_pop(); return report_summary(); } diff --git a/s390x/skrf.c b/s390x/skrf.c new file mode 100644 index 0000000..e77ff35 --- /dev/null +++ b/s390x/skrf.c @@ -0,0 +1,128 @@ +/* + * Storage key removal facility tests + * + * Copyright (c) 2019 IBM Corp + * + * Authors: + * Janosch Frank + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2. + */ +#include +#include +#include +#include +#include +#include + +static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE * 2))); + +static void test_facilities(void) +{ + report_prefix_push("facilities"); + report("!10", !test_facility(10)); + report("!14", !test_facility(14)); + report("!66", !test_facility(66)); + report("!145", !test_facility(145)); + report("!149", !test_facility(140)); + report_prefix_pop(); +} + +static void test_skey(void) +{ + report_prefix_push("sske"); + expect_pgm_int(); + set_storage_key(pagebuf, 0x30, 0); + check_pgm_int_code(PGM_INT_CODE_SPECIAL_OPERATION); + expect_pgm_int(); + report_prefix_pop(); + report_prefix_push("iske"); + get_storage_key(pagebuf); + check_pgm_int_code(PGM_INT_CODE_SPECIAL_OPERATION); + report_prefix_pop(); +} + +static void test_pfmf(void) +{ + union pfmf_r1 r1; + + report_prefix_push("pfmf"); + r1.val = 0; + r1.reg.sk = 1; + r1.reg.fsc = PFMF_FSC_4K; + r1.reg.key = 0x30; + expect_pgm_int(); + pfmf(r1.val, pagebuf); + check_pgm_int_code(PGM_INT_CODE_SPECIAL_OPERATION); + report_prefix_pop(); +} + +static void test_psw_key(void) +{ + uint64_t psw_mask = extract_psw_mask() | 0xF0000000000000UL; + + report_prefix_push("psw key"); + expect_pgm_int(); + load_psw_mask(psw_mask); + check_pgm_int_code(PGM_INT_CODE_SPECIAL_OPERATION); + report_prefix_pop(); +} + +static void test_mvcos(void) +{ + uint64_t r3 = 64; + uint8_t *src = pagebuf; + uint8_t *dst = pagebuf + PAGE_SIZE; + /* K bit set, as well as keys */ + register unsigned long oac asm("0") = 0xf002f002; + + report_prefix_push("mvcos"); + expect_pgm_int(); + asm volatile("mvcos %[dst],%[src],%[len]" + : [dst] "+Q" (*(dst)) + : [src] "Q" (*(src)), [len] "d" (r3), "d" (oac) + : "cc", "memory"); + check_pgm_int_code(PGM_INT_CODE_SPECIAL_OPERATION); + report_prefix_pop(); +} + +static void test_spka(void) +{ + report_prefix_push("spka"); + expect_pgm_int(); + asm volatile("spka 0xf0(0)\n"); + check_pgm_int_code(PGM_INT_CODE_SPECIAL_OPERATION); + report_prefix_pop(); +} + +static void test_tprot(void) +{ + report_prefix_push("tprot"); + expect_pgm_int(); + asm volatile("tprot %[addr],0xf0(0)\n" + : : [addr] "a" (pagebuf) : ); + check_pgm_int_code(PGM_INT_CODE_SPECIAL_OPERATION); + report_prefix_pop(); +} + +int main(void) +{ + report_prefix_push("skrf"); + if (!test_facility(169)) { + report_skip("storage key removal facility not available\n"); + goto done; + } + + test_facilities(); + test_skey(); + test_pfmf(); + test_psw_key(); + test_mvcos(); + test_spka(); + test_tprot(); + +done: + report_prefix_pop(); + return report_summary(); +} From patchwork Wed Sep 25 16:37:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161127 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7BD19112B for ; Wed, 25 Sep 2019 16:38:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5A36621D7A for ; Wed, 25 Sep 2019 16:38:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389657AbfIYQiV (ORCPT ); Wed, 25 Sep 2019 12:38:21 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39278 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728465AbfIYQiV (ORCPT ); Wed, 25 Sep 2019 12:38:21 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1F43D7FDCA; Wed, 25 Sep 2019 16:38:21 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id A326D60BF1; Wed, 25 Sep 2019 16:38:19 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 10/17] s390x: Fix stsi unaligned test and add selector tests Date: Wed, 25 Sep 2019 18:37:07 +0200 Message-Id: <20190925163714.27519-11-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Wed, 25 Sep 2019 16:38:21 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank Alignment and selectors test order is not specified and so, if you have an unaligned address and invalid selectors it's up to the hypervisor to decide which error is presented. Let's add valid selectors to the unalignmnet test and add selector tests. Signed-off-by: Janosch Frank Reviewed-by: Christian Borntraeger Acked-by: David Hildenbrand Signed-off-by: Thomas Huth --- s390x/stsi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/s390x/stsi.c b/s390x/stsi.c index 7232cb0..c5bd0a2 100644 --- a/s390x/stsi.c +++ b/s390x/stsi.c @@ -35,7 +35,7 @@ static void test_specs(void) report_prefix_push("unaligned"); expect_pgm_int(); - stsi(pagebuf + 42, 1, 0, 0); + stsi(pagebuf + 42, 1, 1, 1); check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); report_prefix_pop(); @@ -71,6 +71,8 @@ static inline unsigned long stsi_get_fc(void *addr) static void test_fc(void) { report("invalid fc", stsi(pagebuf, 7, 0, 0) == 3); + report("invalid selector 1", stsi(pagebuf, 1, 0, 1) == 3); + report("invalid selector 2", stsi(pagebuf, 1, 1, 0) == 3); report("query fc >= 2", stsi_get_fc(pagebuf) >= 2); } From patchwork Wed Sep 25 16:37:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161129 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D7874112B for ; Wed, 25 Sep 2019 16:38:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C0AFF21D7C for ; Wed, 25 Sep 2019 16:38:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2505123AbfIYQi0 (ORCPT ); Wed, 25 Sep 2019 12:38:26 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55268 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2502032AbfIYQiZ (ORCPT ); Wed, 25 Sep 2019 12:38:25 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 497C5307D985; Wed, 25 Sep 2019 16:38:25 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7D29760BF1; Wed, 25 Sep 2019 16:38:21 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 11/17] s390x: Use interrupts in SCLP and add locking Date: Wed, 25 Sep 2019 18:37:08 +0200 Message-Id: <20190925163714.27519-12-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 25 Sep 2019 16:38:25 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank We need to properly implement interrupt handling for SCLP, because on z/VM and LPAR SCLP calls are not synchronous! Also with smp CPUs have to compete for sclp. Let's add some locking, so they execute sclp calls in an orderly fashion and don't compete for the data buffer. Signed-off-by: Janosch Frank Reviewed-by: Thomas Huth Message-Id: <20190920080356.1948-2-frankja@linux.ibm.com> Acked-by: David Hildenbrand Signed-off-by: Thomas Huth --- lib/s390x/asm/interrupt.h | 2 ++ lib/s390x/interrupt.c | 12 +++++++-- lib/s390x/sclp-console.c | 2 ++ lib/s390x/sclp.c | 55 +++++++++++++++++++++++++++++++++++++-- lib/s390x/sclp.h | 3 +++ 5 files changed, 70 insertions(+), 4 deletions(-) diff --git a/lib/s390x/asm/interrupt.h b/lib/s390x/asm/interrupt.h index 013709f..f485e96 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..7832711 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/sclp-console.c b/lib/s390x/sclp-console.c index bc01f41..a5ef45f 100644 --- a/lib/s390x/sclp-console.c +++ b/lib/s390x/sclp-console.c @@ -17,6 +17,7 @@ static void sclp_set_write_mask(void) { WriteEventMask *sccb = (void *)_sccb; + sclp_mark_busy(); sccb->h.length = sizeof(WriteEventMask); sccb->mask_length = sizeof(unsigned int); sccb->receive_mask = SCLP_EVENT_MASK_MSG_ASCII; @@ -37,6 +38,7 @@ void sclp_print(const char *str) int len = strlen(str); WriteEventData *sccb = (void *)_sccb; + sclp_mark_busy(); sccb->h.length = sizeof(WriteEventData) + len; sccb->h.function_code = SCLP_FC_NORMAL_WRITE; sccb->ebh.length = sizeof(EventBufferHeader) + len; diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c index b60f7a4..56fca0c 100644 --- a/lib/s390x/sclp.c +++ b/lib/s390x/sclp.c @@ -14,6 +14,8 @@ #include #include #include +#include +#include #include "sclp.h" #include #include @@ -25,6 +27,8 @@ static uint64_t max_ram_size; static uint64_t ram_size; char _sccb[PAGE_SIZE] __attribute__((__aligned__(4096))); +static volatile bool sclp_busy; +static struct spinlock sclp_lock; static void mem_init(phys_addr_t mem_end) { @@ -41,17 +45,62 @@ static void mem_init(phys_addr_t mem_end) page_alloc_ops_enable(); } +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); + spin_lock(&sclp_lock); + sclp_busy = false; + spin_unlock(&sclp_lock); +} + +void sclp_wait_busy(void) +{ + while (sclp_busy) + mb(); +} + +void sclp_mark_busy(void) +{ + /* + * With multiple CPUs we might need to wait for another CPU's + * request before grabbing the busy indication. + */ + while (true) { + sclp_wait_busy(); + spin_lock(&sclp_lock); + if (!sclp_busy) { + sclp_busy = true; + spin_unlock(&sclp_lock); + return; + } + spin_unlock(&sclp_lock); + } +} + static void sclp_read_scp_info(ReadInfo *ri, int length) { unsigned int commands[] = { SCLP_CMDW_READ_SCP_INFO_FORCED, SCLP_CMDW_READ_SCP_INFO }; - int i; + int i, cc; for (i = 0; i < ARRAY_SIZE(commands); i++) { + sclp_mark_busy(); memset(&ri->h, 0, sizeof(ri->h)); ri->h.length = length; - if (sclp_service_call(commands[i], ri)) + cc = sclp_service_call(commands[i], ri); + if (cc) break; if (ri->h.response_code == SCLP_RC_NORMAL_READ_COMPLETION) return; @@ -66,12 +115,14 @@ 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"); + sclp_wait_busy(); if (cc == 3) return -1; if (cc == 2) diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h index 583c4e5..63cf609 100644 --- a/lib/s390x/sclp.h +++ b/lib/s390x/sclp.h @@ -213,6 +213,9 @@ typedef struct ReadEventData { } __attribute__((packed)) ReadEventData; extern char _sccb[]; +void sclp_handle_ext(void); +void sclp_wait_busy(void); +void sclp_mark_busy(void); void sclp_console_setup(void); void sclp_print(const char *str); int sclp_service_call(unsigned int command, void *sccb); From patchwork Wed Sep 25 16:37:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161131 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E9E4112B for ; Wed, 25 Sep 2019 16:38:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 6CD4221D7C for ; Wed, 25 Sep 2019 16:38:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390796AbfIYQi1 (ORCPT ); Wed, 25 Sep 2019 12:38:27 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53048 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2505145AbfIYQi1 (ORCPT ); Wed, 25 Sep 2019 12:38:27 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C07668BA2DA; Wed, 25 Sep 2019 16:38:26 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9290660BF1; Wed, 25 Sep 2019 16:38:25 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 12/17] s390x: Add linemode console Date: Wed, 25 Sep 2019 18:37:09 +0200 Message-Id: <20190925163714.27519-13-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.68]); Wed, 25 Sep 2019 16:38:26 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank z/VM isn't fond of vt220, so we need line mode when running under z/VM. Signed-off-by: Janosch Frank Acked-by: David Hildenbrand Tested-by: Thomas Huth Message-Id: <20190920080356.1948-3-frankja@linux.ibm.com> Signed-off-by: Thomas Huth --- lib/s390x/sclp-console.c | 181 +++++++++++++++++++++++++++++++++++---- lib/s390x/sclp.h | 55 +++++++++++- 2 files changed, 218 insertions(+), 18 deletions(-) diff --git a/lib/s390x/sclp-console.c b/lib/s390x/sclp-console.c index a5ef45f..19416b5 100644 --- a/lib/s390x/sclp-console.c +++ b/lib/s390x/sclp-console.c @@ -11,21 +11,165 @@ #include #include #include +#include +#include #include "sclp.h" +/* + * 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 void sclp_print_ascii(const char *str) +{ + int len = strlen(str); + WriteEventData *sccb = (void *)_sccb; + + sclp_mark_busy(); + memset(sccb, 0, sizeof(*sccb)); + sccb->h.length = offsetof(WriteEventData, msg) + 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->msg, 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 WriteEventData *sccb; + struct mdb *mdb; + struct mto *mto; + struct go *go; + + sclp_mark_busy(); + sccb = (struct WriteEventData *) _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; + 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->h.length = len - offsetof(struct WriteEventData, h); + sccb->h.function_code = SCLP_FC_NORMAL_WRITE; + sccb->ebh.type = EVTYP_MSG; + sccb->ebh.length = len - offsetof(struct WriteEventData, ebh); + mdb = &sccb->msg.mdb; + mdb->header.type = 1; + mdb->header.tag = 0xD4C4C240; + mdb->header.revision_code = 1; + mdb->header.length = len - offsetof(struct WriteEventData, 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 void sclp_set_write_mask(void) { WriteEventMask *sccb = (void *)_sccb; sclp_mark_busy(); + 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 = SCLP_FC_NORMAL_WRITE; + 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); + assert(sccb->h.response_code == SCLP_RC_NORMAL_COMPLETION); } void sclp_console_setup(void) @@ -35,16 +179,19 @@ void sclp_console_setup(void) void sclp_print(const char *str) { - int len = strlen(str); - WriteEventData *sccb = (void *)_sccb; - - sclp_mark_busy(); - 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); + /* + * 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. + */ + if (strlen(str) > (PAGE_SIZE / 2)) { + sclp_print_ascii("Warning: Printing is limited to 2KB of data."); + sclp_print_lm("Warning: Printing is limited to 2KB of data."); + return; + } + sclp_print_ascii(str); + sclp_print_lm(str); } diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h index 63cf609..98c482a 100644 --- a/lib/s390x/sclp.h +++ b/lib/s390x/sclp.h @@ -179,6 +179,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 @@ -193,6 +194,55 @@ typedef struct WriteEventMask { uint32_t receive_mask; } __attribute__((packed)) WriteEventMask; +#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)); + typedef struct EventBufferHeader { uint16_t length; uint8_t type; @@ -203,7 +253,10 @@ typedef struct EventBufferHeader { typedef struct WriteEventData { SCCBHeader h; EventBufferHeader ebh; - char data[0]; + union { + char data[0]; + struct mdb mdb; + } msg; } __attribute__((packed)) WriteEventData; typedef struct ReadEventData { From patchwork Wed Sep 25 16:37:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161133 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D5D24112B for ; Wed, 25 Sep 2019 16:38:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id BE70221D7B for ; Wed, 25 Sep 2019 16:38:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391715AbfIYQi3 (ORCPT ); Wed, 25 Sep 2019 12:38:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57278 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390948AbfIYQi2 (ORCPT ); Wed, 25 Sep 2019 12:38:28 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F93A368CF; Wed, 25 Sep 2019 16:38:28 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 16E2260BF1; Wed, 25 Sep 2019 16:38:26 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 13/17] s390x: Add linemode buffer to fix newline on every print Date: Wed, 25 Sep 2019 18:37:10 +0200 Message-Id: <20190925163714.27519-14-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 25 Sep 2019 16:38:28 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank Linemode seems to add a newline for each sent message which makes reading rather hard. Hence we add a small buffer and only print if it's full or a newline is encountered. Signed-off-by: Janosch Frank Reviewed-by: Thomas Huth Acked-by: David Hildenbrand Message-Id: <20190920112345.2359-1-frankja@linux.ibm.com> Signed-off-by: Thomas Huth --- lib/s390x/sclp-console.c | 43 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/lib/s390x/sclp-console.c b/lib/s390x/sclp-console.c index 19416b5..6067a1a 100644 --- a/lib/s390x/sclp-console.c +++ b/lib/s390x/sclp-console.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "sclp.h" /* @@ -87,6 +88,10 @@ static uint8_t _ascebc[256] = { 0x90, 0x3F, 0x3F, 0x3F, 0x3F, 0xEA, 0x3F, 0xFF }; +static char lm_buff[120]; +static unsigned char lm_buff_off; +static struct spinlock lm_buff_lock; + static void sclp_print_ascii(const char *str) { int len = strlen(str); @@ -103,10 +108,10 @@ static void sclp_print_ascii(const char *str) sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb); } -static void sclp_print_lm(const char *str) +static void lm_print(const char *buff, int len) { unsigned char *ptr, *end, ch; - unsigned int count, offset, len; + unsigned int count, offset; struct WriteEventData *sccb; struct mdb *mdb; struct mto *mto; @@ -117,11 +122,10 @@ static void sclp_print_lm(const char *str) 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++]; + ch = buff[offset++]; if (ch == 0x0a || ptr + count > end) break; ptr[count] = _ascebc[ch]; @@ -148,6 +152,37 @@ static void sclp_print_lm(const char *str) sclp_service_call(SCLP_CMD_WRITE_EVENT_DATA, sccb); } + +/* + * In contrast to the ascii console, linemode produces a new + * line with every write of data. The report() function uses + * several printf() calls to generate a line of data which + * would all end up on different lines. + * + * Hence we buffer here until we encounter a \n or the buffer + * is full. That means that linemode output can look a bit + * different from ascii and that it takes a bit longer for + * lines to appear. + */ +static void sclp_print_lm(const char *str) +{ + int i; + const int len = strlen(str); + + spin_lock(&lm_buff_lock); + + for (i = 0; i < len; i++) { + lm_buff[lm_buff_off++] = str[i]; + + /* Buffer full or newline? */ + if (str[i] == '\n' || lm_buff_off == (ARRAY_SIZE(lm_buff) - 1)) { + lm_print(lm_buff, lm_buff_off); + lm_buff_off = 0; + } + } + spin_unlock(&lm_buff_lock); +} + /* * SCLP needs to be initialized by setting a send and receive mask, * indicating which messages the control program (we) want(s) to From patchwork Wed Sep 25 16:37:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161135 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5BC061747 for ; Wed, 25 Sep 2019 16:38:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2FC4C21D7C for ; Wed, 25 Sep 2019 16:38:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391803AbfIYQib (ORCPT ); Wed, 25 Sep 2019 12:38:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:54690 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728465AbfIYQib (ORCPT ); Wed, 25 Sep 2019 12:38:31 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 5663630609BA; Wed, 25 Sep 2019 16:38:30 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id D7E1260F88; Wed, 25 Sep 2019 16:38:28 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 14/17] s390x: Add initial smp code Date: Wed, 25 Sep 2019 18:37:11 +0200 Message-Id: <20190925163714.27519-15-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Wed, 25 Sep 2019 16:38:30 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank Let's add a rudimentary SMP library, which will scan for cpus and has helper functions that manage the cpu state. Signed-off-by: Janosch Frank Message-Id: <20190923141558.3032-1-frankja@linux.ibm.com> Reviewed-by: Thomas Huth Signed-off-by: Thomas Huth --- lib/s390x/asm/arch_def.h | 8 ++ lib/s390x/asm/sigp.h | 28 ++++- lib/s390x/io.c | 5 +- lib/s390x/sclp.h | 1 + lib/s390x/smp.c | 252 +++++++++++++++++++++++++++++++++++++++ lib/s390x/smp.h | 53 ++++++++ s390x/Makefile | 1 + s390x/cstart64.S | 7 ++ 8 files changed, 349 insertions(+), 6 deletions(-) create mode 100644 lib/s390x/smp.c create mode 100644 lib/s390x/smp.h diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h index 5f8f45e..d5a7f51 100644 --- a/lib/s390x/asm/arch_def.h +++ b/lib/s390x/asm/arch_def.h @@ -157,6 +157,14 @@ struct cpuid { uint64_t reserved : 15; }; +static inline unsigned short stap(void) +{ + unsigned short cpu_address; + + asm volatile("stap %0" : "=Q" (cpu_address)); + return cpu_address; +} + static inline int tprot(unsigned long addr) { int cc; diff --git a/lib/s390x/asm/sigp.h b/lib/s390x/asm/sigp.h index fbd94fc..2d52313 100644 --- a/lib/s390x/asm/sigp.h +++ b/lib/s390x/asm/sigp.h @@ -46,14 +46,32 @@ #ifndef __ASSEMBLER__ -static inline void sigp_stop(void) + +static inline int sigp(uint16_t addr, uint8_t order, unsigned long parm, + uint32_t *status) { - register unsigned long status asm ("1") = 0; - register unsigned long cpu asm ("2") = 0; + register unsigned long reg1 asm ("1") = parm; + int cc; asm volatile( - " sigp %0,%1,0(%2)\n" - : "+d" (status) : "d" (cpu), "d" (SIGP_STOP) : "cc"); + " sigp %1,%2,0(%3)\n" + " ipm %0\n" + " srl %0,28\n" + : "=d" (cc), "+d" (reg1) : "d" (addr), "a" (order) : "cc"); + if (status) + *status = reg1; + return cc; +} + +static inline int sigp_retry(uint16_t addr, uint8_t order, unsigned long parm, + uint32_t *status) +{ + int cc; + + do { + cc = sigp(addr, order, parm, status); + } while (cc == 2); + return cc; } #endif /* __ASSEMBLER__ */ diff --git a/lib/s390x/io.c b/lib/s390x/io.c index becadfc..32f09b5 100644 --- a/lib/s390x/io.c +++ b/lib/s390x/io.c @@ -16,6 +16,7 @@ #include #include #include "sclp.h" +#include "smp.h" extern char ipl_args[]; uint8_t stfl_bytes[NR_STFL_BYTES] __attribute__((aligned(8))); @@ -37,12 +38,14 @@ void setup(void) setup_facilities(); sclp_console_setup(); sclp_memory_setup(); + smp_setup(); } void exit(int code) { + smp_teardown(); printf("\nEXIT: STATUS=%d\n", ((code) << 1) | 1); while (1) { - sigp_stop(); + sigp(0, SIGP_STOP, 0, NULL); } } diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h index 98c482a..4e69845 100644 --- a/lib/s390x/sclp.h +++ b/lib/s390x/sclp.h @@ -19,6 +19,7 @@ #define SCLP_CMD_CODE_MASK 0xffff00ff /* SCLP command codes */ +#define SCLP_READ_CPU_INFO 0x00010001 #define SCLP_CMDW_READ_SCP_INFO 0x00020001 #define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001 #define SCLP_READ_STORAGE_ELEMENT_INFO 0x00040001 diff --git a/lib/s390x/smp.c b/lib/s390x/smp.c new file mode 100644 index 0000000..7602886 --- /dev/null +++ b/lib/s390x/smp.c @@ -0,0 +1,252 @@ +/* + * s390x smp + * Based on Linux's arch/s390/kernel/smp.c and + * arch/s390/include/asm/sigp.h + * + * Copyright (c) 2019 IBM Corp + * + * Authors: + * Janosch Frank + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2. + */ +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#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; + +extern void smp_cpu_setup_state(void); + +int smp_query_num_cpus(void) +{ + struct ReadCpuInfo *info = (void *)cpu_info_buffer; + return info->nr_configured; +} + +struct cpu *smp_cpu_from_addr(uint16_t addr) +{ + int i, num = smp_query_num_cpus(); + + for (i = 0; i < num; i++) { + if (cpus[i].addr == addr) + return &cpus[i]; + } + return NULL; +} + +bool smp_cpu_stopped(uint16_t addr) +{ + uint32_t status; + + if (sigp(addr, SIGP_SENSE, 0, &status) != SIGP_CC_STATUS_STORED) + return false; + return !!(status & (SIGP_STATUS_CHECK_STOP|SIGP_STATUS_STOPPED)); +} + +bool smp_cpu_running(uint16_t addr) +{ + if (sigp(addr, SIGP_SENSE_RUNNING, 0, NULL) != SIGP_CC_STATUS_STORED) + return true; + /* Status stored condition code is equivalent to cpu not running. */ + return false; +} + +static int smp_cpu_stop_nolock(uint16_t addr, bool store) +{ + struct cpu *cpu; + uint8_t order = store ? SIGP_STOP_AND_STORE_STATUS : SIGP_STOP; + + cpu = smp_cpu_from_addr(addr); + if (!cpu || cpu == cpu0) + return -1; + + if (sigp_retry(addr, order, 0, NULL)) + return -1; + + while (!smp_cpu_stopped(addr)) + mb(); + cpu->active = false; + return 0; +} + +int smp_cpu_stop(uint16_t addr) +{ + int rc; + + spin_lock(&lock); + rc = smp_cpu_stop_nolock(addr, false); + spin_unlock(&lock); + return rc; +} + +int smp_cpu_stop_store_status(uint16_t addr) +{ + int rc; + + spin_lock(&lock); + rc = smp_cpu_stop_nolock(addr, true); + spin_unlock(&lock); + return rc; +} + +int smp_cpu_restart(uint16_t addr) +{ + int rc = -1; + struct cpu *cpu; + + spin_lock(&lock); + cpu = smp_cpu_from_addr(addr); + if (cpu) { + rc = sigp(addr, SIGP_RESTART, 0, NULL); + cpu->active = true; + } + spin_unlock(&lock); + return rc; +} + +int smp_cpu_start(uint16_t addr, struct psw psw) +{ + int rc = -1; + struct cpu *cpu; + struct lowcore *lc; + + spin_lock(&lock); + cpu = smp_cpu_from_addr(addr); + if (cpu) { + lc = cpu->lowcore; + lc->restart_new_psw.mask = psw.mask; + lc->restart_new_psw.addr = psw.addr; + rc = sigp(addr, SIGP_RESTART, 0, NULL); + } + spin_unlock(&lock); + return rc; +} + +int smp_cpu_destroy(uint16_t addr) +{ + struct cpu *cpu; + int rc; + + spin_lock(&lock); + rc = smp_cpu_stop_nolock(addr, false); + if (!rc) { + cpu = smp_cpu_from_addr(addr); + free_pages(cpu->lowcore, 2 * PAGE_SIZE); + free_pages(cpu->stack, 4 * PAGE_SIZE); + cpu->lowcore = (void *)-1UL; + cpu->stack = (void *)-1UL; + } + spin_unlock(&lock); + return rc; +} + +int smp_cpu_setup(uint16_t addr, struct psw psw) +{ + struct lowcore *lc; + struct cpu *cpu; + int rc = -1; + + spin_lock(&lock); + + if (!cpus) + goto out; + + cpu = smp_cpu_from_addr(addr); + + if (!cpu || cpu->active) + goto out; + + sigp_retry(cpu->addr, SIGP_INITIAL_CPU_RESET, 0, NULL); + + lc = alloc_pages(1); + cpu->lowcore = lc; + memset(lc, 0, PAGE_SIZE * 2); + sigp_retry(cpu->addr, SIGP_SET_PREFIX, (unsigned long )lc, NULL); + + /* Copy all exception psws. */ + memcpy(lc, cpu0->lowcore, 512); + + /* Setup stack */ + cpu->stack = (uint64_t *)alloc_pages(2); + + /* Start without DAT and any other mask bits. */ + cpu->lowcore->sw_int_grs[14] = psw.addr; + cpu->lowcore->sw_int_grs[15] = (uint64_t)cpu->stack + (PAGE_SIZE * 4); + lc->restart_new_psw.mask = 0x0000000180000000UL; + lc->restart_new_psw.addr = (uint64_t)smp_cpu_setup_state; + lc->sw_int_cr0 = 0x0000000000040000UL; + + /* Start processing */ + rc = sigp_retry(cpu->addr, SIGP_RESTART, 0, NULL); + if (!rc) + cpu->active = true; + +out: + spin_unlock(&lock); + return rc; +} + +/* + * Disregarding state, stop all cpus that once were online except for + * calling cpu. + */ +void smp_teardown(void) +{ + int i = 0; + uint16_t this_cpu = stap(); + struct ReadCpuInfo *info = (void *)cpu_info_buffer; + + spin_lock(&lock); + for (; i < info->nr_configured; i++) { + if (cpus[i].active && + cpus[i].addr != this_cpu) { + sigp_retry(cpus[i].addr, SIGP_STOP, 0, NULL); + } + } + spin_unlock(&lock); +} + +/*Expected to be called from boot cpu */ +extern uint64_t *stackptr; +void smp_setup(void) +{ + int i = 0; + unsigned short cpu0_addr = stap(); + struct ReadCpuInfo *info = (void *)cpu_info_buffer; + + spin_lock(&lock); + sclp_mark_busy(); + info->h.length = PAGE_SIZE; + sclp_service_call(SCLP_READ_CPU_INFO, cpu_info_buffer); + + 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[i].active = false; + if (info->entries[i].address == cpu0_addr) { + cpu0 = &cpus[i]; + cpu0->stack = stackptr; + cpu0->lowcore = (void *)0; + cpu0->active = true; + } + } + spin_unlock(&lock); +} diff --git a/lib/s390x/smp.h b/lib/s390x/smp.h new file mode 100644 index 0000000..ce63a89 --- /dev/null +++ b/lib/s390x/smp.h @@ -0,0 +1,53 @@ +/* + * s390x smp + * + * Copyright (c) 2019 IBM Corp + * + * Authors: + * Janosch Frank + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2. + */ +#ifndef SMP_H +#define SMP_H + +#include + +struct cpu { + struct lowcore *lowcore; + uint64_t *stack; + uint16_t addr; + bool active; +}; + +struct cpu_status { + uint64_t fprs[16]; /* 0x0000 */ + uint64_t grs[16]; /* 0x0080 */ + struct psw psw; /* 0x0100 */ + uint8_t pad_0x0110[0x0118 - 0x0110]; /* 0x0110 */ + uint32_t prefix; /* 0x0118 */ + uint32_t fpc; /* 0x011c */ + uint8_t pad_0x0120[0x0124 - 0x0120]; /* 0x0120 */ + uint32_t todpr; /* 0x0124 */ + uint64_t cputm; /* 0x0128 */ + uint64_t ckc; /* 0x0130 */ + uint8_t pad_0x0138[0x0140 - 0x0138]; /* 0x0138 */ + uint32_t ars[16]; /* 0x0140 */ + uint64_t crs[16]; /* 0x0384 */ +}; + +int smp_query_num_cpus(void); +struct cpu *smp_cpu_from_addr(uint16_t addr); +bool smp_cpu_stopped(uint16_t addr); +bool smp_cpu_running(uint16_t addr); +int smp_cpu_restart(uint16_t addr); +int smp_cpu_start(uint16_t addr, struct psw psw); +int smp_cpu_stop(uint16_t addr); +int smp_cpu_stop_store_status(uint16_t addr); +int smp_cpu_destroy(uint16_t addr); +int smp_cpu_setup(uint16_t addr, struct psw psw); +void smp_teardown(void); +void smp_setup(void); + +#endif diff --git a/s390x/Makefile b/s390x/Makefile index 96033dd..d83dd0b 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -48,6 +48,7 @@ cflatobjs += lib/s390x/sclp.o cflatobjs += lib/s390x/sclp-console.o cflatobjs += lib/s390x/interrupt.o cflatobjs += lib/s390x/mmu.o +cflatobjs += lib/s390x/smp.o OBJDIRS += lib/s390x diff --git a/s390x/cstart64.S b/s390x/cstart64.S index 36f7cab..5dc1577 100644 --- a/s390x/cstart64.S +++ b/s390x/cstart64.S @@ -172,6 +172,13 @@ diag308_load_reset: lhi %r2, 1 br %r14 +.globl smp_cpu_setup_state +smp_cpu_setup_state: + xgr %r1, %r1 + lmg %r0, %r15, GEN_LC_SW_INT_GRS + lctlg %c0, %c0, GEN_LC_SW_INT_CR0 + br %r14 + pgm_int: SAVE_REGS brasl %r14, handle_pgm_int From patchwork Wed Sep 25 16:37:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161137 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1604B1747 for ; Wed, 25 Sep 2019 16:38:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F22EF21D7B for ; Wed, 25 Sep 2019 16:38:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391867AbfIYQid (ORCPT ); Wed, 25 Sep 2019 12:38:33 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38138 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391845AbfIYQic (ORCPT ); Wed, 25 Sep 2019 12:38:32 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 17EE018CB8E7; Wed, 25 Sep 2019 16:38:32 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id B0E1960BF1; Wed, 25 Sep 2019 16:38:30 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 15/17] s390x: Prepare for external calls Date: Wed, 25 Sep 2019 18:37:12 +0200 Message-Id: <20190925163714.27519-16-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Wed, 25 Sep 2019 16:38:32 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank With SMP we also get new external interrupts like external call and emergency call. Let's make them known. Signed-off-by: Janosch Frank Reviewed-by: Thomas Huth Message-Id: <20190920080356.1948-6-frankja@linux.ibm.com> Reviewed-by: David Hildenbrand Signed-off-by: Thomas Huth --- lib/s390x/asm/arch_def.h | 5 +++++ lib/s390x/asm/interrupt.h | 3 +++ lib/s390x/interrupt.c | 23 +++++++++++++++++++---- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h index d5a7f51..96cca2e 100644 --- a/lib/s390x/asm/arch_def.h +++ b/lib/s390x/asm/arch_def.h @@ -19,6 +19,11 @@ struct psw { #define PSW_MASK_DAT 0x0400000000000000UL #define PSW_MASK_PSTATE 0x0001000000000000UL +#define CR0_EXTM_SCLP 0X0000000000000200UL +#define CR0_EXTM_EXTC 0X0000000000002000UL +#define CR0_EXTM_EMGC 0X0000000000004000UL +#define CR0_EXTM_MASK 0X0000000000006200UL + struct lowcore { uint8_t pad_0x0000[0x0080 - 0x0000]; /* 0x0000 */ uint32_t ext_int_param; /* 0x0080 */ diff --git a/lib/s390x/asm/interrupt.h b/lib/s390x/asm/interrupt.h index f485e96..4cfade9 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_EMERGENCY_SIG 0x1201 +#define EXT_IRQ_EXTERNAL_CALL 0x1202 #define EXT_IRQ_SERVICE_SIG 0x2401 void handle_pgm_int(void); @@ -19,6 +21,7 @@ void handle_mcck_int(void); void handle_io_int(void); void handle_svc_int(void); void expect_pgm_int(void); +void expect_ext_int(void); uint16_t clear_pgm_int(void); void check_pgm_int_code(uint16_t code); diff --git a/lib/s390x/interrupt.c b/lib/s390x/interrupt.c index 7832711..5cade23 100644 --- a/lib/s390x/interrupt.c +++ b/lib/s390x/interrupt.c @@ -15,6 +15,7 @@ #include static bool pgm_int_expected; +static bool ext_int_expected; static struct lowcore *lc; void expect_pgm_int(void) @@ -24,6 +25,13 @@ void expect_pgm_int(void) mb(); } +void expect_ext_int(void) +{ + ext_int_expected = true; + lc->ext_int_code = 0; + mb(); +} + uint16_t clear_pgm_int(void) { uint16_t code; @@ -108,15 +116,22 @@ void handle_pgm_int(void) void handle_ext_int(void) { - if (lc->ext_int_code != EXT_IRQ_SERVICE_SIG) { + if (!ext_int_expected && + 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; + return; + } + + if (lc->ext_int_code == EXT_IRQ_SERVICE_SIG) { lc->sw_int_cr0 &= ~(1UL << 9); sclp_handle_ext(); - lc->ext_int_code = 0; + } else { + ext_int_expected = false; } + + if (!(lc->sw_int_cr0 & CR0_EXTM_MASK)) + lc->ext_old_psw.mask &= ~PSW_MASK_EXT; } void handle_mcck_int(void) From patchwork Wed Sep 25 16:37:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161139 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E281112B for ; Wed, 25 Sep 2019 16:38:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DEFB321D7C for ; Wed, 25 Sep 2019 16:38:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391876AbfIYQie (ORCPT ); Wed, 25 Sep 2019 12:38:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35000 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391807AbfIYQie (ORCPT ); Wed, 25 Sep 2019 12:38:34 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 99A7030A7B89; Wed, 25 Sep 2019 16:38:33 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 611E160BF1; Wed, 25 Sep 2019 16:38:32 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 16/17] s390x: SMP test Date: Wed, 25 Sep 2019 18:37:13 +0200 Message-Id: <20190925163714.27519-17-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 25 Sep 2019 16:38:33 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank Testing SIGP emulation for the following order codes: * start * stop * restart * set prefix * store status * stop and store status * reset * initial reset * external call * emegergency call restart and set prefix are part of the library and needed to start other cpus. Signed-off-by: Janosch Frank Message-Id: <20190920080356.1948-7-frankja@linux.ibm.com> [thuth: Replaced a report_abort() with report_skip()] Signed-off-by: Thomas Huth --- s390x/Makefile | 1 + s390x/smp.c | 242 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 + 3 files changed, 247 insertions(+) create mode 100644 s390x/smp.c diff --git a/s390x/Makefile b/s390x/Makefile index d83dd0b..3744372 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -15,6 +15,7 @@ tests += $(TEST_DIR)/cpumodel.elf tests += $(TEST_DIR)/diag288.elf tests += $(TEST_DIR)/stsi.elf tests += $(TEST_DIR)/skrf.elf +tests += $(TEST_DIR)/smp.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binary diff --git a/s390x/smp.c b/s390x/smp.c new file mode 100644 index 0000000..8782cfc --- /dev/null +++ b/s390x/smp.c @@ -0,0 +1,242 @@ +/* + * Tests sigp emulation + * + * Copyright 2019 IBM Corp. + * + * Authors: + * Janosch Frank + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2. + */ +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +static int testflag = 0; + +static void cpu_loop(void) +{ + for (;;) {} +} + +static void test_func(void) +{ + testflag = 1; + mb(); + cpu_loop(); +} + +static void test_start(void) +{ + struct psw psw; + psw.mask = extract_psw_mask(); + psw.addr = (unsigned long)test_func; + + smp_cpu_setup(1, psw); + while (!testflag) { + mb(); + } + report("start", 1); +} + +static void test_stop(void) +{ + smp_cpu_stop(1); + /* + * The smp library waits for the CPU to shut down, but let's + * also do it here, so we don't rely on the library + * implementation + */ + while (!smp_cpu_stopped(1)) {} + report("stop", 1); +} + +static void test_stop_store_status(void) +{ + struct cpu *cpu = smp_cpu_from_addr(1); + struct lowcore *lc = (void *)0x0; + + report_prefix_push("stop store status"); + lc->prefix_sa = 0; + lc->grs_sa[15] = 0; + smp_cpu_stop_store_status(1); + mb(); + report("prefix", lc->prefix_sa == (uint32_t)(uintptr_t)cpu->lowcore); + report("stack", lc->grs_sa[15]); + report_prefix_pop(); +} + +static void test_store_status(void) +{ + struct cpu_status *status = alloc_pages(1); + uint32_t r; + + report_prefix_push("store status at address"); + memset(status, 0, PAGE_SIZE * 2); + + report_prefix_push("running"); + smp_cpu_restart(1); + sigp(1, SIGP_STORE_STATUS_AT_ADDRESS, (uintptr_t)status, &r); + report("incorrect state", r == SIGP_STATUS_INCORRECT_STATE); + report("status not written", !memcmp(status, (void*)status + PAGE_SIZE, PAGE_SIZE)); + report_prefix_pop(); + + memset(status, 0, PAGE_SIZE); + report_prefix_push("stopped"); + smp_cpu_stop(1); + sigp(1, SIGP_STORE_STATUS_AT_ADDRESS, (uintptr_t)status, NULL); + while (!status->prefix) { mb(); } + report("status written", 1); + free_pages(status, PAGE_SIZE * 2); + report_prefix_pop(); + + report_prefix_pop(); +} + +static void ecall(void) +{ + unsigned long mask; + struct lowcore *lc = (void *)0x0; + + expect_ext_int(); + ctl_set_bit(0, 13); + mask = extract_psw_mask(); + mask |= PSW_MASK_EXT; + load_psw_mask(mask); + testflag = 1; + while (lc->ext_int_code != 0x1202) { mb(); } + report("ecall", 1); + testflag= 1; +} + +static void test_ecall(void) +{ + struct psw psw; + psw.mask = extract_psw_mask(); + psw.addr = (unsigned long)ecall; + + report_prefix_push("ecall"); + testflag= 0; + smp_cpu_destroy(1); + + smp_cpu_setup(1, psw); + while (!testflag) { mb(); } + testflag= 0; + sigp(1, SIGP_EXTERNAL_CALL, 0, NULL); + while(!testflag) {mb();} + smp_cpu_stop(1); + report_prefix_pop(); +} + +static void emcall(void) +{ + unsigned long mask; + struct lowcore *lc = (void *)0x0; + + expect_ext_int(); + ctl_set_bit(0, 14); + mask = extract_psw_mask(); + mask |= PSW_MASK_EXT; + load_psw_mask(mask); + testflag= 1; + while (lc->ext_int_code != 0x1201) { mb(); } + report("ecall", 1); + testflag = 1; +} + +static void test_emcall(void) +{ + struct psw psw; + psw.mask = extract_psw_mask(); + psw.addr = (unsigned long)emcall; + + report_prefix_push("emcall"); + testflag= 0; + smp_cpu_destroy(1); + + smp_cpu_setup(1, psw); + while (!testflag) { mb(); } + testflag= 0; + sigp(1, SIGP_EMERGENCY_SIGNAL, 0, NULL); + while(!testflag) { mb(); } + smp_cpu_stop(1); + report_prefix_pop(); +} + +static void test_reset_initial(void) +{ + struct cpu_status *status = alloc_pages(0); + struct psw psw; + + psw.mask = extract_psw_mask(); + psw.addr = (unsigned long)test_func; + + report_prefix_push("reset initial"); + smp_cpu_setup(1, psw); + + sigp_retry(1, SIGP_INITIAL_CPU_RESET, 0, NULL); + sigp(1, SIGP_STORE_STATUS_AT_ADDRESS, (uintptr_t)status, NULL); + + report_prefix_push("clear"); + report("psw", !status->psw.mask && !status->psw.addr); + report("prefix", !status->prefix); + report("fpc", !status->fpc); + report("cpu timer", !status->cputm); + report("todpr", !status->todpr); + report_prefix_pop(); + + report_prefix_push("initialized"); + report("cr0 == 0xE0", status->crs[0] == 0xE0UL); + report("cr14 == 0xC2000000", status->crs[14] == 0xC2000000UL); + report_prefix_pop(); + + report("cpu stopped", smp_cpu_stopped(1)); + free_pages(status, PAGE_SIZE); + report_prefix_pop(); +} + +static void test_reset(void) +{ + struct psw psw; + + psw.mask = extract_psw_mask(); + psw.addr = (unsigned long)test_func; + + report_prefix_push("cpu reset"); + smp_cpu_setup(1, psw); + + sigp_retry(1, SIGP_CPU_RESET, 0, NULL); + report("cpu stopped", smp_cpu_stopped(1)); + report_prefix_pop(); +} + +int main(void) +{ + report_prefix_push("smp"); + + if (smp_query_num_cpus() == 1) { + report_skip("need at least 2 cpus for this test"); + goto done; + } + + test_start(); + test_stop(); + test_stop_store_status(); + test_store_status(); + test_ecall(); + test_emcall(); + test_reset(); + test_reset_initial(); + +done: + report_prefix_pop(); + return report_summary(); +} diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index cc79a4e..f1b07cd 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -71,3 +71,7 @@ extra_params=-device diag288,id=watchdog0 --watchdog-action inject-nmi [stsi] file = stsi.elf + +[smp] +file = smp.elf +extra_params =-smp 2 From patchwork Wed Sep 25 16:37:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11161141 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E6A1F1747 for ; Wed, 25 Sep 2019 16:38:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CF3B821D7C for ; Wed, 25 Sep 2019 16:38:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391845AbfIYQig (ORCPT ); Wed, 25 Sep 2019 12:38:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45416 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2391828AbfIYQif (ORCPT ); Wed, 25 Sep 2019 12:38:35 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7256B85540; Wed, 25 Sep 2019 16:38:35 +0000 (UTC) Received: from thuth.com (ovpn-116-109.ams2.redhat.com [10.36.116.109]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0148060BF1; Wed, 25 Sep 2019 16:38:33 +0000 (UTC) From: Thomas Huth To: kvm@vger.kernel.org, Paolo Bonzini , =?utf-8?b?UmFk?= =?utf-8?b?aW0gS3LEjW3DocWZ?= Cc: David Hildenbrand , Janosch Frank Subject: [kvm-unit-tests PULL 17/17] s390x: Free allocated page in iep test Date: Wed, 25 Sep 2019 18:37:14 +0200 Message-Id: <20190925163714.27519-18-thuth@redhat.com> In-Reply-To: <20190925163714.27519-1-thuth@redhat.com> References: <20190925163714.27519-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 25 Sep 2019 16:38:35 +0000 (UTC) Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Janosch Frank Let's also clean up Signed-off-by: Janosch Frank Message-Id: <20190925135623.9740-3-frankja@linux.ibm.com> Reviewed-by: Thomas Huth Acked-by: David Hildenbrand Signed-off-by: Thomas Huth --- s390x/iep.c | 1 + 1 file changed, 1 insertion(+) diff --git a/s390x/iep.c b/s390x/iep.c index 7da78a3..55c01ee 100644 --- a/s390x/iep.c +++ b/s390x/iep.c @@ -43,6 +43,7 @@ static void test_iep(void) report_prefix_pop(); unprotect_page(iepbuf, PAGE_ENTRY_IEP); ctl_clear_bit(0, 20); + free_page(iepbuf); } int main(void)