All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Peter Maydell <peter.maydell@linaro.org>,
	Peter Xu <peterx@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>,
	Richard Henderson <rth@twiddle.net>,
	Eduardo Habkost <ehabkost@redhat.com>
Subject: [Qemu-devel] [PULL 25/55] x86-iommu: introduce IEC notifiers
Date: Tue, 19 Jul 2016 01:45:15 +0300	[thread overview]
Message-ID: <20160719014515-mutt-send-email-mst@redhat.com> (raw)
In-Reply-To: <1468881010-27229-1-git-send-email-mst@redhat.com>

From: Peter Xu <peterx@redhat.com>

This patch introduces x86 IOMMU IEC (Interrupt Entry Cache)
invalidation notifier list. When vIOMMU receives IEC invalidate
request, all the registered units will be notified with specific
invalidation requests.

Intel IOMMU is the first provider that generates such a event.

Signed-off-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
 hw/i386/intel_iommu_internal.h | 24 ++++++++++++++++++++----
 include/hw/i386/x86-iommu.h    | 40 ++++++++++++++++++++++++++++++++++++++++
 hw/i386/intel_iommu.c          | 36 +++++++++++++++++++++++++++++-------
 hw/i386/x86-iommu.c            | 29 +++++++++++++++++++++++++++++
 hw/i386/trace-events           |  3 +++
 5 files changed, 121 insertions(+), 11 deletions(-)

diff --git a/hw/i386/intel_iommu_internal.h b/hw/i386/intel_iommu_internal.h
index e1a08cb..10c20fe 100644
--- a/hw/i386/intel_iommu_internal.h
+++ b/hw/i386/intel_iommu_internal.h
@@ -296,12 +296,28 @@ typedef enum VTDFaultReason {
 
 #define VTD_CONTEXT_CACHE_GEN_MAX       0xffffffffUL
 
+/* Interrupt Entry Cache Invalidation Descriptor: VT-d 6.5.2.7. */
+struct VTDInvDescIEC {
+    uint32_t type:4;            /* Should always be 0x4 */
+    uint32_t granularity:1;     /* If set, it's global IR invalidation */
+    uint32_t resved_1:22;
+    uint32_t index_mask:5;      /* 2^N for continuous int invalidation */
+    uint32_t index:16;          /* Start index to invalidate */
+    uint32_t reserved_2:16;
+};
+typedef struct VTDInvDescIEC VTDInvDescIEC;
+
 /* Queued Invalidation Descriptor */
-struct VTDInvDesc {
-    uint64_t lo;
-    uint64_t hi;
+union VTDInvDesc {
+    struct {
+        uint64_t lo;
+        uint64_t hi;
+    };
+    union {
+        VTDInvDescIEC iec;
+    };
 };
-typedef struct VTDInvDesc VTDInvDesc;
+typedef union VTDInvDesc VTDInvDesc;
 
 /* Masks for struct VTDInvDesc */
 #define VTD_INV_DESC_TYPE               0xf
diff --git a/include/hw/i386/x86-iommu.h b/include/hw/i386/x86-iommu.h
index fa6ce31..c48e8dd 100644
--- a/include/hw/i386/x86-iommu.h
+++ b/include/hw/i386/x86-iommu.h
@@ -46,9 +46,28 @@ struct X86IOMMUClass {
                      MSIMessage *dst, uint16_t sid);
 };
 
+/**
+ * iec_notify_fn - IEC (Interrupt Entry Cache) notifier hook,
+ *                 triggered when IR invalidation happens.
+ * @private: private data
+ * @global: whether this is a global IEC invalidation
+ * @index: IRTE index to invalidate (start from)
+ * @mask: invalidation mask
+ */
+typedef void (*iec_notify_fn)(void *private, bool global,
+                              uint32_t index, uint32_t mask);
+
+struct IEC_Notifier {
+    iec_notify_fn iec_notify;
+    void *private;
+    QLIST_ENTRY(IEC_Notifier) list;
+};
+typedef struct IEC_Notifier IEC_Notifier;
+
 struct X86IOMMUState {
     SysBusDevice busdev;
     bool intr_supported;        /* Whether vIOMMU supports IR */
+    QLIST_HEAD(, IEC_Notifier) iec_notifiers; /* IEC notify list */
 };
 
 /**
@@ -57,4 +76,25 @@ struct X86IOMMUState {
  */
 X86IOMMUState *x86_iommu_get_default(void);
 
+/**
+ * x86_iommu_iec_register_notifier - register IEC (Interrupt Entry
+ *                                   Cache) notifiers
+ * @iommu: IOMMU device to register
+ * @fn: IEC notifier hook function
+ * @data: notifier private data
+ */
+void x86_iommu_iec_register_notifier(X86IOMMUState *iommu,
+                                     iec_notify_fn fn, void *data);
+
+/**
+ * x86_iommu_iec_notify_all - Notify IEC invalidations
+ * @iommu: IOMMU device that sends the notification
+ * @global: whether this is a global invalidation. If true, @index
+ *          and @mask are undefined.
+ * @index: starting index of interrupt entry to invalidate
+ * @mask: index mask for the invalidation
+ */
+void x86_iommu_iec_notify_all(X86IOMMUState *iommu, bool global,
+                              uint32_t index, uint32_t mask);
+
 #endif
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 064d2ab..abd39cb 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -904,6 +904,12 @@ static void vtd_root_table_setup(IntelIOMMUState *s)
                 (s->root_extended ? "(extended)" : ""));
 }
 
