From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796374114; b=YbUeph6Cq86SuSB3Z0LVq7zyjmJoVHOTYnkNJLc7iy8Dsy3Iqizz/3szDEQK3xvBOBOi bNFg47ztLZHzzSTv0W/f1Ks6C2ieiDG1pYVP34agIG87bgrFf4z+yn2wMN37kHLX7VEH5 LV3SSz+QQhz58U5rqe4b5v0GhuyBdtY0wNQ+eSw37xwHnrXz9Cu2vQ6E6xzGXdHRNNoGq Sv7I9KzNgjlMHB13DYzRd2i/RuBuoxAJQcs38uXU/BlHP64L9QZnGOATjEGwNeRnzkP38 0SMc3R28VjBPcxqXHwi+O31LAeVPTOfFY6qaO9v7T1i08r8Tg6QyYUHyFwLLLr7Rvfg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796374114; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=7Yb8cBBFaSiz9En7Z6XhvBshjgPqD3yaVPHN8aR/uDA=; b=x/7BGeO5T1df6UyjBORY6h+cKGtHOg76yFYdwcR+ZjgxT97YazDP00qxjlxBJKtA2LvX ajJ3KPGYGHXJ3tOBv302NxeObpofJ2j3DOL3hMS8vuOKUt7EJv03TS6toBHCrm0Pl6Q/i OYfCYS1VvGJx5QgFCa8gN19EnzrIWBg29fuiqgcxkX3MYeF9mDarhpV8i/xX6fTlsKft5 HV0ZiPrj/YvY4IONBzGzwVHyxmmDdpkePvliqkykVjp3U5FPo3XZzGnbsczJr823khVsT ezEpGG3+Qjl/fbj2ABeCa0/50q7zlJDR4Pne6joiID3cnwXXoN1WF9kQBOHpIwxOPSg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=pereq.eu; spf=pass smtp.mailfrom=cryspen.com; dkim=pass header.d=pereq.eu header.i=@pereq.eu header.a=rsa-sha256 header.s=google header.b="EDIkYTV/"; arc=none smtp.remote-ip=209.85.128.46 Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 E67E5606A688 for ; Fri, 4 Dec 2026 08:48:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E67E5606A688 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=pereq.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cryspen.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pereq.eu header.i=@pereq.eu header.a=rsa-sha256 header.s=google header.b=EDIkYTV/ Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-49d05d51553so4174965e9.2 for ; Fri, 04 Dec 2026 00:48:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pereq.eu; s=google; t=1796374112; x=1796978912; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=7Yb8cBBFaSiz9En7Z6XhvBshjgPqD3yaVPHN8aR/uDA=; b=EDIkYTV/VBdawSoxUsTcAb37z1hf4+NdVaylygGe+zZroXCsBITg4tjj/pxod+4cXm knMAKmmt+zaeEtvGGFr8geBMc6hd4Sim7RP7GXqLP/AZpB572Z+7ltwYDrq7ZRyA6PPC aJKBiy5r4MYBeyl5/+LSjUrc57mIF8Dh7yCiKlBoknaBqwlcOaEnPkl3aV7M0e2Je8aM H/qHyVQWlr3gBVH8le1yWJjtuWNKpQxpwwS8fdYsjvR0l0An68rcXPD289badGSpL4uS Zfwp2MBDvXHLdOHUzGud1HrEjt5m7piHo+MWVtvlHjbE2hWy2AZAK3pma1Cr6wHy7GJW bcHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796374112; x=1796978912; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=7Yb8cBBFaSiz9En7Z6XhvBshjgPqD3yaVPHN8aR/uDA=; b=BK/z7cOxAV0z6os84LvIDWhXBC+wvGHVfRK+oswymXo+KD2CHkmf3DiCCCbaMJTgzo o1DRSTN7VPP7fOue/gZzN0f1izAQ25eVt1aPISK7New3VuhgNNRe5Swy0Kza+jckCpF4 clCx6P2DpUzafnUvJk9w8PhemfHr31ajjrMyPFbaq2SzrW9GVxmQ/UiALgEZyNdKFNPg GaB7hh1PB8U5e31nMepLaMbn/yIUkfUvrnlq1JkPXPnLdgR8NW3Nb6IqMT9IQQA/l2eU l5Tk/ekXQTcIgai1X6sRbOpIsxtri/pWSw0e+kqWc0J+sBAf1g9YoAmO5hYiosvud0y2 XaEQ== X-Forwarded-Encrypted: i=1; AL+hErE/x2s/g6dxzEnMsjbwHyhTOIxmz0aT57w43p27EDN7l+XaLsoHhSvADF9Do+DrR+lKymshoNvndvt5vuo=@vger.kernel.org X-Gm-Message-State: APuU4Z+QH3rJlj4halfLxQcatDEl8TKxEjmKIJpgCi/mL9vsXAYyDaww G+OryhXWa1GBSUdPIgto3yWLXF/9ijW9gbu9hmXO9DLw6ytosrdhr6Wz+kuSVzEUBzs= X-Gm-Gg: AZFdTZevCyTpdUEPbJmNnvu/p82bV/rZgb5vD7h/ap80Uezic1YBu/RXsO62Tjjvbqe BPx+49mL4Dj4DJpxp3wN/ynCYgrAiMOXekPokOOxRxbysaOc9BQUS6/dDk2WQoRnQwJvtE49LFl 1YoQzM9OR4L7zQp+TIejWBB6Kygp125sdJZbUnnrqwnIIWTQ8PHQuvMrmu9L6VtxQwHHnq+ooVl xQNG0jDUbsfc+nTG8QbvkMUn7IdHi8UX/LV3ed/u50jZV94NUzq/FHnM6kaeudL7dRSt7QZ05aC ueRdrMPLRFtKRlFe1eYz/ZtRWVxedYIxnp59zdfSQdqzPZAL0ug+jWN9trdqL8jgfG133NqGFlG wZ6dqCVif8NNm9fm/eSsfThaegSw5pD9OvV65b0VgLQvStOY5NO8a7HpLUlnOAYyx0XEz15g0qO KTAd27t1xfVBEanZL2PdI5VfCPklPdgGf3ItZSnPQZdaxiEbk3w5BnQEYOYZ0uY2Y+0EAQDGFsN eptisVrlQdi6/OO/5XLqF7B2RUblR438JC/hRooYYh84q48jWow/1HkLPYlHnFpoqP+Chdbj/zp JD+ABTs3fT+DFZHKBG8= X-Received: by 2002:a05:600c:1d0d:b0:4bb:5c97:f4b1 with SMTP id 5b1f17b1804b1-4bbeb8e0cb7mr24740755e9.24.1796374112322; Fri, 04 Dec 2026 00:48:32 -0800 (PST) Received: from localhost ([2c0f:3d00:6be:8900:ce5e:9212:ea4b:f30]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bbea285a26sm36324285e9.7.2026.12.04.00.48.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 00:48:31 -0800 (PST) From: Dan Carpenter Date: Fri, 04 Dec 2026 11:48:10 +0300 Subject: [PATCH v4 6/9] KVM: arm64: nv: Replace a pending SError when injecting a new one 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: <20261204-double_exception_v4-v4-6-523921511673@pereq.eu> References: <20261204-double_exception_v4-v4-0-523921511673@pereq.eu> In-Reply-To: <20261204-double_exception_v4-v4-0-523921511673@pereq.eu> To: Marc Zyngier , Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Marcelo Tosatti , Rusty Russell , James Morse , Eric Auger , Sebastian Ott , Paolo Bonzini , Sean Christopherson , Shuah Khan Cc: Karthik Bhargavan , =?utf-8?q?Cl=C3=A9ment_Blaudeau?= , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, linux-kselftest@vger.kernel.org, Dan Carpenter , Sashiko , stable@vger.kernel.org X-Mailer: b4 0.16.0 The kvm_inject_serror_esr() function injects SErrors as the name implies. The bug is that it doesn't handle already pending errors correctly in nested virtualization. In vanilla KVM the kvm_inject_serror_esr() function always sets the SError to pending. However with nested KVM, it might set it to pending or it might deliver the SError directly. We can only have one pending error at a time. Imagine we enter the function with an SError pending already. In the current code if we decide to pend the new error that's fine, everything works. However if we decide to deliver it directly then the pend flags should be cleared but they are not. So we deliver the SError directly and then deliver the SError that was pending on the next exit or entry. This bug can be triggered in the current code, however in a later patch in this series "KVM: arm64: nv: Re-inject a stored SError after the exit is handled" the bug will become much easier to trigger. In the current code this can only happen when userspace changes where the SError goes between two KVM_RUN calls. For example, userspace injects an SError with the KVM_SET_VCPU_EVENTS ioctl while the vcpu is at vEL2 with SErrors masked, so KVM sets HCR_EL2.VSE. Then userspace uses KVM_SET_ONE_REG to move the vcpu to L2 and injects a second SError. L1 takes SErrors from L2, so KVM delivers the second SError to L1 straight away, but HCR_EL2.VSE is still set. When L1 unmasks SErrors, it takes the first SError as well. After the "KVM: arm64: nv: Re-inject a stored SError after the exit is handled" commit then kvm_nested_sync_hwstate() only stores a pending SError when the guest exits. Then kvm_nested_flush_hwstate() re-injects the SError before the next entry. In between, KVM handles the exit and may return to userspace. If userspace injects an SError during that time, for example on an MMIO exit, the stored SError is still pending, without any change to the routing or masking. So this patch has to come first before the re-inject path. Clear the pend flags unconditionally at the start of the function. Reported-by: Sashiko Closes: https://lore.kernel.org/all/sashiko-outbox-229065@kernel.org/ Fixes: ce66109cec86 ("KVM: arm64: nv: Take "masked" aborts to EL2 when HCRX_EL2.TMEA is set") Fixes: 77ee70a07357 ("KVM: arm64: nv: Honor SError exception routing / masking") Cc: stable@vger.kernel.org Signed-off-by: Dan Carpenter --- v4: no change v3: Add how the bug is triggered to the commit message v2: New patch --- arch/arm64/kvm/inject_fault.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm64/kvm/inject_fault.c b/arch/arm64/kvm/inject_fault.c index aa2011cc0d5a..0f6a89b65074 100644 --- a/arch/arm64/kvm/inject_fault.c +++ b/arch/arm64/kvm/inject_fault.c @@ -361,6 +361,10 @@ int kvm_inject_serror_esr(struct kvm_vcpu *vcpu, u64 esr) { lockdep_assert_held(&vcpu->mutex); + /* A new SError replaces any that is already pending. */ + vcpu_clear_flag(vcpu, NESTED_SERROR_PENDING); + *vcpu_hcr(vcpu) &= ~HCR_EL2_VSE; + if (is_nested_ctxt(vcpu) && kvm_serror_target_is_el2(vcpu)) return kvm_inject_nested_serror(vcpu, esr); -- 2.53.0