2022-05-09 01:34:59

by Ricardo Neri

[permalink] [raw]
Subject: [PATCH v6 13/29] iommu/amd: Compose MSI messages for NMI irqs in non-IR format

If NMIPass is enabled in a device's DTE, the IOMMU lets NMI interrupt
messages pass through unmapped. Therefore, the contents of the MSI
message, not an IRTE, determine how and where the NMI is delivered.

Since the IOMMU driver owns the MSI message of the NMI irq, compose
it using the non-interrupt-remapping format. Also, let descendant
irqchips write the MSI as appropriate for the device.

Cc: Andi Kleen <[email protected]>
Cc: "Ravi V. Shankar" <[email protected]>
Cc: Joerg Roedel <[email protected]>
Cc: Suravee Suthikulpanit <[email protected]>
Cc: Stephane Eranian <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Signed-off-by: Ricardo Neri <[email protected]>
---
Changes since v5:
* Introduced this patch

Changes since v4:
* N/A

Changes since v3:
* N/A

Changes since v2:
* N/A

Changes since v1:
* N/A
---
drivers/iommu/amd/iommu.c | 23 ++++++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c
index 4d7421b6858d..6e07949b3e2a 100644
--- a/drivers/iommu/amd/iommu.c
+++ b/drivers/iommu/amd/iommu.c
@@ -3111,7 +3111,16 @@ static void irq_remapping_prepare_irte(struct amd_ir_data *data,
case X86_IRQ_ALLOC_TYPE_HPET:
case X86_IRQ_ALLOC_TYPE_PCI_MSI:
case X86_IRQ_ALLOC_TYPE_PCI_MSIX:
- fill_msi_msg(&data->msi_entry, irte_info->index);
+ if (irq_cfg->delivery_mode == APIC_DELIVERY_MODE_NMI)
+ /*
+ * The IOMMU lets NMIs pass through unmapped. Thus, the
+ * MSI message, not the IRTE, determines the irq
+ * configuration. Since we own the MSI message,
+ * compose it. Descendant irqchips will write it.
+ */
+ __irq_msi_compose_msg(irq_cfg, &data->msi_entry, true);
+ else
+ fill_msi_msg(&data->msi_entry, irte_info->index);
break;

default:
@@ -3509,6 +3518,18 @@ static int amd_ir_set_affinity(struct irq_data *data,
*/
send_cleanup_vector(cfg);

+ /*
+ * When the delivery mode of an irq is NMI, the IOMMU lets the NMI
+ * interrupt messages pass through unmapped. Hence, changes in the
+ * destination are to be reflected in the NMI message itself, not the
+ * IRTE. Thus, descendant irqchips must set the affinity and compose
+ * write the MSI message.
+ *
+ * Also, NMIs do not have an associated vector. No need for cleanup.
+ */
+ if (cfg->delivery_mode == APIC_DELIVERY_MODE_NMI)
+ return IRQ_SET_MASK_OK;
+
return IRQ_SET_MASK_OK_DONE;
}

--
2.17.1



2022-05-09 02:38:52

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [PATCH v6 13/29] iommu/amd: Compose MSI messages for NMI irqs in non-IR format

On Thu, May 05 2022 at 16:59, Ricardo Neri wrote:
> + *
> + * Also, NMIs do not have an associated vector. No need for cleanup.

They have a vector and what the heck is this cleanup comment for here?
There is nothing cleanup alike anywhere near.

Adding confusing comments is worse than adding no comments at all.

Thanks,

tglx

2022-05-14 03:10:05

by Ricardo Neri

[permalink] [raw]
Subject: Re: [PATCH v6 13/29] iommu/amd: Compose MSI messages for NMI irqs in non-IR format

On Fri, May 06, 2022 at 11:31:56PM +0200, Thomas Gleixner wrote:
> On Thu, May 05 2022 at 16:59, Ricardo Neri wrote:
> > + *
> > + * Also, NMIs do not have an associated vector. No need for cleanup.
>
> They have a vector and what the heck is this cleanup comment for here?
> There is nothing cleanup alike anywhere near.
>
> Adding confusing comments is worse than adding no comments at all.

I will remove the comment regarding cleanup. I will clarify that NMI has a
fixed vector.

Thanks and BR,
Ricardo