Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.227.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796097590; b=UIseUPWc15hfqI3WB66ZOVfaekQz0bFZjm1S7j0uLgMPqqdlU/wUexMGDJseUpBrrj43 oXL5FuzrWedf1fkQKyyh4u4ZcHiMwM5YM7OegtyOQY3LS/ftvY+y6d/bkiGg9kX4WFnPv 8Yq31+bOQXjWVgmCPO6Lv6FscAnzpCIMfoEqMdnoJFpgAUUR33uo5BxlYCDQqmxVoADpN zNtn1tsGb0jsfyL/oek7eBUA14Cvac+c/aRLT+vo+v6EZKNEIon9MIWRgLvTpqC+ndVeA FFU4yPvzlYGKeNTSXVq+c72lobJALaMwsYemeMQvAPYscUct2PJVR7Upn9iO9YN8Q3Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796097590; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=xXreIexpxLl41tC32Yh4UKH8BI4r2PafZ3CmQY1owok=; b=LH/UP9sC5yag5WJQnbGPDypA/KoMelU320l6srDxuQZkOA+SdcE+Q7OnwDcUXbCKbzid ODImGP7RZGHrjMBiwdnANYE/0FLk09oEExzAy1GW8wiZHtzluC9YIHgL+l2GA/6yISoLQ gOWLCbfOe4MxrGQCvaoHKGlthuZXjdjQL/kabVCCuW5CDSHe3ergT4LATtbhw/aUBmDyH KEL9U1DzwF2seQIsCa1i2XCkkT2ZHhWRg27H1araY9qauVw+RHlTEu7+fHuZd5mLCF5eB /VTuD5gdkUIKnJjxihUAQhqo32lzOv060wmUOQ1FNehqKKURJyC+HDwbSuoqoF8PnWg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Vy7AWaOD; arc=none smtp.remote-ip=74.125.227.131 Received: from mail-pj2-f3.google.com (mail-pj2-f3.google.com [74.125.227.131]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D75BA606A31A for ; Tue, 1 Dec 2026 03:59:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D75BA606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=Vy7AWaOD Received: by mail-pj2-f3.google.com with SMTP id 98e67ed59e1d1-3b497279bf2so893125a91.1 for ; Mon, 30 Nov 2026 19:59:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796097589; x=1796702389; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=xXreIexpxLl41tC32Yh4UKH8BI4r2PafZ3CmQY1owok=; b=Vy7AWaODxDIr5nj7vt8Kfrs4DVHRlPS/P3Qh7Pcnd7SqPGaKL+auGr7CHKp5IJUmJU c222r5ZY4nNqkxJXVh3e/55AO7lNUM205hZG/nUssFo0yKqSzahRlSIcnUDQ1YIxmnrU 6AcXhctm4lsl/utTnjD2SvYbnAqEKZj2gPEWPZysQcN5qC0EMYVuHKYxfMaxf8qSfybY xLfoEz489GNWas2G87Ouz49P0QhSuK/mpmuNROapyDXJqw49j8sHgTKVh6ZxyM+asrbL WBgiGbO6vNqgKun4eI/vBDXAJT3wCAlgr4nWYd5nWNgfIiJ9krulFiS80VqEPzOgX7HP cxLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796097589; x=1796702389; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=xXreIexpxLl41tC32Yh4UKH8BI4r2PafZ3CmQY1owok=; b=ukd0Sp4RGmftAK+5LoQRoosy68MRLiptFAMJ+IEnlNOKCIivUryWrN91Y2R5e1vAyy KMAuzIash1xRlbIDfrkUMy/zq50J3f5tyAncVwDfVi1+QUnv8gMeD6zDFfjEhm7P9+ju SZcINbiIc3k16bxRPrkFSRVrwmMYvc0CSeV7YmX5ymzfDI4cPRayrAfKyFfxcPfENyIf bAPiGP90cZ4Tc162tO/1Mt82OY1xjsCC/VEGHgdiIz98u56glMBjNmzHnKEV/ks08ToS kDm9dl67cOK9Kwcq4CPK+N27Gh0lPKYyNmY2MPdFIn6027pUIOhLaH09uLBo0FdjZZhh 6wZQ== X-Forwarded-Encrypted: i=1; AL+hErHwV8aEL8kr6zkFDh59+kye9RRmXWSAuwRkHSXd47Cw/zpTkkqmhXQ1KzptQdrIz1aUhec=@vger.kernel.org X-Gm-Message-State: APuU4Z8zKDzr3q0h7fyMLijx/7l6xvThzXPgdDBEQZvIRtjs876iMllI dYBMwqhSDKOx0aBxMjb/IUcvFDOy02TvAhTj9N5hvQKc+Mke8Nap6UFu X-Gm-Gg: AZFdTZcJd5LLHBszUpl3oe3sRGifY2H/m8h2Aq7S98nlYYeLDQREV7U/5Wenbp2ySnV Lr8GbOm+7r5x+yzO9/f2x6RF8/p7JMgWtdTUuV69ADGfoLyobjjpTiXbFtCQ/ynx9v7S1SOTvkE BVDSukYshAdZDvHelIQVKYv+PxwK212hMcp/VtHBv49KAPwk+3gaxQmGDT6vSCUhnIQjWInkHUd T+22+kyXF04gmc+l6ZZbQSBAxolqymFEvuvthrmLEXW1omLyZtfhdOKLutnGm1wQLcO5fvQxaAP Fk/b4SvF5zYsIKt1BFQJghbKSrTXmsZHGh4FhoxKSZzUSiKz0c8cXzUxPeR+kx0e6SemwtjA9Yh rfpyytlpCIVfzjc4BXr0l0KOP5n4B87u0Z/UYm2xHHJ4F0MckwfGjm4K/95Fz+zBW79RD3XUiKZ P91AgJscRAXVV5LpCjQM4D0wjuB3+qWUEdR5nqIKtSzFU0YPGS7DjJltnUrp39BKCosPIPI+bCB Ii+Ak2u4Sm5A4i68N89xLdXHOjasf10cKu9Im4tn6SMOWvEGoBlUCmzNHqpgTlM9i8qTd/PNksW sNr4J0qVNNRBbyqEE3kS3dRGmVA+NsE+DgtHT2QP/caVU7hIxFAnlUHM92iWeWaRO87jJFV/fsD ORdOar0VhGSJ1KcTnIvu3WZqtTg/M X-Received: by 2002:a05:6a21:2c15:b0:3fa:349a:f54c with SMTP id adf61e73a8af0-4014de5db82mr27983379637.30.1796097589072; Mon, 30 Nov 2026 19:59:49 -0800 (PST) Received: from zihui.lxd ([137.132.218.138]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c87285ccf4sm18243323b3a.12.2026.11.30.19.59.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 19:59:48 -0800 (PST) From: Zihui Guo To: Anup Patel Cc: Atish Patra , Paul Walmsley , Palmer Dabbelt , Albert Ou , Alexandre Ghiti , Quan Zhou , Inochi Amaoto , kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org Subject: [PATCH] RISC-V: KVM: Redirect software-check exceptions without henvcfg.LPE/SSE Date: Tue, 1 Dec 2026 03:59:43 +0000 Message-ID: <20261201035943.3737302-1-youzih27@gmail.com> X-Mailer: git-send-email 2.43.0 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Landing pads for VU-mode are enabled by the guest's senvcfg.LPE. henvcfg.LPE and henvcfg.SSE only cover VS-mode, yet KVM redirects software-check exceptions to the guest only when one of them is set. When a guest enables landing pads for its processes but not for its kernel, which a Linux guest does on a vCPU with Zicfilp but without Zicfiss, hedeleg does not delegate the exception, a landing-pad violation in any guest process is taken in HS-mode, the EXC_SOFTWARE_CHECK case leaves ret at -EFAULT, and KVM_RUN fails. An unprivileged process in the guest can thus stop the whole VM. kvm_riscv_vcpu_trap_redirect() has the same condition on forwarding SPELP, so a trap redirected from VU-mode loses the ELP state of such a guest. Redirect software-check exceptions from the guest unconditionally and always forward SPELP. Without Zicfilp, SPELP reads as zero. Fixes: 864260d71d82 ("RISC-V: KVM: Handle software-check exits for VCPU") Signed-off-by: Zihui Guo --- Tested in a nested setup: QEMU 11.1.91 (virt, aia=aplic-imsic, cpu max with zicfilp=true, zicfiss=false) as the machine, this tree as the L1 host with KVM, kvmtool, and the same kernel as the guest. Without Zicfiss the guest enables landing pads only for its processes. A guest process enables them with prctl(PR_SET_CFI) and jumps through a6 to a target that is not an lpad. Before, KVM_RUN fails and kvmtool exits: kvm [66]: VCPU exit error -14 kvm [66]: SEPC=0x1075c SSTATUS=0x8000000200806620 HSTATUS=0x200201080 kvm [66]: SCAUSE=0x12 STVAL=0x2 HTVAL=0x0 HTINST=0x0 After, the guest kernel gets the exception, the process is killed with SIGSEGV (si_code SEGV_CPERR), and the VM keeps running. The SPELP part is not covered by this test. Not tested on hardware; the test program is available on request. Assisted-by: Claude:claude-opus-5-5 arch/riscv/kvm/vcpu_exit.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/arch/riscv/kvm/vcpu_exit.c b/arch/riscv/kvm/vcpu_exit.c index cab46eb32e9d..e1c440c7d441 100644 --- a/arch/riscv/kvm/vcpu_exit.c +++ b/arch/riscv/kvm/vcpu_exit.c @@ -175,12 +175,14 @@ void kvm_riscv_vcpu_trap_redirect(struct kvm_vcpu *vcpu, /* Clear Guest SSTATUS.SIE bit */ vsstatus &= ~SR_SIE; - /* Change Guest SSTATUS.SPELP bit */ - if (vcpu->arch.cfg.henvcfg & ENVCFG_LPE) { - vsstatus &= ~SR_SPELP; - vsstatus |= vcpu->arch.guest_context.sstatus & SR_SPELP; - vcpu->arch.guest_context.sstatus &= ~SR_SPELP; - } + /* + * Change Guest SSTATUS.SPELP bit. Landing pads for VU-mode are + * enabled by the guest's senvcfg.LPE, so this cannot depend on + * henvcfg.LPE. Without Zicfilp, SPELP reads as zero. + */ + vsstatus &= ~SR_SPELP; + vsstatus |= vcpu->arch.guest_context.sstatus & SR_SPELP; + vcpu->arch.guest_context.sstatus &= ~SR_SPELP; /* Update Guest SSTATUS */ ncsr_write(CSR_VSSTATUS, vsstatus); @@ -275,8 +277,7 @@ int kvm_riscv_vcpu_exit(struct kvm_vcpu *vcpu, struct kvm_run *run, ret = 0; break; case EXC_SOFTWARE_CHECK: - if (vcpu->arch.cfg.henvcfg & (ENVCFG_LPE | ENVCFG_SSE)) - ret = vcpu_redirect(vcpu, trap); + ret = vcpu_redirect(vcpu, trap); break; default: break; base-commit: bd68956997dddcc3b1a7dd2fadadf584529027a1 -- 2.43.0