From patchwork Wed May 26 14:55:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12281993 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6B963C47088 for ; Wed, 26 May 2021 14:55:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4CADF613B4 for ; Wed, 26 May 2021 14:55:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235198AbhEZO52 (ORCPT ); Wed, 26 May 2021 10:57:28 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:47674 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235191AbhEZO50 (ORCPT ); Wed, 26 May 2021 10:57:26 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14QEXw24007092; Wed, 26 May 2021 10:55:55 -0400 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=cl2LHhsjhT4G5eJjip9UyOuXIeOYll7NR4pHngnaNXA=; b=C9byNlR+zv/rqMEJup80GP7W6kZvA22/rlhhJgsCUBJpnLoIy8D2LG5rLsYrBXizTKMF j4C5mWvunq/NvhKFHtAvI94mk79AU3mZMyg5a11u9yl3GjV18eFodMRaEWKAEsHqgTpf TVACVwO6Z3FwbSdAYdbznsATa+fDXofZwwR7tqHfsQ4YywCjVUtwLg5eOY19FNkQN2sk PYfaXg2+73bOdxM6vZo+3f3Id8P+1AdmBkin2Vtk/emqHrbWuZ2LE/9bkf7dZblXLTfc D1ApUUL6mt0ws1cLlMkXbQWVdNs4gxh2pcdXfQ6m2Ol/lFRnMqn2zignWN+23Q7BluXc RQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 38spn7mduw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:55:54 -0400 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 14QEXvj0006944; Wed, 26 May 2021 10:55:54 -0400 Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 38spn7mdtx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:55:54 -0400 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 14QErthi013968; Wed, 26 May 2021 14:55:52 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma04ams.nl.ibm.com with ESMTP id 38s1r48mp0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 14:55:52 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 14QEtndD34275782 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 May 2021 14:55:49 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0565BA40C0; Wed, 26 May 2021 14:55:49 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 630C3A408B; Wed, 26 May 2021 14:55:48 +0000 (GMT) Received: from localhost.localdomain.com (unknown [9.145.174.11]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 26 May 2021 14:55:48 +0000 (GMT) From: Janosch Frank To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, david@redhat.com, borntraeger@de.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, thuth@redhat.com Subject: [kvm-unit-tests GIT PULL 1/9] s390x: uv-guest: Add invalid share location test Date: Wed, 26 May 2021 16:55:31 +0200 Message-Id: <20210526145539.52008-2-frankja@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210526145539.52008-1-frankja@linux.ibm.com> References: <20210526145539.52008-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: pkwNxICg_N3Nuezop6cOeCv7w9mAY1Fs X-Proofpoint-ORIG-GUID: awXBzAnNRHecWZwoZ4BEffkNMplHAjv5 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-05-26_09:2021-05-26,2021-05-26 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 suspectscore=0 mlxscore=0 phishscore=0 spamscore=0 impostorscore=0 malwarescore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105260098 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Lets also test sharing unavailable memory. Signed-off-by: Janosch Frank Reviewed-by: Claudio Imbrenda Reviewed-by: Cornelia Huck Reviewed-by: Thomas Huth --- s390x/uv-guest.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c index 99544442..a13669ab 100644 --- a/s390x/uv-guest.c +++ b/s390x/uv-guest.c @@ -15,6 +15,7 @@ #include #include #include +#include static unsigned long page; @@ -99,6 +100,10 @@ static void test_sharing(void) uvcb.header.len = sizeof(uvcb); cc = uv_call(0, (u64)&uvcb); report(cc == 0 && uvcb.header.rc == UVC_RC_EXECUTED, "share"); + uvcb.paddr = get_ram_size() + PAGE_SIZE; + cc = uv_call(0, (u64)&uvcb); + report(cc == 1 && uvcb.header.rc == 0x101, "invalid memory"); + uvcb.paddr = page; report_prefix_pop(); report_prefix_push("unshare"); From patchwork Wed May 26 14:55:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12281995 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 14A09C4708C for ; Wed, 26 May 2021 14:56:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EE55C61355 for ; Wed, 26 May 2021 14:56:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235211AbhEZO5a (ORCPT ); Wed, 26 May 2021 10:57:30 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:58444 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235201AbhEZO51 (ORCPT ); Wed, 26 May 2021 10:57:27 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14QEXvSD007037; Wed, 26 May 2021 10:55:56 -0400 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=hvQqAKGdoxDaeuu751xv8sqOkuqJyaY3G8b4kN54aIg=; b=cw2K1KtCx6zzpYwjsLkSlyLc3JkAImE1eNSRohsVEBXse4B3Ks0eL0C+8NNlZXp5ZroH q3vT+4udgt2DMLpSZMawwVrFfsk4sAxtNz4+lPLrUPrIqOv+e2Qt5+ngCiF7797lDXyL rcw9SUv7yBtyz0cr0PWWssI+yDnVPqBIgoSHvLgJ7K9mclkoNR9KPBIl2qgezbQHxH5R /H9868RzeVJ8yMcyHSc9BYhtuyKxHc5+KEeT7LrvsvitSUksRcVj3rsyKivkGlLKTqov 3EKjDnU6O7VOVfvo9LZgCp2o0eY65QAXdP+4Scc1ff2i9pqWxvzkC3+83r6cF13JTR9/ lA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 38spn7mdvn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:55:56 -0400 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 14QEY3uv007917; Wed, 26 May 2021 10:55:55 -0400 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 38spn7mdu7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:55:55 -0400 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 14QErKxx023965; Wed, 26 May 2021 14:55:52 GMT Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by ppma06ams.nl.ibm.com with ESMTP id 38s1ukgmc1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 14:55:52 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 14QEtnS033620290 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 May 2021 14:55:49 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A0752A40C9; Wed, 26 May 2021 14:55:49 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1C729A40A6; Wed, 26 May 2021 14:55:49 +0000 (GMT) Received: from localhost.localdomain.com (unknown [9.145.174.11]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 26 May 2021 14:55:49 +0000 (GMT) From: Janosch Frank To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, david@redhat.com, borntraeger@de.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, thuth@redhat.com Subject: [kvm-unit-tests GIT PULL 2/9] s390x: Add more Ultravisor command structure definitions Date: Wed, 26 May 2021 16:55:32 +0200 Message-Id: <20210526145539.52008-3-frankja@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210526145539.52008-1-frankja@linux.ibm.com> References: <20210526145539.52008-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: BV92m_j1F6fkYcQXYdKaG5MgLB-Rqwbs X-Proofpoint-ORIG-GUID: gTr_mOmc-OrNkbEJya5ROvroVddKtuqt X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-05-26_09:2021-05-26,2021-05-26 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 suspectscore=0 mlxscore=0 phishscore=0 spamscore=0 impostorscore=0 malwarescore=0 clxscore=1015 priorityscore=1501 lowpriorityscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105260098 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org They are needed in the new UV tests. As we now extend the size of the query struct, we need to set the length in the UV guest query test to a constant instead of using sizeof. Signed-off-by: Janosch Frank Reviewed-by: Claudio Imbrenda Acked-by: Cornelia Huck Acked-by: Thomas Huth --- lib/s390x/asm/uv.h | 148 ++++++++++++++++++++++++++++++++++++++++++++- s390x/uv-guest.c | 3 +- 2 files changed, 149 insertions(+), 2 deletions(-) diff --git a/lib/s390x/asm/uv.h b/lib/s390x/asm/uv.h index 9c491844..11f70a9f 100644 --- a/lib/s390x/asm/uv.h +++ b/lib/s390x/asm/uv.h @@ -17,16 +17,54 @@ #define UVC_RC_INV_STATE 0x0003 #define UVC_RC_INV_LEN 0x0005 #define UVC_RC_NO_RESUME 0x0007 +#define UVC_RC_INV_GHANDLE 0x0020 +#define UVC_RC_INV_CHANDLE 0x0021 #define UVC_CMD_QUI 0x0001 +#define UVC_CMD_INIT_UV 0x000f +#define UVC_CMD_CREATE_SEC_CONF 0x0100 +#define UVC_CMD_DESTROY_SEC_CONF 0x0101 +#define UVC_CMD_CREATE_SEC_CPU 0x0120 +#define UVC_CMD_DESTROY_SEC_CPU 0x0121 +#define UVC_CMD_CONV_TO_SEC_STOR 0x0200 +#define UVC_CMD_CONV_FROM_SEC_STOR 0x0201 +#define UVC_CMD_SET_SEC_CONF_PARAMS 0x0300 +#define UVC_CMD_UNPACK_IMG 0x0301 +#define UVC_CMD_VERIFY_IMG 0x0302 +#define UVC_CMD_CPU_RESET 0x0310 +#define UVC_CMD_CPU_RESET_INITIAL 0x0311 +#define UVC_CMD_PERF_CONF_CLEAR_RESET 0x0320 +#define UVC_CMD_CPU_RESET_CLEAR 0x0321 +#define UVC_CMD_CPU_SET_STATE 0x0330 +#define UVC_CMD_SET_UNSHARED_ALL 0x0340 +#define UVC_CMD_PIN_PAGE_SHARED 0x0341 +#define UVC_CMD_UNPIN_PAGE_SHARED 0x0342 #define UVC_CMD_SET_SHARED_ACCESS 0x1000 #define UVC_CMD_REMOVE_SHARED_ACCESS 0x1001 /* Bits in installed uv calls */ enum uv_cmds_inst { BIT_UVC_CMD_QUI = 0, + BIT_UVC_CMD_INIT_UV = 1, + BIT_UVC_CMD_CREATE_SEC_CONF = 2, + BIT_UVC_CMD_DESTROY_SEC_CONF = 3, + BIT_UVC_CMD_CREATE_SEC_CPU = 4, + BIT_UVC_CMD_DESTROY_SEC_CPU = 5, + BIT_UVC_CMD_CONV_TO_SEC_STOR = 6, + BIT_UVC_CMD_CONV_FROM_SEC_STOR = 7, BIT_UVC_CMD_SET_SHARED_ACCESS = 8, BIT_UVC_CMD_REMOVE_SHARED_ACCESS = 9, + BIT_UVC_CMD_SET_SEC_PARMS = 11, + BIT_UVC_CMD_UNPACK_IMG = 13, + BIT_UVC_CMD_VERIFY_IMG = 14, + BIT_UVC_CMD_CPU_RESET = 15, + BIT_UVC_CMD_CPU_RESET_INITIAL = 16, + BIT_UVC_CMD_CPU_SET_STATE = 17, + BIT_UVC_CMD_PREPARE_CLEAR_RESET = 18, + BIT_UVC_CMD_CPU_PERFORM_CLEAR_RESET = 19, + BIT_UVC_CMD_UNSHARE_ALL = 20, + BIT_UVC_CMD_PIN_PAGE_SHARED = 21, + BIT_UVC_CMD_UNPIN_PAGE_SHARED = 22, }; struct uv_cb_header { @@ -36,13 +74,81 @@ struct uv_cb_header { u16 rrc; /* Return Reason Code */ } __attribute__((packed)) __attribute__((aligned(8))); +struct uv_cb_init { + struct uv_cb_header header; + u64 reserved08[2]; + u64 stor_origin; + u64 stor_len; + u64 reserved28[4]; + +} __attribute__((packed)) __attribute__((aligned(8))); + struct uv_cb_qui { struct uv_cb_header header; u64 reserved08; u64 inst_calls_list[4]; - u64 reserved30[15]; + u64 reserved30[2]; + u64 uv_base_stor_len; + u64 reserved48; + u64 conf_base_phys_stor_len; + u64 conf_base_virt_stor_len; + u64 conf_virt_var_stor_len; + u64 cpu_stor_len; + u32 reserved70[3]; + u32 max_num_sec_conf; + u64 max_guest_stor_addr; + u8 reserved88[158 - 136]; + u16 max_guest_cpus; + u8 reserveda0[200 - 160]; +} __attribute__((packed)) __attribute__((aligned(8))); + +struct uv_cb_cgc { + struct uv_cb_header header; + u64 reserved08[2]; + u64 guest_handle; + u64 conf_base_stor_origin; + u64 conf_var_stor_origin; + u64 reserved30; + u64 guest_stor_origin; + u64 guest_stor_len; + u64 guest_sca; + u64 guest_asce; + u64 reserved60[5]; } __attribute__((packed)) __attribute__((aligned(8))); +struct uv_cb_csc { + struct uv_cb_header header; + u64 reserved08[2]; + u64 cpu_handle; + u64 guest_handle; + u64 stor_origin; + u8 reserved30[6]; + u16 num; + u64 state_origin; + u64 reserved[4]; +} __attribute__((packed)) __attribute__((aligned(8))); + +struct uv_cb_unp { + struct uv_cb_header header; + u64 reserved08[2]; + u64 guest_handle; + u64 gaddr; + u64 tweak[2]; + u64 reserved38[3]; +} __attribute__((packed)) __attribute__((aligned(8))); + +/* + * A common UV call struct for the following calls: + * Destroy cpu/config + * Verify + */ +struct uv_cb_nodata { + struct uv_cb_header header; + u64 reserved08[2]; + u64 handle; + u64 reserved20[4]; +} __attribute__((packed)) __attribute__((aligned(8))); + struct uv_cb_share { struct uv_cb_header header; u64 reserved08[3]; @@ -50,6 +156,32 @@ struct uv_cb_share { u64 reserved28; } __attribute__((packed)) __attribute__((aligned(8))); +/* Convert to Secure */ +struct uv_cb_cts { + struct uv_cb_header header; + u64 reserved08[2]; + u64 guest_handle; + u64 gaddr; +} __attribute__((packed)) __attribute__((aligned(8))); + +/* Convert from Secure / Pin Page Shared */ +struct uv_cb_cfs { + struct uv_cb_header header; + u64 reserved08[2]; + u64 paddr; +} __attribute__((packed)) __attribute__((aligned(8))); + +/* Set Secure Config Parameter */ +struct uv_cb_ssc { + struct uv_cb_header header; + u64 reserved08[2]; + u64 guest_handle; + u64 sec_header_origin; + u32 sec_header_len; + u32 reserved2c; + u64 reserved30[4]; +} __attribute__((packed)) __attribute__((aligned(8))); + static inline int uv_call_once(unsigned long r1, unsigned long r2) { int cc; @@ -118,4 +250,18 @@ static inline int uv_remove_shared(unsigned long addr) return share(addr, UVC_CMD_REMOVE_SHARED_ACCESS); } +struct uv_cb_cpu_set_state { + struct uv_cb_header header; + u64 reserved08[2]; + u64 cpu_handle; + u8 reserved20[7]; + u8 state; + u64 reserved28[5]; +}; + +#define PV_CPU_STATE_OPR 1 +#define PV_CPU_STATE_STP 2 +#define PV_CPU_STATE_CHKSTP 3 +#define PV_CPU_STATE_OPR_LOAD 5 + #endif diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c index a13669ab..393d7f5c 100644 --- a/s390x/uv-guest.c +++ b/s390x/uv-guest.c @@ -59,7 +59,8 @@ static void test_query(void) { struct uv_cb_qui uvcb = { .header.cmd = UVC_CMD_QUI, - .header.len = sizeof(uvcb) - 8, + /* A dword below the minimum length */ + .header.len = 0xa0, }; int cc; From patchwork Wed May 26 14:55:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12281997 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0F5BC47088 for ; Wed, 26 May 2021 14:56:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AB0E8613B4 for ; Wed, 26 May 2021 14:56:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235242AbhEZO5c (ORCPT ); Wed, 26 May 2021 10:57:32 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:2538 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235156AbhEZO53 (ORCPT ); Wed, 26 May 2021 10:57:29 -0400 Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14QEWbvZ031971; Wed, 26 May 2021 10:55:57 -0400 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=+fiFLkvJW429bUyNlMqzhnk/9Bx1NXP9vx3Q2lpsP54=; b=IEY4P2QS3gM8McRyNQdx+6ylvG/5xYzLJGvVgduF/KLdC6SfNezOIO0G1keU6Rx6l16c rMvFTQoYfybuAuY2iiGzT2Or8DfdSH6ps0OdL+iKfM77Tl7DyIw8QCC/Ciamv9ndDqwt m81OZUhHgYuByF0tJ0WCoA797zw1oFVHtv+f1+o+7jXNM7zpWadbgJBUyv2ov/zkawxn SscPe5EmINMnO/E2ihQPtA6dQiDYFOOTNki8xwlRbkJyBnbm7tS74+IrgHLOfbjTETJv 3IkNONXezqHgw3kFrnTLGvvxu7+L/QGCgUrXgY5XVkdd9w/nBq6FaRUzuilktB9A7sUQ Bw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 38sqanjk11-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:55:57 -0400 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 14QEXoT5037153; Wed, 26 May 2021 10:55:56 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 38sqanjk01-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:55:56 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 14QEqXpp003766; Wed, 26 May 2021 14:55:54 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma03fra.de.ibm.com with ESMTP id 38s1ssrbnh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 14:55:54 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 14QEtpGd18940394 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 May 2021 14:55:51 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 51FD3A407C; Wed, 26 May 2021 14:55:50 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C1C2BA40A6; Wed, 26 May 2021 14:55:49 +0000 (GMT) Received: from localhost.localdomain.com (unknown [9.145.174.11]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 26 May 2021 14:55:49 +0000 (GMT) From: Janosch Frank To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, david@redhat.com, borntraeger@de.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, thuth@redhat.com Subject: [kvm-unit-tests GIT PULL 3/9] s390x: uv: Add UV lib Date: Wed, 26 May 2021 16:55:33 +0200 Message-Id: <20210526145539.52008-4-frankja@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210526145539.52008-1-frankja@linux.ibm.com> References: <20210526145539.52008-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: LJ1A84O7zaxH6vhZJl6Wbxj5ZyxTAXLY X-Proofpoint-ORIG-GUID: xTMSMSRVO0clrL2feQhmPx2whh8B2q0p X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-05-26_09:2021-05-26,2021-05-26 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 priorityscore=1501 phishscore=0 malwarescore=0 suspectscore=0 lowpriorityscore=0 adultscore=0 impostorscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105260098 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Lets add a UV library to make checking the UV feature bit easier. In the future this library file can take care of handling UV initialization and UV guest creation. Signed-off-by: Janosch Frank Reviewed-by: Claudio Imbrenda Reviewed-by: Cornelia Huck Acked-by: Thomas Huth --- lib/s390x/asm/uv.h | 4 ++-- lib/s390x/io.c | 2 ++ lib/s390x/uv.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ lib/s390x/uv.h | 10 ++++++++++ s390x/Makefile | 1 + 5 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 lib/s390x/uv.c create mode 100644 lib/s390x/uv.h diff --git a/lib/s390x/asm/uv.h b/lib/s390x/asm/uv.h index 11f70a9f..b22cbaa8 100644 --- a/lib/s390x/asm/uv.h +++ b/lib/s390x/asm/uv.h @@ -9,8 +9,8 @@ * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2. */ -#ifndef UV_H -#define UV_H +#ifndef ASM_S390X_UV_H +#define ASM_S390X_UV_H #define UVC_RC_EXECUTED 0x0001 #define UVC_RC_INV_CMD 0x0002 diff --git a/lib/s390x/io.c b/lib/s390x/io.c index ef9f59e3..a4f1b113 100644 --- a/lib/s390x/io.c +++ b/lib/s390x/io.c @@ -14,6 +14,7 @@ #include #include #include "sclp.h" +#include "uv.h" #include "smp.h" extern char ipl_args[]; @@ -38,6 +39,7 @@ void setup(void) sclp_facilities_setup(); sclp_console_setup(); sclp_memory_setup(); + uv_setup(); smp_setup(); } diff --git a/lib/s390x/uv.c b/lib/s390x/uv.c new file mode 100644 index 00000000..0d8c141c --- /dev/null +++ b/lib/s390x/uv.c @@ -0,0 +1,45 @@ +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +static struct uv_cb_qui uvcb_qui = { + .header.cmd = UVC_CMD_QUI, + .header.len = sizeof(uvcb_qui), +}; + +bool uv_os_is_guest(void) +{ + return test_facility(158) && + uv_query_test_call(BIT_UVC_CMD_SET_SHARED_ACCESS) && + uv_query_test_call(BIT_UVC_CMD_REMOVE_SHARED_ACCESS); +} + +bool uv_os_is_host(void) +{ + return test_facility(158) && uv_query_test_call(BIT_UVC_CMD_INIT_UV); +} + +bool uv_query_test_call(unsigned int nr) +{ + /* Query needs to be called first */ + assert(uvcb_qui.header.rc); + assert(nr < BITS_PER_LONG * ARRAY_SIZE(uvcb_qui.inst_calls_list)); + + return test_bit_inv(nr, uvcb_qui.inst_calls_list); +} + +int uv_setup(void) +{ + if (!test_facility(158)) + return 0; + + assert(!uv_call(0, (u64)&uvcb_qui)); + return 1; +} diff --git a/lib/s390x/uv.h b/lib/s390x/uv.h new file mode 100644 index 00000000..42608a96 --- /dev/null +++ b/lib/s390x/uv.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef UV_H +#define UV_H + +bool uv_os_is_guest(void); +bool uv_os_is_host(void); +bool uv_query_test_call(unsigned int nr); +int uv_setup(void); + +#endif /* UV_H */ diff --git a/s390x/Makefile b/s390x/Makefile index b92de9c5..bbf177fa 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -67,6 +67,7 @@ cflatobjs += lib/s390x/vm.o cflatobjs += lib/s390x/css_dump.o cflatobjs += lib/s390x/css_lib.o cflatobjs += lib/s390x/malloc_io.o +cflatobjs += lib/s390x/uv.o OBJDIRS += lib/s390x From patchwork Wed May 26 14:55:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12282003 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EDCADC47089 for ; Wed, 26 May 2021 14:56:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CFA9A613B0 for ; Wed, 26 May 2021 14:56:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235255AbhEZO5l (ORCPT ); Wed, 26 May 2021 10:57:41 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:10580 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235182AbhEZO53 (ORCPT ); Wed, 26 May 2021 10:57:29 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14QEiNU1058385; Wed, 26 May 2021 10:55:58 -0400 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=qdPGVyRnVabvWWc/ZVmFVrMfcFHbAjPiuJZTaWiVdRs=; b=L8BMMETNGCjCQVnejcerV5N0rsZwpjuH57kr3nZ00dq4IYqqTcWMywcAGaD23TicAdDc IkaluQQM6rUB8FXDchn/Wxf2HwwyrU6WQpVQ/x/WylOTNHYe7l+f8A3mHcjE78AqtkkC 6DfxQ9PhOlA185EWKkHaVEf8KNEbgBNl/Zy2ZyNkOeoon5KVb3qiC7kBXdQnT1LoBK4W IVzb7a4MNC0j9u4+A5IRiNtGpNdKycLIjisuk0lRgnA2d/fuAFmiKCEgBSm2ykZFLJ0Y Hbbb+kQb/8RNLXp2eJa1K1x2XEhW9pjlUlGCoMixbHjb0eGPZNGMP3hvqsaIgHnLHZm7 ug== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 38srbu8cah-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:55:57 -0400 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 14QEiSoP058603; Wed, 26 May 2021 10:55:57 -0400 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 38srbu8c9j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:55:57 -0400 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 14QErN8d024002; Wed, 26 May 2021 14:55:55 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma06ams.nl.ibm.com with ESMTP id 38s1ukgmcf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 14:55:55 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 14QEtqti20578796 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 May 2021 14:55:52 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 056ACA40A5; Wed, 26 May 2021 14:55:51 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 72CEEA40A6; Wed, 26 May 2021 14:55:50 +0000 (GMT) Received: from localhost.localdomain.com (unknown [9.145.174.11]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 26 May 2021 14:55:50 +0000 (GMT) From: Janosch Frank To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, david@redhat.com, borntraeger@de.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, thuth@redhat.com Subject: [kvm-unit-tests GIT PULL 4/9] s390x: Test for share/unshare call support before using them Date: Wed, 26 May 2021 16:55:34 +0200 Message-Id: <20210526145539.52008-5-frankja@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210526145539.52008-1-frankja@linux.ibm.com> References: <20210526145539.52008-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: lEvGRMCD7ArtcrWgXNafgAwJQLbCN3nq X-Proofpoint-GUID: n4vidrZ2295-Nd9equJZFfXkDRfjh2ab X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-05-26_09:2021-05-26,2021-05-26 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 lowpriorityscore=0 priorityscore=1501 adultscore=0 impostorscore=0 malwarescore=0 bulkscore=0 suspectscore=0 phishscore=0 clxscore=1015 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105260098 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Testing for facility only means the UV Call facility is available. The UV will only indicate the share/unshare calls for a protected guest 2, so lets also check that. Signed-off-by: Janosch Frank Reviewed-by: Claudio Imbrenda Reviewed-by: Cornelia Huck Acked-by: Thomas Huth --- lib/s390x/malloc_io.c | 5 +++-- s390x/uv-guest.c | 6 ++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/s390x/malloc_io.c b/lib/s390x/malloc_io.c index 1dcf1691..78582eac 100644 --- a/lib/s390x/malloc_io.c +++ b/lib/s390x/malloc_io.c @@ -19,6 +19,7 @@ #include #include #include +#include static int share_pages(void *p, int count) { @@ -47,7 +48,7 @@ void *alloc_io_mem(int size, int flags) assert(size); p = alloc_pages_flags(order, AREA_DMA31 | flags); - if (!p || !test_facility(158)) + if (!p || !uv_os_is_guest()) return p; n = share_pages(p, 1 << order); @@ -65,7 +66,7 @@ void free_io_mem(void *p, int size) assert(IS_ALIGNED((uintptr_t)p, PAGE_SIZE)); - if (test_facility(158)) + if (uv_os_is_guest()) unshare_pages(p, 1 << order); free_pages(p); } diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c index 393d7f5c..e99029a7 100644 --- a/s390x/uv-guest.c +++ b/s390x/uv-guest.c @@ -16,6 +16,7 @@ #include #include #include +#include static unsigned long page; @@ -142,6 +143,11 @@ int main(void) goto done; } + if (!uv_os_is_guest()) { + report_skip("Not a protected guest"); + goto done; + } + page = (unsigned long)alloc_page(); test_priv(); test_invalid(); From patchwork Wed May 26 14:55:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12281999 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7423BC47089 for ; Wed, 26 May 2021 14:56:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 56537613B4 for ; Wed, 26 May 2021 14:56:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235268AbhEZO5g (ORCPT ); Wed, 26 May 2021 10:57:36 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:11820 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235222AbhEZO53 (ORCPT ); Wed, 26 May 2021 10:57:29 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14QEXNHO188077; Wed, 26 May 2021 10:55:57 -0400 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=abs9D8u9P+BTHrLcPLWIoxibEzDdviPPQH3pPPDv0fY=; b=H6cb4TX6UM9xGGIm3eP0cdaDGOG8tehMqoHeYC7Y/zqtoZXRVPjBfQGFo/6LgGXWatQ2 zJMvGSuwtCNhg3vLMrxsM28wC6kbw/suSrEriekIEijUtBrhEIrWtv2gAWd/yU22TZ7q 1ek2Eykv1HbJ63oyqq0LgFgcB4n80yGP3EsyUh9h0XIKEt/UIAqPRwel2zRI61zYi4cP QFjz/6Ee5H7sc2p22nY0ACng2Vmc/CNyhHQhLph6uqronmCDt1EiDQc6vEUKseHtwwqA A6bGlI07UigncnyFcHSXXQ1GIy/OP7p09wgzDOXTKuBal/CLYItdz7t8Rck3aQQHPqkD 7Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 38sr31h1ye-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:55:57 -0400 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 14QEXZd0189690; Wed, 26 May 2021 10:55:57 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 38sr31h1xu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:55:57 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 14QEqXpq003766; Wed, 26 May 2021 14:55:55 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma03fra.de.ibm.com with ESMTP id 38s1ssrbnn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 14:55:55 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 14QEtqUG20775340 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 May 2021 14:55:52 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A8FD0A40B0; Wed, 26 May 2021 14:55:51 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 26C07A40C1; Wed, 26 May 2021 14:55:51 +0000 (GMT) Received: from localhost.localdomain.com (unknown [9.145.174.11]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 26 May 2021 14:55:51 +0000 (GMT) From: Janosch Frank To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, david@redhat.com, borntraeger@de.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, thuth@redhat.com Subject: [kvm-unit-tests GIT PULL 5/9] s390x: uv-guest: Test invalid commands Date: Wed, 26 May 2021 16:55:35 +0200 Message-Id: <20210526145539.52008-6-frankja@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210526145539.52008-1-frankja@linux.ibm.com> References: <20210526145539.52008-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: UeiCY4uC9ipcu6CZxvmt-mv2sKGgBzqX X-Proofpoint-ORIG-GUID: ofLf_Q5eJ3tIDMVImAK-JyFCsdNXDwn5 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-05-26_09:2021-05-26,2021-05-26 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 impostorscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 mlxscore=0 malwarescore=0 phishscore=0 clxscore=1015 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105260098 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Lets check if the UV calls that should not be available in a protected guest 2 are actually not available. Also lets check if they are falsely indicated to be available. Signed-off-by: Janosch Frank Reviewed-by: Cornelia Huck Reviewed-by: Claudio Imbrenda Acked-by: Thomas Huth --- s390x/uv-guest.c | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c index e99029a7..f05ae4c3 100644 --- a/s390x/uv-guest.c +++ b/s390x/uv-guest.c @@ -121,16 +121,48 @@ static void test_sharing(void) report_prefix_pop(); } +static struct { + const char *name; + uint16_t cmd; + uint16_t len; + int call_bit; +} invalid_cmds[] = { + { "bogus", 0x4242, sizeof(struct uv_cb_header), -1 }, + { "init", UVC_CMD_INIT_UV, sizeof(struct uv_cb_init), BIT_UVC_CMD_INIT_UV }, + { "create conf", UVC_CMD_CREATE_SEC_CONF, sizeof(struct uv_cb_cgc), BIT_UVC_CMD_CREATE_SEC_CONF }, + { "destroy conf", UVC_CMD_DESTROY_SEC_CONF, sizeof(struct uv_cb_nodata), BIT_UVC_CMD_DESTROY_SEC_CONF }, + { "create cpu", UVC_CMD_CREATE_SEC_CPU, sizeof(struct uv_cb_csc), BIT_UVC_CMD_CREATE_SEC_CPU }, + { "destroy cpu", UVC_CMD_DESTROY_SEC_CPU, sizeof(struct uv_cb_nodata), BIT_UVC_CMD_DESTROY_SEC_CPU }, + { "conv to", UVC_CMD_CONV_TO_SEC_STOR, sizeof(struct uv_cb_cts), BIT_UVC_CMD_CONV_TO_SEC_STOR }, + { "conv from", UVC_CMD_CONV_FROM_SEC_STOR, sizeof(struct uv_cb_cfs), BIT_UVC_CMD_CONV_FROM_SEC_STOR }, + { "set sec conf", UVC_CMD_SET_SEC_CONF_PARAMS, sizeof(struct uv_cb_ssc), BIT_UVC_CMD_SET_SEC_PARMS }, + { "unpack", UVC_CMD_UNPACK_IMG, sizeof(struct uv_cb_unp), BIT_UVC_CMD_UNPACK_IMG }, + { "verify", UVC_CMD_VERIFY_IMG, sizeof(struct uv_cb_nodata), BIT_UVC_CMD_VERIFY_IMG }, + { "cpu reset", UVC_CMD_CPU_RESET, sizeof(struct uv_cb_nodata), BIT_UVC_CMD_CPU_RESET }, + { "cpu initial reset", UVC_CMD_CPU_RESET_INITIAL, sizeof(struct uv_cb_nodata), BIT_UVC_CMD_CPU_RESET_INITIAL }, + { "conf clear reset", UVC_CMD_PERF_CONF_CLEAR_RESET, sizeof(struct uv_cb_nodata), BIT_UVC_CMD_PREPARE_CLEAR_RESET }, + { "cpu clear reset", UVC_CMD_CPU_RESET_CLEAR, sizeof(struct uv_cb_nodata), BIT_UVC_CMD_CPU_PERFORM_CLEAR_RESET }, + { "cpu set state", UVC_CMD_CPU_SET_STATE, sizeof(struct uv_cb_cpu_set_state), BIT_UVC_CMD_CPU_SET_STATE }, + { "pin shared", UVC_CMD_PIN_PAGE_SHARED, sizeof(struct uv_cb_cfs), BIT_UVC_CMD_PIN_PAGE_SHARED }, + { "unpin shared", UVC_CMD_UNPIN_PAGE_SHARED, sizeof(struct uv_cb_cts), BIT_UVC_CMD_UNPIN_PAGE_SHARED }, + { NULL, 0, 0 }, +}; + static void test_invalid(void) { - struct uv_cb_header uvcb = { - .len = 16, - .cmd = 0x4242, - }; - int cc; + struct uv_cb_header *hdr = (void *)page; + int cc, i; - cc = uv_call(0, (u64)&uvcb); - report(cc == 1 && uvcb.rc == UVC_RC_INV_CMD, "invalid command"); + report_prefix_push("invalid"); + for (i = 0; invalid_cmds[i].name; i++) { + hdr->cmd = invalid_cmds[i].cmd; + hdr->len = invalid_cmds[i].len; + cc = uv_call(0, (u64)hdr); + report(cc == 1 && hdr->rc == UVC_RC_INV_CMD && + (invalid_cmds[i].call_bit == -1 || !uv_query_test_call(invalid_cmds[i].call_bit)), + "%s", invalid_cmds[i].name); + } + report_prefix_pop(); } int main(void) From patchwork Wed May 26 14:55:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12282011 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D325FC47082 for ; Wed, 26 May 2021 14:56:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B3FF8613B0 for ; Wed, 26 May 2021 14:56:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235306AbhEZO5s (ORCPT ); Wed, 26 May 2021 10:57:48 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:45626 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235253AbhEZO5d (ORCPT ); Wed, 26 May 2021 10:57:33 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14QEY8RP155223; Wed, 26 May 2021 10:56:02 -0400 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=l+ddbzG/ccztUOPc4L6VjDYuuFFYG1C4+c9IFVZGRsU=; b=rM2BgcvvP8BTLtmhW2B+QPte7xbgMDKlpSVyalreLQRxLplkh8tZ0IzFxiiQQLHo3O+q Z+asXAL75S08gikYzx8MJyT7mjMxXb52/swO9WiPpgvWuJquyY5i4iHTJc1JayxEYaHy 73ACTj57mJxFyicMw5drcII48hTEfQQN7O0wU53DoE5uRmPjhmqVrqF3I91NfjQOdYnX Y4n/Xs2zH+yDJ1hUYsagnjOwouFIO30dE1dQWJj5cbwEmImKtVkXcPYGBgJ+gpgVYNW2 BALXRBPcw3HgPoRvEFb8YpvV0ejeawZlXKcJUEKRtWX7qUyKiF0M4+9OI3/V2z5Y9Uuo FA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 38spv8kqrm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:56:01 -0400 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 14QEaRp2167973; Wed, 26 May 2021 10:56:01 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 38spv8kqqr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:56:01 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 14QEr9cl004266; Wed, 26 May 2021 14:55:58 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma03ams.nl.ibm.com with ESMTP id 38sba2rd2f-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 14:55:58 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 14QEttqP30671310 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 May 2021 14:55:55 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6AB6BA40D4; Wed, 26 May 2021 14:55:52 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C9F6FA40BA; Wed, 26 May 2021 14:55:51 +0000 (GMT) Received: from localhost.localdomain.com (unknown [9.145.174.11]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 26 May 2021 14:55:51 +0000 (GMT) From: Janosch Frank To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, david@redhat.com, borntraeger@de.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, thuth@redhat.com Subject: [kvm-unit-tests GIT PULL 6/9] s390x: Add UV host test Date: Wed, 26 May 2021 16:55:36 +0200 Message-Id: <20210526145539.52008-7-frankja@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210526145539.52008-1-frankja@linux.ibm.com> References: <20210526145539.52008-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: NZRSt6ANCYRFoR9DLs-VYkqwGKXDmZR2 X-Proofpoint-ORIG-GUID: CZ0EuDttqEj72g4YKYsBTbf17g_Gpupu X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-05-26_09:2021-05-26,2021-05-26 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxlogscore=999 suspectscore=0 bulkscore=0 mlxscore=0 phishscore=0 lowpriorityscore=0 spamscore=0 priorityscore=1501 malwarescore=0 impostorscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105260098 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Lets also test the UV host interfaces. Signed-off-by: Janosch Frank Reviewed-by: Claudio Imbrenda Acked-by: Cornelia Huck Acked-by: Thomas Huth --- s390x/Makefile | 1 + s390x/uv-host.c | 480 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 481 insertions(+) create mode 100644 s390x/uv-host.c diff --git a/s390x/Makefile b/s390x/Makefile index bbf177fa..8de926ab 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -21,6 +21,7 @@ tests += $(TEST_DIR)/css.elf tests += $(TEST_DIR)/uv-guest.elf tests += $(TEST_DIR)/sie.elf tests += $(TEST_DIR)/mvpg.elf +tests += $(TEST_DIR)/uv-host.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) ifneq ($(HOST_KEY_DOCUMENT),) diff --git a/s390x/uv-host.c b/s390x/uv-host.c new file mode 100644 index 00000000..49c66f17 --- /dev/null +++ b/s390x/uv-host.c @@ -0,0 +1,480 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Guest Ultravisor Call tests + * + * Copyright (c) 2021 IBM Corp + * + * Authors: + * Janosch Frank + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static struct uv_cb_qui uvcb_qui; +static struct uv_cb_init uvcb_init; +static struct uv_cb_cgc uvcb_cgc; +static struct uv_cb_csc uvcb_csc; + +extern int diag308_load_reset(u64 code); + +struct cmd_list{ + const char *name; + uint16_t cmd; + uint16_t len; + int call_bit; +}; + +static void cpu_loop(void) +{ + for (;;) {} +} + +static struct cmd_list cmds[] = { + { "init", UVC_CMD_INIT_UV, sizeof(struct uv_cb_init), BIT_UVC_CMD_INIT_UV }, + { "create conf", UVC_CMD_CREATE_SEC_CONF, sizeof(struct uv_cb_cgc), BIT_UVC_CMD_CREATE_SEC_CONF }, + { "destroy conf", UVC_CMD_DESTROY_SEC_CONF, sizeof(struct uv_cb_nodata), BIT_UVC_CMD_DESTROY_SEC_CONF }, + { "create cpu", UVC_CMD_CREATE_SEC_CPU, sizeof(struct uv_cb_csc), BIT_UVC_CMD_CREATE_SEC_CPU }, + { "destroy cpu", UVC_CMD_DESTROY_SEC_CPU, sizeof(struct uv_cb_nodata), BIT_UVC_CMD_DESTROY_SEC_CPU }, + { "conv to", UVC_CMD_CONV_TO_SEC_STOR, sizeof(struct uv_cb_cts), BIT_UVC_CMD_CONV_TO_SEC_STOR }, + { "conv from", UVC_CMD_CONV_FROM_SEC_STOR, sizeof(struct uv_cb_cfs), BIT_UVC_CMD_CONV_FROM_SEC_STOR }, + { "set sec conf", UVC_CMD_SET_SEC_CONF_PARAMS, sizeof(struct uv_cb_ssc), BIT_UVC_CMD_SET_SEC_PARMS }, + { "unpack", UVC_CMD_UNPACK_IMG, sizeof(struct uv_cb_unp), BIT_UVC_CMD_UNPACK_IMG }, + { "verify", UVC_CMD_VERIFY_IMG, sizeof(struct uv_cb_nodata), BIT_UVC_CMD_VERIFY_IMG }, + { "cpu reset", UVC_CMD_CPU_RESET, sizeof(struct uv_cb_nodata), BIT_UVC_CMD_CPU_RESET }, + { "cpu initial reset", UVC_CMD_CPU_RESET_INITIAL, sizeof(struct uv_cb_nodata), BIT_UVC_CMD_CPU_RESET_INITIAL }, + { "conf clear reset", UVC_CMD_PERF_CONF_CLEAR_RESET, sizeof(struct uv_cb_nodata), BIT_UVC_CMD_PREPARE_CLEAR_RESET }, + { "cpu clear reset", UVC_CMD_CPU_RESET_CLEAR, sizeof(struct uv_cb_nodata), BIT_UVC_CMD_CPU_PERFORM_CLEAR_RESET }, + { "cpu set state", UVC_CMD_CPU_SET_STATE, sizeof(struct uv_cb_cpu_set_state), BIT_UVC_CMD_CPU_SET_STATE }, + { "pin shared", UVC_CMD_PIN_PAGE_SHARED, sizeof(struct uv_cb_cfs), BIT_UVC_CMD_PIN_PAGE_SHARED }, + { "unpin shared", UVC_CMD_UNPIN_PAGE_SHARED, sizeof(struct uv_cb_cts), BIT_UVC_CMD_UNPIN_PAGE_SHARED }, + { NULL, 0, 0 }, +}; + +static void test_priv(void) +{ + struct uv_cb_header uvcb = {}; + uint16_t pgm; + int i; + + report_prefix_push("privileged"); + for (i = 0; cmds[i].name; i++) { + expect_pgm_int(); + uvcb.cmd = cmds[i].cmd; + uvcb.len = cmds[i].len; + enter_pstate(); + uv_call(0, (uint64_t)&uvcb); + pgm = clear_pgm_int(); + report(pgm == PGM_INT_CODE_PRIVILEGED_OPERATION, "%s", cmds[i].name); + } + report_prefix_pop(); +} + +static void test_config_destroy(void) +{ + int rc; + struct uv_cb_nodata uvcb = { + .header.cmd = UVC_CMD_DESTROY_SEC_CONF, + .header.len = sizeof(uvcb), + .handle = uvcb_cgc.guest_handle, + }; + + report_prefix_push("dsc"); + uvcb.header.len -= 8; + rc = uv_call(0, (uint64_t)&uvcb); + report(rc == 1 && uvcb.header.rc == UVC_RC_INV_LEN, + "hdr invalid length"); + uvcb.header.len += 8; + + uvcb.handle += 1; + rc = uv_call(0, (uint64_t)&uvcb); + report(rc == 1 && uvcb.header.rc == UVC_RC_INV_GHANDLE, "invalid handle"); + uvcb.handle -= 1; + + rc = uv_call(0, (uint64_t)&uvcb); + report(rc == 0 && uvcb.header.rc == UVC_RC_EXECUTED, "success"); + report_prefix_pop(); +} + +static void test_cpu_destroy(void) +{ + int rc; + struct uv_cb_nodata uvcb = { + .header.len = sizeof(uvcb), + .header.cmd = UVC_CMD_DESTROY_SEC_CPU, + .handle = uvcb_csc.cpu_handle, + }; + + report_prefix_push("dcpu"); + + uvcb.header.len -= 8; + rc = uv_call(0, (uint64_t)&uvcb); + report(rc == 1 && uvcb.header.rc == UVC_RC_INV_LEN, + "hdr invalid length"); + uvcb.header.len += 8; + + uvcb.handle += 1; + rc = uv_call(0, (uint64_t)&uvcb); + report(rc == 1 && uvcb.header.rc == UVC_RC_INV_CHANDLE, "invalid handle"); + uvcb.handle -= 1; + + rc = uv_call(0, (uint64_t)&uvcb); + report(rc == 0 && uvcb.header.rc == UVC_RC_EXECUTED, "success"); + + report_prefix_pop(); +} + +static void test_cpu_create(void) +{ + int rc; + unsigned long tmp; + + report_prefix_push("csc"); + uvcb_csc.header.len = sizeof(uvcb_csc); + uvcb_csc.header.cmd = UVC_CMD_CREATE_SEC_CPU; + uvcb_csc.guest_handle = uvcb_cgc.guest_handle; + uvcb_csc.stor_origin = (unsigned long)memalign(PAGE_SIZE, uvcb_qui.cpu_stor_len); + uvcb_csc.state_origin = (unsigned long)memalign(PAGE_SIZE, PAGE_SIZE); + + uvcb_csc.header.len -= 8; + rc = uv_call(0, (uint64_t)&uvcb_csc); + report(uvcb_csc.header.rc == UVC_RC_INV_LEN && rc == 1 && + !uvcb_csc.cpu_handle, "hdr invalid length"); + uvcb_csc.header.len += 8; + + uvcb_csc.guest_handle += 1; + rc = uv_call(0, (uint64_t)&uvcb_csc); + report(uvcb_csc.header.rc == UVC_RC_INV_GHANDLE && rc == 1, + "invalid guest handle"); + uvcb_csc.guest_handle -= 1; + + uvcb_csc.num = uvcb_qui.max_guest_cpus + 1; + rc = uv_call(0, (uint64_t)&uvcb_csc); + report(uvcb_csc.header.rc == 0x103 && rc == 1, + "invalid cpu #"); + uvcb_csc.num = 0; + + tmp = uvcb_csc.stor_origin; + uvcb_csc.stor_origin = get_max_ram_size() + PAGE_SIZE; + rc = uv_call(0, (uint64_t)&uvcb_csc); + report(uvcb_csc.header.rc == 0x105 && rc == 1, + "cpu stor inaccessible"); + uvcb_csc.stor_origin = tmp; + + tmp = uvcb_csc.stor_origin; + uvcb_csc.stor_origin = 0; + rc = uv_call(0, (uint64_t)&uvcb_csc); + report(uvcb_csc.header.rc == 0x106 && rc == 1, + "cpu stor in lowcore"); + uvcb_csc.stor_origin = tmp; + + tmp = uvcb_csc.state_origin; + uvcb_csc.state_origin = get_max_ram_size() + PAGE_SIZE; + rc = uv_call(0, (uint64_t)&uvcb_csc); + report(uvcb_csc.header.rc == 0x107 && rc == 1, + "SIE SD inaccessible"); + uvcb_csc.state_origin = tmp; + + rc = uv_call(0, (uint64_t)&uvcb_csc); + report(rc == 0 && uvcb_csc.header.rc == UVC_RC_EXECUTED && + uvcb_csc.cpu_handle, "success"); + + tmp = uvcb_csc.stor_origin; + uvcb_csc.stor_origin = (unsigned long)memalign(PAGE_SIZE, uvcb_qui.cpu_stor_len); + rc = uv_call(0, (uint64_t)&uvcb_csc); + report(rc == 1 && uvcb_csc.header.rc == 0x104, "already defined"); + uvcb_csc.stor_origin = tmp; + report_prefix_pop(); +} + +static void test_config_create(void) +{ + int rc; + unsigned long vsize, tmp; + static struct uv_cb_cgc uvcb; + + uvcb_cgc.header.cmd = UVC_CMD_CREATE_SEC_CONF; + uvcb_cgc.header.len = sizeof(uvcb_cgc); + report_prefix_push("cgc"); + + uvcb_cgc.guest_stor_origin = 0; + uvcb_cgc.guest_stor_len = 42 * (1UL << 20); + vsize = uvcb_qui.conf_base_virt_stor_len + + ((uvcb_cgc.guest_stor_len / (1UL << 20)) * uvcb_qui.conf_virt_var_stor_len); + + uvcb_cgc.conf_base_stor_origin = (uint64_t)memalign(PAGE_SIZE * 4, uvcb_qui.conf_base_phys_stor_len); + uvcb_cgc.conf_var_stor_origin = (uint64_t)memalign(PAGE_SIZE, vsize); + uvcb_cgc.guest_asce = (uint64_t)memalign(PAGE_SIZE, 4 * PAGE_SIZE) | ASCE_DT_SEGMENT | REGION_TABLE_LENGTH | ASCE_P; + uvcb_cgc.guest_sca = (uint64_t)memalign(PAGE_SIZE * 4, PAGE_SIZE * 4); + + uvcb_cgc.header.len -= 8; + rc = uv_call(0, (uint64_t)&uvcb_cgc); + report(uvcb_cgc.header.rc == UVC_RC_INV_LEN && rc == 1 && + !uvcb_cgc.guest_handle, "hdr invalid length"); + uvcb_cgc.header.len += 8; + + uvcb_cgc.guest_stor_origin = uvcb_qui.max_guest_stor_addr + (1UL << 20) * 2 + 1; + rc = uv_call(0, (uint64_t)&uvcb_cgc); + report(uvcb_cgc.header.rc == 0x101 && rc == 1, + "MSO > max guest addr"); + uvcb_cgc.guest_stor_origin = 0; + + uvcb_cgc.guest_stor_origin = uvcb_qui.max_guest_stor_addr - (1UL << 20); + rc = uv_call(0, (uint64_t)&uvcb_cgc); + report(uvcb_cgc.header.rc == 0x102 && rc == 1, + "MSO + MSL > max guest addr"); + uvcb_cgc.guest_stor_origin = 0; + + uvcb_cgc.guest_asce &= ~ASCE_P; + rc = uv_call(0, (uint64_t)&uvcb_cgc); + report(uvcb_cgc.header.rc == 0x105 && rc == 1, + "ASCE private bit missing"); + uvcb_cgc.guest_asce |= ASCE_P; + + uvcb_cgc.guest_asce |= 0x20; + rc = uv_call(0, (uint64_t)&uvcb_cgc); + report(uvcb_cgc.header.rc == 0x105 && rc == 1, + "ASCE bit 58 set"); + uvcb_cgc.guest_asce &= ~0x20; + + tmp = uvcb_cgc.conf_base_stor_origin; + uvcb_cgc.conf_base_stor_origin = get_max_ram_size() + 8; + rc = uv_call(0, (uint64_t)&uvcb_cgc); + report(uvcb_cgc.header.rc == 0x108 && rc == 1, + "base storage origin > available memory"); + uvcb_cgc.conf_base_stor_origin = tmp; + + tmp = uvcb_cgc.conf_base_stor_origin; + uvcb_cgc.conf_base_stor_origin = 0x1000; + rc = uv_call(0, (uint64_t)&uvcb_cgc); + report(uvcb_cgc.header.rc == 0x109 && rc == 1, + "base storage origin contains lowcore"); + uvcb_cgc.conf_base_stor_origin = tmp; + + if (smp_query_num_cpus() == 1) { + sigp_retry(1, SIGP_SET_PREFIX, + uvcb_cgc.conf_var_stor_origin + PAGE_SIZE, NULL); + rc = uv_call(0, (uint64_t)&uvcb_cgc); + report(uvcb_cgc.header.rc == 0x10e && rc == 1 && + !uvcb_cgc.guest_handle, "variable storage area contains lowcore"); + sigp_retry(1, SIGP_SET_PREFIX, 0x0, NULL); + } + + tmp = uvcb_cgc.guest_sca; + uvcb_cgc.guest_sca = 0; + rc = uv_call(0, (uint64_t)&uvcb_cgc); + report(uvcb_cgc.header.rc == 0x10c && rc == 1, + "sca == 0"); + uvcb_cgc.guest_sca = tmp; + + tmp = uvcb_cgc.guest_sca; + uvcb_cgc.guest_sca = get_max_ram_size() + + PAGE_SIZE * 4; + rc = uv_call(0, (uint64_t)&uvcb_cgc); + report(uvcb_cgc.header.rc == 0x10d && rc == 1, + "sca inaccessible"); + uvcb_cgc.guest_sca = tmp; + + rc = uv_call(0, (uint64_t)&uvcb_cgc); + report(rc == 0 && uvcb_cgc.header.rc == UVC_RC_EXECUTED, "successful"); + + uvcb_cgc.header.rc = 0; + uvcb_cgc.header.rrc = 0; + tmp = uvcb_cgc.guest_handle; + uvcb_cgc.guest_handle = 0; + rc = uv_call(0, (uint64_t)&uvcb_cgc); + report(uvcb_cgc.header.rc >= 0x100 && rc == 1, "reuse uvcb"); + uvcb_cgc.guest_handle = tmp; + + /* Copy over most data from uvcb_cgc, so we have the ASCE that was used. */ + memcpy(&uvcb, &uvcb_cgc, sizeof(uvcb)); + + /* Reset the header and handle */ + uvcb.header.rc = 0; + uvcb.header.rrc = 0; + uvcb.guest_handle = 0; + + /* Use new storage areas. */ + uvcb.conf_base_stor_origin = (uint64_t)memalign(PAGE_SIZE * 4, uvcb_qui.conf_base_phys_stor_len); + uvcb.conf_var_stor_origin = (uint64_t)memalign(PAGE_SIZE, vsize); + + rc = uv_call(0, (uint64_t)&uvcb); + report(uvcb.header.rc >= 0x104 && rc == 1 && !uvcb.guest_handle, + "reuse ASCE"); + free((void *)uvcb.conf_base_stor_origin); + free((void *)uvcb.conf_var_stor_origin); + + /* Missing: 106, 10a, a0b */ + report_prefix_pop(); +} + +static void test_init(void) +{ + int rc; + uint64_t mem; + struct psw psw; + + /* Donated storage needs to be over 2GB */ + mem = (uint64_t)memalign(1UL << 31, uvcb_qui.uv_base_stor_len); + + uvcb_init.header.len = sizeof(uvcb_init); + uvcb_init.header.cmd = UVC_CMD_INIT_UV; + uvcb_init.stor_origin = mem; + uvcb_init.stor_len = uvcb_qui.uv_base_stor_len; + + report_prefix_push("init"); + uvcb_init.header.len -= 8; + rc = uv_call(0, (uint64_t)&uvcb_init); + report(rc == 1 && uvcb_init.header.rc == UVC_RC_INV_LEN, + "hdr invalid length"); + uvcb_init.header.len += 8; + + uvcb_init.stor_len -= 8; + rc = uv_call(0, (uint64_t)&uvcb_init); + report(rc == 1 && uvcb_init.header.rc == 0x103, + "storage invalid length"); + uvcb_init.stor_len += 8; + + uvcb_init.stor_origin = get_max_ram_size() + 8; + rc = uv_call(0, (uint64_t)&uvcb_init); + report(rc == 1 && uvcb_init.header.rc == 0x104, + "storage origin invalid"); + uvcb_init.stor_origin = mem; + + uvcb_init.stor_origin = get_max_ram_size() - 8; + rc = uv_call(0, (uint64_t)&uvcb_init); + report(rc == 1 && uvcb_init.header.rc == 0x105, + "storage + length invalid"); + uvcb_init.stor_origin = mem; + + uvcb_init.stor_origin = 1UL << 30; + rc = uv_call(0, (uint64_t)&uvcb_init); + report(rc == 1 && uvcb_init.header.rc == 0x108, + "storage below 2GB"); + uvcb_init.stor_origin = mem; + + psw.mask = extract_psw_mask(); + psw.addr = (unsigned long)cpu_loop; + smp_cpu_setup(1, psw); + rc = uv_call(0, (uint64_t)&uvcb_init); + report(rc == 1 && uvcb_init.header.rc == 0x102, + "too many running cpus"); + smp_cpu_stop(1); + + rc = uv_call(0, (uint64_t)&uvcb_init); + report(rc == 0 && uvcb_init.header.rc == UVC_RC_EXECUTED, "successful"); + + mem = (uint64_t)memalign(1UL << 31, uvcb_qui.uv_base_stor_len); + rc = uv_call(0, (uint64_t)&uvcb_init); + report(rc == 1 && uvcb_init.header.rc == 0x101, "double init"); + free((void *)mem); + + report_prefix_pop(); +} + +static void test_query(void) +{ + int i = 0; + + uvcb_qui.header.cmd = UVC_CMD_QUI; + uvcb_qui.header.len = sizeof(uvcb_qui); + + report_prefix_push("query"); + uvcb_qui.header.len = 0xa0; + uv_call(0, (uint64_t)&uvcb_qui); + report(uvcb_qui.header.rc == UVC_RC_INV_LEN, "length"); + + uvcb_qui.header.len = 0xa8; + uv_call(0, (uint64_t)&uvcb_qui); + report(uvcb_qui.header.rc == 0x100, "insf length"); + + uvcb_qui.header.len = sizeof(uvcb_qui); + uv_call(0, (uint64_t)&uvcb_qui); + report(uvcb_qui.header.rc == UVC_RC_EXECUTED, "successful query"); + + for (i = 0; cmds[i].name; i++) + report(uv_query_test_call(cmds[i].call_bit), "%s", cmds[i].name); + + report_prefix_pop(); +} + +static struct cmd_list invalid_cmds[] = { + { "bogus", 0x4242, sizeof(struct uv_cb_header), -1}, + { "share", UVC_CMD_SET_SHARED_ACCESS, sizeof(struct uv_cb_share), BIT_UVC_CMD_SET_SHARED_ACCESS }, + { "unshare", UVC_CMD_REMOVE_SHARED_ACCESS, sizeof(struct uv_cb_share), BIT_UVC_CMD_REMOVE_SHARED_ACCESS }, + { NULL, 0, 0 }, +}; + +static void test_invalid(void) +{ + struct uv_cb_header hdr = {}; + int i, cc; + + report_prefix_push("invalid"); + for (i = 0; invalid_cmds[i].name; i++) { + hdr.cmd = invalid_cmds[i].cmd; + hdr.len = invalid_cmds[i].len; + cc = uv_call(0, (uint64_t)&hdr); + report(cc == 1 && hdr.rc == UVC_RC_INV_CMD && + (invalid_cmds[i].call_bit == -1 || !uv_query_test_call(invalid_cmds[i].call_bit)), + "%s", invalid_cmds[i].name); + } + report_prefix_pop(); +} + +static void test_clear(void) +{ + uint64_t *tmp = (void *)uvcb_init.stor_origin; + + diag308_load_reset(1); + sclp_console_setup(); + report(!*tmp, "memory cleared after reset 1"); +} + +static void setup_vmem(void) +{ + uint64_t asce, mask; + + setup_mmu(get_max_ram_size()); + asce = stctg(1); + lctlg(13, asce); + mask = extract_psw_mask() | 0x0000C00000000000UL; + load_psw_mask(mask); +} + +int main(void) +{ + bool has_uvc = test_facility(158); + + report_prefix_push("uvc"); + if (!has_uvc) { + report_skip("Ultravisor call facility is not available"); + goto done; + } + + test_priv(); + test_invalid(); + test_query(); + test_init(); + + setup_vmem(); + test_config_create(); + test_cpu_create(); + test_cpu_destroy(); + test_config_destroy(); + test_clear(); + +done: + return report_summary(); +} From patchwork Wed May 26 14:55:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12282005 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 81D22C47082 for ; Wed, 26 May 2021 14:56:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 683A361355 for ; Wed, 26 May 2021 14:56:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235261AbhEZO5n (ORCPT ); Wed, 26 May 2021 10:57:43 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:52488 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235221AbhEZO5b (ORCPT ); Wed, 26 May 2021 10:57:31 -0400 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14QEXMqA110902; Wed, 26 May 2021 10:56:00 -0400 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=vcREnjPwI2Mgoeiw2rGhFb+6/uFe6268dw7vtHlM+sA=; b=Kl8VLE1w3AwE2TRJxkFSyJwKp6VzUNgeFoP3a4ZwIrUjhebVQ5JNhg6wivnkpBS5iqOo eZ5XvTc6WMviGsYXIT8GIArfpwUHBgP7w4EZdGH6v9kMdRbITSEicjELbkEKZBxywU5Y TbZsdq8x49D2qltZDQaVqqFFyqO5Yqf6ZsmzJgK8MQQg+5MnwW77DfRfpeTvvFYzxTpJ TL+d4mIqWK6CT0qhDWd+uOy4j/SG6oAjE7XmWY/U1aSKikUpmIvLHzra9VXL5AFE3AQv 1u3hFD+zUyWklfL/FbKcoMb1+TtVD/WHpjOSBg7gFrynQ13kCG0Pqgn4z2L7P65Rfbcj 2Q== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 38sq8njy1r-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:55:59 -0400 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 14QEXMnI110913; Wed, 26 May 2021 10:55:59 -0400 Received: from ppma03fra.de.ibm.com (6b.4a.5195.ip4.static.sl-reverse.com [149.81.74.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 38sq8njxym-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:55:59 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 14QEqjZZ004046; Wed, 26 May 2021 14:55:56 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma03fra.de.ibm.com with ESMTP id 38s1ssrbnt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 14:55:56 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 14QEtrAd12976494 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 May 2021 14:55:53 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2335BA40A6; Wed, 26 May 2021 14:55:53 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8B375A408C; Wed, 26 May 2021 14:55:52 +0000 (GMT) Received: from localhost.localdomain.com (unknown [9.145.174.11]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 26 May 2021 14:55:52 +0000 (GMT) From: Janosch Frank To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, david@redhat.com, borntraeger@de.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, thuth@redhat.com Subject: [kvm-unit-tests GIT PULL 7/9] s390x: sclp: Only fetch read info byte 134 if cpu entries are above it Date: Wed, 26 May 2021 16:55:37 +0200 Message-Id: <20210526145539.52008-8-frankja@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210526145539.52008-1-frankja@linux.ibm.com> References: <20210526145539.52008-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: pfm1oy7PJUFuREpjVH772Lntih9fOwUS X-Proofpoint-ORIG-GUID: IRjB9-Q5xFMuugf_wFVTpqEY-7cmWMM5 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-05-26_09:2021-05-26,2021-05-26 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 adultscore=0 mlxlogscore=999 spamscore=0 impostorscore=0 priorityscore=1501 clxscore=1015 bulkscore=0 malwarescore=0 phishscore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105260098 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The cpu offset tells us where the cpu entries are in the sclp read info structure. Signed-off-by: Janosch Frank Reviewed-by: Claudio Imbrenda Reviewed-by: David Hildenbrand Reviewed-by: Cornelia Huck --- lib/s390x/sclp.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c index 7a9b2c52..f11c2035 100644 --- a/lib/s390x/sclp.c +++ b/lib/s390x/sclp.c @@ -138,7 +138,8 @@ void sclp_facilities_setup(void) assert(read_info); cpu = sclp_get_cpu_entries(); - sclp_facilities.has_diag318 = read_info->byte_134_diag318; + if (read_info->offset_cpu > 134) + sclp_facilities.has_diag318 = read_info->byte_134_diag318; for (i = 0; i < read_info->entries_cpu; i++, cpu++) { /* * The logic for only reading the facilities from the From patchwork Wed May 26 14:55:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12282009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE181C47082 for ; Wed, 26 May 2021 14:56:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FD7D613B0 for ; Wed, 26 May 2021 14:56:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235283AbhEZO5q (ORCPT ); Wed, 26 May 2021 10:57:46 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:37674 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235245AbhEZO5c (ORCPT ); Wed, 26 May 2021 10:57:32 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14QEZJdB127888; Wed, 26 May 2021 10:56:01 -0400 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=3K05EQQVHhhrvqEc7hSAacFQvh7iyOrOondQnAvPOgQ=; b=Hqk+M6Shi7DE7w51Z4LK0qg1q6yh3ovME9Sjr/bG1TN9UCHG7Jmi0pYNV2Nyy7Ysmud/ hGjXhDXcJLVXdUwjWaOaNXvYWtHjT+e6Gk+WG87vlKqy3nAabUk+2SICLCQfMCQyvUiW BlymhpPVWEPuSjTauhU44+Oi7AflV1AoheoLDRTkuR//V3Zacwb8Bk44vFWxkpCpPlSb O12KagGPQPVQDBMry+Wme/p9tv5x4bBokhb+7sssEs9mqpFvMLdO66prfdOQJjZ0Tors 9ptt9oMaArQH/fzxxqYkogmmUOKKRBIBlkYyURsKviizmtc6OOtgTGQYEiHGREZTZdNN ug== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 38sr5a0wn4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:56:00 -0400 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 14QEZVgZ129486; Wed, 26 May 2021 10:56:00 -0400 Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com with ESMTP id 38sr5a0wm2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:56:00 -0400 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 14QErZ46017515; Wed, 26 May 2021 14:55:58 GMT Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by ppma02fra.de.ibm.com with ESMTP id 38s2dt0b0h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 14:55:58 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 14QEtt4n23789988 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 May 2021 14:55:55 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CF109A40B7; Wed, 26 May 2021 14:55:53 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 44143A408C; Wed, 26 May 2021 14:55:53 +0000 (GMT) Received: from localhost.localdomain.com (unknown [9.145.174.11]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 26 May 2021 14:55:53 +0000 (GMT) From: Janosch Frank To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, david@redhat.com, borntraeger@de.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, thuth@redhat.com Subject: [kvm-unit-tests GIT PULL 8/9] lib: s390x: sclp: Extend feature probing Date: Wed, 26 May 2021 16:55:38 +0200 Message-Id: <20210526145539.52008-9-frankja@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210526145539.52008-1-frankja@linux.ibm.com> References: <20210526145539.52008-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: jniEnTB9_2XJz_o2ktQ6jtiWk5CaS4HB X-Proofpoint-ORIG-GUID: vByW4rPamigd1wsnh1UZ8-emkE2vsjeN X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-05-26_09:2021-05-26,2021-05-26 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 mlxlogscore=999 clxscore=1015 phishscore=0 mlxscore=0 priorityscore=1501 lowpriorityscore=0 suspectscore=0 impostorscore=0 adultscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105260098 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Let's grab more of the feature bits from SCLP read info so we can use them in the cpumodel tests. Signed-off-by: Janosch Frank Reviewed-by: Claudio Imbrenda Acked-by: Cornelia Huck Acked-by: David Hildenbrand --- lib/s390x/sclp.c | 20 ++++++++++++++++++++ lib/s390x/sclp.h | 39 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/lib/s390x/sclp.c b/lib/s390x/sclp.c index f11c2035..291924b0 100644 --- a/lib/s390x/sclp.c +++ b/lib/s390x/sclp.c @@ -129,6 +129,13 @@ CPUEntry *sclp_get_cpu_entries(void) return (CPUEntry *)(_read_info + read_info->offset_cpu); } +static bool sclp_feat_check(int byte, int bit) +{ + uint8_t *rib = (uint8_t *)read_info; + + return !!(rib[byte] & (0x80 >> bit)); +} + void sclp_facilities_setup(void) { unsigned short cpu0_addr = stap(); @@ -140,6 +147,14 @@ void sclp_facilities_setup(void) cpu = sclp_get_cpu_entries(); if (read_info->offset_cpu > 134) sclp_facilities.has_diag318 = read_info->byte_134_diag318; + sclp_facilities.has_gsls = sclp_feat_check(85, SCLP_FEAT_85_BIT_GSLS); + sclp_facilities.has_kss = sclp_feat_check(98, SCLP_FEAT_98_BIT_KSS); + sclp_facilities.has_cmma = sclp_feat_check(116, SCLP_FEAT_116_BIT_CMMA); + sclp_facilities.has_64bscao = sclp_feat_check(116, SCLP_FEAT_116_BIT_64BSCAO); + sclp_facilities.has_esca = sclp_feat_check(116, SCLP_FEAT_116_BIT_ESCA); + sclp_facilities.has_ibs = sclp_feat_check(117, SCLP_FEAT_117_BIT_IBS); + sclp_facilities.has_pfmfi = sclp_feat_check(117, SCLP_FEAT_117_BIT_PFMFI); + for (i = 0; i < read_info->entries_cpu; i++, cpu++) { /* * The logic for only reading the facilities from the @@ -150,6 +165,11 @@ void sclp_facilities_setup(void) */ if (cpu->address == cpu0_addr) { sclp_facilities.has_sief2 = cpu->feat_sief2; + sclp_facilities.has_skeyi = cpu->feat_skeyi; + sclp_facilities.has_siif = cpu->feat_siif; + sclp_facilities.has_sigpif = cpu->feat_sigpif; + sclp_facilities.has_ib = cpu->feat_ib; + sclp_facilities.has_cei = cpu->feat_cei; break; } } diff --git a/lib/s390x/sclp.h b/lib/s390x/sclp.h index 85231333..7abf1038 100644 --- a/lib/s390x/sclp.h +++ b/lib/s390x/sclp.h @@ -94,9 +94,19 @@ typedef struct CPUEntry { uint8_t reserved0; uint8_t : 4; uint8_t feat_sief2 : 1; + uint8_t feat_skeyi : 1; + uint8_t : 2; + uint8_t : 2; + uint8_t feat_gpere : 1; + uint8_t feat_siif : 1; + uint8_t feat_sigpif : 1; uint8_t : 3; - uint8_t features_res2 [SCCB_CPU_FEATURE_LEN - 1]; - uint8_t reserved2[6]; + uint8_t reserved2[3]; + uint8_t : 2; + uint8_t feat_ib : 1; + uint8_t feat_cei : 1; + uint8_t : 4; + uint8_t reserved3[6]; uint8_t type; uint8_t reserved1; } __attribute__((packed)) CPUEntry; @@ -105,10 +115,33 @@ extern struct sclp_facilities sclp_facilities; struct sclp_facilities { uint64_t has_sief2 : 1; + uint64_t has_skeyi : 1; + uint64_t has_gpere : 1; + uint64_t has_siif : 1; + uint64_t has_sigpif : 1; + uint64_t has_ib : 1; + uint64_t has_cei : 1; + uint64_t has_diag318 : 1; - uint64_t : 62; + uint64_t has_gsls : 1; + uint64_t has_cmma : 1; + uint64_t has_64bscao : 1; + uint64_t has_esca : 1; + uint64_t has_kss : 1; + uint64_t has_pfmfi : 1; + uint64_t has_ibs : 1; + uint64_t : 64 - 15; }; +/* bit number within a certain byte */ +#define SCLP_FEAT_85_BIT_GSLS 7 +#define SCLP_FEAT_98_BIT_KSS 0 +#define SCLP_FEAT_116_BIT_64BSCAO 7 +#define SCLP_FEAT_116_BIT_CMMA 6 +#define SCLP_FEAT_116_BIT_ESCA 3 +#define SCLP_FEAT_117_BIT_PFMFI 6 +#define SCLP_FEAT_117_BIT_IBS 5 + typedef struct ReadInfo { SCCBHeader h; uint16_t rnmax; From patchwork Wed May 26 14:55:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12282007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 458E6C47089 for ; Wed, 26 May 2021 14:56:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2BB31613B4 for ; Wed, 26 May 2021 14:56:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235272AbhEZO5p (ORCPT ); Wed, 26 May 2021 10:57:45 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:40778 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235216AbhEZO5c (ORCPT ); Wed, 26 May 2021 10:57:32 -0400 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 14QEhM7P145542; Wed, 26 May 2021 10:56:01 -0400 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=x753QCuUtpfkDxdhBsKm6pABBw8Ei9O9gGCL8X1s0vw=; b=lhixkU2DDkEtSeIcx5dtF1gmxSWu2c6j2FGYp7bum4sV76dl9WdNj6UG7ykV92+0jJIq 8O1LO4dgnFXLfF/Ogn+S6hUnlhaxp2TdiSz2/dY6ZZs9rNWxImDogx/JR62KqwAEyYf+ ve3gqeBAfOlo/tBNsmvyyYVpqTyrqihmSyl94W/9dzrKSn2XeH/C5glbSHpGnPSP3FuP aqZdt3QbuGt5rfW+EgX0lizQzcdjqhzPl8i6yeEURxU+U0ZuaoMIkJ4svTPg3JkyR93K FQNudgAVp6JX2+ESd692ThOqLgPEl/Pi53rUZuvvhw6UVOoqyyL5Q77WGKdAsE1OpVuK IA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 38srbd0d1s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:56:01 -0400 Received: from m0098394.ppops.net (m0098394.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 14QEhQBC145765; Wed, 26 May 2021 10:56:00 -0400 Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 38srbd0d0h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 10:56:00 -0400 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 14QEqtYT019741; Wed, 26 May 2021 14:55:58 GMT Received: from b06avi18878370.portsmouth.uk.ibm.com (b06avi18878370.portsmouth.uk.ibm.com [9.149.26.194]) by ppma05fra.de.ibm.com with ESMTP id 38s1r50be7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 26 May 2021 14:55:57 +0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 14QEtPvB9830772 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 26 May 2021 14:55:25 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7EF19A409B; Wed, 26 May 2021 14:55:54 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E5BF1A408C; Wed, 26 May 2021 14:55:53 +0000 (GMT) Received: from localhost.localdomain.com (unknown [9.145.174.11]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Wed, 26 May 2021 14:55:53 +0000 (GMT) From: Janosch Frank To: pbonzini@redhat.com Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, david@redhat.com, borntraeger@de.ibm.com, cohuck@redhat.com, linux-s390@vger.kernel.org, imbrenda@linux.ibm.com, thuth@redhat.com Subject: [kvm-unit-tests GIT PULL 9/9] s390x: cpumodel: FMT2 and FMT4 SCLP test Date: Wed, 26 May 2021 16:55:39 +0200 Message-Id: <20210526145539.52008-10-frankja@linux.ibm.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210526145539.52008-1-frankja@linux.ibm.com> References: <20210526145539.52008-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 4iMOAySniT1stY325jnyMU7e9e56kg7d X-Proofpoint-GUID: s37yLRlZC76jvqe2W4JsADFDFJV5hIwC X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.761 definitions=2021-05-26_09:2021-05-26,2021-05-26 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 clxscore=1015 priorityscore=1501 impostorscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 spamscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2104190000 definitions=main-2105260098 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org SCLP is also part of the cpumodel, so we need to make sure that the features indicated via read info / read cpu info are correct. Signed-off-by: Janosch Frank Reviewed-by: Claudio Imbrenda Acked-by: David Hildenbrand Acked-by: Cornelia Huck --- s390x/cpumodel.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/s390x/cpumodel.c b/s390x/cpumodel.c index 4dd8b96f..67bb6543 100644 --- a/s390x/cpumodel.c +++ b/s390x/cpumodel.c @@ -2,14 +2,81 @@ /* * Test the known dependencies for facilities * - * Copyright 2019 IBM Corp. + * Copyright 2019, 2021 IBM Corp. * * Authors: * Christian Borntraeger + * Janosch Frank */ #include #include +#include +#include +#include + +static void test_sclp_missing_sief2_implications(void) +{ + /* Virtualization related facilities */ + report(!sclp_facilities.has_64bscao, "!64bscao"); + report(!sclp_facilities.has_pfmfi, "!pfmfi"); + report(!sclp_facilities.has_gsls, "!gsls"); + report(!sclp_facilities.has_cmma, "!cmma"); + report(!sclp_facilities.has_esca, "!esca"); + report(!sclp_facilities.has_kss, "!kss"); + report(!sclp_facilities.has_ibs, "!ibs"); + + /* Virtualization related facilities reported via CPU entries */ + report(!sclp_facilities.has_sigpif, "!sigpif"); + report(!sclp_facilities.has_sief2, "!sief2"); + report(!sclp_facilities.has_skeyi, "!skeyi"); + report(!sclp_facilities.has_siif, "!siif"); + report(!sclp_facilities.has_cei, "!cei"); + report(!sclp_facilities.has_ib, "!ib"); +} + +static void test_sclp_features_fmt4(void) +{ + /* + * STFLE facilities are handled by the Ultravisor but SCLP + * facilities are advertised by the hypervisor. + */ + report_prefix_push("PV guest implies"); + + /* General facilities */ + report(!sclp_facilities.has_diag318, "!diag318"); + + /* + * Virtualization related facilities, all of which are + * unavailable because there's no virtualization support in a + * protected guest. + */ + test_sclp_missing_sief2_implications(); + + report_prefix_pop(); +} + +static void test_sclp_features_fmt2(void) +{ + if (sclp_facilities.has_sief2) + return; + + report_prefix_push("!sief2 implies"); + test_sclp_missing_sief2_implications(); + report_prefix_pop(); +} + +static void test_sclp_features(void) +{ + report_prefix_push("sclp"); + + if (uv_os_is_guest()) + test_sclp_features_fmt4(); + else + test_sclp_features_fmt2(); + + report_prefix_pop(); +} static struct { int facility; @@ -60,6 +127,8 @@ int main(void) } report_prefix_pop(); + test_sclp_features(); + report_prefix_pop(); return report_summary(); }