From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796220766; b=UO7B1b/OwJbQfeYbzBLBsxROsGJt9a7AhNzFmoo05SsBmYJDOhB+gaXbSp5llPWDjfAt KSYA1Z2wA4kv2NH3QiGF4GYR878iTC+w63DM1t0qbONP2Xr9OklJES5YU3W/TDr0FcAk2 ZpNsqFMPD2zt86LfS8o5DKflTfuvo18TB15pkgIY5SA9zwacqgotgu7J3SE7UrDCJKsjp fCib1NuZA2lahS1Pfc3kc3qPqoXbyrIs5vuA30CqiEzGp3MMnzM3RQmkJWCRXqMcOoDIn uuPJtoKjpdFVN9XD0FclgrdnGGwWjfDunF41Ueah60hNKJyZW8YXEj/OzEhhXU79TAg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796220766; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:From:Date:Subject:MIME-Version: Content-Type:Content-Transfer-Encoding:Message-Id:References: In-Reply-To:To:Cc:X-Mailer:X-TM-AS-GCONF:X-Proofpoint-ORIG-GUID: X-Proofpoint-Spam-Details-Enc:X-Proofpoint-GUID: X-Proofpoint-Spam-Info:X-Authority-Analysis: X-Proofpoint-Virus-Version:X-Proofpoint-Spam-Details; bh=K+syVaiR7B9VOOOlu+TZnkRX+MggRqsqOxN6NVuJg/w=; b=fx7w4apEcUBP9ciiOoJKnOCvSiHMVLlSCXMb4HBSJvzck30I1PP0/9LGEI+wckYG92/z SoWktp29FQpzqcF2LvLQz5NVX7H6PGu8/ujiMnvnBIhrfrZeFUal2Zri5mQ3teUSJlqep 2WNyMwAQ3Hk7p1epO9Wl4z5cZL70dGXrvtMfyyYYj8d9H3wtPgxP1JdbG0BXgfJvHzURO dIu+FC5mUnhaDKPWNnU1DVO85pwLDVGdxcJfXSM7FNt8m+HnIyAGgEyGPmx4i8xP7gNcT 7ybA6Au/tjAehLbEDaEyq7DhJXum6XZcFLOv83n+hbt18XpXnyb58DWPY3n1aCRkHyQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=TOcYtJEa; arc=none smtp.remote-ip=148.163.156.1 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (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 E27E6606A32F; Wed, 2 Dec 2026 14:12:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E27E6606A32F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=TOcYtJEa 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-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list 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 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