Merge tag 'iommu-updates-v4.20' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / drivers / iommu / amd_iommu_init.c
index 9c3d610e1e19be74bda8794c3764ba789060efd5..bb2cd29e165885d1697e4d77614a42333c5457dc 100644 (file)
@@ -902,12 +902,22 @@ static bool copy_device_table(void)
                }
        }
 
-       old_devtb_phys = entry & PAGE_MASK;
+       /*
+        * When SME is enabled in the first kernel, the entry includes the
+        * memory encryption mask(sme_me_mask), we must remove the memory
+        * encryption mask to obtain the true physical address in kdump kernel.
+        */
+       old_devtb_phys = __sme_clr(entry) & PAGE_MASK;
+
        if (old_devtb_phys >= 0x100000000ULL) {
                pr_err("The address of old device table is above 4G, not trustworthy!\n");
                return false;
        }
-       old_devtb = memremap(old_devtb_phys, dev_table_size, MEMREMAP_WB);
+       old_devtb = (sme_active() && is_kdump_kernel())
+                   ? (__force void *)ioremap_encrypted(old_devtb_phys,
+                                                       dev_table_size)
+                   : memremap(old_devtb_phys, dev_table_size, MEMREMAP_WB);
+
        if (!old_devtb)
                return false;