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 v5 26/57] x86-iommu: introduce IEC notifiers
Date: Thu, 21 Jul 2016 20:53:10 +0300	[thread overview]
Message-ID: <1469123413-20809-27-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1469123413-20809-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>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@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 c7ded0f..2acec85 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-21 17:53 UTC|newest]

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

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=1469123413-20809-27-git-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.