All of lore.kernel.org
 help / color / mirror / Atom feed
From: WANG Xuerui <kernel@xen0n.name>
To: Huacai Chen <chenhuacai@gmail.com>
Cc: Huacai Chen <chenhuacai@loongson.cn>,
	Arnd Bergmann <arnd@arndb.de>, Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Peter Zijlstra <peterz@infradead.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	David Airlie <airlied@linux.ie>, Jonathan Corbet <corbet@lwn.net>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	linux-arch <linux-arch@vger.kernel.org>,
	"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Xuefeng Li <lixuefeng@loongson.cn>,
	Yanteng Si <siyanteng@loongson.cn>, Guo Ren <guoren@kernel.org>,
	Jiaxun Yang <jiaxun.yang@flygoat.com>,
	Stephen Rothwell <sfr@canb.auug.org.au>,
	linux-efi <linux-efi@vger.kernel.org>,
	Ard Biesheuvel <ardb@kernel.org>
Subject: Re: [PATCH V10 09/22] LoongArch: Add boot and setup routines
Date: Mon, 16 May 2022 10:41:41 +0800	[thread overview]
Message-ID: <204b9bcf-07d3-1870-a7bb-ba8af7b27362@xen0n.name> (raw)
In-Reply-To: <CAAhV-H6yUKgew018Dj=9AyxYu0ofbBpG9vO3yjmyWSZ9S77BAA@mail.gmail.com>

Hi,

