From patchwork Wed Sep 18 12:04:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11150185 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 374B413BD for ; Wed, 18 Sep 2019 12:04:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 149C021907 for ; Wed, 18 Sep 2019 12:04:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730537AbfIRMEi (ORCPT ); Wed, 18 Sep 2019 08:04:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:30416 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730527AbfIRMEh (ORCPT ); Wed, 18 Sep 2019 08:04:37 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 888643061424; Wed, 18 Sep 2019 12:04:37 +0000 (UTC) Received: from thuth.com (ovpn-116-90.ams2.redhat.com [10.36.116.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 18702600CC; Wed, 18 Sep 2019 12:04:35 +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 1/9] s390x: Support PSW restart boot Date: Wed, 18 Sep 2019 14:04:18 +0200 Message-Id: <20190918120426.20832-2-thuth@redhat.com> In-Reply-To: <20190918120426.20832-1-thuth@redhat.com> References: <20190918120426.20832-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Wed, 18 Sep 2019 12:04:37 +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 18 12:04:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11150187 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 1759613BD for ; Wed, 18 Sep 2019 12:04:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F3E6D21907 for ; Wed, 18 Sep 2019 12:04:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730544AbfIRMEk (ORCPT ); Wed, 18 Sep 2019 08:04:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55762 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730542AbfIRMEj (ORCPT ); Wed, 18 Sep 2019 08:04:39 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 48DEA8A1C80; Wed, 18 Sep 2019 12:04:39 +0000 (UTC) Received: from thuth.com (ovpn-116-90.ams2.redhat.com [10.36.116.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id E67CC600CC; Wed, 18 Sep 2019 12:04:37 +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 2/9] s390x: Diag288 test Date: Wed, 18 Sep 2019 14:04:19 +0200 Message-Id: <20190918120426.20832-3-thuth@redhat.com> In-Reply-To: <20190918120426.20832-1-thuth@redhat.com> References: <20190918120426.20832-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Wed, 18 Sep 2019 12:04:39 +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 18 12:04:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11150189 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 77008196C for ; Wed, 18 Sep 2019 12:04:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 54CE021907 for ; Wed, 18 Sep 2019 12:04:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730556AbfIRMEl (ORCPT ); Wed, 18 Sep 2019 08:04:41 -0400 Received: from mx1.redhat.com ([209.132.183.28]:33903 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730555AbfIRMEl (ORCPT ); Wed, 18 Sep 2019 08:04:41 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0B69F30ADBA7; Wed, 18 Sep 2019 12:04:41 +0000 (UTC) Received: from thuth.com (ovpn-116-90.ams2.redhat.com [10.36.116.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6C52600C8; Wed, 18 Sep 2019 12:04:39 +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 3/9] s390x: Move stsi to library Date: Wed, 18 Sep 2019 14:04:20 +0200 Message-Id: <20190918120426.20832-4-thuth@redhat.com> In-Reply-To: <20190918120426.20832-1-thuth@redhat.com> References: <20190918120426.20832-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Wed, 18 Sep 2019 12:04:41 +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 18 12:04:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11150191 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 0A962196C for ; Wed, 18 Sep 2019 12:04:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E6C6021907 for ; Wed, 18 Sep 2019 12:04:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730582AbfIRMEn (ORCPT ); Wed, 18 Sep 2019 08:04:43 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1917 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730560AbfIRMEn (ORCPT ); Wed, 18 Sep 2019 08:04:43 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AC40B307D9D0; Wed, 18 Sep 2019 12:04:42 +0000 (UTC) Received: from thuth.com (ovpn-116-90.ams2.redhat.com [10.36.116.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E5A6600C8; Wed, 18 Sep 2019 12:04:41 +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 4/9] s390x: STSI tests Date: Wed, 18 Sep 2019 14:04:21 +0200 Message-Id: <20190918120426.20832-5-thuth@redhat.com> In-Reply-To: <20190918120426.20832-1-thuth@redhat.com> References: <20190918120426.20832-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 18 Sep 2019 12:04: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 18 12:04:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11150193 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 E53DA13BD for ; Wed, 18 Sep 2019 12:04:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id CD7A521907 for ; Wed, 18 Sep 2019 12:04:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730546AbfIRMEp (ORCPT ); Wed, 18 Sep 2019 08:04:45 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55916 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730579AbfIRMEo (ORCPT ); Wed, 18 Sep 2019 08:04:44 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 738E18A1C80; Wed, 18 Sep 2019 12:04:44 +0000 (UTC) Received: from thuth.com (ovpn-116-90.ams2.redhat.com [10.36.116.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0FFB9600C8; Wed, 18 Sep 2019 12:04: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 5/9] s390x: Add diag308 subcode 0 testing Date: Wed, 18 Sep 2019 14:04:22 +0200 Message-Id: <20190918120426.20832-6-thuth@redhat.com> In-Reply-To: <20190918120426.20832-1-thuth@redhat.com> References: <20190918120426.20832-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.69]); Wed, 18 Sep 2019 12:04:44 +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 18 12:04:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11150195 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 5914F196C for ; Wed, 18 Sep 2019 12:04:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4099821907 for ; Wed, 18 Sep 2019 12:04:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730612AbfIRMEr (ORCPT ); Wed, 18 Sep 2019 08:04:47 -0400 Received: from mx1.redhat.com ([209.132.183.28]:20046 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730586AbfIRMEq (ORCPT ); Wed, 18 Sep 2019 08:04:46 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 273BC300CB2B; Wed, 18 Sep 2019 12:04:46 +0000 (UTC) Received: from thuth.com (ovpn-116-90.ams2.redhat.com [10.36.116.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id C528C600C8; Wed, 18 Sep 2019 12:04:44 +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 6/9] s390x: Move pfmf to lib and make address void Date: Wed, 18 Sep 2019 14:04:23 +0200 Message-Id: <20190918120426.20832-7-thuth@redhat.com> In-Reply-To: <20190918120426.20832-1-thuth@redhat.com> References: <20190918120426.20832-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Wed, 18 Sep 2019 12:04:46 +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 18 12:04:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11150197 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 344CF196C for ; Wed, 18 Sep 2019 12:04:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1D1BA21924 for ; Wed, 18 Sep 2019 12:04:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730560AbfIRMEt (ORCPT ); Wed, 18 Sep 2019 08:04:49 -0400 Received: from mx1.redhat.com ([209.132.183.28]:45086 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730569AbfIRMEs (ORCPT ); Wed, 18 Sep 2019 08:04:48 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 02A3910576C5; Wed, 18 Sep 2019 12:04:48 +0000 (UTC) Received: from thuth.com (ovpn-116-90.ams2.redhat.com [10.36.116.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 859C86012C; Wed, 18 Sep 2019 12:04:46 +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 7/9] s390x: Storage key library functions now take void ptr addresses Date: Wed, 18 Sep 2019 14:04:24 +0200 Message-Id: <20190918120426.20832-8-thuth@redhat.com> In-Reply-To: <20190918120426.20832-1-thuth@redhat.com> References: <20190918120426.20832-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.64]); Wed, 18 Sep 2019 12:04:48 +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 18 12:04:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11150199 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 888C413BD for ; Wed, 18 Sep 2019 12:04:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 71E9321924 for ; Wed, 18 Sep 2019 12:04:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730617AbfIRMEu (ORCPT ); Wed, 18 Sep 2019 08:04:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55364 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730567AbfIRMEt (ORCPT ); Wed, 18 Sep 2019 08:04:49 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CE7D01895A46; Wed, 18 Sep 2019 12:04:49 +0000 (UTC) Received: from thuth.com (ovpn-116-90.ams2.redhat.com [10.36.116.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E9A66012C; Wed, 18 Sep 2019 12:04:48 +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 8/9] s390x: Bump march to zEC12 Date: Wed, 18 Sep 2019 14:04:25 +0200 Message-Id: <20190918120426.20832-9-thuth@redhat.com> In-Reply-To: <20190918120426.20832-1-thuth@redhat.com> References: <20190918120426.20832-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.62]); Wed, 18 Sep 2019 12:04:49 +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 18 12:04:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 11150201 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 B6212197C for ; Wed, 18 Sep 2019 12:04:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9E77C2054F for ; Wed, 18 Sep 2019 12:04:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730638AbfIRMEy (ORCPT ); Wed, 18 Sep 2019 08:04:54 -0400 Received: from mx1.redhat.com ([209.132.183.28]:39518 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730634AbfIRMEy (ORCPT ); Wed, 18 Sep 2019 08:04:54 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0B3EE18CB901; Wed, 18 Sep 2019 12:04:54 +0000 (UTC) Received: from thuth.com (ovpn-116-90.ams2.redhat.com [10.36.116.90]) by smtp.corp.redhat.com (Postfix) with ESMTP id 38BA960167; Wed, 18 Sep 2019 12:04: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 9/9] s390x: Add storage key removal facility Date: Wed, 18 Sep 2019 14:04:26 +0200 Message-Id: <20190918120426.20832-10-thuth@redhat.com> In-Reply-To: <20190918120426.20832-1-thuth@redhat.com> References: <20190918120426.20832-1-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.63]); Wed, 18 Sep 2019 12:04:54 +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(); +}