{"id":2233287,"url":"http://patchwork.ozlabs.org/api/1.2/patches/2233287/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260506033642.3641390-4-jim.shu@sifive.com/","project":{"id":14,"url":"http://patchwork.ozlabs.org/api/1.2/projects/14/?format=json","name":"QEMU Development","link_name":"qemu-devel","list_id":"qemu-devel.nongnu.org","list_email":"qemu-devel@nongnu.org","web_url":"","scm_url":"","webscm_url":"","list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20260506033642.3641390-4-jim.shu@sifive.com>","list_archive_url":null,"date":"2026-05-06T03:36:40","name":"[v3,3/5] accel/tcg: Provide early AS translate function","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"2123eacf94c179185d82cd1160cb2b64d737cee4","submitter":{"id":83153,"url":"http://patchwork.ozlabs.org/api/1.2/people/83153/?format=json","name":"Jim Shu","email":"jim.shu@sifive.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/qemu-devel/patch/20260506033642.3641390-4-jim.shu@sifive.com/mbox/","series":[{"id":502923,"url":"http://patchwork.ozlabs.org/api/1.2/series/502923/?format=json","web_url":"http://patchwork.ozlabs.org/project/qemu-devel/list/?series=502923","date":"2026-05-06T03:36:39","name":"Defer the IOMMU translation in the CPU path and support access_type","version":3,"mbox":"http://patchwork.ozlabs.org/series/502923/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2233287/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2233287/checks/","tags":{},"related":[],"headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256\n header.s=google header.b=LcS/rs5F;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=nongnu.org\n (client-ip=209.51.188.17; helo=lists1p.gnu.org;\n envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17])\n\t(using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g9Lgz63Zvz1y04\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 06 May 2026 13:38:23 +1000 (AEST)","from localhost ([::1] helo=lists1p.gnu.org)\n\tby lists1p.gnu.org with esmtp (Exim 4.90_1)\n\t(envelope-from <qemu-devel-bounces@nongnu.org>)\n\tid 1wKT4e-0001tP-RF; Tue, 05 May 2026 23:37:24 -0400","from eggs.gnu.org ([2001:470:142:3::10])\n by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)\n (Exim 4.90_1) (envelope-from <jim.shu@sifive.com>)\n id 1wKT4a-0001r4-Dl\n for qemu-devel@nongnu.org; Tue, 05 May 2026 23:37:20 -0400","from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629])\n by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128)\n (Exim 4.90_1) (envelope-from <jim.shu@sifive.com>)\n id 1wKT4X-0006SC-Dt\n for qemu-devel@nongnu.org; Tue, 05 May 2026 23:37:20 -0400","by mail-pl1-x629.google.com with SMTP id\n d9443c01a7336-2b24fcc2b5dso34836285ad.1\n for <qemu-devel@nongnu.org>; Tue, 05 May 2026 20:37:17 -0700 (PDT)","from hsinchu26.internal.sifive.com ([210.176.154.34])\n by smtp.gmail.com with ESMTPSA id\n d9443c01a7336-2ba7ca34cfdsm7666265ad.79.2026.05.05.20.37.08\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Tue, 05 May 2026 20:37:14 -0700 (PDT)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=sifive.com; s=google; t=1778038635; x=1778643435; darn=nongnu.org;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:from:to:cc:subject:date\n :message-id:reply-to;\n bh=79rPXiP3/6QDU0TrDtJD4kbRuSJaUuXqGAi28uS9FeI=;\n b=LcS/rs5FCbATr1nXxCOl+UhzIpPbQw0gn7W0h1uyIzR1fgUiEcsvJtccOh/iqKFHa0\n xr3alo7q7ne9dAxGO347YmR98xrenPgwfUt1SOYSCzqpHEnw3J0X4O/yr6tS07pf/D4k\n KO+sIXPIDdiYq74dNrb4cgEf7+OYy/M8+TS6DoMQ15VvZhZwxgXMv6FK8LLjJmSnQJQZ\n xGV/eAuw4htOq1+SVxMO17gxJe4sbGqM/NIWqB5p9Vq+rf1h90ENvEEvnKVLBCrtW6m/\n /BSGx9G6SH2BvsSW4fRYt7kQYIiliKzDP6unT/q0WjGQvJYCj0TzojUcVT02utoA46Sj\n tqvg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1778038635; x=1778643435;\n h=content-transfer-encoding:mime-version:references:in-reply-to\n :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n :to:cc:subject:date:message-id:reply-to;\n bh=79rPXiP3/6QDU0TrDtJD4kbRuSJaUuXqGAi28uS9FeI=;\n b=XMIPJSe3PVmUE5BYl7Qoo326oN0HFsVOGRf3dFFs4y8FJ3gK70jtip+1PaiL17aGW8\n 1cpR1bMiOp/CeUBvKFpErPWSqffjrGc7nmoU2RVJ6y6/OTYePALsR3fGTAxvDrAaH0rI\n dGqmylNIsF0nqEaxNxdbgHeldk62oJQBNMGLmhUx0z+PFWQ+dsRcG2+v2by2N/E7k/ln\n jeRMfI78SdZSFdnhglkjahPrhf8sHRre7tCS++KiuWdhLV+5lNr9iFwF9T/Cjqu8VPjR\n AxXeUhtxurs2+rGbSJ/AHsMfxcIni27tK9oIlTwImavjPqWKYiLc3BGH0WG64W3d90lk\n XD3w==","X-Gm-Message-State":"AOJu0YwW1XQdnS0rMwT/VJolkMo+9h316qcctTcFVjAQkUAKkzUSAuSF\n 3SQ8TBpDQVFCWGDwKoiHtvNUvJT8kUQ13M1mFFNzn1PT32LxUPT++qoa66A941hTtG7e8yGmniq\n xLjQ+jW4Ub6KCvaqhhcKpgUuwjMZTVmIIdxNBpXbDXTrDVNG5K1tfCd6bDzMEre7jtG8Hl5ck7b\n w1fH3g+mFyUkfo2fnXOHjcIEN/BaVOA/NZ8JCfuzDD","X-Gm-Gg":"AeBDies/gIIsdsEDpMYz/WIZIsgaXWnxDnDmnQJleQRh0dBv4H0eTeu9RdCCtm1OjVh\n /g3Aff6Oq4Ln8lEaZJ6f5HM3FZV+ptAnJf9tv9Xc6PiEHS+6p3BEO7ljSfllfICBy0iP4MDfci8\n nT/xzKKVyoV14t0wzSaFT4Xf7dvc/dPx1LyQnCs7dih6MKwFAooXP1WDoFFhNi3qxY5YUtPxZc9\n kWXgbOpHZslbbcI8UpHuj5uyHMhOFICzd8hB6BJuE+CUsvdrq69kIZhNwfZOeheOA4wolShrupt\n bErCrMJ2sOVHvqSTd1UNISudkxyoORWM8YR/qWi3L0AEMMlhNXFXIYn60xXiAxLwRi+7pZJDnEJ\n FC5WweBAFympVo10Qx3JjiUJKYng1ZA4MSH/Bvclk9QZmedlN1HrJjNcMRofQuQ2vayhWwU1s9Q\n 4a/HBW5HqSIZ1Gmkd0Y0PwQh3wpN0FBJfRhkmdZStgF84rsKJEatCrGtE=","X-Received":"by 2002:a17:903:17cb:b0:2b9:59ea:7eba with SMTP id\n d9443c01a7336-2ba78f54626mr14967615ad.13.1778038635050;\n Tue, 05 May 2026 20:37:15 -0700 (PDT)","From":"Jim Shu <jim.shu@sifive.com>","To":"qemu-devel@nongnu.org,\n\tqemu-riscv@nongnu.org","Cc":"Richard Henderson <richard.henderson@linaro.org>,\n Paolo Bonzini <pbonzini@redhat.com>,\n =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= <philmd@linaro.org>,\n Zhao Liu <zhao1.liu@intel.com>, Peter Xu <peterx@redhat.com>,\n Michael Rolnik <mrolnik@gmail.com>, Song Gao <gaosong@loongson.cn>,\n Laurent Vivier <laurent@vivier.eu>,\n \"Edgar E. Iglesias\" <edgar.iglesias@gmail.com>,\n Aurelien Jarno <aurelien@aurel32.net>, Jiaxun Yang <jiaxun.yang@flygoat.com>,\n Aleksandar Rikalo <arikalo@gmail.com>, Stafford Horne <shorne@gmail.com>,\n Nicholas Piggin <npiggin@gmail.com>, Chinmay Rath <rathc@linux.ibm.com>,\n Glenn Miles <milesg@linux.ibm.com>, Palmer Dabbelt <palmer@dabbelt.com>,\n Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>,\n Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>,\n Liu Zhiwei <zhiwei_liu@linux.alibaba.com>,\n Chao Liu <chao.liu.zevorn@gmail.com>,\n Yoshinori Sato <yoshinori.sato@nifty.com>,\n Ilya Leoshkevich <iii@linux.ibm.com>, David Hildenbrand <david@kernel.org>,\n Cornelia Huck <cohuck@redhat.com>, Eric Farman <farman@linux.ibm.com>,\n Matthew Rosato <mjrosato@linux.ibm.com>,\n Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>,\n Artyom Tarasenko <atar4qemu@gmail.com>, Max Filippov <jcmvbkbc@gmail.com>,\n qemu-ppc@nongnu.org (open list:PowerPC TCG CPUs),\n qemu-s390x@nongnu.org (open list:S390 TCG CPUs),\n Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>,\n Mark Burton <mburton@qti.qualcomm.com>,\n Peter Maydell <peter.maydell@linaro.org>, Jim Shu <jim.shu@sifive.com>","Subject":"[PATCH v3 3/5] accel/tcg: Provide early AS translate function","Date":"Wed,  6 May 2026 11:36:40 +0800","Message-ID":"<20260506033642.3641390-4-jim.shu@sifive.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20260506033642.3641390-1-jim.shu@sifive.com>","References":"<20260506033642.3641390-1-jim.shu@sifive.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","Received-SPF":"pass client-ip=2607:f8b0:4864:20::629;\n envelope-from=jim.shu@sifive.com; helo=mail-pl1-x629.google.com","X-Spam_score_int":"-20","X-Spam_score":"-2.1","X-Spam_bar":"--","X-Spam_report":"(-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,\n DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,\n RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001,\n SPF_PASS=-0.001 autolearn=unavailable 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 <qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<https://lists.nongnu.org/archive/html/qemu-devel>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n <mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org"},"content":"New early AS translate function will skip IOMMU translation. It will\nreturn IOMMU region if finding it. Original function is renamed to the\nlate translate function.\n\nIt is preparation commit of IOMMU lazy translation.\n\nSigned-off-by: Jim Shu <jim.shu@sifive.com>\nAcked-by: Pierrick Bouvier <pierrick.bouvier@oss.qualcomm.com>\n---\n accel/tcg/cputlb.c        |  6 ++---\n include/accel/tcg/iommu.h | 13 +++++++----\n system/physmem.c          | 46 ++++++++++++++++++++++++++++++++++++---\n 3 files changed, 55 insertions(+), 10 deletions(-)","diff":"diff --git a/accel/tcg/cputlb.c b/accel/tcg/cputlb.c\nindex 4ca4152579b..f0c049e1551 100644\n--- a/accel/tcg/cputlb.c\n+++ b/accel/tcg/cputlb.c\n@@ -1049,9 +1049,9 @@ void tlb_set_page_full(CPUState *cpu, int mmu_idx,\n \n     prot = full->prot;\n     asidx = cpu_asidx_from_attrs(cpu, full->attrs);\n-    section = address_space_translate_for_iotlb(cpu, asidx, paddr_page,\n-                                                &xlat, &sz, full->attrs, &prot,\n-                                                access_type);\n+    section = address_space_translate_for_iotlb_late(cpu, asidx, paddr_page,\n+                                                     &xlat, &sz, full->attrs,\n+                                                     &prot);\n     assert(sz >= TARGET_PAGE_SIZE);\n \n     tlb_debug(\"vaddr=%016\" VADDR_PRIx \" paddr=0x\" HWADDR_FMT_plx\ndiff --git a/include/accel/tcg/iommu.h b/include/accel/tcg/iommu.h\nindex 30655aab4ba..11e3d63d798 100644\n--- a/include/accel/tcg/iommu.h\n+++ b/include/accel/tcg/iommu.h\n@@ -15,10 +15,15 @@\n #include \"exec/memattrs.h\"\n \n MemoryRegionSection *\n-address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr addr,\n-                                  hwaddr *xlat, hwaddr *plen,\n-                                  MemTxAttrs attrs, int *prot,\n-                                  MMUAccessType access_type);\n+address_space_translate_for_iotlb_early(CPUState *cpu, int asidx, hwaddr addr,\n+                                        hwaddr *xlat, hwaddr *plen,\n+                                        MemTxAttrs attrs, int *prot);\n+\n+MemoryRegionSection *\n+address_space_translate_for_iotlb_late(CPUState *cpu, int asidx, hwaddr addr,\n+                                       hwaddr *xlat, hwaddr *plen,\n+                                       MemTxAttrs attrs, int *prot,\n+                                       MMUAccessType access_type);\n \n #endif\n \ndiff --git a/system/physmem.c b/system/physmem.c\nindex 564d2c6a648..6e2d43e850f 100644\n--- a/system/physmem.c\n+++ b/system/physmem.c\n@@ -682,11 +682,11 @@ void tcg_iommu_init_notifier_list(CPUState *cpu)\n }\n \n /* Called from RCU critical section */\n-MemoryRegionSection *\n+static MemoryRegionSection *\n address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr orig_addr,\n                                   hwaddr *xlat, hwaddr *plen,\n                                   MemTxAttrs attrs, int *prot,\n-                                  MMUAccessType access_type)\n+                                  MMUAccessType access_type, bool early_trans)\n {\n     MemoryRegionSection *section;\n     IOMMUMemoryRegion *iommu_mr;\n@@ -710,6 +710,11 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr orig_addr,\n         iommu_idx = imrc->attrs_to_index(iommu_mr, attrs);\n         tcg_register_iommu_notifier(cpu, iommu_mr, iommu_idx);\n \n+        /* Defer the iommu translation */\n+        if (early_trans) {\n+            break;\n+        }\n+\n         if (access_type == MMU_DATA_STORE) {\n             iommu_flags = IOMMU_WO;\n         } else {\n@@ -737,7 +742,8 @@ address_space_translate_for_iotlb(CPUState *cpu, int asidx, hwaddr orig_addr,\n         d = flatview_to_dispatch(address_space_to_flatview(iotlb.target_as));\n     }\n \n-    assert(!memory_region_is_iommu(section->mr));\n+    /* For late translation, IOMMU region translation should be finished */\n+    assert(early_trans || !memory_region_is_iommu(section->mr));\n     *xlat = addr;\n     return section;\n \n@@ -755,6 +761,40 @@ translate_fail:\n     return &d->map.sections[PHYS_SECTION_UNASSIGNED];\n }\n \n+/*\n+ * address_space_translate_for_iotlb_early: translate address without\n+ * performing IOMMU translation. This is used for CPU TLB setup.\n+ *\n+ * Called from RCU critical section.\n+ */\n+MemoryRegionSection *\n+address_space_translate_for_iotlb_early(CPUState *cpu, int asidx,\n+                                        hwaddr orig_addr,\n+                                        hwaddr *xlat, hwaddr *plen,\n+                                        MemTxAttrs attrs, int *prot)\n+{\n+    /* access_type doesn't matter for early translation */\n+    return address_space_translate_for_iotlb(cpu, asidx, orig_addr, xlat, plen,\n+                                             attrs, prot, MMU_DATA_LOAD, true);\n+}\n+\n+/*\n+ * address_space_translate_for_iotlb_late: translate address with\n+ * performing IOMMU translation. This is used for lazy IOMMU translation.\n+ *\n+ * Called from RCU critical section.\n+ */\n+MemoryRegionSection *\n+address_space_translate_for_iotlb_late(CPUState *cpu, int asidx,\n+                                       hwaddr orig_addr,\n+                                       hwaddr *xlat, hwaddr *plen,\n+                                       MemTxAttrs attrs, int *prot,\n+                                       MMUAccessType access_type)\n+{\n+    return address_space_translate_for_iotlb(cpu, asidx, orig_addr, xlat, plen,\n+                                             attrs, prot, access_type, false);\n+}\n+\n #endif /* CONFIG_TCG */\n \n void cpu_address_space_init(CPUState *cpu, int asidx,\n","prefixes":["v3","3/5"]}