[PATCH] hw/riscv/riscv-iommu: Fix IOCOUNTINH.CY toggle detection

fangyu.yu@linux.alibaba.com posted 1 patch 2 weeks, 2 days ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260509074941.99295-1-fangyu.yu@linux.alibaba.com
Maintainers: Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Chao Liu <chao.liu.zevorn@gmail.com>
hw/riscv/riscv-iommu-hpm.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] hw/riscv/riscv-iommu: Fix IOCOUNTINH.CY toggle detection
Posted by fangyu.yu@linux.alibaba.com 2 weeks, 2 days ago
From: Fangyu Yu <fangyu.yu@linux.alibaba.com>

Fix IOCOUNTINH.CY toggle detection by comparing normalized CY bit
rather than XORing whole register with boolean.

Fixes: 2cf2a6c027ba ("hw/riscv/riscv-iommu: add IOCOUNTINH mmio writes")
Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
---
 hw/riscv/riscv-iommu-hpm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c
index e8d284ac8b..5bf80a8db9 100644
--- a/hw/riscv/riscv-iommu-hpm.c
+++ b/hw/riscv/riscv-iommu-hpm.c
@@ -245,7 +245,8 @@ void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh)
         s, RISCV_IOMMU_REG_IOCOUNTINH);
 
     /* We only need to process CY bit toggle. */
-    if (!(inhibit ^ prev_cy_inh)) {
+    bool cy_inh = !!(inhibit & RISCV_IOMMU_IOCOUNTINH_CY);
+    if (cy_inh == prev_cy_inh) {
         return;
     }
 
-- 
2.50.1
Re: [PATCH] hw/riscv/riscv-iommu: Fix IOCOUNTINH.CY toggle detection
Posted by Alistair Francis 6 days, 15 hours ago
On Sat, May 9, 2026 at 5:57 PM <fangyu.yu@linux.alibaba.com> wrote:
>
> From: Fangyu Yu <fangyu.yu@linux.alibaba.com>
>
> Fix IOCOUNTINH.CY toggle detection by comparing normalized CY bit
> rather than XORing whole register with boolean.
>
> Fixes: 2cf2a6c027ba ("hw/riscv/riscv-iommu: add IOCOUNTINH mmio writes")
> Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>

Thanks!

Applied to riscv-to-apply.next

Alistair

> ---
>  hw/riscv/riscv-iommu-hpm.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c
> index e8d284ac8b..5bf80a8db9 100644
> --- a/hw/riscv/riscv-iommu-hpm.c
> +++ b/hw/riscv/riscv-iommu-hpm.c
> @@ -245,7 +245,8 @@ void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh)
>          s, RISCV_IOMMU_REG_IOCOUNTINH);
>
>      /* We only need to process CY bit toggle. */
> -    if (!(inhibit ^ prev_cy_inh)) {
> +    bool cy_inh = !!(inhibit & RISCV_IOMMU_IOCOUNTINH_CY);
> +    if (cy_inh == prev_cy_inh) {
>          return;
>      }
>
> --
> 2.50.1
>
>
Re: [PATCH] hw/riscv/riscv-iommu: Fix IOCOUNTINH.CY toggle detection
Posted by Nutty.Liu 1 week ago
On 5/9/2026 3:49 PM, fangyu.yu@linux.alibaba.com wrote:
> From: Fangyu Yu <fangyu.yu@linux.alibaba.com>
>
> Fix IOCOUNTINH.CY toggle detection by comparing normalized CY bit
> rather than XORing whole register with boolean.
>
> Fixes: 2cf2a6c027ba ("hw/riscv/riscv-iommu: add IOCOUNTINH mmio writes")
> Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
Reviewed-by: Nutty Liu <nutty.liu@hotmail.com>

Thanks,
Nutty
> ---
>   hw/riscv/riscv-iommu-hpm.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c
> index e8d284ac8b..5bf80a8db9 100644
> --- a/hw/riscv/riscv-iommu-hpm.c
> +++ b/hw/riscv/riscv-iommu-hpm.c
> @@ -245,7 +245,8 @@ void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh)
>           s, RISCV_IOMMU_REG_IOCOUNTINH);
>   
>       /* We only need to process CY bit toggle. */
> -    if (!(inhibit ^ prev_cy_inh)) {
> +    bool cy_inh = !!(inhibit & RISCV_IOMMU_IOCOUNTINH_CY);
> +    if (cy_inh == prev_cy_inh) {
>           return;
>       }
>
Re: [PATCH] hw/riscv/riscv-iommu: Fix IOCOUNTINH.CY toggle detection
Posted by Daniel Henrique Barboza 1 week, 4 days ago

On 5/9/2026 4:49 AM, fangyu.yu@linux.alibaba.com wrote:
> From: Fangyu Yu <fangyu.yu@linux.alibaba.com>
> 
> Fix IOCOUNTINH.CY toggle detection by comparing normalized CY bit
> rather than XORing whole register with boolean.
> 
> Fixes: 2cf2a6c027ba ("hw/riscv/riscv-iommu: add IOCOUNTINH mmio writes")
> Signed-off-by: Fangyu Yu <fangyu.yu@linux.alibaba.com>
> ---

Reviewed-by: Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>

>   hw/riscv/riscv-iommu-hpm.c | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/hw/riscv/riscv-iommu-hpm.c b/hw/riscv/riscv-iommu-hpm.c
> index e8d284ac8b..5bf80a8db9 100644
> --- a/hw/riscv/riscv-iommu-hpm.c
> +++ b/hw/riscv/riscv-iommu-hpm.c
> @@ -245,7 +245,8 @@ void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh)
>           s, RISCV_IOMMU_REG_IOCOUNTINH);
>   
>       /* We only need to process CY bit toggle. */
> -    if (!(inhibit ^ prev_cy_inh)) {
> +    bool cy_inh = !!(inhibit & RISCV_IOMMU_IOCOUNTINH_CY);
> +    if (cy_inh == prev_cy_inh) {
>           return;
>       }
>