From nobody Sat Feb 7 10:08:38 2026 Received: from out30-113.freemail.mail.aliyun.com (out30-113.freemail.mail.aliyun.com [115.124.30.113]) (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 3F78831AF25; Wed, 20 Aug 2025 12:59:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=115.124.30.113 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755694804; cv=none; b=aBUolJ9LLWw99NhKwok5q0yKmy5DegR7Lifnrfk7rA53Es3hTkqJtC1adHxjH9PtQU8+GkxoU3Fau2U98ElMrd/kgFezse3p5x28KGqM4Ha6HEpic+GXGCV9e77nIi6ivhyhnnJBkT6/a7vnw0/DLseMYrEIwK/nSoRWmjZfc3c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1755694804; c=relaxed/simple; bh=BoYCEutuegVGi1YMFbKRHtU+ZEC5pxWe6YgKpIdGGKk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=rQiF0A8/dks/F/9RyjQyfh64OXg2pmxLC2uY1pMFBOfDc2XWQFkpeoQmaaJMb0fEzmAIixAs0uerqpntDFSzDGC0guFPBmZmpFlHobv870cyMqa3SibMS5RQjTBAUge2MXtPCxZFAiMFQo5P3VNAkBljBK0DHGdj+FEkponJEJg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b=MlcuG4+c; arc=none smtp.client-ip=115.124.30.113 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.b="MlcuG4+c" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1755694798; h=From:To:Subject:Date:Message-Id:MIME-Version; bh=3BJVOCM13LqwDm1dqz/wRNujuXc9x9YGPSojNZlkeNY=; b=MlcuG4+ci+LCc2FGM7C0AFnMDzSTYB/seAZxWnmLjax0rcljZ4AC/gcLnkooXS+rjtSIgdfVT3DhpXoaRJLVP5imD7/TabDELMme3RG5HsWGjGGY51mOe132424/NUtHo+HTEAimPgZtNlpijr91jO0tFUgsoGZKZ+yaR23++Tw= Received: from localhost.localdomain(mailfrom:fangyu.yu@linux.alibaba.com fp:SMTPD_---0WmCQaZW_1755694796 cluster:ay36) by smtp.aliyun-inc.com; Wed, 20 Aug 2025 20:59:56 +0800 From: fangyu.yu@linux.alibaba.com To: anup@brainfault.org, atish.patra@linux.dev, paul.walmsley@sifive.com, palmer@dabbelt.com, aou@eecs.berkeley.edu, alex@ghiti.fr Cc: guoren@kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Fangyu Yu , Nutty Liu , Troy Mitchell Subject: [PATCH v3 1/2] RISC-V: KVM: Write hgatp register with valid mode bits Date: Wed, 20 Aug 2025 20:59:51 +0800 Message-Id: <20250820125952.71689-2-fangyu.yu@linux.alibaba.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) In-Reply-To: <20250820125952.71689-1-fangyu.yu@linux.alibaba.com> References: <20250820125952.71689-1-fangyu.yu@linux.alibaba.com> 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" From: Fangyu Yu According to the RISC-V Privileged Architecture Spec, when MODE=3DBare is selected,software must write zero to the remaining fields of hgatp. We have detected the valid mode supported by the HW before, So using a valid mode to detect how many vmid bits are supported. Fixes: fd7bb4a251df ("RISC-V: KVM: Implement VMID allocator") Reviewed-by: Nutty Liu Reviewed-by: Troy Mitchell Reviewed-by: Guo Ren Signed-off-by: Fangyu Yu --- arch/riscv/kvm/vmid.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kvm/vmid.c b/arch/riscv/kvm/vmid.c index 3b426c800480..5f33625f4070 100644 --- a/arch/riscv/kvm/vmid.c +++ b/arch/riscv/kvm/vmid.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include =20 @@ -28,7 +29,7 @@ void __init kvm_riscv_gstage_vmid_detect(void) =20 /* Figure-out number of VMID bits in HW */ old =3D csr_read(CSR_HGATP); - csr_write(CSR_HGATP, old | HGATP_VMID); + csr_write(CSR_HGATP, (kvm_riscv_gstage_mode << HGATP_MODE_SHIFT) | HGATP_= VMID); vmid_bits =3D csr_read(CSR_HGATP); vmid_bits =3D (vmid_bits & HGATP_VMID) >> HGATP_VMID_SHIFT; vmid_bits =3D fls_long(vmid_bits); --=20 2.49.0