1
0
Fork 0
alistair23-linux/arch
Masahiro Yamada ca2fc0dc1c ARC: build: move symlink creation to arch/arc/Makefile to avoid race
[ Upstream commit c5e6ae563c ]

If you run 'make uImage uImage.gz' with the parallel option, uImage.gz
will be created by two threads simultaneously.

This is because arch/arc/Makefile does not specify the dependency
between uImage and uImage.gz. Hence, GNU Make assumes they can be
built in parallel. One thread descends into arch/arc/boot/ to create
uImage, and another to create uImage.gz.

Please notice the same log is displayed twice in the following steps:

  $ export CROSS_COMPILE=<your-arc-compiler-prefix>
  $ make -s ARCH=arc defconfig
  $ make -j$(nproc) ARCH=arc uImage uImage.gz
  [ snip ]
    LD      vmlinux
    SORTTAB vmlinux
    SYSMAP  System.map
    OBJCOPY arch/arc/boot/vmlinux.bin
    OBJCOPY arch/arc/boot/vmlinux.bin
    GZIP    arch/arc/boot/vmlinux.bin.gz
    GZIP    arch/arc/boot/vmlinux.bin.gz
    UIMAGE  arch/arc/boot/uImage.gz
    UIMAGE  arch/arc/boot/uImage.gz
  Image Name:   Linux-5.10.0-rc4-00003-g62f23044
  Created:      Sun Nov 22 02:52:26 2020
  Image Type:   ARC Linux Kernel Image (gzip compressed)
  Data Size:    2109376 Bytes = 2059.94 KiB = 2.01 MiB
  Load Address: 80000000
  Entry Point:  80004000
    Image arch/arc/boot/uImage is ready
  Image Name:   Linux-5.10.0-rc4-00003-g62f23044
  Created:      Sun Nov 22 02:52:26 2020
  Image Type:   ARC Linux Kernel Image (gzip compressed)
  Data Size:    2815455 Bytes = 2749.47 KiB = 2.69 MiB
  Load Address: 80000000
  Entry Point:  80004000

This is a race between the two threads trying to write to the same file
arch/arc/boot/uImage.gz. This is a potential problem that can generate
a broken file.

I fixed a similar problem for ARM by commit 3939f33450 ("ARM: 8418/1:
add boot image dependencies to not generate invalid images").

I highly recommend to avoid such build rules that cause a race condition.

Move the uImage rule to arch/arc/Makefile.

Another strangeness is that arch/arc/boot/Makefile compares the
timestamps between $(obj)/uImage and $(obj)/uImage.*:

  $(obj)/uImage: $(obj)/uImage.$(suffix-y)
          @ln -sf $(notdir $<) $@
          @echo '  Image $@ is ready'

This does not work as expected since $(obj)/uImage is a symlink.
The symlink should be created in a phony target rule.

I used $(kecho) instead of echo to suppress the message
'Image arch/arc/boot/uImage is ready' when the -s option is given.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-01-19 18:26:14 +01:00
..
alpha alpha: fix annotation of io{read,write}{16,32}be() 2020-08-26 10:40:58 +02:00
arc ARC: build: move symlink creation to arch/arc/Makefile to avoid race 2021-01-19 18:26:14 +01:00
arm ARM: OMAP2+: omap_device: fix idling of devices during probe 2021-01-17 14:05:34 +01:00
arm64 KVM: arm64: Don't access PMCR_EL0 when no PMU is available 2021-01-17 14:05:38 +01:00
c6x mm: consolidate pgtable_cache_init() and pgd_cache_init() 2019-09-24 15:54:09 -07:00
csky csky: Fixup abiv2 syscall_trace break a4 & a5 2020-06-17 16:40:21 +02:00
h8300 mm: consolidate pgtable_cache_init() and pgd_cache_init() 2019-09-24 15:54:09 -07:00
hexagon hexagon: define ioremap_uc 2020-05-10 10:31:31 +02:00
ia64 ia64: fix build error with !COREDUMP 2020-11-05 11:43:33 +01:00
m68k m68k: q40: Fix info-leak in rtc_ioctl 2020-10-01 13:17:12 +02:00
microblaze microblaze: Prevent the overflow of the start 2020-02-24 08:37:02 +01:00
mips MIPS: relocatable: fix possible boot hangup with KASLR enabled 2021-01-19 18:26:12 +01:00
nds32 asm-generic/nds32: don't redefine cacheflush primitives 2020-01-17 19:48:43 +01:00
nios2 nios2 update for v5.4-rc1 2019-09-27 13:02:19 -07:00
openrisc openrisc: Fix issue with get_user for 64-bit values 2020-11-01 12:01:06 +01:00
parisc kbuild: fix broken builds because of GZIP,BZIP2,LZOP variables 2020-09-03 11:27:10 +02:00
powerpc powerpc: Handle .text.{hot,unlikely}.* in linker script 2021-01-12 20:16:17 +01:00
riscv arch: pgtable: define MAX_POSSIBLE_PHYSMEM_BITS where needed 2020-12-02 08:49:50 +01:00
s390 s390/kexec_file: fix diag308 subcode when loading crash kernel 2020-12-30 11:51:34 +01:00
sh sh: landisk: Add missing initialization of sh_io_port_base 2020-08-21 13:05:38 +02:00
sparc sparc: fix handling of page table constructor failure 2020-12-30 11:51:26 +01:00
um um: ubd: Submit all data segments atomically 2021-01-06 14:48:40 +01:00
unicore32 mm: treewide: clarify pgtable_page_{ctor,dtor}() naming 2019-09-26 10:10:44 -07:00
x86 x86/hyperv: check cpu mask after interrupt has been disabled 2021-01-19 18:26:12 +01:00
xtensa xtensa: uaccess: Add missing __user to strncpy_from_user() prototype 2020-12-02 08:49:49 +01:00
.gitignore
Kconfig Revert: "ring-buffer: Remove HAVE_64BIT_ALIGNED_ACCESS" 2020-12-30 11:51:47 +01:00