efi: capsule: clean scatter-gather entries from the D-cache
authorArd Biesheuvel <ardb@kernel.org>
Mon, 7 Dec 2020 17:40:53 +0000 (18:40 +0100)
committerArd Biesheuvel <ardb@kernel.org>
Wed, 9 Dec 2020 07:37:27 +0000 (08:37 +0100)
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>
arch/arm/include/asm/efi.h
arch/arm64/include/asm/efi.h
drivers/firmware/efi/capsule.c

index 3ee4f43819850b3ad1e262f3ef02f0b16a0226ba..e9a06e164e0699e763dc8576f397ac0a2aa3cb74 100644 (file)
@@ -93,4 +93,9 @@ struct efi_arm_entry_state {
        u32     sctlr_after_ebs;
 };
 
+static inline void efi_capsule_flush_cache_range(void *addr, int size)
+{
+       __cpuc_flush_dcache_area(addr, size);
+}
+
 #endif /* _ASM_ARM_EFI_H */
index 973b144152711ace4bc6ee85c44926cebd253274..00bd1e179d36f8ed260dcfe9d55c13f45b4e0d97 100644 (file)
@@ -141,4 +141,9 @@ static inline void efi_set_pgd(struct mm_struct *mm)
 void efi_virtmap_load(void);
 void efi_virtmap_unload(void);
 
+static inline void efi_capsule_flush_cache_range(void *addr, int size)
+{
+       __flush_dcache_area(addr, size);
+}
+
 #endif /* _ASM_EFI_H */
index 43f6fe7bfe80fb91506d3e86928f486852aed477..768430293669fc678b15b35397ea1dbe582e8067 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/highmem.h>
 #include <linux/efi.h>
 #include <linux/vmalloc.h>
+#include <asm/efi.h>
 #include <asm/io.h>
 
 typedef struct {
@@ -265,6 +266,17 @@ int efi_capsule_update(efi_capsule_header_t *capsule, phys_addr_t *pages)
                else
                        sglist[j].data = page_to_phys(sg_pages[i + 1]);
 
+#if defined(CONFIG_ARM) || defined(CONFIG_ARM64)
+               /*
+                * At runtime, the firmware has no way to find out where the
+                * sglist elements are mapped, if they are mapped in the first
+                * place. Therefore, on architectures that can only perform
+                * cache maintenance by virtual address, the firmware is unable
+                * to perform this maintenance, and so it is up to the OS to do
+                * it instead.
+                */
+               efi_capsule_flush_cache_range(sglist, PAGE_SIZE);
+#endif
                kunmap_atomic(sglist);
        }