0002-iommu-amd-Don-t-initialise-remapping-irqdomain-if-IO.patch 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. From a4010c3d6f43dec4bf0010cab87cb3d29b4c7087 Mon Sep 17 00:00:00 2001
  2. From: David Woodhouse <dwmw@amazon.co.uk>
  3. Date: Mon, 15 Mar 2021 11:15:02 +0000
  4. Subject: [PATCH 2/2] iommu/amd: Don't initialise remapping irqdomain if IOMMU
  5. is disabled
  6. When the IOMMU is disabled, the driver still enumerates and initialises
  7. the hardware in order to turn it off. Because IRQ remapping setup is
  8. done early, the irqdomain is set up opportunistically.
  9. In commit b34f10c2dc59 ("iommu/amd: Stop irq_remapping_select() matching
  10. when remapping is disabled") I already make the irq_remapping_select()
  11. function check the amd_iommu_irq_setup flag because that might get
  12. cleared only after the irqdomain setup is done, when the IVRS is parsed.
  13. However, in the case where 'amd_iommu=off' is passed on the command line,
  14. the IRQ remapping setup isn't done but the amd_iommu_irq_setup flag is
  15. still set by the early IRQ remap init code. Stop it doing that, by
  16. bailing out of amd_iommu_prepare() early when it's disabled.
  17. This avoids the crash in irq_remapping_select() as it dereferences the
  18. NULL amd_iommu_rlookup_table[]:
  19. [ 0.243659] Switched APIC routing to physical x2apic.
  20. [ 0.262206] BUG: kernel NULL pointer dereference, address: 0000000000000500
  21. [ 0.262927] #PF: supervisor read access in kernel mode
  22. [ 0.263390] #PF: error_code(0x0000) - not-present page
  23. [ 0.263844] PGD 0 P4D 0
  24. [ 0.264135] Oops: 0000 [#1] SMP PTI
  25. [ 0.264460] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 5.12.0-rc3 #831
  26. [ 0.265069] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-1.fc33 04/01/2014
  27. [ 0.265825] RIP: 0010:irq_remapping_select+0x57/0xb0
  28. [ 0.266327] Code: 4b 0c 48 3d 30 e0 a7 9e 75 0d eb 35 48 8b 00 48 3d 30 e0 a7 9e 74 2a 0f b6 50 10 39 d1 75 ed 0f b7 40 12 48 8b 15 69 e3 d2 01 <48> 8b 14 c2 48 85 d2 74 0e b8 01 00 00 00 48 3b aa 90 04 00 00 74
  29. [ 0.268412] RSP: 0000:ffffffff9e803db0 EFLAGS: 00010246
  30. [ 0.268919] RAX: 00000000000000a0 RBX: ffffffff9e803df8 RCX: 0000000000000000
  31. [ 0.269550] RDX: 0000000000000000 RSI: 0000000000000000 RDI: ffff98120112fe79
  32. [ 0.270245] RBP: ffff9812011c8218 R08: 0000000000000001 R09: 000000000000000a
  33. [ 0.270922] R10: 000000000000000a R11: f000000000000000 R12: ffff9812011c8218
  34. [ 0.271549] R13: ffff98120181ed88 R14: 0000000000000000 R15: 0000000000000000
  35. [ 0.272221] FS: 0000000000000000(0000) GS:ffff98127dc00000(0000) knlGS:0000000000000000
  36. [ 0.272997] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
  37. [ 0.273508] CR2: 0000000000000500 CR3: 0000000030810000 CR4: 00000000000006b0
  38. [ 0.274178] Call Trace:
  39. [ 0.274416] irq_find_matching_fwspec+0x41/0xc0
  40. [ 0.274812] mp_irqdomain_create+0x65/0x150
  41. [ 0.275251] setup_IO_APIC+0x70/0x811
  42. Fixes: a1a785b57242 ("iommu/amd: Implement select() method on remapping irqdomain")
  43. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=212017
  44. Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
  45. ---
  46. drivers/iommu/amd/init.c | 3 +++
  47. 1 file changed, 3 insertions(+)
  48. diff --git a/drivers/iommu/amd/init.c b/drivers/iommu/amd/init.c
  49. index 78339b0bb8e5..398909dab640 100644
  50. --- a/drivers/iommu/amd/init.c
  51. +++ b/drivers/iommu/amd/init.c
  52. @@ -2998,6 +2998,9 @@ int __init amd_iommu_prepare(void)
  53. {
  54. int ret;
  55. + if (amd_iommu_disabled)
  56. + return -ENODEV;
  57. +
  58. amd_iommu_irq_remap = true;
  59. ret = iommu_go_to_state(IOMMU_ACPI_FINISHED);
  60. --
  61. 2.31.1