From patchwork Thu Dec 1 08:46:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Boehr X-Patchwork-Id: 13061069 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 906D8C43217 for ; Thu, 1 Dec 2022 08:48:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229971AbiLAIsJ (ORCPT ); Thu, 1 Dec 2022 03:48:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43952 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229877AbiLAIrf (ORCPT ); Thu, 1 Dec 2022 03:47:35 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED3DF2529C for ; Thu, 1 Dec 2022 00:46:49 -0800 (PST) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B18MkD7018156 for ; Thu, 1 Dec 2022 08:46:49 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=9A9jejsL7eu/3kxWMCwqZytU8Zdc775D/epFSBVtxhw=; b=DPFecrwidvyDgVvfJuCy/qc4I4+4TOdwD8z9pco5LsO3ZnXbvfq3NOg89S3CVwnd5rKg omVIAYm6hB5nmCrGAqzfOVXQgae4lzWmRq6IyzlMQaaf7fk8v2omXO0LL0bdNOvBx84K I3wmeZFqOx4k9qQj9JKP8SUYbUmKV+4M48otbabt2SGWS5iWFS/VoU16ZCOeZAD8JP69 jd2m78ZlRVY3QSmnbhux7fEROWerjWGxdL478H7r8GfQQWh+1KUZ71a5qniGLt5iYQbj ycaay1V0YPYnyvBM1D5j4l3Ue+EhFLyu9/Ws5I4NPJXBtmcP7l5xqoUNPotLr8EWY7ei gA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3m6qqpt7g5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 01 Dec 2022 08:46:49 +0000 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2B18e8sp031224 for ; Thu, 1 Dec 2022 08:46:49 GMT Received: from ppma06fra.de.ibm.com (48.49.7a9f.ip4.static.sl-reverse.com [159.122.73.72]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3m6qqpt7f7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Dec 2022 08:46:48 +0000 Received: from pps.filterd (ppma06fra.de.ibm.com [127.0.0.1]) by ppma06fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 2B18aoTD031592; Thu, 1 Dec 2022 08:46:46 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma06fra.de.ibm.com with ESMTP id 3m3a2hw3q2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Dec 2022 08:46:46 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2B18khUt9175776 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 1 Dec 2022 08:46:43 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 882B2AE045; Thu, 1 Dec 2022 08:46:43 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 51072AE051; Thu, 1 Dec 2022 08:46:43 +0000 (GMT) Received: from a46lp57.lnxne.boe (unknown [9.152.108.100]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 1 Dec 2022 08:46:43 +0000 (GMT) From: Nico Boehr To: kvm@vger.kernel.org Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com, pbonzini@redhat.com Subject: [kvm-unit-tests PATCH v1 1/3] s390x: add library for skey-related functions Date: Thu, 1 Dec 2022 09:46:40 +0100 Message-Id: <20221201084642.3747014-2-nrb@linux.ibm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221201084642.3747014-1-nrb@linux.ibm.com> References: <20221201084642.3747014-1-nrb@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: RKPIgWG08OefHfw3pNuaQr0VWa6VwNcv X-Proofpoint-ORIG-GUID: DvnHc9AHXcb5ckTEJ_xCKt5rwjyUntlK X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-01_04,2022-11-30_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 spamscore=0 priorityscore=1501 suspectscore=0 clxscore=1015 mlxscore=0 malwarescore=0 adultscore=0 lowpriorityscore=0 impostorscore=0 mlxlogscore=750 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212010057 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Upcoming changes will add a test which is very similar to the existing skey migration test. To reduce code duplication, move the common functions to a library which can be re-used by both tests. Signed-off-by: Nico Boehr --- lib/s390x/skey.c | 92 ++++++++++++++++++++++++++++++++++++++++++ lib/s390x/skey.h | 32 +++++++++++++++ s390x/Makefile | 1 + s390x/migration-skey.c | 44 +++----------------- 4 files changed, 131 insertions(+), 38 deletions(-) create mode 100644 lib/s390x/skey.c create mode 100644 lib/s390x/skey.h diff --git a/lib/s390x/skey.c b/lib/s390x/skey.c new file mode 100644 index 000000000000..100f0949a244 --- /dev/null +++ b/lib/s390x/skey.c @@ -0,0 +1,92 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Storage key migration test library + * + * Copyright IBM Corp. 2022 + * + * Authors: + * Nico Boehr + */ + +#include +#include +#include +#include + +/* + * Set storage keys on pagebuf. + * pagebuf must point to page_count consecutive pages. + */ +void skey_set_keys(uint8_t *pagebuf, unsigned long page_count) +{ + unsigned char key_to_set; + unsigned long i; + + for (i = 0; i < page_count; i++) { + /* + * Storage keys are 7 bit, lowest bit is always returned as zero + * by iske. + * This loop will set all 7 bits which means we set fetch + * protection as well as reference and change indication for + * some keys. + */ + key_to_set = i * 2; + set_storage_key(pagebuf + i * PAGE_SIZE, key_to_set, 1); + } +} + +/* + * Verify storage keys on pagebuf. + * Storage keys must have been set by skey_set_keys on pagebuf before. + * + * If storage keys match the expected result, will return a skey_verify_result + * with verify_failed false. All other fields are then invalid. + * If there is a mismatch, returned struct will have verify_failed true and will + * be filled with the details on the first mismatch encountered. + */ +struct skey_verify_result skey_verify_keys(uint8_t *pagebuf, unsigned long page_count) +{ + union skey expected_key, actual_key; + struct skey_verify_result result = { + .verify_failed = true + }; + uint8_t *cur_page; + unsigned long i; + + for (i = 0; i < page_count; i++) { + cur_page = pagebuf + i * PAGE_SIZE; + actual_key.val = get_storage_key(cur_page); + expected_key.val = i * 2; + + /* + * The PoP neither gives a guarantee that the reference bit is + * accurate nor that it won't be cleared by hardware. Hence we + * don't rely on it and just clear the bits to avoid compare + * errors. + */ + actual_key.str.rf = 0; + expected_key.str.rf = 0; + + if (actual_key.val != expected_key.val) { + result.expected_key.val = expected_key.val; + result.actual_key.val = actual_key.val; + result.page_mismatch_idx = i; + result.page_mismatch_addr = (unsigned long)cur_page; + return result; + } + } + + result.verify_failed = false; + return result; +} + +void skey_report_verify(struct skey_verify_result * const result) +{ + if (result->verify_failed) + report_fail("page skey mismatch: first page idx = %lu, addr = 0x%lx, " + "expected_key = 0x%x, actual_key = 0x%x", + result->page_mismatch_idx, result->page_mismatch_addr, + result->expected_key.val, result->actual_key.val); + else + report_pass("skeys match"); +} diff --git a/lib/s390x/skey.h b/lib/s390x/skey.h new file mode 100644 index 000000000000..a0f8caa1270b --- /dev/null +++ b/lib/s390x/skey.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Storage key migration test library + * + * Copyright IBM Corp. 2022 + * + * Authors: + * Nico Boehr + */ +#ifndef S390X_SKEY_H +#define S390X_SKEY_H + +#include +#include +#include +#include + +struct skey_verify_result { + bool verify_failed; + union skey expected_key; + union skey actual_key; + unsigned long page_mismatch_idx; + unsigned long page_mismatch_addr; +}; + +void skey_set_keys(uint8_t *pagebuf, unsigned long page_count); + +struct skey_verify_result skey_verify_keys(uint8_t *pagebuf, unsigned long page_count); + +void skey_report_verify(struct skey_verify_result * const result); + +#endif /* S390X_SKEY_H */ diff --git a/s390x/Makefile b/s390x/Makefile index bf1504f9d58c..d097b7071dfb 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -99,6 +99,7 @@ cflatobjs += lib/s390x/malloc_io.o cflatobjs += lib/s390x/uv.o cflatobjs += lib/s390x/sie.o cflatobjs += lib/s390x/fault.o +cflatobjs += lib/s390x/skey.o OBJDIRS += lib/s390x diff --git a/s390x/migration-skey.c b/s390x/migration-skey.c index b7bd82581abe..fed6fc1ed0f8 100644 --- a/s390x/migration-skey.c +++ b/s390x/migration-skey.c @@ -10,55 +10,23 @@ #include #include -#include -#include -#include #include +#include #define NUM_PAGES 128 -static uint8_t pagebuf[NUM_PAGES][PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); +static uint8_t pagebuf[NUM_PAGES * PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); static void test_migration(void) { - union skey expected_key, actual_key; - int i, key_to_set, key_mismatches = 0; + struct skey_verify_result result; - for (i = 0; i < NUM_PAGES; i++) { - /* - * Storage keys are 7 bit, lowest bit is always returned as zero - * by iske. - * This loop will set all 7 bits which means we set fetch - * protection as well as reference and change indication for - * some keys. - */ - key_to_set = i * 2; - set_storage_key(pagebuf[i], key_to_set, 1); - } + skey_set_keys(pagebuf, NUM_PAGES); puts("Please migrate me, then press return\n"); (void)getchar(); - for (i = 0; i < NUM_PAGES; i++) { - actual_key.val = get_storage_key(pagebuf[i]); - expected_key.val = i * 2; - - /* - * The PoP neither gives a guarantee that the reference bit is - * accurate nor that it won't be cleared by hardware. Hence we - * don't rely on it and just clear the bits to avoid compare - * errors. - */ - actual_key.str.rf = 0; - expected_key.str.rf = 0; - - /* don't log anything when key matches to avoid spamming the log */ - if (actual_key.val != expected_key.val) { - key_mismatches++; - report_fail("page %d expected_key=0x%x actual_key=0x%x", i, expected_key.val, actual_key.val); - } - } - - report(!key_mismatches, "skeys after migration match"); + result = skey_verify_keys(pagebuf, NUM_PAGES); + skey_report_verify(&result); } int main(void) From patchwork Thu Dec 1 08:46:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Boehr X-Patchwork-Id: 13061072 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 149ACC4321E for ; Thu, 1 Dec 2022 08:48:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230003AbiLAIsR (ORCPT ); Thu, 1 Dec 2022 03:48:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229885AbiLAIrh (ORCPT ); Thu, 1 Dec 2022 03:47:37 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD7108932B for ; Thu, 1 Dec 2022 00:46:50 -0800 (PST) Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B18etXd026068 for ; Thu, 1 Dec 2022 08:46:50 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=JkgfLF8oFDY5kHIkU4EbGBISmMhsaXef0e0sBa4rfj4=; b=TNm6lKr1FV5ERb3iRx2OwGm8+USqT+kGPAQlZ1HXZmZwN/KWkTsQzl2TduftB9lve2be c/ifwkcPV6J++PcHcACqVLG6I68DidjVJT5mclSs7v3MbVu9NhyoSPoMHTqhvDRgeeoy D3OOuKec8Z+ALqPb5B21RAMifQqKouabvveB0a7YNO++RbQeWv17Q+NHTeQDz9YO4Mor nYTaW/Zg5q+/ifwvOHMRq5NAelNRJvtf10jbwrtKQW29fkLXq3QXNSXZMT+ESSNorV6J q0q+E7xyoyKfyDotIOFQ+iT2Abff60vwg+8MRiaJ9Do8Oir+UyoDLD9xPUoG9gg5rMM/ NQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3m6r8bscfy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 01 Dec 2022 08:46:49 +0000 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2B18knS0019496 for ; Thu, 1 Dec 2022 08:46:49 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 3m6r8bsces-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Dec 2022 08:46: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 2B18aJpj018278; Thu, 1 Dec 2022 08:46:46 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma06ams.nl.ibm.com with ESMTP id 3m3a2hy2sn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Dec 2022 08:46:46 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2B18khEo9175778 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 1 Dec 2022 08:46:43 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C770FAE045; Thu, 1 Dec 2022 08:46:43 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 91C72AE04D; Thu, 1 Dec 2022 08:46:43 +0000 (GMT) Received: from a46lp57.lnxne.boe (unknown [9.152.108.100]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 1 Dec 2022 08:46:43 +0000 (GMT) From: Nico Boehr To: kvm@vger.kernel.org Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com, pbonzini@redhat.com Subject: [kvm-unit-tests PATCH v1 2/3] lib: s390x: skey: add seed value for storage keys Date: Thu, 1 Dec 2022 09:46:41 +0100 Message-Id: <20221201084642.3747014-3-nrb@linux.ibm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221201084642.3747014-1-nrb@linux.ibm.com> References: <20221201084642.3747014-1-nrb@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Gl5NzhpJtcQomgKdpmJxcmvw7jo3QUAP X-Proofpoint-ORIG-GUID: G8MPOZhJH_uqiqB6A6kOZcDgc4WHWrmf X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-01_04,2022-11-30_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 mlxlogscore=807 lowpriorityscore=0 spamscore=0 mlxscore=0 malwarescore=0 priorityscore=1501 impostorscore=0 adultscore=0 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212010057 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Upcoming changes will change storage keys in a loop. To make sure each iteration of the loops sets different keys, add variants of the storage key library functions which allow to specify a seed. Signed-off-by: Nico Boehr --- lib/s390x/skey.c | 12 +++++++----- lib/s390x/skey.h | 14 ++++++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/lib/s390x/skey.c b/lib/s390x/skey.c index 100f0949a244..4ab0828ee98f 100644 --- a/lib/s390x/skey.c +++ b/lib/s390x/skey.c @@ -14,10 +14,11 @@ #include /* - * Set storage keys on pagebuf. + * Set storage keys on pagebuf with a seed for the storage keys. * pagebuf must point to page_count consecutive pages. + * Only the lower seven bits of the seed are considered. */ -void skey_set_keys(uint8_t *pagebuf, unsigned long page_count) +void skey_set_keys_with_seed(uint8_t *pagebuf, unsigned long page_count, unsigned char seed) { unsigned char key_to_set; unsigned long i; @@ -30,7 +31,7 @@ void skey_set_keys(uint8_t *pagebuf, unsigned long page_count) * protection as well as reference and change indication for * some keys. */ - key_to_set = i * 2; + key_to_set = (i ^ seed) * 2; set_storage_key(pagebuf + i * PAGE_SIZE, key_to_set, 1); } } @@ -38,13 +39,14 @@ void skey_set_keys(uint8_t *pagebuf, unsigned long page_count) /* * Verify storage keys on pagebuf. * Storage keys must have been set by skey_set_keys on pagebuf before. + * skey_set_keys must have been called with the same seed value. * * If storage keys match the expected result, will return a skey_verify_result * with verify_failed false. All other fields are then invalid. * If there is a mismatch, returned struct will have verify_failed true and will * be filled with the details on the first mismatch encountered. */ -struct skey_verify_result skey_verify_keys(uint8_t *pagebuf, unsigned long page_count) +struct skey_verify_result skey_verify_keys_with_seed(uint8_t *pagebuf, unsigned long page_count, unsigned char seed) { union skey expected_key, actual_key; struct skey_verify_result result = { @@ -56,7 +58,7 @@ struct skey_verify_result skey_verify_keys(uint8_t *pagebuf, unsigned long page_ for (i = 0; i < page_count; i++) { cur_page = pagebuf + i * PAGE_SIZE; actual_key.val = get_storage_key(cur_page); - expected_key.val = i * 2; + expected_key.val = (i ^ seed) * 2; /* * The PoP neither gives a guarantee that the reference bit is diff --git a/lib/s390x/skey.h b/lib/s390x/skey.h index a0f8caa1270b..bba1c131276d 100644 --- a/lib/s390x/skey.h +++ b/lib/s390x/skey.h @@ -23,9 +23,19 @@ struct skey_verify_result { unsigned long page_mismatch_addr; }; -void skey_set_keys(uint8_t *pagebuf, unsigned long page_count); +void skey_set_keys_with_seed(uint8_t *pagebuf, unsigned long page_count, unsigned char seed); -struct skey_verify_result skey_verify_keys(uint8_t *pagebuf, unsigned long page_count); +static inline void skey_set_keys(uint8_t *pagebuf, unsigned long page_count) +{ + skey_set_keys_with_seed(pagebuf, page_count, 0); +} + +struct skey_verify_result skey_verify_keys_with_seed(uint8_t *pagebuf, unsigned long page_count, unsigned char seed); + +static inline struct skey_verify_result skey_verify_keys(uint8_t *pagebuf, unsigned long page_count) +{ + return skey_verify_keys_with_seed(pagebuf, page_count, 0); +} void skey_report_verify(struct skey_verify_result * const result); From patchwork Thu Dec 1 08:46:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Boehr X-Patchwork-Id: 13061071 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 D4D1FC43217 for ; Thu, 1 Dec 2022 08:48:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229916AbiLAIsP (ORCPT ); Thu, 1 Dec 2022 03:48:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229843AbiLAIrg (ORCPT ); Thu, 1 Dec 2022 03:47:36 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6606288B5A for ; Thu, 1 Dec 2022 00:46:50 -0800 (PST) Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 2B18ihUf005191 for ; Thu, 1 Dec 2022 08:46:50 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=aCuJ66hDc+FTXapIKCGJxRZSHMW6ebvGa8EMLnUV81E=; b=F2qsIZ5igvG4sPsFfGIFfwzye5ZsaGIM+Sk13zclwYHiujA9QZyUf+SYwryoe6a9Cfcr 6af90L0Kz1IDl39Fdd7jW9mKPQQBpu2NC4ARSgIwT0KLdyD6RYMa5lZDGDs/tFoaSWLe JApe9+Ury0V+hnQLRqpmrzz82ww/sRwFob1+EErDjBk16SPtaU2PVPkjwImU9FXPXZbw 0pKhiAWXM9j6o2UEehyf/IEgRq0Ad5eHLNVF+WHz5w5vahYY6PiyHPcbq9wRfQBJOGIa 3+Zm4NR2CBrRi3DTSiUec2OajGKJnaipcjby338DVjKfXT9ZyZzgcyGUopEyXI+t3r+u Hg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3m6s1e822j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 01 Dec 2022 08:46:49 +0000 Received: from m0098410.ppops.net (m0098410.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 2B18ikmu005477 for ; Thu, 1 Dec 2022 08:46:49 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3m6s1e821t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Dec 2022 08:46:49 +0000 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 2B18ZtN9029645; Thu, 1 Dec 2022 08:46:47 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma04ams.nl.ibm.com with ESMTP id 3m3ae9f1nr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 01 Dec 2022 08:46:47 +0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 2B18kiFl64094578 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 1 Dec 2022 08:46:44 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 14D1CAE045; Thu, 1 Dec 2022 08:46:44 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D2DEFAE051; Thu, 1 Dec 2022 08:46:43 +0000 (GMT) Received: from a46lp57.lnxne.boe (unknown [9.152.108.100]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 1 Dec 2022 08:46:43 +0000 (GMT) From: Nico Boehr To: kvm@vger.kernel.org Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com, pbonzini@redhat.com Subject: [kvm-unit-tests PATCH v1 3/3] s390x: add storage key test during migration Date: Thu, 1 Dec 2022 09:46:42 +0100 Message-Id: <20221201084642.3747014-4-nrb@linux.ibm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20221201084642.3747014-1-nrb@linux.ibm.com> References: <20221201084642.3747014-1-nrb@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: jnxnRiUQYz4umfqglDewWlPpJK7v1HUX X-Proofpoint-GUID: LOZfeddWrAOVmJpCeQFrYRhc5G82UGAq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.219,Aquarius:18.0.895,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2022-12-01_04,2022-11-30_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 malwarescore=0 adultscore=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 lowpriorityscore=0 mlxscore=0 bulkscore=0 clxscore=1015 spamscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2210170000 definitions=main-2212010057 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add a test which modifies storage keys while migration is in progress. Signed-off-by: Nico Boehr --- s390x/Makefile | 1 + s390x/migration-during-skey.c | 103 ++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 5 ++ 3 files changed, 109 insertions(+) create mode 100644 s390x/migration-during-skey.c diff --git a/s390x/Makefile b/s390x/Makefile index d097b7071dfb..d9ba9b5fc392 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -39,6 +39,7 @@ tests += $(TEST_DIR)/panic-loop-extint.elf tests += $(TEST_DIR)/panic-loop-pgm.elf tests += $(TEST_DIR)/migration-sck.elf tests += $(TEST_DIR)/exittime.elf +tests += $(TEST_DIR)/migration-during-skey.elf pv-tests += $(TEST_DIR)/pv-diags.elf diff --git a/s390x/migration-during-skey.c b/s390x/migration-during-skey.c new file mode 100644 index 000000000000..bd0e6feb02bc --- /dev/null +++ b/s390x/migration-during-skey.c @@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Perform storage key operations during migration + * + * Copyright IBM Corp. 2022 + * + * Authors: + * Nico Boehr + */ + +#include +#include +#include +#include +#include +#include + +#define NUM_PAGES 128 +static uint8_t pagebuf[NUM_PAGES * PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); + +static unsigned int thread_iters; +static bool thread_should_exit; +static bool thread_exited; +static struct skey_verify_result result; + +static void test_skeys_during_migration(void) +{ + while (!READ_ONCE(thread_should_exit)) { + skey_set_keys_with_seed(pagebuf, NUM_PAGES, thread_iters); + + result = skey_verify_keys_with_seed(pagebuf, NUM_PAGES, thread_iters); + + /* + * Always increment even if the verify fails. This ensures primary CPU knows where + * we left off and can do an additional verify round after migration finished. + */ + thread_iters++; + + if (result.verify_failed) + break; + } + + WRITE_ONCE(thread_exited, 1); +} + +static void migrate_once(void) +{ + static bool migrated; + + if (migrated) + return; + + migrated = true; + puts("Please migrate me, then press return\n"); + (void)getchar(); +} + +int main(void) +{ + report_prefix_push("migration-skey"); + if (test_facility(169)) { + report_skip("storage key removal facility is active"); + goto error; + } + + if (smp_query_num_cpus() == 1) { + report_skip("need at least 2 cpus for this test"); + goto error; + } + + smp_cpu_setup(1, PSW_WITH_CUR_MASK(test_skeys_during_migration)); + + migrate_once(); + + WRITE_ONCE(thread_should_exit, 1); + + while (!thread_exited) + mb(); + + report_info("thread completed %u iterations", thread_iters); + + report_prefix_push("during migration"); + skey_report_verify(&result); + report_prefix_pop(); + + /* + * Verification of skeys occurs on the thread. We don't know if we + * were still migrating during the verification. + * To be sure, make another verification round after the migration + * finished to catch skeys which might not have been migrated + * correctly. + */ + report_prefix_push("after migration"); + assert(thread_iters > 0); + result = skey_verify_keys_with_seed(pagebuf, NUM_PAGES, thread_iters - 1); + skey_report_verify(&result); + report_prefix_pop(); + +error: + migrate_once(); + report_prefix_pop(); + return report_summary(); +} diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index 3caf81eda396..855c352929a4 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -208,3 +208,8 @@ groups = migration [exittime] file = exittime.elf smp = 2 + +[migration-during-skey] +file = migration-during-skey.elf +smp = 2 +groups = migration