Message ID | 20231119053448.2367725-1-masahiroy@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp1504536vqn; Sat, 18 Nov 2023 21:35:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IGpokJxGggJ8Hd/nfCoiBpywa/MrYLYTxQ8U5yn1Nw38LbNU5EP6vmPJiLUorEuJVZ39gYu X-Received: by 2002:a05:6830:138b:b0:6d6:4c28:5579 with SMTP id d11-20020a056830138b00b006d64c285579mr4399130otq.8.1700372109421; Sat, 18 Nov 2023 21:35:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700372109; cv=none; d=google.com; s=arc-20160816; b=YXL3sNQemEcWF/URBWqssYJ4t3JJ/ClETvBo4t/xG/SOEKxKL4nqrYEJUrE6th3v76 Fh0/X2VE9OObUzt2x/XzwVvd3JJ/lALzpW3v1ecthwUOefOAw3sKw8ZvhdIVgAcMmYpE gq97x62GUl/VeNPaehwrMwV5LqpB6d6JldVntyzL/ftpWx6qy8HmFMfnyurQ9zg94R3J d5vM1gavPQRq+444oO5wV4pEKFuam0pPVfiq6NK8LPfdF1dvuN6C4OhXZbaxzBVfOCjm 8cf/b8zmxywzF+cBUHwdUZesjO+3YTcAdee/oqI4cZmem8yO5DgL/ZmP5hC6G8Js82Rk e4dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=l6KRPb5rQ42LF8Lv9fAhfJaMEF/I+z3SQmWO22W1Y5Y=; fh=MvfJMdVRrePe/l5NnvKVA1++6t22EBfcVd/W7TxEL1w=; b=gWUQmlMPNwd5jJHEEJffScNe5fdShvvkPlqVqYbG4KJkqI5kVTW88ie9fyXhTCzbFH AP09qBJFAz130q+ICO4hQ8R9a6v/uV9siw2BFxPbF4HZ0VWSMFaYzxcVQoF0IVbNOME5 aMjtFsrJiHtOfPoEidSvPBC3U7BO6q1KGHiNtDsN6Oa3EIJjL9W46yYU5WWGfQHpjHXM j7UigmHAh7iZZABDFy4apr7VUxnm382cpWpHDHALxd4pd2aJS4ysXxvKfYQZc6p2rKuG VrEOq9Ybk6je5jNWB/VBYESSCVVk5yJMCrBbTVpgOXC7F/SDvPtLsdBFQc738mFD//7v vL4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T7mlj5GU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id b2-20020a170902b60200b001ce5b7bd150si5219555pls.607.2023.11.18.21.35.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Nov 2023 21:35:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=T7mlj5GU; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 50E7B80A8B5F; Sat, 18 Nov 2023 21:35:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230204AbjKSFfE (ORCPT <rfc822;ouuuleilei@gmail.com> + 99 others); Sun, 19 Nov 2023 00:35:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbjKSFfC (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Sun, 19 Nov 2023 00:35:02 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98F4FE0 for <linux-kernel@vger.kernel.org>; Sat, 18 Nov 2023 21:34:59 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4417EC433C8; Sun, 19 Nov 2023 05:34:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700372099; bh=08ranJTDZ/V2FeaQz06DOfRs9FrKM8GbfKs8aPV/pJ0=; h=From:To:Cc:Subject:Date:From; b=T7mlj5GUg5Ir2bPEcJD672ID2zy1JFi6zQqSV/b06D0APxoOpxxRwLqkZJo9U/gho 4E91B5jnTQfg0EBCqq1aoHQ0G6MupKhi48gJ9n8a+NUPdQMXzBG4GYyUfsymrpMiTe QsasBKKCtXNl8rpQMWS7/R0Q4OzHmkr0g0hmPJpXeWu7ENeLji/9yYUc91/hGQo7jh OpGS3IipJk87W9vaifTYcSBrnn0q5dvfpkAPg/c4+xqrCHCEWOdJX5jmaDL4eXunKR aGDZVSLbP/6TnwyngJZ80Gl7jXmPNAi4g2GwixD6/udG90dSATaW7GkozapYOMzo8O dzFGWJ6aDxc1w== From: Masahiro Yamada <masahiroy@kernel.org> To: Huacai Chen <chenhuacai@kernel.org>, WANG Xuerui <kernel@xen0n.name>, loongarch@lists.linux.dev Cc: linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org, Ard Biesheuvel <ardb@kernel.org>, Simon Glass <sjg@chromium.org>, Masahiro Yamada <masahiroy@kernel.org> Subject: [PATCH] loongarch: add dependency between vmlinuz.efi and vmlinux.efi Date: Sun, 19 Nov 2023 14:34:48 +0900 Message-Id: <20231119053448.2367725-1-masahiroy@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Sat, 18 Nov 2023 21:35:08 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782969384894494215 X-GMAIL-MSGID: 1782969384894494215 |
Series |
loongarch: add dependency between vmlinuz.efi and vmlinux.efi
|
|
Commit Message
Masahiro Yamada
Nov. 19, 2023, 5:34 a.m. UTC
A common issue in Makefile is a race in parallel building.
You need to be careful to prevent multiple threads from writing to the
same file simultaneously.
Commit 3939f3345050 ("ARM: 8418/1: add boot image dependencies to not
generate invalid images") addressed such a bad scenario.
A similar symptom occurs with the following command:
$ make -j$(nproc) ARCH=loongarch vmlinux.efi vmlinuz.efi
[ snip ]
SORTTAB vmlinux
OBJCOPY arch/loongarch/boot/vmlinux.efi
OBJCOPY arch/loongarch/boot/vmlinux.efi
PAD arch/loongarch/boot/vmlinux.bin
GZIP arch/loongarch/boot/vmlinuz
OBJCOPY arch/loongarch/boot/vmlinuz.o
LD arch/loongarch/boot/vmlinuz.efi.elf
OBJCOPY arch/loongarch/boot/vmlinuz.efi
The log "OBJCOPY arch/loongarch/boot/vmlinux.efi" is displayed twice.
It indicates that two threads simultaneously enter arch/loongarch/boot/
and write to arch/loongarch/boot/vmlinux.efi.
It occasionally leads to a build failure:
$ make -j$(nproc) ARCH=loongarch vmlinux.efi vmlinuz.efi
[ snip ]
SORTTAB vmlinux
OBJCOPY arch/loongarch/boot/vmlinux.efi
PAD arch/loongarch/boot/vmlinux.bin
truncate: Invalid number: ‘arch/loongarch/boot/vmlinux.bin’
make[2]: *** [drivers/firmware/efi/libstub/Makefile.zboot:13:
arch/loongarch/boot/vmlinux.bin] Error 1
make[2]: *** Deleting file 'arch/loongarch/boot/vmlinux.bin'
make[1]: *** [arch/loongarch/Makefile:146: vmlinuz.efi] Error 2
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:234: __sub-make] Error 2
vmlinuz.efi depends on vmlinux.efi, but such a dependency is not
specified in arch/loongarch/Makefile.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
arch/loongarch/Makefile | 1 +
1 file changed, 1 insertion(+)
Comments
Hi, Masahiro, On Sun, Nov 19, 2023 at 1:35 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > > A common issue in Makefile is a race in parallel building. > > You need to be careful to prevent multiple threads from writing to the > same file simultaneously. > > Commit 3939f3345050 ("ARM: 8418/1: add boot image dependencies to not > generate invalid images") addressed such a bad scenario. > > A similar symptom occurs with the following command: > > $ make -j$(nproc) ARCH=loongarch vmlinux.efi vmlinuz.efi > [ snip ] > SORTTAB vmlinux > OBJCOPY arch/loongarch/boot/vmlinux.efi > OBJCOPY arch/loongarch/boot/vmlinux.efi > PAD arch/loongarch/boot/vmlinux.bin > GZIP arch/loongarch/boot/vmlinuz > OBJCOPY arch/loongarch/boot/vmlinuz.o > LD arch/loongarch/boot/vmlinuz.efi.elf > OBJCOPY arch/loongarch/boot/vmlinuz.efi > > The log "OBJCOPY arch/loongarch/boot/vmlinux.efi" is displayed twice. > > It indicates that two threads simultaneously enter arch/loongarch/boot/ > and write to arch/loongarch/boot/vmlinux.efi. > > It occasionally leads to a build failure: > > $ make -j$(nproc) ARCH=loongarch vmlinux.efi vmlinuz.efi > [ snip ] > SORTTAB vmlinux > OBJCOPY arch/loongarch/boot/vmlinux.efi > PAD arch/loongarch/boot/vmlinux.bin > truncate: Invalid number: ‘arch/loongarch/boot/vmlinux.bin’ > make[2]: *** [drivers/firmware/efi/libstub/Makefile.zboot:13: > arch/loongarch/boot/vmlinux.bin] Error 1 > make[2]: *** Deleting file 'arch/loongarch/boot/vmlinux.bin' > make[1]: *** [arch/loongarch/Makefile:146: vmlinuz.efi] Error 2 > make[1]: *** Waiting for unfinished jobs.... > make: *** [Makefile:234: __sub-make] Error 2 > > vmlinuz.efi depends on vmlinux.efi, but such a dependency is not > specified in arch/loongarch/Makefile. > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > --- > > arch/loongarch/Makefile | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile > index 9eeb0c05f3f4..6022bf3d30c9 100644 > --- a/arch/loongarch/Makefile > +++ b/arch/loongarch/Makefile > @@ -142,6 +142,7 @@ vdso-install-y += arch/loongarch/vdso/vdso.so.dbg > > all: $(notdir $(KBUILD_IMAGE)) > > +vmlinuz.efi: vmlinux.efi > vmlinux.elf vmlinux.efi vmlinuz.efi: vmlinux > $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@ It is a little strange, because in drivers/firmware/efi/libstub/Makefile.zboot: vmlinuz.efi depends on vmlinuz.efi.elf, vmlinuz.efi.elf depends on vmlinuz.o, vmlinuz.o depends on vmlinuz, vmlinuz depends on vmlinux.bin, vmlinux.bin depends on $(EFI_ZBOOT_PAYLOAD). in arch/loongarch/boot/Makefile, EFI_ZBOOT_PAYLOAD := vmlinux.efi So I think vmlinuz.efi has already depend on vmlinux.efi. Huacai > > -- > 2.40.1 > >
On Sun, Nov 19, 2023 at 8:59 PM Huacai Chen <chenhuacai@kernel.org> wrote: > > Hi, Masahiro, > > On Sun, Nov 19, 2023 at 1:35 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > > > > A common issue in Makefile is a race in parallel building. > > > > You need to be careful to prevent multiple threads from writing to the > > same file simultaneously. > > > > Commit 3939f3345050 ("ARM: 8418/1: add boot image dependencies to not > > generate invalid images") addressed such a bad scenario. > > > > A similar symptom occurs with the following command: > > > > $ make -j$(nproc) ARCH=loongarch vmlinux.efi vmlinuz.efi > > [ snip ] > > SORTTAB vmlinux > > OBJCOPY arch/loongarch/boot/vmlinux.efi > > OBJCOPY arch/loongarch/boot/vmlinux.efi > > PAD arch/loongarch/boot/vmlinux.bin > > GZIP arch/loongarch/boot/vmlinuz > > OBJCOPY arch/loongarch/boot/vmlinuz.o > > LD arch/loongarch/boot/vmlinuz.efi.elf > > OBJCOPY arch/loongarch/boot/vmlinuz.efi > > > > The log "OBJCOPY arch/loongarch/boot/vmlinux.efi" is displayed twice. > > > > It indicates that two threads simultaneously enter arch/loongarch/boot/ > > and write to arch/loongarch/boot/vmlinux.efi. > > > > It occasionally leads to a build failure: > > > > $ make -j$(nproc) ARCH=loongarch vmlinux.efi vmlinuz.efi > > [ snip ] > > SORTTAB vmlinux > > OBJCOPY arch/loongarch/boot/vmlinux.efi > > PAD arch/loongarch/boot/vmlinux.bin > > truncate: Invalid number: ‘arch/loongarch/boot/vmlinux.bin’ > > make[2]: *** [drivers/firmware/efi/libstub/Makefile.zboot:13: > > arch/loongarch/boot/vmlinux.bin] Error 1 > > make[2]: *** Deleting file 'arch/loongarch/boot/vmlinux.bin' > > make[1]: *** [arch/loongarch/Makefile:146: vmlinuz.efi] Error 2 > > make[1]: *** Waiting for unfinished jobs.... > > make: *** [Makefile:234: __sub-make] Error 2 > > > > vmlinuz.efi depends on vmlinux.efi, but such a dependency is not > > specified in arch/loongarch/Makefile. > > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > > --- > > > > arch/loongarch/Makefile | 1 + > > 1 file changed, 1 insertion(+) > > > > diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile > > index 9eeb0c05f3f4..6022bf3d30c9 100644 > > --- a/arch/loongarch/Makefile > > +++ b/arch/loongarch/Makefile > > @@ -142,6 +142,7 @@ vdso-install-y += arch/loongarch/vdso/vdso.so.dbg > > > > all: $(notdir $(KBUILD_IMAGE)) > > > > +vmlinuz.efi: vmlinux.efi > > vmlinux.elf vmlinux.efi vmlinuz.efi: vmlinux > > $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@ > It is a little strange, because > > in drivers/firmware/efi/libstub/Makefile.zboot: > vmlinuz.efi depends on vmlinuz.efi.elf, vmlinuz.efi.elf depends on > vmlinuz.o, vmlinuz.o depends on vmlinuz, vmlinuz depends on > vmlinux.bin, vmlinux.bin depends on $(EFI_ZBOOT_PAYLOAD). > > in arch/loongarch/boot/Makefile, > EFI_ZBOOT_PAYLOAD := vmlinux.efi > > So I think vmlinuz.efi has already depend on vmlinux.efi. That is a story in arch/loongarch/boot/Makefile. I am talking about arch/loongarch/Makefile, which is included from the top Makefile. See this code. vmlinux.elf vmlinux.efi vmlinuz.efi: vmlinux $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@ Only the required dependency is - vmlinux.elf depends on vmlinux - vmlinuz.elf depends on vmlinux vmlinux.elf and vmlinuz.elf are independent of each other. In parallel building, GNU Make considers that vmlinux.elf and vmlinuz.elf can be built simultaneously. GNU Make spawns two processes to execute these simultaneously: $(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/vmlinux.elf $(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/vmlinuz.elf The former enters arch/loongarch/boot/Makefile to build vmlinux.elf. (A) The latter also enters arch/loongarch/boot/Makefile to build vmlinuz.elf, which depends on vmlinux.elf (B) (A) and (B) are independent processes, hence none of them know the other. I hope it is clearer. > Huacai > > > > > -- > > 2.40.1 > > > > >
Hi, Masahiro, On Sun, Nov 19, 2023 at 10:25 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > > On Sun, Nov 19, 2023 at 8:59 PM Huacai Chen <chenhuacai@kernel.org> wrote: > > > > Hi, Masahiro, > > > > On Sun, Nov 19, 2023 at 1:35 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > > > > > > A common issue in Makefile is a race in parallel building. > > > > > > You need to be careful to prevent multiple threads from writing to the > > > same file simultaneously. > > > > > > Commit 3939f3345050 ("ARM: 8418/1: add boot image dependencies to not > > > generate invalid images") addressed such a bad scenario. > > > > > > A similar symptom occurs with the following command: > > > > > > $ make -j$(nproc) ARCH=loongarch vmlinux.efi vmlinuz.efi > > > [ snip ] > > > SORTTAB vmlinux > > > OBJCOPY arch/loongarch/boot/vmlinux.efi > > > OBJCOPY arch/loongarch/boot/vmlinux.efi > > > PAD arch/loongarch/boot/vmlinux.bin > > > GZIP arch/loongarch/boot/vmlinuz > > > OBJCOPY arch/loongarch/boot/vmlinuz.o > > > LD arch/loongarch/boot/vmlinuz.efi.elf > > > OBJCOPY arch/loongarch/boot/vmlinuz.efi > > > > > > The log "OBJCOPY arch/loongarch/boot/vmlinux.efi" is displayed twice. > > > > > > It indicates that two threads simultaneously enter arch/loongarch/boot/ > > > and write to arch/loongarch/boot/vmlinux.efi. > > > > > > It occasionally leads to a build failure: > > > > > > $ make -j$(nproc) ARCH=loongarch vmlinux.efi vmlinuz.efi > > > [ snip ] > > > SORTTAB vmlinux > > > OBJCOPY arch/loongarch/boot/vmlinux.efi > > > PAD arch/loongarch/boot/vmlinux.bin > > > truncate: Invalid number: ‘arch/loongarch/boot/vmlinux.bin’ > > > make[2]: *** [drivers/firmware/efi/libstub/Makefile.zboot:13: > > > arch/loongarch/boot/vmlinux.bin] Error 1 > > > make[2]: *** Deleting file 'arch/loongarch/boot/vmlinux.bin' > > > make[1]: *** [arch/loongarch/Makefile:146: vmlinuz.efi] Error 2 > > > make[1]: *** Waiting for unfinished jobs.... > > > make: *** [Makefile:234: __sub-make] Error 2 > > > > > > vmlinuz.efi depends on vmlinux.efi, but such a dependency is not > > > specified in arch/loongarch/Makefile. > > > > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > > > --- > > > > > > arch/loongarch/Makefile | 1 + > > > 1 file changed, 1 insertion(+) > > > > > > diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile > > > index 9eeb0c05f3f4..6022bf3d30c9 100644 > > > --- a/arch/loongarch/Makefile > > > +++ b/arch/loongarch/Makefile > > > @@ -142,6 +142,7 @@ vdso-install-y += arch/loongarch/vdso/vdso.so.dbg > > > > > > all: $(notdir $(KBUILD_IMAGE)) > > > > > > +vmlinuz.efi: vmlinux.efi > > > vmlinux.elf vmlinux.efi vmlinuz.efi: vmlinux > > > $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@ > > It is a little strange, because > > > > in drivers/firmware/efi/libstub/Makefile.zboot: > > vmlinuz.efi depends on vmlinuz.efi.elf, vmlinuz.efi.elf depends on > > vmlinuz.o, vmlinuz.o depends on vmlinuz, vmlinuz depends on > > vmlinux.bin, vmlinux.bin depends on $(EFI_ZBOOT_PAYLOAD). > > > > in arch/loongarch/boot/Makefile, > > EFI_ZBOOT_PAYLOAD := vmlinux.efi > > > > So I think vmlinuz.efi has already depend on vmlinux.efi. > > > > That is a story in arch/loongarch/boot/Makefile. > > > I am talking about arch/loongarch/Makefile, > which is included from the top Makefile. > > > See this code. > > > vmlinux.elf vmlinux.efi vmlinuz.efi: vmlinux > $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@ > > > > > Only the required dependency is > > - vmlinux.elf depends on vmlinux > - vmlinuz.elf depends on vmlinux > > > vmlinux.elf and vmlinuz.elf are independent of each other. > > > > In parallel building, GNU Make considers that > vmlinux.elf and vmlinuz.elf can be built simultaneously. > > > GNU Make spawns two processes to execute these simultaneously: > > $(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/vmlinux.elf > $(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/vmlinuz.elf > > > > The former enters arch/loongarch/boot/Makefile to build > vmlinux.elf. (A) > > > The latter also enters arch/loongarch/boot/Makefile to build > vmlinuz.elf, which depends on vmlinux.elf (B) > > > > (A) and (B) are independent processes, hence none of them > know the other. > > > I hope it is clearer. Sorry, I'm not familiar with Makefile rules, so you are probably right, but should we do it like this (remove the direct dependency from vmlinuz.efi to vmlinux)? vmlinuz.efi: vmlinux.efi vmlinux.elf vmlinux.efi: vmlinux $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@ Huacai > > > > > > > > Huacai > > > > > > > > -- > > > 2.40.1 > > > > > > > > > > > -- > Best Regards > Masahiro Yamada
On Mon, Nov 20, 2023 at 10:33 AM Huacai Chen <chenhuacai@kernel.org> wrote: > > Hi, Masahiro, > > On Sun, Nov 19, 2023 at 10:25 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > > > > On Sun, Nov 19, 2023 at 8:59 PM Huacai Chen <chenhuacai@kernel.org> wrote: > > > > > > Hi, Masahiro, > > > > > > On Sun, Nov 19, 2023 at 1:35 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > > > > > > > > A common issue in Makefile is a race in parallel building. > > > > > > > > You need to be careful to prevent multiple threads from writing to the > > > > same file simultaneously. > > > > > > > > Commit 3939f3345050 ("ARM: 8418/1: add boot image dependencies to not > > > > generate invalid images") addressed such a bad scenario. > > > > > > > > A similar symptom occurs with the following command: > > > > > > > > $ make -j$(nproc) ARCH=loongarch vmlinux.efi vmlinuz.efi > > > > [ snip ] > > > > SORTTAB vmlinux > > > > OBJCOPY arch/loongarch/boot/vmlinux.efi > > > > OBJCOPY arch/loongarch/boot/vmlinux.efi > > > > PAD arch/loongarch/boot/vmlinux.bin > > > > GZIP arch/loongarch/boot/vmlinuz > > > > OBJCOPY arch/loongarch/boot/vmlinuz.o > > > > LD arch/loongarch/boot/vmlinuz.efi.elf > > > > OBJCOPY arch/loongarch/boot/vmlinuz.efi > > > > > > > > The log "OBJCOPY arch/loongarch/boot/vmlinux.efi" is displayed twice. > > > > > > > > It indicates that two threads simultaneously enter arch/loongarch/boot/ > > > > and write to arch/loongarch/boot/vmlinux.efi. > > > > > > > > It occasionally leads to a build failure: > > > > > > > > $ make -j$(nproc) ARCH=loongarch vmlinux.efi vmlinuz.efi > > > > [ snip ] > > > > SORTTAB vmlinux > > > > OBJCOPY arch/loongarch/boot/vmlinux.efi > > > > PAD arch/loongarch/boot/vmlinux.bin > > > > truncate: Invalid number: ‘arch/loongarch/boot/vmlinux.bin’ > > > > make[2]: *** [drivers/firmware/efi/libstub/Makefile.zboot:13: > > > > arch/loongarch/boot/vmlinux.bin] Error 1 > > > > make[2]: *** Deleting file 'arch/loongarch/boot/vmlinux.bin' > > > > make[1]: *** [arch/loongarch/Makefile:146: vmlinuz.efi] Error 2 > > > > make[1]: *** Waiting for unfinished jobs.... > > > > make: *** [Makefile:234: __sub-make] Error 2 > > > > > > > > vmlinuz.efi depends on vmlinux.efi, but such a dependency is not > > > > specified in arch/loongarch/Makefile. > > > > > > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > > > > --- > > > > > > > > arch/loongarch/Makefile | 1 + > > > > 1 file changed, 1 insertion(+) > > > > > > > > diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile > > > > index 9eeb0c05f3f4..6022bf3d30c9 100644 > > > > --- a/arch/loongarch/Makefile > > > > +++ b/arch/loongarch/Makefile > > > > @@ -142,6 +142,7 @@ vdso-install-y += arch/loongarch/vdso/vdso.so.dbg > > > > > > > > all: $(notdir $(KBUILD_IMAGE)) > > > > > > > > +vmlinuz.efi: vmlinux.efi > > > > vmlinux.elf vmlinux.efi vmlinuz.efi: vmlinux > > > > $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@ > > > It is a little strange, because > > > > > > in drivers/firmware/efi/libstub/Makefile.zboot: > > > vmlinuz.efi depends on vmlinuz.efi.elf, vmlinuz.efi.elf depends on > > > vmlinuz.o, vmlinuz.o depends on vmlinuz, vmlinuz depends on > > > vmlinux.bin, vmlinux.bin depends on $(EFI_ZBOOT_PAYLOAD). > > > > > > in arch/loongarch/boot/Makefile, > > > EFI_ZBOOT_PAYLOAD := vmlinux.efi > > > > > > So I think vmlinuz.efi has already depend on vmlinux.efi. > > > > > > > > That is a story in arch/loongarch/boot/Makefile. > > > > > > I am talking about arch/loongarch/Makefile, > > which is included from the top Makefile. > > > > > > See this code. > > > > > > vmlinux.elf vmlinux.efi vmlinuz.efi: vmlinux > > $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@ > > > > > > > > > > Only the required dependency is > > > > - vmlinux.elf depends on vmlinux > > - vmlinuz.elf depends on vmlinux > > > > > > vmlinux.elf and vmlinuz.elf are independent of each other. > > > > > > > > In parallel building, GNU Make considers that > > vmlinux.elf and vmlinuz.elf can be built simultaneously. > > > > > > GNU Make spawns two processes to execute these simultaneously: > > > > $(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/vmlinux.elf > > $(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/vmlinuz.elf > > > > > > > > The former enters arch/loongarch/boot/Makefile to build > > vmlinux.elf. (A) > > > > > > The latter also enters arch/loongarch/boot/Makefile to build > > vmlinuz.elf, which depends on vmlinux.elf (B) > > > > > > > > (A) and (B) are independent processes, hence none of them > > know the other. > > > > > > I hope it is clearer. > Sorry, I'm not familiar with Makefile rules, so you are probably > right, but should we do it like this (remove the direct dependency > from vmlinuz.efi to vmlinux)? > > vmlinuz.efi: vmlinux.efi > vmlinux.elf vmlinux.efi: vmlinux > $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@ No. It would create only vmlinux.efi because there is no recipe line for vmlinuz.efi vmlinuz.efi: vmlinux.efi $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@ vmlinux.elf vmlinux.efi: vmlinux $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@ will work, but I do not want to repeat the same recipe line. > Huacai > > > > > > > > > > > > > > > > Huacai > > > > > > > > > > > -- > > > > 2.40.1 > > > > > > > > > > > > > > > > > -- > > Best Regards > > Masahiro Yamada
On Mon, Nov 20, 2023 at 12:45 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > > On Mon, Nov 20, 2023 at 10:33 AM Huacai Chen <chenhuacai@kernel.org> wrote: > > > > Hi, Masahiro, > > > > On Sun, Nov 19, 2023 at 10:25 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > > > > > > On Sun, Nov 19, 2023 at 8:59 PM Huacai Chen <chenhuacai@kernel.org> wrote: > > > > > > > > Hi, Masahiro, > > > > > > > > On Sun, Nov 19, 2023 at 1:35 PM Masahiro Yamada <masahiroy@kernel.org> wrote: > > > > > > > > > > A common issue in Makefile is a race in parallel building. > > > > > > > > > > You need to be careful to prevent multiple threads from writing to the > > > > > same file simultaneously. > > > > > > > > > > Commit 3939f3345050 ("ARM: 8418/1: add boot image dependencies to not > > > > > generate invalid images") addressed such a bad scenario. > > > > > > > > > > A similar symptom occurs with the following command: > > > > > > > > > > $ make -j$(nproc) ARCH=loongarch vmlinux.efi vmlinuz.efi > > > > > [ snip ] > > > > > SORTTAB vmlinux > > > > > OBJCOPY arch/loongarch/boot/vmlinux.efi > > > > > OBJCOPY arch/loongarch/boot/vmlinux.efi > > > > > PAD arch/loongarch/boot/vmlinux.bin > > > > > GZIP arch/loongarch/boot/vmlinuz > > > > > OBJCOPY arch/loongarch/boot/vmlinuz.o > > > > > LD arch/loongarch/boot/vmlinuz.efi.elf > > > > > OBJCOPY arch/loongarch/boot/vmlinuz.efi > > > > > > > > > > The log "OBJCOPY arch/loongarch/boot/vmlinux.efi" is displayed twice. > > > > > > > > > > It indicates that two threads simultaneously enter arch/loongarch/boot/ > > > > > and write to arch/loongarch/boot/vmlinux.efi. > > > > > > > > > > It occasionally leads to a build failure: > > > > > > > > > > $ make -j$(nproc) ARCH=loongarch vmlinux.efi vmlinuz.efi > > > > > [ snip ] > > > > > SORTTAB vmlinux > > > > > OBJCOPY arch/loongarch/boot/vmlinux.efi > > > > > PAD arch/loongarch/boot/vmlinux.bin > > > > > truncate: Invalid number: ‘arch/loongarch/boot/vmlinux.bin’ > > > > > make[2]: *** [drivers/firmware/efi/libstub/Makefile.zboot:13: > > > > > arch/loongarch/boot/vmlinux.bin] Error 1 > > > > > make[2]: *** Deleting file 'arch/loongarch/boot/vmlinux.bin' > > > > > make[1]: *** [arch/loongarch/Makefile:146: vmlinuz.efi] Error 2 > > > > > make[1]: *** Waiting for unfinished jobs.... > > > > > make: *** [Makefile:234: __sub-make] Error 2 > > > > > > > > > > vmlinuz.efi depends on vmlinux.efi, but such a dependency is not > > > > > specified in arch/loongarch/Makefile. > > > > > > > > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org> > > > > > --- > > > > > > > > > > arch/loongarch/Makefile | 1 + > > > > > 1 file changed, 1 insertion(+) > > > > > > > > > > diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile > > > > > index 9eeb0c05f3f4..6022bf3d30c9 100644 > > > > > --- a/arch/loongarch/Makefile > > > > > +++ b/arch/loongarch/Makefile > > > > > @@ -142,6 +142,7 @@ vdso-install-y += arch/loongarch/vdso/vdso.so.dbg > > > > > > > > > > all: $(notdir $(KBUILD_IMAGE)) > > > > > > > > > > +vmlinuz.efi: vmlinux.efi > > > > > vmlinux.elf vmlinux.efi vmlinuz.efi: vmlinux > > > > > $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@ > > > > It is a little strange, because > > > > > > > > in drivers/firmware/efi/libstub/Makefile.zboot: > > > > vmlinuz.efi depends on vmlinuz.efi.elf, vmlinuz.efi.elf depends on > > > > vmlinuz.o, vmlinuz.o depends on vmlinuz, vmlinuz depends on > > > > vmlinux.bin, vmlinux.bin depends on $(EFI_ZBOOT_PAYLOAD). > > > > > > > > in arch/loongarch/boot/Makefile, > > > > EFI_ZBOOT_PAYLOAD := vmlinux.efi > > > > > > > > So I think vmlinuz.efi has already depend on vmlinux.efi. > > > > > > > > > > > > That is a story in arch/loongarch/boot/Makefile. > > > > > > > > > I am talking about arch/loongarch/Makefile, > > > which is included from the top Makefile. > > > > > > > > > See this code. > > > > > > > > > vmlinux.elf vmlinux.efi vmlinuz.efi: vmlinux > > > $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@ > > > > > > > > > > > > > > > Only the required dependency is > > > > > > - vmlinux.elf depends on vmlinux > > > - vmlinuz.elf depends on vmlinux > > > > > > > > > vmlinux.elf and vmlinuz.elf are independent of each other. > > > > > > > > > > > > In parallel building, GNU Make considers that > > > vmlinux.elf and vmlinuz.elf can be built simultaneously. > > > > > > > > > GNU Make spawns two processes to execute these simultaneously: > > > > > > $(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/vmlinux.elf > > > $(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/vmlinuz.elf > > > > > > > > > > > > The former enters arch/loongarch/boot/Makefile to build > > > vmlinux.elf. (A) > > > > > > > > > The latter also enters arch/loongarch/boot/Makefile to build > > > vmlinuz.elf, which depends on vmlinux.elf (B) > > > > > > > > > > > > (A) and (B) are independent processes, hence none of them > > > know the other. > > > > > > > > > I hope it is clearer. > > Sorry, I'm not familiar with Makefile rules, so you are probably > > right, but should we do it like this (remove the direct dependency > > from vmlinuz.efi to vmlinux)? > > > > vmlinuz.efi: vmlinux.efi > > vmlinux.elf vmlinux.efi: vmlinux > > $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@ > > > > No. > > It would create only vmlinux.efi because there is > no recipe line for vmlinuz.efi > > > > > vmlinuz.efi: vmlinux.efi > $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@ > vmlinux.elf vmlinux.efi: vmlinux > $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@ > > > will work, but I do not want to repeat the same recipe line. > OK, I know, thank you very much. This patch will be applied to loongarch-fixes. Huacai > > > > > > > > > > > > > > > > > Huacai > > > > > > > > > > > > > > > > > > > > > > > > Huacai > > > > > > > > > > > > > > -- > > > > > 2.40.1 > > > > > > > > > > > > > > > > > > > > > > > -- > > > Best Regards > > > Masahiro Yamada > > > > -- > Best Regards > Masahiro Yamada
diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile index 9eeb0c05f3f4..6022bf3d30c9 100644 --- a/arch/loongarch/Makefile +++ b/arch/loongarch/Makefile @@ -142,6 +142,7 @@ vdso-install-y += arch/loongarch/vdso/vdso.so.dbg all: $(notdir $(KBUILD_IMAGE)) +vmlinuz.efi: vmlinux.efi vmlinux.elf vmlinux.efi vmlinuz.efi: vmlinux $(Q)$(MAKE) $(build)=$(boot) $(bootvars-y) $(boot)/$@