All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gong Shuai <gsh517025@gmail.com>
To: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>,
	tanchi25@mails.ucas.ac.cn
Cc: alistair.francis@wdc.com, chao.liu@processmission.com,
	liwei1518@gmail.com, nutty.liu@hotmail.com, palmer@dabbelt.com,
	pierrick.bouvier@oss.qualcomm.com, qemu-devel@nongnu.org,
	qemu-riscv@nongnu.org, zhiwei_liu@linux.alibaba.com,
	gong.shuai@sanechips.com.cn
Subject: Re: [PATCH v2 0/3] hw/riscv: iommu: Support automatic PTE A/D updates
Date: Tue, 24 Nov 2026 13:18:43 +0800	[thread overview]
Message-ID: <95fe4c53-fe13-4e0c-abbc-bbb546850560@gmail.com> (raw)
In-Reply-To: <841c86f7-9b78-4486-991e-ccec2eede0ec@oss.qualcomm.com>

Hi Daniel,

On 11/24/2026 3:58 AM, Daniel Henrique Barboza wrote:
> Hello,
> 
> On 11/17/2026 11:30 AM, Gong Shuai wrote:
>>> This series adds support for automatic updates of page-table accessed
>>> (A) and dirty (D) bits in the RISC-V IOMMU, as specified by the RISC-V
>>> IOMMU architecture. The feature is advertised through the AMO_HWAD
>>> capability and controlled by the SADE and GADE bits in device contexts.
>>>
>>> The first two patches fix implicit G-stage page-table access handling
>>> and IOATC permission checks. The third patch implements atomic A/D bit
>>> updates using CAS, with page-table walk retries on concurrent
>>> modifications and G-stage permission checks for implicit writes during
>>> nested translation.
>>>
>>> The implementation has been validated with QTests, Linux DMA tests under
>>> KVM and TCG, and concurrency tests covering CAS retries, PTE
>>> modifications, and G-stage mapping changes.
>>>
>>> ---
>>> Changes in v2:
>>> - Set iotval2 to zero for S-stage page faults, as suggested by
>>>    Daniel Henrique Barboza.
>>> - Avoid duplicate implicit_read calculations, as suggested by Nutty Liu.
>>> - Document the new amo-hwad device property.
>>>
>>> v1: https://lore.kernel.org/qemu-devel/20261108143934.129923-1-tanchi25@mails.ucas.ac.cn/
>>>
>>> Tan Chi (3):
>>>    hw/riscv: iommu: Fix implicit G-stage page-table accesses
>>>    hw/riscv: iommu: Check permissions on IOATC hits
>>>    hw/riscv: iommu: Support automatic PTE A/D updates
>> 
>> Hi Tan Chi,
>> 
>> Thanks for your work.
>> 
>> I have tested this series on my nested IOMMU setup.
>> 
>> - Outer QEMU: this series on top of master, -M virt,...,iommu-sys=on,
>>                -global riscv-iommu.amo-hwad=on, emulated NVMe
>> - Inner QEMU: needs accel=on support for riscv-iommu-pci, and
>>                vfio-pci with iommufd
>> - Outer Linux host: needs hardware dirty tracking and nested IOMMU
>>                support
>> 
>> Test flow:
>> 
>> 1. Boot host and guest, do NVMe I/O
>> 2. Clear host S2 D bits and trigger GVMA inval in the inner QEMU monitor,
>>     use command: calc_dirty_rate -b 1
>> 3. Back to guest shell and do another NVMe I/O
>> 
>> It completed without a guest hang or I/O error. With temporary local
>> debug prints I could see en_s=1/en_g=1 and implicit G-stage page-table
>> walks.
>> 
>> One host-side workaround is that on the host I need
>> echo never > /sys/kernel/mm/transparent_hugepage/enabled
>> to avoid an hang with THP; otherwise calc_dirty_rate -b can leave the
>> guest stuck.
> 
> 
> Can you please clarify if this THP hang also happens on master?  It's not clear
> to me if this scenario is already broken or if this automatic PTE A/D work is
> exposing it.

Yes, the THP hang also occurs on master (2bfbe39d0fff).
It is not introduced by the amo_hwad series.

> 
> Even if it's a kernel/KVM side problem (as Tan Chi mentioned in another reply) we
> should be wary of adding emulation changes that can regress regular software
> usage.  At the very least we should document that we're doing an emulation change
> that can break software that doesn't have a certain workaround/patch.

This is indeed a KVM-side issue. It is not related to nested IOMMU
or the amo_hwad series; the hang was simply observed while running
tests that involved them.

I can provide a simple setup to reproduce it.
(Hope the following information is useful.)

With master QEMU as the RISC-V virt host and kernel v7.4-rc4 built
with defconfig + KVM + TRANSPARENT_HUGEPAGE, running:

     timeout 180 ./dirty_log_perf_test \
     -e -s anonymous_thp -v 1 -b 512M -i 2

