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=1796392672; b=qgFnfSogN/G5OBusM4VXwXzfZ34afZxZ2LqJEoJL4znXp8MUW/ilXEk72PCFCyk5KznY Qbr6HGnGpH37NhynG9aIInp240B5QL2wt16o4k3HoJeEagS5TDFLvLlMDHIYwsrI2UjI5 yDkZfJqjCzQdaufyM6SyI8X0fwOaDdLYdCZhi2pdJppKBgXi/+Z5JRFXMzOdg2cVBIioA K8BphNe9QZao/juJuQlq6msHU03MwGCLLLGAKChTPt0d6HMm3ifCh5OqPF1dASlLcpT3Y en8YcoqSRh6NOrMQtXlX6Udo6e6O3nv7C2gZMe44DKc7d0j0TKAcpQuHl1yn6M/+jYQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796392672; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=43ysJM6JWrL2sYu+ISFlAi4PqNcGPLs1MOf5DW8T1ms=; b=r5NCCdErZcmUqpKuNihVYxOEXipxfVJHGkaEIRMAlGLzpY9hcSeXU4OqsdxSJY4m3+r2 jdyxk/A1o+G0YVNpB0X3wnEy6ZIyxZfpYvqYplQ3uqjv58cWNl7tZaeG3pflADGe4QQdD KtZmfPn1dluWxX5XScZT02+thAtOPOYHppSCT9GsninMamoZ3ja0SFODYzFPFt6p4tSFx W7Y5TUB9xV21+oAA0SKTk5PQ9eVJ2jMRswU/hncMZKv/vDGpYTBZr4ycwL5Hg6RFGheaK NikKWijHclIJ3QRYdJLl5HX7WCpftYRYUdbPAW8H+7coLUmyP8tZ7K7Hb8Uw+JWZ+yQ== 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=owdTOJY9; 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 C4056606A681 for ; Fri, 4 Dec 2026 13:57:52 +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=owdTOJY9 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8B83B1F000C2; Fri, 4 Dec 2026 13:57:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796392672; bh=43ysJM6JWrL2sYu+ISFlAi4PqNcGPLs1MOf5DW8T1ms=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=owdTOJY9xpusfi4AOURoLmIYa4cX8sDMreRGcDOmUTm5ecmFlOZTU4hJRnGe5J16E Xi0WGKtGf70wxz0AiyCE3yQAvHIIu1BMCjmlc3icRIJ6VwHyjshIVZFFm/mjDS4b+V V7WDP+dEL3Y0KvzoANxR3PXUj9evzWAujBrYVuh5iP/FUED6FmrhGYs7qfh0bFQkUx SQczk9Aj+6NyOi0v6anwhBC0g0TNoh+Mm/atlyA3TMDncNlxy3CpY2RL5p+nxcmqiz +6KYfsSfKcReqttru0iRqjbBcSrBQMuWiKsM6capekmRIlPq4bZQbRgrPwIRCLKksb xmsyFez9hM7WQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 1/2] RISC-V: KVM: Expose G-stage page table and mapping stats Reply-To: sashiko-reviews@lists.linux.dev To: Bingyu.Xian Cc: kvm@vger.kernel.org In-Reply-To: <20261204132651.413976-2-shanbeeyoo@gmail.com> References: <20261204132651.413976-1-shanbeeyoo@gmail.com> <20261204132651.413976-2-shanbeeyoo@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 13:57:52 +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: - [Medium] KVM: riscv: stats drift on non-leaf overwrite in kvm_riscv_gstage_set_pte() -- commit 2228a1399f45a06009b2d81ae199437ca73d3a36 Author: Bingyu.Xian RISC-V: KVM: Expose G-stage page table and mapping stats This commit adds per-VM G-stage page table and leaf mapping counters (pgtable_pages, pages_4k, pages_2m, pages_1g on RV64; pages_4m on RV32) to struct kvm_vm_stat and exposes them via kvm_vm_stats_desc[]. > diff --git a/arch/riscv/kvm/gstage.c b/arch/riscv/kvm/gstage.c > index 241f4c19ca181..dc311b77a0cc4 100644 > --- a/arch/riscv/kvm/gstage.c > +++ b/arch/riscv/kvm/gstage.c [ ... ] > @@ -194,10 +231,18 @@ int kvm_riscv_gstage_set_pte(struct kvm_gstage *gst= age, > ptep =3D &next_ptep[gstage_pte_index(gstage, map->addr, current_level)= ]; > } > =20 > - if (pte_val(*ptep) !=3D pte_val(map->pte)) { > - bool was_invalid =3D !pte_val(*ptep); > + old_pte =3D ptep_get(ptep); > + if (pte_val(old_pte) !=3D pte_val(map->pte)) { > + bool was_invalid =3D !pte_val(old_pte); > + bool was_leaf =3D gstage_pte_leaf(old_pte); > + bool is_leaf =3D gstage_pte_leaf(map->pte); > + > set_pte(ptep, map->pte); > - if (gstage_pte_leaf(map->pte) && > + if (!was_leaf && is_leaf) > + gstage_update_leaf_stats(gstage, current_level, 1); > + else if (was_leaf && !is_leaf) > + gstage_update_leaf_stats(gstage, current_level, -1); [Severity: Medium] Can overwriting a non-leaf _PAGE_TABLE entry with a huge leaf PTE here cause pgtable_pages and lower-level leaf counts to drift permanently? When map->level > 0, !was_leaf holds for both an empty PTE and a valid _PAGE_TABLE entry. Since kvm_riscv_gstage_unmap_range() leaves lower-level tables linked, a later huge-page fault in kvm_riscv_gstage_map_page() can call kvm_riscv_gstage_set_pte() and overwrite the _PAGE_TABLE entry directl= y. Because the overwritten subtree is not unaccounted, pgtable_pages and any remaining child leaf counts stay inflated even after G-stage teardown. Clearing a non-leaf old_pte via kvm_riscv_gstage_op_pte(..., GSTAGE_OP_CLEA= R) before installing the new leaf would keep the stats accurate. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204132651.4139= 76-1-shanbeeyoo@gmail.com?part=3D1