thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone
ae23c9
From c856dbfb24dcca457dfe8daadfe5a657f60e79f7 Mon Sep 17 00:00:00 2001
ae23c9
From: Peter Xu <peterx@redhat.com>
ae23c9
Date: Fri, 12 Oct 2018 07:58:44 +0100
ae23c9
Subject: [PATCH 14/17] intel-iommu: trace domain id during page walk
ae23c9
ae23c9
RH-Author: Peter Xu <peterx@redhat.com>
ae23c9
Message-id: <20181012075846.25449-8-peterx@redhat.com>
ae23c9
Patchwork-id: 82680
ae23c9
O-Subject: [RHEL-8 qemu-kvm PATCH 7/9] intel-iommu: trace domain id during page walk
ae23c9
Bugzilla: 1450712
ae23c9
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
ae23c9
RH-Acked-by: Xiao Wang <jasowang@redhat.com>
ae23c9
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
ae23c9
ae23c9
This patch only modifies the trace points.
ae23c9
ae23c9
Previously we were tracing page walk levels.  They are redundant since
ae23c9
we have page mask (size) already.  Now we trace something much more
ae23c9
useful which is the domain ID of the page walking.  That can be very
ae23c9
useful when we trace more than one devices on the same system, so that
ae23c9
we can know which map is for which domain.
ae23c9
ae23c9
CC: QEMU Stable <qemu-stable@nongnu.org>
ae23c9
Signed-off-by: Peter Xu <peterx@redhat.com>
ae23c9
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
ae23c9
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
ae23c9
(cherry picked from commit d118c06ebbee2d23ddf873cae4a809311aa61310)
ae23c9
Signed-off-by: Peter Xu <peterx@redhat.com>
ae23c9
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
ae23c9
---
ae23c9
 hw/i386/intel_iommu.c | 16 ++++++++++------
ae23c9
 hw/i386/trace-events  |  2 +-
ae23c9
 2 files changed, 11 insertions(+), 7 deletions(-)
ae23c9
ae23c9
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
ae23c9
index a882894..61bb3d3 100644
ae23c9
--- a/hw/i386/intel_iommu.c
ae23c9
+++ b/hw/i386/intel_iommu.c
ae23c9
@@ -756,6 +756,7 @@ typedef int (*vtd_page_walk_hook)(IOMMUTLBEntry *entry, void *private);
ae23c9
  * @notify_unmap: whether we should notify invalid entries
ae23c9
  * @as: VT-d address space of the device
ae23c9
  * @aw: maximum address width
ae23c9
+ * @domain: domain ID of the page walk
ae23c9
  */
ae23c9
 typedef struct {
ae23c9
     VTDAddressSpace *as;
ae23c9
@@ -763,17 +764,18 @@ typedef struct {
ae23c9
     void *private;
ae23c9
     bool notify_unmap;
ae23c9
     uint8_t aw;
ae23c9
+    uint16_t domain_id;
ae23c9
 } vtd_page_walk_info;
ae23c9
 
ae23c9
-static int vtd_page_walk_one(IOMMUTLBEntry *entry, int level,
ae23c9
-                             vtd_page_walk_info *info)
ae23c9
+static int vtd_page_walk_one(IOMMUTLBEntry *entry, vtd_page_walk_info *info)
ae23c9
 {
ae23c9
     vtd_page_walk_hook hook_fn = info->hook_fn;
ae23c9
     void *private = info->private;
ae23c9
 
ae23c9
     assert(hook_fn);
ae23c9
-    trace_vtd_page_walk_one(level, entry->iova, entry->translated_addr,
ae23c9
-                            entry->addr_mask, entry->perm);
ae23c9
+    trace_vtd_page_walk_one(info->domain_id, entry->iova,
ae23c9
+                            entry->translated_addr, entry->addr_mask,
ae23c9
+                            entry->perm);
ae23c9
     return hook_fn(entry, private);
ae23c9
 }
ae23c9
 
ae23c9
@@ -844,7 +846,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start,
ae23c9
                 trace_vtd_page_walk_skip_perm(iova, iova_next);
ae23c9
                 goto next;
ae23c9
             }
