Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Tiezhu Yang <yangtiezhu@loongson.cn>
To: Huacai Chen <chenhuacai@kernel.org>
Cc: Will Deacon <will@kernel.org>,
	Josh Poimboeuf <jpoimboe@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Paul Walmsley <pjw@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	"Madhavan T. Venkataraman" <madvenka@linux.microsoft.com>,
	Ard Biesheuvel <ardb@kernel.org>,
	loongarch@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	linux-riscv@lists.infradead.org, linux-efi@vger.kernel.org,
	linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org,
	Nathan Chancellor <nathan@kernel.org>
Subject: Re: [PATCH v2] efistub: Only link libstub to final vmlinux
Date: Sun, 23 Nov 2025 11:37:14 +0800	[thread overview]
Message-ID: <fc4fa66f-15a0-ebe3-0a27-f3f38b03bbdb@loongson.cn> (raw)
In-Reply-To: <CAAhV-H4fHBuRpDEDQrExApgnREJaT8JWUJ2700bEPFxDqToi2w@mail.gmail.com>

On 11/23/25 10:29, Huacai Chen wrote:
> On Sat, Nov 22, 2025 at 7:04 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>>
>> Cc: Nathan Chancellor <nathan@kernel.org>
>>
>> Hi all,
>>
>> On 11/21/25 22:36, Huacai Chen wrote:
>>> On Mon, Nov 17, 2025 at 7:33 PM Will Deacon <will@kernel.org> wrote:
>>>>
>>>> On Sat, Nov 15, 2025 at 11:16:42AM +0800, Huacai Chen wrote:
>>>>> On Wed, Nov 12, 2025 at 2:00 AM Josh Poimboeuf <jpoimboe@kernel.org> wrote:
>>>>>>
>>>>>> On Mon, Nov 10, 2025 at 03:00:00PM +0800, Huacai Chen wrote:
>>>>>>> On Mon, Nov 10, 2025 at 9:19 AM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
>>>>>>>> If I understand correctly, I should modify this patch to remove the
>>>>>>>> changes of arm and riscv for now, do the changes only when there is
>>>>>>>> a real problem or requirement some day, right? If no more comments,
>>>>>>>> I will send v3 later.
>>>>>>>
>>>>>>> Now everyone involved agrees that the efistub code is correct, so the
>>>>>>> proper solution is to fix the compiler.
>>>>>>
>>>>>> Hm?  I don't see how it's a compiler bug.  It's really just an objtool
>>>>>> limitation.
>>>>>>
>>>>>>> Changing efistub code and changing objtool (ignore __efistub prefix)
>>>>>>> are both workarounds, but I think changing objtool is a little more
>>>>>>> reasonable. Maybe Josh has different ideas?
>>>>>>
>>>>>> I thought the conversation had converged on what Tiezhu mentioned above,
>>>>>> which is to skip objtool on libstub for loongarch, but leave the other
>>>>>> arches alone.  That way objtool behavior is consistent between loongarch
>>>>>> and x86, and objtool doesn't need to ignore any prefixes.
>>>>>>
>>>>>> So basically, the v2 patch minus the arm64/riscv changes.
>>>>>
>>>>> Hi, ARM64 and RISC-V maintainers,
>>>>>
>>>>> Would you mind that this patch modifies the three architectures
>>>>> together (they are exactly the same style now)?
>>>>>
>>>>> Madhavan is the author of ARM64's objtool, I think your opinion is
>>>>> also very important.
>>>>
>>>> arm64 doesn't (yet) use objtool.
>>>>
>>>> I defer to Ard on anything relating to the arm64 efistub. Reading the
>>>> start of this thread, it doesn't look like he's convinced and I'm not
>>>> surprised if it's purely an issue with objtool.
>>> OK, I know, but I have a concern.
>>>
>>> Ard said that he is reluctant to make changes to accommodate a flawed
>>> build time tool and there may be regression risk.
>>>
>>> So, I'm also reluctant and don't want LoongArch to meet regression
>>> risk. If one day LoongArch has a regression, we probably need another
>>> workaround to "fix" this workaround. But if these three architectures
>>> change in the same way, we may have a chance to solve some fundamental
>>> problems...
>>
>> IIUC, Josh do not like to ignore these EFISTUB functions in
>> validate_branch() of objtool, Huacai do not like to only link
>> libstub to vmlinux only for LoongArch.
>>
>> It seems that there is only one way to fix or workaround this
>> problem, remove the attribute __noreturn for real_kernel_entry()
>> and then make efi_boot_kernel() ends with a return instruction [1]
>> or an unconditional jump instruction [2] that only touches
>> drivers/firmware/efi/libstub/loongarch.c.
>>
>> Since this is a issue only for LoongArch by now, what do you
>> think of this minimal change only for LoongArch libstub code?
>> Using "return EFI_LOAD_ERROR" [1] or "while (1)" [2]?
>>
>> Maybe this is the simple and direct way for this special issue
>> only on LoongArch so far. If not, any other suggestions?
>>
>> On the other hand, is it possible to add KBUILD_VMLINUX_LIBS_FINAL
>> and then use it only for LoongArch first [3]? Any potential risks?
>>
>> What is the next step?
> Is it possible to improve objtool that can handle indirect __noreturn functions?
> Is it possible to improve objtool that can handle
> OBJECT_FILES_NON_STANDARD event LTO is enabled?
> Is it possible to improve objtool that only ignore __efistub prefix
> for LoongArch?

