intel-iommu: Turn off translations at shutdown
PATCH 1/1 intel-iommu: Turn off translations at shutdown
The intel-iommu driver assumes that the iommu state is cleaned up at the start of the new kernel. But, when we try to kexec boot something other than the Linux kernel, the cleanup cannot be relied upon. Hence, cleanup before we go down for reboot.
Keeping the cleanup at initialization also, in case BIOS leaves the IOMMU enabled.
I considered turning off iommu only during kexec reboot, but a clean shutdown seems always a good idea. But if someone wants to make it conditional, we can do that.
Tested that before, the info message
'DMAR: Translation was enabled for <iommu> but we are not in kdump mode' would be reported for each iommu. The message will not appear when the DMA-remapping is not enabled on entry to the kernel.
--- drivers/iommu/intel-iommu.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
drivers/iommu/intel-iommu.c +22 -0
@@ -4764,6 +4764,26 @@ static void intel_disable_iommus(void)iommu_disable_translation (iommu); } +static void intel_iommu_shutdown (void ) +{ +struct dmar_drhd_unit *drhd; +struct intel_iommu *iommu =NULL ; + +if (no_iommu || dmar_disabled) +return ; + +down_write (&dmar_global_lock); + +/* Disable PMRs explicitly here. */ +for_each_iommu (iommu, drhd) +iommu_disable_protect_mem_regions (iommu); + +/* Make sure the IOMMUs are switched off */ +intel_disable_iommus (); + +up_write (&dmar_global_lock); +} +static inline struct intel_iommu *dev_to_intel_iommu (struct device *dev) {struct iommu_device *iommu_dev =dev_to_iommu_device (dev);
@@ -5013,6 +5033,8 @@ int __init intel_iommu_init(void) }up_write (&dmar_global_lock); + x86_platform.iommu_shutdown = intel_iommu_shutdown; +#if defined(CONFIG_X86 ) && defined(CONFIG_SWIOTLB )/* * If the system has no untrusted device or the user has decided
Signature · 1 line
2.17.1
drivers/iommu/intel-iommu.c static void intel_disable_iommus(void) · line 4773
Quoted 3 lines · Deepa Dinamani
drivers/iommu/intel-iommu.c +3
-0+static void intel_iommu_shutdown(void) + if (no_iommu || dmar_disabled) + return;
This check is actually not required here, as the handler is only installed after these have been checked in intel_iommu_init. I can remove this in the next version of the patch, but I'll wait a few days for comments.
-Deepa
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Hi,
Quoted 9 lines · Deepa Dinamani
drivers/iommu/intel-iommu.c static void intel_disable_iommus(void) · line 4773
Quoted 3 lines · Deepa Dinamani
drivers/iommu/intel-iommu.c +3
-0+static void intel_iommu_shutdown(void) + if (no_iommu || dmar_disabled) + return;This check is actually not required here, as the handler is only installed after these have been checked in
intel_iommu_init. I can remove this in the next version of the patch, but I'll wait a few days for comments.
This is probably still necessary if moving to detect_intel_iommu().
Best regards,
baolu
Quoted 7 lines
-Deepa
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Hi,
Quoted 55 lines · Deepa Dinamani
The intel-iommu driver assumes that the iommu state is cleaned up at the start of the new kernel. But, when we try to kexec boot something other than the Linux kernel, the cleanup cannot be relied upon. Hence, cleanup before we go down for reboot.
Keeping the cleanup at initialization also, in case BIOS leaves the IOMMU enabled.
I considered turning off iommu only during kexec reboot, but a clean shutdown seems always a good idea. But if someone wants to make it conditional, we can do that.
Tested that before, the info message
'DMAR: Translation was enabled for <iommu> but we are not in kdump mode' would be reported for each iommu. The message will not appear when the DMA-remapping is not enabled on entry to the kernel.Signed-off-by Deepa Dinamani <[email protected]>--- drivers/iommu/intel-iommu.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)drivers/iommu/intel-iommu.c +20
-0@@ -4764,6 +4764,26 @@ static void intel_disable_iommus(void)iommu_disable_translation (iommu); } +static void intel_iommu_shutdown (void ) +{ +struct dmar_drhd_unit *drhd; +struct intel_iommu *iommu =NULL ; + +if (no_iommu || dmar_disabled) +return ; + +down_write (&dmar_global_lock); + +/* Disable PMRs explicitly here. */ +for_each_iommu (iommu, drhd) +iommu_disable_protect_mem_regions (iommu); + +/* Make sure the IOMMUs are switched off */ +intel_disable_iommus (); + +up_write (&dmar_global_lock); +} +static inline struct intel_iommu *dev_to_intel_iommu (struct device *dev) {struct iommu_device *iommu_dev =dev_to_iommu_device (dev);
drivers/iommu/intel-iommu.c int __init intel_iommu_init(void) · line 5036
Quoted 4 lines
drivers/iommu/intel-iommu.c +1
-0@@ -5013,6 +5033,8 @@ int __init intel_iommu_init(void) }up_write (&dmar_global_lock); + x86_platform.iommu_shutdown = intel_iommu_shutdown;
How about moving it to detect_intel_iommu() in drivers/iommu/dmar.c? And make sure that it's included with CONFIG_X86_64.
Best regards,
baolu
Quoted 5 lines
drivers/iommu/intel-iommu.c +1
-0+#if defined(CONFIG_X86 ) && defined(CONFIG_SWIOTLB )/* * If the system has no untrusted device or the user has decided
Quoted 3 lines
Quoted 1 line
+ x86_platform.iommu_shutdown =
intel_iommu_shutdown;How about moving it to
detect_intel_iommu()indrivers/iommu/dmar.c? And
Ok, makes sense to move it along with the init handler.
Quoted 1 line
make sure that it's included with
CONFIG_X86_64.
You mean CONFIG_X86 like the init that is already there?
#ifdef CONFIG_X86
if (!ret)
x86_init.iommu.iommu_init = intel_iommu_init;#endif
Thanks,
-Deepa
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Hi,
Quoted 6 lines · Deepa Dinamani
Quoted 3 lines
Quoted 1 line
+ x86_platform.iommu_shutdown =
intel_iommu_shutdown;How about moving it to
detect_intel_iommu()indrivers/iommu/dmar.c? AndOk, makes sense to move it along with the init handler.
Quoted 9 lines
Quoted 1 line
make sure that it's included with
CONFIG_X86_64.You mean
CONFIG_X86like the init that is already there?#ifdef CONFIG_X86 if (!ret) x86_init.iommu.iommu_init = intel_iommu_init;#endif
Yes.
Also, change the title to "iommu/vt-d: Turn off ..."
Best regards,
baolu
Quoted 6 lines · Deepa Dinamani
The intel-iommu driver assumes that the iommu state is cleaned up at the start of the new kernel. But, when we try to kexec boot something other than the Linux kernel, the cleanup cannot be relied upon. Hence, cleanup before we go down for reboot.
Quoted 6 lines
Keeping the cleanup at initialization also, in case BIOS leaves the IOMMU enabled.
I considered turning off iommu only during kexec reboot, but a clean shutdown seems always a good idea. But if someone wants to make it conditional, we can do that.
This is going to break things for the VMM live update scheme that Jason presented at KVM Forum, isn't it?
In that case we rely on the IOMMU still operating during the transition.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 24 lines
-----Original Message-----
From: David Woodhouse <[email protected]>
Sent: Friday, November 8, 2019 3:54 PM
To: Deepa Dinamani <[email protected]>; [email protected]; linux- [email protected]
Cc: [email protected]; Zeng, Jason <[email protected]>; Tian, Kevin <[email protected]>
Subject: Re: [PATCH] intel-iommu: Turn off translations at shutdownQuoted 6 lines · Deepa Dinamani
The intel-iommu driver assumes that the iommu state is cleaned up at the start of the new kernel. But, when we try to kexec boot something other than the Linux kernel, the cleanup cannot be relied upon. Hence, cleanup before we go down for reboot.
Quoted 6 lines
Keeping the cleanup at initialization also, in case BIOS leaves the IOMMU enabled.
I considered turning off iommu only during kexec reboot, but a clean shutdown seems always a good idea. But if someone wants to make it conditional, we can do that.
Quoted 5 lines
This is going to break things for the VMM live update scheme that Jason presented at KVM Forum, isn't it?
In that case we rely on the IOMMU still operating during the transition.
For VMM live update case, we should be able to detect and bypass the shutdown that Deepa introduced here, so keep IOMMU still operating?
Thanks,
Jason
Quoted 23 lines · Jason
Quoted 23 lines
-----Original Message-----
From: David Woodhouse <[email protected]>
Sent: Friday, November 8, 2019 3:54 PM
To: Deepa Dinamani <[email protected]>; [email protected]; linux- [email protected]
Cc: [email protected]; Zeng, Jason <[email protected]>; Tian, Kevin <[email protected]>
Subject: Re: [PATCH] intel-iommu: Turn off translations at shutdownQuoted 12 lines · Deepa Dinamani
The intel-iommu driver assumes that the iommu state is cleaned up at the start of the new kernel. But, when we try to kexec boot something other than the Linux kernel, the cleanup cannot be relied upon. Hence, cleanup before we go down for reboot.
Keeping the cleanup at initialization also, in case BIOS leaves the IOMMU enabled.
I considered turning off iommu only during kexec reboot, but a clean shutdown seems always a good idea. But if someone wants to make it conditional, we can do that.
Quoted 8 lines
Quoted 5 lines
This is going to break things for the VMM live update scheme that Jason presented at KVM Forum, isn't it?
In that case we rely on the IOMMU still operating during the transition.
For VMM live update case, we should be able to detect and bypass the shutdown that Deepa introduced here, so keep IOMMU still operating?
Is that a 'yes' to Deepa's "if someone wants to make it conditional, we can do that" ?
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 39 lines
-----Original Message-----
From: David Woodhouse <[email protected]>
Sent: Friday, November 8, 2019 4:57 PM
To: Zeng, Jason <[email protected]>; Deepa Dinamani <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; Tian, Kevin <[email protected]>
Subject: Re: [PATCH] intel-iommu: Turn off translations at shutdownQuoted 4 lines · Jason
Quoted 4 lines
-----Original Message-----
From: David Woodhouse <[email protected]>
Sent: Friday, November 8, 2019 3:54 PM
To: Deepa Dinamani <[email protected]>; [email protected];linux-
Quoted 2 lines
Quoted 2 lines
[email protected]
Cc: [email protected]; Zeng, JasonQuoted 20 lines
Quoted 20 lines
Tian, Kevin <[email protected]>
Subject: Re: [PATCH] intel-iommu: Turn off translations at shutdownQuoted 6 lines · Deepa Dinamani
The intel-iommu driver assumes that the iommu state is cleaned up at the start of the new kernel. But, when we try to kexec boot something other than the Linux kernel, the cleanup cannot be relied upon. Hence, cleanup before we go down for reboot.
Quoted 6 lines
Keeping the cleanup at initialization also, in case BIOS leaves the IOMMU enabled.
I considered turning off iommu only during kexec reboot, but a clean shutdown seems always a good idea. But if someone wants to make it conditional, we can do that.
This is going to break things for the VMM live update scheme that Jason presented at KVM Forum, isn't it?
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
In that case we rely on the IOMMU still operating during the transition.
For VMM live update case, we should be able to detect and bypass the shutdown that Deepa introduced here, so keep IOMMU still operating?
Is that a 'yes' to Deepa's "if someone wants to make it conditional, we can do that" ?
Yes, I think so. Thanks!
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
For VMM live update case, we should be able to detect and bypass the shutdown that Deepa introduced here, so keep IOMMU still operating?
Is that a 'yes' to Deepa's "if someone wants to make it conditional, we can do that" ?
Yes, I think so. Thanks!
Are these changes already part of the kernel like avoiding shutdown of the passthrough devices? device_shutdown() doesn't seem to be doing anything selectively as of now.
Thanks,
Deepa
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 4 lines · Deepa Dinamani
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
For VMM live update case, we should be able to detect and bypass the shutdown that Deepa introduced here, so keep IOMMU still operating?
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Is that a 'yes' to Deepa's "if someone wants to make it conditional, we can do that" ?
Yes, I think so. Thanks!
Are these changes already part of the kernel like avoiding shutdown of the passthrough devices?
device_shutdown()doesn't seem to be doing anything selectively as of now.
I've posted the v2 without the conditional for now:
https://lore.kernel.org/patchwork/patch/1151225/
As a side topic, I'm trying to support https://www.linuxboot.org/. I have a couple of more such cleanups coming. The VMM live updates and linuxboot seem to have contradicting requirements and they both use kexec. So kexec_in_progress doesn't seem like a sufficient indicator to distinguish between the two. Do you already have an idea on how to distiguish between them? Does a separate sys_reboot() command parameter sound ok? Or, we could use the flags in the sys_kexec_load() depending on how the live update feature is implemented.
-Deepa
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 18 lines · Deepa Dinamani
Quoted 4 lines · Deepa Dinamani
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
For VMM live update case, we should be able to detect and bypass the shutdown that Deepa introduced here, so keep IOMMU still operating?
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines
Is that a 'yes' to Deepa's "if someone wants to make it conditional, we can do that" ?
Yes, I think so. Thanks!
Are these changes already part of the kernel like avoiding shutdown of the passthrough devices?
device_shutdown()doesn't seem to be doing anything selectively as of now.I've posted the v2 without the conditional for now:
https://lore.kernel.org/patchwork/patch/1151225/
Quoted 8 lines
As a side topic, I'm trying to support https://www.linuxboot.org/. I have a couple of more such cleanups coming. The VMM live updates and linuxboot seem to have contradicting requirements and they both use kexec. So
kexec_in_progressdoesn't seem like a sufficient indicator to distinguish between the two. Do you already have an idea on how to distiguish between them? Does a separatesys_reboot()command parameter sound ok? Or, we could use the flags in thesys_kexec_load()depending on how the live update feature is implemented.
Also, the AMD driver disables iommu at shutdown already. So the live update feature is already broken on AMD.
-Deepa
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 15 lines
-----Original Message-----
On Sun, Nov 10, 2019 at 10:24 AM Deepa DinamaniQuoted 11 lines
I've posted the v2 without the conditional for now:
https://lore.kernel.org/patchwork/patch/1151225/As a side topic, I'm trying to support https://www.linuxboot.org/. I have a couple of more such cleanups coming. The VMM live updates and linuxboot seem to have contradicting requirements and they both use kexec. So
kexec_in_progressdoesn't seem like a sufficient indicator to distinguish between the two. Do you already have an idea on how to distiguish between them? Does a separatesys_reboot()command parameter sound ok? Or, we could use the flags in thesys_kexec_load()depending on how the live update feature is implemented.
Quoted 3 lines
Also, the AMD driver disables iommu at shutdown already. So the live update feature is already broken on AMD.
Hi Deepa,
I think you may not need to consider too much VMM live update here (although it would be good to consider possible future features), after all it is an on-going effort, we are still not quite sure what exact modifications it needs. The VMM live update itself will figure out what is the best way to modify the code.
Thanks,
Jason
Quoted 1 line
-Deepa
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 5 lines
-----Original Message-----
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
For VMM live update case, we should be able to detect and bypass the shutdown that Deepa introduced here, so keep IOMMU still
operating?
Quoted 1 line
Quoted 1 line
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
Is that a 'yes' to Deepa's "if someone wants to make it conditional, we can do that" ?
Yes, I think so. Thanks!
Are these changes already part of the kernel like avoiding shutdown of the passthrough devices?
device_shutdown()doesn't seem to be doing anything selectively as of now.
No, it is not in upstream yet. It is an on-going effort, which tries to kexec reboot the host while keeping IOMMU still working.
Thanks,
Jason
Quoted 2 lines
Thanks,
Deepa
kbuild test robot
build botThank you for the patch! Yet something to improve:
Hi Deepa,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on v5.4-rc7 next-20191108]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Deepa-Dinamani/intel-iommu-Turn-off-translations-at-shutdown/20191109-195859 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 0058b0a506e40d9a2c62015fe92eb64a44d78cd9 config: ia64-defconfig (attached as .config) compiler: ia64-linux-gcc (GCC) 7.4.0
reproduce:
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
GCC_VERSION=7.4.0 make.cross ARCH=ia64
If you fix the issue, kindly add following tag
All errors (new ones prefixed by >>):
drivers/iommu/intel-iommu.c: In function 'intel_iommu_init':
>> drivers/iommu/intel-iommu.c:5031:2: error: 'x86_platform' undeclared (first use in this function); did you mean 'pci_platform_rom'?
x86_platform.iommu_shutdown = intel_iommu_shutdown;
^~~~~~~~~~~~
pci_platform_rom drivers/iommu/intel-iommu.c:5031:2: note: each undeclared identifier is reported only once for each function it appears in
vim +5031 drivers/iommu/intel-iommu.c
4940
4941 int __init intel_iommu_init(void)
4942 {
4943 int ret = -ENODEV;
4944 struct dmar_drhd_unit *drhd;
4945 struct intel_iommu *iommu;
4946
4947 /*
4948 * Intel IOMMU is required for a TXT/tboot launch or platform
4949 * opt in, so enforce that.
4950 */
4951 force_on = tboot_force_iommu() || platform_optin_force_iommu();
4952
4953 if (iommu_init_mempool()) {
4954 if (force_on)
4955 panic("tboot: Failed to initialize iommu memory\n");
4956 return -ENOMEM;
4957 }
4958
4959 down_write(&dmar_global_lock);
4960 if (dmar_table_init()) {
4961 if (force_on)
4962 panic("tboot: Failed to initialize DMAR table\n");
4963 goto out_free_dmar;
4964 }
4965
4966 if (dmar_dev_scope_init() < 0) {
4967 if (force_on)
4968 panic("tboot: Failed to initialize DMAR device scope\n");
4969 goto out_free_dmar;
4970 }
4971
4972 up_write(&dmar_global_lock);
4973
4974 /*
4975 * The bus notifier takes the dmar_global_lock, so lockdep will
4976 * complain later when we register it under the lock.
4977 */
4978 dmar_register_bus_notifier();
4979
4980 down_write(&dmar_global_lock);
4981
4982 if (no_iommu || dmar_disabled) {
4983 /*
4984 * We exit the function here to ensure IOMMU's remapping and
4985 * mempool aren't setup, which means that the IOMMU's PMRs
4986 * won't be disabled via the call to init_dmars(). So disable
4987 * it explicitly here. The PMRs were setup by tboot prior to
4988 * calling SENTER, but the kernel is expected to reset/tear
4989 * down the PMRs.
4990 */
4991 if (intel_iommu_tboot_noforce) {
4992 for_each_iommu(iommu, drhd)
4993 iommu_disable_protect_mem_regions(iommu);
4994 }
4995
4996 /*
4997 * Make sure the IOMMUs are switched off, even when we
4998 * boot into a kexec kernel and the previous kernel left
4999 * them enabled
5000 */
5001 intel_disable_iommus();
5002 goto out_free_dmar;
5003 }
5004
5005 if (list_empty(&dmar_rmrr_units))
5006 pr_info("No RMRR found\n");
5007
5008 if (list_empty(&dmar_atsr_units))
5009 pr_info("No ATSR found\n");
5010
5011 if (dmar_init_reserved_ranges()) {
5012 if (force_on)
5013 panic("tboot: Failed to reserve iommu ranges\n");
5014 goto out_free_reserved_range;
5015 }
5016
5017 if (dmar_map_gfx)
5018 intel_iommu_gfx_mapped = 1;
5019
5020 init_no_remapping_devices();
5021
5022 ret = init_dmars();
5023 if (ret) {
5024 if (force_on)
5025 panic("tboot: Failed to initialize DMARs\n");
5026 pr_err("Initialization failed\n");
5027 goto out_free_reserved_range;
5028 }
5029 up_write(&dmar_global_lock);
5030
> 5031 x86_platform.iommu_shutdown = intel_iommu_shutdown;
5032
---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation