From nobody Mon Nov 23 05:00:24 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1791199042359624.3455868963662; Mon, 5 Oct 2026 04:17:22 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1xDgg8-0001qt-UZ; Mon, 05 Oct 2026 07:16:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1xDgfo-0001mP-DR; Mon, 05 Oct 2026 07:16:01 -0400 Received: from smtp81.cstnet.cn ([159.226.251.81] helo=cstnet.cn) by eggs.gnu.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1xDgfl-0007Br-M4; Mon, 05 Oct 2026 07:16:00 -0400 Received: from k3-03 (unknown [159.226.43.8]) by APP-03 (Coremail) with SMTP id rQCowABnZjTNhsNqNyGuCQ--.34860S2; Mon, 05 Oct 2026 19:15:48 +0800 (CST) From: Tan Chi To: qemu-devel@nongnu.org Cc: qemu-riscv@nongnu.org, palmer@dabbelt.com, alistair.francis@wdc.com, liwei1518@gmail.com, daniel.barboza@oss.qualcomm.com, zhiwei_liu@linux.alibaba.com, chao.liu@processmission.com, Tan Chi , qemu-stable@nongnu.org Subject: [PATCH v2] hw/riscv/riscv-iommu: fix entry leak with ioatc-limit=0 Date: Mon, 5 Oct 2026 19:15:23 +0800 Message-ID: <20261005111523.277550-1-tanchi25@mails.ucas.ac.cn> X-Mailer: git-send-email 2.53.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-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FwI0_Jr0_Gr 1lIxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjfUe_-BDUUU U X-Originating-IP: [159.226.43.8] X-CM-SenderInfo: pwdquxrlsvqzpdlo2hpxfd2hldfou0/ Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists1p.gnu.org; Received-SPF: pass client-ip=159.226.251.81; envelope-from=tanchi25@mails.ucas.ac.cn; helo=cstnet.cn X-Spam_score_int: -41 X-Spam_score: -4.2 X-Spam_bar: ---- X-Spam_report: (-4.2 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1791199054371158500 Content-Type: text/plain; charset="utf-8" riscv_iommu_translate() allocates an IOATC entry before passing it to riscv_iommu_iot_update(). The update helper normally transfers ownership to the hash table. When ioatc-limit is zero, however, the helper returns without inserting or freeing the entry. Every cacheable non-identity translation therefore leaks one RISCVIOMMUEntry. Avoid this by disabling caching at the caller when ioatc-limit is zero, so riscv_iommu_translate() does not allocate an IOATC entry in the first place. This avoids special-casing entry freeing in riscv_iommu_iot_update() and keeps the ownership semantics simpler. Suggested-by: Daniel Henrique Barboza Fixes: 9d085a1c3cb2 ("hw/riscv/riscv-iommu: add Address Translation Cache (= IOATC)") Cc: qemu-stable@nongnu.org Signed-off-by: Tan Chi Reviewed-by: Daniel Henrique Barboza Reviewed-by: Nutty Liu --- v2: - Disable caching when ioatc-limit is zero instead of freeing the allocated entry in riscv_iommu_iot_update(). hw/riscv/riscv-iommu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c index 323a041b4a..866f49cc39 100644 --- a/hw/riscv/riscv-iommu.c +++ b/hw/riscv/riscv-iommu.c @@ -2919,7 +2919,8 @@ static IOMMUTLBEntry riscv_iommu_memory_region_transl= ate( /* Translation disabled or invalid. */ iotlb.addr_mask =3D 0; iotlb.perm =3D IOMMU_NONE; - } else if (riscv_iommu_translate(as->iommu, ctx, &iotlb, true)) { + } else if (riscv_iommu_translate(as->iommu, ctx, &iotlb, + as->iommu->iot_limit > 0)) { /* Translation disabled or fault reported. */ iotlb.addr_mask =3D 0; iotlb.perm =3D IOMMU_NONE; --=20 2.53.0