This patch is to deal with fault event reported from IOMMU driver.
Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
---
hw/i386/intel_iommu.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
index 9b1ba1b..79507d2 100644
--- a/hw/i386/intel_iommu.c
+++ b/hw/i386/intel_iommu.c
@@ -2286,6 +2286,30 @@ static void vtd_iommu_notify_flag_changed(MemoryRegion *iommu,
}
}
+static void vtd_iommu_notify_fault_event(MemoryRegion *iommu,
+ IOMMUFaultInfo *info)
+{
+ VTDAddressSpace *vtd_as = container_of(iommu, VTDAddressSpace, iommu);
+ IntelIOMMUState *s = vtd_as->iommu_state;
+ bool is_fpd_set = false;
+ uint8_t bus_num = pci_bus_num(vtd_as->bus);
+ uint8_t devfn = vtd_as->devfn;
+ VTDContextEntry ce;
+
+ /* Replace source id with device's vbdf */
+ info->sid = vtd_make_source_id(bus_num, devfn);
+
+ if (!vtd_dev_to_context_entry(s, bus_num, devfn, &ce)) {
+ is_fpd_set = ce.lo & VTD_CONTEXT_ENTRY_FPD;
+ if (is_fpd_set) {
+ trace_vtd_fault_disabled();
+ } else {
+ vtd_report_dmar_fault(s, info->sid, info->addr,
+ info->fault_reason, info->is_write);
+ }
+ }
+}
+
static const VMStateDescription vtd_vmstate = {
.name = "iommu-intel",
.version_id = 1,
@@ -2816,6 +2840,7 @@ static void vtd_init(IntelIOMMUState *s)
s->iommu_ops.translate = vtd_iommu_translate;
s->iommu_ops.notify_flag_changed = vtd_iommu_notify_flag_changed;
+ s->iommu_ops.notify_fault_event = vtd_iommu_notify_fault_event;
s->iommu_ops.replay = vtd_iommu_replay;
s->root = 0;
s->root_extended = false;
--
1.8.3.1
On Mon, 20 Feb 2017 09:28:06 +0800
Lan Tianyu <tianyu.lan@intel.com> wrote:
> This patch is to deal with fault event reported from IOMMU driver.
>
> Signed-off-by: Lan Tianyu <tianyu.lan@intel.com>
> ---
> hw/i386/intel_iommu.c | 25 +++++++++++++++++++++++++
> 1 file changed, 25 insertions(+)
>
> diff --git a/hw/i386/intel_iommu.c b/hw/i386/intel_iommu.c
> index 9b1ba1b..79507d2 100644
> --- a/hw/i386/intel_iommu.c
> +++ b/hw/i386/intel_iommu.c
> @@ -2286,6 +2286,30 @@ static void vtd_iommu_notify_flag_changed(MemoryRegion *iommu,
> }
> }
>
> +static void vtd_iommu_notify_fault_event(MemoryRegion *iommu,
> + IOMMUFaultInfo *info)
> +{
> + VTDAddressSpace *vtd_as = container_of(iommu, VTDAddressSpace, iommu);
> + IntelIOMMUState *s = vtd_as->iommu_state;
> + bool is_fpd_set = false;
> + uint8_t bus_num = pci_bus_num(vtd_as->bus);
> + uint8_t devfn = vtd_as->devfn;
> + VTDContextEntry ce;
> +
> + /* Replace source id with device's vbdf */
> + info->sid = vtd_make_source_id(bus_num, devfn);
> +
> + if (!vtd_dev_to_context_entry(s, bus_num, devfn, &ce)) {
> + is_fpd_set = ce.lo & VTD_CONTEXT_ENTRY_FPD;
> + if (is_fpd_set) {
> + trace_vtd_fault_disabled();
> + } else {
> + vtd_report_dmar_fault(s, info->sid, info->addr,
> + info->fault_reason, info->is_write);
Convenient that the error structure exactly matches the function
parameters here. Is fault_reason going to be standardized across all
IOMMU vendors? If not, how does QEMU know whether the type1 container
is backed by VT-d, AMD-Vi, ARM SMMU, etc?
> + }
> + }
> +}
> +
> static const VMStateDescription vtd_vmstate = {
> .name = "iommu-intel",
> .version_id = 1,
> @@ -2816,6 +2840,7 @@ static void vtd_init(IntelIOMMUState *s)
>
> s->iommu_ops.translate = vtd_iommu_translate;
> s->iommu_ops.notify_flag_changed = vtd_iommu_notify_flag_changed;
> + s->iommu_ops.notify_fault_event = vtd_iommu_notify_fault_event;
> s->iommu_ops.replay = vtd_iommu_replay;
> s->root = 0;
> s->root_extended = false;
© 2016 - 2026 Red Hat, Inc.