From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.128.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796028526; b=2PQP0TmobiCtH5jBB//D/UR5dnKFs7HUPSWiSkv9jgNJ8G4RnM07dwfUShg/itAihR0z zAkz5wbtfn7Z7xUJuBcjDb7O94fO3kjOptEWVtAuSziL/IdL7saisXBW6G06oh7y5Zwyk hBc2Chkw/r/S6IfwdG4IOm9lIw4tX+dBtD0cwFMGFxyT7Op3j5pUKBblHa1Pq8L6qN8Ar jAgF7O+1TVmyOnNJ0e5dbzC9DA1KQ0uveP1Mhv0aP/YatDwVWEda7MNHDjUE44hiL1Dpp +iAYaxrlKeEY/p0SHKf47/fKLPEYju9b9WnciVZ64e7W3hZRhh8t0glXcz6qMpNq5jQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796028526; 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=1DRM/vpAPPvKW0KqhsCCesfCc6Ts8gukp17HEg6g1v8=; b=EU8hhY8mVgqYsjiKJUnb+mgI9sYc1Pc2kMHjAybzvTb6rgMd3CyFxQ9/6t/Occ3riuDi sT23wGVduFvrKRdxPzgG12YHvXCJQAPURDtQilv5Oql37dGD80AgycC1TRq1v832qvMcG TgjDQt9p/ZWdlHMifug9KreN85JyKZGWu49DI/HxxLDnyzuJE3I+bor8+vhLwV3onxAz3 Z2gwudHdD0nyW7TYSIAn3QQuiNugManFgNvUytpKsf/QNp7vEFMZISFo97KgFs41RsqCc AGrIdCt9ktTBeogHpCMQRdrwy6EbRnb8sE4DmgSAsQ+EaEbTM/SZ4mlbeWwlTgE3ZPQ== 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=PNNWrT8v; arc=none smtp.remote-ip=209.85.128.45 Received: from mail-wm1-f45.google.com (mail-wm1-f45.google.com [209.85.128.45]) (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 98849606A6B7 for ; Mon, 30 Nov 2026 08:48:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 98849606A6B7 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=PNNWrT8v Received: by mail-wm1-f45.google.com with SMTP id 5b1f17b1804b1-4a1fbd52ab6so70027785e9.0 for ; Mon, 30 Nov 2026 00:48:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pereq.eu; s=google; t=1796028524; x=1796633324; 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=1DRM/vpAPPvKW0KqhsCCesfCc6Ts8gukp17HEg6g1v8=; b=PNNWrT8vvWf0C9IcR70s1zX0+dicEa6xrnXTON9RnXL8AzO1QRCv6spaMTCGD+E7SD T6S475IBqLyXUVL1ocx7U1/g9C+fGxd14czFVtRGpnEx+3PU/RhZmuH/1r0ikAVIn8Lf 5DA3nWrAz5qbL6zV1IOjWSXTtpazCgwMSpztUykVzVkpkyGSfgpQdM/ipqAwOQhDExiy ItD4d6gtJV+2Sl5hNskNYpTD8aFxvQZkUef9EP3wk5ts+DKBtUYvI2RqEwrh0ASjNgMB MgBiVj2uky2PBb0h6w1D7gsM1yFDA19hlWI3xt+tPJa58AKVExPuJScl0ScT25Bme8iY QKnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796028524; x=1796633324; 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=1DRM/vpAPPvKW0KqhsCCesfCc6Ts8gukp17HEg6g1v8=; b=xoFK5RIjnZEIJW/RpNyx+ie85uqCmqaWjD/L6ACDXuco9OULFMOyfbVOQuXOAaRDhI Bly6uyanHq3eecj3jPzj4colWKtfdM3KC89OALJ6TP4ejCATjAWbDh9xxo0JaGwCeDqk njboLDzsqKv/FMsE3WUvH67FiEGuorRvSQYZFLI9sPAYmMXrEbWxMIGt+umzPhpnntBD g0m4DD7v6Dha5CHyWEl8YR9owAKSb9vZVgJjvpP7/QbPpBBiVyzvBAIalgz0kWHOivlN 15RZrmuIm9jvdCiRNEhhFTQ8QXhfM+lj2GWCUvslrhufWN0vcnnB52NKQOFsP+oLN2hc PIbg== X-Forwarded-Encrypted: i=1; AL+hErH9ILA7h2baYdsLGTp2cL1BfnU6/6rCP9wO+OsPBoQDKTy5jmWwFh4Q3Ny/z/lE+lBCmuQH4wYUySVPG/8=@vger.kernel.org X-Gm-Message-State: APuU4Z8fcnf/nNjGZ+RXZIago4SBfOkP042SP4qF2lxvIyUInV2qKWW1 zwjJF5B1oZiRXuE4vUpTCR4km0DJoOVKjW+2BQTwEGs1ZGUC5RWdix2I9GjWsz6zvCE= X-Gm-Gg: AZFdTZfEisyVCoBJSKPO3jYzRiVInVIkwn7hQsDtjJ3FjDhubO26HydxDdwI5egyt0s lmIZXz06ZEPJao2PV4EdSfST+w0QARxBGd/7DZutsBE8qdICu1IxleC7c1UdEcTDm+TBGdBwg97 DrlscTa0X3MW+IESZYKBGl0LLE1d1Y8otF42oA/aMzS95ubFEbW8lrb13T3hezBl7L4qg/o4h02 EIheQ5s4gm4ErRbXtCEba37o7IwS3KMh4OngbT+6SKxMuGaLwsEsWHe2Z1sT0kRxjC+mkmnjl8Z XdSnfWzMyZUT5FlCQbPBqYMe4BjAN6eKkYzg6idBWemTAeK/0RtmdZTGhpQWkv3j9NuXF2KE0wA 0SC6iyAhijxB1Dd4uIdoo44yFbUaiqud4k+Q7Pq+w9/cHcl2a/smSuw4ZTMck6vo+jScXYh2I3X XyQCncqdv6Doj+l8Wow8T8tsO2O8AvozXFbCExAUsj+nFgK72rmElU3LvaCQVIjr8US73cFwEiL Tcr8OO1ROo+YkPB0U5AChckrn1JgYAPb/LzoKTsQKXlbdaJ1kJYi3/Z0nVNDfSxtLCe6Pq4chOL pOO6PmsDIUACvB3tClI= X-Received: by 2002:a05:600c:5246:b0:4bb:60ba:49e0 with SMTP id 5b1f17b1804b1-4bb88930707mr690379695e9.26.1796028523703; Mon, 30 Nov 2026 00:48:43 -0800 (PST) Received: from localhost ([2c0f:3d00:6be:8900:ce5e:9212:ea4b:f30]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4bb88442995sm966400675e9.2.2026.11.30.00.48.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 00:48:43 -0800 (PST) From: Dan Carpenter Date: Mon, 30 Nov 2026 11:48:19 +0300 Subject: [PATCH v3 7/9] KVM: arm64: nv: Don't deliver a pending SError to the wrong guest 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: <20261130-double_exception_v3-v3-7-864856664b26@pereq.eu> References: <20261130-double_exception_v3-v3-0-864856664b26@pereq.eu> In-Reply-To: <20261130-double_exception_v3-v3-0-864856664b26@pereq.eu> To: Marc Zyngier , Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Mark Rutland , Rusty Russell , Marcelo Tosatti , James Morse , Sebastian Ott , Eric Auger , Paolo Bonzini , Sean Christopherson , Shuah Khan Cc: Dan Carpenter , 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, Sashiko , stable@vger.kernel.org X-Mailer: b4 0.16.0 With nested virtualization, when we inject an SError that the guest has masked, we set the VSE bit in ->hcr_el2 and the CPU delivers it once the guest unmasks SErrors. The problem is that the bit stays set when we switch between L1 and L2, so an SError meant for L2 can be delivered to L1, and the other way around. When we switch, clear the VSE bit and set NESTED_SERROR_PENDING instead. This matches what kvm_nested_sync_hwstate() does after every guest exit. Then kvm_nested_flush_hwstate() injects the SError again and decides where it should go in the new context. Reported-by: Sashiko Closes: https://lore.kernel.org/all/sashiko-outbox-229065@kernel.org/ Fixes: 77ee70a07357 ("KVM: arm64: nv: Honor SError exception routing / masking") Cc: stable@vger.kernel.org Signed-off-by: Dan Carpenter --- v3: no change v2: new patch --- arch/arm64/kvm/emulate-nested.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nested.c index ee71dfc4b861..d1446081fbbf 100644 --- a/arch/arm64/kvm/emulate-nested.c +++ b/arch/arm64/kvm/emulate-nested.c @@ -2792,6 +2792,18 @@ static u64 kvm_check_illegal_exception_return(struct kvm_vcpu *vcpu, u64 spsr) return spsr; } +/* + * HCR_EL2.VSE was set for the context we are leaving. Store the SError + * instead, so that kvm_nested_flush_hwstate() routes it in the new context. + */ +static void kvm_nested_stash_serror(struct kvm_vcpu *vcpu) +{ + if (*vcpu_hcr(vcpu) & HCR_EL2_VSE) { + *vcpu_hcr(vcpu) &= ~HCR_EL2_VSE; + vcpu_set_flag(vcpu, NESTED_SERROR_PENDING); + } +} + void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu) { u64 spsr, elr, esr; @@ -2823,6 +2835,7 @@ void kvm_emulate_nested_eret(struct kvm_vcpu *vcpu) preempt_disable(); vcpu_set_flag(vcpu, IN_NESTED_ERET); kvm_arch_vcpu_put(vcpu); + kvm_nested_stash_serror(vcpu); if (!esr_iss_is_eretax(esr)) elr = __vcpu_sys_reg(vcpu, ELR_EL2); @@ -2909,6 +2922,7 @@ static int kvm_inject_nested(struct kvm_vcpu *vcpu, u64 esr_el2, __kvm_adjust_pc(vcpu); kvm_arch_vcpu_put(vcpu); + kvm_nested_stash_serror(vcpu); kvm_inject_el2_exception(vcpu, esr_el2, type); -- 2.53.0