Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iommu/vt-d: Check VT-d RMRR region in BIOS is reported as reserved

VT-d RMRR (Reserved Memory Region Reporting) regions are reserved
for device use only and should not be part of allocable memory pool of OS.

BIOS e820_table reports complete memory map to OS, including OS usable
memory ranges and BIOS reserved memory ranges etc.

x86 BIOS may not be trusted to include RMRR regions as reserved type
of memory in its e820 memory map, hence validate every RMRR entry
with the e820 memory map to make sure the RMRR regions will not be
used by OS for any other purposes.

ia64 EFI is working fine so implement RMRR validation as a dummy function

Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Sohil Mehta <sohil.mehta@intel.com>
Signed-off-by: Yian Chen <yian.chen@intel.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>

authored by

Yian Chen and committed by
Joerg Roedel
f036c7fa 1ee0186b

+30 -1
+5
arch/ia64/include/asm/iommu.h
··· 2 2 #ifndef _ASM_IA64_IOMMU_H 3 3 #define _ASM_IA64_IOMMU_H 1 4 4 5 + #include <linux/acpi.h> 6 + 5 7 /* 10 seconds */ 6 8 #define DMAR_OPERATION_TIMEOUT (((cycles_t) local_cpu_data->itc_freq)*10) 7 9 ··· 11 9 #ifdef CONFIG_INTEL_IOMMU 12 10 extern int force_iommu, no_iommu; 13 11 extern int iommu_detected; 12 + 13 + static inline int __init 14 + arch_rmrr_sanity_check(struct acpi_dmar_reserved_memory *rmrr) { return 0; } 14 15 #else 15 16 #define no_iommu (1) 16 17 #define iommu_detected (0)
+18
arch/x86/include/asm/iommu.h
··· 2 2 #ifndef _ASM_X86_IOMMU_H 3 3 #define _ASM_X86_IOMMU_H 4 4 5 + #include <linux/acpi.h> 6 + 7 + #include <asm/e820/api.h> 8 + 5 9 extern int force_iommu, no_iommu; 6 10 extern int iommu_detected; 7 11 8 12 /* 10 seconds */ 9 13 #define DMAR_OPERATION_TIMEOUT ((cycles_t) tsc_khz*10*1000) 14 + 15 + static inline int __init 16 + arch_rmrr_sanity_check(struct acpi_dmar_reserved_memory *rmrr) 17 + { 18 + u64 start = rmrr->base_address; 19 + u64 end = rmrr->end_address + 1; 20 + 21 + if (e820__mapped_all(start, end, E820_TYPE_RESERVED)) 22 + return 0; 23 + 24 + pr_err(FW_BUG "No firmware reserved region can cover this RMRR [%#018Lx-%#018Lx], contact BIOS vendor for fixes\n", 25 + start, end - 1); 26 + return -EINVAL; 27 + } 10 28 11 29 #endif /* _ASM_X86_IOMMU_H */
+7 -1
drivers/iommu/intel-iommu.c
··· 4311 4311 { 4312 4312 struct acpi_dmar_reserved_memory *rmrr; 4313 4313 struct dmar_rmrr_unit *rmrru; 4314 + int ret; 4315 + 4316 + rmrr = (struct acpi_dmar_reserved_memory *)header; 4317 + ret = arch_rmrr_sanity_check(rmrr); 4318 + if (ret) 4319 + return ret; 4314 4320 4315 4321 rmrru = kzalloc(sizeof(*rmrru), GFP_KERNEL); 4316 4322 if (!rmrru) 4317 4323 goto out; 4318 4324 4319 4325 rmrru->hdr = header; 4320 - rmrr = (struct acpi_dmar_reserved_memory *)header; 4326 + 4321 4327 rmrru->base_address = rmrr->base_address; 4322 4328 rmrru->end_address = rmrr->end_address; 4323 4329