yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-intel-iommu-start-to-use-error_report_once.patch

26ba25
From df15f85e59fe41c2663242feb7b5213047a9f456 Mon Sep 17 00:00:00 2001
26ba25
From: Peter Xu <peterx@redhat.com>
26ba25
Date: Thu, 8 Nov 2018 06:29:33 +0000
26ba25
Subject: [PATCH 05/35] intel-iommu: start to use error_report_once
26ba25
MIME-Version: 1.0
26ba25
Content-Type: text/plain; charset=UTF-8
26ba25
Content-Transfer-Encoding: 8bit
26ba25
26ba25
RH-Author: Peter Xu <peterx@redhat.com>
26ba25
Message-id: <20181108062938.21143-3-peterx@redhat.com>
26ba25
Patchwork-id: 82961
26ba25
O-Subject: [RHEL-8 qemu-kvm PATCH 2/7] intel-iommu: start to use error_report_once
26ba25
Bugzilla: 1625173
26ba25
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
26ba25
RH-Acked-by: Michael S. Tsirkin <mst@redhat.com>
26ba25
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
26ba25
RH-Acked-by: Laurent Vivier <lvivier@redhat.com>
26ba25
26ba25
Bugzilla: 1625173
26ba25
26ba25
Replace existing trace_vtd_err() with error_report_once() then stderr
26ba25
will capture something if any of the error happens, meanwhile we don't
26ba25
suffer from any DDOS.  Then remove the trace point.  Since at it,
26ba25
provide more information where proper (now we can pass parameters into
26ba25
the report function).
26ba25
26ba25
Signed-off-by: Peter Xu <peterx@redhat.com>
26ba25
Message-Id: <20180815095328.32414-3-peterx@redhat.com>
26ba25
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
26ba25
[Two format strings fixed, whitespace tidied up]
26ba25
Signed-off-by: Markus Armbruster <armbru@redhat.com>
26ba25
(cherry picked from commit 1376211f77bdcd84dc4acb877690f7399d8cf58a)
26ba25
Signed-off-by: Peter Xu <peterx@redhat.com>
26ba25
26ba25
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
26ba25
---
26ba25
 hw/i386/intel_iommu.c | 65 +++++++++++++++++++++++++++++----------------------
26ba25
 hw/i386/trace-events  |  1 -
26ba25
 2 files changed, 37 insertions(+), 29 deletions(-)
