From: "Michael S. Tsirkin" <mst@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org, alejandro.j.jimenez@oracle.com,
Yunhe Wang <yunhewwww@163.com>,
qemu-stable@nongnu.org
Subject: Re: [PATCH] amd_iommu: fix infinite loop
Date: Wed, 27 May 2026 08:07:17 -0400 [thread overview]
Message-ID: <20260527080701-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20260511113923.2478812-1-pbonzini@redhat.com>
On Mon, May 11, 2026 at 01:39:22PM +0200, Paolo Bonzini wrote:
> The AMD IOMMU command buffer is a ring buffer of cmdbuf_len (a power
> of two) entries. Each entries is 16 bytes and the head pointer cycles
> through the set:
>
> The tail pointer is written by the guest through the COMMAND_TAIL MMIO
> register (offset 0x2008); the while loop in amdvi_cmdbuf_run() only
> terminates when head == tail. If tail is set to a value higher than
> cmdbuf_len * 16, head will cycle through all the elements of the ring
> buffer indefinitely, without ever matching tail. Fix this by further
> masking tail (and head, for consistency) against the size of the
> ring buffer.
>
> Reported-by: Yunhe Wang <yunhewwww@163.com>
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
in my tree now.
> ---
> hw/i386/amd_iommu.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/hw/i386/amd_iommu.c b/hw/i386/amd_iommu.c
> index 789e09d6f2b..197e452e3c3 100644
> --- a/hw/i386/amd_iommu.c
> +++ b/hw/i386/amd_iommu.c
> @@ -1578,7 +1578,8 @@ static inline void amdvi_handle_devtab_write(AMDVIState *s)
> static inline void amdvi_handle_cmdhead_write(AMDVIState *s)
> {
> s->cmdbuf_head = amdvi_readq(s, AMDVI_MMIO_COMMAND_HEAD)
> - & AMDVI_MMIO_CMDBUF_HEAD_MASK;
> + & AMDVI_MMIO_CMDBUF_HEAD_MASK
> + & (s->cmdbuf_len * AMDVI_COMMAND_SIZE - 1);
> amdvi_cmdbuf_run(s);
> }
>
> @@ -1594,7 +1595,8 @@ static inline void amdvi_handle_cmdbase_write(AMDVIState *s)
> static inline void amdvi_handle_cmdtail_write(AMDVIState *s)
> {
> s->cmdbuf_tail = amdvi_readq(s, AMDVI_MMIO_COMMAND_TAIL)
> - & AMDVI_MMIO_CMDBUF_TAIL_MASK;
> + & AMDVI_MMIO_CMDBUF_TAIL_MASK
> + & (s->cmdbuf_len * AMDVI_COMMAND_SIZE - 1);
> amdvi_cmdbuf_run(s);
> }
>
> --
> 2.54.0
prev parent reply other threads:[~2026-05-27 12:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-11 11:39 [PATCH] amd_iommu: fix infinite loop Paolo Bonzini
2026-05-12 0:13 ` Alejandro Jimenez
2026-05-27 9:05 ` Paolo Bonzini
2026-05-27 14:38 ` Alejandro Jimenez
2026-05-27 12:07 ` Michael S. Tsirkin [this message]
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=20260527080701-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=alejandro.j.jimenez@oracle.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=yunhewwww@163.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.