From patchwork Tue Aug 23 10:38:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Boehr X-Patchwork-Id: 12952155 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 16714C32772 for ; Tue, 23 Aug 2022 15:38:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241473AbiHWPiB (ORCPT ); Tue, 23 Aug 2022 11:38:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60752 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240327AbiHWPhb (ORCPT ); Tue, 23 Aug 2022 11:37:31 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4C548689B for ; Tue, 23 Aug 2022 04:27:15 -0700 (PDT) Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27NAGcUP023480 for ; Tue, 23 Aug 2022 10:38:39 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=Lm0Q1nGo7xgKWHR3YHGNm/bXM1Blb6wuFPQUbkcBzSk=; b=FWABjmJjuc20aIwD8pjcjYueIYOmZLFsJ7CTAmN6XWNiuFpIl1B11g871q+kEujbIBHt lAu9/qdGlOplm3nsfAHDNGVY/mheYCkTflSTw7TLMp3YS59p5I1Q7eB7ZSTbJQC/TpLK k7ma7Gs77tVtSPsEMtGnSZ2kbEO66CVO73cy7LRwGEJyyxDQfNVDsvrfgysD8fo0LS1W XkYjdDWlddlKeSWjqBvmBuiAcMehX6orEByycMobzdHQ/eWegXaCuLyuBy2TATOl68UR L3XA+sTde4fDlQ8o2dPLOVhI1rlFkJi9E9LpEdfRXy98pkw4Wc7Osk+4RTeZ8CMetydp RA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3j4w07rmnd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 23 Aug 2022 10:38:39 +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 27NAItfX029786 for ; Tue, 23 Aug 2022 10:38:38 GMT Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0b-001b2d01.pphosted.com (PPS) with ESMTPS id 3j4w07rmn0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 23 Aug 2022 10:38:38 +0000 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 27NAL9KE031500; Tue, 23 Aug 2022 10:38:36 GMT Received: from b06avi18626390.portsmouth.uk.ibm.com (b06avi18626390.portsmouth.uk.ibm.com [9.149.26.192]) by ppma03ams.nl.ibm.com with ESMTP id 3j2q88umcp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 23 Aug 2022 10:38:36 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 27NAZZDv32375210 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Aug 2022 10:35:35 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A95B242041; Tue, 23 Aug 2022 10:38:33 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 768AC42052; Tue, 23 Aug 2022 10:38:33 +0000 (GMT) Received: from a46lp57.lnxne.boe (unknown [9.152.108.100]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 23 Aug 2022 10:38:33 +0000 (GMT) From: Nico Boehr To: kvm@vger.kernel.org Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH v6 1/4] runtime: add support for panic tests Date: Tue, 23 Aug 2022 12:38:30 +0200 Message-Id: <20220823103833.156942-2-nrb@linux.ibm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220823103833.156942-1-nrb@linux.ibm.com> References: <20220823103833.156942-1-nrb@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: nzvcxN2BG-CEWq6oCVPDfKXbWGEgCkOS X-Proofpoint-ORIG-GUID: 7JUpo4k0lffthAdrPUF69t3wTURau5ym 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.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-23_04,2022-08-22_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 clxscore=1015 phishscore=0 malwarescore=0 spamscore=0 priorityscore=1501 mlxlogscore=999 impostorscore=0 adultscore=0 suspectscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208230040 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org QEMU supports a guest state "guest-panicked" which indicates something in the guest went wrong. For example on s390x, when an external interrupt loop was triggered. Since the guest does not continue to run when it is in the guest-panicked state, it is currently impossible to write panicking tests in kvm-unit-tests. Support from the runtime is needed to check that the guest enters the guest-panicked state. Similar to migration tests, add a new "panic" group. Tests in this group must enter the guest-panicked state to succeed. The runtime will spawn a QEMU instance, connect to the QMP and listen for events. To parse the QMP protocol, jq[1] is used. Same as with netcat in the migration tests, panic tests won't run if jq is not installed. The guest is created in the stopped state and only is resumed when connection to the QMP was successful. This ensures no events are missed between QEMU start and the connect to the QMP. [1] https://stedolan.github.io/jq/ Signed-off-by: Nico Boehr Reviewed-by: Thomas Huth Reviewed-by: Claudio Imbrenda Acked-by: Janosch Frank --- s390x/run | 2 +- scripts/arch-run.bash | 49 +++++++++++++++++++++++++++++++++++++++++++ scripts/runtime.bash | 3 +++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/s390x/run b/s390x/run index 24138f6803be..f1111dbdbe62 100755 --- a/s390x/run +++ b/s390x/run @@ -30,7 +30,7 @@ M+=",accel=$ACCEL" command="$qemu -nodefaults -nographic $M" command+=" -chardev stdio,id=con0 -device sclpconsole,chardev=con0" command+=" -kernel" -command="$(migration_cmd) $(timeout_cmd) $command" +command="$(panic_cmd) $(migration_cmd) $(timeout_cmd) $command" # We return the exit code via stdout, not via the QEMU return code run_qemu_status $command "$@" diff --git a/scripts/arch-run.bash b/scripts/arch-run.bash index 0dfaf017db0a..51e4b97b27d1 100644 --- a/scripts/arch-run.bash +++ b/scripts/arch-run.bash @@ -104,6 +104,14 @@ qmp () echo '{ "execute": "qmp_capabilities" }{ "execute":' "$2" '}' | ncat -U $1 } +qmp_events () +{ + while ! test -S "$1"; do sleep 0.1; done + echo '{ "execute": "qmp_capabilities" }{ "execute": "cont" }' | + ncat --no-shutdown -U $1 | + jq -c 'select(has("event"))' +} + run_migration () { if ! command -v ncat >/dev/null 2>&1; then @@ -164,6 +172,40 @@ run_migration () return $ret } +run_panic () +{ + if ! command -v ncat >/dev/null 2>&1; then + echo "${FUNCNAME[0]} needs ncat (netcat)" >&2 + return 77 + fi + + if ! command -v jq >/dev/null 2>&1; then + echo "${FUNCNAME[0]} needs jq" >&2 + return 77 + fi + + qmp=$(mktemp -u -t panic-qmp.XXXXXXXXXX) + + trap 'kill 0; exit 2' INT TERM + trap 'rm -f ${qmp}' RETURN EXIT + + # start VM stopped so we don't miss any events + eval "$@" -chardev socket,id=mon1,path=${qmp},server=on,wait=off \ + -mon chardev=mon1,mode=control -S & + + panic_event_count=$(qmp_events ${qmp} | jq -c 'select(.event == "GUEST_PANICKED")' | wc -l) + if [ "$panic_event_count" -lt 1 ]; then + echo "FAIL: guest did not panic" + ret=3 + else + # some QEMU versions report multiple panic events + echo "PASS: guest panicked" + ret=1 + fi + + return $ret +} + migration_cmd () { if [ "$MIGRATION" = "yes" ]; then @@ -171,6 +213,13 @@ migration_cmd () fi } +panic_cmd () +{ + if [ "$PANIC" = "yes" ]; then + echo "run_panic" + fi +} + search_qemu_binary () { local save_path=$PATH diff --git a/scripts/runtime.bash b/scripts/runtime.bash index bbf87cf4ed3f..f8794e9a25ce 100644 --- a/scripts/runtime.bash +++ b/scripts/runtime.bash @@ -145,6 +145,9 @@ function run() if find_word "migration" "$groups"; then cmdline="MIGRATION=yes $cmdline" fi + if find_word "panic" "$groups"; then + cmdline="PANIC=yes $cmdline" + fi if [ "$verbose" = "yes" ]; then echo $cmdline fi From patchwork Tue Aug 23 10:38:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Boehr X-Patchwork-Id: 12952082 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 93369C32774 for ; Tue, 23 Aug 2022 14:04:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242500AbiHWOEQ (ORCPT ); Tue, 23 Aug 2022 10:04:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242815AbiHWOAo (ORCPT ); Tue, 23 Aug 2022 10:00:44 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3F1B23B3EC for ; Tue, 23 Aug 2022 04:08:03 -0700 (PDT) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27NAUkeT006633 for ; Tue, 23 Aug 2022 10:38:40 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=NbGhBPKo27SpqZyaNHn74Gl3SpPLzhLPdCOBBqbsb5c=; b=cLkykzFxAp4FVL5ODrL8MCodlUJWsYZZ5TgrQ1bGc/8VDact5lnfHUHIEa9dKXMYaO2+ 3rC31gdbiSDbCKH8D/aiXMDYGP6e7fw399ejKzGBasigA5e7Vgl0LKk4V1h2oPvDc0G/ NPhCKcqmcWmmjzNCVXJy/Aglv5IxN5BWrGT6IjGnc+zxw3Wz2OvTUhWE7Fd8jA3W/BSI NLf7QgevGeh8U/ZAAruPzSplP8prbYT+3H4yiWSGidxdbUCr6oJYw1cBeNf9LIjaszLl AMvyIOajz/5nqvH39fcJ61bYzopqkajaQ1f6+TXN0fdMQ31GLEDoYWttC0xcl/y99WHT hg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3j4w7508w2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 23 Aug 2022 10:38:40 +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 27NAVeGP009377 for ; Tue, 23 Aug 2022 10:38:39 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 3j4w7508uy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 23 Aug 2022 10:38:39 +0000 Received: from pps.filterd (ppma05fra.de.ibm.com [127.0.0.1]) by ppma05fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 27NALbWk025876; Tue, 23 Aug 2022 10:38:37 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma05fra.de.ibm.com with ESMTP id 3j2q89amqp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 23 Aug 2022 10:38:37 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 27NAcY9X31850822 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Aug 2022 10:38:34 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E714942041; Tue, 23 Aug 2022 10:38:33 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B4DD74204F; Tue, 23 Aug 2022 10:38:33 +0000 (GMT) Received: from a46lp57.lnxne.boe (unknown [9.152.108.100]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 23 Aug 2022 10:38:33 +0000 (GMT) From: Nico Boehr To: kvm@vger.kernel.org Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH v6 2/4] lib/s390x: add CPU timer related defines and functions Date: Tue, 23 Aug 2022 12:38:31 +0200 Message-Id: <20220823103833.156942-3-nrb@linux.ibm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220823103833.156942-1-nrb@linux.ibm.com> References: <20220823103833.156942-1-nrb@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: x9oh_lzk9bN9N5Ea-n64BXfEzNFd27_D X-Proofpoint-GUID: dTDk4GJTEv8jQpyK2SLw3QBBxooJ5zl3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-23_04,2022-08-22_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 bulkscore=0 phishscore=0 spamscore=0 impostorscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 mlxlogscore=972 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208230040 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Upcoming changes will make use of the CPU timer, so add some defines and functions to work with the CPU timer. Since shifts for both CPU timer and TOD clock are the same, introduce a new constant S390_CLOCK_SHIFT_US for this value. The respective shifts for CPU timer and TOD clock reference it, so the semantic difference between the two defines is kept. Also add a constant for the CPU timer subclass mask. Signed-off-by: Nico Boehr Reviewed-by: Janosch Frank Reviewed-by: Thomas Huth --- lib/s390x/asm/arch_def.h | 1 + lib/s390x/asm/time.h | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/s390x/asm/arch_def.h b/lib/s390x/asm/arch_def.h index e7ae454b3a33..b92291e8ae3f 100644 --- a/lib/s390x/asm/arch_def.h +++ b/lib/s390x/asm/arch_def.h @@ -78,6 +78,7 @@ struct cpu { #define CTL0_EMERGENCY_SIGNAL (63 - 49) #define CTL0_EXTERNAL_CALL (63 - 50) #define CTL0_CLOCK_COMPARATOR (63 - 52) +#define CTL0_CPU_TIMER (63 - 53) #define CTL0_SERVICE_SIGNAL (63 - 54) #define CR0_EXTM_MASK 0x0000000000006200UL /* Combined external masks */ diff --git a/lib/s390x/asm/time.h b/lib/s390x/asm/time.h index 7652a151e87a..d8d91d68a667 100644 --- a/lib/s390x/asm/time.h +++ b/lib/s390x/asm/time.h @@ -11,9 +11,13 @@ #ifndef _ASMS390X_TIME_H_ #define _ASMS390X_TIME_H_ -#define STCK_SHIFT_US (63 - 51) +#define S390_CLOCK_SHIFT_US (63 - 51) + +#define STCK_SHIFT_US S390_CLOCK_SHIFT_US #define STCK_MAX ((1UL << 52) - 1) +#define CPU_TIMER_SHIFT_US S390_CLOCK_SHIFT_US + static inline uint64_t get_clock_us(void) { uint64_t clk; @@ -45,4 +49,15 @@ static inline void mdelay(unsigned long ms) udelay(ms * 1000); } +static inline void cpu_timer_set_ms(int64_t timeout_ms) +{ + int64_t timer_value = (timeout_ms * 1000) << CPU_TIMER_SHIFT_US; + + asm volatile ( + "spt %[timer_value]\n" + : + : [timer_value] "Q" (timer_value) + ); +} + #endif From patchwork Tue Aug 23 10:38:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Boehr X-Patchwork-Id: 12952060 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 9725BC32772 for ; Tue, 23 Aug 2022 13:39:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241843AbiHWNjN (ORCPT ); Tue, 23 Aug 2022 09:39:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53416 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241862AbiHWNit (ORCPT ); Tue, 23 Aug 2022 09:38:49 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2DF8A7203 for ; Tue, 23 Aug 2022 03:40:23 -0700 (PDT) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27NAUm6Z006758 for ; Tue, 23 Aug 2022 10:38:40 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=EsQV//QiABNPdlTh5aAAHgmyfXZJlO/do65BQ2j3KXo=; b=f8ZQtfg5xomNSXpWy9iieqv1Xfk2F1qqHz1SJx73DMVSnACG6mKqDBjK2N5nJyulr6To SR7jvKaniwry8dcAygCyKrOsOvDWX94M+jPrbtpYyEJ+mPMQMgE4/h3tOC1jmQkKE6r2 Cnp9LzN98x9JQHAEd4nG0cxYtZ1/H6O+v/5BsSiS+Yho+S+IZUk6ObUvoKarwqsgXrwF CrivjyjmWOI841cX86V7FKk+sysqnwQ4s0CK/7EgEUplantrwFy1OTlYJjWQ9PAMWSIb rGANldIPA3J/qMv0wJf3wKGBJMRsykFRto4zsW2AQS0kx7BEJ4J1Ss+kpUcZWqKZu4TP yw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3j4w7508vw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 23 Aug 2022 10:38:40 +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 27NAVeGN009377 for ; Tue, 23 Aug 2022 10:38:39 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 3j4w7508v0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 23 Aug 2022 10:38:39 +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 27NAL2RL010896; Tue, 23 Aug 2022 10:38:37 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma04ams.nl.ibm.com with ESMTP id 3j2q88umwj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 23 Aug 2022 10:38:37 +0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 27NAcYk228049826 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Aug 2022 10:38:34 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 30A104204F; Tue, 23 Aug 2022 10:38:34 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F29B542054; Tue, 23 Aug 2022 10:38:33 +0000 (GMT) Received: from a46lp57.lnxne.boe (unknown [9.152.108.100]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 23 Aug 2022 10:38:33 +0000 (GMT) From: Nico Boehr To: kvm@vger.kernel.org Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH v6 3/4] s390x: add extint loop test Date: Tue, 23 Aug 2022 12:38:32 +0200 Message-Id: <20220823103833.156942-4-nrb@linux.ibm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220823103833.156942-1-nrb@linux.ibm.com> References: <20220823103833.156942-1-nrb@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Yj4SPJy1sfhppCkfiaMpqBZaQkUiVj2o X-Proofpoint-GUID: NifEZV60vwv15Mw9fQ1tW2vsyBbjNt8e X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-23_04,2022-08-22_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 bulkscore=0 phishscore=0 spamscore=0 impostorscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 mlxlogscore=895 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208230040 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org The CPU timer interrupt stays pending as long as the CPU timer value is negative. This can lead to interruption loops when the ext_new_psw mask has external interrupts enabled and the CPU timer subclass in CR0 is enabled. QEMU is able to detect this situation and panic the guest, so add a test for it. Signed-off-by: Nico Boehr Reviewed-by: Thomas Huth Reviewed-by: Janosch Frank --- s390x/Makefile | 1 + s390x/panic-loop-extint.c | 59 +++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 6 ++++ 3 files changed, 66 insertions(+) create mode 100644 s390x/panic-loop-extint.c diff --git a/s390x/Makefile b/s390x/Makefile index efd5e0c13102..e4649da50d9d 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -34,6 +34,7 @@ tests += $(TEST_DIR)/migration.elf tests += $(TEST_DIR)/pv-attest.elf tests += $(TEST_DIR)/migration-cmm.elf tests += $(TEST_DIR)/migration-skey.elf +tests += $(TEST_DIR)/panic-loop-extint.elf pv-tests += $(TEST_DIR)/pv-diags.elf diff --git a/s390x/panic-loop-extint.c b/s390x/panic-loop-extint.c new file mode 100644 index 000000000000..07325147dc17 --- /dev/null +++ b/s390x/panic-loop-extint.c @@ -0,0 +1,59 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * External interrupt loop test + * + * Copyright IBM Corp. 2022 + * + * Authors: + * Nico Boehr + */ +#include +#include +#include +#include +#include +#include + +static void ext_int_cleanup(struct stack_frame_int *stack) +{ + /* + * Since we form a loop of ext interrupts, this code should never be + * executed. In case it is executed, something went wrong and we want to + * print a failure. + * + * Because the CPU timer subclass mask is still enabled, the CPU timer + * interrupt will fire every time we enable external interrupts, + * preventing us from printing the failure on the console. To avoid + * this, clear the CPU timer subclass mask here. + */ + stack->crs[0] &= ~BIT(CTL0_CPU_TIMER); +} + +int main(void) +{ + report_prefix_push("panic-loop-extint"); + + if (!host_is_qemu() || host_is_tcg()) { + report_skip("QEMU-KVM-only test"); + goto out; + } + + expect_ext_int(); + lowcore.ext_new_psw.mask |= PSW_MASK_EXT; + + psw_mask_set_bits(PSW_MASK_EXT); + + register_ext_cleanup_func(ext_int_cleanup); + + cpu_timer_set_ms(10); + ctl_set_bit(0, CTL0_CPU_TIMER); + mdelay(2000); + + register_ext_cleanup_func(NULL); + + report_fail("survived extint loop"); + +out: + report_prefix_pop(); + return report_summary(); +} diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index f7b1fc3dbca1..b1b25f118ff6 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -185,3 +185,9 @@ groups = migration [migration-skey] file = migration-skey.elf groups = migration + +[panic-loop-extint] +file = panic-loop-extint.elf +groups = panic +accel = kvm +timeout = 5 From patchwork Tue Aug 23 10:38:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Boehr X-Patchwork-Id: 12952072 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 A6CBDC32772 for ; Tue, 23 Aug 2022 13:57:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241277AbiHWN5e (ORCPT ); Tue, 23 Aug 2022 09:57:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241246AbiHWN5O (ORCPT ); Tue, 23 Aug 2022 09:57:14 -0400 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43A1122D07A for ; Tue, 23 Aug 2022 04:03:25 -0700 (PDT) Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 27NAUkeU006633 for ; Tue, 23 Aug 2022 10:38:40 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=i9Qft+jKEvNj+wZkEwNQlreZiejqO02PDN+lrQ/miuQ=; b=Ydv/psmHLykC3t4QvRnySyEs8ckM8rErPec5yr2cisNa1oL0eVZ+ZHClAFSK0Oc0uhcz 1qHGCQvLVUQZV29FoVnzZ2hD8+ZPNtmkI1fimGMtD/Y/whQhqvkYSTnlaAJEdTEQXzeD 2PjWAVjKt8KXvKD1QqNcDHtTb8MlhyZTNMapOZys/q+3+0MiK5Ou6kSdjHZb5iFD8icV SjcPbE9ssS42VeYsRRre6H3sCKbfuixEVKJCnexS6iW0ia1QJ3cr7L2QFl6EZt3OoAuG 10CTQjXNBoFviocgrg9iIivT7MFxg2Ql2uWRpgllz01tn3lblENd1YQv+8nuKq8uoXIo UQ== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 3j4w7508wb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 23 Aug 2022 10:38:40 +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 27NAVAZg008080 for ; Tue, 23 Aug 2022 10:38:40 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 3j4w7508v7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 23 Aug 2022 10:38:40 +0000 Received: from pps.filterd (ppma02fra.de.ibm.com [127.0.0.1]) by ppma02fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 27NAKkGP015660; Tue, 23 Aug 2022 10:38:37 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma02fra.de.ibm.com with ESMTP id 3j2q88tnd3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 23 Aug 2022 10:38:37 +0000 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 27NAcYP828049828 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 23 Aug 2022 10:38:34 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6F6F342041; Tue, 23 Aug 2022 10:38:34 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3C72442052; Tue, 23 Aug 2022 10:38:34 +0000 (GMT) Received: from a46lp57.lnxne.boe (unknown [9.152.108.100]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 23 Aug 2022 10:38:34 +0000 (GMT) From: Nico Boehr To: kvm@vger.kernel.org Cc: frankja@linux.ibm.com, imbrenda@linux.ibm.com, thuth@redhat.com Subject: [kvm-unit-tests PATCH v6 4/4] s390x: add pgm spec interrupt loop test Date: Tue, 23 Aug 2022 12:38:33 +0200 Message-Id: <20220823103833.156942-5-nrb@linux.ibm.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220823103833.156942-1-nrb@linux.ibm.com> References: <20220823103833.156942-1-nrb@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: y5ktHg1wWV8_Q-l7GcYKr_i3ykEmFlsT X-Proofpoint-GUID: SG-DvArvczBr4d2YHR5N7sjnYXCmXCZs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-08-23_04,2022-08-22_02,2022-06-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 bulkscore=0 phishscore=0 spamscore=0 impostorscore=0 clxscore=1015 lowpriorityscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 mlxlogscore=919 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2207270000 definitions=main-2208230040 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org An invalid PSW causes a program interrupt. When an invalid PSW is introduced in the pgm_new_psw, an interrupt loop occurs as soon as a program interrupt is caused. QEMU should detect that and panic the guest, hence add a test for it. Signed-off-by: Nico Boehr Reviewed-by: Claudio Imbrenda Reviewed-by: Janosch Frank Reviewed-by: Thomas Huth --- s390x/Makefile | 1 + s390x/panic-loop-pgm.c | 38 ++++++++++++++++++++++++++++++++++++++ s390x/unittests.cfg | 6 ++++++ 3 files changed, 45 insertions(+) create mode 100644 s390x/panic-loop-pgm.c diff --git a/s390x/Makefile b/s390x/Makefile index e4649da50d9d..66415d0b588d 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -35,6 +35,7 @@ tests += $(TEST_DIR)/pv-attest.elf tests += $(TEST_DIR)/migration-cmm.elf tests += $(TEST_DIR)/migration-skey.elf tests += $(TEST_DIR)/panic-loop-extint.elf +tests += $(TEST_DIR)/panic-loop-pgm.elf pv-tests += $(TEST_DIR)/pv-diags.elf diff --git a/s390x/panic-loop-pgm.c b/s390x/panic-loop-pgm.c new file mode 100644 index 000000000000..23e973477f68 --- /dev/null +++ b/s390x/panic-loop-pgm.c @@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Program interrupt loop test + * + * Copyright IBM Corp. 2022 + * + * Authors: + * Nico Boehr + */ +#include +#include +#include +#include +#include + +int main(void) +{ + report_prefix_push("panic-loop-pgm"); + + if (!host_is_qemu() || host_is_tcg()) { + report_skip("QEMU-KVM-only test"); + goto out; + } + + expect_pgm_int(); + /* bit 12 set is invalid */ + lowcore.pgm_new_psw.mask = extract_psw_mask() | BIT(63 - 12); + mb(); + + /* cause a pgm int */ + psw_mask_set_bits(BIT(63 - 12)); + + report_fail("survived pgm int loop"); + +out: + report_prefix_pop(); + return report_summary(); +} diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index b1b25f118ff6..f9f102abfa89 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -191,3 +191,9 @@ file = panic-loop-extint.elf groups = panic accel = kvm timeout = 5 + +[panic-loop-pgm] +file = panic-loop-pgm.elf +groups = panic +accel = kvm +timeout = 5