26ba25
26ba25
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
26ba25
index b5a09b7..ab11cc4 100644
26ba25
--- a/hw/i386/intel_iommu.c
26ba25
+++ b/hw/i386/intel_iommu.c
26ba25
@@ -311,14 +311,14 @@ static void vtd_generate_fault_event(IntelIOMMUState *s, uint32_t pre_fsts)
26ba25
 {
26ba25
     if (pre_fsts & VTD_FSTS_PPF || pre_fsts & VTD_FSTS_PFO ||
26ba25
         pre_fsts & VTD_FSTS_IQE) {
26ba25
-        trace_vtd_err("There are previous interrupt conditions "
26ba25
-                      "to be serviced by software, fault event "
26ba25
-                      "is not generated.");
26ba25
+        error_report_once("There are previous interrupt conditions "
26ba25
+                          "to be serviced by software, fault event "
26ba25
+                          "is not generated");
26ba25
         return;
26ba25
     }
26ba25
     vtd_set_clear_mask_long(s, DMAR_FECTL_REG, 0, VTD_FECTL_IP);
26ba25
     if (vtd_get_long_raw(s, DMAR_FECTL_REG) & VTD_FECTL_IM) {
26ba25
-        trace_vtd_err("Interrupt Mask set, irq is not generated.");
26ba25
+        error_report_once("Interrupt Mask set, irq is not generated");
26ba25
     } else {
26ba25
         vtd_generate_interrupt(s, DMAR_FEADDR_REG, DMAR_FEDATA_REG);
26ba25
         vtd_set_clear_mask_long(s, DMAR_FECTL_REG, VTD_FECTL_IP, 0);
26ba25
@@ -426,20 +426,20 @@ static void vtd_report_dmar_fault(IntelIOMMUState *s, uint16_t source_id,
26ba25
     trace_vtd_dmar_fault(source_id, fault, addr, is_write);
26ba25
 
26ba25
     if (fsts_reg & VTD_FSTS_PFO) {
26ba25
-        trace_vtd_err("New fault is not recorded due to "
26ba25
-                      "Primary Fault Overflow.");
26ba25
+        error_report_once("New fault is not recorded due to "
26ba25
+                          "Primary Fault Overflow");
26ba25
         return;
26ba25
     }
26ba25
 
26ba25
     if (vtd_try_collapse_fault(s, source_id)) {
26ba25
-        trace_vtd_err("New fault is not recorded due to "
26ba25
-                      "compression of faults.");
26ba25
+        error_report_once("New fault is not recorded due to "
26ba25
+                          "compression of faults");
26ba25
         return;
26ba25
     }
26ba25
 
26ba25
     if (vtd_is_frcd_set(s, s->next_frcd_reg)) {
26ba25
-        trace_vtd_err("Next Fault Recording Reg is used, "
26ba25
-                      "new fault is not recorded, set PFO field.");
26ba25
+        error_report_once("Next Fault Recording Reg is used, "
26ba25
+                          "new fault is not recorded, set PFO field");
26ba25
         vtd_set_clear_mask_long(s, DMAR_FSTS_REG, 0, VTD_FSTS_PFO);
26ba25
         return;
26ba25
     }
26ba25
@@ -447,8 +447,8 @@ static void vtd_report_dmar_fault(IntelIOMMUState *s, uint16_t source_id,
26ba25
     vtd_record_frcd(s, s->next_frcd_reg, source_id, addr, fault, is_write);
26ba25
 
26ba25
     if (fsts_reg & VTD_FSTS_PPF) {
26ba25
-        trace_vtd_err("There are pending faults already, "
26ba25
-                      "fault event is not generated.");
26ba25
+        error_report_once("There are pending faults already, "
26ba25
+                          "fault event is not generated");
26ba25
         vtd_set_frcd_and_update_ppf(s, s->next_frcd_reg);
26ba25
         s->next_frcd_reg++;
26ba25
         if (s->next_frcd_reg == DMAR_FRCD_REG_NR) {
26ba25
@@ -1056,8 +1056,10 @@ static int vtd_sync_shadow_page_table_range(VTDAddressSpace *vtd_as,
26ba25
              * we just skip the sync for this time.  After all we even
26ba25
              * don't have the root table pointer!
26ba25
              */
26ba25
-            trace_vtd_err("Detected invalid context entry when "
26ba25
-                          "trying to sync shadow page table");
26ba25
+            error_report_once("%s: invalid context entry for bus 0x%x"
26ba25
+                              " devfn 0x%x",
26ba25
+                              __func__, pci_bus_num(vtd_as->bus),
26ba25
+                              vtd_as->devfn);
26ba25
             return 0;
26ba25
         }
26ba25
     }
26ba25
@@ -1514,7 +1516,8 @@ static uint64_t vtd_context_cache_invalidate(IntelIOMMUState *s, uint64_t val)
26ba25
         break;
26ba25
 
26ba25
     default:
26ba25
-        trace_vtd_err("Context cache invalidate type error.");
26ba25
+        error_report_once("%s: invalid context: 0x%" PRIx64,
26ba25
+                          __func__, val);
26ba25
         caig = 0;
26ba25
     }
26ba25
     return caig;
26ba25
@@ -1634,7 +1637,8 @@ static uint64_t vtd_iotlb_flush(IntelIOMMUState *s, uint64_t val)
26ba25
         am = VTD_IVA_AM(addr);
26ba25
         addr = VTD_IVA_ADDR(addr);
26ba25
         if (am > VTD_MAMV) {
26ba25
-            trace_vtd_err("IOTLB PSI flush: address mask overflow.");
26ba25
+            error_report_once("%s: address mask overflow: 0x%" PRIx64,
26ba25
+                              __func__, vtd_get_quad_raw(s, DMAR_IVA_REG));
26ba25
             iaig = 0;
26ba25
             break;
26ba25
         }
26ba25
@@ -1643,7 +1647,8 @@ static uint64_t vtd_iotlb_flush(IntelIOMMUState *s, uint64_t val)
26ba25
         break;
26ba25
 
26ba25
     default:
26ba25
-        trace_vtd_err("IOTLB flush: invalid granularity.");
26ba25
+        error_report_once("%s: invalid granularity: 0x%" PRIx64,
26ba25
+                          __func__, val);
26ba25
         iaig = 0;
26ba25
     }
26ba25
     return iaig;
26ba25
@@ -1793,8 +1798,8 @@ static void vtd_handle_ccmd_write(IntelIOMMUState *s)
26ba25
     /* Context-cache invalidation request */
26ba25
     if (val & VTD_CCMD_ICC) {
26ba25
         if (s->qi_enabled) {
26ba25
-            trace_vtd_err("Queued Invalidation enabled, "
26ba25
-                          "should not use register-based invalidation");
26ba25
+            error_report_once("Queued Invalidation enabled, "
26ba25
+                              "should not use register-based invalidation");
26ba25
             return;
26ba25
         }
26ba25
         ret = vtd_context_cache_invalidate(s, val);
26ba25
@@ -1814,8 +1819,8 @@ static void vtd_handle_iotlb_write(IntelIOMMUState *s)
26ba25
     /* IOTLB invalidation request */
26ba25
     if (val & VTD_TLB_IVT) {
26ba25
         if (s->qi_enabled) {
26ba25
-            trace_vtd_err("Queued Invalidation enabled, "
26ba25
-                          "should not use register-based invalidation.");
26ba25
+            error_report_once("Queued Invalidation enabled, "
26ba25
+                              "should not use register-based invalidation");
26ba25
             return;
26ba25
         }
26ba25
         ret = vtd_iotlb_flush(s, val);
26ba25
@@ -1833,7 +1838,7 @@ static bool vtd_get_inv_desc(dma_addr_t base_addr, uint32_t offset,
26ba25
     dma_addr_t addr = base_addr + offset * sizeof(*inv_desc);
26ba25
     if (dma_memory_read(&address_space_memory, addr, inv_desc,
26ba25
         sizeof(*inv_desc))) {
26ba25
-        trace_vtd_err("Read INV DESC failed.");
26ba25
+        error_report_once("Read INV DESC failed");
26ba25
         inv_desc->lo = 0;
26ba25
         inv_desc->hi = 0;
26ba25
         return false;
26ba25
@@ -2188,7 +2193,8 @@ static uint64_t vtd_mem_read(void *opaque, hwaddr addr, unsigned size)
26ba25
     trace_vtd_reg_read(addr, size);
26ba25
 
26ba25
     if (addr + size > DMAR_REG_SIZE) {
26ba25
-        trace_vtd_err("Read MMIO over range.");
26ba25
+        error_report_once("%s: MMIO over range: addr=0x%" PRIx64
26ba25
+                          " size=0x%u", __func__, addr, size);
26ba25
         return (uint64_t)-1;
26ba25
     }
26ba25
 
26ba25
@@ -2239,7 +2245,8 @@ static void vtd_mem_write(void *opaque, hwaddr addr,
26ba25
     trace_vtd_reg_write(addr, size, val);
26ba25
 
26ba25
     if (addr + size > DMAR_REG_SIZE) {
26ba25
-        trace_vtd_err("Write MMIO over range.");
26ba25
+        error_report_once("%s: MMIO over range: addr=0x%" PRIx64
26ba25
+                          " size=0x%u", __func__, addr, size);
26ba25
         return;
26ba25
     }
26ba25
 
26ba25
@@ -2610,7 +2617,8 @@ static int vtd_irte_get(IntelIOMMUState *iommu, uint16_t index,
26ba25
     addr = iommu->intr_root + index * sizeof(*entry);
26ba25
     if (dma_memory_read(&address_space_memory, addr, entry,
26ba25
                         sizeof(*entry))) {
26ba25
-        trace_vtd_err("Memory read failed for IRTE.");
26ba25
+        error_report_once("%s: read failed: ind=0x%x addr=0x%" PRIx64,
26ba25
+                          __func__, index, addr);
26ba25
         return -VTD_FR_IR_ROOT_INVAL;
26ba25
     }
26ba25
 
26ba25
@@ -2742,14 +2750,15 @@ static int vtd_interrupt_remap_msi(IntelIOMMUState *iommu,
26ba25
     }
26ba25
 
26ba25
     if (origin->address & VTD_MSI_ADDR_HI_MASK) {
26ba25
-        trace_vtd_err("MSI address high 32 bits non-zero when "
26ba25
-                      "Interrupt Remapping enabled.");
26ba25
+        error_report_once("%s: MSI address high 32 bits non-zero detected: "
26ba25
+                          "address=0x%" PRIx64, __func__, origin->address);
26ba25
         return -VTD_FR_IR_REQ_RSVD;
26ba25
     }
26ba25
 
26ba25
     addr.data = origin->address & VTD_MSI_ADDR_LO_MASK;
26ba25
     if (addr.addr.__head != 0xfee) {
26ba25
-        trace_vtd_err("MSI addr low 32 bit invalid.");
26ba25
+        error_report_once("%s: MSI address low 32 bit invalid: 0x%" PRIx32,
26ba25
+                          __func__, addr.data);
26ba25
         return -VTD_FR_IR_REQ_RSVD;
26ba25
     }
26ba25
 
26ba25
diff --git a/hw/i386/trace-events b/hw/i386/trace-events
26ba25
index e14d06e..922431b 100644
26ba25
--- a/hw/i386/trace-events
26ba25
+++ b/hw/i386/trace-events
26ba25
@@ -69,7 +69,6 @@ vtd_ir_remap_msi_req(uint64_t addr, uint64_t data) "addr 0x%"PRIx64" data 0x%"PR
26ba25
 vtd_fsts_ppf(bool set) "FSTS PPF bit set to %d"
26ba25
 vtd_fsts_clear_ip(void) ""
26ba25
 vtd_frr_new(int index, uint64_t hi, uint64_t lo) "index %d high 0x%"PRIx64" low 0x%"PRIx64
26ba25
-vtd_err(const char *str) "%s"
26ba25
 vtd_err_dmar_iova_overflow(uint64_t iova) "iova 0x%"PRIx64
26ba25
 vtd_err_dmar_slpte_read_error(uint64_t iova, int level) "iova 0x%"PRIx64" level %d"
26ba25
 vtd_err_dmar_slpte_perm_error(uint64_t iova, int level, uint64_t slpte, bool is_write) "iova 0x%"PRIx64" level %d slpte 0x%"PRIx64" write %d"
26ba25
-- 
26ba25
1.8.3.1
26ba25