From nobody Thu Apr 9 17:03:00 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C072481A9C; Fri, 6 Mar 2026 21:09:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772831351; cv=none; b=P+zMmlqQSjgzrozaGLTePnNPsW26JFFH22CFQLcCMhewTfAocXaH2DqeOjCut0OWhEeASYF2JsJDarye+A/yEAebU09l6B4kOk9jNJ8p2slKvXk4r7XvGRVaHlDwb0VZK1FpQfE01PeHrfKYIovDPG99NNGJW4kr45+8nSEl5+E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772831351; c=relaxed/simple; bh=in1bbterwp8ZETaHG9kMMOIjehLDOJ5KlUVscZMC+Xc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=CTymk4WFgl+4Qt80CT/Z737MuFdA8I2/vy6Y8oHFDDe1ww6FkSyePFEQmMDW3iRGyGotPLApK2uPYDWWeYTXpcICq+tV/eRZ6r73c7bsrqZGf0YS59oIY9zlo7ek5YoWg8y48JqtfwX65JLcT7kIpvy9qxAcqTgqehDzlVdaFDg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=SwOYsY6a; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="SwOYsY6a" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 01001C2BC9E; Fri, 6 Mar 2026 21:09:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1772831351; bh=in1bbterwp8ZETaHG9kMMOIjehLDOJ5KlUVscZMC+Xc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SwOYsY6aTse99kZTaCfTx7xyj2OALKnXCXCuvqOST1UxrvCtFuLce3CeH5FwTEJHd VyTypysUvVwLzZ4261I5wH8FGkSsrPlyrPIjfpOZKw24adeeOMbfStkkAOuWQwmZ98 Ve/azw6lM73mNrQZrqu+/8qsug/UhK204wWn+BRa4ny1oOZRvexSDmISliQvMvfoiu b+2tOOzUtNcwwrg/kZg7jQKfgMSPlfygCXmB3U7fCHFWNQcVQdqhzMD6OVm6nYaIbu anT1YMA3Ny4zXK9hhDHWvMVFBRJRKo0ic5cSZXdAX0fYevsBsi3FhIrC8qG8oLqLoy apKZ/sLsgWu7g== From: Yosry Ahmed To: Sean Christopherson Cc: Paolo Bonzini , Jim Mattson , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Yosry Ahmed Subject: [PATCH v2 1/6] KVM: SVM: Use maxphyaddr in emulator RAX check for VMRUN/VMLOAD/VMSAVE Date: Fri, 6 Mar 2026 21:08:55 +0000 Message-ID: <20260306210900.1933788-2-yosry@kernel.org> X-Mailer: git-send-email 2.53.0.473.g4a7958ca14-goog In-Reply-To: <20260306210900.1933788-1-yosry@kernel.org> References: <20260306210900.1933788-1-yosry@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Architecturally, VMRUN/VMLOAD/VMSAVE should generate a #GP if the physical address in RAX is not supported. check_svme_pa() hardcodes this to checking that bits 63-48 are not set. This is incorrect on HW supporting 52 bits of physical address space, so use maxphyaddr instead. Note that the host's maxphyaddr is used, not the guest, because the emulator path for VMLOAD/VMSAVE is generally used when virtual VMLOAD/VMSAVE is enabled AND a #NPF is generated. If a #NPF is not generated, the CPU will inject a #GP based on the host's maxphyaddr. So this keeps the behavior consistent. If KVM wants to consistently inject a #GP based on the guest's maxphyaddr, it would need to disabled virtual VMLOAD/VMSAVE and intercept all VMLOAD/VMSAVE instructions to do the check. Also, emulating a smaller maxphyaddr for the guest than the host generally doesn't work well, so it's not worth handling this. Fixes: 01de8b09e606 ("KVM: SVM: Add intercept checks for SVM instructions") Signed-off-by: Yosry Ahmed --- arch/x86/kvm/emulate.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c index 6145dac4a605a..9ea2584dda912 100644 --- a/arch/x86/kvm/emulate.c +++ b/arch/x86/kvm/emulate.c @@ -3887,8 +3887,7 @@ static int check_svme_pa(struct x86_emulate_ctxt *ctx= t) { u64 rax =3D reg_read(ctxt, VCPU_REGS_RAX); =20 - /* Valid physical address? */ - if (rax & 0xffff000000000000ULL) + if (rax & rsvd_bits(kvm_host.maxphyaddr, 63)) return emulate_gp(ctxt, 0); =20 return check_svme(ctxt); --=20 2.53.0.473.g4a7958ca14-goog