#include #include #include #include #include "utils.h" #define MAX_LEN 8192 #define MAX_OFFSET 16 #define MIN_REDZONE 128 #define BUFLEN (MAX_LEN+MAX_OFFSET+2*MIN_REDZONE) #define POISON 0xa5 unsigned long COPY_LOOP(void *to, const void *from, unsigned long size); static void do_one(char *src, char *dst, unsigned long src_off, unsigned long dst_off, unsigned long len, void *redzone, void *fill) { char *srcp, *dstp; unsigned long ret; unsigned long i; srcp = src + MIN_REDZONE + src_off; dstp = dst + MIN_REDZONE + dst_off; memset(src, POISON, BUFLEN); memset(dst, POISON, BUFLEN); memcpy(srcp, fill, len); ret = COPY_LOOP(dstp, srcp, len); if (ret && ret != (unsigned long)dstp) { printf("(%p,%p,%ld) returned %ld\n", dstp, srcp, len, ret); abort(); } if (memcmp(dstp, srcp, len)) { printf("(%p,%p,%ld) miscompare\n", dstp, srcp, len); printf("src: "); for (i = 0; i < len; i++) printf("%02x ", srcp[i]); printf("\ndst: "); for (i = 0; i < len; i++) printf("%02x ", dstp[i]); printf("\n"); abort(); } if (memcmp(dst, redzone, dstp - dst)) { printf("(%p,%p,%ld) redzone before corrupted\n", dstp, srcp, len); abort(); } if (memcmp(dstp+len, redzone, dst+BUFLEN-(dstp+len))) { printf("(%p,%p,%ld) redzone after corrupted\n", dstp, srcp, len); abort(); } } int test_copy_loop(void) { char *src, *dst, *redzone, *fill; unsigned long len, src_off, dst_off; unsigned long i; src = memalign(BUFLEN, BUFLEN); dst = memalign(BUFLEN, BUFLEN); redzone = malloc(BUFLEN); fill = malloc(BUFLEN); if (!src || !dst || !redzone || !fill) { fprintf(stderr, "malloc failed\n"); exit(1); } memset(redzone, POISON, BUFLEN); /* Fill with sequential bytes */ for (i = 0; i < BUFLEN; i++) fill[i] = i & 0xff; for (len = 1; len < MAX_LEN; len++) { for (src_off = 0; src_off < MAX_OFFSET; src_off++) { for (dst_off = 0; dst_off < MAX_OFFSET; dst_off++) { do_one(src, dst, src_off, dst_off, len, redzone, fill); } } } return 0; } int main(void) { return test_harness(test_copy_loop, str(COPY_LOOP)); } cfc718d13a50fbc746ed9b415c25e92'>commitdiff
diff options
context:
space:
mode:
authorArd Biesheuvel <ard.biesheuvel@linaro.org>2017-02-01 17:45:02 +0000
committerIngo Molnar <mingo@kernel.org>2017-02-01 21:17:49 +0100
commitc8f325a59cfc718d13a50fbc746ed9b415c25e92 (patch)
treed53fbdac9d0781e39a13b2ac6b2bd258cf3b4140 /sound/soc/kirkwood/armada-370-db.c
parentbf29bddf0417a4783da3b24e8c9e017ac649326f (diff)
efi/fdt: Avoid FDT manipulation after ExitBootServices()
Some AArch64 UEFI implementations disable the MMU in ExitBootServices(), after which unaligned accesses to RAM are no longer supported. Commit: abfb7b686a3e ("efi/libstub/arm*: Pass latest memory map to the kernel") fixed an issue in the memory map handling of the stub FDT code, but inadvertently created an issue with such firmware, by moving some of the FDT manipulation to after the invocation of ExitBootServices(). Given that the stub's libfdt implementation uses the ordinary, accelerated string functions, which rely on hardware handling of unaligned accesses, manipulating the FDT with the MMU off may result in alignment faults. So fix the situation by moving the update_fdt_memmap() call into the callback function invoked by efi_exit_boot_services() right before it calls the ExitBootServices() UEFI service (which is arguably a better place for it anyway) Note that disabling the MMU in ExitBootServices() is not compliant with the UEFI spec, and carries great risk due to the fact that switching from cached to uncached memory accesses halfway through compiler generated code (i.e., involving a stack) can never be done in a way that is architecturally safe. Fixes: abfb7b686a3e ("efi/libstub/arm*: Pass latest memory map to the kernel") Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> Tested-by: Riku Voipio <riku.voipio@linaro.org> Cc: <stable@vger.kernel.org> Cc: mark.rutland@arm.com Cc: linux-efi@vger.kernel.org Cc: matt@codeblueprint.co.uk Cc: leif.lindholm@linaro.org Cc: linux-arm-kernel@lists.infradead.org Link: http://lkml.kernel.org/r/1485971102-23330-2-git-send-email-ard.biesheuvel@linaro.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'sound/soc/kirkwood/armada-370-db.c')