Blame SOURCES/kvm-vfio-common-remove-spurious-tpm-crb-cmd-misalignment.patch

29b115
From b90a5878355bd549200ed1eff52ea084325bfc8a Mon Sep 17 00:00:00 2001
29b115
From: Eric Auger <eric.auger@redhat.com>
29b115
Date: Fri, 6 May 2022 15:25:10 +0200
29b115
Subject: [PATCH 5/5] vfio/common: remove spurious tpm-crb-cmd misalignment
29b115
 warning
29b115
MIME-Version: 1.0
29b115
Content-Type: text/plain; charset=UTF-8
29b115
Content-Transfer-Encoding: 8bit
29b115
29b115
RH-Author: Eric Auger <eric.auger@redhat.com>
29b115
RH-MergeRequest: 84: vfio/common: Remove spurious tpm-crb-cmd misalignment warning
29b115
RH-Commit: [2/2] 9b73a9aec59cb50d5e3468cc553464bf4a73d0a1 (eauger1/centos-qemu-kvm)
29b115
RH-Bugzilla: 2037612
29b115
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
29b115
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
29b115
RH-Acked-by: Andrew Jones <drjones@redhat.com>
29b115
29b115
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2037612
29b115
Brew: https://brewweb.engineering.redhat.com/brew/taskinfo?taskID=45166961
29b115
Upstream Status: YES
29b115
Tested: With TPM-CRB and VFIO
29b115
29b115
The CRB command buffer currently is a RAM MemoryRegion and given
29b115
its base address alignment, it causes an error report on
29b115
vfio_listener_region_add(). This region could have been a RAM device
29b115
region, easing the detection of such safe situation but this option
29b115
was not well received. So let's add a helper function that uses the
29b115
memory region owner type to detect the situation is safe wrt
29b115
the assignment. Other device types can be checked here if such kind
29b115
of problem occurs again.
29b115
29b115
Conflicts in hw/vfio/common.c
29b115
We don't have 8e3b0cbb721 ("Replace qemu_real_host_page variables with inlined functions")
29b115
29b115
Signed-off-by: Eric Auger <eric.auger@redhat.com>
29b115
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
29b115
Acked-by: Stefan Berger <stefanb@linux.ibm.com>
29b115
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
29b115
Link: https://lore.kernel.org/r/20220506132510.1847942-3-eric.auger@redhat.com
29b115
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
29b115
(cherry picked from commit 851d6d1a0ff29a87ec588205842edf6b86d99b5c)
29b115
Signed-off-by: Eric Auger <eric.auger@redhat.com>
29b115
---
29b115
 hw/vfio/common.c     | 27 ++++++++++++++++++++++++++-
29b115
 hw/vfio/trace-events |  1 +
29b115
 2 files changed, 27 insertions(+), 1 deletion(-)
29b115
29b115
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
29b115
index 080046e3f5..0fbe0d47af 100644
29b115
--- a/hw/vfio/common.c
29b115
+++ b/hw/vfio/common.c
29b115
@@ -40,6 +40,7 @@
29b115
 #include "trace.h"
29b115
 #include "qapi/error.h"
29b115
 #include "migration/migration.h"
29b115
+#include "sysemu/tpm.h"
29b115
 
29b115
 VFIOGroupList vfio_group_list =
29b115
     QLIST_HEAD_INITIALIZER(vfio_group_list);
29b115
@@ -861,6 +862,22 @@ static void vfio_unregister_ram_discard_listener(VFIOContainer *container,
29b115
     g_free(vrdl);
29b115
 }
29b115
 
29b115
+static bool vfio_known_safe_misalignment(MemoryRegionSection *section)
29b115
+{
29b115
+    MemoryRegion *mr = section->mr;
29b115
+
29b115
+    if (!TPM_IS_CRB(mr->owner)) {
29b115
+        return false;
29b115
+    }
29b115
+
29b115
+    /* this is a known safe misaligned region, just trace for debug purpose */
29b115
+    trace_vfio_known_safe_misalignment(memory_region_name(mr),
29b115
+                                       section->offset_within_address_space,
29b115
+                                       section->offset_within_region,
29b115
+                                       qemu_real_host_page_size);
29b115
+    return true;
29b115
+}
29b115
+
29b115
 static void vfio_listener_region_add(MemoryListener *listener,
29b115
                                      MemoryRegionSection *section)
29b115
 {
29b115
@@ -884,7 +901,15 @@ static void vfio_listener_region_add(MemoryListener *listener,
29b115
     if (unlikely((section->offset_within_address_space &
29b115
                   ~qemu_real_host_page_mask) !=
29b115
                  (section->offset_within_region & ~qemu_real_host_page_mask))) {
29b115
-        error_report("%s received unaligned region", __func__);
29b115
+        if (!vfio_known_safe_misalignment(section)) {
29b115
+            error_report("%s received unaligned region %s iova=0x%"PRIx64
29b115
+                         " offset_within_region=0x%"PRIx64
29b115
+                         " qemu_real_host_page_size=0x%"PRIxPTR,
29b115
+                         __func__, memory_region_name(section->mr),
29b115
+                         section->offset_within_address_space,
29b115
+                         section->offset_within_region,
29b115
+                         qemu_real_host_page_size);
29b115
+        }
29b115
         return;
29b115
     }
29b115
 
29b115
diff --git a/hw/vfio/trace-events b/hw/vfio/trace-events
29b115
index 0ef1b5f4a6..582882db91 100644
29b115
--- a/hw/vfio/trace-events
29b115
+++ b/hw/vfio/trace-events
29b115
@@ -100,6 +100,7 @@ vfio_listener_region_add_skip(uint64_t start, uint64_t end) "SKIPPING region_add
29b115
 vfio_spapr_group_attach(int groupfd, int tablefd) "Attached groupfd %d to liobn fd %d"
29b115
 vfio_listener_region_add_iommu(uint64_t start, uint64_t end) "region_add [iommu] 0x%"PRIx64" - 0x%"PRIx64
29b115
 vfio_listener_region_add_ram(uint64_t iova_start, uint64_t iova_end, void *vaddr) "region_add [ram] 0x%"PRIx64" - 0x%"PRIx64" [%p]"
29b115
+vfio_known_safe_misalignment(const char *name, uint64_t iova, uint64_t offset_within_region, uintptr_t page_size) "Region \"%s\" iova=0x%"PRIx64" offset_within_region=0x%"PRIx64" qemu_real_host_page_size=0x%"PRIxPTR ": cannot be mapped for DMA"
29b115
 vfio_listener_region_add_no_dma_map(const char *name, uint64_t iova, uint64_t size, uint64_t page_size) "Region \"%s\" 0x%"PRIx64" size=0x%"PRIx64" is not aligned to 0x%"PRIx64" and cannot be mapped for DMA"
29b115
 vfio_listener_region_del_skip(uint64_t start, uint64_t end) "SKIPPING region_del 0x%"PRIx64" - 0x%"PRIx64
29b115
 vfio_listener_region_del(uint64_t start, uint64_t end) "region_del 0x%"PRIx64" - 0x%"PRIx64
29b115
-- 
29b115
2.31.1
29b115