From patchwork Mon May 23 13:24:04 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: 12859023 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 D0AFFC4332F for ; Mon, 23 May 2022 13:24:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236134AbiEWNYV (ORCPT ); Mon, 23 May 2022 09:24:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236120AbiEWNYR (ORCPT ); Mon, 23 May 2022 09:24:17 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B20449CBA; Mon, 23 May 2022 06:24:15 -0700 (PDT) Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24ND0Xgn017719; Mon, 23 May 2022 13:24:14 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=H8AGerif3e2bUJ7vC2uLQnpBiDlHaQMNSt1wzNsxkq0=; b=GusK7RqRcrNYNNz1H/U9kXYLX6iM1AkfTocrBUWxBNNd+p8+6bMCMK/i6cpEUcVJjpyQ u6zp6LeHzHVuclZwufbsmOAAiDe7vfFOpOH2qWKw1TekHPUWYh4yoW4oIiJurvEvbKT1 MJFTKc1Gk4su25pVXBHNj4lQw/P4sVI6qm6WkAquBWvxBjU6xLtB6OA5N7QphlM4x0v/ jb8FCHJE/BvxCPplcpJ9N1oPInuzNGViQEFEJl9utfmbX0epQWKtxt5IgPUFn/HZ+sVy hsyN5svgWy9QrqbO/318hPGz0+SZfJVVdGe8FRwLFofCElvQYecPJp6vD4M/QuhJTQ2t mQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3g72avbj7m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 May 2022 13:24:14 +0000 Received: from m0098414.ppops.net (m0098414.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 24NDHcLc023924; Mon, 23 May 2022 13:24:13 GMT Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3g72avbj75-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 May 2022 13:24:13 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 24ND6Dh0014943; Mon, 23 May 2022 13:24:11 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma02fra.de.ibm.com with ESMTP id 3g6qq937kp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 May 2022 13:24:11 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 24NDO8Am38338982 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 May 2022 13:24:08 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C094FA404D; Mon, 23 May 2022 13:24:08 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 87441A4040; Mon, 23 May 2022 13:24:08 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 23 May 2022 13:24:08 +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 v3 1/3] s390x: Test TEID values in storage key test Date: Mon, 23 May 2022 15:24:04 +0200 Message-Id: <20220523132406.1820550-2-scgl@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220523132406.1820550-1-scgl@linux.ibm.com> References: <20220523132406.1820550-1-scgl@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: UUtaC7nw2qkoXcoLgWQ7wSGs_gZwvWeH X-Proofpoint-ORIG-GUID: n7EsSKgC4248AKwCyLck_ir5aThk6yhI X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-23_06,2022-05-23_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 bulkscore=0 clxscore=1015 spamscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 phishscore=0 impostorscore=0 priorityscore=1501 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205230073 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 --- s390x/skey.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/s390x/skey.c b/s390x/skey.c index 42bf598c..5e234cde 100644 --- a/s390x/skey.c +++ b/s390x/skey.c @@ -8,6 +8,7 @@ * Janosch Frank */ #include +#include #include #include #include @@ -158,6 +159,68 @@ static void test_test_protection(void) report_prefix_pop(); } +enum access { + ACC_STORE = 1, + ACC_FETCH = 2, + ACC_UPDATE = 3, +}; + +enum protection { + PROT_STORE = 1, + PROT_FETCH_STORE = 3, +}; + +static void check_key_prot_exc(enum access access, enum protection prot) +{ + union teid teid; + int access_code; + + check_pgm_int_code(PGM_INT_CODE_PROTECTION); + report_prefix_push("TEID"); + teid.val = lowcore.trans_exc_id; + switch (get_supp_on_prot_facility()) { + case SOP_NONE: + case SOP_BASIC: + break; + case SOP_ENHANCED_1: + report(!teid.esop1_acc_list_or_dat, "valid protection code"); + break; + case SOP_ENHANCED_2: + switch (teid_esop2_prot_code(teid)) { + case PROT_KEY: + access_code = teid.acc_exc_f_s; + + switch (access_code) { + case 0: + report_pass("valid access code"); + break; + case 1: + case 2: + report((access & access_code) && (prot & access_code), + "valid access code"); + break; + case 3: + /* + * This is incorrect in that reserved values + * should be ignored, but kvm should not return + * a reserved value and having a test for that + * is more valuable. + */ + report_fail("valid access code"); + break; + } + /* fallthrough */ + case PROT_KEY_LAP: + report_pass("valid protection code"); + break; + default: + report_fail("valid protection code"); + } + break; + } + report_prefix_pop(); +} + /* * Perform STORE CPU ADDRESS (STAP) instruction while temporarily executing * with access key 1. @@ -199,7 +262,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 +273,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 +291,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 +377,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 +390,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 +414,7 @@ static void test_set_prefix(void) install_page(root, virt_to_pte_phys(root, pagebuf), 0); set_prefix_key_1((uint32_t *)&mem_all[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 Mon May 23 13:24:05 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: 12859026 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 09050C433F5 for ; Mon, 23 May 2022 13:24:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236156AbiEWNYb (ORCPT ); Mon, 23 May 2022 09:24:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236084AbiEWNYR (ORCPT ); Mon, 23 May 2022 09:24:17 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 935C04B1FC; Mon, 23 May 2022 06:24:15 -0700 (PDT) Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24ND1gpu000614; Mon, 23 May 2022 13:24:14 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=MXp1LyYo96QFOgVWkGck80oG0rjOefifVFyzSQg18nc=; b=KTqdVdIzkNCxdLso10XKPyukYeRMXJtaS2xwiW+WukgeYE40/TZXUUdXPjTWxQ8xmdVV YwlQ6QN8A7gz5dkl7j8w/7ouAY8SeDxh/NIYIJ942ws8EXGJnwnSCf0ujTC1HaRzMdG9 1YKFRilC4jDgtEzw+1Lx0jw/LcUKmS/YbKEhPTHtrpvbtLTUAaYzqnA9xbfXQGztQtI3 m+N1w4nl6X3T64u9tp4v4q6bqDVR5w0/aU2ofGjaaDTh15tPHD1bp/L08RgRjjCXA5tV 4REgfqAtlIX4DxV45MRo80EoBK7eg7omWr1movkJXC37PDb6SGI8+UuM3EPyKKntAcu3 8w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3g882k4nt3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 May 2022 13:24:14 +0000 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 24NDJkrx029569; Mon, 23 May 2022 13:24:14 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3g882k4nss-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 May 2022 13:24:14 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 24NCfnS3016033; Mon, 23 May 2022 13:24:12 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma03ams.nl.ibm.com with ESMTP id 3g6qq92vet-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 May 2022 13:24:12 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 24NDNMsU31785404 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 May 2022 13:23:22 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3D791A404D; Mon, 23 May 2022 13:24:09 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EFFC8A4040; Mon, 23 May 2022 13:24:08 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 23 May 2022 13:24:08 +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 v3 2/3] s390x: Test effect of storage keys on some more instructions Date: Mon, 23 May 2022 15:24:05 +0200 Message-Id: <20220523132406.1820550-3-scgl@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220523132406.1820550-1-scgl@linux.ibm.com> References: <20220523132406.1820550-1-scgl@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: ohW0zvT8YQrZBalGZUK-n-tzAnaHYQBs X-Proofpoint-GUID: 44oLApAxn0znJh_06VxhBOumtZPmo95k X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-23_06,2022-05-23_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 mlxlogscore=999 mlxscore=0 phishscore=0 impostorscore=0 suspectscore=0 malwarescore=0 adultscore=0 bulkscore=0 lowpriorityscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205230073 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 Reviewed-by: Claudio Imbrenda --- s390x/skey.c | 275 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 1 + 2 files changed, 276 insertions(+) diff --git a/s390x/skey.c b/s390x/skey.c index 5e234cde..a55034b5 100644 --- a/s390x/skey.c +++ b/s390x/skey.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -299,6 +300,115 @@ 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 chsc_key_1(void *comm_block) +{ + uint32_t program_mask; + + asm volatile ( + "spka 0x10\n\t" + ".insn rre,0xb25f0000,%[comm_block],0\n\t" + "spka 0\n\t" + "ipm %[program_mask]\n" + : [program_mask] "=d" (program_mask) + : [comm_block] "d" (comm_block) + : "memory" + ); + return program_mask >> 28; +} + +static const char chsc_msg[] = "Performed store-channel-subsystem-characteristics"; +static void init_comm_block(uint16_t *comm_block) +{ + memset(comm_block, 0, PAGE_SIZE); + /* store-channel-subsystem-characteristics command */ + comm_block[0] = 0x10; + comm_block[1] = 0x10; + comm_block[9] = 0; +} + +static void test_channel_subsystem_call(void) +{ + uint16_t *comm_block = (uint16_t *)&pagebuf; + unsigned int cc; + + report_prefix_push("CHANNEL SUBSYSTEM CALL"); + + report_prefix_push("zero key"); + init_comm_block(comm_block); + set_storage_key(comm_block, 0x10, 0); + asm volatile ( + ".insn rre,0xb25f0000,%[comm_block],0\n\t" + "ipm %[cc]\n" + : [cc] "=d" (cc) + : [comm_block] "d" (comm_block) + : "memory" + ); + cc = cc >> 28; + report(cc == 0 && comm_block[9], chsc_msg); + report_prefix_pop(); + + report_prefix_push("matching key"); + init_comm_block(comm_block); + set_storage_key(comm_block, 0x10, 0); + cc = chsc_key_1(comm_block); + report(cc == 0 && comm_block[9], chsc_msg); + report_prefix_pop(); + + report_prefix_push("mismatching key"); + + report_prefix_push("no fetch protection"); + init_comm_block(comm_block); + set_storage_key(comm_block, 0x20, 0); + expect_pgm_int(); + chsc_key_1(comm_block); + check_key_prot_exc(ACC_UPDATE, PROT_STORE); + report_prefix_pop(); + + report_prefix_push("fetch protection"); + init_comm_block(comm_block); + set_storage_key(comm_block, 0x28, 0); + expect_pgm_int(); + chsc_key_1(comm_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(comm_block, 0x20, 0); + init_comm_block(comm_block); + expect_pgm_int(); + chsc_key_1(comm_block); + check_key_prot_exc(ACC_UPDATE, PROT_STORE); + report_prefix_pop(); + + report_prefix_push("storage-protection override, override key"); + init_comm_block(comm_block); + set_storage_key(comm_block, 0x90, 0); + cc = chsc_key_1(comm_block); + report(cc == 0 && comm_block[9], chsc_msg); + report_prefix_pop(); + + ctl_clear_bit(0, CTL0_STORAGE_PROTECTION_OVERRIDE); + + report_prefix_push("storage-protection override disabled, override key"); + init_comm_block(comm_block); + set_storage_key(comm_block, 0x90, 0); + expect_pgm_int(); + chsc_key_1(comm_block); + check_key_prot_exc(ACC_UPDATE, PROT_STORE); + report_prefix_pop(); + + report_prefix_pop(); + + set_storage_key(comm_block, 0x00, 0); + report_prefix_pop(); +} + /* * Perform SET PREFIX (SPX) instruction while temporarily executing * with access key 1. @@ -425,6 +535,169 @@ 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); + 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); + 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 *)&mem_all[2048]); + install_page(root, 0, 0); + check_key_prot_exc(ACC_FETCH, PROT_FETCH_STORE); + 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"); @@ -439,9 +712,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 b456b288..1280ff0f 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 From patchwork Mon May 23 13:24:06 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: 12859025 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 39B08C433F5 for ; Mon, 23 May 2022 13:24:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236158AbiEWNY2 (ORCPT ); Mon, 23 May 2022 09:24:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236119AbiEWNYS (ORCPT ); Mon, 23 May 2022 09:24:18 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 773B712D22; Mon, 23 May 2022 06:24:17 -0700 (PDT) Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 24ND6aBg016906; Mon, 23 May 2022 13:24:16 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=HzBAqXTluqfHmRDvLzs26uLfXg3kXGzzuFGVf2/5Tbs=; b=FJgJemFQRKngp5zQXNI5sTalGY6s7CrFvAQ8PIIqBGtn2k/ZNDJ2bwK4uZ/p1sC9HO7J LFtj6ar7lGiw3cg//5DZ/HS0mkFnVafW5L8pXtn4cB8PVvuF+P61bXmV2C7M7LducbTk wQYKQOPNpCJSeMV/aepLaUyTdSHGteChxGY1z3yEbH58fL06yB35OcJCgdSTQgAj5ZBV b6UK7GbR2eqQFJlWJqYdHvBx7MU6G4irxTG8GxQ3jsabTFdsvUKSBIN1Ed1/060oEuBn AUY4aE6WNRoO8P6ML2EmlJIPcPH1Lq5HrvHZ2lcZCv4SO+COn3vNGshkB1aPgqtxDx2v ow== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3g87p05bb2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 May 2022 13:24:16 +0000 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 24ND16Ro017168; Mon, 23 May 2022 13:24:16 GMT Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3g87p05ba6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 May 2022 13:24:16 +0000 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 24NCKoEj011955; Mon, 23 May 2022 13:24:12 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma03fra.de.ibm.com with ESMTP id 3g6qq9ad72-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 23 May 2022 13:24:12 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 24NDNMms32375138 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 May 2022 13:23:23 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A6524A404D; Mon, 23 May 2022 13:24:09 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6DBACA4040; Mon, 23 May 2022 13:24:09 +0000 (GMT) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 23 May 2022 13:24:09 +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 v3 3/3] s390x: Test effect of storage keys on diag 308 Date: Mon, 23 May 2022 15:24:06 +0200 Message-Id: <20220523132406.1820550-4-scgl@linux.ibm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220523132406.1820550-1-scgl@linux.ibm.com> References: <20220523132406.1820550-1-scgl@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Qc9NBEapVJ6vExRuqSvEZXg6tt-Dnxj8 X-Proofpoint-GUID: FBtQX8bxlfpdX05M1isNvmdOtvSAbGgG X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.874,Hydra:6.0.486,FMLib:17.11.64.514 definitions=2022-05-23_06,2022-05-23_01,2022-02-23_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 spamscore=0 mlxlogscore=999 priorityscore=1501 malwarescore=0 mlxscore=0 clxscore=1015 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2202240000 definitions=main-2205230073 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Test that key-controlled protection does not apply to diag 308. Signed-off-by: Janis Schoetterl-Glausch Reviewed-by: Claudio Imbrenda --- s390x/skey.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/s390x/skey.c b/s390x/skey.c index a55034b5..074667e2 100644 --- a/s390x/skey.c +++ b/s390x/skey.c @@ -300,6 +300,31 @@ static void test_store_cpu_address(void) report_prefix_pop(); } +static void test_diag_308(void) +{ + uint16_t response; + uint32_t *ipib = (uint32_t *)pagebuf; + + report_prefix_push("DIAG 308"); + WRITE_ONCE(ipib[0], 0); /* Invalid length */ + set_storage_key(ipib, 0x28, 0); + /* key-controlled protection does not apply */ + asm volatile ( + "lr %%r2,%[ipib]\n\t" + "spka 0x10\n\t" + "diag %%r2,%[code],0x308\n\t" + "spka 0\n\t" + "lr %[response],%%r3\n" + : [response] "=d" (response) + : [ipib] "d" (ipib), + [code] "d" (5) + : "%r2", "%r3" + ); + report(response == 0x402, "no exception on fetch, response: invalid IPIB"); + set_storage_key(ipib, 0x00, 0); + report_prefix_pop(); +} + /* * Perform CHANNEL SUBSYSTEM CALL (CHSC) instruction while temporarily executing * with access key 1. @@ -712,6 +737,7 @@ int main(void) test_chg(); test_test_protection(); test_store_cpu_address(); + test_diag_308(); test_channel_subsystem_call(); setup_vm();