From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.52 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796374117; b=J9z+XlyuAkFepJtlqhOf5fD6oCidyX9C8OG8WfHfMR8Pcj85AI2/rNH4H5EWraLUVv9z x6eR98okwE45w5fSx3fH/hVclhafQwQj2rKS880VjHtQh72EeWRutNw5+2Sk+s7tQqd0I lY4YQhxvfdtV9bQoiqZTKKIlTt2Y/S7NzBqHYk+9RWyH4ZI6qXikFRZwPsiFTrhyiw79l xwf+q4umFhKOCqy7aK9Uck3dkDM9XsBK6UGsTSds/QhUCgmZAzgcTtj/gOSOhz5j8jmWJ Sx2wv+kLl1u2Xwte9SwSF/jMfAMVb+3s7tdJjgzBQ0MZb+IWpemUSaCSctbG8575yqA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796374117; 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=EoYx4IoaOFcZWxc1qhMzMe3DEEZVV0+bDsmFlnX0kBQ=; b=32ZD+f1sMW6WKOw825dLsel0iFNFiRCbKZI84pEs1IUgzPjNFUe/3NpVOw572F/gkwfA RMt/QhQhwGUSEqyeUiVKJqvXCf23rbGbFHiGsrgdyKol3IyIGGeifaTAj9e4qW0fmiOSp +YVD3r3DRbCsc/cc07lWicXztlqrzGqNZ9NKmumew2s9wBVV5J7vn84AFQPiP/IOEsZMM BUFYM2L2lLHE8sJAWQkX+IX0zTIS36pQPkv2bcGHBayA849gmwwB+BEY4hoYcW7QBRpXz HmimaUA9s08HZv+8tGO6/CF3Evqzcu52gTtcHwfqWMtxOWezAej6JIyNUJwFNVxLb3A== 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=e7z9xjli; arc=none smtp.remote-ip=209.85.221.52 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 BF937606A69C for ; Fri, 4 Dec 2026 08:48:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org BF937606A69C 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=e7z9xjli Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-4acb44dcd7bso756782f8f.0 for ; Fri, 04 Dec 2026 00:48:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pereq.eu; s=google; t=1796374115; x=1796978915; 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=EoYx4IoaOFcZWxc1qhMzMe3DEEZVV0+bDsmFlnX0kBQ=; b=e7z9xjli4ozC9DdZVKxmqABirI8mQZyWnOAW+dcOnZHyKfTxe5VZGKwXj+GqLiTw3x HfO2xqF/RQW1bELDjzg6EJaD2YBMM/mUM6CPLc/BeddCaYZik0qyRHYpAAex015nj/Wi Zy/wbJtW93drhxCcntfbcf+WfW56fhqYQPlvcdifh2Z42ql3JVnwG2s7xoJ8BTwRDAxp +0IEBTBAw3ykGSI9sV0w4dvXPgCWxpBZzs98kH4oeqcJv3HXvou3rEr07IQA8Y3T7Gnu A7rwOFlSRKsVJHc3bm14sdqItvWEL6x3czaxV0HdXY9mfaOX/m/1O154a/EixUHluCLr jnDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796374115; x=1796978915; 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=EoYx4IoaOFcZWxc1qhMzMe3DEEZVV0+bDsmFlnX0kBQ=; b=x394ggrG6ws0/tElGipsHzmlQWQiJ46NpJ/rivK/VBCjy+wENpBNaSR5axLvOfAJm9 YEPQUyN/uy8u2rTtC5tXkDEnKipTkei81AKivw6P//F4zr8nmShwRnRvNjp5XAayXCqW 1mvuwHro9273Von/17kkQ7HAYwRWqlS0VgcNtqZcqiubZUZIJ4EL2G4xOs1AQElD0bWH scR/klVZvlltgYYk0mPQHPaCC7NRKmML7ei0JDAZRIdgcnwjP6I53WHuXTSHAwxAjwrj AtNR5Q8U92eKtS59dGnQvYeUKk4R3fQYVlwLZMgWqcMsObVyVIop+94JaWrsNz/WYBha dr3Q== X-Forwarded-Encrypted: i=1; AL+hErG8wADxqLrza2vYIwec3o1UQAkyM41Fq6uMuxSCRakbq5I14PdCKJk8wa+EcK3qR59e5i3Ks/Zm/jKVp+c=@vger.kernel.org X-Gm-Message-State: APuU4Z9bGfDyLz7Yyf+5k91HW0FAVOaUpJapM62UfzL4cpEpzuoOAWJn uSaMcyC57g94sI3oTwBrd+CoU34uNOb0bPuVzvw9if0AwpeUSrW89Eyq2bnZ26CDAOU= X-Gm-Gg: AZFdTZfTZEIE43wcZnjc8LEZDNjLSOnl8MqT3HbUTHJLB5Rdj5iiTMSC64dOW0cNQtC qDo4zkEa83eubrENyebYdgAFuhcph7A4KDRs3vzgw7/+TRdKNyJzg/7eSo6pu9ifdAxPmzjpX06 ClT+6IuRXjeU+X4XAxEmYWn8WrE5gVcyI1PsPrNgF5tKUgXPa9VEyp7q7TA81J8fLBimNAETgjv LagqXJXj801dt7arTWFrV72xj7nVRiSIkWX0zNtiI8+kS7MCQelxmHQveQJeRcsdZwto0T/+J2L S9n3/k4E451mqqaoahp8cTEIH1EpJ2HWGb+tAnDFZzW1WYrjIV1RGEpoPtr5BzcsgY/FZd74R9F Yi0iYyRsgJFgupazsqkPH/xocYfP58S8XheWTpEojpLwbc1JoTde+OGroScD8cFGhlitKVcPxRN elVseorXpfWjUHFXMCVy73ujmqL1Kw0CkJ59TBOyspxCOYg8j93Je6an9MBC8nRHkcdKSbmp2Yi WGjQeYFz7lnCQsNadwOXJTW4ixe20BrIjjAFkssEgIxFwk2E2m0Vz95ifQ/UdurlvsGAF2QIWOQ +t7uGAK/663ChQauQ9w= X-Received: by 2002:a5d:6f1b:0:b0:4a9:760f:1832 with SMTP id ffacd0b85a97d-4d1ec16d4abmr2323035f8f.45.1796374115185; Fri, 04 Dec 2026 00:48:35 -0800 (PST) Received: from localhost ([2c0f:3d00:6be:8900:ce5e:9212:ea4b:f30]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d17445284esm4292008f8f.44.2026.12.04.00.48.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 00:48:34 -0800 (PST) From: Dan Carpenter Date: Fri, 04 Dec 2026 11:48:11 +0300 Subject: [PATCH v4 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: <20261204-double_exception_v4-v4-7-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 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 --- v4: no change 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