qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Eric Auger <eric.auger@redhat.com>,
	Jean-Philippe Brucker <jean-philippe@linaro.org>
Subject: [PULL 03/22] virtio-iommu: Standardize granule extraction and formatting
Date: Thu, 3 Aug 2023 18:20:52 -0400	[thread overview]
Message-ID: <1084feddc6a677cdfdde56936bfb97cf32cc4dee.1691101215.git.mst@redhat.com> (raw)
In-Reply-To: <cover.1691101215.git.mst@redhat.com>

From: Eric Auger <eric.auger@redhat.com>

At several locations we compute the granule from the config
page_size_mask using ctz() and then format it in traces using
BIT(). As the page_size_mask is 64b we should use ctz64 and
BIT_ULL() for formatting. We failed to be consistent.

Note the page_size_mask is garanteed to be non null. The spec
mandates the device to set at least one bit, so ctz64 cannot
return 64. This is garanteed by the fact the device
initializes the page_size_mask to qemu_target_page_mask()
and then the page_size_mask is further constrained by
virtio_iommu_set_page_size_mask() callback which can't
result in a new mask being null. So if Coverity complains
round those ctz64/BIT_ULL with CID 1517772 this is a false
positive

Signed-off-by: Eric Auger <eric.auger@redhat.com>
Fixes: 94df5b2180 ("virtio-iommu: Fix 64kB host page size VFIO device assignment")
Message-Id: <20230718182136.40096-1-eric.auger@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Jean-Philippe Brucker <jean-philippe@linaro.org>
---
 hw/virtio/virtio-iommu.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/hw/virtio/virtio-iommu.c b/hw/virtio/virtio-iommu.c
index 4dcf1d5c62..be51635895 100644
--- a/hw/virtio/virtio-iommu.c
+++ b/hw/virtio/virtio-iommu.c
@@ -854,17 +854,19 @@ static IOMMUTLBEntry virtio_iommu_translate(IOMMUMemoryRegion *mr, hwaddr addr,
     VirtIOIOMMUEndpoint *ep;
     uint32_t sid, flags;
     bool bypass_allowed;
+    int granule;
     bool found;
     int i;
 
     interval.low = addr;
     interval.high = addr + 1;
+    granule = ctz64(s->config.page_size_mask);
 
     IOMMUTLBEntry entry = {
         .target_as = &address_space_memory,
         .iova = addr,
         .translated_addr = addr,
-        .addr_mask = (1 << ctz32(s->config.page_size_mask)) - 1,
+        .addr_mask = BIT_ULL(granule) - 1,
         .perm = IOMMU_NONE,
     };
 
@@ -1117,7 +1119,7 @@ static int virtio_iommu_set_page_size_mask(IOMMUMemoryRegion *mr,
     if (s->granule_frozen) {
         int cur_granule = ctz64(cur_mask);
 
-        if (!(BIT(cur_granule) & new_mask)) {
+        if (!(BIT_ULL(cur_granule) & new_mask)) {
             error_setg(errp, "virtio-iommu %s does not support frozen granule 0x%llx",
                        mr->parent_obj.name, BIT_ULL(cur_granule));
             return -1;
@@ -1163,7 +1165,7 @@ static void virtio_iommu_freeze_granule(Notifier *notifier, void *data)
     }
     s->granule_frozen = true;
     granule = ctz64(s->config.page_size_mask);
-    trace_virtio_iommu_freeze_granule(BIT(granule));
+    trace_virtio_iommu_freeze_granule(BIT_ULL(granule));
 }
 
 static void virtio_iommu_device_realize(DeviceState *dev, Error **errp)
-- 
MST



  parent reply	other threads:[~2023-08-03 22:22 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-03 22:20 [PULL 00/22] pc,pci,virtio,crypto: bugfixes Michael S. Tsirkin
2023-08-03 22:20 ` [PULL 01/22] hw/virtio-iommu: Fix potential OOB access in virtio_iommu_handle_command() Michael S. Tsirkin
2023-08-03 22:20 ` [PULL 02/22] hw/pci-bridge/cxl_upstream.c: Use g_new0() in build_cdat_table() Michael S. Tsirkin
2023-08-03 22:20 ` Michael S. Tsirkin [this message]
2023-08-03 22:20 ` [PULL 04/22] hw/virtio: Add a protection against duplicate vu_scmi_stop calls Michael S. Tsirkin
2023-08-03 22:20 ` [PULL 05/22] tests: acpi: x86: whitelist expected blobs Michael S. Tsirkin
2023-08-03 22:21 ` [PULL 06/22] x86: acpi: workaround Windows not handling name references in Package properly Michael S. Tsirkin
2023-08-03 22:21 ` [PULL 07/22] tests: acpi: x86: update expected blobs Michael S. Tsirkin
2023-08-03 22:21 ` [PULL 08/22] tests: acpi: whitelist " Michael S. Tsirkin
2023-08-03 22:21 ` [PULL 09/22] acpi: x86: remove _ADR on host bridges Michael S. Tsirkin
2023-08-03 22:21 ` [PULL 10/22] tests: acpi: update expected blobs Michael S. Tsirkin
2023-08-03 22:21 ` [PULL 11/22] hw/virtio: qmp: add RING_RESET to 'info virtio-status' Michael S. Tsirkin
2023-08-03 22:21 ` [PULL 12/22] virtio: Fix packed virtqueue used_idx mask Michael S. Tsirkin
2023-08-03 22:21 ` [PULL 13/22] pci: do not respond config requests after PCI device eject Michael S. Tsirkin
2023-08-04  4:37   ` Michael Tokarev
2023-08-03 22:21 ` [PULL 14/22] vhost: fix the fd leak Michael S. Tsirkin
2023-08-04  4:36   ` Michael Tokarev
2023-08-04  4:56     ` Michael Tokarev
2023-08-03 22:21 ` [PULL 15/22] hw/i386/intel_iommu: Fix trivial endianness problems Michael S. Tsirkin
2023-08-03 22:21 ` [PULL 16/22] hw/i386/intel_iommu: Fix endianness problems related to VTD_IR_TableEntry Michael S. Tsirkin
2023-08-03 22:21 ` [PULL 17/22] hw/i386/intel_iommu: Fix struct VTDInvDescIEC on big endian hosts Michael S. Tsirkin
2023-08-03 22:21 ` [PULL 18/22] hw/i386/intel_iommu: Fix index calculation in vtd_interrupt_remap_msi() Michael S. Tsirkin
2023-08-03 22:21 ` [PULL 19/22] hw/i386/x86-iommu: Fix endianness issue in x86_iommu_irq_to_msi_message() Michael S. Tsirkin
2023-08-03 22:21 ` [PULL 20/22] include/hw/i386/x86-iommu: Fix struct X86IOMMU_MSIMessage for big endian hosts Michael S. Tsirkin
2023-08-03 22:21 ` [PULL 21/22] virtio-crypto: verify src&dst buffer length for sym request Michael S. Tsirkin
2023-08-03 22:21 ` [PULL 22/22] cryptodev: Handle unexpected request to avoid crash Michael S. Tsirkin
2023-08-04  4:35   ` Michael Tokarev
2023-08-04  6:10     ` zhenwei pi
2023-08-04  6:35       ` Michael Tokarev
2023-08-04  4:12 ` [PULL 00/22] pc,pci,virtio,crypto: bugfixes Richard Henderson

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=1084feddc6a677cdfdde56936bfb97cf32cc4dee.1691101215.git.mst@redhat.com \
    --to=mst@redhat.com \
    --cc=eric.auger@redhat.com \
    --cc=jean-philippe@linaro.org \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).