From patchwork Fri Apr 21 11:36:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 13219858 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 7CDDDC7618E for ; Fri, 21 Apr 2023 11:39:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231837AbjDULjV (ORCPT ); Fri, 21 Apr 2023 07:39:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231799AbjDULjS (ORCPT ); Fri, 21 Apr 2023 07:39:18 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84753C141; Fri, 21 Apr 2023 04:38:35 -0700 (PDT) Received: from pps.filterd (m0353727.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33LBZJ0o013457; Fri, 21 Apr 2023 11:37:27 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=J8MXHooEbZxLg10nF8GMHYpehdtFuKcjNFlsO2dpEmU=; b=IS64x1PyXYZrpI5kpm0VghFAFp9oecpvzRDsChc1XRXeGHOm2ilQPPKSmlVSbn1+yn71 XZ+xGoqK3CmwUsOqSPpGr/esnUsSdmh+RXEZrVzaPPzwjGRsMdhzpac6U6A/Uk8RBS/L PySzTldjMX1pUed9VKutG79N/k0fhjCd8nTKZk0p/AO5culZNEUcIAVRRee6lWa322f9 i2PPYGfP2I6MLNaXCpgGhDTYkJEraJqL6QPC5bjm/ckSzTaJ7nzANgjMO7fUQJ8gQu7A pcIhV/Rp2ltL/8vz8ilJkChcKDk1j/WWPPTrTaqCmLVF81ACh54CrMTDD5e7VJ4iABQC PA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q3rhc2qhy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:26 +0000 Received: from m0353727.ppops.net (m0353727.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 33LBZpsN017309; Fri, 21 Apr 2023 11:37:25 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q3rhc2qbp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:25 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 33L5KFrO015894; Fri, 21 Apr 2023 11:37:21 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma06fra.de.ibm.com (PPS) with ESMTPS id 3pyk6fkanr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:21 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 33LBbH4S54722950 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Apr 2023 11:37:17 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C2D8D20040; Fri, 21 Apr 2023 11:37:17 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EB38D20043; Fri, 21 Apr 2023 11:37:16 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 21 Apr 2023 11:37:16 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, thuth@redhat.com, nrb@linux.ibm.com, david@redhat.com Subject: [kvm-unit-tests PATCH v3 1/7] lib: s390x: uv: Introduce UV validity function Date: Fri, 21 Apr 2023 11:36:41 +0000 Message-Id: <20230421113647.134536-2-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230421113647.134536-1-frankja@linux.ibm.com> References: <20230421113647.134536-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 0dtU0NfLJaGp-spZDAVG8NocDfz3D_Qr X-Proofpoint-ORIG-GUID: 6tghTix5-5-8Uy2Rdl2uZHGHKEURROXr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-21_05,2023-04-21_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 priorityscore=1501 phishscore=0 lowpriorityscore=0 suspectscore=0 bulkscore=0 mlxscore=0 clxscore=1015 impostorscore=0 adultscore=0 malwarescore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304210100 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org PV related validities are in the 0x20** range but the last byte might be implementation specific, so everytime we check for a UV validity we need to mask the last byte. Let's add a function that checks for a UV validity and returns a boolean. Signed-off-by: Janosch Frank Reviewed-by: Claudio Imbrenda Reviewed-by: Nico Boehr --- lib/s390x/uv.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/s390x/uv.h b/lib/s390x/uv.h index 5fe29bda..78b979b7 100644 --- a/lib/s390x/uv.h +++ b/lib/s390x/uv.h @@ -35,4 +35,11 @@ static inline void uv_setup_asces(void) lctlg(13, asce); } +static inline bool uv_validity_check(struct vm *vm) +{ + uint16_t vir = sie_get_validity(vm); + + return vm->sblk->icptcode == ICPT_VALIDITY && (vir & 0xff00) == 0x2000; +} + #endif /* UV_H */ From patchwork Fri Apr 21 11:36:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 13219821 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 083F9C77B7C for ; Fri, 21 Apr 2023 11:39:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231758AbjDULjR (ORCPT ); Fri, 21 Apr 2023 07:39:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34326 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231689AbjDULjP (ORCPT ); Fri, 21 Apr 2023 07:39:15 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C0346D310; Fri, 21 Apr 2023 04:38:33 -0700 (PDT) Received: from pps.filterd (m0353728.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33LBXVDh019821; Fri, 21 Apr 2023 11:37:25 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=/yoypl42IowxfcwIi8B4m/HgA1WIvYGkafDgmtd9PMs=; b=qtQhcgfSG0jYgWUtRfaet/EgGETXLICKQO9nw5TWC9VtZS1Od4OAhu8KTlHuoqc8fgc8 ku5zu0bmrSgvPxDc2t0cV4cqbcqralx+Bxc207fZDxfwtw8O61Ql9C24c2nV6a0e6NG6 HvLQUsoghX8O9L4vMICl6jX/qF03d5WVKnE4ah0zgWtv/BygSVeAII+4QdWjrALJpzP+ ev1BgLw+0m+YlFIscX8Dya5ZBO4vh5XIZ3Y2Ob4GbfMmDtQ/fuefL9L52QihiBs4L1GG k6MSrK3FlbUhv1JE0JNupS7cKfk7fN4Amb9IumK5NbM4mJm4vlMj4IvQJ2OwnfmaADrQ XA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q3smn0dxn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:25 +0000 Received: from m0353728.ppops.net (m0353728.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 33LBXXq5020113; Fri, 21 Apr 2023 11:37:24 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q3smn0dvs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:24 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 33L2arIu012596; Fri, 21 Apr 2023 11:37:22 GMT Received: from smtprelay04.fra02v.mail.ibm.com ([9.218.2.228]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3pyk6fm0yx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:22 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay04.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 33LBbI9224052238 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Apr 2023 11:37:18 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BEF812004D; Fri, 21 Apr 2023 11:37:18 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F094C20040; Fri, 21 Apr 2023 11:37:17 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 21 Apr 2023 11:37:17 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, thuth@redhat.com, nrb@linux.ibm.com, david@redhat.com Subject: [kvm-unit-tests PATCH v3 2/7] lib: s390x: uv: Add intercept data check library function Date: Fri, 21 Apr 2023 11:36:42 +0000 Message-Id: <20230421113647.134536-3-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230421113647.134536-1-frankja@linux.ibm.com> References: <20230421113647.134536-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: DLk19zKyFstfT3z_Svh8kzV15cemTUAv X-Proofpoint-GUID: dxivhmVzKXwHoz3MJY7u7UmIfSRBt7pu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-21_05,2023-04-21_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 clxscore=1015 malwarescore=0 phishscore=0 impostorscore=0 priorityscore=1501 mlxlogscore=999 adultscore=0 bulkscore=0 suspectscore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304210100 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When working with guests it's essential to check the SIE intercept data for the correct values. Fortunately on PV guests these values are constants so we can create check functions which test for the constants. While we're at it let's make pv-diags.c use this new function. Signed-off-by: Janosch Frank Reviewed-by: Claudio Imbrenda Reviewed-by: Nico Boehr --- lib/s390x/pv_icptdata.h | 42 +++++++++++++++++++++++++++++++++++++++++ s390x/pv-diags.c | 14 ++++++-------- 2 files changed, 48 insertions(+), 8 deletions(-) create mode 100644 lib/s390x/pv_icptdata.h diff --git a/lib/s390x/pv_icptdata.h b/lib/s390x/pv_icptdata.h new file mode 100644 index 00000000..4746117e --- /dev/null +++ b/lib/s390x/pv_icptdata.h @@ -0,0 +1,42 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Commonly used checks for PV SIE intercept data + * + * Copyright IBM Corp. 2023 + * Author: Janosch Frank + */ + +#ifndef _S390X_PV_ICPTDATA_H_ +#define _S390X_PV_ICPTDATA_H_ + +#include + +/* + * Checks the diagnose instruction intercept data for consistency with + * the constants defined by the PV SIE architecture + * + * Supports: 0x44, 0x9c, 0x288, 0x308, 0x500 + */ +static bool pv_icptdata_check_diag(struct vm *vm, int diag) +{ + int icptcode; + + switch (diag) { + case 0x44: + case 0x9c: + case 0x288: + case 0x308: + icptcode = ICPT_PV_NOTIFY; + break; + case 0x500: + icptcode = ICPT_PV_INSTR; + break; + default: + /* If a new diag is introduced add it to the cases above! */ + assert(0); + } + + return vm->sblk->icptcode == icptcode && vm->sblk->ipa == 0x8302 && + vm->sblk->ipb == 0x50000000 && vm->save_area.guest.grs[5] == diag; +} +#endif diff --git a/s390x/pv-diags.c b/s390x/pv-diags.c index 5165937a..096ac61f 100644 --- a/s390x/pv-diags.c +++ b/s390x/pv-diags.c @@ -9,6 +9,7 @@ */ #include #include +#include #include #include #include @@ -31,8 +32,7 @@ static void test_diag_500(void) size_gbin, size_hdr, SNIPPET_UNPACK_OFF); sie(&vm); - report(vm.sblk->icptcode == ICPT_PV_INSTR && vm.sblk->ipa == 0x8302 && - vm.sblk->ipb == 0x50000000 && vm.save_area.guest.grs[5] == 0x500, + report(pv_icptdata_check_diag(&vm, 0x500), "intercept values"); report(vm.save_area.guest.grs[1] == 1 && vm.save_area.guest.grs[2] == 2 && @@ -45,9 +45,8 @@ static void test_diag_500(void) */ vm.sblk->iictl = IICTL_CODE_OPERAND; sie(&vm); - report(vm.sblk->icptcode == ICPT_PV_NOTIFY && vm.sblk->ipa == 0x8302 && - vm.sblk->ipb == 0x50000000 && vm.save_area.guest.grs[5] == 0x9c - && vm.save_area.guest.grs[0] == PGM_INT_CODE_OPERAND, + report(pv_icptdata_check_diag(&vm, 0x9c) && + vm.save_area.guest.grs[0] == PGM_INT_CODE_OPERAND, "operand exception"); /* @@ -58,9 +57,8 @@ static void test_diag_500(void) vm.sblk->iictl = IICTL_CODE_SPECIFICATION; /* Inject PGM, next exit should be 9c */ sie(&vm); - report(vm.sblk->icptcode == ICPT_PV_NOTIFY && vm.sblk->ipa == 0x8302 && - vm.sblk->ipb == 0x50000000 && vm.save_area.guest.grs[5] == 0x9c - && vm.save_area.guest.grs[0] == PGM_INT_CODE_SPECIFICATION, + report(pv_icptdata_check_diag(&vm, 0x9c) && + vm.save_area.guest.grs[0] == PGM_INT_CODE_SPECIFICATION, "specification exception"); /* No need for cleanup, just tear down the VM */ From patchwork Fri Apr 21 11:36:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 13219822 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 207E5C7618E for ; Fri, 21 Apr 2023 11:39:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231770AbjDULjS (ORCPT ); Fri, 21 Apr 2023 07:39:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231451AbjDULjQ (ORCPT ); Fri, 21 Apr 2023 07:39:16 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 444061727; Fri, 21 Apr 2023 04:38:35 -0700 (PDT) Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33LBXATh022152; Fri, 21 Apr 2023 11:37:26 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=240hch4l3N6CNEKqjo7/3vdjo6Dat6MzH04SeI8Vnek=; b=FDl0Wn3A4VjzspJSzr+ov/XmU8w/1bVI3Y6qYjxc0aBVrCgGTgHObfRzs6fD/AC0HjrZ snEJTd8ZtUYP2RDxA7riOYrXnwjRQ2lgT+vDArMVBdZ6IKJ26XMJdbrC+wpPB5rhGS9+ lSsTZd+fC4/8erGFE+QAJGcjoUis6+XoZUjFgjFMUbnmuepXmjkGTyGFVLTuMy17YHrM WVLnNCu3gbPQSZY4q+2ntDz4UsTOS1+0pO7vqs6g97giFZsW/vq1Xj5MyyXPBzZpA2tJ TmMAsSzbv8LvAZm8HYPTub1snlV1TMMgZnbwvvN3N0t1L7IHNu201vCH04xd/WBOA8db Eg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q3scyrtdt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:25 +0000 Received: from m0353724.ppops.net (m0353724.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 33LBYZXr002195; Fri, 21 Apr 2023 11:37:25 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q3scyrtbd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:25 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 33KLakZB002549; Fri, 21 Apr 2023 11:37:23 GMT Received: from smtprelay05.fra02v.mail.ibm.com ([9.218.2.225]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3pyk6fm0yy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:23 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay05.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 33LBbJei29753870 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Apr 2023 11:37:19 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BA2822004E; Fri, 21 Apr 2023 11:37:19 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ECAD420043; Fri, 21 Apr 2023 11:37:18 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 21 Apr 2023 11:37:18 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, thuth@redhat.com, nrb@linux.ibm.com, david@redhat.com Subject: [kvm-unit-tests PATCH v3 3/7] s390x: pv-diags: Drop snippet from snippet names Date: Fri, 21 Apr 2023 11:36:43 +0000 Message-Id: <20230421113647.134536-4-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230421113647.134536-1-frankja@linux.ibm.com> References: <20230421113647.134536-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: yczWsqP91wyJthRVMNGfgYEAKNdzM0wW X-Proofpoint-ORIG-GUID: lsngeCX8-QCMBLhKK3fh6LXW9GlcRFGm X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-21_04,2023-04-21_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 spamscore=0 priorityscore=1501 malwarescore=0 impostorscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304210091 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org It's a bit redundant. Signed-off-by: Janosch Frank Reviewed-by: Claudio Imbrenda Acked-by: Nico Boehr --- s390x/Makefile | 6 +-- s390x/pv-diags.c | 48 +++++++++---------- .../{snippet-pv-diag-288.S => pv-diag-288.S} | 0 .../{snippet-pv-diag-500.S => pv-diag-500.S} | 0 ...nippet-pv-diag-yield.S => pv-diag-yield.S} | 0 5 files changed, 27 insertions(+), 27 deletions(-) rename s390x/snippets/asm/{snippet-pv-diag-288.S => pv-diag-288.S} (100%) rename s390x/snippets/asm/{snippet-pv-diag-500.S => pv-diag-500.S} (100%) rename s390x/snippets/asm/{snippet-pv-diag-yield.S => pv-diag-yield.S} (100%) diff --git a/s390x/Makefile b/s390x/Makefile index a80db538..8d1cfc7c 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -122,9 +122,9 @@ snippet_lib = $(snippet_asmlib) lib/auxinfo.o $(TEST_DIR)/mvpg-sie.elf: snippets = $(SNIPPET_DIR)/c/mvpg-snippet.gbin $(TEST_DIR)/spec_ex-sie.elf: snippets = $(SNIPPET_DIR)/c/spec_ex.gbin -$(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/snippet-pv-diag-yield.gbin -$(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/snippet-pv-diag-288.gbin -$(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/snippet-pv-diag-500.gbin +$(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-yield.gbin +$(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-288.gbin +$(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-500.gbin ifneq ($(GEN_SE_HEADER),) snippets += $(pv-snippets) diff --git a/s390x/pv-diags.c b/s390x/pv-diags.c index 096ac61f..fa4e5532 100644 --- a/s390x/pv-diags.c +++ b/s390x/pv-diags.c @@ -18,17 +18,17 @@ static struct vm vm; static void test_diag_500(void) { - extern const char SNIPPET_NAME_START(asm, snippet_pv_diag_500)[]; - extern const char SNIPPET_NAME_END(asm, snippet_pv_diag_500)[]; - extern const char SNIPPET_HDR_START(asm, snippet_pv_diag_500)[]; - extern const char SNIPPET_HDR_END(asm, snippet_pv_diag_500)[]; - int size_hdr = SNIPPET_HDR_LEN(asm, snippet_pv_diag_500); - int size_gbin = SNIPPET_LEN(asm, snippet_pv_diag_500); + extern const char SNIPPET_NAME_START(asm, pv_diag_500)[]; + extern const char SNIPPET_NAME_END(asm, pv_diag_500)[]; + extern const char SNIPPET_HDR_START(asm, pv_diag_500)[]; + extern const char SNIPPET_HDR_END(asm, pv_diag_500)[]; + int size_hdr = SNIPPET_HDR_LEN(asm, pv_diag_500); + int size_gbin = SNIPPET_LEN(asm, pv_diag_500); report_prefix_push("diag 0x500"); - snippet_pv_init(&vm, SNIPPET_NAME_START(asm, snippet_pv_diag_500), - SNIPPET_HDR_START(asm, snippet_pv_diag_500), + snippet_pv_init(&vm, SNIPPET_NAME_START(asm, pv_diag_500), + SNIPPET_HDR_START(asm, pv_diag_500), size_gbin, size_hdr, SNIPPET_UNPACK_OFF); sie(&vm); @@ -70,17 +70,17 @@ static void test_diag_500(void) static void test_diag_288(void) { - extern const char SNIPPET_NAME_START(asm, snippet_pv_diag_288)[]; - extern const char SNIPPET_NAME_END(asm, snippet_pv_diag_288)[]; - extern const char SNIPPET_HDR_START(asm, snippet_pv_diag_288)[]; - extern const char SNIPPET_HDR_END(asm, snippet_pv_diag_288)[]; - int size_hdr = SNIPPET_HDR_LEN(asm, snippet_pv_diag_288); - int size_gbin = SNIPPET_LEN(asm, snippet_pv_diag_288); + extern const char SNIPPET_NAME_START(asm, pv_diag_288)[]; + extern const char SNIPPET_NAME_END(asm, pv_diag_288)[]; + extern const char SNIPPET_HDR_START(asm, pv_diag_288)[]; + extern const char SNIPPET_HDR_END(asm, pv_diag_288)[]; + int size_hdr = SNIPPET_HDR_LEN(asm, pv_diag_288); + int size_gbin = SNIPPET_LEN(asm, pv_diag_288); report_prefix_push("diag 0x288"); - snippet_pv_init(&vm, SNIPPET_NAME_START(asm, snippet_pv_diag_288), - SNIPPET_HDR_START(asm, snippet_pv_diag_288), + snippet_pv_init(&vm, SNIPPET_NAME_START(asm, pv_diag_288), + SNIPPET_HDR_START(asm, pv_diag_288), size_gbin, size_hdr, SNIPPET_UNPACK_OFF); sie(&vm); @@ -111,17 +111,17 @@ static void test_diag_288(void) static void test_diag_yield(void) { - extern const char SNIPPET_NAME_START(asm, snippet_pv_diag_yield)[]; - extern const char SNIPPET_NAME_END(asm, snippet_pv_diag_yield)[]; - extern const char SNIPPET_HDR_START(asm, snippet_pv_diag_yield)[]; - extern const char SNIPPET_HDR_END(asm, snippet_pv_diag_yield)[]; - int size_hdr = SNIPPET_HDR_LEN(asm, snippet_pv_diag_yield); - int size_gbin = SNIPPET_LEN(asm, snippet_pv_diag_yield); + extern const char SNIPPET_NAME_START(asm, pv_diag_yield)[]; + extern const char SNIPPET_NAME_END(asm, pv_diag_yield)[]; + extern const char SNIPPET_HDR_START(asm, pv_diag_yield)[]; + extern const char SNIPPET_HDR_END(asm, pv_diag_yield)[]; + int size_hdr = SNIPPET_HDR_LEN(asm, pv_diag_yield); + int size_gbin = SNIPPET_LEN(asm, pv_diag_yield); report_prefix_push("diag yield"); - snippet_pv_init(&vm, SNIPPET_NAME_START(asm, snippet_pv_diag_yield), - SNIPPET_HDR_START(asm, snippet_pv_diag_yield), + snippet_pv_init(&vm, SNIPPET_NAME_START(asm, pv_diag_yield), + SNIPPET_HDR_START(asm, pv_diag_yield), size_gbin, size_hdr, SNIPPET_UNPACK_OFF); /* 0x44 */ diff --git a/s390x/snippets/asm/snippet-pv-diag-288.S b/s390x/snippets/asm/pv-diag-288.S similarity index 100% rename from s390x/snippets/asm/snippet-pv-diag-288.S rename to s390x/snippets/asm/pv-diag-288.S diff --git a/s390x/snippets/asm/snippet-pv-diag-500.S b/s390x/snippets/asm/pv-diag-500.S similarity index 100% rename from s390x/snippets/asm/snippet-pv-diag-500.S rename to s390x/snippets/asm/pv-diag-500.S diff --git a/s390x/snippets/asm/snippet-pv-diag-yield.S b/s390x/snippets/asm/pv-diag-yield.S similarity index 100% rename from s390x/snippets/asm/snippet-pv-diag-yield.S rename to s390x/snippets/asm/pv-diag-yield.S From patchwork Fri Apr 21 11:36:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 13219823 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 2BA58C77B75 for ; Fri, 21 Apr 2023 11:39:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231772AbjDULjT (ORCPT ); Fri, 21 Apr 2023 07:39:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231766AbjDULjR (ORCPT ); Fri, 21 Apr 2023 07:39:17 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 759A11998; Fri, 21 Apr 2023 04:38:35 -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 33LBXEcW028181; Fri, 21 Apr 2023 11:37:27 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=zLgSyE+CTqUXbXEYYQDj+oecn0igaVoyRz9/okrYn4s=; b=CRF8DCICxxk1bdv05jz8FDny6mIqQ4uyZOsuyCvwW2qa7VVrkZtvd2LQVy1ju/d2AjcM 9c6t3+OI3HtBDuxvOSqRJU5zOatLdgsHtTumfRyK5hxH2s3omhS5jkH7hiErKRNgWamJ vuqi6P8qDAi3XfPjIX4ELMJeUQmxY7nBb9bvo9kjjeHUcrcPBmJr/2rKsXqTDTDCEFBB Pt0ulhDobLN+g65DwIuWWpKz9++DBHnT25+TwpV6qrGmenNvNkSM15tuKckTvojYhpMD 2S8xfrZQLnztda7c0IzsVPajbzFsRfR+UGpYJJpGzBpPkGmNyZSWz7AlXBiJipqtq588 UQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q3s0nsm35-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:26 +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 33LBY52D002303; Fri, 21 Apr 2023 11:37:26 GMT Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q3s0nsm0j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:26 +0000 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 33L8bLjS017177; Fri, 21 Apr 2023 11:37:24 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma01fra.de.ibm.com (PPS) with ESMTPS id 3pykj6kaks-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:24 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 33LBbK9f10486352 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Apr 2023 11:37:20 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B56642004D; Fri, 21 Apr 2023 11:37:20 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E7ACC20040; Fri, 21 Apr 2023 11:37:19 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 21 Apr 2023 11:37:19 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, thuth@redhat.com, nrb@linux.ibm.com, david@redhat.com Subject: [kvm-unit-tests PATCH v3 4/7] lib: s390x: uv: Add pv guest requirement check function Date: Fri, 21 Apr 2023 11:36:44 +0000 Message-Id: <20230421113647.134536-5-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230421113647.134536-1-frankja@linux.ibm.com> References: <20230421113647.134536-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: w3Ddxe2BXmKgmBQuTDQcjzNm-BLTa53k X-Proofpoint-GUID: hGCzUuhJVRwO0RdWJotB9is7sYtOxjWq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-21_04,2023-04-21_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 phishscore=0 impostorscore=0 lowpriorityscore=0 mlxscore=0 adultscore=0 clxscore=1015 mlxlogscore=999 malwarescore=0 spamscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304210095 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org When running PV guests some of the UV memory needs to be allocated with > 31 bit addresses which means tests with PV guests will always need a lot more memory than other tests. Additionally facilities nr 158 and sclp.sief2 need to be available. Let's add a function that checks for these requirements and prints a helpful skip message. Signed-off-by: Janosch Frank Reviewed-by: Nico Boehr --- lib/s390x/snippet.h | 7 +++++++ lib/s390x/uv.c | 20 ++++++++++++++++++++ lib/s390x/uv.h | 1 + s390x/pv-diags.c | 8 +------- 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/lib/s390x/snippet.h b/lib/s390x/snippet.h index 57045994..11ec54c3 100644 --- a/lib/s390x/snippet.h +++ b/lib/s390x/snippet.h @@ -30,6 +30,13 @@ #define SNIPPET_HDR_LEN(type, file) \ ((uintptr_t)SNIPPET_HDR_END(type, file) - (uintptr_t)SNIPPET_HDR_START(type, file)) +/* + * Some of the UV memory needs to be allocated with >31 bit + * addresses which means we need a lot more memory than other + * tests. + */ +#define SNIPPET_PV_MIN_MEM_SIZE (SZ_1M * 2200UL) + #define SNIPPET_PV_TWEAK0 0x42UL #define SNIPPET_PV_TWEAK1 0UL #define SNIPPET_UNPACK_OFF 0 diff --git a/lib/s390x/uv.c b/lib/s390x/uv.c index 383271a5..db47536c 100644 --- a/lib/s390x/uv.c +++ b/lib/s390x/uv.c @@ -18,6 +18,7 @@ #include #include #include +#include static struct uv_cb_qui uvcb_qui = { .header.cmd = UVC_CMD_QUI, @@ -38,6 +39,25 @@ bool uv_os_is_host(void) return test_facility(158) && uv_query_test_call(BIT_UVC_CMD_INIT_UV); } +bool uv_guest_requirement_checks(void) +{ + if (!test_facility(158)) { + report_skip("UV Call facility unavailable"); + return false; + } + if (!sclp_facilities.has_sief2) { + report_skip("SIEF2 facility unavailable"); + return false; + } + if (get_ram_size() < SNIPPET_PV_MIN_MEM_SIZE) { + report_skip("Not enough memory. This test needs about %ld MB of memory", + SNIPPET_PV_MIN_MEM_SIZE / 1024 / 1024); + return false; + } + + return true; +} + bool uv_query_test_call(unsigned int nr) { /* Query needs to be called first */ diff --git a/lib/s390x/uv.h b/lib/s390x/uv.h index 78b979b7..d9af691a 100644 --- a/lib/s390x/uv.h +++ b/lib/s390x/uv.h @@ -7,6 +7,7 @@ bool uv_os_is_guest(void); bool uv_os_is_host(void); +bool uv_guest_requirement_checks(void); bool uv_query_test_call(unsigned int nr); const struct uv_cb_qui *uv_get_query_data(void); void uv_init(void); diff --git a/s390x/pv-diags.c b/s390x/pv-diags.c index fa4e5532..1289a571 100644 --- a/s390x/pv-diags.c +++ b/s390x/pv-diags.c @@ -149,14 +149,8 @@ static void test_diag_yield(void) int main(void) { report_prefix_push("pv-diags"); - if (!test_facility(158)) { - report_skip("UV Call facility unavailable"); + if (!uv_guest_requirement_checks()) goto done; - } - if (!sclp_facilities.has_sief2) { - report_skip("SIEF2 facility unavailable"); - goto done; - } uv_setup_asces(); snippet_setup_guest(&vm, true); From patchwork Fri Apr 21 11:36:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 13219859 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 81348C77B76 for ; Fri, 21 Apr 2023 11:39:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231799AbjDULjY (ORCPT ); Fri, 21 Apr 2023 07:39:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231808AbjDULjW (ORCPT ); Fri, 21 Apr 2023 07:39:22 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10FC3AF27; Fri, 21 Apr 2023 04:38:41 -0700 (PDT) Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33LBY9FR027755; Fri, 21 Apr 2023 11:37:30 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=uHhKTXY0mq+sXSzTaJbyJn63P+zy+P7OPL5x0AEa1jQ=; b=FaY/kVMZzxibpZCgHRJnFEZvDhxUg51JA21v8yPdHL3qLesv/aZXlt4iRownqkfTMKjF i6irxinxJlJsOf0gkFULd9VROEolnIwnVoXE3ZSzEtFsJJlTtNhRYfKJQeXC9kLMnbGX GVNb/udA/DY+BgJM08xzs7cyZv/Nl7TIIoUJ5WLSumPflLUQlmdk5Uz21vR532+UwmMx T3yeELWveIPIedP/OtoOqya4ZOoQ5/Vayy7nKcNdw5wrjWvO/Lp7gK1FyFKhKUYGR25K X0Et7S+AWcGumo9jrIZGJVrGKPQcF+USuTvNYIxAGY2kGAodZ6T8Zg3r0QiMzxy2h9HL 2Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q3rhe2n37-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:30 +0000 Received: from m0353726.ppops.net (m0353726.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 33LBY3Zf027415; Fri, 21 Apr 2023 11:37:28 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q3rhe2mxm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:28 +0000 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 33L98Pg2012228; Fri, 21 Apr 2023 11:37:25 GMT Received: from smtprelay02.fra02v.mail.ibm.com ([9.218.2.226]) by ppma06ams.nl.ibm.com (PPS) with ESMTPS id 3pyk6fm100-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:25 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay02.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 33LBbLtn18809456 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Apr 2023 11:37:21 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BB02920043; Fri, 21 Apr 2023 11:37:21 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E364D20040; Fri, 21 Apr 2023 11:37:20 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 21 Apr 2023 11:37:20 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, thuth@redhat.com, nrb@linux.ibm.com, david@redhat.com Subject: [kvm-unit-tests PATCH v3 5/7] s390x: pv: Add sie entry intercept and validity test Date: Fri, 21 Apr 2023 11:36:45 +0000 Message-Id: <20230421113647.134536-6-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230421113647.134536-1-frankja@linux.ibm.com> References: <20230421113647.134536-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: V-yFvmEikGpFIk773oaEVo0UmzfW12e7 X-Proofpoint-GUID: q4o7IATh9TKbZSb9Pu8LLUZI1sh63uvj X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-21_05,2023-04-21_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 spamscore=0 adultscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=999 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304210100 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The lowcore is an important part of any s390 cpu so we need to make sure it's always available when we virtualize one. For non-PV guests that would mean ensuring that the lowcore page is read and writable by the guest. For PV guests we additionally need to make sure that the page is owned by the guest as it is only allowed to access them if that's the case. The code 112 SIE intercept tells us if the lowcore pages aren't secure anymore. Let's check if that intercept is reported by SIE if we export the lowcore pages. Additionally check if that's also the case if the guest shares the lowcore which will make it readable to the host but ownership of the page should not change. Also we check for validities in these conditions: * Manipulated cpu timer * Double SIE for same vcpu * Re-use of VCPU handle from another secure configuration * ASCE re-use Signed-off-by: Janosch Frank --- s390x/Makefile | 5 + s390x/pv-icptcode.c | 370 ++++++++++++++++++++++++ s390x/snippets/asm/icpt-loop.S | 15 + s390x/snippets/asm/loop.S | 13 + s390x/snippets/asm/pv-icpt-vir-timing.S | 22 ++ s390x/unittests.cfg | 5 + 6 files changed, 430 insertions(+) create mode 100644 s390x/pv-icptcode.c create mode 100644 s390x/snippets/asm/icpt-loop.S create mode 100644 s390x/snippets/asm/loop.S create mode 100644 s390x/snippets/asm/pv-icpt-vir-timing.S diff --git a/s390x/Makefile b/s390x/Makefile index 8d1cfc7c..67be5360 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -42,6 +42,7 @@ tests += $(TEST_DIR)/exittime.elf tests += $(TEST_DIR)/ex.elf pv-tests += $(TEST_DIR)/pv-diags.elf +pv-tests += $(TEST_DIR)/pv-icptcode.elf ifneq ($(HOST_KEY_DOCUMENT),) ifneq ($(GEN_SE_HEADER),) @@ -125,6 +126,10 @@ $(TEST_DIR)/spec_ex-sie.elf: snippets = $(SNIPPET_DIR)/c/spec_ex.gbin $(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-yield.gbin $(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-288.gbin $(TEST_DIR)/pv-diags.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-500.gbin +$(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-icpt-112.gbin +$(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/icpt-loop.gbin +$(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/loop.gbin +$(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-icpt-vir-timing.gbin ifneq ($(GEN_SE_HEADER),) snippets += $(pv-snippets) diff --git a/s390x/pv-icptcode.c b/s390x/pv-icptcode.c new file mode 100644 index 00000000..38a8053a --- /dev/null +++ b/s390x/pv-icptcode.c @@ -0,0 +1,370 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * PV virtualization interception tests for intercepts that are not + * caused by an instruction. + * + * Copyright (c) 2023 IBM Corp + * + * Authors: + * Janosch Frank + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static struct vm vm, vm2; + +/* + * The hypervisor should not be able to decrease the cpu timer by an + * amount that is higher than the amount of time spent outside of + * SIE. + * + * Warning: A lot of things influence time so decreasing the timer by + * a more significant amount than the difference to have a safety + * margin is advised. + */ +static void test_validity_timing(void) +{ + extern const char SNIPPET_NAME_START(asm, pv_icpt_vir_timing)[]; + extern const char SNIPPET_NAME_END(asm, pv_icpt_vir_timing)[]; + extern const char SNIPPET_HDR_START(asm, pv_icpt_vir_timing)[]; + extern const char SNIPPET_HDR_END(asm, pv_icpt_vir_timing)[]; + int size_hdr = SNIPPET_HDR_LEN(asm, pv_icpt_vir_timing); + int size_gbin = SNIPPET_LEN(asm, pv_icpt_vir_timing); + uint64_t time_exit, time_entry; + + report_prefix_push("manipulated cpu time"); + snippet_pv_init(&vm, SNIPPET_NAME_START(asm, pv_icpt_vir_timing), + SNIPPET_HDR_START(asm, pv_icpt_vir_timing), + size_gbin, size_hdr, SNIPPET_UNPACK_OFF); + + sie(&vm); + report(pv_icptdata_check_diag(&vm, 0x44), "stp done"); + stck(&time_exit); + mb(); + + /* Cpu timer counts down so adding a ms should lead to a validity */ + vm.sblk->cputm += S390_CLOCK_SHIFT_US * 1000; + sie_expect_validity(&vm); + sie(&vm); + report(uv_validity_check(&vm), "validity entry cput > exit cput"); + vm.sblk->cputm -= S390_CLOCK_SHIFT_US; + + /* + * We are not allowed to decrement the timer more than the + * time spent outside of SIE + */ + stck(&time_entry); + vm.sblk->cputm -= (time_entry - time_exit) + S390_CLOCK_SHIFT_US * 1000; + sie_expect_validity(&vm); + sie(&vm); + report(uv_validity_check(&vm), "validity entry cput < time spent outside SIE"); + + uv_destroy_guest(&vm); + report_prefix_pop(); +} + +static void run_loop(void) +{ + sie(&vm); + sigp_retry(stap(), SIGP_STOP, 0, NULL); +} + +static void test_validity_already_running(void) +{ + extern const char SNIPPET_NAME_START(asm, loop)[]; + extern const char SNIPPET_NAME_END(asm, loop)[]; + extern const char SNIPPET_HDR_START(asm, loop)[]; + extern const char SNIPPET_HDR_END(asm, loop)[]; + int size_hdr = SNIPPET_HDR_LEN(asm, loop); + int size_gbin = SNIPPET_LEN(asm, loop); + struct psw psw = { + .mask = PSW_MASK_64, + .addr = (uint64_t)run_loop, + }; + + report_prefix_push("already running"); + if (smp_query_num_cpus() < 3) { + report_skip("need at least 3 cpus for this test"); + goto out; + } + + snippet_pv_init(&vm, SNIPPET_NAME_START(asm, loop), + SNIPPET_HDR_START(asm, loop), + size_gbin, size_hdr, SNIPPET_UNPACK_OFF); + + sie_expect_validity(&vm); + smp_cpu_setup(1, psw); + smp_cpu_setup(2, psw); + while (vm.sblk->icptcode != ICPT_VALIDITY) { + mb(); + } + + /* + * One cpu will enter SIE and one will receive the validity. + * We rely on the expectation that the cpu in SIE won't exit + * until we had a chance to observe the validity as the exit + * would overwrite the validity. + * + * In general that expectation is valid but HW/FW can in + * theory still exit to handle their interrupts. + */ + report(uv_validity_check(&vm), "validity"); + smp_cpu_stop(1); + smp_cpu_stop(2); + uv_destroy_guest(&vm); + +out: + report_prefix_pop(); +} + +/* Tests if a vcpu handle from another configuration results in a validity intercept. */ +static void test_validity_handle_not_in_config(void) +{ + extern const char SNIPPET_NAME_START(asm, icpt_loop)[]; + extern const char SNIPPET_NAME_END(asm, icpt_loop)[]; + extern const char SNIPPET_HDR_START(asm, icpt_loop)[]; + extern const char SNIPPET_HDR_END(asm, icpt_loop)[]; + int size_hdr = SNIPPET_HDR_LEN(asm, icpt_loop); + int size_gbin = SNIPPET_LEN(asm, icpt_loop); + + report_prefix_push("handle not in config"); + /* Setup our primary vm */ + snippet_pv_init(&vm, SNIPPET_NAME_START(asm, icpt_loop), + SNIPPET_HDR_START(asm, icpt_loop), + size_gbin, size_hdr, SNIPPET_UNPACK_OFF); + + /* Setup secondary vm */ + snippet_setup_guest(&vm2, true); + snippet_pv_init(&vm2, SNIPPET_NAME_START(asm, icpt_loop), + SNIPPET_HDR_START(asm, icpt_loop), + size_gbin, size_hdr, SNIPPET_UNPACK_OFF); + + vm.sblk->pv_handle_cpu = vm2.sblk->pv_handle_cpu; + sie_expect_validity(&vm); + sie(&vm); + report(uv_validity_check(&vm), "validity"); + + /* Restore cpu handle and destroy the second vm */ + vm.sblk->pv_handle_cpu = vm.uv.vcpu_handle; + uv_destroy_guest(&vm2); + sie_guest_destroy(&vm2); + + uv_destroy_guest(&vm); + report_prefix_pop(); +} + +/* Tests if a wrong vm or vcpu handle results in a validity intercept. */ +static void test_validity_seid(void) +{ + extern const char SNIPPET_NAME_START(asm, icpt_loop)[]; + extern const char SNIPPET_NAME_END(asm, icpt_loop)[]; + extern const char SNIPPET_HDR_START(asm, icpt_loop)[]; + extern const char SNIPPET_HDR_END(asm, icpt_loop)[]; + int size_hdr = SNIPPET_HDR_LEN(asm, icpt_loop); + int size_gbin = SNIPPET_LEN(asm, icpt_loop); + int fails = 0; + int i; + + report_prefix_push("handles"); + snippet_pv_init(&vm, SNIPPET_NAME_START(asm, icpt_loop), + SNIPPET_HDR_START(asm, icpt_loop), + size_gbin, size_hdr, SNIPPET_UNPACK_OFF); + + for (i = 0; i < 64; i++) { + vm.sblk->pv_handle_config ^= 1UL << i; + sie_expect_validity(&vm); + sie(&vm); + if (!uv_validity_check(&vm)) { + report_fail("SIE accepted wrong VM SEID, changed bit %d", + 63 - i); + fails++; + } + vm.sblk->pv_handle_config ^= 1UL << i; + } + report(!fails, "No wrong vm handle accepted"); + + fails = 0; + for (i = 0; i < 64; i++) { + vm.sblk->pv_handle_cpu ^= 1UL << i; + sie_expect_validity(&vm); + sie(&vm); + if (!uv_validity_check(&vm)) { + report_fail("SIE accepted wrong CPU SEID, changed bit %d", + 63 - i); + fails++; + } + vm.sblk->pv_handle_cpu ^= 1UL << i; + } + report(!fails, "No wrong cpu handle accepted"); + + uv_destroy_guest(&vm); + report_prefix_pop(); +} + +/* + * Tests if we get a validity intercept if the CR1 asce at SIE entry + * is not the same as the one given at the UV creation of the VM. + */ +static void test_validity_asce(void) +{ + extern const char SNIPPET_NAME_START(asm, pv_icpt_112)[]; + extern const char SNIPPET_NAME_END(asm, pv_icpt_112)[]; + extern const char SNIPPET_HDR_START(asm, pv_icpt_112)[]; + extern const char SNIPPET_HDR_END(asm, pv_icpt_112)[]; + int size_hdr = SNIPPET_HDR_LEN(asm, pv_icpt_112); + int size_gbin = SNIPPET_LEN(asm, pv_icpt_112); + uint64_t asce_old, asce_new; + void *pgd_new, *pgd_old; + + report_prefix_push("asce"); + snippet_pv_init(&vm, SNIPPET_NAME_START(asm, pv_icpt_112), + SNIPPET_HDR_START(asm, pv_icpt_112), + size_gbin, size_hdr, SNIPPET_UNPACK_OFF); + + asce_old = vm.save_area.guest.asce; + pgd_new = memalign_pages_flags(PAGE_SIZE, PAGE_SIZE * 4, 0); + pgd_old = (void *)(asce_old & PAGE_MASK); + + /* Copy the contents of the top most table */ + memcpy(pgd_new, pgd_old, PAGE_SIZE * 4); + + /* Create the replacement ASCE */ + asce_new = __pa(pgd_new) | ASCE_DT_REGION1 | REGION_TABLE_LENGTH | ASCE_P; + vm.save_area.guest.asce = asce_new; + + sie_expect_validity(&vm); + sie(&vm); + report(uv_validity_check(&vm), "wrong CR1 validity"); + + /* Restore the old ASCE */ + vm.save_area.guest.asce = asce_old; + + /* Try if we can still do an entry with the correct asce */ + sie(&vm); + report(pv_icptdata_check_diag(&vm, 0x44), "re-entry with valid CR1"); + uv_destroy_guest(&vm); + free_pages(pgd_new); + report_prefix_pop(); +} + +static void run_icpt_122_tests(unsigned long lc_off) +{ + uv_export(vm.sblk->mso + lc_off); + sie(&vm); + report(vm.sblk->icptcode == ICPT_PV_PREF, "Intercept 112 for page 0"); + uv_import(vm.uv.vm_handle, vm.sblk->mso + lc_off); + + uv_export(vm.sblk->mso + lc_off + PAGE_SIZE); + report(vm.sblk->icptcode == ICPT_PV_PREF, "Intercept 112 for page 1"); + uv_import(vm.uv.vm_handle, vm.sblk->mso + lc_off + PAGE_SIZE); +} + +static void run_icpt_122_tests_prefix(unsigned long prefix) +{ + char prfxstr[7]; + uint32_t *ptr = 0; + + snprintf(prfxstr, sizeof(prfxstr), "0x%lx", prefix); + + report_prefix_push(prfxstr); + report_prefix_push("unshared"); + run_icpt_122_tests(prefix); + report_prefix_pop(); + + /* + * Guest will share the lowcore and we need to check if that + * makes a difference (which it should not). + */ + report_prefix_push("shared"); + + sie(&vm); + /* Guest indicates that it has been setup via the diag 0x44 */ + assert(pv_icptdata_check_diag(&vm, 0x44)); + /* If the pages have not been shared these writes will cause exceptions */ + ptr = (uint32_t *)prefix; + WRITE_ONCE(ptr, 0); + ptr = (uint32_t *)(prefix + offsetof(struct lowcore, ars_sa[0])); + WRITE_ONCE(ptr, 0); + + run_icpt_122_tests(prefix); + + /* shared*/ + report_prefix_pop(); + /* prefix hex value */ + report_prefix_pop(); +} + +static void test_icpt_112(void) +{ + extern const char SNIPPET_NAME_START(asm, pv_icpt_112)[]; + extern const char SNIPPET_NAME_END(asm, pv_icpt_112)[]; + extern const char SNIPPET_HDR_START(asm, pv_icpt_112)[]; + extern const char SNIPPET_HDR_END(asm, pv_icpt_112)[]; + int size_hdr = SNIPPET_HDR_LEN(asm, pv_icpt_112); + int size_gbin = SNIPPET_LEN(asm, pv_icpt_112); + + unsigned long lc_off = 0; + + report_prefix_push("prefix"); + + snippet_pv_init(&vm, SNIPPET_NAME_START(asm, pv_icpt_112), + SNIPPET_HDR_START(asm, pv_icpt_112), + size_gbin, size_hdr, SNIPPET_UNPACK_OFF); + + /* Setup of the guest's state for 0x0 prefix */ + sie(&vm); + assert(pv_icptdata_check_diag(&vm, 0x44)); + + /* Test on standard 0x0 prefix */ + run_icpt_122_tests_prefix(0); + + /* Setup of the guest's state for 0x8000 prefix */ + lc_off = 0x8000; + uv_import(vm.uv.vm_handle, vm.sblk->mso + lc_off); + uv_import(vm.uv.vm_handle, vm.sblk->mso + lc_off + PAGE_SIZE); + /* Guest will set prefix to 0x8000 */ + sie(&vm); + /* SPX generates a PV instruction notification */ + assert(vm.sblk->icptcode == ICPT_PV_NOTIFY && vm.sblk->ipa == 0xb210); + assert(*(u32 *)vm.sblk->sidad == 0x8000); + + /* Test on 0x8000 prefix */ + run_icpt_122_tests_prefix(0x8000); + + /* Try a re-entry after everything has been imported again */ + sie(&vm); + report(pv_icptdata_check_diag(&vm, 0x9c) && + vm.save_area.guest.grs[0] == 42, + "re-entry successful"); + report_prefix_pop(); + uv_destroy_guest(&vm); +} + +int main(void) +{ + report_prefix_push("pv-icpts"); + if (!uv_guest_requirement_checks()) + goto done; + + snippet_setup_guest(&vm, true); + test_icpt_112(); + test_validity_asce(); + test_validity_seid(); + test_validity_handle_not_in_config(); + test_validity_already_running(); + test_validity_timing(); + sie_guest_destroy(&vm); + +done: + report_prefix_pop(); + return report_summary(); +} diff --git a/s390x/snippets/asm/icpt-loop.S b/s390x/snippets/asm/icpt-loop.S new file mode 100644 index 00000000..2aa59c01 --- /dev/null +++ b/s390x/snippets/asm/icpt-loop.S @@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Infinite loop snippet which can be used to test manipulated SIE + * control block intercepts. E.g. when manipulating the PV handles. + * + * Copyright (c) 2023 IBM Corp + * + * Authors: + * Janosch Frank + */ +.section .text +xgr %r0, %r0 +retry: +diag 0,0,0x44 +j retry diff --git a/s390x/snippets/asm/loop.S b/s390x/snippets/asm/loop.S new file mode 100644 index 00000000..a75bf00d --- /dev/null +++ b/s390x/snippets/asm/loop.S @@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Infinite loop snippet with no exit + * + * Copyright (c) 2023 IBM Corp + * + * Authors: + * Janosch Frank + */ +.section .text + +retry: +j retry diff --git a/s390x/snippets/asm/pv-icpt-vir-timing.S b/s390x/snippets/asm/pv-icpt-vir-timing.S new file mode 100644 index 00000000..b35f02c9 --- /dev/null +++ b/s390x/snippets/asm/pv-icpt-vir-timing.S @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Sets a cpu timer which the host can manipulate to check if it will + * receive a validity + * + * Copyright (c) 2023 IBM Corp + * + * Authors: + * Janosch Frank + */ +.section .text +larl %r1, time_val +spt 0 (%r1) +diag 0, 0, 0x44 +xgr %r1, %r1 +lghi %r1, 42 +diag 1, 0, 0x9c + + +.align 8 +time_val: + .quad 0x280de80000 diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index b61faf07..e2d3478e 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -218,3 +218,8 @@ extra_params = -append '--parallel' [execute] file = ex.elf + +[pv-icptcode] +file = pv-icptcode.elf +smp = 3 +extra_params = -m 2200 From patchwork Fri Apr 21 11:36:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 13219818 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 B0681C77B75 for ; Fri, 21 Apr 2023 11:39:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231675AbjDULjM (ORCPT ); Fri, 21 Apr 2023 07:39:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231161AbjDULjK (ORCPT ); Fri, 21 Apr 2023 07:39:10 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B843C665; Fri, 21 Apr 2023 04:38:26 -0700 (PDT) Received: from pps.filterd (m0353726.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33LBXxGR026529; Fri, 21 Apr 2023 11:37:29 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=qUkOxiXPrxZWeZG0ZI1NQXc9ZWtSGgUCM1b129joIXE=; b=Sv5f80ZsrcVyqRL/cJ3RACarv7XW0jjiBo1APYqfpAe3ppAmRQHebQAWkfNAxxS2AjTr nYAz1JISpILFC6blpyPYMd/QrxgCP2wj1v/vbMG4qAMnA+OBVdxtr246uhuphelwV9DE 3nayXapaZ1yTMJ3YiSqB4l0MRGAFiwc5V9bM53KsDWwlyc/i/5wvm0Cwh8q8KZ/JTfg1 bKrTdseiM/gEQEDRM0kaMBbzh7Y4w6FfUiW6TkvDlMFXBUFNTJqYMfaETqUfADUXb60E bqO7Fz9iViTJ4EkOiefCwA21Wazn5h3Hg27eF7HdFG6hnGZKHIPO5MFa/JPUY7ksWdw9 dQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q3rhe2n3k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:29 +0000 Received: from m0353726.ppops.net (m0353726.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 33LBYmtC001485; Fri, 21 Apr 2023 11:37:28 GMT Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q3rhe2n05-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:28 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 33L9aIAN015113; Fri, 21 Apr 2023 11:37:26 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma02fra.de.ibm.com (PPS) with ESMTPS id 3pykj6kata-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:26 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 33LBbMNA15860258 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Apr 2023 11:37:22 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B723920043; Fri, 21 Apr 2023 11:37:22 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E901D20040; Fri, 21 Apr 2023 11:37:21 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 21 Apr 2023 11:37:21 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, thuth@redhat.com, nrb@linux.ibm.com, david@redhat.com Subject: [kvm-unit-tests PATCH v3 6/7] s390x: pv: Add IPL reset tests Date: Fri, 21 Apr 2023 11:36:46 +0000 Message-Id: <20230421113647.134536-7-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230421113647.134536-1-frankja@linux.ibm.com> References: <20230421113647.134536-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: b2fucuycnkqfW-FZO5Tsm_cAVTVYhj5Y X-Proofpoint-GUID: QhGUhhrFG-JOqJ1mndi5psCwRp-Udtb3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-21_05,2023-04-21_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 priorityscore=1501 clxscore=1015 spamscore=0 adultscore=0 suspectscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=999 impostorscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304210100 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The diag308 requires extensive cooperation between the hypervisor and the Ultravisor so the Ultravisor can make sure all necessary reset steps have been done. Let's check if we get the correct validity errors. Signed-off-by: Janosch Frank --- s390x/Makefile | 2 + s390x/pv-ipl.c | 145 ++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 ++ 3 files changed, 151 insertions(+) create mode 100644 s390x/pv-ipl.c diff --git a/s390x/Makefile b/s390x/Makefile index 67be5360..b5b94810 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -43,6 +43,7 @@ tests += $(TEST_DIR)/ex.elf pv-tests += $(TEST_DIR)/pv-diags.elf pv-tests += $(TEST_DIR)/pv-icptcode.elf +pv-tests += $(TEST_DIR)/pv-ipl.elf ifneq ($(HOST_KEY_DOCUMENT),) ifneq ($(GEN_SE_HEADER),) @@ -130,6 +131,7 @@ $(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-icpt-112.gbin $(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/icpt-loop.gbin $(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/loop.gbin $(TEST_DIR)/pv-icptcode.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-icpt-vir-timing.gbin +$(TEST_DIR)/pv-ipl.elf: pv-snippets += $(SNIPPET_DIR)/asm/pv-diag-308.gbin ifneq ($(GEN_SE_HEADER),) snippets += $(pv-snippets) diff --git a/s390x/pv-ipl.c b/s390x/pv-ipl.c new file mode 100644 index 00000000..aad1275e --- /dev/null +++ b/s390x/pv-ipl.c @@ -0,0 +1,145 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * PV diagnose 308 (IPL) tests + * + * Copyright (c) 2023 IBM Corp + * + * Authors: + * Janosch Frank + */ +#include +#include +#include +#include +#include +#include +#include + +static struct vm vm; + +static void test_diag_308(int subcode) +{ + extern const char SNIPPET_NAME_START(asm, pv_diag_308)[]; + extern const char SNIPPET_NAME_END(asm, pv_diag_308)[]; + extern const char SNIPPET_HDR_START(asm, pv_diag_308)[]; + extern const char SNIPPET_HDR_END(asm, pv_diag_308)[]; + int size_hdr = SNIPPET_HDR_LEN(asm, pv_diag_308); + int size_gbin = SNIPPET_LEN(asm, pv_diag_308); + uint16_t rc, rrc; + char prefix[10]; + int cc; + + snprintf(prefix, sizeof(prefix), "subcode %d", subcode); + + report_prefix_push(prefix); + snippet_pv_init(&vm, SNIPPET_NAME_START(asm, pv_diag_308), + SNIPPET_HDR_START(asm, pv_diag_308), + size_gbin, size_hdr, SNIPPET_UNPACK_OFF); + + /* First exit is a diag 0x500 */ + sie(&vm); + assert(pv_icptdata_check_diag(&vm, 0x500)); + + /* + * The snippet asked us for the subcode and we answer with 0 in gr2 + * SIE will copy gr2 to the guest + */ + vm.save_area.guest.grs[2] = subcode; + + /* Continue after diag 0x500, next icpt should be the 0x308 */ + sie(&vm); + assert(pv_icptdata_check_diag(&vm, 0x308)); + assert(vm.save_area.guest.grs[2] == subcode); + + /* + * We need to perform several UV calls to emulate the subcode + * 0/1. Failing to do that should result in a validity. + * + * - Mark all cpus as stopped + * - Unshare all memory + * - Prepare the reset + * - Reset the cpus + * - Load the reset PSW + */ + sie_expect_validity(&vm); + sie(&vm); + report(uv_validity_check(&vm), "validity, no action"); + + /* Mark the CPU as stopped so we can unshare and reset */ + cc = uv_set_cpu_state(vm.sblk->pv_handle_cpu, PV_CPU_STATE_STP); + report(!cc, "Set cpu stopped"); + + sie_expect_validity(&vm); + sie(&vm); + report(uv_validity_check(&vm), "validity, stopped"); + + /* Unshare all memory */ + cc = uv_cmd_nodata(vm.sblk->pv_handle_config, + UVC_CMD_SET_UNSHARED_ALL, &rc, &rrc); + report(cc == 0 && rc == 1, "Unshare all"); + + sie_expect_validity(&vm); + sie(&vm); + report(uv_validity_check(&vm), "validity, stopped, unshared"); + + /* Prepare the CPU reset */ + cc = uv_cmd_nodata(vm.sblk->pv_handle_config, + UVC_CMD_PREPARE_RESET, &rc, &rrc); + report(cc == 0 && rc == 1, "Prepare reset call"); + + sie_expect_validity(&vm); + sie(&vm); + report(uv_validity_check(&vm), "validity, stopped, unshared, prep reset"); + + /* + * Do the reset on the initiating cpu + * + * Reset clear for subcode 0 + * Reset initial for subcode 1 + */ + if (subcode == 0) { + cc = uv_cmd_nodata(vm.sblk->pv_handle_cpu, + UVC_CMD_CPU_RESET_CLEAR, &rc, &rrc); + report(cc == 0 && rc == 1, "Clear reset cpu"); + } else { + cc = uv_cmd_nodata(vm.sblk->pv_handle_cpu, + UVC_CMD_CPU_RESET_INITIAL, &rc, &rrc); + report(cc == 0 && rc == 1, "Initial reset cpu"); + } + + sie_expect_validity(&vm); + sie(&vm); + report(uv_validity_check(&vm), "validity, stopped, unshared, prep reset, cpu reset"); + + /* Load the PSW from 0x0 */ + cc = uv_set_cpu_state(vm.sblk->pv_handle_cpu, PV_CPU_STATE_OPR_LOAD); + report(!cc, "Set cpu load"); + + /* + * Check if we executed the iaddr of the reset PSW, we should + * see a diagnose 0x9c PV instruction notification. + */ + sie(&vm); + report(pv_icptdata_check_diag(&vm, 0x9c) && + vm.save_area.guest.grs[0] == 42, + "continue after load"); + + uv_destroy_guest(&vm); + report_prefix_pop(); +} + +int main(void) +{ + report_prefix_push("uv-sie"); + if (!uv_guest_requirement_checks()) + goto done; + + snippet_setup_guest(&vm, true); + test_diag_308(0); + test_diag_308(1); + sie_guest_destroy(&vm); + +done: + report_prefix_pop(); + return report_summary(); +} diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index e2d3478e..e08e5c84 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -223,3 +223,7 @@ file = ex.elf file = pv-icptcode.elf smp = 3 extra_params = -m 2200 + +[pv-ipl] +file = pv-ipl.elf +extra_params = -m 2200 From patchwork Fri Apr 21 11:36:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 13219819 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 63995C7618E for ; Fri, 21 Apr 2023 11:39:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231694AbjDULjN (ORCPT ); Fri, 21 Apr 2023 07:39:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231451AbjDULjL (ORCPT ); Fri, 21 Apr 2023 07:39:11 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27570D309; Fri, 21 Apr 2023 04:38:28 -0700 (PDT) Received: from pps.filterd (m0353724.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33LBXPmS023567; Fri, 21 Apr 2023 11:37:29 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=7j7soiS82/jhgiE5I7uOTm0ya5Yp+7Wjlod0EWUQD14=; b=MYGzl3cn0Dese4wzLz1shFZuTnaaVtfRZRKxAIJNxn/ZCQmLIreoVxPFg6Q58JWqY/xf kscG3CnBnkYOwKXjawn/fyQn7DDBV4KGPGjKJ6Xwl/1ZPOqNHrt4eUcQQIxij/wHj4S3 AaN7Ao87YXY2fAi2kLGdfaNwf6ubRkCZSccPIDHdCEEtMVb5m8Lp0Us5jG+PrPUBVmyK 8wsgBEbOIDqp0xr3D/T+NzN+/ufNDb871w/vYL/utKdy2iR9DIAVcRQRFwvKN+ZuF4Cr TWGBn2NGA1nvLwuPlvVlyAd9R3yYmhtfW5Ms244cpRIQiKD6blPHXTtvF6dAWv7mR7z/ Bw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q3scyrtjt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:29 +0000 Received: from m0353724.ppops.net (m0353724.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 33LBYhmi003180; Fri, 21 Apr 2023 11:37:29 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3q3scyrth2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:28 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 33L2bWu1024426; Fri, 21 Apr 2023 11:37:27 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3pykj6m10u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 21 Apr 2023 11:37:27 +0000 Received: from smtpav01.fra02v.mail.ibm.com (smtpav01.fra02v.mail.ibm.com [10.20.54.100]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 33LBbNRO36045110 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 21 Apr 2023 11:37:23 GMT Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BC8E420043; Fri, 21 Apr 2023 11:37:23 +0000 (GMT) Received: from smtpav01.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E4D9F20040; Fri, 21 Apr 2023 11:37:22 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by smtpav01.fra02v.mail.ibm.com (Postfix) with ESMTP; Fri, 21 Apr 2023 11:37:22 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, thuth@redhat.com, nrb@linux.ibm.com, david@redhat.com Subject: [kvm-unit-tests PATCH v3 7/7] s390x: pv-diags: Add the test to unittests.conf Date: Fri, 21 Apr 2023 11:36:47 +0000 Message-Id: <20230421113647.134536-8-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230421113647.134536-1-frankja@linux.ibm.com> References: <20230421113647.134536-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: 3_uHCgkxz-Q8AH3IjZkT09nyI0ad-Q86 X-Proofpoint-ORIG-GUID: RLvpspeWlgQ5M4p3RyXbz0kRQ7m7E3Oe X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-21_04,2023-04-21_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 lowpriorityscore=0 suspectscore=0 clxscore=1015 spamscore=0 priorityscore=1501 malwarescore=0 impostorscore=0 mlxlogscore=999 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304210091 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Better to have it run into a skip than to not run it at all. Signed-off-by: Janosch Frank Reviewed-by: Claudio Imbrenda --- s390x/unittests.cfg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index e08e5c84..d6e7b170 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -227,3 +227,7 @@ extra_params = -m 2200 [pv-ipl] file = pv-ipl.elf extra_params = -m 2200 + +[pv-diags] +file = pv-diags.elf +extra_params = -m 2200