From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796375837; b=eUmfQL6XYkovgrV8JL1bBN0UmFsE8B+fKCYftB9x4oW0jOEOO2SEgXHLFyJ6uituJOmi 1RKizqp0yHyzKv7n4GCJ6TbvS4BAOW2YDMTWr3jduZrNZYPWnsF7uVnIzKijSfbkT7VNC 6Xh57oT7n8G5Xbu7A2aGDLay0SOOAZuBqmI+LFctbGyhZWBdHzYWjsdsv54gmpVFN2WLL bYz9rOLQfKPDfp7DIWGi2gYveRlYE2gc91GK21L7Hwpo1LyqlmM5l4DTnobM66r9a2+t7 2slcKKr1rzN5xWzuzSN5mZXbsDD5M7C77U+aHRz2hT8AdR1MsK5nuq60rrHFdNzjNGQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796375837; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=jWo2mg/uTN+o+O9uDoGTKXn4YDQUKAWwwL8V5bsNY9c=; b=oW/zRz/VJdMnuQ+gOFQugNqaOKtSSpeKOkOrfkUMhu0Aj8ZfZGFZHLbwwGE2gUA7SV+e tZPZ2KhabEWs6oGf71WU8a0oJoqmWFACm7c3WnR7dXjl0ZgeWHk3irp8NdBu5F7S2BchL CpCCAnkQkctpRUWQ1Z7J6HdX5Psl1z5/XIXWDdz2EFZj8bwEd/myqx6NNqT4jPdZUhERx Tpf82GRbyK05sa0th1GdroygfApZyD/n/6RhtE545le5dovNUjvltGaT1XqvUiKB1XoCv Z0ErYKQ7VV3kdy6zrlJVXWUJY/sKyB78KVCW+nl+g9LPAvfj2NrWpFcVjtN+CnPYD+Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HTlvJewB; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8600E606A322; Fri, 4 Dec 2026 09:17:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=HTlvJewB Received: by smtp.kernel.org (Postfix) with ESMTPSA id E93CC1F000CE; Fri, 4 Dec 2026 09:17:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796375837; bh=jWo2mg/uTN+o+O9uDoGTKXn4YDQUKAWwwL8V5bsNY9c=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=HTlvJewBaPNkfVkWnWXFyywflDi08lIR1xjTaUCcKmzZ4+XRZCr78dt1cI8/fsc5b mr3wc920YHz2wBY9PEFrmea6Vq79uSSNYgmJcJ3/Z2IveJv7QBRVymnGv8oSZAAR3H wysPJmCEXvflw7ALx7gZKDaeNZoI81PsymMv5W59XGR/QUtfa6BdGp/o6VwcBR8x4S p4PGJgBuxWQbyT0Y5B93vqGkqq6LAuXmsoYqXnYJeuNatNmCVOZYh0nmkzoq91PX6j oU5FjO9VNa+JwVN+DEV3vxoygVISid67NpI2PT2RjfDTIHqHnNtrYqPh4lYKBGaO4N tz+7D3TWeIBkA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v4 7/9] KVM: arm64: nv: Don't deliver a pending SError to the wrong guest Reply-To: sashiko-reviews@lists.linux.dev To: "Dan Carpenter" Cc: kvmarm@lists.linux.dev, kvm@vger.kernel.org, "Oliver Upton" , "Marc Zyngier" In-Reply-To: <20261204-double_exception_v4-v4-7-523921511673@pereq.eu> References: <20261204-double_exception_v4-v4-0-523921511673@pereq.eu> <20261204-double_exception_v4-v4-7-523921511673@pereq.eu> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 09:17:16 +0000 X-Mailing-List: kvm@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] KVM: arm64: non-atomic hcr_el2 RMW in kvm_nested_stash_serror() races -- commit 9a7da4512bb06d4ccc09ceb91f2bedac7608acb2 Author: Dan Carpenter KVM: arm64: nv: Don't deliver a pending SError to the wrong guest This commit adds kvm_nested_stash_serror() to clear HCR_EL2_VSE and set NESTED_SERROR_PENDING when switching between L1 and L2 in kvm_emulate_nested_eret() and kvm_inject_nested(). > diff --git a/arch/arm64/kvm/emulate-nested.c b/arch/arm64/kvm/emulate-nes= ted.c > index ee71dfc4b8617..d1446081fbbf9 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(stru= ct kvm_vcpu *vcpu, u64 spsr) > return spsr; > } > =20 > +/* > + * 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 cont= ext. > + */ > +static void kvm_nested_stash_serror(struct kvm_vcpu *vcpu) > +{ > + if (*vcpu_hcr(vcpu) & HCR_EL2_VSE) { > + *vcpu_hcr(vcpu) &=3D ~HCR_EL2_VSE; > + vcpu_set_flag(vcpu, NESTED_SERROR_PENDING); > + } > +} [Severity: Low] Can the non-atomic read-modify-write on *vcpu_hcr(vcpu) race with vcpu_interrupt_line()? Before an in-kernel vGIC is created on a nested-virt vCPU, one thread can reach kvm_nested_stash_serror() under vcpu->mutex via KVM_SET_VCPU_EVENTS (kvm_inject_sea_dabt() -> kvm_inject_nested()). Concurrently, another thread can call KVM_IRQ_LINE with KVM_ARM_IRQ_TYPE_CPU, which does not take vcpu->mutex and updates HCR_EL2_VI or HCR_EL2_VF atomically in the same word via vcpu_interrupt_line(): CPU0 CPU1 kvm_arm_vcpu_set_events() ... kvm_nested_stash_serror() load *vcpu_hcr(vcpu) kvm_vm_ioctl_irq_line() vcpu_interrupt_line() test_and_set_bit(VI, hcr) store (*vcpu_hcr(vcpu) & ~VSE) <-- VI update lost This is a data race that can lose a concurrent set of HCR_EL2_VI or HCR_EL2_VF, or overwrite a concurrent clear with a stale 1. Using test_and_clear_bit(__ffs(HCR_EL2_VSE), vcpu_hcr(vcpu)) would avoid the non-atomic read-modify-write here. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204-double_exc= eption_v4-v4-0-523921511673@pereq.eu?part=3D7