HID: amd_sfh: Use shared interrupts
Subsystems (3)
PATCH v2 1/1 HID: amd_sfh: Use shared interrupts
The AMD SFH driver requests interrupts without IRQF_SHARED. This can cause VFIO PCI passthrough initialization to fail when a passed-through device shares the interrupt with AMD MP2.
Request the interrupt with IRQF_SHARED. Check for a pending MP2 interrupt before clearing and acknowledging it, and return IRQ_NONE when no MP2 interrupt is pending so the interrupt can be shared with other devices.
On an AMD Ryzen 7 7735HS host running 7.0.0-38-generic kernel from Ubuntu, trying to pass through an xHCI controller (1022:161d, 0000:e6:00.3) fails with this message:
genirq: Flags mismatch irq 45.
00200080 (vfio-intx(0000:e6:00.3)) vs. 00200000 (pcie_mp2_amd)
QEMU reports:
vfio 0000:e6:00.3: Failed to set up TRIGGER eventfd signaling for interrupt INTX-0: VFIO_DEVICE_SET_IRQS failure: Device or resource busy
With this change, the passthrough is successful through VFIO on the same host.
--- drivers/hid/amd-sfh-hid/amd_sfh_common.h | 6 +++--- drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-)
drivers/hid/amd-sfh-hid/amd_sfh_common.h +3 -3
@@ -85,7 +85,7 @@ struct amd_mp2_ops {void (*stop)(struct amd_mp2_dev *privdata,u16 sensor_idx);void (*stop_all)(struct amd_mp2_dev *privdata);int (*response)(struct amd_mp2_dev *mp2,u8 sid,u32 sensor_sts); -void (*clear_intr)(struct amd_mp2_dev *privdata); +bool (*clear_intr)(struct amd_mp2_dev *privdata);int (*init_intr)(struct amd_mp2_dev *privdata);int (*discovery_status)(struct amd_mp2_dev *privdata);void (*suspend)(struct amd_mp2_dev *mp2);
@@ -100,9 +100,9 @@ struct amd_mp2_ops {void amd_sfh_work (struct work_struct *work);void amd_sfh_work_buffer (struct work_struct *work); -void amd_sfh_clear_intr_v2 (struct amd_mp2_dev *privdata); +bool amd_sfh_clear_intr_v2 (struct amd_mp2_dev *privdata);int amd_sfh_irq_init_v2 (struct amd_mp2_dev *privdata); -void amd_sfh_clear_intr (struct amd_mp2_dev *privdata); +bool amd_sfh_clear_intr (struct amd_mp2_dev *privdata);int amd_sfh_irq_init (struct amd_mp2_dev *privdata);static inline u64 amd_get_c2p_val (struct amd_mp2_dev *mp2,u32 idx)
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +12 -6
@@ -103,25 +103,31 @@ static void amd_stop_all_sensor_v2(struct amd_mp2_dev *privdata)writel (cmd_base.ul, privdata->mmio +AMD_C2P_MSG0 ); } -void amd_sfh_clear_intr_v2 (struct amd_mp2_dev *privdata) +bool amd_sfh_clear_intr_v2 (struct amd_mp2_dev *privdata) {if (readl (privdata->mmio +amd_get_p2c_val (privdata,4 ))) {writel (0 , privdata->mmio +amd_get_p2c_val (privdata,4 ));writel (0xf , privdata->mmio +amd_get_p2c_val (privdata,5 )); +return true; } + +return false; } -void amd_sfh_clear_intr (struct amd_mp2_dev *privdata) +bool amd_sfh_clear_intr (struct amd_mp2_dev *privdata) {if (privdata->mp2_ops->clear_intr) - privdata->mp2_ops->clear_intr (privdata); +return privdata->mp2_ops->clear_intr (privdata); + +return false; }static irqreturn_t amd_sfh_irq_handler (int irq,void *data) { -amd_sfh_clear_intr (data); +if (amd_sfh_clear_intr (data)) +return IRQ_HANDLED ; -return IRQ_HANDLED ; +return IRQ_NONE ; }int amd_sfh_irq_init_v2 (struct amd_mp2_dev *privdata)
@@ -129,7 +135,7 @@ int amd_sfh_irq_init_v2(struct amd_mp2_dev *privdata)pcim_intx (privdata->pdev, true);return devm_request_irq (&privdata->pdev->dev, privdata->pdev->irq, - amd_sfh_irq_handler,0 ,DRIVER_NAME , privdata); + amd_sfh_irq_handler,IRQF_SHARED ,DRIVER_NAME , privdata); }static int amd_sfh_dis_sts_v2 (struct amd_mp2_dev *privdata)
base-commit: 2c2fe95ab19b09bef7391e3e5cdf8146d09792b6
Signature · 1 line
2.55.0
Quoted 101 lines · Ho Jie Feng
[You don't often get email from [email protected]. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
The AMD SFH driver requests interrupts without
IRQF_SHARED. This can cause VFIO PCI passthrough initialization to fail when a passed-through device shares the interrupt with AMD MP2.Request the interrupt with
IRQF_SHARED. Check for a pending MP2 interrupt before clearing and acknowledging it, and returnIRQ_NONEwhen no MP2 interrupt is pending so the interrupt can be shared with other devices.On an AMD Ryzen 7 7735HS host running 7.0.0-38-generic kernel from Ubuntu, trying to pass through an xHCI controller (1022:161d, 0000:e6:00.3) fails with this message:
genirq: Flags mismatch irq 45.
00200080 (vfio-intx(0000:e6:00.3)) vs. 00200000 (pcie_mp2_amd)QEMU reports:
vfio 0000:e6:00.3: Failed to set up TRIGGER eventfd signaling for interrupt INTX-0:
VFIO_DEVICE_SET_IRQSfailure: Device or resource busyWith this change, the passthrough is successful through VFIO on the same host.
Fixes 7f016b35ca76 ("HID: amd_sfh: Add interrupt handler to process interrupts")Signed-off-by Ho Jie Feng <[email protected]>--- drivers/hid/amd-sfh-hid/amd_sfh_common.h | 6 +++--- drivers/hid/amd-sfh-hid/amd_sfh_pcie.c | 18 ++++++++++++------ 2 files changed, 15 insertions(+), 9 deletions(-)drivers/hid/amd-sfh-hid/amd_sfh_common.h +3
-3@@ -85,7 +85,7 @@ struct amd_mp2_ops {void (*stop)(struct amd_mp2_dev *privdata,u16 sensor_idx);void (*stop_all)(struct amd_mp2_dev *privdata);int (*response)(struct amd_mp2_dev *mp2,u8 sid,u32 sensor_sts); -void (*clear_intr)(struct amd_mp2_dev *privdata); +bool (*clear_intr)(struct amd_mp2_dev *privdata);int (*init_intr)(struct amd_mp2_dev *privdata);int (*discovery_status)(struct amd_mp2_dev *privdata);void (*suspend)(struct amd_mp2_dev *mp2);@@ -100,9 +100,9 @@ struct amd_mp2_ops {void amd_sfh_work (struct work_struct *work);void amd_sfh_work_buffer (struct work_struct *work); -void amd_sfh_clear_intr_v2 (struct amd_mp2_dev *privdata); +bool amd_sfh_clear_intr_v2 (struct amd_mp2_dev *privdata);int amd_sfh_irq_init_v2 (struct amd_mp2_dev *privdata); -void amd_sfh_clear_intr (struct amd_mp2_dev *privdata); +bool amd_sfh_clear_intr (struct amd_mp2_dev *privdata);int amd_sfh_irq_init (struct amd_mp2_dev *privdata);static inline u64 amd_get_c2p_val (struct amd_mp2_dev *mp2,u32 idx)drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +11
-5@@ -103,25 +103,31 @@ static void amd_stop_all_sensor_v2(struct amd_mp2_dev *privdata)writel (cmd_base.ul, privdata->mmio +AMD_C2P_MSG0 ); } -void amd_sfh_clear_intr_v2 (struct amd_mp2_dev *privdata) +bool amd_sfh_clear_intr_v2 (struct amd_mp2_dev *privdata) {if (readl (privdata->mmio +amd_get_p2c_val (privdata,4 ))) {writel (0 , privdata->mmio +amd_get_p2c_val (privdata,4 ));writel (0xf , privdata->mmio +amd_get_p2c_val (privdata,5 )); +return true; } + +return false; } -void amd_sfh_clear_intr (struct amd_mp2_dev *privdata) +bool amd_sfh_clear_intr (struct amd_mp2_dev *privdata) {if (privdata->mp2_ops->clear_intr) - privdata->mp2_ops->clear_intr (privdata); +return privdata->mp2_ops->clear_intr (privdata); + +return false; }static irqreturn_t amd_sfh_irq_handler (int irq,void *data) { -amd_sfh_clear_intr (data); +if (amd_sfh_clear_intr (data)) +return IRQ_HANDLED ; -return IRQ_HANDLED ; +return IRQ_NONE ; }int amd_sfh_irq_init_v2 (struct amd_mp2_dev *privdata)
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c int amd_sfh_irq_init_v2(struct amd_mp2_dev *privdata) · line 141
Quoted 8 lines
drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +1
-1@@ -129,7 +135,7 @@ int amd_sfh_irq_init_v2(struct amd_mp2_dev *privdata)pcim_intx (privdata->pdev, true);return devm_request_irq (&privdata->pdev->dev, privdata->pdev->irq, - amd_sfh_irq_handler,0 ,DRIVER_NAME , privdata); + amd_sfh_irq_handler,IRQF_SHARED ,DRIVER_NAME , privdata); }static int amd_sfh_dis_sts_v2 (struct amd_mp2_dev *privdata)
Thanks,
--
Basavaraj
Quoted 5 lines
base-commit:
2c2fe95ab19b09bef7391e3e5cdf8146d09792b6--
2.55.0
Quoted 21 lines · Ho Jie Feng
The AMD SFH driver requests interrupts without
IRQF_SHARED. This can cause VFIO PCI passthrough initialization to fail when a passed-through device shares the interrupt with AMD MP2.Request the interrupt with
IRQF_SHARED. Check for a pending MP2 interrupt before clearing and acknowledging it, and returnIRQ_NONEwhen no MP2 interrupt is pending so the interrupt can be shared with other devices.On an AMD Ryzen 7 7735HS host running 7.0.0-38-generic kernel from Ubuntu, trying to pass through an xHCI controller (1022:161d, 0000:e6:00.3) fails with this message:
genirq: Flags mismatch irq 45.
00200080 (vfio-intx(0000:e6:00.3)) vs. 00200000 (pcie_mp2_amd)QEMU reports:
vfio 0000:e6:00.3: Failed to set up TRIGGER eventfd signaling for interrupt INTX-0:
VFIO_DEVICE_SET_IRQSfailure: Device or resource busy
Quoted 6 lines
With this change, the passthrough is successful through VFIO on the same host.
Fixes 7f016b35ca76 ("HID: amd_sfh: Add interrupt handler to process interrupts")Signed-off-by Ho Jie Feng <[email protected]>
Applied, thanks.
Signature · 2 lines
Jiri Kosina SUSE Labs