+static void vtd_iec_notify_all(IntelIOMMUState *s, bool global,
+                               uint32_t index, uint32_t mask)
+{
+    x86_iommu_iec_notify_all(X86_IOMMU_DEVICE(s), global, index, mask);
+}
+
 static void vtd_interrupt_remap_table_setup(IntelIOMMUState *s)
 {
     uint64_t value = 0;
@@ -911,7 +917,8 @@ static void vtd_interrupt_remap_table_setup(IntelIOMMUState *s)
     s->intr_size = 1UL << ((value & VTD_IRTA_SIZE_MASK) + 1);
     s->intr_root = value & VTD_IRTA_ADDR_MASK;
 
-    /* TODO: invalidate interrupt entry cache */
+    /* Notify global invalidation */
+    vtd_iec_notify_all(s, true, 0, 0);
 
     VTD_DPRINTF(CSR, "int remap table addr 0x%"PRIx64 " size %"PRIu32,
                 s->intr_root, s->intr_size);
@@ -1413,6 +1420,21 @@ static bool vtd_process_iotlb_desc(IntelIOMMUState *s, VTDInvDesc *inv_desc)
     return true;
 }
 
+static bool vtd_process_inv_iec_desc(IntelIOMMUState *s,
+                                     VTDInvDesc *inv_desc)
+{
+    VTD_DPRINTF(INV, "inv ir glob %d index %d mask %d",
+                inv_desc->iec.granularity,
+                inv_desc->iec.index,
+                inv_desc->iec.index_mask);
+
+    vtd_iec_notify_all(s, !inv_desc->iec.granularity,
+                       inv_desc->iec.index,
+                       inv_desc->iec.index_mask);
+
+    return true;
+}
+
 static bool vtd_process_inv_desc(IntelIOMMUState *s)
 {
     VTDInvDesc inv_desc;
@@ -1453,12 +1475,12 @@ static bool vtd_process_inv_desc(IntelIOMMUState *s)
         break;
 
     case VTD_INV_DESC_IEC:
-        VTD_DPRINTF(INV, "Interrupt Entry Cache Invalidation "
-                    "not implemented yet");
-        /*
-         * Since currently we do not cache interrupt entries, we can
-         * just mark this descriptor as "good" and move on.
-         */
+        VTD_DPRINTF(INV, "Invalidation Interrupt Entry Cache "
+                    "Descriptor hi 0x%"PRIx64 " lo 0x%"PRIx64,
+                    inv_desc.hi, inv_desc.lo);
+        if (!vtd_process_inv_iec_desc(s, &inv_desc)) {
+            return false;
+        }
         break;
 
     default:
diff --git a/hw/i386/x86-iommu.c b/hw/i386/x86-iommu.c
index 4280839..ce26b2a 100644
--- a/hw/i386/x86-iommu.c
+++ b/hw/i386/x86-iommu.c
@@ -22,6 +22,33 @@
 #include "hw/boards.h"
 #include "hw/i386/x86-iommu.h"
 #include "qemu/error-report.h"
+#include "trace.h"
+
+void x86_iommu_iec_register_notifier(X86IOMMUState *iommu,
+                                     iec_notify_fn fn, void *data)
+{
+    IEC_Notifier *notifier = g_new0(IEC_Notifier, 1);
+
+    notifier->iec_notify = fn;
+    notifier->private = data;
+
+    QLIST_INSERT_HEAD(&iommu->iec_notifiers, notifier, list);
+}
+
+void x86_iommu_iec_notify_all(X86IOMMUState *iommu, bool global,
+                              uint32_t index, uint32_t mask)
+{
+    IEC_Notifier *notifier;
+
+    trace_x86_iommu_iec_notify(global, index, mask);
+
+    QLIST_FOREACH(notifier, &iommu->iec_notifiers, list) {
+        if (notifier->iec_notify) {
+            notifier->iec_notify(notifier->private, global,
+                                 index, mask);
+        }
+    }
+}
 
 /* Default X86 IOMMU device */
 static X86IOMMUState *x86_iommu_default = NULL;
@@ -46,7 +73,9 @@ X86IOMMUState *x86_iommu_get_default(void)
 
 static void x86_iommu_realize(DeviceState *dev, Error **errp)
 {
+    X86IOMMUState *x86_iommu = X86_IOMMU_DEVICE(dev);
     X86IOMMUClass *x86_class = X86_IOMMU_GET_CLASS(dev);
+    QLIST_INIT(&x86_iommu->iec_notifiers);
     if (x86_class->realize) {
         x86_class->realize(dev, errp);
     }
diff --git a/hw/i386/trace-events b/hw/i386/trace-events
index ea77bc2..b4882c1 100644
--- a/hw/i386/trace-events
+++ b/hw/i386/trace-events
@@ -10,3 +10,6 @@ xen_pv_mmio_write(uint64_t addr) "WARNING: write to Xen PV Device MMIO space (ad
 # hw/i386/pc.c
 mhp_pc_dimm_assigned_slot(int slot) "0x%d"
 mhp_pc_dimm_assigned_address(uint64_t addr) "0x%"PRIx64
+
+# hw/i386/x86-iommu.c
+x86_iommu_iec_notify(bool global, uint32_t index, uint32_t mask) "Notify IEC invalidation: global=%d index=%" PRIu32 " mask=%" PRIu32
-- 
MST

  parent reply	other threads:[~2016-07-18 22:45 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1468881010-27229-1-git-send-email-mst@redhat.com>
2016-07-18 22:42 ` [Qemu-devel] [PULL 01/55] nvdimm: fix memory leak in error code path Michael S. Tsirkin
2016-07-18 22:42 ` [Qemu-devel] [PULL 02/55] tests/prom-env-test: increase the test timeout Michael S. Tsirkin
2016-07-18 22:42 ` [Qemu-devel] [PULL 03/55] hw/alpha: fix PCI bus initialization Michael S. Tsirkin
2016-07-18 22:42 ` [Qemu-devel] [PULL 04/55] hw/mips: " Michael S. Tsirkin
2016-07-18 22:43 ` [Qemu-devel] [PULL 05/55] hw/apb: " Michael S. Tsirkin
2016-07-18 22:43 ` [Qemu-devel] [PULL 06/55] hw/grackle: " Michael S. Tsirkin
2016-07-18 22:43 ` [Qemu-devel] [PULL 07/55] hw/prep: realize the PCI root bus as part of the prep init Michael S. Tsirkin
2016-07-18 22:43 ` [Qemu-devel] [PULL 08/55] hw/versatile: realize the PCI root bus as part of the versatile init Michael S. Tsirkin
2016-07-18 22:43 ` [Qemu-devel] [PULL 09/55] x86-iommu: introduce parent class Michael S. Tsirkin
2016-07-18 22:43 ` [Qemu-devel] [PULL 10/55] intel_iommu: rename VTD_PCI_DEVFN_MAX to x86-iommu Michael S. Tsirkin
2016-07-18 22:43 ` [Qemu-devel] [PULL 11/55] x86-iommu: provide x86_iommu_get_default Michael S. Tsirkin
2016-07-18 22:43 ` [Qemu-devel] [PULL 12/55] x86-iommu: introduce "intremap" property Michael S. Tsirkin
2016-07-18 22:43 ` [Qemu-devel] [PULL 13/55] acpi: enable INTR for DMAR report structure Michael S. Tsirkin
2016-07-18 22:43 ` [Qemu-devel] [PULL 14/55] intel_iommu: allow queued invalidation for IR Michael S. Tsirkin
2016-07-18 22:43 ` [Qemu-devel] [PULL 15/55] intel_iommu: set IR bit for ECAP register Michael S. Tsirkin
2016-07-18 22:44 ` [Qemu-devel] [PULL 16/55] acpi: add DMAR scope definition for root IOAPIC Michael S. Tsirkin
2016-07-18 22:44 ` [Qemu-devel] [PULL 17/55] intel_iommu: define interrupt remap table addr register Michael S. Tsirkin
2016-07-18 22:44 ` [Qemu-devel] [PULL 18/55] intel_iommu: handle interrupt remap enable Michael S. Tsirkin
2016-07-18 22:44 ` [Qemu-devel] [PULL 19/55] intel_iommu: define several structs for IOMMU IR Michael S. Tsirkin
2016-07-18 22:44 ` [Qemu-devel] [PULL 20/55] intel_iommu: add IR translation faults defines Michael S. Tsirkin
2016-07-18 22:44 ` [Qemu-devel] [PULL 21/55] intel_iommu: Add support for PCI MSI remap Michael S. Tsirkin
2016-07-18 22:44 ` [Qemu-devel] [PULL 22/55] q35: ioapic: add support for emulated IOAPIC IR Michael S. Tsirkin
2016-11-11 17:18   ` Emilio G. Cota
2016-11-11 19:50     ` Emilio G. Cota
2016-11-11 23:17     ` Peter Xu
2016-11-12  2:04       ` Emilio G. Cota
2016-11-12 11:01         ` Alex Bennée
2016-07-18 22:44 ` [Qemu-devel] [PULL 23/55] ioapic: introduce ioapic_entry_parse() helper Michael S. Tsirkin
2016-07-18 22:45 ` [PULL 24/55] intel_iommu: add support for split irqchip Michael S. Tsirkin
2016-07-18 22:45   ` [Qemu-devel] " Michael S. Tsirkin
2016-07-18 22:45 ` Michael S. Tsirkin [this message]
2016-07-18 22:45 ` [Qemu-devel] [PULL 26/55] ioapic: register IOMMU IEC notifier for ioapic Michael S. Tsirkin
2016-07-18 22:45 ` [Qemu-devel] [PULL 27/55] intel_iommu: Add support for Extended Interrupt Mode Michael S. Tsirkin
2016-07-18 22:45 ` [Qemu-devel] [PULL 28/55] intel_iommu: add SID validation for IR Michael S. Tsirkin
2016-07-18 22:45 ` [PULL 29/55] kvm-irqchip: simplify kvm_irqchip_add_msi_route Michael S. Tsirkin
2016-07-18 22:45   ` [Qemu-devel] " Michael S. Tsirkin
2016-07-18 22:45 ` [PULL 30/55] kvm-irqchip: i386: add hook for add/remove virq Michael S. Tsirkin
2016-07-18 22:45   ` [Qemu-devel] " Michael S. Tsirkin
2016-07-18 22:45 ` [PULL 31/55] kvm-irqchip: x86: add msi route notify fn Michael S. Tsirkin
2016-07-18 22:45   ` [Qemu-devel] " Michael S. Tsirkin
2016-07-18 22:46 ` [PULL 32/55] kvm-irqchip: do explicit commit when update irq Michael S. Tsirkin
2016-07-18 22:46   ` [Qemu-devel] " Michael S. Tsirkin
2016-07-18 22:46 ` [Qemu-devel] [PULL 33/55] intel_iommu: support all masks in interrupt entry cache invalidation Michael S. Tsirkin
2016-07-18 22:46 ` [PULL 34/55] kvm-all: add trace events for kvm irqchip ops Michael S. Tsirkin
2016-07-18 22:46   ` [Qemu-devel] " Michael S. Tsirkin
2016-07-18 22:46 ` [Qemu-devel] [PULL 35/55] intel_iommu: disallow kernel-irqchip=on with IR Michael S. Tsirkin
2016-07-18 22:46 ` [Qemu-devel] [PULL 36/55] virtio: Add typedef for handle_output Michael S. Tsirkin
2016-07-18 22:46 ` [Qemu-devel] [PULL 37/55] virtio: Introduce virtio_add_queue_aio Michael S. Tsirkin
2016-07-18 22:46 ` [Qemu-devel] [PULL 38/55] virtio-blk: Call virtio_add_queue_aio Michael S. Tsirkin
2016-07-18 22:46 ` [Qemu-devel] [PULL 39/55] virtio-scsi: " Michael S. Tsirkin
2016-07-18 22:46 ` [Qemu-devel] [PULL 40/55] Revert "mirror: Workaround for unexpected iohandler events during completion" Michael S. Tsirkin
2016-07-18 22:47 ` [Qemu-devel] [PULL 41/55] virtio-scsi: Replace HandleOutput typedef Michael S. Tsirkin
2016-07-18 22:47 ` [Qemu-devel] [PULL 42/55] virtio-net: Remove old migration version support Michael S. Tsirkin
2016-07-18 22:47 ` [Qemu-devel] [PULL 43/55] virtio-serial: " Michael S. Tsirkin
2016-07-18 22:47 ` [Qemu-devel] [PULL 44/55] virtio: Migration helper function and macro Michael S. Tsirkin
2016-07-18 22:47 ` [Qemu-devel] [PULL 45/55] virtio-scsi: Wrap in vmstate Michael S. Tsirkin
2016-07-18 22:47 ` [Qemu-devel] [PULL 46/55] virtio-blk: " Michael S. Tsirkin
2016-07-18 22:47 ` [Qemu-devel] [PULL 47/55] virtio-rng: " Michael S. Tsirkin
2016-07-18 22:47 ` [Qemu-devel] [PULL 48/55] virtio-balloon: " Michael S. Tsirkin
2016-07-18 22:47 ` [Qemu-devel] [PULL 49/55] virtio-net: " Michael S. Tsirkin
2016-07-18 22:47 ` [Qemu-devel] [PULL 50/55] virtio-serial: " Michael S. Tsirkin
2016-07-18 22:47 ` [Qemu-devel] [PULL 51/55] 9pfs: " Michael S. Tsirkin
2016-07-18 22:48 ` [Qemu-devel] [PULL 52/55] virtio-input: " Michael S. Tsirkin
2016-07-18 22:48 ` [Qemu-devel] [PULL 53/55] virtio-gpu: Use migrate_add_blocker for virgl migration blocking Michael S. Tsirkin
2016-07-18 22:48 ` [Qemu-devel] [PULL 54/55] virtio-gpu: Wrap in vmstate Michael S. Tsirkin
2016-07-18 22:48 ` [Qemu-devel] [PULL 55/55] virtio: Update migration docs Michael S. Tsirkin

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=20160719014515-mutt-send-email-mst@redhat.com \
    --to=mst@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=peterx@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.