From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3393B606A683 for ; Wed, 2 Dec 2026 14:13:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=PEM8jWys; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=TOcYtJEa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References :Message-Id:Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=K+syVaiR7B9VOOOlu+TZnkRX+MggRqsqOxN6NVuJg/w=; b=PEM8jWys++QI4L aktW+V56SvbCyRjC+MsiMuffTVFolt4IAEPWFFwQPorp7EjG88qO4flRt0l7tzMY7/7HsnCj+ad0E 7AracP44SdXFPcMfGtJFclxZveu6YWRwrNbYkUUDBvQdu82FS8JDOqEQgK0xeTUa7V6Bpna+SOq4y Jm7wl5rDdQ3N5uUFDADLRETr0yPNNX6Xi99hfVdkwmvpiZhJBapSoOsIdwCdKRBRhyLlSM9Kq7d04 K9OXAAn6vGCTy50javV3RSF/Al4OPLmD51UtkmmuyiZivXeKM1vTu+/juMEOQKYDQCstwwure6NwU xqSMCQbLN2XmlbN9QUfw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYl4d-0000000BhBA-0Mmi; Wed, 02 Dec 2026 14:12:43 +0000 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYl4b-0000000Bh9C-0apF for linux-arm-kernel@lists.infradead.org; Wed, 02 Dec 2026 14:12:42 +0000 Received: from pps.filterd (m0353729.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B2AMCl22795200; Wed, 2 Dec 2026 14:12:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=K+syVa iR7B9VOOOlu+TZnkRX+MggRqsqOxN6NVuJg/w=; b=TOcYtJEaBNeUfSot3vRU01 PEikn829ICMF3mkp0R4J7li5DylPquu/FQzI98X1AEEyUvE7A7Iq+xGINVG/0+G0 j/h77puawUbl5ph5eYXYfNS6lYFbOuWHPRdEhAo30ErctsVzHoE1SyKQ79A/BBEV rtpV3jm+cLQ/uL1M3l7ipLUKr3dmlQOxLBEzol/ogt0pg0bw5ta8P6vS88OY+UPW rlcddL+SM0lI+FV1mgUJbuKB3ymvobN+YRF189hgj15Rl7Ud68lrG7LadLKiHyh5 BVFGR3t/t+7wzqgNzUXDU4Ev+/2G2CfUTcvYi1hdxe8LaoAS/C5qy3zQYZEwQ6Aw == Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7pmta4e7-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 02 Dec 2026 14:12:11 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B2BYdfB3858174; Wed, 2 Dec 2026 14:12:10 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4ja2uv3rwt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 02 Dec 2026 14:12:10 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (smtpav03.fra02v.mail.ibm.com [10.20.54.102]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B2EC6bn44499302 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 2 Dec 2026 14:12:06 GMT Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 99F192004B; Wed, 2 Dec 2026 14:12:06 +0000 (GMT) Received: from smtpav03.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4C2E520040; Wed, 2 Dec 2026 14:12:06 +0000 (GMT) Received: from a46lp73.lnxne.boe (unknown [9.87.84.240]) by smtpav03.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 2 Dec 2026 14:12:06 +0000 (GMT) From: Steffen Eiden Date: Wed, 02 Dec 2026 15:11:49 +0100 Subject: [PATCH 11/12] KVM: s390: arm64: Trap WFx X-Archived-By: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261202-smccc-v1-11-48340e2737b6@linux.ibm.com> References: <20261202-smccc-v1-0-48340e2737b6@linux.ibm.com> In-Reply-To: <20261202-smccc-v1-0-48340e2737b6@linux.ibm.com> To: Marc Zyngier , Oliver Upton , Fuad Tabba , Joey Gouly , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Andreas Grapentin , Christian Borntraeger , Janosch Frank , Claudio Imbrenda , David Hildenbrand , Heiko Carstens , Vasily Gorbik , Alexander Gordeev , Sven Schnelle , Friedrich Welter , Gautam Gala , Hariharan Mari , Hendrik Brueckner , Nico Boehr , Ulrich Weigand , Arnd Bergmann , Paolo Bonzini Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-s390@vger.kernel.org, Steffen Eiden X-Mailer: b4 0.14.3 X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Ic_LC9-fAM-tzBPSDpueqyprk4TXfgxb X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAyMDA1NiBTYWx0ZWRfX7CmwnzT84y+5 WuAM32GQYrDQiDNaGOTOo89aYbN6+zKci49TVGzppaOCeZTWs4HPaLX//yX8eutvKfXC3pxJ5MP k0hV6jsMvLYaSajK2ZVM9pABgWCkjt2uCbAASs12fHiwI/c9ghBQGSXOl7kKqKa/FhgL/ERF21W /vYEzB7Vh5E69sw6j7DYqPksN9zE+yH/PVGsiUYuHKJgGP6yTHcUTXJa6ibEWYNqX7vWOKwvTQ2 4eTCa5DPN95ZUhht06MmOAwYjlWjfAN93pzyG4dEIE8ACw3i45fMfxBUhMwiXNPjAx5AR7V1A+U rcvMQo4DL1ai98veWxj7AlhiYFmM3s6YrJACxRW+Xz5DQ9Tsd+q3HCgDgxGBjsWmuuI4QauSNtG zSrpUhc59FuJHa/qnmUNky7KXKs37XJUp5aFW16EA+znQD/37KGCEOYHzjaU6SCCZVml6nOt0PO ehOlmDYNoAGo8Nn5VEA== X-Proofpoint-GUID: Ic_LC9-fAM-tzBPSDpueqyprk4TXfgxb X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAyMDA1NiBTYWx0ZWRfXw/NDdcVusom7 yhtheu2YXsrS0NTfD+iIVhK9dlqc5sdUjUCviCoMytJG9VX3/SETRKR3Zmb//e6Owa1wv8P2Egc R7dCAVzD6hNDao0Jj1OZFWl7xErMroI= X-Authority-Analysis: v=2.4 cv=U9cHnuru c=1 sm=1 tr=0 ts=6b10273b cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=uAbxVGIbfxUO_5tXvNgY:22 a=VnNF1IyMAAAA:8 a=HKtmopZd6QwW6iNG6zkA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-02_02,2026-12-01_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 phishscore=0 malwarescore=0 impostorscore=0 lowpriorityscore=0 clxscore=1015 spamscore=0 priorityscore=1501 bulkscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612020056 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261202_061241_217647_D6A264C4 X-CRM114-Status: GOOD ( 22.50 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" X-Spam-Status: No, score=-16.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 From: Gautam Gala Enable the TWI and TWE trap bits in HCR_EL2 and handle the resulting WFx exceptions in kvm_handle_wfx(). WFI halts the vCPU until it becomes runnable again, i.e. until userspace asserts an IRQ/FIQ line (KVM_IRQ_LINE) or a guest timer output level changes. WFE is treated as a directed yield to another vCPU of the same VM. WFxT carries a deadline: compare it against the guest counter obtained with PTFF QAGPT from the guest physical time offset (GPTO) in the SAE block, and complete the instruction immediately if it has already passed. Otherwise, halt as for WFI with IN_WFIT set so the timer code takes the deadline into account. WFxT with an invalid RN is executed as plain WFI/WFE. Co-developed-by: Steffen Eiden Signed-off-by: Gautam Gala Signed-off-by: Steffen Eiden --- arch/s390/kvm/arm64/handle_exit.c | 54 +++++++++++++++++++++++++++++++++++++++ arch/s390/kvm/arm64/reset.c | 3 ++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/arch/s390/kvm/arm64/handle_exit.c b/arch/s390/kvm/arm64/handle_exit.c index 551cf6fc3afe..06f73be83f46 100644 --- a/arch/s390/kvm/arm64/handle_exit.c +++ b/arch/s390/kvm/arm64/handle_exit.c @@ -6,6 +6,8 @@ #include #include +#include + #include "handle_exit.h" typedef int (*exit_handle_fn)(struct kvm_vcpu *); @@ -43,8 +45,60 @@ static int handle_smc(struct kvm_vcpu *vcpu) return kvm_smccc_call_handler(vcpu); } +/** + * kvm_handle_wfx - handle a wait-for-interrupts or wait-for-event + * instruction executed by a guest + * + * @vcpu: the vcpu pointer + * + * WFI: Virtualize the instruction by halting the vCPU until it becomes + * runnable, i.e. until userspace asserts an IRQ/FIQ line (KVM_IRQ_LINE) or + * a guest timer output level changes. + * WFE: Handled as a directed yield to another vCPU of the same VM. + * WFxT: WFI/WFE with a deadline; if the deadline has already passed, the + * instruction completes immediately. + */ +static int kvm_handle_wfx(struct kvm_vcpu *vcpu) +{ + u64 esr = kvm_vcpu_get_esr(vcpu); + bool is_wfe = !!(esr & ESR_ELx_WFx_ISS_WFE); + + if (is_wfe) + vcpu->stat.wfe_exit_stat++; + else + vcpu->stat.wfi_exit_stat++; + + if (esr & ESR_ELx_WFx_ISS_WFxT) { + if (esr & ESR_ELx_WFx_ISS_RV) { + u64 val, now; + + now = ptff_qagpt(vcpu->arch.sae_block.gpto); + val = vcpu_get_reg(vcpu, kvm_vcpu_sys_get_rt(vcpu)); + if (now >= val) + goto out; + } else { + /* Treat WFxT as WFx if RN is invalid */ + esr &= ~ESR_ELx_WFx_ISS_WFxT; + } + } + + if (esr & ESR_ELx_WFx_ISS_WFE) { + kvm_vcpu_on_spin(vcpu, vcpu_mode_priv(vcpu)); + } else { + if (esr & ESR_ELx_WFx_ISS_WFxT) + vcpu_set_flag(vcpu, IN_WFIT); + + kvm_vcpu_wfi(vcpu); + } +out: + kvm_incr_pc(vcpu); + + return 1; +} + static exit_handle_fn arm_exit_handlers[] = { [0 ... ESR_ELx_EC_MAX] = kvm_handle_unknown_ec, + [ESR_ELx_EC_WFx] = kvm_handle_wfx, [ESR_ELx_EC_SMC64] = handle_smc, [ESR_ELx_EC_HVC64] = handle_hvc, [ESR_ELx_EC_SYS64] = kvm_handle_sys_reg, diff --git a/arch/s390/kvm/arm64/reset.c b/arch/s390/kvm/arm64/reset.c index 391f6e5e49b7..feec5009d2cb 100644 --- a/arch/s390/kvm/arm64/reset.c +++ b/arch/s390/kvm/arm64/reset.c @@ -30,7 +30,8 @@ static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu) /* traps */ vcpu->arch.hcr_el2 |= HCR_EL2_TSC | HCR_EL2_TID1 | HCR_EL2_TID2 | HCR_EL2_TID3 | HCR_EL2_TID4 | HCR_EL2_TID5 | - HCR_EL2_TIDCP | HCR_EL2_TLOR; + HCR_EL2_TIDCP | HCR_EL2_TLOR | + HCR_EL2_TWI | HCR_EL2_TWE; } void vcpu_reset_hcrx(struct kvm_vcpu *vcpu) -- 2.56.1