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

efi: capsule: clean scatter-gather entries from the D-cache

Scatter-gather lists passed to UpdateCapsule() should be cleaned
from the D-cache to ensure that they are visible to the CPU after a
warm reboot before the MMU is enabled. On ARM and arm64 systems, this
implies a D-cache clean by virtual address to the point of coherency.

However, due to the fact that the firmware itself is not able to map
physical addresses back to virtual addresses when running under the OS,
this must be done by the caller.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>

+22
+5
arch/arm/include/asm/efi.h
··· 93 93 u32 sctlr_after_ebs; 94 94 }; 95 95 96 + static inline void efi_capsule_flush_cache_range(void *addr, int size) 97 + { 98 + __cpuc_flush_dcache_area(addr, size); 99 + } 100 + 96 101 #endif /* _ASM_ARM_EFI_H */
+5
arch/arm64/include/asm/efi.h
··· 141 141 void efi_virtmap_load(void); 142 142 void efi_virtmap_unload(void); 143 143 144 + static inline void efi_capsule_flush_cache_range(void *addr, int size) 145 + { 146 + __flush_dcache_area(addr, size); 147 + } 148 + 144 149 #endif /* _ASM_EFI_H */
+12
drivers/firmware/efi/capsule.c
··· 12 12 #include <linux/highmem.h> 13 13 #include <linux/efi.h> 14 14 #include <linux/vmalloc.h> 15 + #include <asm/efi.h> 15 16 #include <asm/io.h> 16 17 17 18 typedef struct { ··· 266 265 else 267 266 sglist[j].data = page_to_phys(sg_pages[i + 1]); 268 267 268 + #if defined(CONFIG_ARM) || defined(CONFIG_ARM64) 269 + /* 270 + * At runtime, the firmware has no way to find out where the 271 + * sglist elements are mapped, if they are mapped in the first 272 + * place. Therefore, on architectures that can only perform 273 + * cache maintenance by virtual address, the firmware is unable 274 + * to perform this maintenance, and so it is up to the OS to do 275 + * it instead. 276 + */ 277 + efi_capsule_flush_cache_range(sglist, PAGE_SIZE); 278 + #endif 269 279 kunmap_atomic(sglist); 270 280 } 271 281