From patchwork Tue Oct 10 08:49:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 13415036 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 C42CCCD690B for ; Tue, 10 Oct 2023 08:51:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230036AbjJJIvp (ORCPT ); Tue, 10 Oct 2023 04:51:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229660AbjJJIvf (ORCPT ); Tue, 10 Oct 2023 04:51:35 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D12E397 for ; Tue, 10 Oct 2023 01:51:32 -0700 (PDT) Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39A8k7nF020416 for ; Tue, 10 Oct 2023 08:51:32 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=bBt+AcKEPwHlT1mhIG6eOxmu5yk+gOSnOCal5q7tATg=; b=HcPwWT/vNJaoWhQP9fenVS4Q71f1iT4q4tv3q9pLrd9EryeSkb4AjR1CqfPQOUC1yIqu uUW+REN2aKfVbRRlDd+PsAgMXGTvUqTtvztfJY9Wb7Zbm1L//uI8gjOhclTnjhoi5+dm tklEwwuDGUe09B0DuNOgTrXf1EuSQfdnTdjuT7rHPYmH0vDw8m0Qi5poOFal9BJhOYKf ayWqJ2oT75b/Jz7/4d5ZVOyjmy+hX03d8/MA0bu3AYsEVThL62dzehimGEEN5FQy/6Sh Qgu667bYogbE/9gWsHiT7884rcu+ofXqvx+nVK97XBwfu712JTTty+/MypgbU2D3U83+ uA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tn3ct08u7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 10 Oct 2023 08:51:29 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 39A8kbXS021575 for ; Tue, 10 Oct 2023 08:51:19 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tn3ct07xt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 08:51:18 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 39A7B6M7028255; Tue, 10 Oct 2023 08:51:08 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3tkj1xybyk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 08:51:08 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 39A8p5JJ6554112 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 08:51:05 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6A25C2004F; Tue, 10 Oct 2023 08:51:05 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3E9FD2004E; Tue, 10 Oct 2023 08:51:05 +0000 (GMT) Received: from a46lp67.. (unknown [9.152.108.100]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 10 Oct 2023 08:51:05 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: imbrenda@linux.ibm.com, thuth@redhat.com, david@redhat.com, nsg@linux.ibm.com, nrb@linux.ibm.com Subject: [kvm-unit-tests PATCH v2 1/7] lib: s390x: Add ap library Date: Tue, 10 Oct 2023 08:49:30 +0000 Message-Id: <20231010084936.70773-2-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231010084936.70773-1-frankja@linux.ibm.com> References: <20231010084936.70773-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: KITtciHsIDcmo0Da8wS0YPAm_0lMjtMQ X-Proofpoint-GUID: nn2wUdaZC6udytAyxCoVcOe92dbmJ-rb X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_04,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 mlxscore=0 spamscore=0 malwarescore=0 priorityscore=1501 suspectscore=0 phishscore=0 impostorscore=0 adultscore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100065 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add functions and definitions needed to test the Adjunct Processor (AP) crypto interface. Signed-off-by: Janosch Frank --- lib/s390x/ap.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++ lib/s390x/ap.h | 88 +++++++++++++++++++++++++++++++++++++++++++++++ s390x/Makefile | 1 + 3 files changed, 181 insertions(+) create mode 100644 lib/s390x/ap.c create mode 100644 lib/s390x/ap.h diff --git a/lib/s390x/ap.c b/lib/s390x/ap.c new file mode 100644 index 00000000..4af3cdee --- /dev/null +++ b/lib/s390x/ap.c @@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * AP crypto functions + * + * Some parts taken from the Linux AP driver. + * + * Copyright IBM Corp. 2023 + * Author: Janosch Frank + * Tony Krowiak + * Martin Schwidefsky + * Harald Freudenberger + */ + +#include +#include +#include +#include +#include + +int ap_pqap_tapq(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw, + struct pqap_r2 *r2) +{ + struct pqap_r0 r0 = { + .ap = ap, + .qn = qn, + .fc = PQAP_TEST_APQ + }; + int cc; + + /* + * Test AP Queue + * + * Writes AP configuration information to the memory pointed + * at by GR2. + * + * Inputs: GR0 + * Outputs: GR1 (APQSW), GR2 (tapq data) + * Synchronous + */ + asm volatile( + " lgr 0,%[r0]\n" + " .insn rre,0xb2af0000,0,0\n" /* PQAP */ + " stg 1,%[apqsw]\n" + " stg 2,%[r2]\n" + " ipm %[cc]\n" + " srl %[cc],28\n" + : [apqsw] "=&T" (*apqsw), [r2] "=&T" (*r2), [cc] "=&d" (cc) + : [r0] "d" (r0)); + + return cc; +} + +int ap_pqap_qci(struct ap_config_info *info) +{ + struct pqap_r0 r0 = { .fc = PQAP_QUERY_AP_CONF_INFO }; + int cc; + + /* + * Query AP Configuration Information + * + * Writes AP configuration information to the memory pointed + * at by GR2. + * + * Inputs: GR0, GR2 (QCI block address) + * Outputs: memory at GR2 address + * Synchronous + */ + asm volatile( + " lgr 0,%[r0]\n" + " lgr 2,%[info]\n" + " .insn rre,0xb2af0000,0,0\n" /* PQAP */ + " ipm %[cc]\n" + " srl %[cc],28\n" + : [cc] "=&d" (cc) + : [r0] "d" (r0), [info] "d" (info) + : "cc", "memory", "0", "2"); + + return cc; +} + +bool ap_check(void) +{ + /* + * Base AP support has no STFLE or SCLP feature bit but the + * PQAP QCI support is indicated via stfle bit 12. As this + * library relies on QCI we bail out if it's not available. + */ + if (!test_facility(12)) + return false; + + return true; +} diff --git a/lib/s390x/ap.h b/lib/s390x/ap.h new file mode 100644 index 00000000..411591f2 --- /dev/null +++ b/lib/s390x/ap.h @@ -0,0 +1,88 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * AP definitions + * + * Some parts taken from the Linux AP driver. + * + * Copyright IBM Corp. 2023 + * Author: Janosch Frank + * Tony Krowiak + * Martin Schwidefsky + * Harald Freudenberger + */ + +#ifndef _S390X_AP_H_ +#define _S390X_AP_H_ + +enum PQAP_FC { + PQAP_TEST_APQ, + PQAP_RESET_APQ, + PQAP_ZEROIZE_APQ, + PQAP_QUEUE_INT_CONTRL, + PQAP_QUERY_AP_CONF_INFO, + PQAP_QUERY_AP_COMP_TYPE, + PQAP_BEST_AP, +}; + +struct ap_queue_status { + uint32_t pad0; /* Ignored padding for zArch */ + uint32_t empty : 1; + uint32_t replies_waiting: 1; + uint32_t full : 1; + uint32_t pad1 : 4; + uint32_t irq_enabled : 1; + uint32_t rc : 8; + uint32_t pad2 : 16; +} __attribute__((packed)) __attribute__((aligned(8))); +_Static_assert(sizeof(struct ap_queue_status) == sizeof(uint64_t), "APQSW size"); + +struct ap_config_info { + uint8_t apsc : 1; /* S bit */ + uint8_t apxa : 1; /* N bit */ + uint8_t qact : 1; /* C bit */ + uint8_t rc8a : 1; /* R bit */ + uint8_t l : 1; /* L bit */ + uint8_t lext : 3; /* Lext bits */ + uint8_t reserved2[3]; + uint8_t Na; /* max # of APs - 1 */ + uint8_t Nd; /* max # of Domains - 1 */ + uint8_t reserved6[10]; + uint32_t apm[8]; /* AP ID mask */ + uint32_t aqm[8]; /* AP (usage) queue mask */ + uint32_t adm[8]; /* AP (control) domain mask */ + uint8_t _reserved4[16]; +} __attribute__((aligned(8))) __attribute__ ((__packed__)); +_Static_assert(sizeof(struct ap_config_info) == 128, "PQAP QCI size"); + +struct pqap_r0 { + uint32_t pad0; + uint8_t fc; + uint8_t t : 1; /* Test facilities (TAPQ)*/ + uint8_t pad1 : 7; + uint8_t ap; + uint8_t qn; +} __attribute__((packed)) __attribute__((aligned(8))); + +struct pqap_r2 { + uint8_t s : 1; /* Special Command facility */ + uint8_t m : 1; /* AP4KM */ + uint8_t c : 1; /* AP4KC */ + uint8_t cop : 1; /* AP is in coprocessor mode */ + uint8_t acc : 1; /* AP is in accelerator mode */ + uint8_t xcp : 1; /* AP is in XCP-mode */ + uint8_t n : 1; /* AP extended addressing facility */ + uint8_t pad_0 : 1; + uint8_t pad_1[3]; + uint8_t at; + uint8_t nd; + uint8_t pad_6; + uint8_t pad_7 : 4; + uint8_t qd : 4; +} __attribute__((packed)) __attribute__((aligned(8))); +_Static_assert(sizeof(struct pqap_r2) == sizeof(uint64_t), "pqap_r2 size"); + +bool ap_check(void); +int ap_pqap_tapq(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw, + struct pqap_r2 *r2); +int ap_pqap_qci(struct ap_config_info *info); +#endif diff --git a/s390x/Makefile b/s390x/Makefile index 6e967194..d9abe5c1 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -109,6 +109,7 @@ cflatobjs += lib/s390x/malloc_io.o cflatobjs += lib/s390x/uv.o cflatobjs += lib/s390x/sie.o cflatobjs += lib/s390x/fault.o +cflatobjs += lib/s390x/ap.o OBJDIRS += lib/s390x From patchwork Tue Oct 10 08:49:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 13415030 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 47017CD690B for ; Tue, 10 Oct 2023 08:51:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229807AbjJJIvd (ORCPT ); Tue, 10 Oct 2023 04:51:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231160AbjJJIvW (ORCPT ); Tue, 10 Oct 2023 04:51:22 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1131CB7 for ; Tue, 10 Oct 2023 01:51:19 -0700 (PDT) Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39A8k4Ep020345 for ; Tue, 10 Oct 2023 08:51:19 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=3D0CbE6WYDMx7GxiLswZEJn/rW4fCetV57TVns8ea5M=; b=mzOa13PzZml7oPIaDu1x+FFgt0lhDYLrwwU0vPbfcMsIX2IiGGu5P0rOGb/cyE3rH3io 6JxUIqRfyd0Wx9EGB4BnJU/dRZqbmrpfA5vmkf4FKQcXPkwXnzBdWIK2rLIPViFZnH5Q g1fW8uF3m+wT2s0iJfWermS160nnn08jdQekIOFXcrzCftnVeZaFdOs+/0f+pzKZ7ISE xVNIOW/bDEXRd7FB3AXEt6ajdw2ei+FiJo+sIXMKJ9PoLMfMWi/Z9HkIl/LwJ8P8Gzz9 V5osE/V7jqugESsGQJB47pnhfFAGjOYcjARRZ3+OHq+1laTvEawNnr0jA8E5SzeFlPcN Ww== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tn3ct089g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 10 Oct 2023 08:51:18 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 39A8lKhm024659 for ; Tue, 10 Oct 2023 08:51:13 GMT Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tn3ct07ya-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 08:51:12 +0000 Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 39A6jnhN028191; Tue, 10 Oct 2023 08:51:08 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3tkj1xybym-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 08:51:08 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 39A8p5HY7144172 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 08:51:05 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A64F42004D; Tue, 10 Oct 2023 08:51:05 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 729972005A; Tue, 10 Oct 2023 08:51:05 +0000 (GMT) Received: from a46lp67.. (unknown [9.152.108.100]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 10 Oct 2023 08:51:05 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: imbrenda@linux.ibm.com, thuth@redhat.com, david@redhat.com, nsg@linux.ibm.com, nrb@linux.ibm.com Subject: [kvm-unit-tests PATCH v2 2/7] s390x: Add guest 2 AP test Date: Tue, 10 Oct 2023 08:49:31 +0000 Message-Id: <20231010084936.70773-3-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231010084936.70773-1-frankja@linux.ibm.com> References: <20231010084936.70773-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: i7iVR3BwarXe_mOwqLGpGpJvGaVXvcaa X-Proofpoint-GUID: 7yYrK0CyeUHAjV_oMUnPLAiq8qI-4Pc7 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_04,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=696 mlxscore=0 spamscore=0 malwarescore=0 priorityscore=1501 suspectscore=0 phishscore=0 impostorscore=0 adultscore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100065 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add a test that checks the exceptions for the PQAP, NQAP and DQAP adjunct processor (AP) crypto instructions. Since triggering the exceptions doesn't require actual AP hardware, this test can run without complicated setup. Signed-off-by: Janosch Frank --- s390x/Makefile | 1 + s390x/ap.c | 309 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 3 + 3 files changed, 313 insertions(+) create mode 100644 s390x/ap.c diff --git a/s390x/Makefile b/s390x/Makefile index d9abe5c1..d75845b6 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -41,6 +41,7 @@ tests += $(TEST_DIR)/migration-sck.elf tests += $(TEST_DIR)/exittime.elf tests += $(TEST_DIR)/ex.elf tests += $(TEST_DIR)/topology.elf +tests += $(TEST_DIR)/ap.elf pv-tests += $(TEST_DIR)/pv-diags.elf pv-tests += $(TEST_DIR)/pv-icptcode.elf diff --git a/s390x/ap.c b/s390x/ap.c new file mode 100644 index 00000000..94f08783 --- /dev/null +++ b/s390x/ap.c @@ -0,0 +1,309 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * AP instruction G2 tests + * + * Copyright (c) 2023 IBM Corp + * + * Authors: + * Janosch Frank + */ + +#include +#include +#include +#include +#include +#include +#include + +/* For PQAP PGM checks where we need full control over the input */ +static void pqap(unsigned long grs[3]) +{ + asm volatile( + " lgr 0,%[r0]\n" + " lgr 1,%[r1]\n" + " lgr 2,%[r2]\n" + " .insn rre,0xb2af0000,0,0\n" /* PQAP */ + :: [r0] "d" (grs[0]), [r1] "d" (grs[1]), [r2] "d" (grs[2]) + : "cc", "memory", "0", "1", "2"); +} + +static void test_pgms_pqap(void) +{ + unsigned long grs[3] = {}; + struct pqap_r0 *r0 = (struct pqap_r0 *)grs; + uint8_t *data = alloc_page(); + uint16_t pgm; + int fails = 0; + int i; + + report_prefix_push("pqap"); + + /* Wrong FC code */ + report_prefix_push("invalid fc"); + r0->fc = 42; + expect_pgm_int(); + pqap(grs); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + memset(grs, 0, sizeof(grs)); + report_prefix_pop(); + + report_prefix_push("invalid gr0 bits"); + /* + * GR0 bits 41 - 47 are defined 0 and result in a + * specification exception if set to 1. + */ + for (i = 0; i < 48 - 41; i++) { + grs[0] = BIT(63 - 47 + i); + + expect_pgm_int(); + pqap(grs); + pgm = clear_pgm_int(); + + if (pgm != PGM_INT_CODE_SPECIFICATION) { + report_fail("fail on bit %d", 42 + i); + fails++; + } + } + report(!fails, "All bits tested"); + memset(grs, 0, sizeof(grs)); + fails = 0; + report_prefix_pop(); + + report_prefix_push("alignment"); + report_prefix_push("fc=4"); + r0->fc = PQAP_QUERY_AP_CONF_INFO; + grs[2] = (unsigned long)data; + for (i = 1; i < 8; i++) { + expect_pgm_int(); + grs[2]++; + pqap(grs); + pgm = clear_pgm_int(); + if (pgm != PGM_INT_CODE_SPECIFICATION) { + report_fail("fail on bit %d", i); + fails++; + } + } + report(!fails, "All alignments tested"); + report_prefix_pop(); + report_prefix_push("fc=6"); + r0->fc = PQAP_BEST_AP; + grs[2] = (unsigned long)data; + for (i = 1; i < 8; i++) { + expect_pgm_int(); + grs[2]++; + pqap(grs); + pgm = clear_pgm_int(); + if (pgm != PGM_INT_CODE_SPECIFICATION) { + report_fail("fail on bit %d", i); + fails++; + } + } + report(!fails, "All alignments tested"); + report_prefix_pop(); + report_prefix_pop(); + + free_page(data); + report_prefix_pop(); +} + +static void test_pgms_nqap(void) +{ + uint8_t gr0_zeroes_bits[] = { + 32, 34, 35, 40 + }; + uint64_t gr0; + bool fail; + int i; + + report_prefix_push("nqap"); + + /* Registers 0 and 1 are always used, the others are even/odd pairs */ + report_prefix_push("spec"); + report_prefix_push("r1"); + expect_pgm_int(); + asm volatile ( + ".insn rre,0xb2ad0000,3,6\n" + : : : "cc", "memory", "0", "1", "2", "3", "4", "6", "7"); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_push("r2"); + expect_pgm_int(); + asm volatile ( + ".insn rre,0xb2ad0000,2,7\n" + : : : "cc", "memory", "0", "1", "2", "3", "4", "6", "7"); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_push("both"); + expect_pgm_int(); + asm volatile ( + ".insn rre,0xb2ad0000,3,7\n" + : : : "cc", "memory", "0", "1", "2", "3", "4", "6", "7"); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_push("len==0"); + expect_pgm_int(); + asm volatile ( + "xgr 0,0\n" + "xgr 5,5\n" + ".insn rre,0xb2ad0000,2,4\n" + : : : "cc", "memory", "0", "1", "2", "3", "4", "5", "6", "7"); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_push("gr0_zero_bits"); + fail = false; + for (i = 0; i < ARRAY_SIZE(gr0_zeroes_bits); i++) { + expect_pgm_int(); + gr0 = BIT_ULL(63 - gr0_zeroes_bits[i]); + asm volatile ( + "xgr 5,5\n" + "lghi 5, 128\n" + "lg 0, 0(%[val])\n" + ".insn rre,0xb2ad0000,2,4\n" + : : [val] "a" (&gr0) + : "cc", "memory", "0", "1", "2", "3", "4", "5", "6", "7"); + if (clear_pgm_int() != PGM_INT_CODE_SPECIFICATION) { + report_fail("setting gr0 bit %d did not result in a spec exception", + gr0_zeroes_bits[i]); + fail = true; + } + } + report(!fail, "set bit gr0 pgms"); + report_prefix_pop(); + + report_prefix_pop(); + report_prefix_pop(); +} + +static void test_pgms_dqap(void) +{ + uint8_t gr0_zeroes_bits[] = { + 33, 34, 35, 40, 41 + }; + uint64_t gr0; + bool fail; + int i; + + report_prefix_push("dqap"); + + /* Registers 0 and 1 are always used, the others are even/odd pairs */ + report_prefix_push("spec"); + report_prefix_push("r1"); + expect_pgm_int(); + asm volatile ( + ".insn rre,0xb2ae0000,3,6\n" + : : : "cc", "memory", "0", "1", "2", "3", "4", "6", "7"); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_push("r2"); + expect_pgm_int(); + asm volatile ( + ".insn rre,0xb2ae0000,2,7\n" + : : : "cc", "memory", "0", "1", "2", "3", "4", "6", "7"); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_push("both"); + expect_pgm_int(); + asm volatile ( + ".insn rre,0xb2ae0000,3,7\n" + : : : "cc", "memory", "0", "1", "2", "3", "4", "6", "7"); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_push("len==0"); + expect_pgm_int(); + asm volatile ( + "xgr 0,0\n" + "xgr 5,5\n" + ".insn rre,0xb2ae0000,2,4\n" + : : : "cc", "memory", "0", "1", "2", "3", "4", "5", "6", "7"); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_push("gr0_zero_bits"); + fail = false; + for (i = 0; i < ARRAY_SIZE(gr0_zeroes_bits); i++) { + expect_pgm_int(); + gr0 = BIT_ULL(63 - gr0_zeroes_bits[i]); + asm volatile ( + "xgr 5,5\n" + "lghi 5, 128\n" + "lg 0, 0(%[val])\n" + ".insn rre,0xb2ae0000,2,4\n" + : : [val] "a" (&gr0) + : "cc", "memory", "0", "1", "2", "3", "4", "5", "6", "7"); + if (clear_pgm_int() != PGM_INT_CODE_SPECIFICATION) { + report_info("setting gr0 bit %d did not result in a spec exception", + gr0_zeroes_bits[i]); + fail = true; + } + } + report(!fail, "set bit pgms"); + report_prefix_pop(); + + report_prefix_pop(); + report_prefix_pop(); +} + +static void test_priv(void) +{ + struct ap_config_info info = {}; + + report_prefix_push("privileged"); + + report_prefix_push("pqap"); + expect_pgm_int(); + enter_pstate(); + ap_pqap_qci(&info); + check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION); + report_prefix_pop(); + + /* + * Enqueue and dequeue take too many registers so a simple + * inline assembly makes more sense than using the library + * functions. + */ + report_prefix_push("nqap"); + expect_pgm_int(); + enter_pstate(); + asm volatile ( + ".insn rre,0xb2ad0000,0,2\n" + : : : "cc", "memory", "0", "1", "2", "3"); + check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION); + report_prefix_pop(); + + report_prefix_push("dqap"); + expect_pgm_int(); + enter_pstate(); + asm volatile ( + ".insn rre,0xb2ae0000,0,2\n" + : : : "cc", "memory", "0", "1", "2", "3"); + check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION); + report_prefix_pop(); + + report_prefix_pop(); +} + +int main(void) +{ + report_prefix_push("ap"); + if (!ap_check()) { + report_skip("AP instructions not available"); + goto done; + } + + test_priv(); + test_pgms_pqap(); + test_pgms_nqap(); + test_pgms_dqap(); + +done: + report_prefix_pop(); + return report_summary(); +} diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index 68e119e4..2f190a22 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -247,3 +247,6 @@ file = topology.elf [topology-2] file = topology.elf extra_params = -cpu max,ctop=on -smp sockets=31,cores=8,maxcpus=248 -append '-sockets 31 -cores 8' + +[ap] +file = ap.elf From patchwork Tue Oct 10 08:49:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 13415037 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 60C14CD690A for ; Tue, 10 Oct 2023 08:51:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230061AbjJJIvr (ORCPT ); Tue, 10 Oct 2023 04:51:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbjJJIvg (ORCPT ); Tue, 10 Oct 2023 04:51:36 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6527A9 for ; Tue, 10 Oct 2023 01:51:34 -0700 (PDT) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39A8k03D029396 for ; Tue, 10 Oct 2023 08:51:34 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=pCXKqhroo1R74007BzXirT9D10PJ63HJpGA2GrsKIJs=; b=GLai0QSXnaKr1CBgZlMSIiuQ2g4chdfXHkLqkTCkmm5zcQGwp7SeRHk3M6vJrDc2J2kl 5N+RmJeQycbrKSQojcobHo/KRZ80ics4ySb+H2vnWY0g6bkcYXEuVGBomRnSyLxuxWEV 4IBAM2vgk0glc1ZywB4uMdaZLuxXGnG5kFdaO7YK343jV30ZjwY7bPXvmJvmRC8QV/64 28LwiovuxnagsE9seo4yjUtI0WhCBqB5utpXCKVJ4h7UgabkwE+wmSsNJoELObh7nQFe +Txj5VSphUAHbd4CaXWjHDHwVrOLGx/1vOvYZbtyWI1l5gCxulruGwAeYtWXOsC4SOMK Yg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tn3cug8t0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 10 Oct 2023 08:51:32 +0000 Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 39A8k1I6029454 for ; Tue, 10 Oct 2023 08:51:17 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tn3cug82u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 08:51:17 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 39A5xSwr000653; Tue, 10 Oct 2023 08:51:10 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3tkk5kf01m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 08:51:09 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 39A8p5xX6554118 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 08:51:06 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D95D320040; Tue, 10 Oct 2023 08:51:05 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AE3602004F; Tue, 10 Oct 2023 08:51:05 +0000 (GMT) Received: from a46lp67.. (unknown [9.152.108.100]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 10 Oct 2023 08:51:05 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: imbrenda@linux.ibm.com, thuth@redhat.com, david@redhat.com, nsg@linux.ibm.com, nrb@linux.ibm.com Subject: [kvm-unit-tests PATCH v2 3/7] lib: s390x: ap: Add ap_setup Date: Tue, 10 Oct 2023 08:49:32 +0000 Message-Id: <20231010084936.70773-4-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231010084936.70773-1-frankja@linux.ibm.com> References: <20231010084936.70773-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: NzL0QB53UTM5ANkZ2H6uQT0RaL-eVMzv X-Proofpoint-ORIG-GUID: 6YYKBBLwHVrkJmn_LZ-NRr3ZMUka5qGs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_04,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxscore=0 mlxlogscore=894 suspectscore=0 impostorscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100065 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org For the next tests we need a valid queue which means we need to grab the qci info and search the first set bit in the ap and aq masks. Let's move from the ap_check function to a proper setup function that also returns arrays for the aps and qns. Signed-off-by: Janosch Frank --- lib/s390x/ap.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++-- lib/s390x/ap.h | 17 +++++++++- s390x/ap.c | 4 ++- 3 files changed, 105 insertions(+), 5 deletions(-) diff --git a/lib/s390x/ap.c b/lib/s390x/ap.c index 4af3cdee..9ba5a037 100644 --- a/lib/s390x/ap.c +++ b/lib/s390x/ap.c @@ -13,10 +13,18 @@ #include #include +#include +#include #include #include #include +static uint8_t num_ap; +static uint8_t num_queue; +static uint8_t *array_ap; +static uint8_t *array_queue; +static struct ap_config_info qci; + int ap_pqap_tapq(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw, struct pqap_r2 *r2) { @@ -78,15 +86,90 @@ int ap_pqap_qci(struct ap_config_info *info) return cc; } -bool ap_check(void) +static int get_entry(uint8_t *ptr, int i, size_t len) { + /* Skip over the last entry */ + if (i) + i++; + + for (; i < 8 * len; i++) { + /* Do we even need to check the byte? */ + if (!ptr[i / 8]) { + i += 7; + continue; + } + + /* Check the bit in big-endian order */ + if (ptr[i / 8] & BIT(7 - (i % 8))) + return i; + } + return -1; +} + +static void setup_info(void) +{ + int i, entry = 0; + + ap_pqap_qci(&qci); + + for (i = 0; i < AP_ARRAY_MAX_NUM; i++) { + entry = get_entry((uint8_t *)qci.apm, entry, sizeof(qci.apm)); + if (entry == -1) + break; + + if (!num_ap) { + /* + * We have at least one AP, time to + * allocate the queue arrays + */ + array_ap = malloc(AP_ARRAY_MAX_NUM); + array_queue = malloc(AP_ARRAY_MAX_NUM); + } + array_ap[num_ap] = entry; + num_ap += 1; + } + + /* Without an AP we don't even need to look at the queues */ + if (!num_ap) + return; + + entry = 0; + for (i = 0; i < AP_ARRAY_MAX_NUM; i++) { + entry = get_entry((uint8_t *)qci.aqm, entry, sizeof(qci.aqm)); + if (entry == -1) + return; + + array_queue[num_queue] = entry; + num_queue += 1; + } + +} + +int ap_setup(uint8_t **ap_array, uint8_t **qn_array, uint8_t *naps, uint8_t *nqns) +{ + assert(!num_ap); + /* * Base AP support has no STFLE or SCLP feature bit but the * PQAP QCI support is indicated via stfle bit 12. As this * library relies on QCI we bail out if it's not available. */ if (!test_facility(12)) - return false; + return AP_SETUP_NOINSTR; - return true; + /* Setup ap and queue arrays */ + setup_info(); + + if (!num_ap) + return AP_SETUP_NOAPQN; + + /* Only provide the data if the caller actually needs it. */ + if (ap_array && qn_array && naps && nqns) { + *ap_array = array_ap; + *qn_array = array_queue; + *naps = num_ap; + *nqns = num_queue; + } + + return AP_SETUP_READY; } diff --git a/lib/s390x/ap.h b/lib/s390x/ap.h index 411591f2..ac9e59d1 100644 --- a/lib/s390x/ap.h +++ b/lib/s390x/ap.h @@ -81,7 +81,22 @@ struct pqap_r2 { } __attribute__((packed)) __attribute__((aligned(8))); _Static_assert(sizeof(struct pqap_r2) == sizeof(uint64_t), "pqap_r2 size"); -bool ap_check(void); +/* + * Maximum number of APQNs that we keep track of. + * + * This value is already way larger than the number of APQNs a AP test + * is probably going to use. + */ +#define AP_ARRAY_MAX_NUM 16 + +/* Return values of ap_setup() */ +enum { + AP_SETUP_NOINSTR, /* AP instructions not available */ + AP_SETUP_NOAPQN, /* Instructions available but no APQNs */ + AP_SETUP_READY /* Full setup complete, at least one APQN */ +}; + +int ap_setup(uint8_t **ap_array, uint8_t **qn_array, uint8_t *naps, uint8_t *nqns); int ap_pqap_tapq(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw, struct pqap_r2 *r2); int ap_pqap_qci(struct ap_config_info *info); diff --git a/s390x/ap.c b/s390x/ap.c index 94f08783..32feb8db 100644 --- a/s390x/ap.c +++ b/s390x/ap.c @@ -292,8 +292,10 @@ static void test_priv(void) int main(void) { + int setup_rc = ap_setup(NULL, NULL, NULL, NULL); + report_prefix_push("ap"); - if (!ap_check()) { + if (setup_rc == AP_SETUP_NOINSTR) { report_skip("AP instructions not available"); goto done; } From patchwork Tue Oct 10 08:49:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 13415033 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 016E7CD690A for ; Tue, 10 Oct 2023 08:51:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229928AbjJJIvj (ORCPT ); Tue, 10 Oct 2023 04:51:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229755AbjJJIvW (ORCPT ); Tue, 10 Oct 2023 04:51:22 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08929C6 for ; Tue, 10 Oct 2023 01:51:20 -0700 (PDT) Received: from pps.filterd (m0353722.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39A8j2ZN011006 for ; Tue, 10 Oct 2023 08:51:20 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=qBF6zsmyaj5I0L80762pP709SBEX0yQJZrP31rNAlso=; b=oFNJ/ysS+9T+i5t5rmdXOeO5f9kEKmXWdQhWVw+hlZSY24sWqNyY44JLBhmt5Mv3wW9F T4aqAPFUyNINYCJzunC0HgGLN95Q2sBSDPN6dS8Ha5fsoZMzvZ7gb8Btyk8r5i/dDfDy q93wXptub33FU6ezMqRqFKr9Yk6p8616VWGXSsK0uO6ZJ4J6nZqWP63R4qMP6zzeOZoj EwPR+ON2xU30DK/ArvsRVm73dt1Du4XzJkKCMJHBiyd1Zviw3bhQJrzgbmOnGx0WQx0w QIFWwjTR4AXlbUDN0eWPTtSHw1gYz0qc2CHbL0RHo7rJfc4CiZJjr3Kq9Y3H5Uexq+4J 6Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tn3cf0bg9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 10 Oct 2023 08:51:19 +0000 Received: from m0353722.ppops.net (m0353722.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 39A8j75s011824 for ; Tue, 10 Oct 2023 08:51:12 GMT Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tn3cf0b8v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 08:51:12 +0000 Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 39A8LJsW000693; Tue, 10 Oct 2023 08:51:09 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 3tkk5kf01p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 08:51:09 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 39A8p67Z14418580 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 08:51:06 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 18FA220040; Tue, 10 Oct 2023 08:51:06 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E1B6420043; Tue, 10 Oct 2023 08:51:05 +0000 (GMT) Received: from a46lp67.. (unknown [9.152.108.100]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 10 Oct 2023 08:51:05 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: imbrenda@linux.ibm.com, thuth@redhat.com, david@redhat.com, nsg@linux.ibm.com, nrb@linux.ibm.com Subject: [kvm-unit-tests PATCH v2 4/7] s390x: ap: Add pqap aqic tests Date: Tue, 10 Oct 2023 08:49:33 +0000 Message-Id: <20231010084936.70773-5-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231010084936.70773-1-frankja@linux.ibm.com> References: <20231010084936.70773-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: ivvEro_IlXkin99p5NmpVQ9nNjspBrbU X-Proofpoint-GUID: GmrePOVUxhj45ziyklmRkUutRwhQXrme X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_04,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 spamscore=0 adultscore=0 priorityscore=1501 bulkscore=0 mlxlogscore=932 malwarescore=0 lowpriorityscore=0 suspectscore=0 impostorscore=0 phishscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100065 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Let's check if we can enable/disable interrupts and if all errors are reported if we specify bad addresses for the notification indication byte. Signed-off-by: Janosch Frank --- lib/s390x/ap.c | 33 ++++++++++++++++++++++ lib/s390x/ap.h | 11 ++++++++ s390x/ap.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 118 insertions(+), 1 deletion(-) diff --git a/lib/s390x/ap.c b/lib/s390x/ap.c index 9ba5a037..23338c2d 100644 --- a/lib/s390x/ap.c +++ b/lib/s390x/ap.c @@ -58,6 +58,39 @@ int ap_pqap_tapq(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw, return cc; } +int ap_pqap_aqic(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw, + struct ap_qirq_ctrl aqic, unsigned long addr) +{ + struct pqap_r0 r0 = {}; + int cc; + + /* + * AP-Queue Interruption Control + * + * Enables/disables interrupts for a APQN + * + * Inputs: 0,1,2 + * Outputs: 1 (APQSW) + * Synchronous + */ + r0.ap = ap; + r0.qn = qn; + r0.fc = PQAP_QUEUE_INT_CONTRL; + asm volatile( + " lgr 0,%[r0]\n" + " lgr 1,%[aqic]\n" + " lgr 2,%[addr]\n" + " .insn rre,0xb2af0000,0,0\n" /* PQAP */ + " stg 1, %[apqsw]\n" + " ipm %[cc]\n" + " srl %[cc],28\n" + : [apqsw] "=&T" (*apqsw), [cc] "=&d" (cc) + : [r0] "d" (r0), [aqic] "d" (aqic), [addr] "d" (addr) + : "cc", "memory", "0", "2"); + + return cc; +} + int ap_pqap_qci(struct ap_config_info *info) { struct pqap_r0 r0 = { .fc = PQAP_QUERY_AP_CONF_INFO }; diff --git a/lib/s390x/ap.h b/lib/s390x/ap.h index ac9e59d1..7a91881d 100644 --- a/lib/s390x/ap.h +++ b/lib/s390x/ap.h @@ -81,6 +81,15 @@ struct pqap_r2 { } __attribute__((packed)) __attribute__((aligned(8))); _Static_assert(sizeof(struct pqap_r2) == sizeof(uint64_t), "pqap_r2 size"); +struct ap_qirq_ctrl { + uint64_t res0 : 16; + uint64_t ir : 1; /* ir flag: enable (1) or disable (0) irq */ + uint64_t res1 : 44; + uint64_t isc : 3; /* irq sub class */ +} __attribute__((packed)) __attribute__((aligned(8))); +_Static_assert(sizeof(struct ap_qirq_ctrl) == sizeof(uint64_t), + "struct ap_qirq_ctrl size"); + /* * Maximum number of APQNs that we keep track of. * @@ -100,4 +109,6 @@ int ap_setup(uint8_t **ap_array, uint8_t **qn_array, uint8_t *naps, uint8_t *nqn int ap_pqap_tapq(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw, struct pqap_r2 *r2); int ap_pqap_qci(struct ap_config_info *info); +int ap_pqap_aqic(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw, + struct ap_qirq_ctrl aqic, unsigned long addr); #endif diff --git a/s390x/ap.c b/s390x/ap.c index 32feb8db..8ea2b52e 100644 --- a/s390x/ap.c +++ b/s390x/ap.c @@ -12,10 +12,15 @@ #include #include #include +#include +#include #include #include #include +static uint8_t apn; +static uint8_t qn; + /* For PQAP PGM checks where we need full control over the input */ static void pqap(unsigned long grs[3]) { @@ -290,9 +295,63 @@ static void test_priv(void) report_prefix_pop(); } +static void test_pqap_aqic(void) +{ + uint8_t *not_ind_byte = alloc_io_mem(PAGE_SIZE, 0); + struct ap_queue_status apqsw = {}; + struct ap_qirq_ctrl aqic = {}; + struct pqap_r2 r2 = {}; + int cc; + + report_prefix_push("aqic"); + *not_ind_byte = 0; + + aqic.ir = 1; + cc = ap_pqap_aqic(apn, qn, &apqsw, aqic, 0); + report(cc == 3 && apqsw.rc == 6, "invalid addr 0"); + + aqic.ir = 1; + cc = ap_pqap_aqic(apn, qn, &apqsw, aqic, -1); + report(cc == 3 && apqsw.rc == 6, "invalid addr -1"); + + aqic.ir = 0; + cc = ap_pqap_aqic(apn, qn, &apqsw, aqic, (uintptr_t)not_ind_byte); + report(cc == 3 && apqsw.rc == 7, "disable IRQs while already disabled"); + + aqic.ir = 1; + cc = ap_pqap_aqic(apn, qn, &apqsw, aqic, (uintptr_t)not_ind_byte); + report(cc == 0 && apqsw.rc == 0, "enable IRQs"); + + do { + mdelay(20); + cc = ap_pqap_tapq(apn, qn, &apqsw, &r2); + } while (cc == 0 && apqsw.irq_enabled == 0); + report(cc == 0 && apqsw.irq_enabled == 1, "enable IRQs tapq data"); + + cc = ap_pqap_aqic(apn, qn, &apqsw, aqic, (uintptr_t)not_ind_byte); + report(cc == 3 && apqsw.rc == 7, "enable IRQs while already enabled"); + + aqic.ir = 0; + cc = ap_pqap_aqic(apn, qn, &apqsw, aqic, (uintptr_t)not_ind_byte); + report(cc == 0 && apqsw.rc == 0, "disable IRQs"); + + do { + mdelay(20); + cc = ap_pqap_tapq(apn, qn, &apqsw, &r2); + } while (cc == 0 && apqsw.irq_enabled == 1); + report(cc == 0 && apqsw.irq_enabled == 0, "disable IRQs tapq data"); + + report_prefix_pop(); + + free_io_mem(not_ind_byte, PAGE_SIZE); +} + int main(void) { - int setup_rc = ap_setup(NULL, NULL, NULL, NULL); + uint8_t num_ap, num_qn; + uint8_t *apns; + uint8_t *qns; + int setup_rc = ap_setup(&apns, &qns, &num_ap, &num_qn); report_prefix_push("ap"); if (setup_rc == AP_SETUP_NOINSTR) { @@ -305,6 +364,20 @@ int main(void) test_pgms_nqap(); test_pgms_dqap(); + /* The next tests need queues */ + if (setup_rc == AP_SETUP_NOAPQN) { + report_skip("No APQN available"); + goto done; + } + apn = apns[0]; + qn = qns[0]; + report_prefix_push("pqap"); + if (test_facility(65)) + test_pqap_aqic(); + else + report_skip("no AQIC and reset tests without IRQ support"); + report_prefix_pop(); + done: report_prefix_pop(); return report_summary(); From patchwork Tue Oct 10 08:49:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 13415035 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 3FC10CD690A for ; Tue, 10 Oct 2023 08:51:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230014AbjJJIvn (ORCPT ); Tue, 10 Oct 2023 04:51:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229709AbjJJIvd (ORCPT ); Tue, 10 Oct 2023 04:51:33 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4DB67A9 for ; Tue, 10 Oct 2023 01:51:32 -0700 (PDT) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39A8k2t6029578 for ; Tue, 10 Oct 2023 08:51:31 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=CTl8DNNTGZiI+7wsYVwnp0pnAMahQ58kmrxPgViAuoc=; b=i1U6nKIBwwNnh4UD/M/vkhuybRO8o4w1AfJpxKnYvm0ENBRBcACLyi6s+K4IRJzJwWEK qqEjJxSTO4CiM1zA1FedVSSEvcX3a5QQg+eOKjJPSByOhwJ9E3vQgwPgudr8OgiJf6uA UtawZqXZo5b+jDAWiDzd1UTdEzbOxELpHvOqkrFTaePzPzPSsbIXsT6YrxmAN5LP+e+F 8DmxXPdn91uhn35CxCRnYfK6Hg4Psw7f4swAwnwr5Si4SSCTpHlC+Wxyt5UK1fIGS4Sk 7FYc5Dii5laDQFJXCPPfEm+sg7pONY+Jp3rpSZVU0cpupDY7Bopi2GsNhMQGwF2jgQIT Cw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tn3cug91s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 10 Oct 2023 08:51:30 +0000 Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 39A8lU0n003314 for ; Tue, 10 Oct 2023 08:51:23 GMT Received: from ppma13.dal12v.mail.ibm.com (dd.9e.1632.ip4.static.sl-reverse.com [50.22.158.221]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tn3cug876-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 08:51:22 +0000 Received: from pps.filterd (ppma13.dal12v.mail.ibm.com [127.0.0.1]) by ppma13.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 39A6D39x001150; Tue, 10 Oct 2023 08:51:10 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma13.dal12v.mail.ibm.com (PPS) with ESMTPS id 3tkkvjpru2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 08:51:10 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 39A8p6rh14418582 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 08:51:06 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4B85120040; Tue, 10 Oct 2023 08:51:06 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 20DE62004F; Tue, 10 Oct 2023 08:51:06 +0000 (GMT) Received: from a46lp67.. (unknown [9.152.108.100]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 10 Oct 2023 08:51:06 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: imbrenda@linux.ibm.com, thuth@redhat.com, david@redhat.com, nsg@linux.ibm.com, nrb@linux.ibm.com Subject: [kvm-unit-tests PATCH v2 5/7] s390x: ap: Add reset tests Date: Tue, 10 Oct 2023 08:49:34 +0000 Message-Id: <20231010084936.70773-6-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231010084936.70773-1-frankja@linux.ibm.com> References: <20231010084936.70773-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: hXHEeRSjTXux-mH8ZODMD1-kljxN762H X-Proofpoint-ORIG-GUID: TLVsPUcLbRUj7sBSHZiDby_MsoRQOKdy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_04,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 impostorscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100065 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Test if the IRQ enablement is turned off on a reset or zeroize PQAP. Signed-off-by: Janosch Frank --- lib/s390x/ap.c | 69 ++++++++++++++++++++++++++++++++++++++++++ lib/s390x/ap.h | 4 +++ s390x/ap.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 152 insertions(+), 2 deletions(-) diff --git a/lib/s390x/ap.c b/lib/s390x/ap.c index 23338c2d..c1acfda8 100644 --- a/lib/s390x/ap.c +++ b/lib/s390x/ap.c @@ -119,6 +119,75 @@ int ap_pqap_qci(struct ap_config_info *info) return cc; } +static int pqap_reset(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw, + bool zeroize) +{ + struct pqap_r0 r0 = {}; + int cc; + + /* + * Reset/zeroize AP Queue + * + * Resets/zeroizes a queue and disables IRQs + * + * Inputs: GR0 + * Outputs: GR1 (APQSW) + * Asynchronous + */ + r0.ap = ap; + r0.qn = qn; + r0.fc = zeroize ? PQAP_ZEROIZE_APQ : PQAP_RESET_APQ; + asm volatile( + " lgr 0,%[r0]\n" + " .insn rre,0xb2af0000,0,0\n" /* PQAP */ + " stg 1, %[apqsw]\n" + " ipm %[cc]\n" + " srl %[cc],28\n" + : [apqsw] "=&T" (*apqsw), [cc] "=&d" (cc) + : [r0] "d" (r0) + : "memory"); + + return cc; +} + +static int pqap_reset_wait(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw, + bool zeroize) +{ + struct pqap_r2 r2 = {}; + int cc; + + cc = pqap_reset(ap, qn, apqsw, zeroize); + + /* On a cc == 3 / error we don't need to wait */ + if (cc) + return cc; + + /* + * TAPQ returns AP_RC_RESET_IN_PROGRESS if a reset is being + * processed + */ + do { + /* Give it some time to process before the retry */ + mdelay(20); + cc = ap_pqap_tapq(ap, qn, apqsw, &r2); + } while (apqsw->rc == AP_RC_RESET_IN_PROGRESS); + + if (apqsw->rc) + printf("Wait for reset failed on ap %d queue %d with tapq rc %d.", + ap, qn, apqsw->rc); + return cc; +} + +int ap_pqap_reset(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw) +{ + return pqap_reset_wait(ap, qn, apqsw, false); +} + +int ap_pqap_reset_zeroize(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw) +{ + return pqap_reset_wait(ap, qn, apqsw, true); +} + static int get_entry(uint8_t *ptr, int i, size_t len) { /* Skip over the last entry */ diff --git a/lib/s390x/ap.h b/lib/s390x/ap.h index 7a91881d..e037a974 100644 --- a/lib/s390x/ap.h +++ b/lib/s390x/ap.h @@ -14,6 +14,8 @@ #ifndef _S390X_AP_H_ #define _S390X_AP_H_ +#define AP_RC_RESET_IN_PROGRESS 0x02 + enum PQAP_FC { PQAP_TEST_APQ, PQAP_RESET_APQ, @@ -108,6 +110,8 @@ enum { int ap_setup(uint8_t **ap_array, uint8_t **qn_array, uint8_t *naps, uint8_t *nqns); int ap_pqap_tapq(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw, struct pqap_r2 *r2); +int ap_pqap_reset(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw); +int ap_pqap_reset_zeroize(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw); int ap_pqap_qci(struct ap_config_info *info); int ap_pqap_aqic(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw, struct ap_qirq_ctrl aqic, unsigned long addr); diff --git a/s390x/ap.c b/s390x/ap.c index 8ea2b52e..0ae2809e 100644 --- a/s390x/ap.c +++ b/s390x/ap.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -346,6 +347,80 @@ static void test_pqap_aqic(void) free_io_mem(not_ind_byte, PAGE_SIZE); } +static void test_pqap_resets(void) +{ + uint8_t *not_ind_byte = alloc_io_mem(sizeof(*not_ind_byte), 0); + struct ap_queue_status apqsw = {}; + struct ap_qirq_ctrl aqic = {}; + struct pqap_r2 r2 = {}; + + int cc; + + report_prefix_push("rapq"); + + /* Enable IRQs which the resets will disable */ + aqic.ir = 1; + cc = ap_pqap_aqic(apn, qn, &apqsw, aqic, (uintptr_t)not_ind_byte); + report(cc == 0 && apqsw.rc == 0, "enable IRQs for reset tests"); + + do { + mdelay(20); + cc = ap_pqap_tapq(apn, qn, &apqsw, &r2); + } while (cc == 0 && apqsw.irq_enabled == 0); + report(apqsw.irq_enabled == 1, "IRQs enabled tapq data"); + + ap_pqap_reset(apn, qn, &apqsw); + cc = ap_pqap_tapq(apn, qn, &apqsw, &r2); + assert(!cc); + report(apqsw.irq_enabled == 0, "IRQs have been disabled via reset"); + + report_prefix_pop(); + + report_prefix_push("zapq"); + + /* Enable IRQs which the resets will disable */ + aqic.ir = 1; + cc = ap_pqap_aqic(apn, qn, &apqsw, aqic, (uintptr_t)not_ind_byte); + report(cc == 0 && apqsw.rc == 0, "enable IRQs for reset tests"); + + do { + mdelay(20); + cc = ap_pqap_tapq(apn, qn, &apqsw, &r2); + } while (cc == 0 && apqsw.irq_enabled == 0); + report(apqsw.irq_enabled == 1, "IRQs enabled tapq data"); + + ap_pqap_reset_zeroize(apn, qn, &apqsw); + cc = ap_pqap_tapq(apn, qn, &apqsw, &r2); + assert(!cc); + report(apqsw.irq_enabled == 0, "IRQs have been disabled via reset"); + + report_prefix_pop(); + /* + * This is a wrinkle in the architecture for PV guests. + * + * The notification byte is pinned shared for PV guests. + * RAPQ, ZAPQ and AQIC can all disable IRQs but there's no + * intercept for resets triggered by a PV guests. Hence the + * host keeps the notification byte page pinned UNTIL IRQs are + * disabled via AQIC. + * + * Firmware will not generate an intercept if the IRQs have + * already been disabled via a reset. Therefore we need to + * enable AND disable to achieve a disable. + */ + if (uv_os_is_guest()) { + aqic.ir = 1; + cc = ap_pqap_aqic(apn, qn, &apqsw, aqic, + (uintptr_t)not_ind_byte); + assert(cc == 0 && apqsw.rc == 0); + aqic.ir = 0; + cc = ap_pqap_aqic(apn, qn, &apqsw, aqic, + (uintptr_t)not_ind_byte); + assert(cc == 0 && apqsw.rc == 0); + } + free_io_mem(not_ind_byte, sizeof(*not_ind_byte)); +} + int main(void) { uint8_t num_ap, num_qn; @@ -372,10 +447,12 @@ int main(void) apn = apns[0]; qn = qns[0]; report_prefix_push("pqap"); - if (test_facility(65)) + if (test_facility(65)) { test_pqap_aqic(); - else + test_pqap_resets(); + } else { report_skip("no AQIC and reset tests without IRQ support"); + } report_prefix_pop(); done: From patchwork Tue Oct 10 08:49:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 13415032 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 D3925CD690B for ; Tue, 10 Oct 2023 08:51:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229925AbjJJIvh (ORCPT ); Tue, 10 Oct 2023 04:51:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230248AbjJJIvX (ORCPT ); Tue, 10 Oct 2023 04:51:23 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F34BFCA for ; Tue, 10 Oct 2023 01:51:21 -0700 (PDT) Received: from pps.filterd (m0356516.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39A8k177020233 for ; Tue, 10 Oct 2023 08:51:21 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=LdSTOCRF/Y2mm7f4UJzdgFcO5CKZJDr3FoCQzhucFNA=; b=fTsEYFwIfUvvAmfimWjj9k32CxiLboTlr6yI/wZNHLwas6qJnRMGUZ1B2wNm61DU+ISr C4Ti8jYyysrXqcBRJ4FyK5vm+e2s1ei/U6Lfi/xZbZrrgHz8N0vVXAkEOjHxGkCuX1uk ayrAEA09ZCyysMsbHoh5AmWsZv5nkF/TZcHLrOPCGpnosUZErua1dY3fEW9hkdviam1p DAlB2oTux1fxNS+1/sgGLs9XEmWstlstIEPBYAiQscBlA73Rn6UpRjkYlwRH8KSRy3dj l0GR6Pb53bcUOI4X0zTP2kTOpgyX5K4SNITyLSCclirwVcUeqX61ZK2lDUQ3WNOnGKq4 sQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tn3ct08b2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 10 Oct 2023 08:51:19 +0000 Received: from m0356516.ppops.net (m0356516.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 39A8lKho024659 for ; Tue, 10 Oct 2023 08:51:14 GMT Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tn3ct080f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 08:51:14 +0000 Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 39A6i0PK023094; Tue, 10 Oct 2023 08:51:09 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 3tkmc1enkd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 08:51:09 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 39A8p6mo17105600 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 08:51:06 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7F85A2004D; Tue, 10 Oct 2023 08:51:06 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5419320043; Tue, 10 Oct 2023 08:51:06 +0000 (GMT) Received: from a46lp67.. (unknown [9.152.108.100]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 10 Oct 2023 08:51:06 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: imbrenda@linux.ibm.com, thuth@redhat.com, david@redhat.com, nsg@linux.ibm.com, nrb@linux.ibm.com Subject: [kvm-unit-tests PATCH v2 6/7] lib: s390x: ap: Add tapq test facility bit Date: Tue, 10 Oct 2023 08:49:35 +0000 Message-Id: <20231010084936.70773-7-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231010084936.70773-1-frankja@linux.ibm.com> References: <20231010084936.70773-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Y4RUb4D08YK1PDWpNQcuPtbK6rJRH3du X-Proofpoint-GUID: raqMieL2CL6EHOrXkhIdA2Ssml6_zKO8 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_04,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 mlxscore=0 spamscore=0 malwarescore=0 priorityscore=1501 suspectscore=0 phishscore=0 impostorscore=0 adultscore=0 bulkscore=0 clxscore=1015 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100065 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When the t bit is one the first 32 bits of register 2 are populated on a tapq. Those bits tell us in which mode the queu is and which facilities it supports. Signed-off-by: Janosch Frank --- lib/s390x/ap.c | 5 +++-- lib/s390x/ap.h | 2 +- s390x/ap.c | 12 ++++++------ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/s390x/ap.c b/lib/s390x/ap.c index c1acfda8..fbc33227 100644 --- a/lib/s390x/ap.c +++ b/lib/s390x/ap.c @@ -26,11 +26,12 @@ static uint8_t *array_queue; static struct ap_config_info qci; int ap_pqap_tapq(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw, - struct pqap_r2 *r2) + struct pqap_r2 *r2, bool t) { struct pqap_r0 r0 = { .ap = ap, .qn = qn, + .t = t, .fc = PQAP_TEST_APQ }; int cc; @@ -169,7 +170,7 @@ static int pqap_reset_wait(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw do { /* Give it some time to process before the retry */ mdelay(20); - cc = ap_pqap_tapq(ap, qn, apqsw, &r2); + cc = ap_pqap_tapq(ap, qn, apqsw, &r2, false); } while (apqsw->rc == AP_RC_RESET_IN_PROGRESS); if (apqsw->rc) diff --git a/lib/s390x/ap.h b/lib/s390x/ap.h index e037a974..17f8016d 100644 --- a/lib/s390x/ap.h +++ b/lib/s390x/ap.h @@ -109,7 +109,7 @@ enum { int ap_setup(uint8_t **ap_array, uint8_t **qn_array, uint8_t *naps, uint8_t *nqns); int ap_pqap_tapq(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw, - struct pqap_r2 *r2); + struct pqap_r2 *r2, bool t); int ap_pqap_reset(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw); int ap_pqap_reset_zeroize(uint8_t ap, uint8_t qn, struct ap_queue_status *apqsw); int ap_pqap_qci(struct ap_config_info *info); diff --git a/s390x/ap.c b/s390x/ap.c index 0ae2809e..05664df8 100644 --- a/s390x/ap.c +++ b/s390x/ap.c @@ -325,7 +325,7 @@ static void test_pqap_aqic(void) do { mdelay(20); - cc = ap_pqap_tapq(apn, qn, &apqsw, &r2); + cc = ap_pqap_tapq(apn, qn, &apqsw, &r2, false); } while (cc == 0 && apqsw.irq_enabled == 0); report(cc == 0 && apqsw.irq_enabled == 1, "enable IRQs tapq data"); @@ -338,7 +338,7 @@ static void test_pqap_aqic(void) do { mdelay(20); - cc = ap_pqap_tapq(apn, qn, &apqsw, &r2); + cc = ap_pqap_tapq(apn, qn, &apqsw, &r2, false); } while (cc == 0 && apqsw.irq_enabled == 1); report(cc == 0 && apqsw.irq_enabled == 0, "disable IRQs tapq data"); @@ -365,12 +365,12 @@ static void test_pqap_resets(void) do { mdelay(20); - cc = ap_pqap_tapq(apn, qn, &apqsw, &r2); + cc = ap_pqap_tapq(apn, qn, &apqsw, &r2, false); } while (cc == 0 && apqsw.irq_enabled == 0); report(apqsw.irq_enabled == 1, "IRQs enabled tapq data"); ap_pqap_reset(apn, qn, &apqsw); - cc = ap_pqap_tapq(apn, qn, &apqsw, &r2); + cc = ap_pqap_tapq(apn, qn, &apqsw, &r2, false); assert(!cc); report(apqsw.irq_enabled == 0, "IRQs have been disabled via reset"); @@ -385,12 +385,12 @@ static void test_pqap_resets(void) do { mdelay(20); - cc = ap_pqap_tapq(apn, qn, &apqsw, &r2); + cc = ap_pqap_tapq(apn, qn, &apqsw, &r2, false); } while (cc == 0 && apqsw.irq_enabled == 0); report(apqsw.irq_enabled == 1, "IRQs enabled tapq data"); ap_pqap_reset_zeroize(apn, qn, &apqsw); - cc = ap_pqap_tapq(apn, qn, &apqsw, &r2); + cc = ap_pqap_tapq(apn, qn, &apqsw, &r2, false); assert(!cc); report(apqsw.irq_enabled == 0, "IRQs have been disabled via reset"); From patchwork Tue Oct 10 08:49:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 13415031 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 0C7E1CD690D for ; Tue, 10 Oct 2023 08:51:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229918AbjJJIvf (ORCPT ); Tue, 10 Oct 2023 04:51:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbjJJIv1 (ORCPT ); Tue, 10 Oct 2023 04:51:27 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F381FDB for ; Tue, 10 Oct 2023 01:51:24 -0700 (PDT) Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39A8k0pZ029383 for ; Tue, 10 Oct 2023 08:51:24 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=G0XnmZfu2SkHR+t0qTf9/eCWhw8RbAwq5JQajxUkXjo=; b=iVruL+olqpvT2UGkmAj3RbDbtS2qA9CVagScYHCyUE0G5Izy6ryg9zTTO4Q6lz+UI2LW 4zeqjwqcNl8KsTvx9gSZqrvleblykxu6C/GO27cJiXGhWG6dOTHar3zjZYvXw+lH8SUw q5MUhVXyJRx9sxQJBp9CB3g3Ds2b8Zb8KbG3lkPugDGKs+sEs3x2Dkz8TD2Ep3DWXNV0 eb8R9OTfHCkiBzYZVYiaIcP8nyJ9F3W92pUz1IaIkcre2NRDpz+PGJ8V+mmYjDL3syN9 hRPp0oommanNDahAyzGybbnXu+CPa/juvRiATg3yM3maZSPIMdhdaMY5SATNBGcqUk6N vw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tn3cug8ac-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 10 Oct 2023 08:51:23 +0000 Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 39A8k1U7029460 for ; Tue, 10 Oct 2023 08:51:12 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3tn3cug81s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 08:51:12 +0000 Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 39A6uAl1024445; Tue, 10 Oct 2023 08:51:09 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 3tkhnsffpd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 10 Oct 2023 08:51:09 +0000 Received: from smtpav04.fra02v.mail.ibm.com (smtpav04.fra02v.mail.ibm.com [10.20.54.103]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 39A8p6iQ17105602 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 Oct 2023 08:51:06 GMT Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B2C5320043; Tue, 10 Oct 2023 08:51:06 +0000 (GMT) Received: from smtpav04.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 87F342005A; Tue, 10 Oct 2023 08:51:06 +0000 (GMT) Received: from a46lp67.. (unknown [9.152.108.100]) by smtpav04.fra02v.mail.ibm.com (Postfix) with ESMTP; Tue, 10 Oct 2023 08:51:06 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: imbrenda@linux.ibm.com, thuth@redhat.com, david@redhat.com, nsg@linux.ibm.com, nrb@linux.ibm.com Subject: [kvm-unit-tests PATCH v2 7/7] s390x: ap: Add nq/dq len test Date: Tue, 10 Oct 2023 08:49:36 +0000 Message-Id: <20231010084936.70773-8-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231010084936.70773-1-frankja@linux.ibm.com> References: <20231010084936.70773-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: A3aLEmFTzJCqZeYFjU-HWID7Q55kBXhk X-Proofpoint-ORIG-GUID: LCqsg8Nj_H4fpcw0uXq0Zeq3sFUZEBtj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-10_04,2023-10-09_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 adultscore=0 phishscore=0 malwarescore=0 mlxscore=0 mlxlogscore=999 suspectscore=0 impostorscore=0 clxscore=1015 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310100065 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org For years the nqap/dqap max length was 12KB but with a recent machine extended message length support was introduced. The support is AP type and generation specific, so it can vary from card to card which complicates testing by a lot. This test will use the APQN that all other tests use no matter if there's extended length support or not. But if longer messages are supported by the APQN we need to adapt our tests. Signed-off-by: Janosch Frank --- lib/s390x/ap.h | 3 +- s390x/ap.c | 103 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/lib/s390x/ap.h b/lib/s390x/ap.h index 17f8016d..2511074d 100644 --- a/lib/s390x/ap.h +++ b/lib/s390x/ap.h @@ -77,7 +77,8 @@ struct pqap_r2 { uint8_t pad_1[3]; uint8_t at; uint8_t nd; - uint8_t pad_6; + uint8_t pad_6 : 4; + uint8_t ml : 4; uint8_t pad_7 : 4; uint8_t qd : 4; } __attribute__((packed)) __attribute__((aligned(8))); diff --git a/s390x/ap.c b/s390x/ap.c index 05664df8..89c22b81 100644 --- a/s390x/ap.c +++ b/s390x/ap.c @@ -257,6 +257,106 @@ static void test_pgms_dqap(void) report_prefix_pop(); } +/* + * For years the nqap/dqap max length was 12KB but with a recent + * machine extended message length support was introduced. The support + * is AP type and generation specific, so it can vary from card to + * card. + * + * This test will use the APQN that all other tests use no matter if + * there's extended length support or not. But if longer messages are + * supported by the APQN we need to adapt our tests. + */ +static void test_pgms_nqdq_len(void) +{ + struct ap_queue_status apqsw = {}; + struct pqap_r2 r2 = {}; + uint64_t len, mlen; + bool fail; + int i; + + /* Extended message support is reported via tapq with T=1 */ + ap_pqap_tapq(apn, qn, &apqsw, &r2, true); + /* < 3 means 3 because of backwards compatibility */ + mlen = r2.ml ? r2.ml : 3; + /* Len is reported in pages */ + mlen *= PAGE_SIZE; + + report_prefix_push("nqap"); + report_prefix_push("spec"); + + report_prefix_push("len + 1"); + expect_pgm_int(); + len = mlen + 1; + asm volatile ( + "lg 5, 0(%[len])\n" + ".insn rre,0xb2ae0000,2,4\n" + : : [len] "a" (&len) + : "cc", "memory", "0", "1", "2", "3", "4", "5", "6", "7"); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_push("len bits"); + fail = false; + for (i = 12; i < 63; i++) { + len = BIT(i); + if (len < mlen) + continue; + expect_pgm_int(); + asm volatile ( + "lg 5, 0(%[len])\n" + ".insn rre,0xb2ae0000,2,4\n" + : : [len] "a" (&len) + : "cc", "memory", "0", "1", "2", "3", "4", "5", "6", "7"); + if (clear_pgm_int() != PGM_INT_CODE_SPECIFICATION) { + report_fail("setting len to %lx did not result in a spec exception", + len); + fail = true; + } + } + report(!fail, "length pgms"); + report_prefix_pop(); + report_prefix_pop(); + report_prefix_pop(); + + report_prefix_push("dqap"); + report_prefix_push("spec"); + + report_prefix_push("len + 1"); + expect_pgm_int(); + len = mlen + 1; + asm volatile ( + "lg 5, 0(%[len])\n" + ".insn rre,0xb2ae0000,2,4\n" + : : [len] "a" (&len) + : "cc", "memory", "0", "1", "2", "3", "4", "5", "6", "7"); + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + report_prefix_pop(); + + report_prefix_push("len bits"); + fail = false; + for (i = 12; i < 63; i++) { + len = BIT(i); + if (len < mlen) + continue; + expect_pgm_int(); + asm volatile ( + "lg 5, 0(%[len])\n" + ".insn rre,0xb2ae0000,2,4\n" + : : [len] "a" (&len) + : "cc", "memory", "0", "1", "2", "3", "4", "5", "6", "7"); + if (clear_pgm_int() != PGM_INT_CODE_SPECIFICATION) { + report_fail("setting len to %lx did not result in a spec exception", + len); + fail = true; + } + } + report(!fail, "length pgms"); + report_prefix_pop(); + report_prefix_pop(); + report_prefix_pop(); +} + static void test_priv(void) { struct ap_config_info info = {}; @@ -446,6 +546,9 @@ int main(void) } apn = apns[0]; qn = qns[0]; + + test_pgms_nqdq_len(); + report_prefix_push("pqap"); if (test_facility(65)) { test_pqap_aqic();