iommu/amd: Workaround for ERBT1312
PATCH 2/2 iommu/amd: Workaround for ERBT1312
From: Suravee Suthikulpanit <[email protected]>
The IOMMU interrupt handling in bottom half must clear the PPR log interrupt and event log interrupt bits to re-enable the interrupt. This is done by writing 1 to the memory mapped register to clear the bit. Due to hardware bug, if the driver tries to clear this bit while the IOMMU hardware also setting this bit, the conflict will result with the bit being set. If the interrupt handling code does not make sure to clear this bit, subsequent changes in the event/PPR logs will no longer generating interrupts, and would result if buffer overflow. After clearing the bits, the driver must read back the register to verify.
--- xen/drivers/passthrough/amd/iommu_init.c | 41 ++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 14 deletions(-)
xen/drivers/passthrough/amd/iommu_init.c +27 -14
@@ -615,16 +615,23 @@ static void iommu_check_event_log(struct amd_iommu *iommu) sizeof(event_entry_t), parse_event_log_entry);spin_lock_irqsave (&iommu->lock, flags); - -/*check event overflow */ + entry =readl (iommu->mmio_base +IOMMU_STATUS_MMIO_OFFSET ); -if (iommu_get_bit (entry,IOMMU_STATUS_EVENT_OVERFLOW_SHIFT ) ) -iommu_reset_log (iommu, &iommu->event_log, set_iommu_event_log_control); +while (entry &IOMMU_STATUS_EVENT_LOG_INT_MASK ) { + +/*check event overflow */ +if (iommu_get_bit (entry,IOMMU_STATUS_EVENT_OVERFLOW_SHIFT ) ) +iommu_reset_log (iommu, &iommu->event_log, + set_iommu_event_log_control); -/* reset interrupt status bit */ -writel (IOMMU_STATUS_EVENT_LOG_INT_MASK , - iommu->mmio_base +IOMMU_STATUS_MMIO_OFFSET ); +/* reset interrupt status bit */ +writel (IOMMU_STATUS_EVENT_LOG_INT_MASK , + iommu->mmio_base +IOMMU_STATUS_MMIO_OFFSET ); + +/* This is a hardware bug workaround (ERBT1312) */ + entry =readl (iommu->mmio_base +IOMMU_STATUS_MMIO_OFFSET ); + }spin_unlock_irqrestore (&iommu->lock, flags); }
@@ -681,18 +688,24 @@ static void iommu_check_ppr_log(struct amd_iommu *iommu)iommu_read_log (iommu, &iommu->ppr_log,sizeof (ppr_entry_t), parse_ppr_log_entry); - +spin_lock_irqsave (&iommu->lock, flags); -/*check event overflow */ entry =readl (iommu->mmio_base +IOMMU_STATUS_MMIO_OFFSET ); -if (iommu_get_bit (entry,IOMMU_STATUS_PPR_LOG_OVERFLOW_SHIFT ) ) -iommu_reset_log (iommu, &iommu->ppr_log, set_iommu_ppr_log_control); +while (entry &IOMMU_STATUS_PPR_LOG_INT_MASK ) { + +/*check event overflow */ +if (iommu_get_bit (entry,IOMMU_STATUS_PPR_LOG_OVERFLOW_SHIFT ) ) +iommu_reset_log (iommu, &iommu->ppr_log, set_iommu_ppr_log_control); -/* reset interrupt status bit */ -writel (IOMMU_STATUS_PPR_LOG_INT_MASK , - iommu->mmio_base +IOMMU_STATUS_MMIO_OFFSET ); +/* reset interrupt status bit */ +writel (IOMMU_STATUS_PPR_LOG_INT_MASK , + iommu->mmio_base +IOMMU_STATUS_MMIO_OFFSET ); + +/* This is a hardware bug workaround (ERBT1312) */ + entry =readl (iommu->mmio_base +IOMMU_STATUS_MMIO_OFFSET ); + }spin_unlock_irqrestore (&iommu->lock, flags); }
Signature · 1 line
1.7.10.4
Quoted 1 line
Quoted 1 line
Quoted 1 line · On 18.04.13 at 20:41, <[email protected]> wrote:
What is ERBT1312? Please reference at least the title of the document containing this in the description, so that in few months/years time one can still reconstruct what this refers to.
Quoted 55 lines
xen/drivers/passthrough/amd/iommu_init.c +20
-14@@ -615,16 +615,23 @@ static void iommu_check_event_log(struct amd_iommu *iommu) sizeof(event_entry_t), parse_event_log_entry);spin_lock_irqsave (&iommu->lock, flags); - -/*check event overflow */ + entry =readl (iommu->mmio_base +IOMMU_STATUS_MMIO_OFFSET ); -if (iommu_get_bit (entry,IOMMU_STATUS_EVENT_OVERFLOW_SHIFT ) ) -iommu_reset_log (iommu, &iommu->event_log, set_iommu_event_log_control); +while (entry &IOMMU_STATUS_EVENT_LOG_INT_MASK ) { + +/*check event overflow */ +if (iommu_get_bit (entry,IOMMU_STATUS_EVENT_OVERFLOW_SHIFT ) ) +iommu_reset_log (iommu, &iommu->event_log, + set_iommu_event_log_control); -/* reset interrupt status bit */ -writel (IOMMU_STATUS_EVENT_LOG_INT_MASK , - iommu->mmio_base +IOMMU_STATUS_MMIO_OFFSET ); +/* reset interrupt status bit */ +writel (IOMMU_STATUS_EVENT_LOG_INT_MASK , + iommu->mmio_base +IOMMU_STATUS_MMIO_OFFSET ); + +/* This is a hardware bug workaround (ERBT1312) */ + entry =readl (iommu->mmio_base +IOMMU_STATUS_MMIO_OFFSET ); + }spin_unlock_irqrestore (&iommu->lock, flags); }@@ -681,18 +688,24 @@ static void iommu_check_ppr_log(struct amd_iommu *iommu)iommu_read_log (iommu, &iommu->ppr_log,sizeof (ppr_entry_t), parse_ppr_log_entry); - +spin_lock_irqsave (&iommu->lock, flags); -/*check event overflow */ entry =readl (iommu->mmio_base +IOMMU_STATUS_MMIO_OFFSET ); -if (iommu_get_bit (entry,IOMMU_STATUS_PPR_LOG_OVERFLOW_SHIFT ) ) -iommu_reset_log (iommu, &iommu->ppr_log, set_iommu_ppr_log_control); +while (entry &IOMMU_STATUS_PPR_LOG_INT_MASK ) { + +/*check event overflow */ +if (iommu_get_bit (entry,IOMMU_STATUS_PPR_LOG_OVERFLOW_SHIFT ) ) +iommu_reset_log (iommu, &iommu->ppr_log, set_iommu_ppr_log_control); -/* reset interrupt status bit */ -writel (IOMMU_STATUS_PPR_LOG_INT_MASK , - iommu->mmio_base +IOMMU_STATUS_MMIO_OFFSET );
xen/drivers/passthrough/amd/iommu_init.c static void iommu_check_ppr_log(struct amd_iommu *iommu) · line 711
Quoted 10 lines
xen/drivers/passthrough/amd/iommu_init.c +7
-0+/* reset interrupt status bit */ +writel (IOMMU_STATUS_PPR_LOG_INT_MASK , + iommu->mmio_base +IOMMU_STATUS_MMIO_OFFSET ); + +/* This is a hardware bug workaround (ERBT1312) */ + entry =readl (iommu->mmio_base +IOMMU_STATUS_MMIO_OFFSET ); + }spin_unlock_irqrestore (&iommu->lock, flags); }
This needs cleaning up from a coding style perspective: No hard tabs, braces on separate lines, spaces inside the outermost parentheses following keywords, a space following the opening /* of comments, proper indentation of multi-line function arguments.
Jan
Quoted 12 lines
Quoted 1 line
Quoted 1 line · On 18.04.13 at 20:41, <[email protected]> wrote:
The IOMMU interrupt handling in bottom half must clear the PPR log interrupt and event log interrupt bits to re-enable the interrupt. This is done by writing 1 to the memory mapped register to clear the bit. Due to hardware bug,
if the driver tries to clear this bit while the IOMMU hardware also setting this bit, the conflict will result with the bit being set. If the interrupt handling code does not make sure to clear this bit, subsequent changes in the
event/PPR logs will no longer generating interrupts, and would result if buffer overflow. After clearing the bits, the driver must read back the register to verify.
The Completion Wait Interrupt bit is unaffected by this erratum? Or else, is it guaranteed that flush_command_buffer() wouldn't need a similar fix?
Jan