From patchwork Fri Jul 17 14:58:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 11670567 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 572DB13B1 for ; Fri, 17 Jul 2020 14:58:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 48EFE2076D for ; Fri, 17 Jul 2020 14:58:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726977AbgGQO63 (ORCPT ); Fri, 17 Jul 2020 10:58:29 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:53698 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726755AbgGQO62 (ORCPT ); Fri, 17 Jul 2020 10:58:28 -0400 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 06HEUxx3031437; Fri, 17 Jul 2020 10:58:27 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 32b61knv3e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Jul 2020 10:58:27 -0400 Received: from m0098413.ppops.net (m0098413.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 06HEVESE032683; Fri, 17 Jul 2020 10:58:27 -0400 Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0b-001b2d01.pphosted.com with ESMTP id 32b61knv32-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Jul 2020 10:58:27 -0400 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 06HEpZVZ018424; Fri, 17 Jul 2020 14:58:25 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma05fra.de.ibm.com with ESMTP id 327q2y34a7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Jul 2020 14:58:25 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 06HEwM8r52363336 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Jul 2020 14:58:22 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4CBE142049; Fri, 17 Jul 2020 14:58:22 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 892D842041; Fri, 17 Jul 2020 14:58:21 +0000 (GMT) Received: from linux01.pok.stglabs.ibm.com (unknown [9.114.17.81]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 17 Jul 2020 14:58:21 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: thuth@redhat.com, linux-s390@vger.kernel.org, david@redhat.com, borntraeger@de.ibm.com, cohuck@redhat.com, imbrenda@linux.ibm.com Subject: [kvm-unit-tests PATCH 1/3] s390x: Add custom pgm cleanup function Date: Fri, 17 Jul 2020 10:58:11 -0400 Message-Id: <20200717145813.62573-2-frankja@linux.ibm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200717145813.62573-1-frankja@linux.ibm.com> References: <20200717145813.62573-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-07-17_06:2020-07-17,2020-07-17 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 malwarescore=0 mlxscore=0 adultscore=0 impostorscore=0 mlxlogscore=999 spamscore=0 clxscore=1015 suspectscore=1 phishscore=0 priorityscore=1501 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007170103 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Sometimes we need to do cleanup which we don't necessarily want to add to interrupt.c, so lets add a way to register a cleanup function. Signed-off-by: Janosch Frank Reviewed-by: Claudio Imbrenda Reviewed-by: Thomas Huth --- lib/s390x/asm/interrupt.h | 1 + lib/s390x/interrupt.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/lib/s390x/asm/interrupt.h b/lib/s390x/asm/interrupt.h index 4cfade9..b2a7c83 100644 --- a/lib/s390x/asm/interrupt.h +++ b/lib/s390x/asm/interrupt.h @@ -15,6 +15,7 @@ #define EXT_IRQ_EXTERNAL_CALL 0x1202 #define EXT_IRQ_SERVICE_SIG 0x2401 +void register_pgm_int_func(void (*f)(void)); void handle_pgm_int(void); void handle_ext_int(void); void handle_mcck_int(void); diff --git a/lib/s390x/interrupt.c b/lib/s390x/interrupt.c index 243b9c2..36ba720 100644 --- a/lib/s390x/interrupt.c +++ b/lib/s390x/interrupt.c @@ -16,6 +16,7 @@ static bool pgm_int_expected; static bool ext_int_expected; +static void (*pgm_int_func)(void); static struct lowcore *lc; void expect_pgm_int(void) @@ -51,8 +52,16 @@ void check_pgm_int_code(uint16_t code) lc->pgm_int_code); } +void register_pgm_int_func(void (*f)(void)) +{ + pgm_int_func = f; +} + static void fixup_pgm_int(void) { + if (pgm_int_func) + return (*pgm_int_func)(); + switch (lc->pgm_int_code) { case PGM_INT_CODE_PRIVILEGED_OPERATION: /* Normal operation is in supervisor state, so this exception From patchwork Fri Jul 17 14:58:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 11670569 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 780B614E3 for ; Fri, 17 Jul 2020 14:58:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 69E34208C7 for ; Fri, 17 Jul 2020 14:58:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726996AbgGQO6a (ORCPT ); Fri, 17 Jul 2020 10:58:30 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:28212 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726832AbgGQO63 (ORCPT ); Fri, 17 Jul 2020 10:58:29 -0400 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 06HEWMDU137528; Fri, 17 Jul 2020 10:58:28 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 32aut55um1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Jul 2020 10:58:28 -0400 Received: from m0098420.ppops.net (m0098420.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 06HEwRf2032000; Fri, 17 Jul 2020 10:58:27 -0400 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0b-001b2d01.pphosted.com with ESMTP id 32aut55ukf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Jul 2020 10:58:27 -0400 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 06HEpTOH027910; Fri, 17 Jul 2020 14:58:26 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma06ams.nl.ibm.com with ESMTP id 3274pgxkxd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Jul 2020 14:58:26 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 06HEwNGJ57081882 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Jul 2020 14:58:23 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2D2EF42045; Fri, 17 Jul 2020 14:58:23 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 736B94203F; Fri, 17 Jul 2020 14:58:22 +0000 (GMT) Received: from linux01.pok.stglabs.ibm.com (unknown [9.114.17.81]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 17 Jul 2020 14:58:22 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: thuth@redhat.com, linux-s390@vger.kernel.org, david@redhat.com, borntraeger@de.ibm.com, cohuck@redhat.com, imbrenda@linux.ibm.com Subject: [kvm-unit-tests PATCH 2/3] s390x: skrf: Add exception new skey test and add test to unittests.cfg Date: Fri, 17 Jul 2020 10:58:12 -0400 Message-Id: <20200717145813.62573-3-frankja@linux.ibm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200717145813.62573-1-frankja@linux.ibm.com> References: <20200717145813.62573-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-07-17_06:2020-07-17,2020-07-17 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 adultscore=0 clxscore=1015 bulkscore=0 spamscore=0 suspectscore=1 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 mlxscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007170103 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org If a exception new psw mask contains a key a specification exception instead of a special operation exception is presented. Let's test that. Also let's add the test to unittests.cfg so it is run more often. Signed-off-by: Janosch Frank Reviewed-by: Claudio Imbrenda --- s390x/skrf.c | 81 +++++++++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 4 +++ 2 files changed, 85 insertions(+) diff --git a/s390x/skrf.c b/s390x/skrf.c index 9cae589..9733412 100644 --- a/s390x/skrf.c +++ b/s390x/skrf.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include static uint8_t pagebuf[PAGE_SIZE * 2] __attribute__((aligned(PAGE_SIZE * 2))); @@ -106,6 +108,84 @@ static void test_tprot(void) report_prefix_pop(); } +#include +static int testflag = 0; + +static void wait_for_flag(void) +{ + while (!testflag) + mb(); +} + +static void set_flag(int val) +{ + mb(); + testflag = val; + mb(); +} + +static void ecall_cleanup(void) +{ + struct lowcore *lc = (void *)0x0; + + lc->ext_new_psw.mask = 0x0000000180000000UL; + lc->sw_int_crs[0] = 0x0000000000040000; + + /* + * PGM old contains the ext new PSW, we need to clean it up, + * so we don't get a special oepration exception on the lpswe + * of pgm old. + */ + lc->pgm_old_psw.mask = 0x0000000180000000UL; + lc->pgm_old_psw.addr = (unsigned long)wait_for_flag; + + check_pgm_int_code(PGM_INT_CODE_SPECIFICATION); + set_flag(1); +} + +/* Set a key into the external new psw mask and open external call masks */ +static void ecall_setup(void) +{ + struct lowcore *lc = (void *)0x0; + uint64_t mask; + + register_pgm_int_func(ecall_cleanup); + expect_pgm_int(); + /* Put a skey into the ext new psw */ + lc->ext_new_psw.mask = 0x00F0000180000000UL; + /* Open up ext masks */ + ctl_set_bit(0, 13); + mask = extract_psw_mask(); + mask |= PSW_MASK_EXT; + load_psw_mask(mask); + /* Tell cpu 0 that we're ready */ + set_flag(1); +} + +static void test_exception_ext_new(void) +{ + struct psw psw = { + .mask = extract_psw_mask(), + .addr = (unsigned long)ecall_setup + }; + + report_prefix_push("exception external new"); + if (smp_query_num_cpus() < 2) { + report_skip("Need second cpu for exception external new test."); + report_prefix_pop(); + return; + } + + smp_cpu_setup(1, psw); + wait_for_flag(); + set_flag(0); + + sigp(1, SIGP_EXTERNAL_CALL, 0, NULL); + wait_for_flag(); + smp_cpu_stop(1); + report_prefix_pop(); +} + int main(void) { report_prefix_push("skrf"); @@ -121,6 +201,7 @@ int main(void) test_mvcos(); test_spka(); test_tprot(); + test_exception_ext_new(); done: report_prefix_pop(); diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index 0f156af..b35269b 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -88,3 +88,7 @@ extra_params = -m 3G [css] file = css.elf extra_params = -device virtio-net-ccw + +[skrf] +file = skrf.elf +smp = 2 From patchwork Fri Jul 17 14:58:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 11670571 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8D26014E3 for ; Fri, 17 Jul 2020 14:58:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 79213207DD for ; Fri, 17 Jul 2020 14:58:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726788AbgGQO6d (ORCPT ); Fri, 17 Jul 2020 10:58:33 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:55532 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726832AbgGQO6b (ORCPT ); Fri, 17 Jul 2020 10:58:31 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 06HEWOPn102274; Fri, 17 Jul 2020 10:58:30 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 32aurbecdp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Jul 2020 10:58:30 -0400 Received: from m0098399.ppops.net (m0098399.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 06HEfWq4133005; Fri, 17 Jul 2020 10:58:29 -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 32aurbeccs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Jul 2020 10:58:29 -0400 Received: from pps.filterd (ppma03fra.de.ibm.com [127.0.0.1]) by ppma03fra.de.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 06HEntOw008047; Fri, 17 Jul 2020 14:58:27 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 327527kffw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 17 Jul 2020 14:58:26 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 06HEwOW241680970 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 17 Jul 2020 14:58:24 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 21EA242041; Fri, 17 Jul 2020 14:58:24 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5DC0C4203F; Fri, 17 Jul 2020 14:58:23 +0000 (GMT) Received: from linux01.pok.stglabs.ibm.com (unknown [9.114.17.81]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 17 Jul 2020 14:58:23 +0000 (GMT) From: Janosch Frank To: kvm@vger.kernel.org Cc: thuth@redhat.com, linux-s390@vger.kernel.org, david@redhat.com, borntraeger@de.ibm.com, cohuck@redhat.com, imbrenda@linux.ibm.com Subject: [kvm-unit-tests PATCH 3/3] s390x: Ultavisor guest API test Date: Fri, 17 Jul 2020 10:58:13 -0400 Message-Id: <20200717145813.62573-4-frankja@linux.ibm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200717145813.62573-1-frankja@linux.ibm.com> References: <20200717145813.62573-1-frankja@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235,18.0.687 definitions=2020-07-17_06:2020-07-17,2020-07-17 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 adultscore=0 mlxlogscore=999 suspectscore=3 clxscore=1015 bulkscore=0 spamscore=0 phishscore=0 malwarescore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2007170103 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Test the error conditions of guest 2 Ultravisor calls, namely: * Query Ultravisor information * Set shared access * Remove shared access Signed-off-by: Janosch Frank Reviewed-by: Claudio Imbrenda --- lib/s390x/asm/uv.h | 68 +++++++++++++++++++ s390x/Makefile | 1 + s390x/unittests.cfg | 3 + s390x/uv-guest.c | 156 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 228 insertions(+) create mode 100644 lib/s390x/asm/uv.h create mode 100644 s390x/uv-guest.c diff --git a/lib/s390x/asm/uv.h b/lib/s390x/asm/uv.h new file mode 100644 index 0000000..14ab5cc --- /dev/null +++ b/lib/s390x/asm/uv.h @@ -0,0 +1,68 @@ +/* + * s390x Ultravisor related definitions + * + * Copyright (c) 2020 IBM Corp + * + * Authors: + * Janosch Frank + * + * 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 + +#define UVC_RC_EXECUTED 0x0001 +#define UVC_RC_INV_CMD 0x0002 +#define UVC_RC_INV_STATE 0x0003 +#define UVC_RC_INV_LEN 0x0005 +#define UVC_RC_NO_RESUME 0x0007 + +#define UVC_CMD_QUI 0x0001 +#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_SET_SHARED_ACCESS = 8, + BIT_UVC_CMD_REMOVE_SHARED_ACCESS = 9, +}; + +struct uv_cb_header { + u16 len; + u16 cmd; /* Command Code */ + u16 rc; /* Response Code */ + u16 rrc; /* Return Reason Code */ +} __attribute__((packed)) __attribute__((aligned(8))); + +struct uv_cb_qui { + struct uv_cb_header header; + u64 reserved08; + u64 inst_calls_list[4]; + u64 reserved30[15]; +} __attribute__((packed)) __attribute__((aligned(8))); + +struct uv_cb_share { + struct uv_cb_header header; + u64 reserved08[3]; + u64 paddr; + u64 reserved28; +} __attribute__((packed)) __attribute__((aligned(8))); + +static inline int uv_call(unsigned long r1, unsigned long r2) +{ + int cc; + + asm volatile( + "0: .insn rrf,0xB9A40000,%[r1],%[r2],0,0\n" + " brc 3,0b\n" + " ipm %[cc]\n" + " srl %[cc],28\n" + : [cc] "=d" (cc) + : [r1] "a" (r1), [r2] "a" (r2) + : "memory", "cc"); + return cc; +} + +#endif diff --git a/s390x/Makefile b/s390x/Makefile index 0f54bf4..c2213ad 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -18,6 +18,7 @@ tests += $(TEST_DIR)/skrf.elf tests += $(TEST_DIR)/smp.elf tests += $(TEST_DIR)/sclp.elf tests += $(TEST_DIR)/css.elf +tests += $(TEST_DIR)/uv-guest.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) all: directories test_cases test_cases_binary diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index b35269b..38c3257 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -92,3 +92,6 @@ extra_params = -device virtio-net-ccw [skrf] file = skrf.elf smp = 2 + +[uv-guest] +file = uv-guest.elf \ No newline at end of file diff --git a/s390x/uv-guest.c b/s390x/uv-guest.c new file mode 100644 index 0000000..0cb5fae --- /dev/null +++ b/s390x/uv-guest.c @@ -0,0 +1,156 @@ +/* + * Guest Ultravisor Call tests + * + * Copyright (c) 2020 IBM Corp + * + * Authors: + * Janosch Frank + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2. + */ + +#include +#include +#include +#include +#include +#include +#include + +static inline int share(unsigned long addr, u16 cmd) +{ + struct uv_cb_share uvcb = { + .header.cmd = cmd, + .header.len = sizeof(uvcb), + .paddr = addr + }; + + uv_call(0, (u64)&uvcb); + return uvcb.header.rc; +} + +static inline int uv_set_shared(unsigned long addr) +{ + return share(addr, UVC_CMD_SET_SHARED_ACCESS); +} + +static inline int uv_remove_shared(unsigned long addr) +{ + return share(addr, UVC_CMD_REMOVE_SHARED_ACCESS); +} + +static void test_priv(void) +{ + struct uv_cb_header uvcb = {}; + + report_prefix_push("privileged"); + + report_prefix_push("query"); + expect_pgm_int(); + uvcb.cmd = UVC_CMD_QUI; + uvcb.len = sizeof(struct uv_cb_qui); + enter_pstate(); + uv_call(0, (u64)&uvcb); + check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION); + report_prefix_pop(); + + report_prefix_push("share"); + expect_pgm_int(); + enter_pstate(); + uv_set_shared(0x42000); + check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION); + report_prefix_pop(); + + report_prefix_push("unshare"); + expect_pgm_int(); + enter_pstate(); + uv_remove_shared(0x42000); + check_pgm_int_code(PGM_INT_CODE_PRIVILEGED_OPERATION); + report_prefix_pop(); + + report_prefix_pop(); +} + +static void test_query(void) +{ + struct uv_cb_qui uvcb = { + .header.cmd = UVC_CMD_QUI, + .header.len = sizeof(uvcb) - 8, + }; + + report_prefix_push("query"); + uv_call(0, (u64)&uvcb); + report(uvcb.header.rc == UVC_RC_INV_LEN, "length"); + + uvcb.header.len = sizeof(uvcb); + uv_call(0, (u64)&uvcb); + report(uvcb.header.rc == UVC_RC_EXECUTED, "successful query"); + + /* + * These bits have been introduced with the very first + * Ultravisor version and are expected to always be available + * because they are basic building blocks. + */ + report(uvcb.inst_calls_list[0] & (1UL << (63 - BIT_UVC_CMD_QUI)), + "query indicated"); + report(uvcb.inst_calls_list[0] & (1UL << (63 - BIT_UVC_CMD_SET_SHARED_ACCESS)), + "share indicated"); + report(uvcb.inst_calls_list[0] & (1UL << (63 - BIT_UVC_CMD_REMOVE_SHARED_ACCESS)), + "unshare indicated"); + report_prefix_pop(); +} + +static void test_sharing(void) +{ + unsigned long mem = (unsigned long)alloc_page(); + struct uv_cb_share uvcb = { + .header.cmd = UVC_CMD_SET_SHARED_ACCESS, + .header.len = sizeof(uvcb) - 8, + }; + + report_prefix_push("share"); + uv_call(0, (u64)&uvcb); + report(uvcb.header.rc == UVC_RC_INV_LEN, "length"); + report(uv_set_shared(mem) == UVC_RC_EXECUTED, "share"); + report_prefix_pop(); + + report_prefix_push("unshare"); + uvcb.header.cmd = UVC_CMD_REMOVE_SHARED_ACCESS; + uv_call(0, (u64)&uvcb); + report(uvcb.header.rc == UVC_RC_INV_LEN, "length"); + report(uv_remove_shared(mem) == UVC_RC_EXECUTED, "unshare"); + free_page((void *)mem); + report_prefix_pop(); + + report_prefix_pop(); +} + +static void test_invalid(void) +{ + struct uv_cb_header uvcb = { + .len = 16, + .cmd = 0x4242, + }; + + uv_call(0, (u64)&uvcb); + report(uvcb.rc == UVC_RC_INV_CMD, "invalid command"); +} + +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_sharing(); +done: + return report_summary(); +}