From patchwork Mon Feb 21 13:07:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Boehr X-Patchwork-Id: 12753604 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 47032C43219 for ; Mon, 21 Feb 2022 13:08:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358573AbiBUNIZ (ORCPT ); Mon, 21 Feb 2022 08:08:25 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:40000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358550AbiBUNIU (ORCPT ); Mon, 21 Feb 2022 08:08:20 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 433961EC58; Mon, 21 Feb 2022 05:07:56 -0800 (PST) Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21LCCIJj020242; Mon, 21 Feb 2022 13:07:56 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 : content-transfer-encoding : mime-version; s=pp1; bh=/AqcVq6wO3aHnWv7O34YabrPeV0tcX8DhvifMiBXhlw=; b=g/pYHwKOJndEuigCwTI7J/PlzCbp4X+uUEftLRzuG2fg6FOV/YJakT+dLjOb9+9MAqrp aTYqmoDsw/edD4ckgm7gJjXIopTmkn0Fnm/X6dJo0SYsXRbackNIes8HrP7X9jrJUTP7 4FK9OYxv+GTEbHbFvrB0nmiyQDYtRTMxj+RMe5HL+7uthZ7/h7K4KkqzdZpBZsk9R+Sp 2T+MaSyuEy3aYiYXZ1o4/PcDXt6uoEd0oykksNUAeGegmQ+CsAn2slVrtmRdP0x5zahi fKpyAjzdHU+7CgMvAwlMXHeXWncdfGh0YWBNi6rEvKun/ZzdSX3wQpcQ7XVhmpbcZkGA 4g== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ecahjh3wr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:55 +0000 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 21LCO6RC031407; Mon, 21 Feb 2022 13:07:55 GMT Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ecahjh3vr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:55 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 21LCwo0V007241; Mon, 21 Feb 2022 13:07:53 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma01fra.de.ibm.com with ESMTP id 3ear68std3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:53 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 21LD7lDT54132992 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 21 Feb 2022 13:07:48 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BE06D4C04E; Mon, 21 Feb 2022 13:07:47 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7BE364C05C; Mon, 21 Feb 2022 13:07:47 +0000 (GMT) Received: from t46lp57.lnxne.boe (unknown [9.152.108.100]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 21 Feb 2022 13:07:47 +0000 (GMT) From: Nico Boehr To: kvm@vger.kernel.org, linux-s390@vger.kernel.org Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com, david@redhat.com Subject: [kvm-unit-tests PATCH v2 1/8] s390x: Add more tests for MSCH Date: Mon, 21 Feb 2022 14:07:39 +0100 Message-Id: <20220221130746.1754410-2-nrb@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220221130746.1754410-1-nrb@linux.ibm.com> References: <20220221130746.1754410-1-nrb@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 3NDcuLZRSGUJEiBNbBqIWDkmrc2pMFlr X-Proofpoint-ORIG-GUID: 1EeY5nKqRZK9-iEjGr4pa0fEQXJlMwBW X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-21_06,2022-02-21_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 mlxscore=0 clxscore=1015 spamscore=0 malwarescore=0 adultscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202210078 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We already have some coverage for MSCH, but there are more cases to test for: - invalid SCHIB structure. We cover that by setting reserved bits 0, 1, 6 and 7 in the flags of the PMCW. This test currently fails because of a QEMU bug, a fix is available (see "[PATCH qemu] s390x/css: fix PMCW invalid mask") - a pointer to an unaligned SCHIB. We cover misalignment by 1 and 2 bytes. Using pointer to valid memory avoids messing up random memory in case of test failures. Here's the QEMU PMCW invalid mask fix: https://lists.nongnu.org/archive/html/qemu-s390x/2021-12/msg00100.html Signed-off-by: Nico Boehr Reviewed-by: Janosch Frank Reviewed-by: Claudio Imbrenda Reviewed-by: Thomas Huth --- s390x/css.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/s390x/css.c b/s390x/css.c index 881206ba1cef..932daf69bb36 100644 --- a/s390x/css.c +++ b/s390x/css.c @@ -27,6 +27,8 @@ static int test_device_sid; static struct senseid *senseid; struct ccw1 *ccw; +char alignment_test_page[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); + static void test_enumerate(void) { test_device_sid = css_enumerate(); @@ -331,6 +333,56 @@ static void test_schm_fmt1(void) free_io_mem(mb1, sizeof(struct measurement_block_format1)); } +static void test_msch(void) +{ + const int align_to = 4; + int cc; + int invalid_pmcw_flags[] = {0, 1, 6, 7}; + int invalid_flag; + uint16_t old_pmcw_flags; + + if (!test_device_sid) { + report_skip("No device"); + return; + } + + cc = stsch(test_device_sid, &schib); + if (cc) { + report_fail("stsch: sch %08x failed with cc=%d", test_device_sid, cc); + return; + } + + report_prefix_push("Unaligned"); + for (int i = 1; i < align_to; i *= 2) { + report_prefix_pushf("%d", i); + + expect_pgm_int(); + msch(test_device_sid, (struct schib *)(alignment_test_page + i)); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + + report_prefix_pop(); + } + report_prefix_pop(); + + report_prefix_push("Invalid SCHIB"); + old_pmcw_flags = schib.pmcw.flags; + for (int i = 0; i < ARRAY_SIZE(invalid_pmcw_flags); i++) { + invalid_flag = invalid_pmcw_flags[i]; + + report_prefix_pushf("PMCW flag bit %d set", invalid_flag); + + schib.pmcw.flags = old_pmcw_flags | BIT(15 - invalid_flag); + expect_pgm_int(); + msch(test_device_sid, &schib); + check_pgm_int_code(PGM_INT_CODE_OPERAND); + + report_prefix_pop(); + } + report_prefix_pop(); + + schib.pmcw.flags = old_pmcw_flags; +} + static struct { const char *name; void (*func)(void); @@ -343,6 +395,7 @@ static struct { { "measurement block (schm)", test_schm }, { "measurement block format0", test_schm_fmt0 }, { "measurement block format1", test_schm_fmt1 }, + { "msch", test_msch }, { NULL, NULL } }; From patchwork Mon Feb 21 13:07:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Boehr X-Patchwork-Id: 12753600 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 EEF91C43217 for ; Mon, 21 Feb 2022 13:07:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358559AbiBUNIV (ORCPT ); Mon, 21 Feb 2022 08:08:21 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:39974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358544AbiBUNIT (ORCPT ); Mon, 21 Feb 2022 08:08:19 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E95C1EC4B; Mon, 21 Feb 2022 05:07:54 -0800 (PST) Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21LBZ3rx011692; Mon, 21 Feb 2022 13:07:53 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=KrHgcefxFkJNDSHdEUfFE4b1KWfOLQhgZfB62ZWZEGw=; b=EwQVeSpRmmOTBhOkHMRk+7xC04MWtgw8ZZq8Wlyzj2225DBJbYhVwrxhzBjNDyuspKfV i9W747nfW/Q5jEF+r9BQcaLASlXVwMRriNo/uIl8TIkXo/kkqADFzsf27LILMuAhTOAX vW1DDgpwSDtJLVkKq9fK/mLdL+aAoeVnIwqPpWINjUH6P1ngz5smLXql27LqfaZvD5Mn hGqc06wBbyllOZ7fjUaLtcI5yP8K50HeYebCuGTW1YZ9hWCIHCleX3hYtVRSbxjBTZYE mhhdKUy41uE5vzks2coQcyNyVI33mhKoGFffial0aHfphOsPNAGCy+Fz9rm6czTPMQW/ Cg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3ec5sff589-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:53 +0000 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 21LCsNPF022537; Mon, 21 Feb 2022 13:07:53 GMT Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 3ec5sff57t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:52 +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 21LCwqIi012801; Mon, 21 Feb 2022 13:07:51 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma03fra.de.ibm.com with ESMTP id 3ear68stgw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:51 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 21LD7mPU45351260 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 21 Feb 2022 13:07:48 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1794E4C04A; Mon, 21 Feb 2022 13:07:48 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CA16A4C040; Mon, 21 Feb 2022 13:07:47 +0000 (GMT) Received: from t46lp57.lnxne.boe (unknown [9.152.108.100]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 21 Feb 2022 13:07:47 +0000 (GMT) From: Nico Boehr To: kvm@vger.kernel.org, linux-s390@vger.kernel.org Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com, david@redhat.com Subject: [kvm-unit-tests PATCH v2 2/8] s390x: Add test for PFMF low-address protection Date: Mon, 21 Feb 2022 14:07:40 +0100 Message-Id: <20220221130746.1754410-3-nrb@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220221130746.1754410-1-nrb@linux.ibm.com> References: <20220221130746.1754410-1-nrb@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: YHyYkl5jxMAN4qGZxIi6_7zH92rfpcTt X-Proofpoint-ORIG-GUID: cUQwGYNBkWqWD6CvGIfJ00uWLgRNMjpo X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-21_06,2022-02-21_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 lowpriorityscore=0 bulkscore=0 adultscore=0 priorityscore=1501 mlxlogscore=707 impostorscore=0 suspectscore=0 phishscore=0 malwarescore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202210078 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org PFMF should respect the low-address protection when clearing pages, hence add some tests for it. When low-address protection fails, clearing frame 0 is a destructive operation. It messes up interrupts and thus printing test results won't work properly. Hence, we first attempt to clear frame 1 which is not as destructive. Doing it this way around increases the chances for the user to see a proper failure message instead of QEMU randomly quitting in the middle of the test run. Signed-off-by: Nico Boehr Reviewed-by: Claudio Imbrenda Reviewed-by: Janosch Frank Reviewed-by: Thomas Huth --- s390x/pfmf.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/s390x/pfmf.c b/s390x/pfmf.c index 2f3cb110dc4c..aa1305292ee8 100644 --- a/s390x/pfmf.c +++ b/s390x/pfmf.c @@ -113,6 +113,34 @@ static void test_1m_clear(void) report_prefix_pop(); } +static void test_low_addr_prot(void) +{ + union pfmf_r1 r1 = { + .reg.cf = 1, + .reg.fsc = PFMF_FSC_4K + }; + + report_prefix_push("low-address protection"); + + report_prefix_push("0x1000"); + expect_pgm_int(); + low_prot_enable(); + pfmf(r1.val, (void *)0x1000); + low_prot_disable(); + check_pgm_int_code(PGM_INT_CODE_PROTECTION); + report_prefix_pop(); + + report_prefix_push("0x0"); + expect_pgm_int(); + low_prot_enable(); + pfmf(r1.val, 0); + low_prot_disable(); + check_pgm_int_code(PGM_INT_CODE_PROTECTION); + report_prefix_pop(); + + report_prefix_pop(); +} + int main(void) { bool has_edat = test_facility(8); @@ -124,6 +152,7 @@ int main(void) } test_priv(); + test_low_addr_prot(); /* Force the buffer pages in */ memset(pagebuf, 0, PAGE_SIZE * 256); From patchwork Mon Feb 21 13:07:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Boehr X-Patchwork-Id: 12753606 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 468DCC433EF for ; Mon, 21 Feb 2022 13:08:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358575AbiBUNI2 (ORCPT ); Mon, 21 Feb 2022 08:08:28 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:40004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358546AbiBUNIU (ORCPT ); Mon, 21 Feb 2022 08:08:20 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27E661EC59; Mon, 21 Feb 2022 05:07:57 -0800 (PST) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21LD3pvO016689; Mon, 21 Feb 2022 13:07:57 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=7ITZWcjQo2bitjwxYSTlQbXl7mEYUdDgYV2/FD4UCYE=; b=thL1kBY7oZZbqtTnVCDW1MuUVd6sS4rUJU9IxAaEOavdPTMGRShgJKfGzJAPNJwoWnSN lW3cNWbJ2644c/bb3OmdvEdsgk/E5HLqZx6v/SqifqnrVk/rCXSRuQYLatbXluJSw5HD DwbrUzVqhRj/6p0KpfKp3kn9FLxVlwW4FBWDMG7B2d3M9LXGc4DpxwQu8IcgjcxRTJcJ t5JHqPRbVpAn0+mSQWF4+JusKBMcCzmJE6qPXUVeBabn+FtmAfV5ggZ5Cp6yMLPT/cEB GbwCs9LYhf72p9Jq11AYixYtIBprOwwWzhc2iSt2yZJwxRiaeJUo0bB/u6FC5iMU4tf0 +Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ec5q0fsd7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:56 +0000 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 21LD784B010415; Mon, 21 Feb 2022 13:07:56 GMT Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ec5q0fsc4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:56 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 21LCwqXq032626; Mon, 21 Feb 2022 13:07:53 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma05fra.de.ibm.com with ESMTP id 3ear691sc2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:52 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 21LD7mbh45351264 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 21 Feb 2022 13:07:48 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 664984C04A; Mon, 21 Feb 2022 13:07:48 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 23CBE4C050; Mon, 21 Feb 2022 13:07:48 +0000 (GMT) Received: from t46lp57.lnxne.boe (unknown [9.152.108.100]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 21 Feb 2022 13:07:48 +0000 (GMT) From: Nico Boehr To: kvm@vger.kernel.org, linux-s390@vger.kernel.org Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com, david@redhat.com Subject: [kvm-unit-tests PATCH v2 3/8] s390x: Add sck tests Date: Mon, 21 Feb 2022 14:07:41 +0100 Message-Id: <20220221130746.1754410-4-nrb@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220221130746.1754410-1-nrb@linux.ibm.com> References: <20220221130746.1754410-1-nrb@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: FGe66rUWFSJk742CX9wn2vjTqkm3uCb_ X-Proofpoint-GUID: ByMQfQeJectOhVa-Sy_G8YuuUzmnCFVE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-21_06,2022-02-21_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 malwarescore=0 adultscore=0 phishscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202210078 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org SCK updates the guest's TOD clock. It needs to be intercepted, hence we should have some tests for it: - its operand must be 8-byte aligned. We test for 1, 2 and 4 byte misalignment. - it should actually update the clock value. As guests are unable to stop their clock, we can only check the clock value is at least higher than the value we set. - it is a privileged call, so expect it to fail when in problem state. We also test the clock value is not changed in this case. We do so by first adjusting it (privileged) to a high value. We then attempt, in nonprivileged mode, to set the clock to a comparatively small value. We can then store the clock value and test its value is strictly higher than the high value we set previously. Signed-off-by: Nico Boehr Reviewed-by: Claudio Imbrenda Reviewed-by: Pierre Morel --- s390x/Makefile | 1 + s390x/sck.c | 127 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 3 ++ 3 files changed, 131 insertions(+) create mode 100644 s390x/sck.c diff --git a/s390x/Makefile b/s390x/Makefile index 53b0fe044fe7..a76b78e5a011 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -17,6 +17,7 @@ tests += $(TEST_DIR)/stsi.elf tests += $(TEST_DIR)/skrf.elf tests += $(TEST_DIR)/smp.elf tests += $(TEST_DIR)/sclp.elf +tests += $(TEST_DIR)/sck.elf tests += $(TEST_DIR)/css.elf tests += $(TEST_DIR)/uv-guest.elf tests += $(TEST_DIR)/sie.elf diff --git a/s390x/sck.c b/s390x/sck.c new file mode 100644 index 000000000000..dcddd1b2e5f8 --- /dev/null +++ b/s390x/sck.c @@ -0,0 +1,127 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Perform Set Clock tests + * + * Copyright IBM Corp. 2022 + * + * Authors: + * Nico Boehr + */ +#include +#include +#include + +static inline int sck(uint64_t *time) +{ + int cc; + + asm volatile( + " sck %[time]\n" + " ipm %[cc]\n" + " srl %[cc],28\n" + : [cc] "=d"(cc) + : [time] "Q"(*time) + : "cc" + ); + + return cc; +} + +static inline int stck(uint64_t *time) +{ + int cc; + + asm volatile( + " stck %[time]\n" + " ipm %[cc]\n" + " srl %[cc],28\n" + : [cc] "=d" (cc), [time] "=Q" (*time) + : + : "cc", "memory" + ); + + return cc; +} + +static void test_priv(void) +{ + uint64_t time_to_set_privileged = 0xfacef00dcafe0000, + time_to_set_nonprivileged = 0xcafe0000, + time_verify; + int cc; + + report_prefix_push("privileged"); + cc = sck(&time_to_set_privileged); + report(!cc, "set clock cc=%d", cc); + + cc = stck(&time_verify); + report(!cc, "store clock cc=%d", cc); + report(time_verify > time_to_set_privileged, + "privileged set affected the clock"); + + expect_pgm_int(); + enter_pstate(); + sck(&time_to_set_nonprivileged); + leave_pstate(); + check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION); + + cc = stck(&time_verify); + report(!cc, "store clock cc=%d", cc); + report(time_verify > time_to_set_privileged, + "unprivileged set did not affect the clock"); + report_prefix_pop(); +} + +static void test_align(void) +{ + const int align_to = 8; + char unalign[sizeof(uint64_t) + align_to] __attribute__((aligned(8))); + + report_prefix_push("Unaligned operand"); + for (int i = 1; i < align_to; i *= 2) { + report_prefix_pushf("%d", i); + expect_pgm_int(); + sck((uint64_t *)(unalign + i)); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + } + report_prefix_pop(); +} + +static void test_set(void) +{ + uint64_t start = 0, end = 0, time = 0xcafef00dbeef; + const uint64_t ticks_per_ms = 1000 << 12, ms_to_wait = 5; + int cc; + + report_prefix_push("set"); + + cc = sck(&time); + report(!cc, "set clock cc=%d", cc); + + cc = stck(&start); + report(!cc, "store start clock cc=%d", cc); + report(start >= time, "start >= set value"); + + mdelay(ms_to_wait); + + cc = stck(&end); + report(!cc, "store end clock cc=%d", cc); + report(end > time, "end > set value"); + + report(end - start > (ticks_per_ms * ms_to_wait), "Advances"); + + report_prefix_pop(); +} + +int main(void) +{ + report_prefix_push("sck"); + + test_align(); + test_set(); + test_priv(); + + report_prefix_pop(); + return report_summary(); +} diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index 1600e714c8b9..8b148fe31ac0 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -136,3 +136,6 @@ file = firq.elf timeout = 20 extra_params = -smp 1,maxcpus=3 -cpu qemu -device qemu-s390x-cpu,core-id=2 -device qemu-s390x-cpu,core-id=1 accel = tcg + +[sck] +file = sck.elf From patchwork Mon Feb 21 13:07:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Boehr X-Patchwork-Id: 12753602 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 4DB2FC4321E for ; Mon, 21 Feb 2022 13:08:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358564AbiBUNIX (ORCPT ); Mon, 21 Feb 2022 08:08:23 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:39996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358548AbiBUNIU (ORCPT ); Mon, 21 Feb 2022 08:08:20 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 787491EC4F; Mon, 21 Feb 2022 05:07:55 -0800 (PST) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21LC8gkW011808; Mon, 21 Feb 2022 13:07:54 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=9wg2s4eWJfpmKWhtRpSZLpvQzrsyW5kDy9RuOgyWVVw=; b=abp/lRglFror++oLFT82t67urT5axz9ITx2pZmJ5QT3xSvpWfB86d6HAqku0XBPY78nl q3IrRmLzfDUchXFRhCVWOx5cAYhw0x+TsfZiDSxw9ugd8riU6loSvV6jmviRl5KyXt4h 36zg3a82uvh2UUT0gJjCJhhjJEAAc2K3LYF8XGwwlETj/JvUuAJ4UaXSfP7cZs/pSUCW XZlhWI0a7IKbbZsyIwJvnFlj22TCdqb2QCpiHpeuCvVXduqclAEuaG9XNc8A9aQoBVk3 akyW15GUZaZZSxuM2TIXg8911dGRRolu+BNbFtz8oJrXqBL/5e+hAvnl4Jf4liaMXlBl Kg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3eby66wrrp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:54 +0000 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 21LCt1cm011314; Mon, 21 Feb 2022 13:07:54 GMT Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com with ESMTP id 3eby66wrqk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:53 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 21LCwvlp007314; Mon, 21 Feb 2022 13:07:52 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma01fra.de.ibm.com with ESMTP id 3ear68std0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:51 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 21LD7mFw45351270 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 21 Feb 2022 13:07:48 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AD1BA4C04A; Mon, 21 Feb 2022 13:07:48 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 729BE4C059; Mon, 21 Feb 2022 13:07:48 +0000 (GMT) Received: from t46lp57.lnxne.boe (unknown [9.152.108.100]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 21 Feb 2022 13:07:48 +0000 (GMT) From: Nico Boehr To: kvm@vger.kernel.org, linux-s390@vger.kernel.org Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com, david@redhat.com Subject: [kvm-unit-tests PATCH v2 4/8] s390x: Add tests for STCRW Date: Mon, 21 Feb 2022 14:07:42 +0100 Message-Id: <20220221130746.1754410-5-nrb@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220221130746.1754410-1-nrb@linux.ibm.com> References: <20220221130746.1754410-1-nrb@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: sSIF9NBFgSnnT5NMGoo_nMAuPvzSOD09 X-Proofpoint-GUID: 9STb_ZVPZAoqG-FOaX-h5i5XNZfjGGJ7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-21_06,2022-02-21_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 mlxlogscore=999 priorityscore=1501 bulkscore=0 mlxscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 malwarescore=0 impostorscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202210078 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The test consists of two parts: First a simple check to ensure we enforce an aligned address. We test misalignment by 1 and 2 bytes. The second part tests the handling of pending Channel Reports (CR). We first assume no CR is initally pending and check STCRW returns accordingly. Then, we generate a CR by resetting a Channel Path using RCHP and make sure this results in exactly one CRW being generated which has a Reporting-Source Code (RSC) corresponding to the Channel Path facility. Signed-off-by: Nico Boehr Reviewed-by: Claudio Imbrenda Reviewed-by: Pierre Morel --- lib/s390x/css.h | 17 ++++++++++ lib/s390x/css_lib.c | 60 +++++++++++++++++++++++++++++++++ s390x/css.c | 82 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 159 insertions(+) diff --git a/lib/s390x/css.h b/lib/s390x/css.h index 0db8a28166f6..a6a68577248b 100644 --- a/lib/s390x/css.h +++ b/lib/s390x/css.h @@ -266,6 +266,20 @@ static inline int rchp(unsigned long chpid) return cc; } +static inline int stcrw(uint32_t *crw) +{ + int cc; + + asm volatile( + " stcrw %[crw]\n" + " ipm %[cc]\n" + " srl %[cc],28" + : [cc] "=d" (cc) + : [crw] "Q" (*crw) + : "cc", "memory"); + return cc; +} + /* Debug functions */ char *dump_pmcw_flags(uint16_t f); char *dump_scsw_flags(uint32_t f); @@ -294,6 +308,9 @@ int css_residual_count(unsigned int schid); void enable_io_isc(uint8_t isc); int wait_and_check_io_completion(int schid); +int css_find_installed_chpid(int sid, uint8_t *chpid_out); +int css_generate_crw(int sid); + /* * CHSC definitions */ diff --git a/lib/s390x/css_lib.c b/lib/s390x/css_lib.c index 80e9e078b0f6..a9f5097f3486 100644 --- a/lib/s390x/css_lib.c +++ b/lib/s390x/css_lib.c @@ -504,3 +504,63 @@ void enable_io_isc(uint8_t isc) value = (uint64_t)isc << 24; lctlg(6, value); } + +static int is_path_installed(struct schib *schib, int chp_idx) +{ + return schib->pmcw.pim & BIT(7 - chp_idx); +} + +/* + * css_find_installed_chpid: find any installed CHPID + * @sid: subsystem-identification word + * @chpid_out: store the found chpid here, left alone if none found + * + * returns 0 on success, -1 if no chpid found any other value + * indicates the condition code of a failing STSCH instruction + */ +int css_find_installed_chpid(int sid, uint8_t *chpid_out) +{ + int cc; + + cc = stsch(sid, &schib); + if (cc) { + report_fail("%s: sch %08x failed with cc=%d", __func__, sid, cc); + return cc; + } + + for (int i = 0; i < ARRAY_SIZE(schib.pmcw.chpid); i++) { + if (is_path_installed(&schib, i)) { + *chpid_out = schib.pmcw.chpid[i]; + return 0; + } + } + + return -1; +} + +/* + * css_generate_crw: Generate a CRW by issuing RCHP on any channel path + * @sid: subsystem-identification word + * + * returns 0 when a CRW was generated, -1 if no chpid found. + */ +int css_generate_crw(int sid) +{ + int ret, cc; + uint8_t chpid; + + report_prefix_push("Generate CRW"); + + ret = css_find_installed_chpid(sid, &chpid); + if (ret) { + report_fail("No CHPID found: ret=%d", ret); + return -1; + } + + cc = rchp(chpid); + report(!cc, "rhcp cc != 0"); + + report_prefix_pop(); + + return 0; +} diff --git a/s390x/css.c b/s390x/css.c index 932daf69bb36..6a2db79c8097 100644 --- a/s390x/css.c +++ b/s390x/css.c @@ -383,6 +383,87 @@ static void test_msch(void) schib.pmcw.flags = old_pmcw_flags; } +static void check_stcrw_no_crw_available(void) +{ + uint32_t crw = 0xfeedc0fe; + int cc; + + report_prefix_push("No CRW available"); + cc = stcrw(&crw); + report(cc == 1, "cc == 1"); + report(!crw, "stored zeroes in crw"); + report_prefix_pop(); +} + +static int check_stcrw_crw_available(void) +{ + const uint32_t magic = 0xfeedc0fe; + uint32_t crw = magic; + int cc; + + report_prefix_push("CRW available"); + cc = stcrw(&crw); + report(!cc, "cc is zero"); + report(crw != magic, "stored crw"); + report_prefix_pop(); + + return crw; +} + +static uint32_t crw_get_rsc(uint32_t crw) +{ + const int rsc_begin = 4; + const int rsc_end = 8; + + return (crw & GENMASK(31 - rsc_begin, 31 - rsc_end)) >> 24; +} + +#define CRW_RSC_CHP 4 +static void test_stcrw(void) +{ + const int align_to = 4; + int res; + uint32_t crw; + + if (!test_device_sid) { + report_skip("No device"); + return; + } + + report_prefix_push("Unaligned"); + for (int i = 1; i < align_to; i *= 2) { + report_prefix_pushf("%d", i); + + expect_pgm_int(); + stcrw((uint32_t *)(alignment_test_page + i)); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + + report_prefix_pop(); + } + report_prefix_pop(); + + report_prefix_push("No CRW available initally"); + check_stcrw_no_crw_available(); + report_prefix_pop(); + + res = css_generate_crw(test_device_sid); + if (res) { + report_skip("Couldn't generate CRW"); + report_prefix_pop(); + return; + } + + crw = check_stcrw_crw_available(); + + report_prefix_push("CRW available"); + report(crw_get_rsc(crw) == CRW_RSC_CHP, "CRW has Channel Path RSC"); + report_prefix_pop(); + + report_prefix_push("No more CRWs pending"); + check_stcrw_no_crw_available(); + report_prefix_pop(); +} + static struct { const char *name; void (*func)(void); @@ -396,6 +477,7 @@ static struct { { "measurement block format0", test_schm_fmt0 }, { "measurement block format1", test_schm_fmt1 }, { "msch", test_msch }, + { "stcrw", test_stcrw }, { NULL, NULL } }; From patchwork Mon Feb 21 13:07:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Boehr X-Patchwork-Id: 12753603 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 4149BC433FE for ; Mon, 21 Feb 2022 13:08:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358572AbiBUNIY (ORCPT ); Mon, 21 Feb 2022 08:08:24 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:39998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358549AbiBUNIU (ORCPT ); Mon, 21 Feb 2022 08:08:20 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B44261EC52; Mon, 21 Feb 2022 05:07:55 -0800 (PST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21LCgIGq023270; Mon, 21 Feb 2022 13:07:55 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=ILNYyHhfWX4IBhBTXyc9j6Dahg2hHrYhKGqQRtMnia4=; b=CZR/NQqHwzlVTm6jENRtSqnly01j6EQz767yiJV5NG4sfGq+469WfEIz/hoYFnwnQCUt jFm1IQwbbBn6hDmIPBw3YdaHjt2tsaVqtnsW52jY0R6p4EP+vnTAWhCTN/RghWiK9Ef3 A1ROQzWmdI3fM9IOtYaKBIrk0B7AV69OY2c4Dl7DTc/98LQpwv4ZzQQIQtT8sG7THHPV 69T3LnXRlLiFaLRoN8nTlYJ2dZ/qC+PeG/HARb+AdbARHquDnb3S1kmNxBP90GmXdWzY J+73nBHzdL0Z3nDONMEJobqNEwcth9YFB2r4yr1MKtBSaEBzZClsVJNJZaYvhqSZDK27 Eg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ecayg8gcv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:55 +0000 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 21LCtES0022050; Mon, 21 Feb 2022 13:07:54 GMT Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ecayg8gc1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:54 +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 21LCwlrq019562; Mon, 21 Feb 2022 13:07:52 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma04fra.de.ibm.com with ESMTP id 3ear691t6x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:52 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 21LD7nFb57344294 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 21 Feb 2022 13:07:49 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 110694C040; Mon, 21 Feb 2022 13:07:49 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C2BD44C04E; Mon, 21 Feb 2022 13:07:48 +0000 (GMT) Received: from t46lp57.lnxne.boe (unknown [9.152.108.100]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 21 Feb 2022 13:07:48 +0000 (GMT) From: Nico Boehr To: kvm@vger.kernel.org, linux-s390@vger.kernel.org Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com, david@redhat.com Subject: [kvm-unit-tests PATCH v2 5/8] s390x: Add more tests for SSCH Date: Mon, 21 Feb 2022 14:07:43 +0100 Message-Id: <20220221130746.1754410-6-nrb@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220221130746.1754410-1-nrb@linux.ibm.com> References: <20220221130746.1754410-1-nrb@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: R2XyDNKm4bre1SlokP22vDey5lmG9HIy X-Proofpoint-ORIG-GUID: BToPuQPvFMzTuW9bcw-3EdJslEcLdF1K X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-21_06,2022-02-21_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 lowpriorityscore=0 bulkscore=0 phishscore=0 clxscore=1015 suspectscore=0 malwarescore=0 impostorscore=0 mlxlogscore=999 adultscore=0 spamscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202210078 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We already have some coverage of SSCH due to its use in start_ccw1_chain() in css_lib, but two more cases deserve our attention: - unaligned operand address. We check for misalignment by 1 and 2 bytes. - an invalid ORB structure. Signed-off-by: Nico Boehr Reviewed-by: Claudio Imbrenda Reviewed-by: Pierre Morel --- s390x/css.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/s390x/css.c b/s390x/css.c index 6a2db79c8097..a90a0cd64e2b 100644 --- a/s390x/css.c +++ b/s390x/css.c @@ -464,6 +464,38 @@ static void test_stcrw(void) report_prefix_pop(); } +static void test_ssch(void) +{ + const int align_to = 4; + struct orb orb; + + if (!test_device_sid) { + report_skip("No device"); + return; + } + + report_prefix_push("Unaligned"); + for (int i = 1; i < align_to; i *= 2) { + report_prefix_pushf("%d", i); + + expect_pgm_int(); + ssch(test_device_sid, (struct orb *)(alignment_test_page + i)); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + + report_prefix_pop(); + } + report_prefix_pop(); + + report_prefix_push("Invalid ORB"); + + memset(&orb, 0xff, sizeof(orb)); + expect_pgm_int(); + ssch(test_device_sid, &orb); + check_pgm_int_code(PGM_INT_CODE_OPERAND); + + report_prefix_pop(); +} + static struct { const char *name; void (*func)(void); @@ -478,6 +510,7 @@ static struct { { "measurement block format1", test_schm_fmt1 }, { "msch", test_msch }, { "stcrw", test_stcrw }, + { "ssch", test_ssch }, { NULL, NULL } }; From patchwork Mon Feb 21 13:07:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Boehr X-Patchwork-Id: 12753607 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 A1D95C433F5 for ; Mon, 21 Feb 2022 13:08:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358580AbiBUNI2 (ORCPT ); Mon, 21 Feb 2022 08:08:28 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:40018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358557AbiBUNIV (ORCPT ); Mon, 21 Feb 2022 08:08:21 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D70B1EC4B; Mon, 21 Feb 2022 05:07:58 -0800 (PST) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21LBgja8020649; Mon, 21 Feb 2022 13:07:57 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 : content-transfer-encoding : mime-version; s=pp1; bh=iplXjZQPCjA5Vn+ln7KCTNZdpLgHFNCce96hooYxNPc=; b=P6H4tstrEoCY+alD9/t3n5X2NV3EC4SxmAgpiMfz7p0Y5OCEKcqnH3Q5+AnlsCm7YWUB 2dSELlegUKf6rEsZBLWnJRHobnks9jgMt5i3X3mMciA8B0z5vhgjf6GVfaQ5CedElgXA lVJFaOzNe22u+sTohjzDxm03g4Kq7AGJHb4uL+iahgvkQbHtUzA54zD0Lgm4UI/dZSGl srp9LII8W3KGD4+vVK27i/D8P+dtO7vyy460Ok/biPlsuBI2A3mFPCfnUzlw0J/cRatM di+s1cmlV+KxRngfn2Vx8SkEKvXmYpP/56va+QOHKLjmRKbn7GaJ2xEoHVa94XQU97eZ bw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3eca3shq1x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:57 +0000 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 21LD0taj028532; Mon, 21 Feb 2022 13:07:56 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com with ESMTP id 3eca3shq1b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:56 +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 21LCwp1G006874; Mon, 21 Feb 2022 13:07:55 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma04ams.nl.ibm.com with ESMTP id 3ear68tm6c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:54 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 21LD7n2W51315194 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 21 Feb 2022 13:07:49 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5FA774C040; Mon, 21 Feb 2022 13:07:49 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1CF604C04A; Mon, 21 Feb 2022 13:07:49 +0000 (GMT) Received: from t46lp57.lnxne.boe (unknown [9.152.108.100]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 21 Feb 2022 13:07:49 +0000 (GMT) From: Nico Boehr To: kvm@vger.kernel.org, linux-s390@vger.kernel.org Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com, david@redhat.com Subject: [kvm-unit-tests PATCH v2 6/8] s390x: Add more tests for STSCH Date: Mon, 21 Feb 2022 14:07:44 +0100 Message-Id: <20220221130746.1754410-7-nrb@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220221130746.1754410-1-nrb@linux.ibm.com> References: <20220221130746.1754410-1-nrb@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Pa2GNRc5S_bRsd4RSGg5cBM6Jm8UPdDg X-Proofpoint-ORIG-GUID: 9hmCKYeO8cE8ZQ33ZVuCletW0NMqQqaI X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-21_06,2022-02-21_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 impostorscore=0 suspectscore=0 priorityscore=1501 mlxscore=0 spamscore=0 bulkscore=0 adultscore=0 malwarescore=0 lowpriorityscore=0 clxscore=1015 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202210078 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org css_lib extensively uses STSCH, but two more cases deserve their own tests: - unaligned address for SCHIB. We check for misalignment by 1 and 2 bytes. - channel not operational - bit 47 in SID not set - bit 5 of PMCW flags. As per the principles of operation, bit 5 of the PMCW flags shall be ignored by msch and always stored as zero by stsch. Currently, QEMU requires this bit to always be zero on msch, which is why this test currently fails. A fix was posted upstream ("[PATCH qemu] s390x/css: fix PMCW invalid mask"). Here's the QEMU PMCW invalid mask fix: https://lists.nongnu.org/archive/html/qemu-s390x/2021-12/msg00100.html Signed-off-by: Nico Boehr --- s390x/css.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) diff --git a/s390x/css.c b/s390x/css.c index a90a0cd64e2b..021eb12573c0 100644 --- a/s390x/css.c +++ b/s390x/css.c @@ -496,6 +496,78 @@ static void test_ssch(void) report_prefix_pop(); } +static void test_stsch(void) +{ + const int align_to = 4; + struct schib schib; + int cc; + + if (!test_device_sid) { + report_skip("No device"); + return; + } + + report_prefix_push("Unaligned"); + for (int i = 1; i < align_to; i *= 2) { + report_prefix_pushf("%d", i); + + expect_pgm_int(); + stsch(test_device_sid, (struct schib *)(alignment_test_page + i)); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + + report_prefix_pop(); + } + report_prefix_pop(); + + report_prefix_push("Invalid subchannel number"); + cc = stsch(0x0001ffff, &schib); + report(cc == 3, "Channel not operational"); + report_prefix_pop(); + + report_prefix_push("Bit 47 in SID is zero"); + expect_pgm_int(); + stsch(0x0000ffff, &schib); + check_pgm_int_code(PGM_INT_CODE_OPERAND); + report_prefix_pop(); +} + +static void test_pmcw_bit5(void) +{ + int cc; + uint16_t old_pmcw_flags; + + cc = stsch(test_device_sid, &schib); + if (cc) { + report_fail("stsch: sch %08x failed with cc=%d", test_device_sid, cc); + return; + } + old_pmcw_flags = schib.pmcw.flags; + + report_prefix_push("Bit 5 set"); + + schib.pmcw.flags = old_pmcw_flags | BIT(15 - 5); + cc = msch(test_device_sid, &schib); + report(!cc, "MSCH cc == 0"); + + cc = stsch(test_device_sid, &schib); + report(!cc, "STSCH cc == 0"); + report(!(schib.pmcw.flags & BIT(15 - 5)), "STSCH PMCW Bit 5 is clear"); + + report_prefix_pop(); + + report_prefix_push("Bit 5 clear"); + + schib.pmcw.flags = old_pmcw_flags & ~BIT(15 - 5); + cc = msch(test_device_sid, &schib); + report(!cc, "MSCH cc == 0"); + + cc = stsch(test_device_sid, &schib); + report(!cc, "STSCH cc == 0"); + report(!(schib.pmcw.flags & BIT(15 - 5)), "STSCH PMCW Bit 5 is clear"); + + report_prefix_pop(); +} + static struct { const char *name; void (*func)(void); @@ -511,6 +583,8 @@ static struct { { "msch", test_msch }, { "stcrw", test_stcrw }, { "ssch", test_ssch }, + { "stsch", test_stsch }, + { "pmcw bit 5 ignored", test_pmcw_bit5 }, { NULL, NULL } }; From patchwork Mon Feb 21 13:07:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Boehr X-Patchwork-Id: 12753605 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 B6D35C433F5 for ; Mon, 21 Feb 2022 13:08:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358550AbiBUNI1 (ORCPT ); Mon, 21 Feb 2022 08:08:27 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:40002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358551AbiBUNIU (ORCPT ); Mon, 21 Feb 2022 08:08:20 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A01221EAFB; Mon, 21 Feb 2022 05:07:57 -0800 (PST) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21LAcYdE016042; Mon, 21 Feb 2022 13:07:56 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=EZbL3x6R1FugjcHfkRqvQ0Rqsgvz6qMdmHRUKz2rBmo=; b=MqNi2u+d2MlutErQ0zd7po8R7LwCscdgQMyx8VY8VZ0clwv9yMMcjFcW09E6ojIEJ/+d Vs3uajdk9ICmeNX0sx60wYhcq9JbhIUGbCjoz5kaf4vPICCrgIPMsHnBCJbk/874FWvv crVhquO/ljtfcr1i/eg5rgXgnWCGOwcxCwrJjZHPS3Q54swfHZWzzLIFOxpMyh4aAc3G gvGAdQV/KhBc2oYgnL5+8B+rAaQWEoG1Wew71ez1x6RTcueN4VeKWkj4px4kRalVaG9w gGavjNd8+WdJrCeYzlbBPCQVnP82MgZzTUfc3lfQdZFHBGKIoefS7T+PzpBnb36qvSAP gA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ec65aq0mt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:56 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 21LCxFT4020908; Mon, 21 Feb 2022 13:07:55 GMT Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ec65aq0m1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:55 +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 21LCuoO7027619; Mon, 21 Feb 2022 13:07:53 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma02fra.de.ibm.com with ESMTP id 3ear68stnp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:53 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 21LD7nns51315198 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 21 Feb 2022 13:07:49 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AD8764C052; Mon, 21 Feb 2022 13:07:49 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6BAD94C044; Mon, 21 Feb 2022 13:07:49 +0000 (GMT) Received: from t46lp57.lnxne.boe (unknown [9.152.108.100]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 21 Feb 2022 13:07:49 +0000 (GMT) From: Nico Boehr To: kvm@vger.kernel.org, linux-s390@vger.kernel.org Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com, david@redhat.com Subject: [kvm-unit-tests PATCH v2 7/8] s390x: Add tests for TSCH Date: Mon, 21 Feb 2022 14:07:45 +0100 Message-Id: <20220221130746.1754410-8-nrb@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220221130746.1754410-1-nrb@linux.ibm.com> References: <20220221130746.1754410-1-nrb@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: DNaZpdXN94icLi6Xqs5FQdlpb2aiSrOK X-Proofpoint-ORIG-GUID: A0qOd1gTqz8VB1nFyg4WwwY1Q8-D_QXA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-21_06,2022-02-21_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 mlxlogscore=999 bulkscore=0 suspectscore=0 impostorscore=0 phishscore=0 clxscore=1015 spamscore=0 malwarescore=0 priorityscore=1501 adultscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202210078 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org TSCH has two special cases which need to be tested: - unaligned address. We test for misalignment by 1 and 2 bytes. - channel not operational - bit 47 in SID not set Signed-off-by: Nico Boehr Reviewed-by: Claudio Imbrenda Reviewed-by: Pierre Morel --- s390x/css.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/s390x/css.c b/s390x/css.c index 021eb12573c0..b2e027c99848 100644 --- a/s390x/css.c +++ b/s390x/css.c @@ -568,6 +568,41 @@ static void test_pmcw_bit5(void) report_prefix_pop(); } +static void test_tsch(void) +{ + const int align_to = 4; + struct irb irb; + int cc; + + if (!test_device_sid) { + report_skip("No device"); + return; + } + + report_prefix_push("Unaligned"); + for (int i = 1; i < align_to; i *= 2) { + report_prefix_pushf("%d", i); + + expect_pgm_int(); + tsch(test_device_sid, (struct irb *)(alignment_test_page + i)); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + + report_prefix_pop(); + } + report_prefix_pop(); + + report_prefix_push("Invalid subchannel number"); + cc = tsch(0x0001ffff, &irb); + report(cc == 3, "Channel not operational"); + report_prefix_pop(); + + report_prefix_push("Bit 47 in SID is zero"); + expect_pgm_int(); + tsch(0x0000ffff, &irb); + check_pgm_int_code(PGM_INT_CODE_OPERAND); + report_prefix_pop(); +} + static struct { const char *name; void (*func)(void); @@ -585,6 +620,7 @@ static struct { { "ssch", test_ssch }, { "stsch", test_stsch }, { "pmcw bit 5 ignored", test_pmcw_bit5 }, + { "tsch", test_tsch }, { NULL, NULL } }; From patchwork Mon Feb 21 13:07:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Boehr X-Patchwork-Id: 12753608 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 0B886C4332F for ; Mon, 21 Feb 2022 13:08:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1358588AbiBUNI3 (ORCPT ); Mon, 21 Feb 2022 08:08:29 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:40022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1358561AbiBUNIV (ORCPT ); Mon, 21 Feb 2022 08:08:21 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 769661EAFB; Mon, 21 Feb 2022 05:07:58 -0800 (PST) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 21LA1RUH015805; Mon, 21 Feb 2022 13:07:58 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=Zqbky2/cC7AetT8vZX04ajXKKos844KHqybipcQnzXo=; b=CwxjaKo8q/Wd4lI3x4LDPiPaq3G8MdHf07q4zEyK1OZn0Zy54LT41dpFeS6widLG/R5J e809UGlkIRadzGp3z61UI7rv/tU01cfxs0/IPIfxCrWtAgTq01L4zOHQge/mLga4DrAW xHblFhzFYbnKObbgZv/h+tbLYhz9jJanVAjQ0eGoJwLpkmuzTjZw4gj4F0Bd7cQ3Gpd/ pVlKTuAtSjcmT+kAcR/ck+H+QIr1H9dA0Xb6s/wEwfYMqnt2jFDPQMLS4mUX5Ui7ddCK hzOxyD6CAfFpXMc+jTvoC+OQkaz6Zm3g12cnTwKEAH4BT2S5ENIT7pSRzJjd/44yrlv6 tA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ec5q0fsdu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:58 +0000 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 21LCgfrX015248; Mon, 21 Feb 2022 13:07:57 GMT Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com with ESMTP id 3ec5q0fscw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:57 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 21LCwnu2007238; Mon, 21 Feb 2022 13:07:55 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma01fra.de.ibm.com with ESMTP id 3ear68stdd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 21 Feb 2022 13:07:55 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 21LD7ovO55771532 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 21 Feb 2022 13:07:50 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0974F4C05E; Mon, 21 Feb 2022 13:07:50 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BB0474C058; Mon, 21 Feb 2022 13:07:49 +0000 (GMT) Received: from t46lp57.lnxne.boe (unknown [9.152.108.100]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Mon, 21 Feb 2022 13:07:49 +0000 (GMT) From: Nico Boehr To: kvm@vger.kernel.org, linux-s390@vger.kernel.org Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com, david@redhat.com Subject: [kvm-unit-tests PATCH v2 8/8] s390x: Add EPSW test Date: Mon, 21 Feb 2022 14:07:46 +0100 Message-Id: <20220221130746.1754410-9-nrb@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220221130746.1754410-1-nrb@linux.ibm.com> References: <20220221130746.1754410-1-nrb@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: W0_Grn92Rw7gkReVRS-6h2ad1IbmExWb X-Proofpoint-GUID: W22tTyjRLaGbbwfkU2lHMXzci6bR-y4t X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.816,Hydra:6.0.425,FMLib:17.11.62.513 definitions=2022-02-21_06,2022-02-21_01,2021-12-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxscore=0 malwarescore=0 adultscore=0 phishscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2201110000 definitions=main-2202210078 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org EPSW is only intercepted in certain cases. One of these cases is if we have a CRW pending and machine check interrupts are masked. This can be achieved by issuing a RCHP on a valid channel path. This is why we need the CSS lib and an IO device in this test and hence need to skip it when not running under QEMU. Three special cases deserve our attention: - upper 32 bits of both operands are never modified, - second operand is not modified if it is zero. - when both operands are zero, bits 0-11 and 13-31 of the PSW are stored in r0. We also verify we get the correct contents when the second operand is zero. To do so, we save the data stored at the first operand in the first case as a reference. As we don't mess with the PSW, the only thing that might change is the Condition Code (CC) due to some instruction in between, so we zero it out using zero_out_cc_from_epsw_op1(). This test must be fenced when running in non-QEMU. Signed-off-by: Nico Boehr Reviewed-by: Claudio Imbrenda --- s390x/Makefile | 1 + s390x/epsw.c | 113 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 ++ 3 files changed, 118 insertions(+) create mode 100644 s390x/epsw.c diff --git a/s390x/Makefile b/s390x/Makefile index a76b78e5a011..25449708da0d 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -27,6 +27,7 @@ tests += $(TEST_DIR)/edat.elf tests += $(TEST_DIR)/mvpg-sie.elf tests += $(TEST_DIR)/spec_ex-sie.elf tests += $(TEST_DIR)/firq.elf +tests += $(TEST_DIR)/epsw.elf pv-tests += $(TEST_DIR)/pv-diags.elf diff --git a/s390x/epsw.c b/s390x/epsw.c new file mode 100644 index 000000000000..192115cf2fac --- /dev/null +++ b/s390x/epsw.c @@ -0,0 +1,113 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * EPSW Interception Tests + * + * Copyright IBM Corp. 2022 + * + * Authors: + * Nico Boehr + */ +#include +#include +#include + +static uint32_t zero_out_cc_from_epsw_op1(uint32_t epsw_op1) +{ + return epsw_op1 & ~GENMASK(31 - 18, 31 - 20); +} + +static void generate_crw(void) +{ + int test_device_sid = css_enumerate(); + int cc, ret; + + if (!(test_device_sid & SCHID_ONE)) { + report_fail("No I/O device found"); + return; + } + + cc = css_enable(test_device_sid, IO_SCH_ISC); + report(cc == 0, "Enable subchannel %08x", test_device_sid); + + ret = css_generate_crw(test_device_sid); + if (ret) + report_fail("Couldn't generate CRW"); +} + +static void test_epsw(void) +{ + const uint64_t MAGIC1 = 0x1234567890abcdefUL; + const uint64_t MAGIC2 = 0xcafedeadbeeffaceUL; + + uint64_t op1 = MAGIC1; + uint64_t op2 = MAGIC2; + uint32_t prev_epsw_op1; + + /* + * having machine check interrupts masked and pending CRW ensures + * EPSW is intercepted under KVM + */ + generate_crw(); + + report_prefix_push("both operands given"); + asm volatile( + "epsw %0, %1\n" + : "+&d" (op1), "+&a" (op2)); + report(upper_32_bits(op1) == upper_32_bits(MAGIC1) && + upper_32_bits(op2) == upper_32_bits(MAGIC2), + "upper 32 bits unmodified"); + report(lower_32_bits(op1) != lower_32_bits(MAGIC1) && + lower_32_bits(op2) != lower_32_bits(MAGIC2), + "lower 32 bits modified"); + prev_epsw_op1 = zero_out_cc_from_epsw_op1(lower_32_bits(op1)); + report_prefix_pop(); + + report_prefix_push("second operand 0"); + op1 = MAGIC1; + op2 = MAGIC2; + asm volatile( + " lgr 0,%[op2]\n" + " epsw %[op1], 0\n" + " lgr %[op2],0\n" + : [op2] "+&d" (op2), [op1] "+&a" (op1) + : + : "0"); + report(upper_32_bits(op1) == upper_32_bits(MAGIC1), + "upper 32 bits of first operand unmodified"); + report(zero_out_cc_from_epsw_op1(lower_32_bits(op1)) == prev_epsw_op1, + "first operand matches previous reading"); + report(op2 == MAGIC2, "r0 unmodified"); + report_prefix_pop(); + + report_prefix_push("both operands 0"); + op1 = MAGIC1; + asm volatile( + " lgr 0,%[op1]\n" + " epsw 0, 0\n" + " lgr %[op1],0\n" + : [op1] "+&d" (op1) + : + : "0"); + report(upper_32_bits(op1) == upper_32_bits(MAGIC1), + "upper 32 bits of first operand unmodified"); + report(zero_out_cc_from_epsw_op1(lower_32_bits(op1)) == prev_epsw_op1, + "first operand matches previous reading"); + report_prefix_pop(); +} + +int main(int argc, char **argv) +{ + if (!vm_is_kvm() && !vm_is_tcg()) { + report_skip("Not running under QEMU"); + goto done; + } + + report_prefix_push("epsw"); + + test_epsw(); + +done: + report_prefix_pop(); + + return report_summary(); +} diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index 8b148fe31ac0..aeb82246dddf 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -139,3 +139,7 @@ accel = tcg [sck] file = sck.elf + +[epsw] +file = epsw.elf +extra_params = -device virtio-net-ccw