I think a new arch_is_efistub() can be added in objtool
to handle this issue only for LoongArch, something like:

bool arch_is_retpoline(struct symbol *sym);
bool arch_is_rethunk(struct symbol *sym);
bool arch_is_embedded_insn(struct symbol *sym);

This is valid for LoongArch and will not affect x86,
arm64 and riscv can implement it some day.

The code looks like:

tools/objtool/include/objtool/arch.h:
bool arch_is_efistub(struct symbol *sym);

tools/objtool/check.c:
__weak bool arch_is_efistub(struct symbol *sym)
{
	return false;
}

tools/objtool/arch/loongarch/decode.c:
bool arch_is_efistub(struct symbol *sym)
{
	return !strncmp(func->name, "__efistub_", 10));
}

tools/objtool/check.c:
static int validate_branch()
{
...
			if (arch_is_efistub(func))
				return 0;

			if (file->ignore_unreachables)
				return 0;

			WARN("%s() falls through to next function %s()",
			     func->name, insn_func(insn)->name);
			func->warned = 1;

			return 1;
...
}

Let us wait for Josh's opinion.

Thanks,
Tiezhu



  reply	other threads:[~2025-11-23  3:37 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-28  8:55 [PATCH v2] efistub: Only link libstub to final vmlinux Tiezhu Yang
2025-09-28 13:41 ` Ard Biesheuvel
2025-09-28 13:52   ` Huacai Chen
2025-09-28 14:39     ` Ard Biesheuvel
2025-09-28 14:41       ` Ard Biesheuvel
2025-10-09  7:27         ` Tiezhu Yang
2025-10-10 16:25           ` Ard Biesheuvel
2025-10-11  1:13             ` Tiezhu Yang
2025-10-11  2:54               ` Huacai Chen
2025-10-11  3:40                 ` Ard Biesheuvel
2025-10-11  7:29                   ` Tiezhu Yang
2025-10-11  7:42                     ` Huacai Chen
2025-10-11  8:13                       ` Tiezhu Yang
2025-10-11 14:48                       ` Ard Biesheuvel
2025-10-11 15:01                         ` Huacai Chen
2025-10-11 15:58                           ` Ard Biesheuvel
2025-10-13  7:34                             ` Tiezhu Yang
2025-10-13 14:09                             ` Huacai Chen
2025-10-13 14:36                               ` Ard Biesheuvel
2025-10-14 16:47                                 ` Josh Poimboeuf
2025-10-16 14:52                                   ` Ard Biesheuvel
2025-10-16 15:49                                     ` Josh Poimboeuf
2025-10-17 11:00                                       ` Ard Biesheuvel
2025-10-17 16:22                                         ` Josh Poimboeuf
2025-10-17 16:26                                           ` Ard Biesheuvel
2025-10-17 17:05                                             ` Josh Poimboeuf
2025-10-20  1:24                                               ` Tiezhu Yang
2025-10-20  6:55                                                 ` Huacai Chen
2025-10-23  6:55                                                   ` Tiezhu Yang
2025-10-23  8:01                                                     ` Huacai Chen
2025-10-23  8:06                                                       ` Ard Biesheuvel
2025-10-26 11:20                                                         ` Huacai Chen
2025-10-28 13:47                                                           ` Ard Biesheuvel
2025-11-10  1:18                                                             ` Tiezhu Yang
2025-11-10  7:00                                                               ` Huacai Chen
2025-11-11 16:49                                                                 ` Ard Biesheuvel
2025-11-11 18:00                                                                 ` Josh Poimboeuf
2025-11-15  3:16                                                                   ` Huacai Chen
2025-11-17 11:33                                                                     ` Will Deacon
2025-11-21  2:09                                                                       ` Paul Walmsley
2025-11-21 14:36                                                                       ` Huacai Chen
2025-11-22 11:04                                                                         ` Tiezhu Yang
2025-11-23  2:29                                                                           ` Huacai Chen
2025-11-23  3:37                                                                             ` Tiezhu Yang [this message]
2025-11-25  1:49                                                                               ` Josh Poimboeuf
2025-11-28 10:11                                                                                 ` Huacai Chen
2025-09-30  2:52       ` Huacai Chen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=fc4fa66f-15a0-ebe3-0a27-f3f38b03bbdb@loongson.cn \
    --to=yangtiezhu@loongson.cn \
    --cc=aou@eecs.berkeley.edu \
    --cc=ardb@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=chenhuacai@kernel.org \
    --cc=jpoimboe@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=loongarch@lists.linux.dev \
    --cc=madvenka@linux.microsoft.com \
    --cc=nathan@kernel.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox