From patchwork Thu May 5 12:46:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janis Schoetterl-Glausch X-Patchwork-Id: 12839531 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF8BCC433EF for ; Thu, 5 May 2022 12:47:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377697AbiEEMus (ORCPT ); Thu, 5 May 2022 08:50:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238479AbiEEMup (ORCPT ); Thu, 5 May 2022 08:50:45 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6D9D64B874; Thu, 5 May 2022 05:47:06 -0700 (PDT) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 245CUEMZ024893; Thu, 5 May 2022 12:47:05 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=SKXRTMt1x4e2INCCED82LImTmULmQXdinkTbOAi/nSk=; b=hOFIW/u3j3DS7owaBXU716uIWeEpwRkmmrxmtGa4UsaFjyDPy2kuf7133Kn9rWO9xStF FBDFwAWE5Rjm8mEzwvUjzi1+5YbLv912Nltk1v2KbzY6vSh4HyNKVSvTalbYlVlyeiEs C3zxYIR7mRYu6/zoIpA8ClitGnkKXvb6yObFK9ZTGQruBgEOhfoywdnbhRKUhAYkEwdL dgTWKnBG+mg6uLpSJKdEkxFvGYsgt3pEJ+xk581QlryO9AjBNzegptKoUwARkR5FUA09 wjiac6EQBEZbcCmI97ssFYAHfnRWStanvOz9+rcOxiprxFzh4vdj09mjmIC6tH4yMzEX 9g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3fven509ru-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 May 2022 12:47:05 +0000 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 245CZTMK012495; Thu, 5 May 2022 12:47:04 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3fven509r9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 May 2022 12:47:04 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 245CiB8l027356; Thu, 5 May 2022 12:47:03 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma06fra.de.ibm.com with ESMTP id 3fttcj33ba-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 May 2022 12:47:02 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 245CksIo26476820 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 5 May 2022 12:46:54 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3346342045; Thu, 5 May 2022 12:46:59 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D531A42041; Thu, 5 May 2022 12:46:58 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 5 May 2022 12:46:58 +0000 (GMT) From: Janis Schoetterl-Glausch To: Thomas Huth , Janosch Frank , Claudio Imbrenda , Cornelia Huck , David Hildenbrand Cc: Janis Schoetterl-Glausch , kvm@vger.kernel.org, linux-s390@vger.kernel.org Subject: [kvm-unit-tests PATCH 1/3] s390x: Fix sclp facility bit numbers Date: Thu, 5 May 2022 14:46:54 +0200 Message-Id: <20220505124656.1954092-2-scgl@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505124656.1954092-1-scgl@linux.ibm.com> References: <20220505124656.1954092-1-scgl@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: xVAC7ExXh606VheaKCNzV0p0l0o8QJKf X-Proofpoint-GUID: fcbG-mmOKIySIE2x2Mc88vE2NzKKXzpH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-05_05,2022-05-05_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 suspectscore=0 spamscore=0 priorityscore=1501 phishscore=0 clxscore=1015 bulkscore=0 impostorscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205050091 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org sclp_feat_check takes care of adjusting the bit numbering such that they can be defined as they are in the documentation. Fixes: 4dd649c8 ("lib: s390x: sclp: Extend feature probing") Signed-off-by: Janis Schoetterl-Glausch Reviewed-by: Claudio Imbrenda Reviewed-by: Janosch Frank --- lib/s390x/sclp.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h index fead007a..4ce2209f 100644 --- a/lib/s390x/sclp.h +++ b/lib/s390x/sclp.h @@ -134,13 +134,15 @@ struct sclp_facilities { }; /* bit number within a certain byte */ -#define SCLP_FEAT_85_BIT_GSLS 7 -#define SCLP_FEAT_98_BIT_KSS 0 -#define SCLP_FEAT_116_BIT_64BSCAO 7 -#define SCLP_FEAT_116_BIT_CMMA 6 -#define SCLP_FEAT_116_BIT_ESCA 3 -#define SCLP_FEAT_117_BIT_PFMFI 6 -#define SCLP_FEAT_117_BIT_IBS 5 +#define SCLP_FEAT_80_BIT_SOP 2 +#define SCLP_FEAT_85_BIT_GSLS 0 +#define SCLP_FEAT_85_BIT_ESOP 6 +#define SCLP_FEAT_98_BIT_KSS 7 +#define SCLP_FEAT_116_BIT_64BSCAO 0 +#define SCLP_FEAT_116_BIT_CMMA 1 +#define SCLP_FEAT_116_BIT_ESCA 4 +#define SCLP_FEAT_117_BIT_PFMFI 1 +#define SCLP_FEAT_117_BIT_IBS 2 typedef struct ReadInfo { SCCBHeader h; From patchwork Thu May 5 12:46:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janis Schoetterl-Glausch X-Patchwork-Id: 12839532 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BAD0CC433F5 for ; Thu, 5 May 2022 12:47:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377709AbiEEMut (ORCPT ); Thu, 5 May 2022 08:50:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56772 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377660AbiEEMup (ORCPT ); Thu, 5 May 2022 08:50:45 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CDEF36E1A; Thu, 5 May 2022 05:47:06 -0700 (PDT) Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 245Bbdtx006139; Thu, 5 May 2022 12:47:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=Dgg4PcvKoVzcCN2cMC3zSqRkGViME57U2q1HJcYF0hg=; b=m+SwIS0nzCa36vYL8F5pgi0dd8X5q0oTYppGCl3kbSv9YDDhjI5B1Pwiz+FuZoWX1xs1 Uq0FhYBQyAi4+kxJHQw6+F4bcVUC0HCUmp7mNHk2Gz4L4VXasu9I5ZKOcGAzq/HMJNkP cuyXHY1aHsyCjINDQrMLnceBRc9GUkPN54I2itQisIIPR40mgbDaIbnkZikkH8n/bQdk S90LceT+kl8RH5eyv5wdJig7tZO3jAzjs8eES2viY/RpIICfwsnaUq5gixamFkMtdskU fBpJZXQ8YvQSKEopVXC81TdKHDWyNUUE472QNdM2eGJsPnGwMxKC+ro0/IvFIyQMPxrQ MQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3fvbvnuex3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 May 2022 12:47:05 +0000 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 245CCGnp024710; Thu, 5 May 2022 12:47:05 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3fvbvnuew2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 May 2022 12:47:05 +0000 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 245CiVvU001853; Thu, 5 May 2022 12:47:02 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma04fra.de.ibm.com with ESMTP id 3frvr8wt4q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 May 2022 12:47:02 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 245Cksg530146964 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 5 May 2022 12:46:54 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 91D5342042; Thu, 5 May 2022 12:46:59 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4F2014203F; Thu, 5 May 2022 12:46:59 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 5 May 2022 12:46:59 +0000 (GMT) From: Janis Schoetterl-Glausch To: Thomas Huth , Janosch Frank , Claudio Imbrenda Cc: Janis Schoetterl-Glausch , David Hildenbrand , kvm@vger.kernel.org, linux-s390@vger.kernel.org Subject: [kvm-unit-tests PATCH 2/3] s390x: Test TEID values in storage key test Date: Thu, 5 May 2022 14:46:55 +0200 Message-Id: <20220505124656.1954092-3-scgl@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505124656.1954092-1-scgl@linux.ibm.com> References: <20220505124656.1954092-1-scgl@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: w_HyWUySnRIaWjLMQ7R-psDFLn0EbnZj X-Proofpoint-ORIG-GUID: IlqQ4_Ph3A1G0wStUdyQmxNISc3hhY3O X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-05_05,2022-05-05_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 phishscore=0 malwarescore=0 clxscore=1015 priorityscore=1501 suspectscore=0 spamscore=0 mlxscore=0 mlxlogscore=999 adultscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205050091 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org On a protection exception, test that the Translation-Exception Identification (TEID) values are correct given the circumstances of the particular test. The meaning of the TEID values is dependent on the installed suppression-on-protection facility. Signed-off-by: Janis Schoetterl-Glausch --- lib/s390x/asm/facility.h | 21 ++++++++++++++ lib/s390x/sclp.h | 2 ++ lib/s390x/sclp.c | 2 ++ s390x/skey.c | 60 ++++++++++++++++++++++++++++++++++++---- 4 files changed, 79 insertions(+), 6 deletions(-) diff --git a/lib/s390x/asm/facility.h b/lib/s390x/asm/facility.h index ef0fd037..f21bb9d7 100644 --- a/lib/s390x/asm/facility.h +++ b/lib/s390x/asm/facility.h @@ -12,6 +12,7 @@ #include #include #include +#include #define NB_STFL_DOUBLEWORDS 32 extern uint64_t stfl_doublewords[]; @@ -44,4 +45,24 @@ static inline void setup_facilities(void) stfle(stfl_doublewords, NB_STFL_DOUBLEWORDS); } +enum supp_on_prot_facility { + SOP_NONE, + SOP_BASIC, + SOP_ENHANCED_1, + SOP_ENHANCED_2, +}; + +static inline enum supp_on_prot_facility get_supp_on_prot_facility(void) +{ + if (sclp_facilities.has_esop) { + if (test_facility(131)) /* side-effect-access facility */ + return SOP_ENHANCED_2; + else + return SOP_ENHANCED_1; + } + if (sclp_facilities.has_sop) + return SOP_BASIC; + return SOP_NONE; +} + #endif diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h index 4ce2209f..f57896b2 100644 --- a/lib/s390x/sclp.h +++ b/lib/s390x/sclp.h @@ -123,7 +123,9 @@ struct sclp_facilities { uint64_t has_cei : 1; uint64_t has_diag318 : 1; + uint64_t has_sop : 1; uint64_t has_gsls : 1; + uint64_t has_esop : 1; uint64_t has_cmma : 1; uint64_t has_64bscao : 1; uint64_t has_esca : 1; diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c index b8204c5f..e6017f64 100644 --- a/lib/s390x/sclp.c +++ b/lib/s390x/sclp.c @@ -152,7 +152,9 @@ void sclp_facilities_setup(void) cpu = sclp_get_cpu_entries(); if (read_info->offset_cpu > 134) sclp_facilities.has_diag318 = read_info->byte_134_diag318; + sclp_facilities.has_sop = sclp_feat_check(80, SCLP_FEAT_80_BIT_SOP); sclp_facilities.has_gsls = sclp_feat_check(85, SCLP_FEAT_85_BIT_GSLS); + sclp_facilities.has_esop = sclp_feat_check(85, SCLP_FEAT_85_BIT_ESOP); sclp_facilities.has_kss = sclp_feat_check(98, SCLP_FEAT_98_BIT_KSS); sclp_facilities.has_cmma = sclp_feat_check(116, SCLP_FEAT_116_BIT_CMMA); sclp_facilities.has_64bscao = sclp_feat_check(116, SCLP_FEAT_116_BIT_64BSCAO); diff --git a/s390x/skey.c b/s390x/skey.c index 32bf1070..56bf5f45 100644 --- a/s390x/skey.c +++ b/s390x/skey.c @@ -8,6 +8,7 @@ * Janosch Frank */ #include +#include #include #include #include @@ -158,6 +159,53 @@ static void test_test_protection(void) report_prefix_pop(); } +enum access { + ACC_FETCH = 2, + ACC_STORE = 1, + ACC_UPDATE = 3, +}; + +enum protection { + PROT_STORE = 1, + PROT_FETCH_STORE = 3, +}; + +static void check_key_prot_exc(enum access access, enum protection prot) +{ + struct lowcore *lc = 0; + union teid teid; + + check_pgm_int_code(PGM_INT_CODE_PROTECTION); + report_prefix_push("TEID"); + teid.val = lc->trans_exc_id; + switch (get_supp_on_prot_facility()) { + case SOP_NONE: + case SOP_BASIC: + break; + case SOP_ENHANCED_1: + if ((teid.val & (BIT(63 - 61))) == 0) + report_pass("key-controlled protection"); + break; + case SOP_ENHANCED_2: + if ((teid.val & (BIT(63 - 56) | BIT(63 - 61))) == 0) { + report_pass("key-controlled protection"); + if (teid.val & BIT(63 - 60)) { + int access_code = teid.fetch << 1 | teid.store; + + report_info("access code: %d", access_code); + if (access_code == 2) + report((access & 2) && (prot & 2), + "exception due to fetch"); + if (access_code == 1) + report((access & 1) && (prot & 1), + "exception due to store"); + } + } + break; + } + report_prefix_pop(); +} + /* * Perform STORE CPU ADDRESS (STAP) instruction while temporarily executing * with access key 1. @@ -199,7 +247,7 @@ static void test_store_cpu_address(void) expect_pgm_int(); *out = 0xbeef; store_cpu_address_key_1(out); - check_pgm_int_code(PGM_INT_CODE_PROTECTION); + check_key_prot_exc(ACC_STORE, PROT_STORE); report(*out == 0xbeef, "no store occurred"); report_prefix_pop(); @@ -210,7 +258,7 @@ static void test_store_cpu_address(void) expect_pgm_int(); *out = 0xbeef; store_cpu_address_key_1(out); - check_pgm_int_code(PGM_INT_CODE_PROTECTION); + check_key_prot_exc(ACC_STORE, PROT_STORE); report(*out == 0xbeef, "no store occurred"); report_prefix_pop(); @@ -228,7 +276,7 @@ static void test_store_cpu_address(void) expect_pgm_int(); *out = 0xbeef; store_cpu_address_key_1(out); - check_pgm_int_code(PGM_INT_CODE_PROTECTION); + check_key_prot_exc(ACC_STORE, PROT_STORE); report(*out == 0xbeef, "no store occurred"); report_prefix_pop(); @@ -314,7 +362,7 @@ static void test_set_prefix(void) set_storage_key(pagebuf, 0x28, 0); expect_pgm_int(); set_prefix_key_1(prefix_ptr); - check_pgm_int_code(PGM_INT_CODE_PROTECTION); + check_key_prot_exc(ACC_FETCH, PROT_FETCH_STORE); report(get_prefix() == old_prefix, "did not set prefix"); report_prefix_pop(); @@ -327,7 +375,7 @@ static void test_set_prefix(void) install_page(root, virt_to_pte_phys(root, pagebuf), 0); set_prefix_key_1((uint32_t *)0); install_page(root, 0, 0); - check_pgm_int_code(PGM_INT_CODE_PROTECTION); + check_key_prot_exc(ACC_FETCH, PROT_FETCH_STORE); report(get_prefix() == old_prefix, "did not set prefix"); report_prefix_pop(); @@ -351,7 +399,7 @@ static void test_set_prefix(void) install_page(root, virt_to_pte_phys(root, pagebuf), 0); set_prefix_key_1((uint32_t *)2048); install_page(root, 0, 0); - check_pgm_int_code(PGM_INT_CODE_PROTECTION); + check_key_prot_exc(ACC_FETCH, PROT_FETCH_STORE); report(get_prefix() == old_prefix, "did not set prefix"); report_prefix_pop(); From patchwork Thu May 5 12:46:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janis Schoetterl-Glausch X-Patchwork-Id: 12839533 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C3B6C433F5 for ; Thu, 5 May 2022 12:47:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377715AbiEEMuu (ORCPT ); Thu, 5 May 2022 08:50:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229704AbiEEMuq (ORCPT ); Thu, 5 May 2022 08:50:46 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C17DB2ED61; Thu, 5 May 2022 05:47:06 -0700 (PDT) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 245C0n5I022704; Thu, 5 May 2022 12:47:06 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=QAN5cUqFa42ivKRlWcIsy6bybjDb4xtexWAbRPx5vFU=; b=aY3KdIlyo/vQ0UxVWjVlzd04zftMU/QQGy5muoN+kULRANXwFYf6EnX0RawtGRCWZMr/ LQYE2F/UKH5eDejFbjLAOfT4+LH8M5ugo2C7VxeCKhmFhLqkZjSoCI3chVwbavNxA1+m rvh/TwRWkt8gw7x3KabRjhFTkV0RKg2PBz7NobdzXsi0hP+gPpApMBquitF4Cc37susR UH0J7vtgSYP0l5w1CwzSc+cOfFa8fYRunHjWz1tHnTd6HlWlTunxgSv4b/j53aFxXaZZ vxQmd/3CZjEUDWjHSaOD9Z4ETZLd2ON7q/cyJdtM1PTbVnpa6iO4wbKklgi3dlj8fcxi uA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3fve7brxc2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 May 2022 12:47:06 +0000 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 245C1R7E027468; Thu, 5 May 2022 12:47:05 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3fve7brxbb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 May 2022 12:47:05 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 245Cj467024168; Thu, 5 May 2022 12:47:03 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma04ams.nl.ibm.com with ESMTP id 3frvr8y7ab-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 May 2022 12:47:02 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 245CXb5g51052970 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 5 May 2022 12:33:37 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 016E942042; Thu, 5 May 2022 12:47:00 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ADBB84203F; Thu, 5 May 2022 12:46:59 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 5 May 2022 12:46:59 +0000 (GMT) From: Janis Schoetterl-Glausch To: Thomas Huth , Janosch Frank , Claudio Imbrenda Cc: Janis Schoetterl-Glausch , David Hildenbrand , kvm@vger.kernel.org, linux-s390@vger.kernel.org Subject: [kvm-unit-tests PATCH 3/3] s390x: Test effect of storage keys on some more instructions Date: Thu, 5 May 2022 14:46:56 +0200 Message-Id: <20220505124656.1954092-4-scgl@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220505124656.1954092-1-scgl@linux.ibm.com> References: <20220505124656.1954092-1-scgl@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 5H2DNoReVWDIgyy_kQSfPKcT_gun3ntq X-Proofpoint-ORIG-GUID: jZ-fc78BSJWx3PdPXRGtcxJrkfDXsq3u X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.858,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-05_05,2022-05-05_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 malwarescore=0 impostorscore=0 mlxlogscore=999 clxscore=1015 priorityscore=1501 mlxscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205050091 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Test correctness of some instructions handled by user space instead of KVM with regards to storage keys. Test success and error conditions, including coverage of storage and fetch protection override. Signed-off-by: Janis Schoetterl-Glausch --- s390x/skey.c | 277 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 1 + 2 files changed, 278 insertions(+) diff --git a/s390x/skey.c b/s390x/skey.c index 56bf5f45..d50470a8 100644 --- a/s390x/skey.c +++ b/s390x/skey.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -284,6 +285,114 @@ static void test_store_cpu_address(void) report_prefix_pop(); } +/* + * Perform CHANNEL SUBSYSTEM CALL (CHSC) instruction while temporarily executing + * with access key 1. + */ +static unsigned int channel_subsystem_call_key_1(void *communication_block) +{ + uint32_t program_mask; + + asm volatile ( + "spka 0x10\n\t" + ".insn rre,0xb25f0000,%[communication_block],0\n\t" + "spka 0\n\t" + "ipm %[program_mask]\n" + : [program_mask] "=d" (program_mask) + : [communication_block] "d" (communication_block) + : "memory" + ); + return program_mask >> 28; +} + +static void init_store_channel_subsystem_characteristics(uint16_t *communication_block) +{ + memset(communication_block, 0, PAGE_SIZE); + communication_block[0] = 0x10; + communication_block[1] = 0x10; + communication_block[9] = 0; +} + +static void test_channel_subsystem_call(void) +{ + static const char request_name[] = "Store channel-subsystem-characteristics"; + uint16_t *communication_block = (uint16_t *)&pagebuf; + unsigned int cc; + + report_prefix_push("CHANNEL SUBSYSTEM CALL"); + + report_prefix_push("zero key"); + init_store_channel_subsystem_characteristics(communication_block); + set_storage_key(communication_block, 0x10, 0); + asm volatile ( + ".insn rre,0xb25f0000,%[communication_block],0\n\t" + "ipm %[cc]\n" + : [cc] "=d" (cc) + : [communication_block] "d" (communication_block) + : "memory" + ); + cc = cc >> 28; + report(cc == 0 && communication_block[9], request_name); + report_prefix_pop(); + + report_prefix_push("matching key"); + init_store_channel_subsystem_characteristics(communication_block); + set_storage_key(communication_block, 0x10, 0); + cc = channel_subsystem_call_key_1(communication_block); + report(cc == 0 && communication_block[9], request_name); + report_prefix_pop(); + + report_prefix_push("mismatching key"); + + report_prefix_push("no fetch protection"); + init_store_channel_subsystem_characteristics(communication_block); + set_storage_key(communication_block, 0x20, 0); + expect_pgm_int(); + channel_subsystem_call_key_1(communication_block); + check_key_prot_exc(ACC_UPDATE, PROT_STORE); + report_prefix_pop(); + + report_prefix_push("fetch protection"); + init_store_channel_subsystem_characteristics(communication_block); + set_storage_key(communication_block, 0x28, 0); + expect_pgm_int(); + channel_subsystem_call_key_1(communication_block); + check_key_prot_exc(ACC_UPDATE, PROT_FETCH_STORE); + report_prefix_pop(); + + ctl_set_bit(0, CTL0_STORAGE_PROTECTION_OVERRIDE); + + report_prefix_push("storage-protection override, invalid key"); + set_storage_key(communication_block, 0x20, 0); + init_store_channel_subsystem_characteristics(communication_block); + expect_pgm_int(); + channel_subsystem_call_key_1(communication_block); + check_key_prot_exc(ACC_UPDATE, PROT_STORE); + report_prefix_pop(); + + report_prefix_push("storage-protection override, override key"); + init_store_channel_subsystem_characteristics(communication_block); + set_storage_key(communication_block, 0x90, 0); + cc = channel_subsystem_call_key_1(communication_block); + report(cc == 0 && communication_block[9], request_name); + report_prefix_pop(); + + ctl_clear_bit(0, CTL0_STORAGE_PROTECTION_OVERRIDE); + + report_prefix_push("storage-protection override disabled, override key"); + init_store_channel_subsystem_characteristics(communication_block); + set_storage_key(communication_block, 0x90, 0); + expect_pgm_int(); + channel_subsystem_call_key_1(communication_block); + check_key_prot_exc(ACC_UPDATE, PROT_STORE); + report_prefix_pop(); + + report_prefix_pop(); + + set_storage_key(communication_block, 0x00, 0); + report_prefix_pop(); +} + /* * Perform SET PREFIX (SPX) instruction while temporarily executing * with access key 1. @@ -410,6 +519,172 @@ static void test_set_prefix(void) report_prefix_pop(); } +/* + * Perform MODIFY SUBCHANNEL (MSCH) instruction while temporarily executing + * with access key 1. + */ +static uint32_t modify_subchannel_key_1(uint32_t sid, struct schib *schib) +{ + uint32_t program_mask; + + asm volatile ( + "lr %%r1,%[sid]\n\t" + "spka 0x10\n\t" + "msch %[schib]\n\t" + "spka 0\n\t" + "ipm %[program_mask]\n" + : [program_mask] "=d" (program_mask) + : [sid] "d" (sid), + [schib] "Q" (*schib) + : "%r1" + ); + return program_mask >> 28; +} + +static void test_msch(void) +{ + struct schib *schib = (struct schib *)pagebuf; + struct schib *no_override_schib; + int test_device_sid; + pgd_t *root; + int cc; + + report_prefix_push("MSCH"); + root = (pgd_t *)(stctg(1) & PAGE_MASK); + test_device_sid = css_enumerate(); + + if (!(test_device_sid & SCHID_ONE)) { + report_fail("no I/O device found"); + return; + } + + cc = stsch(test_device_sid, schib); + if (cc) { + report_fail("could not store SCHIB"); + return; + } + + report_prefix_push("zero key"); + schib->pmcw.intparm = 100; + set_storage_key(schib, 0x28, 0); + cc = msch(test_device_sid, schib); + if (!cc) { + WRITE_ONCE(schib->pmcw.intparm, 0); + cc = stsch(test_device_sid, schib); + report(!cc && schib->pmcw.intparm == 100, "fetched from SCHIB"); + } else { + report_fail("MSCH cc != 0"); + } + report_prefix_pop(); + + report_prefix_push("matching key"); + schib->pmcw.intparm = 200; + set_storage_key(schib, 0x18, 0); + cc = modify_subchannel_key_1(test_device_sid, schib); + if (!cc) { + WRITE_ONCE(schib->pmcw.intparm, 0); + cc = stsch(test_device_sid, schib); + report(!cc && schib->pmcw.intparm == 200, "fetched from SCHIB"); + } else { + report_fail("MSCH cc != 0"); + } + report_prefix_pop(); + + report_prefix_push("mismatching key"); + + report_prefix_push("no fetch protection"); + schib->pmcw.intparm = 300; + set_storage_key(schib, 0x20, 0); + cc = modify_subchannel_key_1(test_device_sid, schib); + if (!cc) { + WRITE_ONCE(schib->pmcw.intparm, 0); + cc = stsch(test_device_sid, schib); + report(!cc && schib->pmcw.intparm == 300, "fetched from SCHIB"); + } else { + report_fail("MSCH cc != 0"); + } + report_prefix_pop(); + + schib->pmcw.intparm = 0; + if (!msch(test_device_sid, schib)) { + report_prefix_push("fetch protection"); + schib->pmcw.intparm = 400; + set_storage_key(schib, 0x28, 0); + expect_pgm_int(); + modify_subchannel_key_1(test_device_sid, schib); + check_key_prot_exc(ACC_FETCH, PROT_FETCH_STORE); + WRITE_ONCE(schib->pmcw.intparm, 0); + cc = stsch(test_device_sid, schib); + report(!cc && schib->pmcw.intparm == 0, "did not modify subchannel"); + report_prefix_pop(); + } else { + report_fail("could not reset SCHIB"); + } + + register_pgm_cleanup_func(dat_fixup_pgm_int); + + schib->pmcw.intparm = 0; + if (!msch(test_device_sid, schib)) { + report_prefix_push("remapped page, fetch protection"); + schib->pmcw.intparm = 500; + set_storage_key(pagebuf, 0x28, 0); + expect_pgm_int(); + install_page(root, virt_to_pte_phys(root, pagebuf), 0); + modify_subchannel_key_1(test_device_sid, (struct schib *)0); + install_page(root, 0, 0); + check_key_prot_exc(ACC_FETCH, PROT_FETCH_STORE); + WRITE_ONCE(schib->pmcw.intparm, 0); + cc = stsch(test_device_sid, schib); + report(!cc && schib->pmcw.intparm == 0, "did not modify subchannel"); + report_prefix_pop(); + } else { + report_fail("could not reset SCHIB"); + } + + ctl_set_bit(0, CTL0_FETCH_PROTECTION_OVERRIDE); + + report_prefix_push("fetch-protection override applies"); + schib->pmcw.intparm = 600; + set_storage_key(pagebuf, 0x28, 0); + install_page(root, virt_to_pte_phys(root, pagebuf), 0); + cc = modify_subchannel_key_1(test_device_sid, (struct schib *)0); + install_page(root, 0, 0); + if (!cc) { + WRITE_ONCE(schib->pmcw.intparm, 0); + cc = stsch(test_device_sid, schib); + report(!cc && schib->pmcw.intparm == 600, "fetched from SCHIB"); + } else { + report_fail("MSCH cc != 0"); + } + report_prefix_pop(); + + schib->pmcw.intparm = 0; + if (!msch(test_device_sid, schib)) { + report_prefix_push("fetch-protection override does not apply"); + schib->pmcw.intparm = 700; + no_override_schib = (struct schib *)(pagebuf + 2048); + memcpy(no_override_schib, schib, sizeof(struct schib)); + set_storage_key(pagebuf, 0x28, 0); + expect_pgm_int(); + install_page(root, virt_to_pte_phys(root, pagebuf), 0); + modify_subchannel_key_1(test_device_sid, (struct schib *)2048); + install_page(root, 0, 0); + check_key_prot_exc(ACC_FETCH, PROT_FETCH_STORE); + WRITE_ONCE(schib->pmcw.intparm, 0); + cc = stsch(test_device_sid, schib); + report(!cc && schib->pmcw.intparm == 0, "did not modify subchannel"); + report_prefix_pop(); + } else { + report_fail("could not reset SCHIB"); + } + + ctl_clear_bit(0, CTL0_FETCH_PROTECTION_OVERRIDE); + register_pgm_cleanup_func(NULL); + report_prefix_pop(); + set_storage_key(schib, 0x00, 0); + report_prefix_pop(); +} + int main(void) { report_prefix_push("skey"); @@ -424,9 +699,11 @@ int main(void) test_chg(); test_test_protection(); test_store_cpu_address(); + test_channel_subsystem_call(); setup_vm(); test_set_prefix(); + test_msch(); done: report_prefix_pop(); return report_summary(); diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index 743013b2..069c41a7 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -41,6 +41,7 @@ file = sthyi.elf [skey] file = skey.elf +extra_params = -device virtio-net-ccw [diag10] file = diag10.elf