From: Jonathan Cameron via <qemu-arm@nongnu.org>
To: Shameer Kolothum <skolothumtho@nvidia.com>
Cc: <qemu-arm@nongnu.org>, <qemu-devel@nongnu.org>,
<eric.auger@redhat.com>, <peter.maydell@linaro.org>,
<nicolinc@nvidia.com>, <nathanc@nvidia.com>, <mochs@nvidia.com>,
<zhangfei.gao@linaro.org>, <zhenzhong.duan@intel.com>,
<jgg@nvidia.com>, <kjaju@nvidia.com>
Subject: Re: [RFC PATCH 4/4] hw/arm/smmuv3-accel: Read and propagate host vIOMMU events
Date: Tue, 11 Nov 2025 13:29:29 +0000 [thread overview]
Message-ID: <20251111132929.000064ce@huawei.com> (raw)
In-Reply-To: <20251105154657.37386-5-skolothumtho@nvidia.com>
On Wed, 5 Nov 2025 15:46:52 +0000
Shameer Kolothum <skolothumtho@nvidia.com> wrote:
> Install an event handler on the vEVENTQ fd to read and propagate host
> generated vIOMMU events to the guest.
>
> The handler runs in QEMU’s main loop, using a non-blocking fd registered
> via qemu_set_fd_handler().
>
> Signed-off-by: Shameer Kolothum <skolothumtho@nvidia.com>
A few minor suggestions inline. Otherwise set looks good to me, though
I'm very far from an expert of this stuff!
Jonathan
> ---
> hw/arm/smmuv3-accel.c | 62 +++++++++++++++++++++++++++++++++++++++++++
> hw/arm/smmuv3-accel.h | 2 ++
> 2 files changed, 64 insertions(+)
>
> diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c
> index 210e7ebf36..e6c81c4786 100644
> --- a/hw/arm/smmuv3-accel.c
> +++ b/hw/arm/smmuv3-accel.c
> @@ -383,6 +383,62 @@ static SMMUv3AccelDevice *smmuv3_accel_get_dev(SMMUState *bs, SMMUPciBus *sbus,
> return accel_dev;
> }
>
> +static void smmuv3_accel_event_read(void *opaque)
> +{
> + SMMUv3State *s = opaque;
> + SMMUv3AccelState *s_accel = s->s_accel;
> + SMMUViommu *vsmmu = s_accel->vsmmu;
> + struct iommu_vevent_arm_smmuv3 *vevent;
> + struct iommufd_vevent_header *hdr;
> + ssize_t readsz = sizeof(*hdr) + sizeof(*vevent);
> + uint8_t buf[sizeof(*hdr) + sizeof(*vevent)];
Could you wrap this up in a structure to make it a tiny
bit more obvious what is going on?
struct {
struct iommufd_vevent_header hdr;
struct iommufd_vevent_arm_smmuv3 vevent;
} buf;
Should allow sizeof(buf);
and accessing elements directly without casts.
> + uint32_t last_seq = vsmmu->last_event_seq;
> + ssize_t bytes;
> + Evt evt = {};
Given you copy into this based on sizeof(evt) I can't see why you need
to initialize.
> +
> + bytes = read(vsmmu->veventq->veventq_fd, buf, readsz);
> + if (bytes <= 0) {
> + if (errno == EAGAIN || errno == EINTR) {
> + return;
> + }
> + error_report("vEVENTQ: read failed (%s)", strerror(errno));
> + return;
> + }
> +
> + if (bytes < readsz) {
> + error_report("vEVENTQ: incomplete read (%zd/%zd bytes)", bytes, readsz);
> + return;
> + }
> +
> + hdr = (struct iommufd_vevent_header *)buf;
> + if (hdr->flags & IOMMU_VEVENTQ_FLAG_LOST_EVENTS) {
> + error_report("vEVENTQ has lost events");
> + return;
> + }
> +
> + vevent = (struct iommu_vevent_arm_smmuv3 *)(buf + sizeof(*hdr));
> + /* Check sequence in hdr for lost events if any */
> + if (vsmmu->event_start) {
> + uint32_t expected = (last_seq == INT_MAX) ? 0 : last_seq + 1;
> +
> + if (hdr->sequence != expected) {
> + uint32_t delta;
> +
> + if (hdr->sequence >= last_seq) {
> + delta = hdr->sequence - last_seq;
> + } else {
> + /* Handle wraparound from INT_MAX */
> + delta = (INT_MAX - last_seq) + hdr->sequence + 1;
> + }
> + error_report("vEVENTQ: detected lost %u event(s)", delta - 1);
> + }
> + }
> + vsmmu->last_event_seq = hdr->sequence;
> + vsmmu->event_start = true;
> + memcpy(&evt, vevent, sizeof(evt));
> + smmuv3_propagate_event(s, &evt);
Why is the copy needed? Can't you just use the vevent in place?
> +}
WARNING: multiple messages have this Message-ID (diff)
From: Jonathan Cameron via <qemu-devel@nongnu.org>
To: Shameer Kolothum <skolothumtho@nvidia.com>
Cc: <qemu-arm@nongnu.org>, <qemu-devel@nongnu.org>,
<eric.auger@redhat.com>, <peter.maydell@linaro.org>,
<nicolinc@nvidia.com>, <nathanc@nvidia.com>, <mochs@nvidia.com>,
<zhangfei.gao@linaro.org>, <zhenzhong.duan@intel.com>,
<jgg@nvidia.com>, <kjaju@nvidia.com>
Subject: Re: [RFC PATCH 4/4] hw/arm/smmuv3-accel: Read and propagate host vIOMMU events
Date: Tue, 11 Nov 2025 13:29:29 +0000 [thread overview]
Message-ID: <20251111132929.000064ce@huawei.com> (raw)
In-Reply-To: <20251105154657.37386-5-skolothumtho@nvidia.com>
On Wed, 5 Nov 2025 15:46:52 +0000
Shameer Kolothum <skolothumtho@nvidia.com> wrote:
> Install an event handler on the vEVENTQ fd to read and propagate host
> generated vIOMMU events to the guest.
>
> The handler runs in QEMU’s main loop, using a non-blocking fd registered
> via qemu_set_fd_handler().
>
> Signed-off-by: Shameer Kolothum <skolothumtho@nvidia.com>
A few minor suggestions inline. Otherwise set looks good to me, though
I'm very far from an expert of this stuff!
Jonathan
> ---
> hw/arm/smmuv3-accel.c | 62 +++++++++++++++++++++++++++++++++++++++++++
> hw/arm/smmuv3-accel.h | 2 ++
> 2 files changed, 64 insertions(+)
>
> diff --git a/hw/arm/smmuv3-accel.c b/hw/arm/smmuv3-accel.c
> index 210e7ebf36..e6c81c4786 100644
> --- a/hw/arm/smmuv3-accel.c
> +++ b/hw/arm/smmuv3-accel.c
> @@ -383,6 +383,62 @@ static SMMUv3AccelDevice *smmuv3_accel_get_dev(SMMUState *bs, SMMUPciBus *sbus,
> return accel_dev;
> }
>
> +static void smmuv3_accel_event_read(void *opaque)
> +{
> + SMMUv3State *s = opaque;
> + SMMUv3AccelState *s_accel = s->s_accel;
> + SMMUViommu *vsmmu = s_accel->vsmmu;
> + struct iommu_vevent_arm_smmuv3 *vevent;
> + struct iommufd_vevent_header *hdr;
> + ssize_t readsz = sizeof(*hdr) + sizeof(*vevent);
> + uint8_t buf[sizeof(*hdr) + sizeof(*vevent)];
Could you wrap this up in a structure to make it a tiny
bit more obvious what is going on?
struct {
struct iommufd_vevent_header hdr;
struct iommufd_vevent_arm_smmuv3 vevent;
} buf;
Should allow sizeof(buf);
and accessing elements directly without casts.
> + uint32_t last_seq = vsmmu->last_event_seq;
> + ssize_t bytes;
> + Evt evt = {};
Given you copy into this based on sizeof(evt) I can't see why you need
to initialize.
> +
> + bytes = read(vsmmu->veventq->veventq_fd, buf, readsz);
> + if (bytes <= 0) {
> + if (errno == EAGAIN || errno == EINTR) {
> + return;
> + }
> + error_report("vEVENTQ: read failed (%s)", strerror(errno));
> + return;
> + }
> +
> + if (bytes < readsz) {
> + error_report("vEVENTQ: incomplete read (%zd/%zd bytes)", bytes, readsz);
> + return;
> + }
> +
> + hdr = (struct iommufd_vevent_header *)buf;
> + if (hdr->flags & IOMMU_VEVENTQ_FLAG_LOST_EVENTS) {
> + error_report("vEVENTQ has lost events");
> + return;
> + }
> +
> + vevent = (struct iommu_vevent_arm_smmuv3 *)(buf + sizeof(*hdr));
> + /* Check sequence in hdr for lost events if any */
> + if (vsmmu->event_start) {
> + uint32_t expected = (last_seq == INT_MAX) ? 0 : last_seq + 1;
> +
> + if (hdr->sequence != expected) {
> + uint32_t delta;
> +
> + if (hdr->sequence >= last_seq) {
> + delta = hdr->sequence - last_seq;
> + } else {
> + /* Handle wraparound from INT_MAX */
> + delta = (INT_MAX - last_seq) + hdr->sequence + 1;
> + }
> + error_report("vEVENTQ: detected lost %u event(s)", delta - 1);
> + }
> + }
> + vsmmu->last_event_seq = hdr->sequence;
> + vsmmu->event_start = true;
> + memcpy(&evt, vevent, sizeof(evt));
> + smmuv3_propagate_event(s, &evt);
Why is the copy needed? Can't you just use the vevent in place?
> +}
next prev parent reply other threads:[~2025-11-11 13:29 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-05 15:46 [RFC PATCH 0/4] vEVENTQ support for accelerated SMMUv3 devices Shameer Kolothum
2025-11-05 15:46 ` [RFC PATCH 1/4] backends/iommufd: Introduce iommufd_backend_alloc_veventq Shameer Kolothum
2025-11-05 15:46 ` [RFC PATCH 2/4] hw/arm/smmuv3-accel: Allocate vEVENTQ for accelerated SMMUv3 devices Shameer Kolothum
2025-11-05 15:46 ` [RFC PATCH 3/4] hw/arm/smmuv3: Introduce a helper function for event propagation Shameer Kolothum
2025-11-05 15:46 ` [RFC PATCH 4/4] hw/arm/smmuv3-accel: Read and propagate host vIOMMU events Shameer Kolothum
2025-11-11 13:29 ` Jonathan Cameron via [this message]
2025-11-11 13:29 ` Jonathan Cameron via
2025-11-13 11:59 ` Zhangfei Gao
2025-11-13 13:07 ` Shameer Kolothum
2025-11-13 17:44 ` Nicolin Chen
2025-11-14 8:45 ` Zhangfei Gao
2025-11-14 8:55 ` Shameer Kolothum
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=20251111132929.000064ce@huawei.com \
--to=qemu-arm@nongnu.org \
--cc=eric.auger@redhat.com \
--cc=jgg@nvidia.com \
--cc=jonathan.cameron@huawei.com \
--cc=kjaju@nvidia.com \
--cc=mochs@nvidia.com \
--cc=nathanc@nvidia.com \
--cc=nicolinc@nvidia.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=skolothumtho@nvidia.com \
--cc=zhangfei.gao@linaro.org \
--cc=zhenzhong.duan@intel.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.