From patchwork Thu Jan 5 12:15:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Imbrenda X-Patchwork-Id: 13089765 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 D51AFC53210 for ; Thu, 5 Jan 2023 12:15:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233023AbjAEMPv (ORCPT ); Thu, 5 Jan 2023 07:15:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233090AbjAEMPr (ORCPT ); Thu, 5 Jan 2023 07:15:47 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACB76559DE for ; Thu, 5 Jan 2023 04:15:46 -0800 (PST) Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 305BooMZ011189 for ; Thu, 5 Jan 2023 12:15:46 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 : content-transfer-encoding : mime-version; s=pp1; bh=tkDnMC00Tn2Q5YFCgM82W0T5/cOUQ2OtxDaLIVkEBvg=; b=o5C/OqTVatSyP8PiTNKY8H3VY2reunJfE1zbOr5pH7V9WA+Od8gtvY0Rsbg0nIJy6Htf 9patrmM84t3XJhzKnaXOOZp3Jt6DM6Uzl42b/pwytZkRiDSmq/uopWdeWnda3kvJy2om UfPABtVlz2WqGHsVZNyooc9hMG+AqSwLd+0OC8yIHrZ3KZMiDGQit6l0NBRRaNPsqpRi uTT1f6I9Buk7s7Hi71YvEdxi5b1GMt3Rx6Yt/nxgJ1ACkkFBdUGu/kfGnU/HtYLdoSik P9uhWQfq1jrzCUdocd5logg38pAeCfM5i75Slht0WoVZNK1IROLcbolSpIZlpBxp9iGq Zg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mwx1kggxe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 05 Jan 2023 12:15:46 +0000 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 305BrFHC019519 for ; Thu, 5 Jan 2023 12:15:45 GMT Received: from ppma02fra.de.ibm.com (47.49.7a9f.ip4.static.sl-reverse.com [159.122.73.71]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mwx1kggwr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 Jan 2023 12:15:45 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 3050abUj018137; Thu, 5 Jan 2023 12:15:43 GMT Received: from smtprelay06.fra02v.mail.ibm.com ([9.218.2.230]) by ppma02fra.de.ibm.com (PPS) with ESMTPS id 3mtcq6vwxh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 Jan 2023 12:15:43 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay06.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 305CFdaZ20054348 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 5 Jan 2023 12:15:40 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CB12A2004B; Thu, 5 Jan 2023 12:15:39 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6938220040; Thu, 5 Jan 2023 12:15:39 +0000 (GMT) Received: from p-imbrenda.ibmuc.com (unknown [9.171.26.82]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 5 Jan 2023 12:15:39 +0000 (GMT) From: Claudio Imbrenda To: pbonzini@redhat.com, thuth@redhat.com Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, Nico Boehr , Janis Schoetterl-Glausch Subject: [kvm-unit-tests GIT PULL 1/4] lib: s390x: add PSW and PSW_WITH_CUR_MASK macros Date: Thu, 5 Jan 2023 13:15:35 +0100 Message-Id: <20230105121538.52008-2-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230105121538.52008-1-imbrenda@linux.ibm.com> References: <20230105121538.52008-1-imbrenda@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: VxLiAJugX7D9l_myOmhjcCBpvqTK08X4 X-Proofpoint-GUID: SDDEUqboc-e9Dtsg5Bdc583TLCB4pi0X X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-05_04,2023-01-04_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 mlxlogscore=985 suspectscore=0 bulkscore=0 mlxscore=0 phishscore=0 priorityscore=1501 adultscore=0 spamscore=0 clxscore=1015 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301050095 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Since a lot of code starts new CPUs using the current PSW mask, add two macros to streamline the creation of generic PSWs and PSWs with the current program mask. Reviewed-by: Nico Boehr Reviewed-by: Janis Schoetterl-Glausch Reviewed-by: Janosch Frank Link: https://lore.kernel.org/r/20221130154038.70492-2-imbrenda@linux.ibm.com Signed-off-by: Claudio Imbrenda Message-Id: <20221130154038.70492-2-imbrenda@linux.ibm.com> --- lib/s390x/asm/arch_def.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h index 783a7eaa..bb26e008 100644 --- a/lib/s390x/asm/arch_def.h +++ b/lib/s390x/asm/arch_def.h @@ -41,6 +41,8 @@ struct psw { uint64_t addr; }; +#define PSW(m, a) ((struct psw){ .mask = (m), .addr = (uint64_t)(a) }) + struct short_psw { uint32_t mask; uint32_t addr; @@ -321,6 +323,8 @@ static inline uint64_t extract_psw_mask(void) return (uint64_t) mask_upper << 32 | mask_lower; } +#define PSW_WITH_CUR_MASK(addr) PSW(extract_psw_mask(), (addr)) + static inline void load_psw_mask(uint64_t mask) { struct psw psw = { From patchwork Thu Jan 5 12:15:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Imbrenda X-Patchwork-Id: 13089768 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 9B286C3DA7D for ; Thu, 5 Jan 2023 12:15:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232427AbjAEMP4 (ORCPT ); Thu, 5 Jan 2023 07:15:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233024AbjAEMPw (ORCPT ); Thu, 5 Jan 2023 07:15:52 -0500 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E53B44C7B for ; Thu, 5 Jan 2023 04:15:47 -0800 (PST) Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 305CDqNH031751 for ; Thu, 5 Jan 2023 12:15:46 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 : content-transfer-encoding : mime-version; s=pp1; bh=PJbQIz/zbNwA7ijTPNjmFyiicQpm5G7XsywY/uXc/ig=; b=mbCzlcKm1lj9AR3ZFP6gvyHsSb1IV8xPzR51I4OC/qvvw10ipHAfQusoCZGnrknemikG 43t6eikf5EOEQF1XKB/kx3bo0VS3+bs+aFn462FzfpWc6yfveuACBraiamuBfHmEMGxP uuAbaGb9yXaZG1pcS9a6kJ/vo8Xf9eiMX98i76z3GmK3re0EFFOuiPm7dhm8rkplUWQH 1cOnZ00+d9yftYwVAjUFahDBAdVcs+T5UJ+731fpETV10lpgymiAHlCQv64vHejYDqRs ht2l6LWPytyiu+0YBCHRh+fsh6pNLsBYcxrCBKNJZcde+3/uq22gXA5DCuHVxP6fGEKJ ZA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mwxc9g0yy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 05 Jan 2023 12:15:46 +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 305CFJPG003985 for ; Thu, 5 Jan 2023 12:15:45 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mwxc9g0ya-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 Jan 2023 12:15:45 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 305BtNSl007699; Thu, 5 Jan 2023 12:15:44 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma03ams.nl.ibm.com (PPS) with ESMTPS id 3mtcq6er60-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 Jan 2023 12:15:43 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 305CFeSH53215544 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 5 Jan 2023 12:15:40 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3A54C20043; Thu, 5 Jan 2023 12:15:40 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E1D7420040; Thu, 5 Jan 2023 12:15:39 +0000 (GMT) Received: from p-imbrenda.ibmuc.com (unknown [9.171.26.82]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 5 Jan 2023 12:15:39 +0000 (GMT) From: Claudio Imbrenda To: pbonzini@redhat.com, thuth@redhat.com Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, Janis Schoetterl-Glausch Subject: [kvm-unit-tests GIT PULL 2/4] s390x: use the new PSW and PSW_WITH_CUR_MASK macros Date: Thu, 5 Jan 2023 13:15:36 +0100 Message-Id: <20230105121538.52008-3-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230105121538.52008-1-imbrenda@linux.ibm.com> References: <20230105121538.52008-1-imbrenda@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: mSPJvl-21jNQfmV8IuMM1MAhQErnwcIh X-Proofpoint-ORIG-GUID: 3DvPurS7WgtB6tn2libXNra0fWubEpi9 X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-05_04,2023-01-04_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 priorityscore=1501 impostorscore=0 malwarescore=0 mlxscore=0 phishscore=0 suspectscore=0 spamscore=0 bulkscore=0 mlxlogscore=951 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301050095 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Use the new macros in the existing code. No functional changes intended. Reviewed-by: Janis Schoetterl-Glausch Reviewed-by: Janosch Frank Link: https://lore.kernel.org/r/20221130154038.70492-3-imbrenda@linux.ibm.com Signed-off-by: Claudio Imbrenda Message-Id: <20221130154038.70492-3-imbrenda@linux.ibm.com> --- s390x/adtl-status.c | 24 ++++---------------- s390x/firq.c | 5 +---- s390x/migration.c | 6 +---- s390x/skrf.c | 7 +----- s390x/smp.c | 53 ++++++++++----------------------------------- s390x/uv-host.c | 5 +---- 6 files changed, 19 insertions(+), 81 deletions(-) diff --git a/s390x/adtl-status.c b/s390x/adtl-status.c index 9fb76319..2db650a1 100644 --- a/s390x/adtl-status.c +++ b/s390x/adtl-status.c @@ -205,16 +205,11 @@ static void restart_write_vector(void) static void cpu_write_magic_to_vector_regs(uint16_t cpu_idx) { - struct psw new_psw; - smp_cpu_stop(cpu_idx); - new_psw.mask = extract_psw_mask(); - new_psw.addr = (unsigned long)restart_write_vector; - set_flag(0); - smp_cpu_start(cpu_idx, new_psw); + smp_cpu_start(cpu_idx, PSW_WITH_CUR_MASK(restart_write_vector)); wait_for_flag(); } @@ -241,7 +236,6 @@ static int adtl_status_check_unmodified_fields_for_lc(unsigned long lc) static void __store_adtl_status_vector_lc(unsigned long lc) { uint32_t status = -1; - struct psw psw; int cc; report_prefix_pushf("LC %lu", lc); @@ -274,9 +268,7 @@ static void __store_adtl_status_vector_lc(unsigned long lc) * Destroy and re-initalize the CPU to fix that. */ smp_cpu_destroy(1); - psw.mask = extract_psw_mask(); - psw.addr = (unsigned long)test_func; - smp_cpu_setup(1, psw); + smp_cpu_setup(1, PSW_WITH_CUR_MASK(test_func)); out: report_prefix_pop(); @@ -325,16 +317,11 @@ static void restart_write_gs_regs(void) static void cpu_write_to_gs_regs(uint16_t cpu_idx) { - struct psw new_psw; - smp_cpu_stop(cpu_idx); - new_psw.mask = extract_psw_mask(); - new_psw.addr = (unsigned long)restart_write_gs_regs; - set_flag(0); - smp_cpu_start(cpu_idx, new_psw); + smp_cpu_start(cpu_idx, PSW_WITH_CUR_MASK(restart_write_gs_regs)); wait_for_flag(); } @@ -382,7 +369,6 @@ out: int main(void) { - struct psw psw; report_prefix_push("adtl_status"); if (smp_query_num_cpus() == 1) { @@ -391,9 +377,7 @@ int main(void) } /* Setting up the cpu to give it a stack and lowcore */ - psw.mask = extract_psw_mask(); - psw.addr = (unsigned long)test_func; - smp_cpu_setup(1, psw); + smp_cpu_setup(1, PSW_WITH_CUR_MASK(test_func)); smp_cpu_stop(1); test_store_adtl_status_unavail(); diff --git a/s390x/firq.c b/s390x/firq.c index b4b3542e..0d65d87f 100644 --- a/s390x/firq.c +++ b/s390x/firq.c @@ -33,7 +33,6 @@ static void wait_for_sclp_int(void) */ static void test_wait_state_delivery(void) { - struct psw psw; SCCBHeader *h; int ret; @@ -55,9 +54,7 @@ static void test_wait_state_delivery(void) sclp_mark_busy(); /* Start CPU #1 and let it wait for the interrupt. */ - psw.mask = extract_psw_mask(); - psw.addr = (unsigned long)wait_for_sclp_int; - ret = smp_cpu_setup(1, psw); + ret = smp_cpu_setup(1, PSW_WITH_CUR_MASK(wait_for_sclp_int)); /* This must not fail because we have at least 3 CPUs */ assert(!ret); diff --git a/s390x/migration.c b/s390x/migration.c index fe6ea836..269e272d 100644 --- a/s390x/migration.c +++ b/s390x/migration.c @@ -159,8 +159,6 @@ static void test_func(void) int main(void) { - struct psw psw; - /* don't say migrate here otherwise we will migrate right away */ report_prefix_push("migration"); @@ -170,9 +168,7 @@ int main(void) } /* Second CPU does the actual tests */ - psw.mask = extract_psw_mask(); - psw.addr = (unsigned long)test_func; - smp_cpu_setup(1, psw); + smp_cpu_setup(1, PSW_WITH_CUR_MASK(test_func)); /* wait for thread setup */ while(!flag_thread_complete) diff --git a/s390x/skrf.c b/s390x/skrf.c index 4cb563c3..e72a2b19 100644 --- a/s390x/skrf.c +++ b/s390x/skrf.c @@ -151,11 +151,6 @@ static void ecall_setup(void) 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."); @@ -163,7 +158,7 @@ static void test_exception_ext_new(void) return; } - smp_cpu_setup(1, psw); + smp_cpu_setup(1, PSW_WITH_CUR_MASK(ecall_setup)); wait_for_flag(); set_flag(0); diff --git a/s390x/smp.c b/s390x/smp.c index 91f3e3bc..2b03bf0c 100644 --- a/s390x/smp.c +++ b/s390x/smp.c @@ -101,12 +101,8 @@ static void test_func(void) static void test_start(void) { - struct psw psw; - psw.mask = extract_psw_mask(); - psw.addr = (unsigned long)test_func; - set_flag(0); - smp_cpu_start(1, psw); + smp_cpu_start(1, PSW_WITH_CUR_MASK(test_func)); wait_for_flag(); report_pass("start"); } @@ -120,8 +116,7 @@ static void test_restart(void) report_prefix_push("restart"); report_prefix_push("stopped"); - lc->restart_new_psw.mask = extract_psw_mask(); - lc->restart_new_psw.addr = (unsigned long)test_func; + lc->restart_new_psw = PSW_WITH_CUR_MASK(test_func); /* Make sure cpu is stopped */ smp_cpu_stop(1); @@ -256,7 +251,6 @@ static void test_set_prefix(void) struct lowcore *new_lc = alloc_pages_flags(1, AREA_DMA31); struct cpu *cpu1 = smp_cpu_from_idx(1); uint32_t status = 0; - struct psw new_psw; int cc; report_prefix_push("set prefix"); @@ -268,9 +262,7 @@ static void test_set_prefix(void) report_prefix_push("running"); set_flag(0); - new_psw.addr = (unsigned long)stpx_and_set_flag; - new_psw.mask = extract_psw_mask(); - smp_cpu_start(1, new_psw); + smp_cpu_start(1, PSW_WITH_CUR_MASK(stpx_and_set_flag)); wait_for_flag(); cpu1_prefix = 0xFFFFFFFF; @@ -326,7 +318,6 @@ static void call_received(void) static void test_calls(void) { int i; - struct psw psw; for (i = 0; i < ARRAY_SIZE(cases_sigp_call); i++) { current_sigp_call_case = &cases_sigp_call[i]; @@ -339,9 +330,7 @@ static void test_calls(void) } set_flag(0); - psw.mask = extract_psw_mask(); - psw.addr = (unsigned long)call_received; - smp_cpu_start(1, psw); + smp_cpu_start(1, PSW_WITH_CUR_MASK(call_received)); /* Wait until the receiver has finished setup */ wait_for_flag(); @@ -389,7 +378,6 @@ static void call_in_wait_cleanup(void) static void test_calls_in_wait(void) { int i; - struct psw psw; report_prefix_push("psw wait"); for (i = 0; i < ARRAY_SIZE(cases_sigp_call); i++) { @@ -404,9 +392,7 @@ static void test_calls_in_wait(void) /* Let the secondary CPU setup the external mask and the external interrupt cleanup function */ set_flag(0); - psw.mask = extract_psw_mask(); - psw.addr = (unsigned long)call_in_wait_setup; - smp_cpu_start(1, psw); + smp_cpu_start(1, PSW_WITH_CUR_MASK(call_in_wait_setup)); /* Wait until the receiver has finished setup */ wait_for_flag(); @@ -422,9 +408,7 @@ static void test_calls_in_wait(void) * wait until the CPU becomes operating (done by smp_cpu_start). */ smp_cpu_stop(1); - psw.mask = extract_psw_mask() | PSW_MASK_EXT | PSW_MASK_WAIT; - psw.addr = (unsigned long)call_in_wait_received; - smp_cpu_start(1, psw); + smp_cpu_start(1, PSW(extract_psw_mask() | PSW_MASK_EXT | PSW_MASK_WAIT, call_in_wait_received)); smp_sigp(1, current_sigp_call_case->call, 0, NULL); @@ -439,9 +423,7 @@ static void test_calls_in_wait(void) * to catch an interrupt that is presented twice since we would * disable the external call on the first interrupt. */ - psw.mask = extract_psw_mask(); - psw.addr = (unsigned long)call_in_wait_cleanup; - smp_cpu_start(1, psw); + smp_cpu_start(1, PSW_WITH_CUR_MASK(call_in_wait_cleanup)); /* Wait until the cleanup has been completed */ wait_for_flag(); @@ -478,15 +460,11 @@ static void test_func_initial(void) static void test_reset_initial(void) { struct cpu_status *status = alloc_pages_flags(0, AREA_DMA31); - struct psw psw; int i; - psw.mask = extract_psw_mask(); - psw.addr = (unsigned long)test_func_initial; - report_prefix_push("reset initial"); set_flag(0); - smp_cpu_start(1, psw); + smp_cpu_start(1, PSW_WITH_CUR_MASK(test_func_initial)); wait_for_flag(); smp_sigp(1, SIGP_INITIAL_CPU_RESET, 0, NULL); @@ -525,22 +503,16 @@ static void test_local_ints(void) static void test_reset(void) { - struct psw psw; - - psw.mask = extract_psw_mask(); - psw.addr = (unsigned long)test_func; - report_prefix_push("cpu reset"); smp_sigp(1, SIGP_EMERGENCY_SIGNAL, 0, NULL); smp_sigp(1, SIGP_EXTERNAL_CALL, 0, NULL); - smp_cpu_start(1, psw); + smp_cpu_start(1, PSW_WITH_CUR_MASK(test_func)); smp_sigp(1, SIGP_CPU_RESET, 0, NULL); report(smp_cpu_stopped(1), "cpu stopped"); set_flag(0); - psw.addr = (unsigned long)test_local_ints; - smp_cpu_start(1, psw); + smp_cpu_start(1, PSW_WITH_CUR_MASK(test_local_ints)); wait_for_flag(); report_pass("local interrupts cleared"); report_prefix_pop(); @@ -548,7 +520,6 @@ static void test_reset(void) int main(void) { - struct psw psw; report_prefix_push("smp"); if (smp_query_num_cpus() == 1) { @@ -557,9 +528,7 @@ int main(void) } /* Setting up the cpu to give it a stack and lowcore */ - psw.mask = extract_psw_mask(); - psw.addr = (unsigned long)test_func; - smp_cpu_setup(1, psw); + smp_cpu_setup(1, PSW_WITH_CUR_MASK(test_func)); smp_cpu_stop(1); test_start(); diff --git a/s390x/uv-host.c b/s390x/uv-host.c index 9f09f80e..33e6eec6 100644 --- a/s390x/uv-host.c +++ b/s390x/uv-host.c @@ -501,7 +501,6 @@ static void test_init(void) { int rc; uint64_t mem; - struct psw psw; /* Donated storage needs to be over 2GB */ mem = (uint64_t)memalign_pages_flags(SZ_1M, uvcb_qui.uv_base_stor_len, AREA_NORMAL); @@ -547,9 +546,7 @@ static void test_init(void) "storage below 2GB"); uvcb_init.stor_origin = mem; - psw.mask = extract_psw_mask(); - psw.addr = (unsigned long)cpu_loop; - smp_cpu_setup(1, psw); + smp_cpu_setup(1, PSW_WITH_CUR_MASK(cpu_loop)); rc = uv_call(0, (uint64_t)&uvcb_init); report(rc == 1 && uvcb_init.header.rc == 0x102, "too many running cpus"); From patchwork Thu Jan 5 12:15:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Imbrenda X-Patchwork-Id: 13089766 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 4C550C3DA7A for ; Thu, 5 Jan 2023 12:15:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233032AbjAEMPx (ORCPT ); Thu, 5 Jan 2023 07:15:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231579AbjAEMPw (ORCPT ); Thu, 5 Jan 2023 07:15:52 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8378358FAA for ; Thu, 5 Jan 2023 04:15:47 -0800 (PST) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 305Brf5T008300 for ; Thu, 5 Jan 2023 12:15:46 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 : content-transfer-encoding : mime-version; s=pp1; bh=4p+iSthvHkZy9KpKb7IDTuk3GVBW9fJ3pLrOldwiWpA=; b=B91sHkkQ33QRsoeLAdifAM18+GtHyhzTUqf064nHrlA9/0b60pAiIYxS8W5hkfvc6f9R D7FNYaSSB2uaflWUIrLDuWrJXKd+0GJTboIRNHpIB/A43veC3TaW5FAxsZJdL7Q65+9x qmSAhsSwVCB+H2DreebXGSjX2fRwqmYLKhn9X+Ql2tV0BDjLyPJ37EKPjEww2Yi9qSdz runG99SPuGY96bumP8w1jAr+JL6LJnUiJXMNMYDogYMBkns8XnSEsZgUObnmIfAMU9sb nozeKmQEgb+24sQIqq6XUFyy/yieH59Ye2NtV4ALwadb0CtxTXFm8LgV43eixKI8MLvt rA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3mwx2y8fas-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 05 Jan 2023 12:15:46 +0000 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 305CCthU019548 for ; Thu, 5 Jan 2023 12:15:46 GMT Received: from ppma04ams.nl.ibm.com (63.31.33a9.ip4.static.sl-reverse.com [169.51.49.99]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3mwx2y8fa9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 Jan 2023 12:15:46 +0000 Received: from pps.filterd (ppma04ams.nl.ibm.com [127.0.0.1]) by ppma04ams.nl.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 30590ooZ005147; Thu, 5 Jan 2023 12:15:44 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma04ams.nl.ibm.com (PPS) with ESMTPS id 3mtcq6er0m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 Jan 2023 12:15:44 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 305CFemI52494782 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 5 Jan 2023 12:15:40 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A216720040; Thu, 5 Jan 2023 12:15:40 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4DAA420049; Thu, 5 Jan 2023 12:15:40 +0000 (GMT) Received: from p-imbrenda.ibmuc.com (unknown [9.171.26.82]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 5 Jan 2023 12:15:40 +0000 (GMT) From: Claudio Imbrenda To: pbonzini@redhat.com, thuth@redhat.com Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, Nico Boehr , Nina Schoetterl-Glausch Subject: [kvm-unit-tests GIT PULL 3/4] s390x: add parallel skey migration test Date: Thu, 5 Jan 2023 13:15:37 +0100 Message-Id: <20230105121538.52008-4-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230105121538.52008-1-imbrenda@linux.ibm.com> References: <20230105121538.52008-1-imbrenda@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: l_ymrT16_CbUKT1aqbiHuWrRuQF6b7wc X-Proofpoint-GUID: wwxWbZ2T0aHwrZieIrq_O5-Cu8MxZoG1 X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-05_04,2023-01-04_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 mlxscore=0 clxscore=1015 malwarescore=0 spamscore=0 lowpriorityscore=0 bulkscore=0 impostorscore=0 adultscore=0 priorityscore=1501 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301050095 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Nico Boehr Right now, we have a test which sets storage keys, then migrates the VM and - after migration finished - verifies the skeys are still there. Add a new version of the test which changes storage keys while the migration is in progress. This is achieved by adding a command line argument to the existing migration-skey test. Signed-off-by: Nico Boehr Reviewed-by: Nina Schoetterl-Glausch Reviewed-by: Claudio Imbrenda Link: https://lore.kernel.org/r/20221220083030.30153-2-nrb@linux.ibm.com Message-Id: <20221220083030.30153-2-nrb@linux.ibm.com> Signed-off-by: Claudio Imbrenda --- s390x/migration-skey.c | 218 +++++++++++++++++++++++++++++++++++++---- s390x/unittests.cfg | 15 ++- 2 files changed, 210 insertions(+), 23 deletions(-) diff --git a/s390x/migration-skey.c b/s390x/migration-skey.c index a91eb6b5..8d6d8ecf 100644 --- a/s390x/migration-skey.c +++ b/s390x/migration-skey.c @@ -2,6 +2,12 @@ /* * Storage Key migration tests * + * There are two variants of this test: + * - sequential: set storage keys on some pages, migrates the VM and then + * verifies that the storage keys are still as we expect. + * - parallel: start migration and set and check storage keys on some + * pages while migration is in process. + * * Copyright IBM Corp. 2022 * * Authors: @@ -13,16 +19,45 @@ #include #include #include -#include +#include #include +#include + +struct verify_result { + bool verify_failed; + union skey expected_key; + union skey actual_key; + unsigned long page_mismatch_idx; + unsigned long page_mismatch_addr; +}; #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 struct verify_result result; + +static unsigned int thread_iters; +static bool thread_should_exit; +static bool thread_exited; + +static enum { + TEST_INVALID, + TEST_SEQUENTIAL, + TEST_PARALLEL +} arg_test_to_run; -static void test_migration(void) +/* + * Set storage key test pattern on pagebuf with a seed for the storage keys. + * + * Each page's storage key is generated by taking the page's index in pagebuf, + * XOR-ing that with the given seed and then multipling the result with two. + * + * Only the lower seven bits of the seed are considered. + */ +static void set_test_pattern(unsigned char seed) { - union skey expected_key, actual_key; - int i, key_to_set, key_mismatches = 0; + unsigned char key_to_set; + unsigned long i; for (i = 0; i < NUM_PAGES; i++) { /* @@ -32,15 +67,34 @@ static void test_migration(void) * 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); + key_to_set = (i ^ seed) * 2; + set_storage_key(pagebuf + i * PAGE_SIZE, key_to_set, 1); } +} - migrate_once(); +/* + * Verify storage keys on pagebuf. + * Storage keys must have been set by set_test_pattern on pagebuf before. + * set_test_pattern must have been called with the same seed value. + * + * If storage keys match the expected result, will return a 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. + */ +static struct verify_result verify_test_pattern(unsigned char seed) +{ + union skey expected_key, actual_key; + struct verify_result result = { + .verify_failed = true + }; + uint8_t *cur_page; + unsigned long i; for (i = 0; i < NUM_PAGES; i++) { - actual_key.val = get_storage_key(pagebuf[i]); - expected_key.val = i * 2; + cur_page = pagebuf + i * PAGE_SIZE; + actual_key.val = get_storage_key(cur_page); + expected_key.val = (i ^ seed) * 2; /* * The PoP neither gives a guarantee that the reference bit is @@ -51,27 +105,153 @@ static void test_migration(void) 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); + 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; } } - report(!key_mismatches, "skeys after migration match"); + result.verify_failed = false; + return result; +} + +static void report_verify_result(const struct verify_result * result) +{ + if (result->verify_failed) + report_fail("page skey mismatch: first page idx = %lu, addr = 0x%lx, " + "expected_key = 0x%02x, actual_key = 0x%02x", + result->page_mismatch_idx, result->page_mismatch_addr, + result->expected_key.val, result->actual_key.val); + else + report_pass("skeys match"); +} + +static void test_skey_migration_sequential(void) +{ + report_prefix_push("sequential"); + + set_test_pattern(0); + + migrate_once(); + + result = verify_test_pattern(0); + report_verify_result(&result); + + report_prefix_pop(); +} + +static void set_skeys_thread(void) +{ + while (!READ_ONCE(thread_should_exit)) { + set_test_pattern(thread_iters); + + result = verify_test_pattern(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 test_skey_migration_parallel(void) +{ + report_prefix_push("parallel"); + + 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(set_skeys_thread)); + + migrate_once(); + + WRITE_ONCE(thread_should_exit, 1); + + while (!READ_ONCE(thread_exited)) + ; + + /* Ensure we read result and thread_iters below from memory after thread exited */ + mb(); + report_info("thread completed %u iterations", thread_iters); + + report_prefix_push("during migration"); + report_verify_result(&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 = verify_test_pattern(thread_iters - 1); + report_verify_result(&result); + report_prefix_pop(); + +error: + report_prefix_pop(); +} + +static void print_usage(void) +{ + report_info("Usage: migration-skey [--parallel|--sequential]"); +} + +static void parse_args(int argc, char **argv) +{ + if (argc < 2) { + /* default to sequential since it only needs one cpu */ + arg_test_to_run = TEST_SEQUENTIAL; + return; + } + + if (!strcmp("--parallel", argv[1])) + arg_test_to_run = TEST_PARALLEL; + else if (!strcmp("--sequential", argv[1])) + arg_test_to_run = TEST_SEQUENTIAL; + else + arg_test_to_run = TEST_INVALID; } -int main(void) +int main(int argc, char **argv) { report_prefix_push("migration-skey"); - if (test_facility(169)) + if (test_facility(169)) { report_skip("storage key removal facility is active"); - else - test_migration(); + goto error; + } - migrate_once(); + parse_args(argc, argv); + + switch (arg_test_to_run) { + case TEST_SEQUENTIAL: + test_skey_migration_sequential(); + break; + case TEST_PARALLEL: + test_skey_migration_parallel(); + break; + default: + print_usage(); + break; + } +error: + migrate_once(); report_prefix_pop(); return report_summary(); } diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index 3caf81ed..d97eb5e9 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -185,10 +185,6 @@ smp = 2 file = migration-cmm.elf groups = migration -[migration-skey] -file = migration-skey.elf -groups = migration - [panic-loop-extint] file = panic-loop-extint.elf groups = panic @@ -208,3 +204,14 @@ groups = migration [exittime] file = exittime.elf smp = 2 + +[migration-skey-sequential] +file = migration-skey.elf +groups = migration +extra_params = -append '--sequential' + +[migration-skey-parallel] +file = migration-skey.elf +smp = 2 +groups = migration +extra_params = -append '--parallel' From patchwork Thu Jan 5 12:15:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudio Imbrenda X-Patchwork-Id: 13089767 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 5953DC53210 for ; Thu, 5 Jan 2023 12:15:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232736AbjAEMPy (ORCPT ); Thu, 5 Jan 2023 07:15:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232464AbjAEMPw (ORCPT ); Thu, 5 Jan 2023 07:15:52 -0500 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22EE297 for ; Thu, 5 Jan 2023 04:15:48 -0800 (PST) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 305C7f6V029763 for ; Thu, 5 Jan 2023 12:15:48 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 : content-transfer-encoding : mime-version; s=pp1; bh=D6Vrv1SAbPCQGMyFX8oTkm3MwVis5hjnBRH1cahvJn8=; b=hEvMca3XB7+6B1jCkQOpIv+o7GXrbz4UGUaZwVb/SoRdSoV3zEtS7qekfNyygKR7rLMV TGirydDjyO+gwKJkXjOmKUEE/2AZjYj3+UKa0uPmpVxtF+wJzdj/yHaqEM1QR2zolJzb 7Vk6DOKpDN6h9OgTC85tVSO0fCPnqcFBWwyzU0dOxzfXGnLUzn6TsWXgnA1YIRoTR/x3 qYEk4S6AWRnH2EpbKLdZPaH3dOKShUkeBHyEXoXRl4732jvrKwoyu7qtgthdP2TX72Bx 4SJaNXHQRqNAhOmk/9zyXz+Cz9Wjnf0ToqJ123Burdru7GBy6j1EXUuHE+0aliomMNL/ 4A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mww14hsxs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 05 Jan 2023 12:15:47 +0000 Received: from m0098404.ppops.net (m0098404.ppops.net [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 305C7jPr030523 for ; Thu, 5 Jan 2023 12:15:47 GMT Received: from ppma05fra.de.ibm.com (6c.4a.5195.ip4.static.sl-reverse.com [149.81.74.108]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3mww14hsx8-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 Jan 2023 12:15:47 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 304LI98c004235; Thu, 5 Jan 2023 12:15:44 GMT Received: from smtprelay01.fra02v.mail.ibm.com ([9.218.2.227]) by ppma05fra.de.ibm.com (PPS) with ESMTPS id 3mtcq6mxts-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 05 Jan 2023 12:15:44 +0000 Received: from smtpav07.fra02v.mail.ibm.com (smtpav07.fra02v.mail.ibm.com [10.20.54.106]) by smtprelay01.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 305CFfG841222618 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 5 Jan 2023 12:15:41 GMT Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0E9B020040; Thu, 5 Jan 2023 12:15:41 +0000 (GMT) Received: from smtpav07.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B564020043; Thu, 5 Jan 2023 12:15:40 +0000 (GMT) Received: from p-imbrenda.ibmuc.com (unknown [9.171.26.82]) by smtpav07.fra02v.mail.ibm.com (Postfix) with ESMTP; Thu, 5 Jan 2023 12:15:40 +0000 (GMT) From: Claudio Imbrenda To: pbonzini@redhat.com, thuth@redhat.com Cc: kvm@vger.kernel.org, frankja@linux.ibm.com, Nico Boehr Subject: [kvm-unit-tests GIT PULL 4/4] s390x: add CMM test during migration Date: Thu, 5 Jan 2023 13:15:38 +0100 Message-Id: <20230105121538.52008-5-imbrenda@linux.ibm.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: <20230105121538.52008-1-imbrenda@linux.ibm.com> References: <20230105121538.52008-1-imbrenda@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 9KQmWweqOtSmEyXMliVNoAf0xDuqbRIw X-Proofpoint-GUID: jbQrTocfI1S9U0kpIVmeBHwDDUwCQ2UU X-Proofpoint-UnRewURL: 0 URL was un-rewritten MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.923,Hydra:6.0.545,FMLib:17.11.122.1 definitions=2023-01-05_04,2023-01-04_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 priorityscore=1501 spamscore=0 phishscore=0 clxscore=1015 adultscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 bulkscore=0 mlxscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2301050095 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Nico Boehr Add a test which modifies CMM page states while migration is in progress. This is added to the existing migration-cmm test, which gets a new command line argument for the sequential and parallel variants. Signed-off-by: Nico Boehr Reviewed-by: Claudio Imbrenda Link: https://lore.kernel.org/r/20221221090953.341247-2-nrb@linux.ibm.com Message-Id: <20221221090953.341247-2-nrb@linux.ibm.com> Signed-off-by: Claudio Imbrenda --- s390x/migration-cmm.c | 258 +++++++++++++++++++++++++++++++++++++----- s390x/unittests.cfg | 15 ++- 2 files changed, 240 insertions(+), 33 deletions(-) diff --git a/s390x/migration-cmm.c b/s390x/migration-cmm.c index 43673f18..2d46c6be 100644 --- a/s390x/migration-cmm.c +++ b/s390x/migration-cmm.c @@ -2,6 +2,12 @@ /* * CMM migration tests (ESSA) * + * There are two variants of this test: + * - sequential: sets CMM page states, then migrates the VM and - after + * migration finished - verifies that page states have been preserved. + * - parallel: migrate VM and - while migration is in progress - change + * page states and verify that they are preserved. + * * Copyright IBM Corp. 2022 * * Authors: @@ -13,55 +19,249 @@ #include #include #include +#include #include +#include + +struct verify_result { + bool verify_failed; + char expected_mask; + char actual_mask; + unsigned long page_mismatch_idx; + unsigned long page_mismatch_addr; +}; + +static enum { + TEST_INVLALID, + TEST_SEQUENTIAL, + TEST_PARALLEL +} arg_test_to_run; #define NUM_PAGES 128 -static uint8_t pagebuf[NUM_PAGES][PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); -static void test_migration(void) +/* + * Allocate 3 pages more than we need so we can start at different offsets. + * For the parallel test, this ensures page states change on every loop iteration. + */ +static uint8_t pagebuf[(NUM_PAGES + 3) * PAGE_SIZE] __attribute__((aligned(PAGE_SIZE))); + +static struct verify_result result; + +static unsigned int thread_iters; +static int thread_should_exit; +static int thread_exited; + +/* + * Maps ESSA actions to states the page is allowed to be in after the + * respective action was executed. + */ +static const unsigned long allowed_essa_state_masks[4] = { + BIT(ESSA_USAGE_STABLE), /* ESSA_SET_STABLE */ + BIT(ESSA_USAGE_UNUSED), /* ESSA_SET_UNUSED */ + BIT(ESSA_USAGE_VOLATILE), /* ESSA_SET_VOLATILE */ + BIT(ESSA_USAGE_VOLATILE) | BIT(ESSA_USAGE_POT_VOLATILE) /* ESSA_SET_POT_VOLATILE */ +}; + +/* + * Set CMM page state test pattern on pagebuf. + * pagebuf must point to page_count consecutive pages. + * page_count must be a multiple of 4. + */ +static void set_test_pattern(uint8_t *pagebuf, size_t page_count) +{ + unsigned long addr = (unsigned long)pagebuf; + size_t i; + + assert(page_count % 4 == 0); + for (i = 0; i < page_count; i += 4) { + essa(ESSA_SET_STABLE, addr + i * PAGE_SIZE); + essa(ESSA_SET_UNUSED, addr + (i + 1) * PAGE_SIZE); + essa(ESSA_SET_VOLATILE, addr + (i + 2) * PAGE_SIZE); + essa(ESSA_SET_POT_VOLATILE, addr + (i + 3) * PAGE_SIZE); + } +} + +/* + * Verify CMM page states on pagebuf. + * Page states must have been set by set_test_pattern on pagebuf before. + * page_count must be a multiple of 4. + * + * If page states match the expected result, will return a verify_result + * with verify_failed false. All other fields are then invalid. + * If there is a mismatch, the returned struct will have verify_failed true + * and will be filled with details on the first mismatch encountered. + */ +static struct verify_result verify_page_states(uint8_t *pagebuf, size_t page_count) +{ + unsigned long expected_mask, actual_mask; + struct verify_result result = { + .verify_failed = true + }; + unsigned long addr; + size_t i; + + assert(page_count % 4 == 0); + for (i = 0; i < page_count; i++) { + addr = (unsigned long)(pagebuf + i * PAGE_SIZE); + actual_mask = essa(ESSA_GET_STATE, addr); + /* usage state in bits 60 and 61 */ + actual_mask = BIT((actual_mask >> 2) & 0x3); + expected_mask = allowed_essa_state_masks[i % ARRAY_SIZE(allowed_essa_state_masks)]; + if (!(actual_mask & expected_mask)) { + result.page_mismatch_idx = i; + result.page_mismatch_addr = addr; + result.expected_mask = expected_mask; + result.actual_mask = actual_mask; + return result; + } + } + + result.verify_failed = false; + return result; +} + +static void report_verify_result(const struct verify_result *result) +{ + if (result->verify_failed) + report_fail("page state mismatch: first page idx = %lu, addr = %lx, " + "expected_mask = 0x%x, actual_mask = 0x%x", + result->page_mismatch_idx, result->page_mismatch_addr, + result->expected_mask, result->actual_mask); + else + report_pass("page states match"); +} + +static void test_cmm_migration_sequential(void) +{ + report_prefix_push("sequential"); + + set_test_pattern(pagebuf, NUM_PAGES); + + migrate_once(); + + result = verify_page_states(pagebuf, NUM_PAGES); + report_verify_result(&result); + + report_prefix_pop(); +} + +static void set_cmm_thread(void) { - int i, state_mask, actual_state; + uint8_t *pagebuf_start; /* - * Maps ESSA actions to states the page is allowed to be in after the - * respective action was executed. + * The second CPU must not print to the console, otherwise it will race with + * the primary CPU on the SCLP buffer. */ - int allowed_essa_state_masks[4] = { - BIT(ESSA_USAGE_STABLE), /* ESSA_SET_STABLE */ - BIT(ESSA_USAGE_UNUSED), /* ESSA_SET_UNUSED */ - BIT(ESSA_USAGE_VOLATILE), /* ESSA_SET_VOLATILE */ - BIT(ESSA_USAGE_VOLATILE) | BIT(ESSA_USAGE_POT_VOLATILE) /* ESSA_SET_POT_VOLATILE */ - }; + while (!READ_ONCE(thread_should_exit)) { + /* + * Start on a offset different from the last iteration so page states change with + * every iteration. This is why pagebuf has 3 extra pages. + */ + pagebuf_start = pagebuf + (thread_iters % 4) * PAGE_SIZE; + set_test_pattern(pagebuf_start, NUM_PAGES); + + /* + * 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++; - assert(NUM_PAGES % 4 == 0); - for (i = 0; i < NUM_PAGES; i += 4) { - essa(ESSA_SET_STABLE, (unsigned long)pagebuf[i]); - essa(ESSA_SET_UNUSED, (unsigned long)pagebuf[i + 1]); - essa(ESSA_SET_VOLATILE, (unsigned long)pagebuf[i + 2]); - essa(ESSA_SET_POT_VOLATILE, (unsigned long)pagebuf[i + 3]); + result = verify_page_states(pagebuf_start, NUM_PAGES); + if (result.verify_failed) + break; } + WRITE_ONCE(thread_exited, 1); +} + +static void test_cmm_migration_parallel(void) +{ + report_prefix_push("parallel"); + + 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(set_cmm_thread)); + migrate_once(); - for (i = 0; i < NUM_PAGES; i++) { - actual_state = essa(ESSA_GET_STATE, (unsigned long)pagebuf[i]); - /* extract the usage state in bits 60 and 61 */ - actual_state = (actual_state >> 2) & 0x3; - state_mask = allowed_essa_state_masks[i % ARRAY_SIZE(allowed_essa_state_masks)]; - report(BIT(actual_state) & state_mask, "page %d state: expected_mask=0x%x actual_mask=0x%lx", i, state_mask, BIT(actual_state)); + WRITE_ONCE(thread_should_exit, 1); + + while (!READ_ONCE(thread_exited)) + ; + + /* Ensure thread_iters and result below are read from memory after thread completed */ + mb(); + + report_info("thread completed %u iterations", thread_iters); + + report_prefix_push("during migration"); + report_verify_result(&result); + report_prefix_pop(); + + /* + * Verification of page states 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 page states which might not have been migrated + * correctly. + */ + report_prefix_push("after migration"); + assert(thread_iters > 0); + result = verify_page_states(pagebuf + ((thread_iters - 1) % 4) * PAGE_SIZE, NUM_PAGES); + report_verify_result(&result); + report_prefix_pop(); + +error: + report_prefix_pop(); +} + +static void print_usage(void) +{ + report_info("Usage: migration-cmm [--parallel|--sequential]"); +} + +static void parse_args(int argc, char **argv) +{ + if (argc < 2) { + /* default to sequential since it only needs one CPU */ + arg_test_to_run = TEST_SEQUENTIAL; + return; } + + if (!strcmp("--parallel", argv[1])) + arg_test_to_run = TEST_PARALLEL; + else if (!strcmp("--sequential", argv[1])) + arg_test_to_run = TEST_SEQUENTIAL; + else + arg_test_to_run = TEST_INVLALID; } -int main(void) +int main(int argc, char **argv) { report_prefix_push("migration-cmm"); - - if (!check_essa_available()) + if (!check_essa_available()) { report_skip("ESSA is not available"); - else - test_migration(); + goto error; + } - migrate_once(); + parse_args(argc, argv); + + switch (arg_test_to_run) { + case TEST_SEQUENTIAL: + test_cmm_migration_sequential(); + break; + case TEST_PARALLEL: + test_cmm_migration_parallel(); + break; + default: + print_usage(); + } +error: + migrate_once(); report_prefix_pop(); return report_summary(); } diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index d97eb5e9..96977f2b 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -181,10 +181,6 @@ file = migration.elf groups = migration smp = 2 -[migration-cmm] -file = migration-cmm.elf -groups = migration - [panic-loop-extint] file = panic-loop-extint.elf groups = panic @@ -215,3 +211,14 @@ file = migration-skey.elf smp = 2 groups = migration extra_params = -append '--parallel' + +[migration-cmm-sequential] +file = migration-cmm.elf +groups = migration +extra_params = -append '--sequential' + +[migration-cmm-parallel] +file = migration-cmm.elf +groups = migration +smp = 2 +extra_params = -append '--parallel'