On 5/15/22 20:38, Huacai Chen wrote:
>>> diff --git a/arch/loongarch/kernel/head.S b/arch/loongarch/kernel/head.S
>>> new file mode 100644
>>> index 000000000000..f0b3e76bb762
>>> --- /dev/null
>>> +++ b/arch/loongarch/kernel/head.S
>>> @@ -0,0 +1,97 @@
>>> +/* SPDX-License-Identifier: GPL-2.0 */
>>> +/*
>>> + * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
>>> + */
>>> +#include <linux/init.h>
>>> +#include <linux/threads.h>
>>> +
>>> +#include <asm/addrspace.h>
>>> +#include <asm/asm.h>
>>> +#include <asm/asmmacro.h>
>>> +#include <asm/regdef.h>
>>> +#include <asm/loongarch.h>
>>> +#include <asm/stackframe.h>
>>> +#include <generated/compile.h>
>>> +#include <generated/utsrelease.h>
>>> +
>>> +#ifdef CONFIG_EFI_STUB
>>> +
>>> +#include "efi-header.S"
>>> +
>>> +     __HEAD
>>> +
>>> +_head:
>>> +     .word   MZ_MAGIC                /* "MZ", MS-DOS header */
>>> +     .org    0x28
>>> +     .ascii  "Loongson\0"            /* Magic number for BootLoader */
>> If you must use a magic number, "Loongson" is not recommended, because
>> this string lacks uniqueness in the Loongson/LoongArch world. Too many
>> things are called "Loongson foo" right now, and the string is so
>> ordinary people don't immediately think of it as "magic".
>>
>> I recommended using some other interesting text (and encoding) for the
>> magic number, in a different communication venue, but I think that
>> proposal got ignored by you without any explanation whatsoever. For now
>> I'll just repeat myself:
>>
>> For an interesting magic number related to Loongson/LoongArch/Loong
>> (like dragons but not exactly the same, let's not expand on that front)
>> in general, it's perhaps better to use GB18030-encoded four-character
>> dragon-related idioms. It's GB18030 because one Chinese character is 2
>> bytes in this encoding, and being non-UTF-8 it's unlikely any user input
>> would accidentally resemble it. So we get 8 bytes that appear as huge
>> negative numbers if cast into C long, and random enough that collisions
>> are highly unlikely.
>>
>> For example, I chose 4 famous dragon-related phrases from the I Ching,
>> in both simplified and traditional characters:
>>
>> 潜龙勿用: 0xc7b1c1facef0d3c3
>> 见龙在田: 0xbcfbc1fad4daccef
>> 飞龙在天: 0xb7c9c1fad4daccec
>> 亢龙有悔: 0xbfbac1fad3d0bbda
>> 潛龍勿用: 0x9d93fd88cef0d3c3
>> 見龍在田: 0xd28afd88d4daccef
>> 飛龍在天: 0xef77fd88d4daccec
>> 亢龍有悔: 0xbfbafd88d3d0bbda
>>
>> and I think each of them is better than "Loongson".
> ARM64_IMAGE_MAGIC is "ARM64", RISCV_IMAGE_MAGIC is "RISCV", so I think
> we use "Loongson" as a magic is just OK.

Actually you made a good point here, that I failed to check for myself 
earlier.

Looking at the arm64 and riscv image header code more closely, it seems 
loongarch is trying to follow the now deprecated riscv-specific practice 
of using 8-byte magic (deprecated as of commit 474efecb65dce ("riscv: 
modify the Image header to improve compatibility with the ARM64 
header")). In doing this they also changed the offset of the magic: on 
riscv it's at 0x30, while here it's at 0x28 (riscv's "res2" field). This 
is just the exact kind of "proliferation of image header formats" that 
we would want to avoid.

Now for some additional but important bikeshedding...

The current arm64 and riscv magic numbers are all 4-byte long, at offset 
0x38, and they are cute little strings identifying their origin: 
"ARM\x64" and "RSC\x05" respectively. Thus, for loongarch, we probably 
want to do the same -- 4-byte nice little strings with a hint of 
LoongArch/Loong. Considering UTF-8 uses 3 bytes for most Chinese 
characters, and 4 bytes for characters outside of BMP, we could use a 
little bit of creativity here:

- "LA64", the "dullest" version with only ASCII characters, but I don't 
know if future LA32 systems will want to use the same image header format;
- "\xe9\xbe\x99\x64" ("龙\x64") or "\xe9\xbe\x8d\x64" ("龍\x64") -- 龙/龍 
means "loong/dragon", hence a variant of the above;
- "\xf0\x9f\x90\xb2" ("🐲") or "\xf0\x9f\x90\x89" ("🐉") -- the 
loong/dragon emoji, taking full advantage of the 4 bytes available while 
not mentioning bitness.

A case might be made for pure-ASCII magic numbers, that they're easier 
for naked-eye inspection, but (1) this is already not the case for the 
new riscv magic, and (2) given all other interesting fields are in 
binary it's already necessary to use hex editors for any task more 
complex than mere identification.

So, I think the bottom line is: don't use the 8-byte magic at offset 
0x28, switch to 4-byte magic at offset 0x38 to keep consistent with 
everyone else. I don't actually have a preference, but personally I'd 
prefer some freshness in the low-level land, if that doesn't hamper 
people's flows. ;-)


  reply	other threads:[~2022-05-16  2:41 UTC|newest]

Thread overview: 77+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-14  8:03 [PATCH V10 00/22] arch: Add basic LoongArch support Huacai Chen
2022-05-14  8:03 ` [PATCH V10 01/22] Documentation: LoongArch: Add basic documentations Huacai Chen
2022-05-14 13:11   ` WANG Xuerui
2022-05-14 15:40     ` Huacai Chen
2022-05-15 12:41   ` Bagas Sanjaya
2022-05-15 13:14     ` Huacai Chen
2022-05-14  8:03 ` [PATCH V10 02/22] Documentation/zh_CN: Add basic LoongArch documentations Huacai Chen
2022-05-14 13:26   ` WANG Xuerui
2022-05-14 14:49     ` Huacai Chen
2022-05-15 14:14       ` Wu X.C.
2022-05-14  8:03 ` [PATCH V3 03/22] LoongArch: Add elf-related definitions Huacai Chen
2022-05-14 13:29   ` WANG Xuerui
2022-05-14 14:11     ` Huacai Chen
2022-05-15  4:13       ` WANG Xuerui
2022-05-15 11:47         ` Huacai Chen
2022-05-14  8:03 ` [PATCH V10 04/22] LoongArch: Add writecombine support for drm Huacai Chen
2022-05-15  4:18   ` WANG Xuerui
2022-05-15 11:50     ` Huacai Chen
2022-05-14  8:03 ` [PATCH V10 05/22] LoongArch: Add build infrastructure Huacai Chen
2022-05-14 13:38   ` WANG Xuerui
2022-05-14  8:03 ` [PATCH V10 06/22] LoongArch: Add CPU definition headers Huacai Chen
2022-05-14  8:03 ` [PATCH V10 07/22] LoongArch: Add atomic/locking headers Huacai Chen
2022-05-14  8:03 ` [PATCH V10 08/22] LoongArch: Add other common headers Huacai Chen
2022-05-15  0:01   ` Jason A. Donenfeld
2022-05-15 11:42     ` Huacai Chen
2022-05-14  8:03 ` [PATCH V10 09/22] LoongArch: Add boot and setup routines Huacai Chen
2022-05-15  8:44   ` WANG Xuerui
2022-05-15 12:38     ` Huacai Chen
2022-05-16  2:41       ` WANG Xuerui [this message]
2022-05-14  8:03 ` [PATCH V10 10/22] LoongArch: Add exception/interrupt handling Huacai Chen
2022-05-15  9:07   ` WANG Xuerui
2022-05-15 13:00     ` Huacai Chen
2022-05-14  8:03 ` [PATCH V10 11/22] LoongArch: Add process management Huacai Chen
2022-05-15  9:20   ` WANG Xuerui
2022-05-15 13:25     ` Huacai Chen
2022-05-14  8:03 ` [PATCH V10 12/22] LoongArch: Add memory management Huacai Chen
2022-05-15  9:42   ` WANG Xuerui
2022-05-15 13:38     ` Huacai Chen
2022-05-14  8:03 ` [PATCH V10 13/22] LoongArch: Add system call support Huacai Chen
2022-05-14 13:53   ` WANG Xuerui
2022-05-14 14:39     ` Huacai Chen
2022-05-15  9:47       ` WANG Xuerui
2022-05-14  8:03 ` [PATCH V10 14/22] LoongArch: Add signal handling support Huacai Chen
2022-05-15 10:39   ` WANG Xuerui
2022-05-15 13:48     ` Huacai Chen
2022-05-16  3:51       ` WANG Xuerui
     [not found]         ` <87bkvxd12b.fsf@email.froward.int.ebiederm.org>
2022-05-16 15:02           ` WANG Xuerui
2022-05-17  2:08           ` Huacai Chen
2022-05-17 15:36             ` Eric W. Biederman
2022-05-14  8:03 ` [PATCH V10 15/22] LoongArch: Add ELF and module support Huacai Chen
2022-05-15 11:03   ` WANG Xuerui
2022-05-15 14:13     ` Huacai Chen
2022-05-14  8:03 ` [PATCH V10 16/22] LoongArch: Add misc common routines Huacai Chen
2022-05-14 12:56   ` Alexandre Belloni
2022-05-14 14:12     ` Huacai Chen
2022-05-14 16:00       ` Alexandre Belloni
2022-05-15 13:03   ` WANG Xuerui
2022-05-15 14:21     ` Huacai Chen
2022-05-14  8:03 ` [PATCH V10 17/22] LoongArch: Add some library functions Huacai Chen
2022-05-15 13:11   ` WANG Xuerui
2022-05-15 14:27     ` Huacai Chen
2022-05-14  8:03 ` [PATCH V10 18/22] LoongArch: Add PCI controller support Huacai Chen
2022-05-15 13:35   ` WANG Xuerui
2022-05-14  8:03 ` [PATCH V10 19/22] LoongArch: Add VDSO and VSYSCALL support Huacai Chen
2022-05-15 14:47   ` WANG Xuerui
2022-05-15 14:52     ` Huacai Chen
2022-05-14  8:04 ` [PATCH V10 20/22] LoongArch: Add multi-processor (SMP) support Huacai Chen
2022-05-15 14:16   ` WANG Xuerui
2022-05-15 14:47     ` Huacai Chen
2022-05-14  8:04 ` [PATCH V10 21/22] LoongArch: Add Non-Uniform Memory Access (NUMA) support Huacai Chen
2022-05-15 14:27   ` WANG Xuerui
2022-05-15 14:49     ` Huacai Chen
2022-05-14  8:04 ` [PATCH V10 22/22] LoongArch: Add Loongson-3 default config file Huacai Chen
2022-05-15 14:30   ` WANG Xuerui
2022-05-14 20:54 ` [PATCH V10 00/22] arch: Add basic LoongArch support Arnd Bergmann
2022-05-16  7:41   ` Huacai Chen
2022-05-15 15:09 ` WANG Xuerui

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=204b9bcf-07d3-1870-a7bb-ba8af7b27362@xen0n.name \
    --to=kernel@xen0n.name \
    --cc=airlied@linux.ie \
    --cc=akpm@linux-foundation.org \
    --cc=ardb@kernel.org \
    --cc=arnd@arndb.de \
    --cc=chenhuacai@gmail.com \
    --cc=chenhuacai@loongson.cn \
    --cc=corbet@lwn.net \
    --cc=guoren@kernel.org \
    --cc=jiaxun.yang@flygoat.com \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lixuefeng@loongson.cn \
    --cc=luto@kernel.org \
    --cc=peterz@infradead.org \
    --cc=sfr@canb.auug.org.au \
    --cc=siyanteng@loongson.cn \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.