From patchwork Thu Aug 11 15:00:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Janosch Frank X-Patchwork-Id: 12941492 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76FC3C19F2A for ; Thu, 11 Aug 2022 15:00:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235396AbiHKPAy (ORCPT ); Thu, 11 Aug 2022 11:00:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234066AbiHKPAw (ORCPT ); Thu, 11 Aug 2022 11:00:52 -0400 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F084E237C2 for ; Thu, 11 Aug 2022 08:00:51 -0700 (PDT) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27BElCdx002528 for ; Thu, 11 Aug 2022 15:00:51 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=pp1; bh=JwrE3WYdlRmp/SZ39ZRaiBz1d+IkeHOLbTNY8ng7qGg=; b=cQ9ROcVbJ7fsWp3OT7Emrs7fdIjNcZCy0jrlvVv4b5UNau8bcpAjZ+8falp5iH71WGDT zrDJedyG/uj6jlzrj52tcpv8vHxToISWhshpNjrJo4gxyrgx9Tj5syF9vr+SRo54mjVe VKgFCFBzvCW5ZfBsTZyCIzM+d/tyD7Cea00bUYHHc3rXCDTx5NJOaNldKbDAabvp/cyn KuGn8qnRhdA7tA+d/Q1JQ11mzLxTxbrHRScapCMkk5gCgUkQmME2kOeA34IIVODvGLj+ U9LsRcRLs0KXzi9vdNKR6AomsYIgp5ZAMEJDkytyYAFi15oDfRGmLyIs9ITnfrpfvL5o 0w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hw3u38e6g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 11 Aug 2022 15:00:50 +0000 Received: from m0098421.ppops.net (m0098421.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 27BEm95d008214 for ; Thu, 11 Aug 2022 15:00:50 GMT Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3hw3u38e5j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Aug 2022 15:00:49 +0000 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 27BEpUmW003113; Thu, 11 Aug 2022 15:00:48 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 3huwvf26b0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 11 Aug 2022 15:00:48 +0000 Received: from d06av25.portsmouth.uk.ibm.com (d06av25.portsmouth.uk.ibm.com [9.149.105.61]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 27BF0i9a33620346 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 11 Aug 2022 15:00:44 GMT Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D381311C04A; Thu, 11 Aug 2022 15:00:44 +0000 (GMT) Received: from d06av25.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2F7DB11C04C; Thu, 11 Aug 2022 15:00:44 +0000 (GMT) Received: from linux6.. (unknown [9.114.12.104]) by d06av25.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 11 Aug 2022 15:00:44 +0000 (GMT) From: Janosch Frank To: imbrenda@linux.ibm.com Cc: kvm@vger.kernel.org, seiden@linux.ibm.com, nrb@linux.ibm.com, scgl@linux.ibm.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH v5] s390x: uv-host: Add access checks for donated memory Date: Thu, 11 Aug 2022 15:00:39 +0000 Message-Id: <20220811150039.29938-1-frankja@linux.ibm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220811161716.358a68eb@p-imbrenda> References: <20220811161716.358a68eb@p-imbrenda> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: jpx7IbPp90hErCDwasiHHYqmH9I2keED X-Proofpoint-GUID: XbpXK4yeCeWA-zJH0BeO2TGj82AeWPIH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-11_11,2022-08-11_01,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 spamscore=0 bulkscore=0 phishscore=0 mlxlogscore=847 mlxscore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208110049 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Let's check if the UV really protected all the memory we donated. Signed-off-by: Janosch Frank Reviewed-by: Nico Boehr Reviewed-by: Claudio Imbrenda --- This patch is clearly cursed :) --- s390x/uv-host.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/s390x/uv-host.c b/s390x/uv-host.c index dfcebe10..191e8b3f 100644 --- a/s390x/uv-host.c +++ b/s390x/uv-host.c @@ -45,6 +45,32 @@ static void cpu_loop(void) for (;;) {} } +/* + * Checks if a memory area is protected as secure memory. + * Will return true if all pages are protected, false otherwise. + */ +static bool access_check_3d(uint8_t *access_ptr, uint64_t len) +{ + assert(!(len & ~PAGE_MASK)); + assert(!((uint64_t)access_ptr & ~PAGE_MASK)); + + while (len) { + expect_pgm_int(); + READ_ONCE(*access_ptr); + if (clear_pgm_int() != PGM_INT_CODE_SECURE_STOR_ACCESS) + return false; + expect_pgm_int(); + WRITE_ONCE(*access_ptr, 42); + if (clear_pgm_int() != PGM_INT_CODE_SECURE_STOR_ACCESS) + return false; + + access_ptr += PAGE_SIZE; + len -= PAGE_SIZE; + } + + return true; +} + 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 }, @@ -332,6 +358,10 @@ static void test_cpu_create(void) report(rc == 0 && uvcb_csc.header.rc == UVC_RC_EXECUTED && uvcb_csc.cpu_handle, "success"); + rc = access_check_3d((uint8_t *)uvcb_csc.stor_origin, + uvcb_qui.cpu_stor_len); + report(rc, "Storage protection"); + 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); @@ -430,6 +460,13 @@ static void test_config_create(void) rc = uv_call(0, (uint64_t)&uvcb_cgc); report(rc == 0 && uvcb_cgc.header.rc == UVC_RC_EXECUTED, "successful"); + rc = access_check_3d((uint8_t *)uvcb_cgc.conf_base_stor_origin, + uvcb_qui.conf_base_phys_stor_len); + report(rc, "Base storage protection"); + + rc = access_check_3d((uint8_t *)uvcb_cgc.conf_var_stor_origin, vsize); + report(rc, "Variable storage protection"); + uvcb_cgc.header.rc = 0; uvcb_cgc.header.rrc = 0; tmp = uvcb_cgc.guest_handle;