ae23c9
-            ret = vtd_page_walk_one(&entry, level, info);
ae23c9
+            ret = vtd_page_walk_one(&entry, info);
ae23c9
             if (ret < 0) {
ae23c9
                 return ret;
ae23c9
             }
ae23c9
@@ -856,7 +858,7 @@ static int vtd_page_walk_level(dma_addr_t addr, uint64_t start,
ae23c9
                      * Translated address is meaningless, zero it.
ae23c9
                      */
ae23c9
                     entry.translated_addr = 0x0;
ae23c9
-                    ret = vtd_page_walk_one(&entry, level, info);
ae23c9
+                    ret = vtd_page_walk_one(&entry, info);
ae23c9
                     if (ret < 0) {
ae23c9
                         return ret;
ae23c9
                     }
ae23c9
@@ -1466,6 +1468,7 @@ static void vtd_iotlb_page_invalidate_notify(IntelIOMMUState *s,
ae23c9
                     .notify_unmap = true,
ae23c9
                     .aw = s->aw_bits,
ae23c9
                     .as = vtd_as,
ae23c9
+                    .domain_id = domain_id,
ae23c9
                 };
ae23c9
 
ae23c9
                 /*
ae23c9
@@ -2947,6 +2950,7 @@ static void vtd_iommu_replay(IOMMUMemoryRegion *iommu_mr, IOMMUNotifier *n)
ae23c9
                 .notify_unmap = false,
ae23c9
                 .aw = s->aw_bits,
ae23c9
                 .as = vtd_as,
ae23c9
+                .domain_id = VTD_CONTEXT_ENTRY_DID(ce.hi),
ae23c9
             };
ae23c9
 
ae23c9
             vtd_page_walk(&ce, 0, ~0ULL, &info;;
ae23c9
diff --git a/hw/i386/trace-events b/hw/i386/trace-events
ae23c9
index 22d4464..ca23ba9 100644
ae23c9
--- a/hw/i386/trace-events
ae23c9
+++ b/hw/i386/trace-events
ae23c9
@@ -39,7 +39,7 @@ vtd_fault_disabled(void) "Fault processing disabled for context entry"
ae23c9
 vtd_replay_ce_valid(uint8_t bus, uint8_t dev, uint8_t fn, uint16_t domain, uint64_t hi, uint64_t lo) "replay valid context device %02"PRIx8":%02"PRIx8".%02"PRIx8" domain 0x%"PRIx16" hi 0x%"PRIx64" lo 0x%"PRIx64
ae23c9
 vtd_replay_ce_invalid(uint8_t bus, uint8_t dev, uint8_t fn) "replay invalid context device %02"PRIx8":%02"PRIx8".%02"PRIx8
ae23c9
 vtd_page_walk_level(uint64_t addr, uint32_t level, uint64_t start, uint64_t end) "walk (base=0x%"PRIx64", level=%"PRIu32") iova range 0x%"PRIx64" - 0x%"PRIx64
ae23c9
-vtd_page_walk_one(uint32_t level, uint64_t iova, uint64_t gpa, uint64_t mask, int perm) "detected page level 0x%"PRIx32" iova 0x%"PRIx64" -> gpa 0x%"PRIx64" mask 0x%"PRIx64" perm %d"
ae23c9
+vtd_page_walk_one(uint16_t domain, uint64_t iova, uint64_t gpa, uint64_t mask, int perm) "domain 0x%"PRIu16" iova 0x%"PRIx64" -> gpa 0x%"PRIx64" mask 0x%"PRIx64" perm %d"
ae23c9
 vtd_page_walk_skip_read(uint64_t iova, uint64_t next) "Page walk skip iova 0x%"PRIx64" - 0x%"PRIx64" due to unable to read"
ae23c9
 vtd_page_walk_skip_perm(uint64_t iova, uint64_t next) "Page walk skip iova 0x%"PRIx64" - 0x%"PRIx64" due to perm empty"
ae23c9
 vtd_page_walk_skip_reserve(uint64_t iova, uint64_t next) "Page walk skip iova 0x%"PRIx64" - 0x%"PRIx64" due to rsrv set"
ae23c9
-- 
ae23c9
1.8.3.1
ae23c9