Re: [PATCH] iommu/vt-d: Ratelimit fault handler

From: Joe Perches
Date: Tue Mar 15 2016 - 13:11:08 EST


On Tue, 2016-03-15 at 10:35 -0600, Alex Williamson wrote:
> Fault rates can easily overwhelm the console and make the system
> unresponsive.  Ratelimit to allow an opportunity for maintenance.

A few suggestions:

o Use a single ratelimit state.
o The multiple lines output are unnecessary and hard to grep
  in the dmesg output because of inconsistent prefixing as
  second and subsequent output lines are not prefixed by pr_fmt.
o The DMAR prefix on the second block is also unnecessary as
  it's already prefixed by pr_fmt
o Coalesce the formats for easier grep.

so maybe:
---
 drivers/iommu/dmar.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
index 8ffd756..59dcaaa 100644
--- a/drivers/iommu/dmar.c
+++ b/drivers/iommu/dmar.c
@@ -1575,23 +1575,27 @@ static int dmar_fault_do_one(struct intel_iommu *iommu, int type,
 {
  const char *reason;
  int fault_type;
+ static DEFINE_RATELIMIT_STATE(rs,
+       DEFAULT_RATELIMIT_INTERVAL,
+       DEFAULT_RATELIMIT_BURST);
+
+ if (__ratelimit(&rs))
+ return 0;
 
  reason = dmar_get_fault_reason(fault_reason, &fault_type);
 
  if (fault_type == INTR_REMAP)
- pr_err("INTR-REMAP: Request device [[%02x:%02x.%d] "
-        "fault index %llx\n"
- "INTR-REMAP:[fault reason %02d] %s\n",
- (source_id >> 8), PCI_SLOT(source_id & 0xFF),
- PCI_FUNC(source_id & 0xFF), addr >> 48,
- fault_reason, reason);
+ pr_err("[INTR-REMAP] Request device [%02x:%02x.%d] fault index %llx [fault reason %02d] %s\n",
+        source_id >> 8, PCI_SLOT(source_id & 0xFF),
+        PCI_FUNC(source_id & 0xFF), addr >> 48,
+        fault_reason, reason);
  else
- pr_err("DMAR:[%s] Request device [%02x:%02x.%d] "
-        "fault addr %llx \n"
-        "DMAR:[fault reason %02d] %s\n",
-        (type ? "DMA Read" : "DMA Write"),
-        (source_id >> 8), PCI_SLOT(source_id & 0xFF),
-        PCI_FUNC(source_id & 0xFF), addr, fault_reason, reason);
+ pr_err("[%s] Request device [%02x:%02x.%d] fault addr %llx [fault reason %02d] %s\n",
+        type ? "DMA Read" : "DMA Write",
+        source_id >> 8, PCI_SLOT(source_id & 0xFF),
+        PCI_FUNC(source_id & 0xFF), addr,
+        fault_reason, reason);
+
  return 0;
 }