From nobody Mon Sep 28 07:17:11 2026 Received: from mta0.migadu.com (out-132.mta0.migadu.com [91.218.175.132]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 424AB3E5A0C for ; Tue, 25 Aug 2026 08:59:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.132 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787648397; cv=none; b=cFgMnDBVfd7jGEA1zDBeNJUHEdhRrbqa6QAAwlTluug8zuvTjyZp67NTiibsW8b+3Z4InzQsSom+e4aXS3p+1c8k2FC11q4N7uPV+9N/cgaefeBPe93c8JfbY6hwTL/WMMb9quO6f9e/Sf3nootL1lfaGypBCp/r6u9YdnHu4w8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787648397; c=relaxed/simple; bh=qzr5u5nyOHcveIVIzXVin5uMFlcqJuyQtDVpldTuy/o=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=p55HZLfBTqu+EJsDFHS1VXZl0gVxeg9vDwJXbuqZntpiO5W6H3WAbnxo/SrE9A+a5sfPLas9UQfiNVuVwA8D1VjrT/s+kBkh/cjixXxo9DVOaYvT1tDoRh4D+oacwYLqQu8TzFim+l5ytGxvPmsB5qTF4zn6YhPY2IoVGr9Raj4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=j3OjFZTB; arc=none smtp.client-ip=91.218.175.132 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="j3OjFZTB" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=qzr5u5nyOHcveIVIzXVin5uMFlcqJuyQtDVpldTuy/o=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787648394; v=1; x=1788253194; b=j3OjFZTBxOBbZXn156bp158NgZLaY0sZiSrRDlCB50ws+ThmNw8sq6whitCwpIutFFVcaqVN tXSaicL5Vd7AQoFn2gIhySGGX2liVFYua6pH/FXGACEKG5Xo07raate+KvhwEG0ddbjDXCG+ns1 UFSOv08YbQiqnHW+0VDmRJsE= X-Envelope-To: linux-kernel@vger.kernel.org Received: from claudy.local (2a01:4b00:ad36:1d00:3a05:25ff:fe33:35a9) by smtp.migadu.com with ESMTPS id 4384835a12538f90; Tue, 25 Aug 2026 08:59:53 +0000 X-Mizu-Trace-ID: 4384835a12538f90 X-Migadu-Flow: FLOW_OUT From: Fuad Tabba To: Marc Zyngier , Oliver Upton Cc: Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Quentin Perret , Stefan Teodorescu , tabba@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] KVM: arm64: Validate the SVE vector length in pkvm_vcpu_init_sve() Date: Tue, 25 Aug 2026 09:59:45 +0100 Message-Id: <20260825085948.1674721-2-fuad.tabba@linux.dev> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260825085948.1674721-1-fuad.tabba@linux.dev> References: <20260825085948.1674721-1-fuad.tabba@linux.dev> 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" pkvm_vcpu_init_sve() clamps only the upper bound of the host-provided sve_max_vl, so an invalid vector length reaches sve_state_size_from_vl() and the WARN_ON() there, which is fatal at EL2. The existing !sve_state_size test rejects such a length, but only after the macro has run. Check sve_vl_valid() before deriving the state size. A valid length cannot yield a zero size, so the !sve_state_size test goes with it. Fixes: 5db1bef93342 ("KVM: arm64: Track SVE state in the hypervisor vcpu st= ructure") Reported-by: Stefan Teodorescu Reviewed-by: Marc Zyngier Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/nvhe/pkvm.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c index 24d6f164129ac..095ebfce91b08 100644 --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c @@ -460,14 +460,15 @@ static int pkvm_vcpu_init_sve(struct pkvm_hyp_vcpu *h= yp_vcpu, struct kvm_vcpu *h =20 /* Limit guest vector length to the maximum supported by the host. */ sve_max_vl =3D min(READ_ONCE(host_vcpu->arch.sve_max_vl), kvm_host_sve_ma= x_vl); - sve_state_size =3D sve_state_size_from_vl(sve_max_vl); sve_state =3D kern_hyp_va(READ_ONCE(host_vcpu->arch.sve_state)); =20 - if (!sve_state || !sve_state_size) { + if (!sve_vl_valid(sve_max_vl) || !sve_state) { ret =3D -EINVAL; goto err; } =20 + sve_state_size =3D sve_state_size_from_vl(sve_max_vl); + ret =3D hyp_pin_shared_mem(sve_state, sve_state + sve_state_size); if (ret) goto err; --=20 2.39.5 From nobody Mon Sep 28 07:17:11 2026 Received: from mta1.migadu.com (out-45.mta1.migadu.com [95.215.58.45]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B12423EA973 for ; Tue, 25 Aug 2026 08:59:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.45 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787648398; cv=none; b=FW+wr+BoWuJ1W8SXoYXgb2HEN2WIpPJ2dn0mB0ZrU+pCfxq1+BGITdj8n8t+VwdSxiPqxE2y/50oPRXp1kStwgxsS8HEO/EgZDI8lBeIlSV5UmKMlCmZ+CMPW4bHF0aQOZ2utHrVY6BU1Y77ZzhSDhnRC+lyXMkUnVHyvritNcg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787648398; c=relaxed/simple; bh=LjE9PUUTQJc3Mt/mX5qIW0W4SIgnuYSMj4Bego/GGoo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=mrhJj1YcbdDvwr7MwE+cq0suB0pRMZ5e40cIeXAcD4B4wY7QZNu0XIGQXss7zUuxGlDxpnJLPi3Py9/DAPf+pyjzZe9wA7yAvxa3MLfniOj/RJ5XJfoA7ZJ5wR67S5sY2z0UKjet4x40sE+gum83s3F7UC8P3FxW+pN1lbFP2cM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=PizeKtKN; arc=none smtp.client-ip=95.215.58.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="PizeKtKN" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=LjE9PUUTQJc3Mt/mX5qIW0W4SIgnuYSMj4Bego/GGoo=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787648394; v=1; x=1788253194; b=PizeKtKNVePp47zcXi4tGyWtNRvk0XL+iIwQqHTBQbuvzuNoPc86Zb58UuZi+HT9hzdBHnFU Be5pvemwNA+93yVZnHANCGbOwkcELitLVL/PLp0MC/Tb74JNHd29ootKvuFFDIXZKdoGWppOUlA J4JVq7NaRo59if/zZ4xKNH2k= X-Envelope-To: linux-kernel@vger.kernel.org Received: from claudy.local (2a01:4b00:ad36:1d00:3a05:25ff:fe33:35a9) by smtp.migadu.com with ESMTPS id e9bb1680c418ec1f; Tue, 25 Aug 2026 08:59:54 +0000 X-Mizu-Trace-ID: e9bb1680c418ec1f X-Migadu-Flow: FLOW_OUT From: Fuad Tabba To: Marc Zyngier , Oliver Upton Cc: Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Quentin Perret , Stefan Teodorescu , tabba@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] KVM: arm64: Do not clear VM-wide SVE feature on vCPU init failure Date: Tue, 25 Aug 2026 09:59:46 +0100 Message-Id: <20260825085948.1674721-3-fuad.tabba@linux.dev> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260825085948.1674721-1-fuad.tabba@linux.dev> References: <20260825085948.1674721-1-fuad.tabba@linux.dev> 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" pkvm_vcpu_init_sve() clears KVM_ARM_VCPU_SVE in kvm->arch.vcpu_features when it fails, but vcpu_has_sve() tests KVM_ARCH_FLAG_GUEST_HAS_SVE, which is left set. Later vCPUs on that VM then skip the SVE setup and register with a NULL sve_state, which the guest's first FP access hands to sve_load_state(). Return the error without touching vcpu_features. Fixes: 5db1bef93342 ("KVM: arm64: Track SVE state in the hypervisor vcpu st= ructure") Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/nvhe/pkvm.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c index 095ebfce91b08..73e6ee059eebb 100644 --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c @@ -451,7 +451,7 @@ static int pkvm_vcpu_init_sve(struct pkvm_hyp_vcpu *hyp= _vcpu, struct kvm_vcpu *h unsigned int sve_max_vl; size_t sve_state_size; void *sve_state; - int ret =3D 0; + int ret; =20 if (!vcpu_has_feature(vcpu, KVM_ARM_VCPU_SVE)) { vcpu_clear_flag(vcpu, VCPU_SVE_FINALIZED); @@ -462,24 +462,19 @@ static int pkvm_vcpu_init_sve(struct pkvm_hyp_vcpu *h= yp_vcpu, struct kvm_vcpu *h sve_max_vl =3D min(READ_ONCE(host_vcpu->arch.sve_max_vl), kvm_host_sve_ma= x_vl); sve_state =3D kern_hyp_va(READ_ONCE(host_vcpu->arch.sve_state)); =20 - if (!sve_vl_valid(sve_max_vl) || !sve_state) { - ret =3D -EINVAL; - goto err; - } + if (!sve_vl_valid(sve_max_vl) || !sve_state) + return -EINVAL; =20 sve_state_size =3D sve_state_size_from_vl(sve_max_vl); =20 ret =3D hyp_pin_shared_mem(sve_state, sve_state + sve_state_size); if (ret) - goto err; + return ret; =20 vcpu->arch.sve_state =3D sve_state; vcpu->arch.sve_max_vl =3D sve_max_vl; =20 return 0; -err: - clear_bit(KVM_ARM_VCPU_SVE, vcpu->kvm->arch.vcpu_features); - return ret; } =20 static int vm_copy_id_regs(struct pkvm_hyp_vcpu *hyp_vcpu) --=20 2.39.5 From nobody Mon Sep 28 07:17:11 2026 Received: from mta0.migadu.com (out-140.mta0.migadu.com [91.218.175.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C96FD3EAC61 for ; Tue, 25 Aug 2026 08:59:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.140 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787648400; cv=none; b=B3lenb5vnUhOJT2vncE7PyKZ3Rns4hQfwMye306Krcsei5KJBUOCRBJm0nVGln8zm9fTi2TG2tbGhRqRypXgUsXlB9GxjMXbdP3GUkhiJ0BXniYnXLITbqDz4mI2Txr5u2tPuYivdQhzlpeeWeAOnVibSxZgLY8ggVMA9wQePOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787648400; c=relaxed/simple; bh=MSUuQABVVUc6gwSvoRq9rt/EUbCdwq4ILWrmprQ0Dzo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TtHKPTkpVwLv9WPvH9VP6DpbDYpY9x5PG6mx3VX1eGD0cSukCwZWq9acSaAztZ9Sdi2yclZNIdjqCyZz/qLJ+PZQSPYsKc9zHx9qAK1KXHzztPjvUBz68VAbidLc1W3cfOuLd0dBXcKGULac2pesihm6FTBquUsZgQttiknNWvg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=jgkIIzZ0; arc=none smtp.client-ip=91.218.175.140 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="jgkIIzZ0" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=MSUuQABVVUc6gwSvoRq9rt/EUbCdwq4ILWrmprQ0Dzo=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787648395; v=1; x=1788253195; b=jgkIIzZ0XypmlQHdcS+BIeouet3Ll7e9QuqukDEJOJq/pV4OcSk1HB7U9TR6XMSqoAeyt7nk ljke+jZ8poO13AaGJBl7+h/sIxhjozVGOzW7X5938qmGD0UBJnrmYtC9vs6phx0jFyCFTyLFNC/ 0jiwdU3NqPP5M6o5iqToBe+I= X-Envelope-To: linux-kernel@vger.kernel.org Received: from claudy.local (2a01:4b00:ad36:1d00:3a05:25ff:fe33:35a9) by smtp.migadu.com with ESMTPS id c708cb14ba227278; Tue, 25 Aug 2026 08:59:55 +0000 X-Mizu-Trace-ID: c708cb14ba227278 X-Migadu-Flow: FLOW_OUT From: Fuad Tabba To: Marc Zyngier , Oliver Upton Cc: Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Quentin Perret , Stefan Teodorescu , tabba@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] KVM: arm64: Key unpin_host_sve_state() on the state it unpins Date: Tue, 25 Aug 2026 09:59:47 +0100 Message-Id: <20260825085948.1674721-4-fuad.tabba@linux.dev> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260825085948.1674721-1-fuad.tabba@linux.dev> References: <20260825085948.1674721-1-fuad.tabba@linux.dev> 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" unpin_host_sve_state() gates on the VM's SVE feature bit, but what it unpins is the state pkvm_vcpu_init_sve() pinned. A vCPU that completed init has sve_state set exactly when that bit is set, so the two agree. Gate on sve_state, which is what is being unpinned. Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/nvhe/pkvm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c index 73e6ee059eebb..1d8cc984fb88c 100644 --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c @@ -398,10 +398,10 @@ static void unpin_host_sve_state(struct pkvm_hyp_vcpu= *hyp_vcpu) { void *sve_state; =20 - if (!vcpu_has_feature(&hyp_vcpu->vcpu, KVM_ARM_VCPU_SVE)) + sve_state =3D hyp_vcpu->vcpu.arch.sve_state; + if (!sve_state) return; =20 - sve_state =3D hyp_vcpu->vcpu.arch.sve_state; hyp_unpin_shared_mem(sve_state, sve_state + vcpu_sve_state_size(&hyp_vcpu->vcpu)); } --=20 2.39.5 From nobody Mon Sep 28 07:17:11 2026 Received: from mta1.migadu.com (out-53.mta1.migadu.com [95.215.58.53]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 74ECC3F12C4 for ; Tue, 25 Aug 2026 09:00:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787648404; cv=none; b=j5S/lflaUfA9zpZkywnIpcX4hl76tjKF6FMIlMEW73owVq12UnMqE1GhiCEvOqziEzIVUzkjxxR3BAejiemwCJYpARpZLSN38bhBGM2+/29L4KmnmYn64J6VNO94B7WENdXDdWGkOuNM3z6lvwLOfU2WyIhl9l9GlC0VcsT4wS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787648404; c=relaxed/simple; bh=k4w2yytoDHZE0wCz7242BNWe7ZWxIERicnhL5Vmij0I=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=FxwWWeUk/vaeqBvbCohLL8g1g4nbwna54dVwVsX2LbDvOxtbnrulEdM/gqD5ws7y1upb3BIg3mM23wi9XSV8tdsZ1tekzjTz2ef8HZii/+vwfCA85cm9Z0dsoF9dfWKPHoZ5+/6N/DLI+qc2U/5nvbeDonPLdV4WCKuR6Dd0umE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=l0jglARL; arc=none smtp.client-ip=95.215.58.53 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="l0jglARL" X-Envelope-To: linux-kernel@vger.kernel.org DKIM-Signature: a=rsa-sha256; bh=k4w2yytoDHZE0wCz7242BNWe7ZWxIERicnhL5Vmij0I=; c=simple/simple; d=linux.dev; h=from:to:subject:date:message-id:mime-version:content-type; s=key1; t=1787648400; v=1; x=1788253200; b=l0jglARLlnQBxD+OijYoGIoFq9pxQ9aQlpAkcAHwS56fR1guDG4LBWY7cl9Cxf++2Oto5K4E EChzzSdPqNQ+6+Qyp9MrrvoGO1F9LEl8EKXH2TdIzWTAxgNVN2Moer3fBbKQrCe5JoQpc3pzyXx NyhCz91AjJkgTDeTacU75inw= X-Envelope-To: linux-kernel@vger.kernel.org Received: from claudy.local (2a01:4b00:ad36:1d00:3a05:25ff:fe33:35a9) by smtp.migadu.com with ESMTPS id c08eced77c6b2cfb; Tue, 25 Aug 2026 09:00:00 +0000 X-Mizu-Trace-ID: c08eced77c6b2cfb X-Migadu-Flow: FLOW_OUT From: Fuad Tabba To: Marc Zyngier , Oliver Upton Cc: Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , Quentin Perret , Stefan Teodorescu , tabba@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] KVM: arm64: Derive GUEST_HAS_SVE from the SVE feature bit at EL2 Date: Tue, 25 Aug 2026 09:59:48 +0100 Message-Id: <20260825085948.1674721-5-fuad.tabba@linux.dev> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20260825085948.1674721-1-fuad.tabba@linux.dev> References: <20260825085948.1674721-1-fuad.tabba@linux.dev> 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" pkvm_init_features_from_host() takes KVM_ARCH_FLAG_GUEST_HAS_SVE and KVM_ARM_VCPU_SVE from the host separately, but pkvm_vcpu_init_sve() tests the bit while vcpu_has_sve() reads the flag. A host that sets the flag without the bit gets a vCPU with a NULL sve_state that the world switch loads the guest's SVE state from. Derive the flag from the bit, and drop the protected path's copy of the host's flag, which is dead code since protected VMs are not allowed SVE. Fixes: 41d6028e28bd ("KVM: arm64: Convert the SVE guest vcpu flag to a vm f= lag") Signed-off-by: Fuad Tabba --- arch/arm64/kvm/hyp/nvhe/pkvm.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c index 1d8cc984fb88c..6efca70e5f5a9 100644 --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c @@ -360,7 +360,7 @@ static void pkvm_init_features_from_host(struct pkvm_hy= p_vm *hyp_vm, const struc if (test_bit(KVM_ARCH_FLAG_WRITABLE_IMP_ID_REGS, &host_arch_flags)) hyp_vm->kvm.arch.midr_el1 =3D host_kvm->arch.midr_el1; =20 - return; + goto out; } =20 if (kvm_pkvm_ext_allowed(kvm, KVM_CAP_ARM_MTE)) @@ -379,13 +379,14 @@ static void pkvm_init_features_from_host(struct pkvm_= hyp_vm *hyp_vm, const struc if (kvm_pkvm_ext_allowed(kvm, KVM_CAP_ARM_PTRAUTH_GENERIC)) set_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, allowed_features); =20 - if (kvm_pkvm_ext_allowed(kvm, KVM_CAP_ARM_SVE)) { + if (kvm_pkvm_ext_allowed(kvm, KVM_CAP_ARM_SVE)) set_bit(KVM_ARM_VCPU_SVE, allowed_features); - kvm->arch.flags |=3D host_arch_flags & BIT(KVM_ARCH_FLAG_GUEST_HAS_SVE); - } =20 bitmap_and(kvm->arch.vcpu_features, host_kvm->arch.vcpu_features, allowed_features, KVM_VCPU_MAX_FEATURES); +out: + __assign_bit(KVM_ARCH_FLAG_GUEST_HAS_SVE, &kvm->arch.flags, + kvm_vcpu_has_feature(kvm, KVM_ARM_VCPU_SVE)); } =20 static void unpin_host_vcpu(struct kvm_vcpu *host_vcpu) --=20 2.39.5