hangs and exits due to timeout, whereas:

     timeout 180 ./dirty_log_perf_test \
     -e -s anonymous -v 1 -b 512M -i 2

exits normally.

After applying the fix patch [1] to the kernel, both tests exit
normally.

Detailed logs for the four command runs are provided below for
reference.

Case 1: without fix patch, anonymous_thp ---- HANG and TIMEOUT(124)

   $ cat /sys/kernel/mm/transparent_hugepage/enabled
   [always] madvise never
   $ timeout 180 ./dirty_log_perf_test -e -s anonymous_thp -v 1 -b 512M -i 2
   Random seed: 0x77be2754
   Test iterations: 2
   Testing guest mode: PA-bits:50,  VA-bits:48,  4K pages
   Random seed: 0x1
   guest physical test memory: [0x3ffffdfe00000, 0x3ffffffe00000)
   Populate memory time: 0.277703400s
   Enabling dirty logging time: 0.001101300s

   Iteration 1 dirty memory time: 0.086482400s
   Iteration 1 get dirty log time: 0.000188500s
   Iteration 1 clear dirty log time: 0.017205400s
   Iteration 2 dirty memory time: 3.617855200s
   Iteration 2 get dirty log time: 0.000093700s
   Iteration 2 clear dirty log time: 0.014652300s
   Disabling dirty logging time: 0.001215600s

   $ echo $?
   124

Case 2: without fix patch, anonymous

   $ timeout 180 ./dirty_log_perf_test -e -s anonymous -v 1 -b 512M -i 2
   Random seed: 0x68f16937
   Test iterations: 2
   Testing guest mode: PA-bits:50,  VA-bits:48,  4K pages
   Random seed: 0x1
   guest physical test memory: [0x3ffffdffff000, 0x3fffffffff000)
   Populate memory time: 8.404907600s
   Enabling dirty logging time: 0.001048700s

   Iteration 1 dirty memory time: 0.080460200s
   Iteration 1 get dirty log time: 0.000119300s
   Iteration 1 clear dirty log time: 0.014741000s
   Iteration 2 dirty memory time: 3.689446400s
   Iteration 2 get dirty log time: 0.000034200s
   Iteration 2 clear dirty log time: 0.013190500s
   Disabling dirty logging time: 0.000651400s
   Get dirty log over 2 iterations took 0.000153500s. (Avg 0.000076750s/iteration)
   Clear dirty log over 2 iterations took 0.027931500s. (Avg 0.013965750s/iteration)
   Testing guest mode: PA-bits:50,  VA-bits:39,  4K pages
   guest physical test memory: [0x3ffffdffff000, 0x3fffffffff000)
   Populate memory time: 7.828295400s
   Enabling dirty logging time: 0.000798200s

   Iteration 1 dirty memory time: 0.066219100s
   Iteration 1 get dirty log time: 0.000039900s
   Iteration 1 clear dirty log time: 0.023695500s
   Iteration 2 dirty memory time: 3.429129500s
   Iteration 2 get dirty log time: 0.000032200s
   Iteration 2 clear dirty log time: 0.020796400s
   Disabling dirty logging time: 0.000772600s
   Get dirty log over 2 iterations took 0.000072100s. (Avg 0.000036050s/iteration)
   Clear dirty log over 2 iterations took 0.044491900s. (Avg 0.022245950s/iteration)

Case 3: withfix patch, anonymous_thp

   $ cat /sys/kernel/mm/transparent_hugepage/enabled
   [always] madvise never
   $ timeout 180 ./dirty_log_perf_test -e -s anonymous_thp -v 1 -b 512M -i 2
   Random seed: 0x3b6f1968
   Test iterations: 2
   Testing guest mode: PA-bits:50,  VA-bits:48,  4K pages
   Random seed: 0x1
   guest physical test memory: [0x3ffffdfe00000, 0x3ffffffe00000)
   Populate memory time: 0.221626400s
   Enabling dirty logging time: 0.001002400s

   Iteration 1 dirty memory time: 0.079966800s
   Iteration 1 get dirty log time: 0.000119400s
   Iteration 1 clear dirty log time: 0.012897100s
   Iteration 2 dirty memory time: 3.490279400s
   Iteration 2 get dirty log time: 0.000044900s
   Iteration 2 clear dirty log time: 0.013184200s
   Disabling dirty logging time: 0.000883200s
   Get dirty log over 2 iterations took 0.000164300s. (Avg 0.000082150s/iteration)
   Clear dirty log over 2 iterations took 0.026081300s. (Avg 0.013040650s/iteration)
   Testing guest mode: PA-bits:50,  VA-bits:39,  4K pages
   guest physical test memory: [0x3ffffdfe00000, 0x3ffffffe00000)
   Populate memory time: 0.209773300s
   Enabling dirty logging time: 0.000790800s

   Iteration 1 dirty memory time: 0.063432900s
   Iteration 1 get dirty log time: 0.000040100s
   Iteration 1 clear dirty log time: 0.012308600s
   Iteration 2 dirty memory time: 3.367311900s
   Iteration 2 get dirty log time: 0.000032500s
   Iteration 2 clear dirty log time: 0.013141600s
   Disabling dirty logging time: 0.000953800s
   Get dirty log over 2 iterations took 0.000072600s. (Avg 0.000036300s/iteration)
   Clear dirty log over 2 iterations took 0.025450200s. (Avg 0.012725100s/iteration)

Case 4: withfix patch, anonymous

   $ timeout 180 ./dirty_log_perf_test -e -s anonymous -v 1 -b 512M -i 2
   Random seed: 0x679b7adb
   Test iterations: 2
   Testing guest mode: PA-bits:50,  VA-bits:48,  4K pages
   Random seed: 0x1
   guest physical test memory: [0x3ffffdffff000, 0x3fffffffff000)
   Populate memory time: 8.066872600s
   Enabling dirty logging time: 0.001247200s

   Iteration 1 dirty memory time: 0.081895900s
   Iteration 1 get dirty log time: 0.000186200s
   Iteration 1 clear dirty log time: 0.014706800s
   Iteration 2 dirty memory time: 3.441165900s
   Iteration 2 get dirty log time: 0.000031500s
   Iteration 2 clear dirty log time: 0.013069200s
   Disabling dirty logging time: 0.000469100s
   Get dirty log over 2 iterations took 0.000217700s. (Avg 0.000108850s/iteration)
   Clear dirty log over 2 iterations took 0.027776000s. (Avg 0.013888000s/iteration)
   Testing guest mode: PA-bits:50,  VA-bits:39,  4K pages
   guest physical test memory: [0x3ffffdffff000, 0x3fffffffff000)
   Populate memory time: 7.804275600s
   Enabling dirty logging time: 0.003435000s

   Iteration 1 dirty memory time: 0.067627700s
   Iteration 1 get dirty log time: 0.000037100s
   Iteration 1 clear dirty log time: 0.013302700s
   Iteration 2 dirty memory time: 3.433272000s
   Iteration 2 get dirty log time: 0.000031800s
   Iteration 2 clear dirty log time: 0.013085400s
   Disabling dirty logging time: 0.000614100s
   Get dirty log over 2 iterations took 0.000068900s. (Avg 0.000034450s/iteration)
   Clear dirty log over 2 iterations took 0.026388100s. (Avg 0.013194050s/iteration)

[1] https://lore.kernel.org/linux-riscv/20260815103245.864925-1-jinyu.tang@linux.dev/

Thanks,
Shuai

> 
> Thanks,
> Daniel
> 
>> 
>> This is only a limited positive test. A Linux guest is not suitable for
>> constructing negative cases so I would not claim full Tested-by coverage.
>> 
>> Thanks,
>> Shuai
>> 
>>>
>>>   docs/specs/riscv-iommu.rst |   2 +
>>>   hw/riscv/riscv-iommu.c     | 254 +++++++++++++++++++++++++++++++++----
>>>   hw/riscv/riscv-iommu.h     |   1 +
>>>   3 files changed, 232 insertions(+), 25 deletions(-)
>>>
>>> -- 
>>> 2.53.0
>>>
> 



  reply	other threads:[~2026-11-24  5:19 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-13 15:12 [PATCH v2 0/3] hw/riscv: iommu: Support automatic PTE A/D updates Tan Chi
2026-11-13 15:12 ` [PATCH v2 1/3] hw/riscv: iommu: Fix implicit G-stage page-table accesses Tan Chi
2026-11-13 15:12 ` [PATCH v2 2/3] hw/riscv: iommu: Check permissions on IOATC hits Tan Chi
2026-11-13 15:12 ` [PATCH v2 3/3] hw/riscv: iommu: Support automatic PTE A/D updates Tan Chi
2026-11-17 14:30 ` [PATCH v2 0/3] " Gong Shuai
2026-11-18 14:40   ` Tan Chi
2026-11-23 19:58   ` Daniel Henrique Barboza
2026-11-24  5:18     ` Gong Shuai [this message]
2026-11-24 19:58       ` Daniel Henrique Barboza

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=95fe4c53-fe13-4e0c-abbc-bbb546850560@gmail.com \
    --to=gsh517025@gmail.com \
    --cc=alistair.francis@wdc.com \
    --cc=chao.liu@processmission.com \
    --cc=daniel.barboza@oss.qualcomm.com \
    --cc=gong.shuai@sanechips.com.cn \
    --cc=liwei1518@gmail.com \
    --cc=nutty.liu@hotmail.com \
    --cc=palmer@dabbelt.com \
    --cc=pierrick.bouvier@oss.qualcomm.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-riscv@nongnu.org \
    --cc=tanchi25@mails.ucas.ac.cn \
    --cc=zhiwei_liu@linux.alibaba.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.