* [PATCH v8 0/8] Add generated modalias to modules.builtin.modinfo
From: Alexey Gladkov @ 2025-09-18 8:05 UTC (permalink / raw)
To: Nathan Chancellor, Nicolas Schier, Petr Pavlu, Luis Chamberlain,
Sami Tolvanen, Daniel Gomez
Cc: linux-kernel, linux-modules, linux-kbuild, Alexey Gladkov
The modules.builtin.modinfo file is used by userspace (kmod to be specific) to
get information about builtin modules. Among other information about the module,
information about module aliases is stored. This is very important to determine
that a particular modalias will be handled by a module that is inside the
kernel.
There are several mechanisms for creating modalias for modules:
The first is to explicitly specify the MODULE_ALIAS of the macro. In this case,
the aliases go into the '.modinfo' section of the module if it is compiled
separately or into vmlinux.o if it is builtin into the kernel.
The second is the use of MODULE_DEVICE_TABLE followed by the use of the
modpost utility. In this case, vmlinux.o no longer has this information and
does not get it into modules.builtin.modinfo.
For example:
$ modinfo pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30
modinfo: ERROR: Module pci:v00008086d0000A36Dsv00001043sd00008694bc0Csc03i30 not found.
$ modinfo xhci_pci
name: xhci_pci
filename: (builtin)
license: GPL
file: drivers/usb/host/xhci-pci
description: xHCI PCI Host Controller Driver
The builtin module is missing alias "pci:v*d*sv*sd*bc0Csc03i30*" which will be
generated by modpost if the module is built separately.
To fix this it is necessary to add the generated by modpost modalias to
modules.builtin.modinfo. Fortunately modpost already generates .vmlinux.export.c
for exported symbols. It is possible to add `.modinfo` for builtin modules and
modify the build system so that `.modinfo` section is extracted from the
intermediate vmlinux after modpost is executed.
---
Notes:
- v8:
* Fix build warnings about unused variable.
* Fix objcopy "warning: empty loadable segment detected ...".
* v7: https://lore.kernel.org/all/cover.1755535876.git.legion@kernel.org/
- v7:
* Reorder patches to avoid unnecessary linker warnings on s390.
* Drop the patch for pinctrl since it's already been applied.
* v6: https://lore.kernel.org/all/cover.1755170493.git.legion@kernel.org/
- v6:
* Rebase to v6.17-rc1-16-g8742b2d8935f to pick up the fixes made by Masahiro Yamada.
* Fix an issue on i386 configs caused by the use of string_32.h.
* v5: https://lore.kernel.org/all/cover.1753354215.git.legion@kernel.org/
- v5:
* Rebase to v6.16-rc6-281-gf4a40a4282f4 to pick up the fixes made by Masahiro Yamada.
* Attempt to fix linker warning on s390.
* Fix typo in pinctrl/meson found by the kernel test robot.
* v4: https://lore.kernel.org/all/cover.1750511018.git.legion@kernel.org/
- v4:
* Rework the patchset based on top of Masahiro Yamada's patches.
* Add removal of unnecessary __mod_device_table__* symbols to avoid symbol
table growth in vmlinux.
* rust code takes into account changes in __mod_device_table__*.
* v3: https://lore.kernel.org/all/cover.1748335606.git.legion@kernel.org/
- v3:
* Add `Reviewed-by` tag to patches from Petr Pavlu.
* Rebase to v6.15.
* v2: https://lore.kernel.org/all/20250509164237.2886508-1-legion@kernel.org/
- v2:
* Drop patch for mfd because it was already applied and is in linux-next.
* The generation of aliases for builtin modules has been redone as
suggested by Masahiro Yamada.
* Rebase to v6.15-rc5-136-g9c69f8884904
* v1: https://lore.kernel.org/all/cover.1745591072.git.legion@kernel.org/
Alexey Gladkov (5):
s390: vmlinux.lds.S: Reorder sections
scsi: Always define blogic_pci_tbl structure
modpost: Add modname to mod_device_table alias
modpost: Create modalias for builtin modules
kbuild: vmlinux.unstripped should always depend on .vmlinux.export.o
Masahiro Yamada (3):
kbuild: always create intermediate vmlinux.unstripped
kbuild: keep .modinfo section in vmlinux.unstripped
kbuild: extract modules.builtin.modinfo from vmlinux.unstripped
arch/s390/kernel/vmlinux.lds.S | 10 ++--
drivers/scsi/BusLogic.c | 4 +-
include/asm-generic/vmlinux.lds.h | 2 +-
include/linux/module.h | 18 +++++--
rust/kernel/device_id.rs | 8 ++--
scripts/Makefile.vmlinux | 79 ++++++++++++++++++++-----------
scripts/Makefile.vmlinux_o | 26 +---------
scripts/link-vmlinux.sh | 5 +-
scripts/mksysmap | 6 +++
scripts/mod/file2alias.c | 34 +++++++++++--
scripts/mod/modpost.c | 15 ++++++
scripts/mod/modpost.h | 2 +
12 files changed, 131 insertions(+), 78 deletions(-)
base-commit: aa943a280e88e3585ed5a06d55e78c4123fcead3
--
2.51.0
^ permalink raw reply
* Re: [PATCH v7 3/8] kbuild: keep .modinfo section in vmlinux.unstripped
From: Nicolas Schier @ 2025-09-18 4:08 UTC (permalink / raw)
To: Alexey Gladkov
Cc: Nathan Chancellor, Petr Pavlu, Luis Chamberlain, Sami Tolvanen,
Daniel Gomez, linux-kernel, linux-modules, linux-kbuild,
Masahiro Yamada
In-Reply-To: <aMqrrjXZxYXN0zdY@example.org>
On Wed, Sep 17, 2025 at 02:38:06PM +0200, Alexey Gladkov wrote:
> On Wed, Sep 17, 2025 at 01:55:36PM +0200, Nicolas Schier wrote:
> > On Tue, Sep 16, 2025 at 02:42:48PM +0200, Nicolas Schier wrote:
> > > On Tue, Sep 16, 2025 at 01:30:20PM +0200, Alexey Gladkov wrote:
> > ...
> > > > I think in the case of .modinfo, we can change the flag in the section
> > > > since we are going to delete it anyway.
> > > >
> > > > diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> > > > index dbbe3bf0cf23..9a118b31d0dc 100644
> > > > --- a/scripts/Makefile.vmlinux
> > > > +++ b/scripts/Makefile.vmlinux
> > > > @@ -87,7 +87,8 @@ remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> > > > remove-symbols := -w --strip-symbol='__mod_device_table__*'
> > > >
> > > > quiet_cmd_strip_relocs = OBJCOPY $@
> > > > - cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
> > > > + cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< && \
> > > > + $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
> > > > $(remove-symbols) $< $@
> > > >
> > > > targets += vmlinux
> > >
> > > Ah, great! I thought we had to fiddle around with linker scripts et al.
> > > I needed to use an intermediate file:
> > >
> > > diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> > > index e2ceeb9e168d..516d51ca634b 100644
> > > --- a/scripts/Makefile.vmlinux
> > > +++ b/scripts/Makefile.vmlinux
> > > @@ -90,6 +90,9 @@ remove-section-y := .modinfo
> > > remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> > >
> > > quiet_cmd_strip_relocs = OBJCOPY $@
> > > - cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $< $@
> > > + cmd_strip_relocs = set -e; \
> > > + trap 'rm $<.noload' EXIT HUP INT; \
> > > + $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $<.noload && \
> > > + $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $<.noload $@
> > >
> > > targets += vmlinux
> >
> > I'd like to suggest another version closer to yours, as mine has several flaws:
> >
> > diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> > index dbbe3bf0cf23..9a118b31d0dc 100644
> > --- a/scripts/Makefile.vmlinux
> > +++ b/scripts/Makefile.vmlinux
> > @@ -87,7 +87,8 @@ remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> > remove-symbols := -w --strip-symbol='__mod_device_table__*'
> >
> > quiet_cmd_strip_relocs = OBJCOPY $@
> > - cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
> > + cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $@; \
> > + $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
> > $(remove-symbols) $@
> >
> > targets += vmlinux
> >
> >
> >
> > Rationale (mainly for myself to not walk into that trap too often again):
> >
> > * Use ';' instead of '&&' as 'cmd_' is evaluated in a 'set -e'
> > environment ('cmd') and thus '&&' may hide a possible error exit
> > code.
>
> No, it can't hide exit code. The exit code will be correct even if
> ‘set -e’ is not used.
>
> $ (exit 0) && (exit 2) && (exit 3); echo $?
> 2
>
> Actually ‘&&’ is protection against the absence of ‘set -e’.
That is correct for such a simple command sequence.
Putting a compound 'command1 && command2' sequence in a cmd_* macro leads to a
mixture of non-comound and compound statements:
( set -e; (exit 0) && (exit 2) && (exit 3); printf 'bye\n' ); echo $?
thus we have a case as described in [1, "-e"], so that the exit code 2
gets lost due to the following successful 'printf'.
[1]: https://pubs.opengroup.org/onlinepubs/9799919799/utilities/V3_chap02.html#tag_19_26
>
> > * Create 'vmlinux' already with the first objcopy and let the second
> > one modify it in order to not need a temporary file; iff one or the
> > other objcopy exists with an error exit code, the 'set -e + trap'
> > ('delete-on-interrupt') shell will remove a possibly existing
> > vmlinux file.
>
> That makes totally sense. This will avoid a temporary file. I will use it
> in the new version.
>
> --
> Rgrds, legion
>
--
Nicolas
^ permalink raw reply
* Re: [PATCH v3 4/4] ALSA: doc: add docs about device_device_quirk_flags in snd-usb-audio
From: Randy Dunlap @ 2025-09-17 17:58 UTC (permalink / raw)
To: cryolitia, Jaroslav Kysela, Takashi Iwai, Jonathan Corbet,
Luis Chamberlain, Petr Pavlu, Daniel Gomez, Sami Tolvanen
Cc: linux-sound, linux-usb, linux-kernel, linux-doc, Mingcong Bai,
Kexy Biscuit, Nie Cheng, Zhan Jun, Feng Yuan, qaqland, kernel,
linux-modules
In-Reply-To: <20250917-sound-v3-4-92ebe9472a0a@uniontech.com>
On 9/17/25 5:46 AM, Cryolitia PukNgae via B4 Relay wrote:
> @@ -2344,8 +2386,8 @@ report it to the upstream.
> NB: ``quirk_alias`` option is provided only for testing / development.
> If you want to have a proper support, contact to upstream for
> adding the matching quirk in the driver code statically.
> -Ditto for ``quirk_flags``. If a device is known to require specific
> -workarounds, please report to the upstream.
> +Ditto for ``quirk_flags``. If a device
> +is known to require specific workarounds, please report to the upstream.
What is the purpose of this change?
--
~Randy
^ permalink raw reply
* Re: [PATCH v3 4/4] ALSA: doc: add docs about device_device_quirk_flags in snd-usb-audio
From: Cryolitia @ 2025-09-17 14:09 UTC (permalink / raw)
To: Dragan Simic
Cc: Jaroslav Kysela, Takashi Iwai, Jonathan Corbet, Luis Chamberlain,
PetrPavlu, Daniel Gomez, SamiTolvanen, linux-sound, linux-usb,
linux-kernel, linux-doc, Mingcong Bai, Kexy Biscuit,
聂诚, 占俊, 冯园,
安国立, kernel, linux-modules
In-Reply-To: <0999abc5390bbfcb21e15bd140510540@manjaro.org>
> Hello Cryolitia,
>
> On 2025-09-17 14:46, Cryolitia PukNgae via B4 Relay wrote:
>> From: Cryolitia PukNgae <cryolitia@uniontech.com>
>>
>> Just briefly described about the new option.
>>
>> Signed-off-by: Cryolitia PukNgae <cryolitia@uniontech.com>
> Isn't the patch subject a bit wrong, and should contain
> "device quirk_flags" instead of "device_device_quirk_flags"?
Sorry for that, I forget to re-write the commit message.
Thx for pointing out.
Best regards,
Cryolitia PukNgae
^ permalink raw reply
* Re: [PATCH v3 3/4] ALSA: usb-audio: add module param device_quirk_flags
From: Takashi Iwai @ 2025-09-17 13:45 UTC (permalink / raw)
To: cryolitia, Cryolitia PukNgae via B4 Relay
Cc: Jaroslav Kysela, Takashi Iwai, Jonathan Corbet, Luis Chamberlain,
Petr Pavlu, Daniel Gomez, Sami Tolvanen, linux-sound, linux-usb,
linux-kernel, linux-doc, Mingcong Bai, Kexy Biscuit, Nie Cheng,
Zhan Jun, Feng Yuan, qaqland, kernel, linux-modules, Takashi Iwai
In-Reply-To: <20250917-sound-v3-3-92ebe9472a0a@uniontech.com>
On Wed, 17 Sep 2025 14:46:42 +0200,
Cryolitia PukNgae via B4 Relay wrote:
>
> From: Cryolitia PukNgae <cryolitia@uniontech.com>
>
> For apply and unapply quirk flags more flexibly though param and sysfs
>
> Co-developed-by: Takashi Iwai <tiwai@suse.de>
> Signed-off-by: Cryolitia PukNgae <cryolitia@uniontech.com>
I think an easier approach would be to rather parse the string value
at each time when probing a device and seeking for options.
That is, let's code without a mutex at first (for the permission
0444):
void snd_usb_init_dynamic_quirks(int idx, struct snd_usb_audio *chip)
{
....
/* old style option found: the position-based integer value */
if (quirk_flags[idx] &&
!kstrtou32(quirk_flags[idx], 0, &chip->quirk_flags)) {
usb_audio_dbg(....);
return;
}
/* take the default quirk from the quirk table */
snd_usb_init_quirk_flags(chip);
for (i = 0; i < ARRAY_SIZE(quirk_flags); i++) {
if (quirk_flags[i] && *quirk_flags[i]) {
err = parse_quirk_option(chip, quirk_flags[i]);
if (err < 0)
return;
}
}
}
and the parser would be something like:
static int parse_quirk_option(struct snd_usb_audio *chip, const char *str)
{
char *val __free(kfree) = NULL;
char *field;
int pid, vid;
if (!strchr(str, ':'))
return 0;
val = kstrdup(str, GFP_KERNEL);
if (!val)
return -ENOMEM;
/* Each entry consists of VID:PID:flags */
field = strsep(&p, ":");
if (!field)
return 0;
if (strcmp(field, "*") == 0)
vid = 0;
else if (kstrtou16(field, 16, &vid))
return 0; // can spew warning message, too
field = strsep(&p, ":");
if (!field)
return 0;
if (strcmp(field, "*") == 0)
pid = 0;
else if (kstrtou16(field, 16, &pid))
return 0; // can spew warning message, too
.... // evaluate the tokens, set or clear chip->quirk_flags accordingly
return 0;
}
So you can just use the normal charp type for the parameters.
Once after this working, we may want to allow the dynamic module
parameter change. Then make the parameter a special type just to take
the device_quirk_mutex at set callback, while the set callback simply
calls parm_set_charp() for the rest. For get and free callbacks, we
can use param_get_charp() and param_free_charp() as is.
Finally, snd_usb_init_dynamic_quirks() takes the device_quirk_mutex,
and that's all. No need for heavy cleanups or linked list handling.
Of course, it's a bit inefficient from the performance POV, but the
device probing is rather a very rare event, so the speed doesn't
matter at all.
thanks,
Takashi
^ permalink raw reply
* Re: [PATCH v3 4/4] ALSA: doc: add docs about device_device_quirk_flags in snd-usb-audio
From: Dragan Simic @ 2025-09-17 13:27 UTC (permalink / raw)
To: cryolitia
Cc: Jaroslav Kysela, Takashi Iwai, Jonathan Corbet, Luis Chamberlain,
Petr Pavlu, Daniel Gomez, Sami Tolvanen, linux-sound, linux-usb,
linux-kernel, linux-doc, Mingcong Bai, Kexy Biscuit, Nie Cheng,
Zhan Jun, Feng Yuan, qaqland, kernel, linux-modules
In-Reply-To: <20250917-sound-v3-4-92ebe9472a0a@uniontech.com>
Hello Cryolitia,
On 2025-09-17 14:46, Cryolitia PukNgae via B4 Relay wrote:
> From: Cryolitia PukNgae <cryolitia@uniontech.com>
>
> Just briefly described about the new option.
>
> Signed-off-by: Cryolitia PukNgae <cryolitia@uniontech.com>
Isn't the patch subject a bit wrong, and should contain
"device quirk_flags" instead of "device_device_quirk_flags"?
^ permalink raw reply
* [PATCH v3 3/4] ALSA: usb-audio: add module param device_quirk_flags
From: Cryolitia PukNgae via B4 Relay @ 2025-09-17 12:46 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, Jonathan Corbet, Luis Chamberlain,
Petr Pavlu, Daniel Gomez, Sami Tolvanen
Cc: linux-sound, linux-usb, linux-kernel, linux-doc, Mingcong Bai,
Kexy Biscuit, Nie Cheng, Zhan Jun, Feng Yuan, qaqland, kernel,
linux-modules, Cryolitia PukNgae, Takashi Iwai
In-Reply-To: <20250917-sound-v3-0-92ebe9472a0a@uniontech.com>
From: Cryolitia PukNgae <cryolitia@uniontech.com>
For apply and unapply quirk flags more flexibly though param and sysfs
Co-developed-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Cryolitia PukNgae <cryolitia@uniontech.com>
---
sound/usb/card.c | 177 ++++++++++++++++++++++++++++++++++++++++++++++++---
sound/usb/quirks.c | 41 ++++++++++++
sound/usb/quirks.h | 2 +
sound/usb/usbaudio.h | 14 ++++
4 files changed, 226 insertions(+), 8 deletions(-)
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 0265206a8e8cf31133e8463c98fe0497d8ace89e..743aae910cfdf540c6677c6846061754f36a8c1b 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -73,8 +73,8 @@ static bool lowlatency = true;
static char *quirk_alias[SNDRV_CARDS];
static char *delayed_register[SNDRV_CARDS];
static bool implicit_fb[SNDRV_CARDS];
-static unsigned int quirk_flags[SNDRV_CARDS];
+char *quirk_flags[SNDRV_CARDS];
bool snd_usb_use_vmalloc = true;
bool snd_usb_skip_validation;
@@ -103,13 +103,161 @@ module_param_array(delayed_register, charp, NULL, 0444);
MODULE_PARM_DESC(delayed_register, "Quirk for delayed registration, given by id:iface, e.g. 0123abcd:4.");
module_param_array(implicit_fb, bool, NULL, 0444);
MODULE_PARM_DESC(implicit_fb, "Apply generic implicit feedback sync mode.");
-module_param_array(quirk_flags, uint, NULL, 0444);
-MODULE_PARM_DESC(quirk_flags, "Driver quirk bit flags.");
module_param_named(use_vmalloc, snd_usb_use_vmalloc, bool, 0444);
MODULE_PARM_DESC(use_vmalloc, "Use vmalloc for PCM intermediate buffers (default: yes).");
module_param_named(skip_validation, snd_usb_skip_validation, bool, 0444);
MODULE_PARM_DESC(skip_validation, "Skip unit descriptor validation (default: no).");
+DEFINE_MUTEX(device_quirk_mutex); /* protects quirk_flags && device_quirk_list */
+LIST_HEAD(device_quirk_list);
+
+static void free_device_quirk_list(void)
+{
+ struct device_quirk_entry *pos, *tmp;
+
+ list_for_each_entry_safe(pos, tmp, &device_quirk_list, list) {
+ list_del(&pos->list);
+ kfree(pos);
+ }
+}
+
+static int device_quirks_param_set(const char *value,
+ const struct kernel_param *kp)
+{
+ u32 mask_flags, unmask_flags, bit;
+ struct device_quirk_entry *data;
+ char *val, *p, *field, *flag;
+ bool is_unmask;
+ u16 vid, pid;
+ int err = 0;
+ size_t i;
+
+ mutex_lock(&device_quirk_mutex);
+
+ memset(quirk_flags, 0, sizeof(quirk_flags));
+
+ err = param_array_set(value, kp);
+ if (err)
+ goto unlock;
+
+ free_device_quirk_list();
+
+ for (i = 0; i < ARRAY_SIZE(quirk_flags); i++) {
+ if (!quirk_flags[i] || !*quirk_flags[i])
+ break;
+
+ val = kstrdup(quirk_flags[i], GFP_KERNEL);
+
+ if (!val) {
+ err = -ENOMEM;
+ goto unlock;
+ }
+
+ for (p = val; p && *p;) {
+ /* Each entry consists of VID:PID:flags */
+ field = strsep(&p, ":");
+ if (!field)
+ break;
+
+ if (strcmp(field, "*") == 0)
+ vid = 0;
+ else if (kstrtou16(field, 16, &vid))
+ break;
+
+ field = strsep(&p, ":");
+ if (!field)
+ break;
+
+ if (strcmp(field, "*") == 0)
+ pid = 0;
+ else if (kstrtou16(field, 16, &pid))
+ break;
+
+ field = strsep(&p, ";");
+ if (!field || !*field)
+ break;
+
+ /* Collect the flags */
+ mask_flags = 0;
+ unmask_flags = 0;
+ while (field && *field) {
+ flag = strsep(&field, "|");
+
+ if (!flag)
+ break;
+
+ if (*flag == '!') {
+ is_unmask = true;
+ flag++;
+ } else {
+ is_unmask = false;
+ }
+
+ if (!kstrtou32(flag, 16, &bit)) {
+ if (is_unmask)
+ unmask_flags |= bit;
+ else
+ mask_flags |= bit;
+
+ break;
+ }
+
+ bit = snd_usb_quirk_flags_from_name(flag);
+
+ if (bit) {
+ if (is_unmask)
+ unmask_flags |= bit;
+ else
+ mask_flags |= bit;
+ } else {
+ pr_warn("snd_usb_audio: unknown flag %s while parsing param device_quirk_flags\n",
+ field);
+ }
+ }
+
+ data = kzalloc(sizeof(*data), GFP_KERNEL);
+
+ if (!data) {
+ kfree(val);
+ err = -ENOMEM;
+ goto unlock;
+ }
+
+ data->vid = vid;
+ data->pid = pid;
+ data->mask_flags = mask_flags;
+ data->unmask_flags = unmask_flags;
+
+ INIT_LIST_HEAD(&data->list);
+ list_add(&data->list, &device_quirk_list);
+ }
+
+ kfree(val);
+ }
+
+unlock:
+ mutex_unlock(&device_quirk_mutex);
+ return err;
+}
+
+static const struct kernel_param_ops quirk_flags_param_ops = {
+ .set = device_quirks_param_set,
+ .get = param_array_get,
+ .free = param_array_free,
+};
+
+static struct kparam_array quirk_flags_param_array = {
+ .max = SNDRV_CARDS,
+ .elemsize = sizeof(char *),
+ .num = NULL,
+ .ops = ¶m_ops_charp,
+ .elem = &quirk_flags,
+};
+
+device_param_cb(quirk_flags, &quirk_flags_param_ops, &quirk_flags_param_array,
+ 0644);
+MODULE_PARM_DESC(quirk_flags, "Add/modify USB audio quirks");
+
/*
* we keep the snd_usb_audio_t instances by ourselves for merging
* the all interfaces on the same card as one sound device.
@@ -750,10 +898,7 @@ static int snd_usb_audio_create(struct usb_interface *intf,
INIT_LIST_HEAD(&chip->midi_v2_list);
INIT_LIST_HEAD(&chip->mixer_list);
- if (quirk_flags[idx])
- chip->quirk_flags = quirk_flags[idx];
- else
- snd_usb_init_quirk_flags(chip);
+ snd_usb_init_dynamic_quirks(idx, chip);
card->private_free = snd_usb_audio_free;
@@ -1290,4 +1435,20 @@ static struct usb_driver usb_audio_driver = {
.supports_autosuspend = 1,
};
-module_usb_driver(usb_audio_driver);
+static int __init usb_audio_init(void)
+{
+ return usb_register_driver(&usb_audio_driver, THIS_MODULE,
+ KBUILD_MODNAME);
+}
+
+static void __exit usb_audio_exit(void)
+{
+ mutex_lock(&device_quirk_mutex);
+ free_device_quirk_list();
+ mutex_unlock(&device_quirk_mutex);
+
+ usb_deregister(&usb_audio_driver);
+}
+
+module_init(usb_audio_init);
+module_exit(usb_audio_exit);
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 94854f352b1702b491e1bf3c8b769f7088e03976..ee531ffa5ab13ac8b24c670e6529d3811f927b46 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -2537,3 +2537,44 @@ void snd_usb_init_quirk_flags(struct snd_usb_audio *chip)
}
}
}
+
+void snd_usb_init_dynamic_quirks(int idx, struct snd_usb_audio *chip)
+{
+ u16 vid = USB_ID_VENDOR(chip->usb_id);
+ u16 pid = USB_ID_PRODUCT(chip->usb_id);
+ struct device_quirk_entry *pos;
+
+ mutex_lock(&device_quirk_mutex);
+
+ /* old style option found: the position-based integer value */
+ if (quirk_flags[idx] &&
+ !kstrtou32(quirk_flags[idx], 0, &chip->quirk_flags)) {
+ usb_audio_dbg(chip,
+ "Set quirk flags 0x%x from param based on position %d for device %04x:%04x\n",
+ chip->quirk_flags, idx,
+ USB_ID_VENDOR(chip->usb_id),
+ USB_ID_PRODUCT(chip->usb_id));
+
+ mutex_unlock(&device_quirk_mutex);
+ return;
+ }
+
+ /* take the default quirk from the quirk table */
+ snd_usb_init_quirk_flags(chip);
+
+ /* add or correct quirk bits from options */
+ list_for_each_entry(pos, &device_quirk_list, list) {
+ if (pos->vid == 0 || (vid == pos->vid && pos->pid == 0) ||
+ (vid == pos->vid && pid == pos->pid)) {
+ chip->quirk_flags |= pos->mask_flags;
+ chip->quirk_flags &= ~pos->unmask_flags;
+ usb_audio_dbg(chip,
+ "Set mask quirk flag 0x%x and unmask quirk flag 0x%x from param for device %04x:%04x\n",
+ pos->mask_flags, pos->unmask_flags,
+ USB_ID_VENDOR(chip->usb_id),
+ USB_ID_PRODUCT(chip->usb_id));
+ }
+ }
+
+ mutex_unlock(&device_quirk_mutex);
+}
diff --git a/sound/usb/quirks.h b/sound/usb/quirks.h
index bd5baf2b193a1985f3a0e52bf4a77ca741364769..00c2852c4769d0790a9e2a31b92f3414767c9a98 100644
--- a/sound/usb/quirks.h
+++ b/sound/usb/quirks.h
@@ -53,4 +53,6 @@ void snd_usb_init_quirk_flags(struct snd_usb_audio *chip);
const char *snd_usb_quirk_flag_find_name(unsigned long flag);
u32 snd_usb_quirk_flags_from_name(char *name);
+void snd_usb_init_dynamic_quirks(int idx, struct snd_usb_audio *chip);
+
#endif /* __USBAUDIO_QUIRKS_H */
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index 0a22cb4a02344b2dcf4009c560a759f2da25ca67..3d09d4b7950d884a2076fa48f2180a5e7c87cb3a 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -7,6 +7,8 @@
* Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
*/
+ #include <sound/core.h>
+
/* handling of USB vendor/product ID pairs as 32-bit numbers */
#define USB_ID(vendor, product) (((unsigned int)(vendor) << 16) | (product))
#define USB_ID_VENDOR(id) ((id) >> 16)
@@ -162,9 +164,13 @@ DEFINE_CLASS(snd_usb_lock, struct __snd_usb_lock,
__snd_usb_unlock_shutdown(&(_T)), __snd_usb_lock_shutdown(chip),
struct snd_usb_audio *chip)
+extern char *quirk_flags[SNDRV_CARDS];
extern bool snd_usb_use_vmalloc;
extern bool snd_usb_skip_validation;
+extern struct mutex device_quirk_mutex;
+extern struct list_head device_quirk_list;
+
/*
* Driver behavior quirk flags, stored in chip->quirk_flags
*
@@ -254,4 +260,12 @@ extern bool snd_usb_skip_validation;
#define QUIRK_FLAG_MIXER_CAPTURE_MIN_MUTE (1U << 25)
/* Please also edit snd_usb_audio_quirk_flag_names */
+struct device_quirk_entry {
+ struct list_head list;
+ u16 vid;
+ u16 pid;
+ u32 mask_flags;
+ u32 unmask_flags;
+};
+
#endif /* __USBAUDIO_H */
--
2.51.0
^ permalink raw reply related
* [PATCH v3 4/4] ALSA: doc: add docs about device_device_quirk_flags in snd-usb-audio
From: Cryolitia PukNgae via B4 Relay @ 2025-09-17 12:46 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, Jonathan Corbet, Luis Chamberlain,
Petr Pavlu, Daniel Gomez, Sami Tolvanen
Cc: linux-sound, linux-usb, linux-kernel, linux-doc, Mingcong Bai,
Kexy Biscuit, Nie Cheng, Zhan Jun, Feng Yuan, qaqland, kernel,
linux-modules, Cryolitia PukNgae
In-Reply-To: <20250917-sound-v3-0-92ebe9472a0a@uniontech.com>
From: Cryolitia PukNgae <cryolitia@uniontech.com>
Just briefly described about the new option.
Signed-off-by: Cryolitia PukNgae <cryolitia@uniontech.com>
---
Documentation/sound/alsa-configuration.rst | 112 ++++++++++++++++++++---------
1 file changed, 77 insertions(+), 35 deletions(-)
diff --git a/Documentation/sound/alsa-configuration.rst b/Documentation/sound/alsa-configuration.rst
index a2fb8ed251dd0294e7a62209ca15d5c32c6adfae..23ee37f24ff89a983b3dffe6312057cd84b8f579 100644
--- a/Documentation/sound/alsa-configuration.rst
+++ b/Documentation/sound/alsa-configuration.rst
@@ -2297,39 +2297,81 @@ skip_validation
of the unit descriptor instead of a driver probe error, so that we
can check its details.
quirk_flags
- Contains the bit flags for various device specific workarounds.
- Applied to the corresponding card index.
-
- * bit 0: Skip reading sample rate for devices
- * bit 1: Create Media Controller API entries
- * bit 2: Allow alignment on audio sub-slot at transfer
- * bit 3: Add length specifier to transfers
- * bit 4: Start playback stream at first in implement feedback mode
- * bit 5: Skip clock selector setup
- * bit 6: Ignore errors from clock source search
- * bit 7: Indicates ITF-USB DSD based DACs
- * bit 8: Add a delay of 20ms at each control message handling
- * bit 9: Add a delay of 1-2ms at each control message handling
- * bit 10: Add a delay of 5-6ms at each control message handling
- * bit 11: Add a delay of 50ms at each interface setup
- * bit 12: Perform sample rate validations at probe
- * bit 13: Disable runtime PM autosuspend
- * bit 14: Ignore errors for mixer access
- * bit 15: Support generic DSD raw U32_BE format
- * bit 16: Set up the interface at first like UAC1
- * bit 17: Apply the generic implicit feedback sync mode
- * bit 18: Don't apply implicit feedback sync mode
- * bit 19: Don't closed interface during setting sample rate
- * bit 20: Force an interface reset whenever stopping & restarting
- a stream
- * bit 21: Do not set PCM rate (frequency) when only one rate is
- available for the given endpoint.
- * bit 22: Set the fixed resolution 16 for Mic Capture Volume
- * bit 23: Set the fixed resolution 384 for Mic Capture Volume
- * bit 24: Set minimum volume control value as mute for devices
- where the lowest playback value represents muted state instead
- of minimum audible volume
- * bit 25: Be similar to bit 24 but for capture streams
+ The option provides a refined and flexible control for applying quirk
+ flags. It allows to specify the quirk flags for each device, and could
+ be modified dynamically via sysfs.
+ The old usage accepts an array of integers, each of which apply quirk
+ flags on the device in the order of probing.
+ e.g. ``quirk_flags=0x01,0x02`` applies get_sample_rate to the first
+ device, and share_media_device to the second device.
+ The new usage accepts a string in the format of
+ ``VID1:PID1:FLAGS1;VID2:PID2:FLAGS2;...``, where ``VIDx`` and ``PIDx``
+ specify the device, and ``FLAGSx`` specify the flags to be applied.
+ ``VIDx`` and ``PIDx`` are 4-digit hexadecimal numbers, and could be
+ specified as ``*`` to match any value. ``FLAGSx`` could be a set of
+ flags given by name, separated by ``|``, or a hexadecimal number
+ representing the bit flags. The available flag names are listed above.
+ An exclamation mark could be prefixed to a flag name to negate the flag.
+ For example, ``1234:abcd:mixer_playback_min_mute|!ignore_ctl_error;*:*:0x01;``
+ applies the ``mixer_playback_min_mute`` flag and clears the
+ ``ignore_ctl_error`` flag for the device 1234:abcd, and applies the
+ ``skip_sample_rate`` flag for all devices.
+
+ * bit 0: ``get_sample_rate``
+ Skip reading sample rate for devices
+ * bit 1: ``share_media_device``
+ Create Media Controller API entries
+ * bit 2: ``align_transfer``
+ Allow alignment on audio sub-slot at transfer
+ * bit 3: ``tx_length``
+ Add length specifier to transfers
+ * bit 4: ``playback_first``
+ Start playback stream at first in implement feedback mode
+ * bit 5: ``skip_clock_selector``
+ Skip clock selector setup
+ * bit 6: ``ignore_clock_source``
+ Ignore errors from clock source search
+ * bit 7: ``itf_usb_dsd_dac``
+ Indicates ITF-USB DSD based DACs
+ * bit 8: ``ctl_msg_delay``
+ Add a delay of 20ms at each control message handling
+ * bit 9: ``ctl_msg_delay_1m``
+ Add a delay of 1-2ms at each control message handling
+ * bit 10: ``ctl_msg_delay_5m``
+ Add a delay of 5-6ms at each control message handling
+ * bit 11: ``iface_delay``
+ Add a delay of 50ms at each interface setup
+ * bit 12: ``validate_rates``
+ Perform sample rate validations at probe
+ * bit 13: ``disable_autosuspend``
+ Disable runtime PM autosuspend
+ * bit 14: ``ignore_ctl_error``
+ Ignore errors for mixer access
+ * bit 15: ``dsd_raw``
+ Support generic DSD raw U32_BE format
+ * bit 16: ``set_iface_first``
+ Set up the interface at first like UAC1
+ * bit 17: ``generic_implicit_fb``
+ Apply the generic implicit feedback sync mode
+ * bit 18: ``skip_implicit_fb``
+ Don't apply implicit feedback sync mode
+ * bit 19: ``iface_skip_close``
+ Don't closed interface during setting sample rate
+ * bit 20: ``force_iface_reset``
+ Force an interface reset whenever stopping & restarting a stream
+ * bit 21: ``fixed_rate``
+ Do not set PCM rate (frequency) when only one rate is available
+ for the given endpoint
+ * bit 22: ``mic_res_16``
+ Set the fixed resolution 16 for Mic Capture Volume
+ * bit 23: ``mic_res_384``
+ Set the fixed resolution 384 for Mic Capture Volume
+ * bit 24: ``mixer_playback_min_mute``
+ Set minimum volume control value as mute for devices where the
+ lowest playback value represents muted state instead of minimum
+ audible volume
+ * bit 25: ``mixer_capture_min_mute``
+ Be similar to bit 24 but for capture streams
This module supports multiple devices, autoprobe and hotplugging.
@@ -2344,8 +2386,8 @@ report it to the upstream.
NB: ``quirk_alias`` option is provided only for testing / development.
If you want to have a proper support, contact to upstream for
adding the matching quirk in the driver code statically.
-Ditto for ``quirk_flags``. If a device is known to require specific
-workarounds, please report to the upstream.
+Ditto for ``quirk_flags``. If a device
+is known to require specific workarounds, please report to the upstream.
Module snd-usb-caiaq
--------------------
--
2.51.0
^ permalink raw reply related
* [PATCH v3 2/4] param: export param_array related functions
From: Cryolitia PukNgae via B4 Relay @ 2025-09-17 12:46 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, Jonathan Corbet, Luis Chamberlain,
Petr Pavlu, Daniel Gomez, Sami Tolvanen
Cc: linux-sound, linux-usb, linux-kernel, linux-doc, Mingcong Bai,
Kexy Biscuit, Nie Cheng, Zhan Jun, Feng Yuan, qaqland, kernel,
linux-modules, Cryolitia PukNgae
In-Reply-To: <20250917-sound-v3-0-92ebe9472a0a@uniontech.com>
From: Cryolitia PukNgae <cryolitia@uniontech.com>
- int param_array_set(const char *val, const struct kernel_param *kp);
- int param_array_get(char *buffer, const struct kernel_param *kp);
- void param_array_free(void *arg);
It would be helpful for the new module param we designed in
snd_usb_audio, in order to run additional custom codes when params
are set in runtime, and re-use the extisted codes in param.c
Signed-off-by: Cryolitia PukNgae <cryolitia@uniontech.com>
---
include/linux/moduleparam.h | 3 +++
kernel/params.c | 9 ++++++---
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
index 3a25122d83e2802e6e6a1475a52816251498b26a..4ef09ad2004789855bd21783029c653fac94b9dd 100644
--- a/include/linux/moduleparam.h
+++ b/include/linux/moduleparam.h
@@ -593,6 +593,9 @@ enum hwparam_type {
extern const struct kernel_param_ops param_array_ops;
+extern int param_array_set(const char *val, const struct kernel_param *kp);
+extern int param_array_get(char *buffer, const struct kernel_param *kp);
+extern void param_array_free(void *arg);
extern const struct kernel_param_ops param_ops_string;
extern int param_set_copystring(const char *val, const struct kernel_param *);
diff --git a/kernel/params.c b/kernel/params.c
index b96cfd693c9968012d42acb85611fee1acd47790..a936e018a1c6d0bf2b6b4566f80751840366f652 100644
--- a/kernel/params.c
+++ b/kernel/params.c
@@ -462,7 +462,7 @@ static int param_array(struct module *mod,
return 0;
}
-static int param_array_set(const char *val, const struct kernel_param *kp)
+int param_array_set(const char *val, const struct kernel_param *kp)
{
const struct kparam_array *arr = kp->arr;
unsigned int temp_num;
@@ -471,8 +471,9 @@ static int param_array_set(const char *val, const struct kernel_param *kp)
arr->elemsize, arr->ops->set, kp->level,
arr->num ?: &temp_num);
}
+EXPORT_SYMBOL(param_array_set);
-static int param_array_get(char *buffer, const struct kernel_param *kp)
+int param_array_get(char *buffer, const struct kernel_param *kp)
{
int i, off, ret;
const struct kparam_array *arr = kp->arr;
@@ -492,8 +493,9 @@ static int param_array_get(char *buffer, const struct kernel_param *kp)
buffer[off] = '\0';
return off;
}
+EXPORT_SYMBOL(param_array_get);
-static void param_array_free(void *arg)
+void param_array_free(void *arg)
{
unsigned int i;
const struct kparam_array *arr = arg;
@@ -502,6 +504,7 @@ static void param_array_free(void *arg)
for (i = 0; i < (arr->num ? *arr->num : arr->max); i++)
arr->ops->free(arr->elem + arr->elemsize * i);
}
+EXPORT_SYMBOL(param_array_free);
const struct kernel_param_ops param_array_ops = {
.set = param_array_set,
--
2.51.0
^ permalink raw reply related
* [PATCH v3 1/4] ALSA: usb-audio: add two-way convert between name and bit for QUIRK_FLAG_*
From: Cryolitia PukNgae via B4 Relay @ 2025-09-17 12:46 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, Jonathan Corbet, Luis Chamberlain,
Petr Pavlu, Daniel Gomez, Sami Tolvanen
Cc: linux-sound, linux-usb, linux-kernel, linux-doc, Mingcong Bai,
Kexy Biscuit, Nie Cheng, Zhan Jun, Feng Yuan, qaqland, kernel,
linux-modules, Cryolitia PukNgae
In-Reply-To: <20250917-sound-v3-0-92ebe9472a0a@uniontech.com>
From: Cryolitia PukNgae <cryolitia@uniontech.com>
Also improve debug logs for applied quirks
Signed-off-by: Cryolitia PukNgae <cryolitia@uniontech.com>
---
sound/usb/quirks.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++---
sound/usb/quirks.h | 3 ++
sound/usb/usbaudio.h | 1 +
3 files changed, 82 insertions(+), 4 deletions(-)
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index d736a4750356597bfb0f9d5ab01cdaeaac0f907c..94854f352b1702b491e1bf3c8b769f7088e03976 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -2446,6 +2446,62 @@ static const struct usb_audio_quirk_flags_table quirk_flags_table[] = {
{} /* terminator */
};
+static const char *const snd_usb_audio_quirk_flag_names[] = {
+ "get_sample_rate",
+ "share_media_device",
+ "align_transfer",
+ "tx_length",
+ "playback_first",
+ "skip_clock_selector",
+ "ignore_clock_source",
+ "itf_usb_dsd_dac",
+ "ctl_msg_delay",
+ "ctl_msg_delay_1m",
+ "ctl_msg_delay_5m",
+ "iface_delay",
+ "validate_rates",
+ "disable_autosuspend",
+ "ignore_ctl_error",
+ "dsd_raw",
+ "set_iface_first",
+ "generic_implicit_fb",
+ "skip_implicit_fb",
+ "iface_skip_close",
+ "force_iface_reset",
+ "fixed_rate",
+ "mic_res_16",
+ "mic_res_384",
+ "mixer_playback_min_mute",
+ "mixer_capture_min_mute",
+ NULL
+};
+
+const char *snd_usb_quirk_flag_find_name(unsigned long index)
+{
+ if (index >= ARRAY_SIZE(snd_usb_audio_quirk_flag_names))
+ return NULL;
+
+ return snd_usb_audio_quirk_flag_names[index];
+}
+
+u32 snd_usb_quirk_flags_from_name(char *name)
+{
+ u32 flag = 0;
+ u32 i;
+
+ if (!name || !*name)
+ return 0;
+
+ for (i = 0; snd_usb_audio_quirk_flag_names[i]; i++) {
+ if (strcmp(name, snd_usb_audio_quirk_flag_names[i]) == 0) {
+ flag = (1U << i);
+ break;
+ }
+ }
+
+ return flag;
+}
+
void snd_usb_init_quirk_flags(struct snd_usb_audio *chip)
{
const struct usb_audio_quirk_flags_table *p;
@@ -2454,10 +2510,28 @@ void snd_usb_init_quirk_flags(struct snd_usb_audio *chip)
if (chip->usb_id == p->id ||
(!USB_ID_PRODUCT(p->id) &&
USB_ID_VENDOR(chip->usb_id) == USB_ID_VENDOR(p->id))) {
- usb_audio_dbg(chip,
- "Set quirk_flags 0x%x for device %04x:%04x\n",
- p->flags, USB_ID_VENDOR(chip->usb_id),
- USB_ID_PRODUCT(chip->usb_id));
+ unsigned long flags = p->flags;
+ unsigned long bit;
+
+ for_each_set_bit(bit, &flags,
+ BYTES_TO_BITS(sizeof(p->flags))) {
+ const char *name =
+ snd_usb_audio_quirk_flag_names[bit];
+
+ if (name)
+ usb_audio_dbg(chip,
+ "Set quirk flag %s for device %04x:%04x\n",
+ name,
+ USB_ID_VENDOR(chip->usb_id),
+ USB_ID_PRODUCT(chip->usb_id));
+ else
+ usb_audio_warn(chip,
+ "Set unknown quirk flag 0x%lx for device %04x:%04x\n",
+ bit,
+ USB_ID_VENDOR(chip->usb_id),
+ USB_ID_PRODUCT(chip->usb_id));
+ }
+
chip->quirk_flags |= p->flags;
return;
}
diff --git a/sound/usb/quirks.h b/sound/usb/quirks.h
index f9bfd5ac7bab01717de3a76227482a128bf73165..bd5baf2b193a1985f3a0e52bf4a77ca741364769 100644
--- a/sound/usb/quirks.h
+++ b/sound/usb/quirks.h
@@ -50,4 +50,7 @@ void snd_usb_audioformat_attributes_quirk(struct snd_usb_audio *chip,
void snd_usb_init_quirk_flags(struct snd_usb_audio *chip);
+const char *snd_usb_quirk_flag_find_name(unsigned long flag);
+u32 snd_usb_quirk_flags_from_name(char *name);
+
#endif /* __USBAUDIO_QUIRKS_H */
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index 30b5102e3caed01eeb86d0075c41338104c58950..0a22cb4a02344b2dcf4009c560a759f2da25ca67 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -252,5 +252,6 @@ extern bool snd_usb_skip_validation;
#define QUIRK_FLAG_MIC_RES_384 (1U << 23)
#define QUIRK_FLAG_MIXER_PLAYBACK_MIN_MUTE (1U << 24)
#define QUIRK_FLAG_MIXER_CAPTURE_MIN_MUTE (1U << 25)
+/* Please also edit snd_usb_audio_quirk_flag_names */
#endif /* __USBAUDIO_H */
--
2.51.0
^ permalink raw reply related
* [PATCH v3 0/4] ALSA: usb-audio: add module param device_quirk_flags
From: Cryolitia PukNgae via B4 Relay @ 2025-09-17 12:46 UTC (permalink / raw)
To: Jaroslav Kysela, Takashi Iwai, Jonathan Corbet, Luis Chamberlain,
Petr Pavlu, Daniel Gomez, Sami Tolvanen
Cc: linux-sound, linux-usb, linux-kernel, linux-doc, Mingcong Bai,
Kexy Biscuit, Nie Cheng, Zhan Jun, Feng Yuan, qaqland, kernel,
linux-modules, Cryolitia PukNgae, Takashi Iwai
As an implementation of what has been discussed previously[1].
1. https://lore.kernel.org/all/87h5xm5g7f.wl-tiwai@suse.de/
Signed-off-by: Cryolitia PukNgae <cryolitia@uniontech.com>
---
Changes in v3:
- Instead of a new param, improve the existed one.
- Link to v2: https://lore.kernel.org/r/20250912-sound-v2-0-01ea3d279f4b@uniontech.com
Changes in v2:
- Cleaned up some internal rebase confusion, sorry for that
- Link to v1: https://lore.kernel.org/r/20250912-sound-v1-0-cc9cfd9f2d01@uniontech.com
---
Cryolitia PukNgae (4):
ALSA: usb-audio: add two-way convert between name and bit for QUIRK_FLAG_*
param: export param_array related functions
ALSA: usb-audio: add module param device_quirk_flags
ALSA: doc: add docs about device_device_quirk_flags in snd-usb-audio
Documentation/sound/alsa-configuration.rst | 112 ++++++++++++------
include/linux/moduleparam.h | 3 +
kernel/params.c | 9 +-
sound/usb/card.c | 177 +++++++++++++++++++++++++++--
sound/usb/quirks.c | 123 +++++++++++++++++++-
sound/usb/quirks.h | 5 +
sound/usb/usbaudio.h | 15 +++
7 files changed, 394 insertions(+), 50 deletions(-)
---
base-commit: 4c421c40c8b30ab7aae1edc7f7e294fcd33fc186
change-id: 20250910-sound-a91c86c92dba
Best regards,
--
Cryolitia PukNgae <cryolitia@uniontech.com>
^ permalink raw reply
* Re: [PATCH v7 3/8] kbuild: keep .modinfo section in vmlinux.unstripped
From: Alexey Gladkov @ 2025-09-17 12:38 UTC (permalink / raw)
To: Nicolas Schier
Cc: Nathan Chancellor, Petr Pavlu, Luis Chamberlain, Sami Tolvanen,
Daniel Gomez, linux-kernel, linux-modules, linux-kbuild,
Masahiro Yamada
In-Reply-To: <aMqhuFQGAGtYFbRV@levanger>
On Wed, Sep 17, 2025 at 01:55:36PM +0200, Nicolas Schier wrote:
> On Tue, Sep 16, 2025 at 02:42:48PM +0200, Nicolas Schier wrote:
> > On Tue, Sep 16, 2025 at 01:30:20PM +0200, Alexey Gladkov wrote:
> ...
> > > I think in the case of .modinfo, we can change the flag in the section
> > > since we are going to delete it anyway.
> > >
> > > diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> > > index dbbe3bf0cf23..9a118b31d0dc 100644
> > > --- a/scripts/Makefile.vmlinux
> > > +++ b/scripts/Makefile.vmlinux
> > > @@ -87,7 +87,8 @@ remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> > > remove-symbols := -w --strip-symbol='__mod_device_table__*'
> > >
> > > quiet_cmd_strip_relocs = OBJCOPY $@
> > > - cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
> > > + cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< && \
> > > + $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
> > > $(remove-symbols) $< $@
> > >
> > > targets += vmlinux
> >
> > Ah, great! I thought we had to fiddle around with linker scripts et al.
> > I needed to use an intermediate file:
> >
> > diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> > index e2ceeb9e168d..516d51ca634b 100644
> > --- a/scripts/Makefile.vmlinux
> > +++ b/scripts/Makefile.vmlinux
> > @@ -90,6 +90,9 @@ remove-section-y := .modinfo
> > remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> >
> > quiet_cmd_strip_relocs = OBJCOPY $@
> > - cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $< $@
> > + cmd_strip_relocs = set -e; \
> > + trap 'rm $<.noload' EXIT HUP INT; \
> > + $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $<.noload && \
> > + $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $<.noload $@
> >
> > targets += vmlinux
>
> I'd like to suggest another version closer to yours, as mine has several flaws:
>
> diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> index dbbe3bf0cf23..9a118b31d0dc 100644
> --- a/scripts/Makefile.vmlinux
> +++ b/scripts/Makefile.vmlinux
> @@ -87,7 +87,8 @@ remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> remove-symbols := -w --strip-symbol='__mod_device_table__*'
>
> quiet_cmd_strip_relocs = OBJCOPY $@
> - cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
> + cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $@; \
> + $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
> $(remove-symbols) $@
>
> targets += vmlinux
>
>
>
> Rationale (mainly for myself to not walk into that trap too often again):
>
> * Use ';' instead of '&&' as 'cmd_' is evaluated in a 'set -e'
> environment ('cmd') and thus '&&' may hide a possible error exit
> code.
No, it can't hide exit code. The exit code will be correct even if
‘set -e’ is not used.
$ (exit 0) && (exit 2) && (exit 3); echo $?
2
Actually ‘&&’ is protection against the absence of ‘set -e’.
> * Create 'vmlinux' already with the first objcopy and let the second
> one modify it in order to not need a temporary file; iff one or the
> other objcopy exists with an error exit code, the 'set -e + trap'
> ('delete-on-interrupt') shell will remove a possibly existing
> vmlinux file.
That makes totally sense. This will avoid a temporary file. I will use it
in the new version.
--
Rgrds, legion
^ permalink raw reply
* Re: [PATCH v7 4/8] kbuild: extract modules.builtin.modinfo from vmlinux.unstripped
From: Nicolas Schier @ 2025-09-17 11:57 UTC (permalink / raw)
To: Alexey Gladkov
Cc: Nathan Chancellor, Petr Pavlu, Luis Chamberlain, Sami Tolvanen,
Daniel Gomez, linux-kernel, linux-modules, linux-kbuild,
Masahiro Yamada
In-Reply-To: <ed2530db3903b1332ce4bc2aaf95a0397e1581e8.1755535876.git.legion@kernel.org>
On Mon, Aug 18, 2025 at 06:54:58PM +0200, Alexey Gladkov wrote:
> From: Masahiro Yamada <masahiroy@kernel.org>
>
> Currently, we assume all the data for modules.builtin.modinfo are
> available in vmlinux.o.
>
> This makes it impossible for modpost, which is invoked after vmlinux.o,
> to add additional module info.
>
> This commit moves the modules.builtin.modinfo rule after modpost.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> Signed-off-by: Alexey Gladkov <legion@kernel.org>
> ---
> scripts/Makefile.vmlinux | 26 ++++++++++++++++++++++++++
> scripts/Makefile.vmlinux_o | 26 +-------------------------
> 2 files changed, 27 insertions(+), 25 deletions(-)
>
Reviewed-by: Nicolas Schier <nsc@kernel.org>
^ permalink raw reply
* Re: [PATCH v7 2/8] kbuild: always create intermediate vmlinux.unstripped
From: Nicolas Schier @ 2025-09-17 11:57 UTC (permalink / raw)
To: Alexey Gladkov
Cc: Nathan Chancellor, Petr Pavlu, Luis Chamberlain, Sami Tolvanen,
Daniel Gomez, linux-kernel, linux-modules, linux-kbuild,
Masahiro Yamada
In-Reply-To: <df6f570daa38a22da59135b294705e3c5680e441.1755535876.git.legion@kernel.org>
On Mon, Aug 18, 2025 at 06:54:56PM +0200, Alexey Gladkov wrote:
> From: Masahiro Yamada <masahiroy@kernel.org>
>
> Generate the intermediate vmlinux.unstripped regardless of
> CONFIG_ARCH_VMLINUX_NEEDS_RELOCS.
>
> If CONFIG_ARCH_VMLINUX_NEEDS_RELOCS is unset, vmlinux.unstripped and
> vmlinux are identiacal.
>
> This simplifies the build rule, and allows to strip more sections
> by adding them to remove-section-y.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> ---
> scripts/Makefile.vmlinux | 45 ++++++++++++++++++++--------------------
> 1 file changed, 22 insertions(+), 23 deletions(-)
Reviewed-by: Nicolas Schier <nsc@kernel.org>
^ permalink raw reply
* Re: [PATCH v7 3/8] kbuild: keep .modinfo section in vmlinux.unstripped
From: Nicolas Schier @ 2025-09-17 11:55 UTC (permalink / raw)
To: Alexey Gladkov
Cc: Nathan Chancellor, Petr Pavlu, Luis Chamberlain, Sami Tolvanen,
Daniel Gomez, linux-kernel, linux-modules, linux-kbuild,
Masahiro Yamada
In-Reply-To: <aMlbSEnwGOPM39Op@levanger>
On Tue, Sep 16, 2025 at 02:42:48PM +0200, Nicolas Schier wrote:
> On Tue, Sep 16, 2025 at 01:30:20PM +0200, Alexey Gladkov wrote:
...
> > I think in the case of .modinfo, we can change the flag in the section
> > since we are going to delete it anyway.
> >
> > diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> > index dbbe3bf0cf23..9a118b31d0dc 100644
> > --- a/scripts/Makefile.vmlinux
> > +++ b/scripts/Makefile.vmlinux
> > @@ -87,7 +87,8 @@ remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> > remove-symbols := -w --strip-symbol='__mod_device_table__*'
> >
> > quiet_cmd_strip_relocs = OBJCOPY $@
> > - cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
> > + cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< && \
> > + $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
> > $(remove-symbols) $< $@
> >
> > targets += vmlinux
>
> Ah, great! I thought we had to fiddle around with linker scripts et al.
> I needed to use an intermediate file:
>
> diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> index e2ceeb9e168d..516d51ca634b 100644
> --- a/scripts/Makefile.vmlinux
> +++ b/scripts/Makefile.vmlinux
> @@ -90,6 +90,9 @@ remove-section-y := .modinfo
> remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
>
> quiet_cmd_strip_relocs = OBJCOPY $@
> - cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $< $@
> + cmd_strip_relocs = set -e; \
> + trap 'rm $<.noload' EXIT HUP INT; \
> + $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $<.noload && \
> + $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $<.noload $@
>
> targets += vmlinux
I'd like to suggest another version closer to yours, as mine has several flaws:
diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
index dbbe3bf0cf23..9a118b31d0dc 100644
--- a/scripts/Makefile.vmlinux
+++ b/scripts/Makefile.vmlinux
@@ -87,7 +87,8 @@ remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
remove-symbols := -w --strip-symbol='__mod_device_table__*'
quiet_cmd_strip_relocs = OBJCOPY $@
- cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
+ cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $@; \
+ $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
$(remove-symbols) $@
targets += vmlinux
Rationale (mainly for myself to not walk into that trap too often again):
* Use ';' instead of '&&' as 'cmd_' is evaluated in a 'set -e'
environment ('cmd') and thus '&&' may hide a possible error exit
code.
* Create 'vmlinux' already with the first objcopy and let the second
one modify it in order to not need a temporary file; iff one or the
other objcopy exists with an error exit code, the 'set -e + trap'
('delete-on-interrupt') shell will remove a possibly existing
vmlinux file.
Kind regards,
Nicolas
^ permalink raw reply related
* Re: [PATCH v7 3/8] kbuild: keep .modinfo section in vmlinux.unstripped
From: Alexey Gladkov @ 2025-09-17 6:49 UTC (permalink / raw)
To: Nathan Chancellor
Cc: Nicolas Schier, Petr Pavlu, Luis Chamberlain, Sami Tolvanen,
Daniel Gomez, linux-kernel, linux-modules, linux-kbuild,
Masahiro Yamada
In-Reply-To: <20250917011010.GA3106929@ax162>
On Tue, Sep 16, 2025 at 06:10:10PM -0700, Nathan Chancellor wrote:
> On Tue, Sep 16, 2025 at 03:28:09PM +0200, Nicolas Schier wrote:
> > yeah, it's actually because I dislike modifying vmlinux.unstripped in
> > the vmlinux rule.
> >
> > But it may be that Nathan does not see it this way.
>
> Yeah, I would agree that it is good form to avoid modifying the inputs
> of a rule.
>
> This warning is pretty annoying since it is intentional but we do not
> have great tools to hide just this one instance it seems... This is
> probably worth a comment.
>
> It would be nice if this section could be marked as NOLOAD from the
> beginning but that will mess with extracting .modinfo via objcopy from
> my brief testing.
>
Yeah, I was thinking about that too.
Ok, I will make a new version of the patchset with fixes.
--
Rgrds, legion
^ permalink raw reply
* Re: [PATCH v7 3/8] kbuild: keep .modinfo section in vmlinux.unstripped
From: Nathan Chancellor @ 2025-09-17 1:10 UTC (permalink / raw)
To: Nicolas Schier
Cc: Alexey Gladkov, Petr Pavlu, Luis Chamberlain, Sami Tolvanen,
Daniel Gomez, linux-kernel, linux-modules, linux-kbuild,
Masahiro Yamada
In-Reply-To: <aMll6cHPhIY2yswz@levanger>
On Tue, Sep 16, 2025 at 03:28:09PM +0200, Nicolas Schier wrote:
> yeah, it's actually because I dislike modifying vmlinux.unstripped in
> the vmlinux rule.
>
> But it may be that Nathan does not see it this way.
Yeah, I would agree that it is good form to avoid modifying the inputs
of a rule.
This warning is pretty annoying since it is intentional but we do not
have great tools to hide just this one instance it seems... This is
probably worth a comment.
It would be nice if this section could be marked as NOLOAD from the
beginning but that will mess with extracting .modinfo via objcopy from
my brief testing.
Cheers,
Nathan
^ permalink raw reply
* Re: [PATCH v7 3/8] kbuild: keep .modinfo section in vmlinux.unstripped
From: Nicolas Schier @ 2025-09-16 13:28 UTC (permalink / raw)
To: Alexey Gladkov, Nathan Chancellor
Cc: Petr Pavlu, Luis Chamberlain, Sami Tolvanen, Daniel Gomez,
linux-kernel, linux-modules, linux-kbuild, Masahiro Yamada
In-Reply-To: <aMlgMkB2nL31K2OB@example.org>
On Tue, Sep 16, 2025 at 03:03:46PM +0200, Alexey Gladkov wrote:
> On Tue, Sep 16, 2025 at 02:42:48PM +0200, Nicolas Schier wrote:
> > > > > > Hi Alexey,
> > > > > >
> > > > > > with this patch applied, I still get a warning from objcpy as Masahiro
> > > > > > and Stephen wrote [1,2]
> > > > > >
> > > > > > SORTTAB vmlinux.unstripped
> > > > > > + sorttable vmlinux.unstripped
> > > > > > + nm -S vmlinux.unstripped
> > > > > > + ./scripts/sorttable -s .tmp_vmlinux.nm-sort vmlinux.unstripped
> > > > > > + is_enabled CONFIG_KALLSYMS
> > > > > > + grep -q ^CONFIG_KALLSYMS=y include/config/auto.conf
> > > > > > + cmp -s System.map .tmp_vmlinux2.syms
> > > > > > + echo vmlinux.unstripped: ../scripts/link-vmlinux.sh
> > > > > > # OBJCOPY vmlinux
> > > > > > objcopy --remove-section=.modinfo vmlinux.unstripped vmlinux
> > > > > > objcopy: vmlinux.unstripped: warning: empty loadable segment detected at vaddr=0xffff8000807a0000, is this intentional?
> > > > > >
> > > > > > (arm64, allnoconfig)
> > > > > >
> > > > > > Kind regards,
> > > > > > Nicolas
> > > > > >
> > > > > >
> > > > > > [1]: https://lore.kernel.org/linux-kbuild/CAK7LNAR-gD2H6Kk-rZjo0R3weTHCGTm0a=u2tRH1WWW6Sx6=RQ@mail.gmail.com/
> > > > > > [2]: https://lore.kernel.org/lkml/20250730164047.7c4a731a@canb.auug.org.au/
> > > > > >
> > > > >
> > > > > Hm. I missed that. I need to investigate how to fix this. Nothing comes
> > > > > to mind right now.
> > > >
> > > > Same here. Only thing I could find until now is
> > > >
> > > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/diff/scripts/link-vmlinux.sh?id=90ceddcb495008ac8ba7a3dce297841efcd7d584
> > > >
> > > > where '2>/dev/null' is appended exactly to prevent this very warning.
> > > > But for me, it doesn't feel good doing that when stripping to vmlinux.
> > >
> > > Yes, that's not a very good approach. It will hide other errors that will
> > > definitely need to be seen. I think the commit you mentioned is actually
> > > incorrect. I think there should be a different solution.
> > >
> > > I think in the case of .modinfo, we can change the flag in the section
> > > since we are going to delete it anyway.
> > >
> > > diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> > > index dbbe3bf0cf23..9a118b31d0dc 100644
> > > --- a/scripts/Makefile.vmlinux
> > > +++ b/scripts/Makefile.vmlinux
> > > @@ -87,7 +87,8 @@ remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> > > remove-symbols := -w --strip-symbol='__mod_device_table__*'
> > >
> > > quiet_cmd_strip_relocs = OBJCOPY $@
> > > - cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
> > > + cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< && \
> > > + $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
> > > $(remove-symbols) $< $@
> > >
> > > targets += vmlinux
> >
> > Ah, great! I thought we had to fiddle around with linker scripts et al.
> > I needed to use an intermediate file:
> >
> > diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> > index e2ceeb9e168d..516d51ca634b 100644
> > --- a/scripts/Makefile.vmlinux
> > +++ b/scripts/Makefile.vmlinux
> > @@ -90,6 +90,9 @@ remove-section-y := .modinfo
> > remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> >
> > quiet_cmd_strip_relocs = OBJCOPY $@
> > - cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $< $@
> > + cmd_strip_relocs = set -e; \
> > + trap 'rm $<.noload' EXIT HUP INT; \
> > + $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $<.noload && \
> > + $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $<.noload $@
> >
> > targets += vmlinux
>
> according to man-page:
>
> If you do not specify outfile, objcopy creates a temporary file and
> destructively renames the result with the name of infile.
>
> That is true even in freebsd:
>
> https://man.freebsd.org/cgi/man.cgi?query=objcopy
>
> Do you want to support any other objcopy implementations ?
yeah, it's actually because I dislike modifying vmlinux.unstripped in
the vmlinux rule.
But it may be that Nathan does not see it this way.
--
Nicolas
^ permalink raw reply
* Re: [PATCH v7 3/8] kbuild: keep .modinfo section in vmlinux.unstripped
From: Alexey Gladkov @ 2025-09-16 13:03 UTC (permalink / raw)
To: Nicolas Schier
Cc: Nathan Chancellor, Petr Pavlu, Luis Chamberlain, Sami Tolvanen,
Daniel Gomez, linux-kernel, linux-modules, linux-kbuild,
Masahiro Yamada
In-Reply-To: <aMlbSEnwGOPM39Op@levanger>
On Tue, Sep 16, 2025 at 02:42:48PM +0200, Nicolas Schier wrote:
> > > > > Hi Alexey,
> > > > >
> > > > > with this patch applied, I still get a warning from objcpy as Masahiro
> > > > > and Stephen wrote [1,2]
> > > > >
> > > > > SORTTAB vmlinux.unstripped
> > > > > + sorttable vmlinux.unstripped
> > > > > + nm -S vmlinux.unstripped
> > > > > + ./scripts/sorttable -s .tmp_vmlinux.nm-sort vmlinux.unstripped
> > > > > + is_enabled CONFIG_KALLSYMS
> > > > > + grep -q ^CONFIG_KALLSYMS=y include/config/auto.conf
> > > > > + cmp -s System.map .tmp_vmlinux2.syms
> > > > > + echo vmlinux.unstripped: ../scripts/link-vmlinux.sh
> > > > > # OBJCOPY vmlinux
> > > > > objcopy --remove-section=.modinfo vmlinux.unstripped vmlinux
> > > > > objcopy: vmlinux.unstripped: warning: empty loadable segment detected at vaddr=0xffff8000807a0000, is this intentional?
> > > > >
> > > > > (arm64, allnoconfig)
> > > > >
> > > > > Kind regards,
> > > > > Nicolas
> > > > >
> > > > >
> > > > > [1]: https://lore.kernel.org/linux-kbuild/CAK7LNAR-gD2H6Kk-rZjo0R3weTHCGTm0a=u2tRH1WWW6Sx6=RQ@mail.gmail.com/
> > > > > [2]: https://lore.kernel.org/lkml/20250730164047.7c4a731a@canb.auug.org.au/
> > > > >
> > > >
> > > > Hm. I missed that. I need to investigate how to fix this. Nothing comes
> > > > to mind right now.
> > >
> > > Same here. Only thing I could find until now is
> > >
> > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/diff/scripts/link-vmlinux.sh?id=90ceddcb495008ac8ba7a3dce297841efcd7d584
> > >
> > > where '2>/dev/null' is appended exactly to prevent this very warning.
> > > But for me, it doesn't feel good doing that when stripping to vmlinux.
> >
> > Yes, that's not a very good approach. It will hide other errors that will
> > definitely need to be seen. I think the commit you mentioned is actually
> > incorrect. I think there should be a different solution.
> >
> > I think in the case of .modinfo, we can change the flag in the section
> > since we are going to delete it anyway.
> >
> > diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> > index dbbe3bf0cf23..9a118b31d0dc 100644
> > --- a/scripts/Makefile.vmlinux
> > +++ b/scripts/Makefile.vmlinux
> > @@ -87,7 +87,8 @@ remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> > remove-symbols := -w --strip-symbol='__mod_device_table__*'
> >
> > quiet_cmd_strip_relocs = OBJCOPY $@
> > - cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
> > + cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< && \
> > + $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
> > $(remove-symbols) $< $@
> >
> > targets += vmlinux
>
> Ah, great! I thought we had to fiddle around with linker scripts et al.
> I needed to use an intermediate file:
>
> diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> index e2ceeb9e168d..516d51ca634b 100644
> --- a/scripts/Makefile.vmlinux
> +++ b/scripts/Makefile.vmlinux
> @@ -90,6 +90,9 @@ remove-section-y := .modinfo
> remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
>
> quiet_cmd_strip_relocs = OBJCOPY $@
> - cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $< $@
> + cmd_strip_relocs = set -e; \
> + trap 'rm $<.noload' EXIT HUP INT; \
> + $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $<.noload && \
> + $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $<.noload $@
>
> targets += vmlinux
according to man-page:
If you do not specify outfile, objcopy creates a temporary file and
destructively renames the result with the name of infile.
That is true even in freebsd:
https://man.freebsd.org/cgi/man.cgi?query=objcopy
Do you want to support any other objcopy implementations ?
--
Rgrds, legion
^ permalink raw reply
* Re: [PATCH v7 3/8] kbuild: keep .modinfo section in vmlinux.unstripped
From: Nicolas Schier @ 2025-09-16 12:42 UTC (permalink / raw)
To: Alexey Gladkov
Cc: Nathan Chancellor, Petr Pavlu, Luis Chamberlain, Sami Tolvanen,
Daniel Gomez, linux-kernel, linux-modules, linux-kbuild,
Masahiro Yamada
In-Reply-To: <aMlKTPpNXrRW6v_7@example.org>
On Tue, Sep 16, 2025 at 01:30:20PM +0200, Alexey Gladkov wrote:
> On Tue, Sep 16, 2025 at 11:36:54AM +0200, Nicolas Schier wrote:
> > On Tue, Sep 16, 2025 at 09:12:22AM +0200, Alexey Gladkov wrote:
> > > On Mon, Sep 15, 2025 at 07:56:16AM +0200, Nicolas Schier wrote:
> > > > On Mon, Aug 18, 2025 at 06:54:57PM +0200, Alexey Gladkov wrote:
> > > > > From: Masahiro Yamada <masahiroy@kernel.org>
> > > > >
> > > > > Keep the .modinfo section during linking, but strip it from the final
> > > > > vmlinux.
> > > > >
> > > > > Adjust scripts/mksysmap to exclude modinfo symbols from kallsyms.
> > > > >
> > > > > This change will allow the next commit to extract the .modinfo section
> > > > > from the vmlinux.unstripped intermediate.
> > > > >
> > > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > > > > ---
> > > > > include/asm-generic/vmlinux.lds.h | 2 +-
> > > > > scripts/Makefile.vmlinux | 2 +-
> > > > > scripts/mksysmap | 3 +++
> > > > > 3 files changed, 5 insertions(+), 2 deletions(-)
> > > > >
> > > > > diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> > > > > index ae2d2359b79e9..cfa63860dfd4c 100644
> > > > > --- a/include/asm-generic/vmlinux.lds.h
> > > > > +++ b/include/asm-generic/vmlinux.lds.h
> > > > > @@ -831,6 +831,7 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
> > > > >
> > > > > /* Required sections not related to debugging. */
> > > > > #define ELF_DETAILS \
> > > > > + .modinfo : { *(.modinfo) } \
> > > > > .comment 0 : { *(.comment) } \
> > > > > .symtab 0 : { *(.symtab) } \
> > > > > .strtab 0 : { *(.strtab) } \
> > > > > @@ -1044,7 +1045,6 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
> > > > > *(.discard.*) \
> > > > > *(.export_symbol) \
> > > > > *(.no_trim_symbol) \
> > > > > - *(.modinfo) \
> > > > > /* ld.bfd warns about .gnu.version* even when not emitted */ \
> > > > > *(.gnu.version*) \
> > > > >
> > > > > diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> > > > > index 4f2d4c3fb7372..e2ceeb9e168d4 100644
> > > > > --- a/scripts/Makefile.vmlinux
> > > > > +++ b/scripts/Makefile.vmlinux
> > > > > @@ -86,7 +86,7 @@ endif
> > > > > # vmlinux
> > > > > # ---------------------------------------------------------------------------
> > > > >
> > > > > -remove-section-y :=
> > > > > +remove-section-y := .modinfo
> > > > > remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> > > > >
> > > > > quiet_cmd_strip_relocs = OBJCOPY $@
> > > > > diff --git a/scripts/mksysmap b/scripts/mksysmap
> > > > > index 3accbdb269ac7..a607a0059d119 100755
> > > > > --- a/scripts/mksysmap
> > > > > +++ b/scripts/mksysmap
> > > > > @@ -79,6 +79,9 @@
> > > > > / _SDA_BASE_$/d
> > > > > / _SDA2_BASE_$/d
> > > > >
> > > > > +# MODULE_INFO()
> > > > > +/ __UNIQUE_ID_modinfo[0-9]*$/d
> > > > > +
> > > > > # ---------------------------------------------------------------------------
> > > > > # Ignored patterns
> > > > > # (symbols that contain the pattern are ignored)
> > > > > --
> > > > > 2.50.1
> > > > >
> > > >
> > > > Hi Alexey,
> > > >
> > > > with this patch applied, I still get a warning from objcpy as Masahiro
> > > > and Stephen wrote [1,2]
> > > >
> > > > SORTTAB vmlinux.unstripped
> > > > + sorttable vmlinux.unstripped
> > > > + nm -S vmlinux.unstripped
> > > > + ./scripts/sorttable -s .tmp_vmlinux.nm-sort vmlinux.unstripped
> > > > + is_enabled CONFIG_KALLSYMS
> > > > + grep -q ^CONFIG_KALLSYMS=y include/config/auto.conf
> > > > + cmp -s System.map .tmp_vmlinux2.syms
> > > > + echo vmlinux.unstripped: ../scripts/link-vmlinux.sh
> > > > # OBJCOPY vmlinux
> > > > objcopy --remove-section=.modinfo vmlinux.unstripped vmlinux
> > > > objcopy: vmlinux.unstripped: warning: empty loadable segment detected at vaddr=0xffff8000807a0000, is this intentional?
> > > >
> > > > (arm64, allnoconfig)
> > > >
> > > > Kind regards,
> > > > Nicolas
> > > >
> > > >
> > > > [1]: https://lore.kernel.org/linux-kbuild/CAK7LNAR-gD2H6Kk-rZjo0R3weTHCGTm0a=u2tRH1WWW6Sx6=RQ@mail.gmail.com/
> > > > [2]: https://lore.kernel.org/lkml/20250730164047.7c4a731a@canb.auug.org.au/
> > > >
> > >
> > > Hm. I missed that. I need to investigate how to fix this. Nothing comes
> > > to mind right now.
> >
> > Same here. Only thing I could find until now is
> >
> > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/diff/scripts/link-vmlinux.sh?id=90ceddcb495008ac8ba7a3dce297841efcd7d584
> >
> > where '2>/dev/null' is appended exactly to prevent this very warning.
> > But for me, it doesn't feel good doing that when stripping to vmlinux.
>
> Yes, that's not a very good approach. It will hide other errors that will
> definitely need to be seen. I think the commit you mentioned is actually
> incorrect. I think there should be a different solution.
>
> I think in the case of .modinfo, we can change the flag in the section
> since we are going to delete it anyway.
>
> diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> index dbbe3bf0cf23..9a118b31d0dc 100644
> --- a/scripts/Makefile.vmlinux
> +++ b/scripts/Makefile.vmlinux
> @@ -87,7 +87,8 @@ remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> remove-symbols := -w --strip-symbol='__mod_device_table__*'
>
> quiet_cmd_strip_relocs = OBJCOPY $@
> - cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
> + cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< && \
> + $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
> $(remove-symbols) $< $@
>
> targets += vmlinux
Ah, great! I thought we had to fiddle around with linker scripts et al.
I needed to use an intermediate file:
diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
index e2ceeb9e168d..516d51ca634b 100644
--- a/scripts/Makefile.vmlinux
+++ b/scripts/Makefile.vmlinux
@@ -90,6 +90,9 @@ remove-section-y := .modinfo
remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
quiet_cmd_strip_relocs = OBJCOPY $@
- cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $< $@
+ cmd_strip_relocs = set -e; \
+ trap 'rm $<.noload' EXIT HUP INT; \
+ $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< $<.noload && \
+ $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) $<.noload $@
targets += vmlinux
Kind regards,
Nicolas
^ permalink raw reply related
* Re: [PATCH v7 3/8] kbuild: keep .modinfo section in vmlinux.unstripped
From: Alexey Gladkov @ 2025-09-16 11:30 UTC (permalink / raw)
To: Nicolas Schier
Cc: Nathan Chancellor, Petr Pavlu, Luis Chamberlain, Sami Tolvanen,
Daniel Gomez, linux-kernel, linux-modules, linux-kbuild,
Masahiro Yamada
In-Reply-To: <aMkvtg55F1gJ5feM@levanger>
On Tue, Sep 16, 2025 at 11:36:54AM +0200, Nicolas Schier wrote:
> On Tue, Sep 16, 2025 at 09:12:22AM +0200, Alexey Gladkov wrote:
> > On Mon, Sep 15, 2025 at 07:56:16AM +0200, Nicolas Schier wrote:
> > > On Mon, Aug 18, 2025 at 06:54:57PM +0200, Alexey Gladkov wrote:
> > > > From: Masahiro Yamada <masahiroy@kernel.org>
> > > >
> > > > Keep the .modinfo section during linking, but strip it from the final
> > > > vmlinux.
> > > >
> > > > Adjust scripts/mksysmap to exclude modinfo symbols from kallsyms.
> > > >
> > > > This change will allow the next commit to extract the .modinfo section
> > > > from the vmlinux.unstripped intermediate.
> > > >
> > > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > > > ---
> > > > include/asm-generic/vmlinux.lds.h | 2 +-
> > > > scripts/Makefile.vmlinux | 2 +-
> > > > scripts/mksysmap | 3 +++
> > > > 3 files changed, 5 insertions(+), 2 deletions(-)
> > > >
> > > > diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> > > > index ae2d2359b79e9..cfa63860dfd4c 100644
> > > > --- a/include/asm-generic/vmlinux.lds.h
> > > > +++ b/include/asm-generic/vmlinux.lds.h
> > > > @@ -831,6 +831,7 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
> > > >
> > > > /* Required sections not related to debugging. */
> > > > #define ELF_DETAILS \
> > > > + .modinfo : { *(.modinfo) } \
> > > > .comment 0 : { *(.comment) } \
> > > > .symtab 0 : { *(.symtab) } \
> > > > .strtab 0 : { *(.strtab) } \
> > > > @@ -1044,7 +1045,6 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
> > > > *(.discard.*) \
> > > > *(.export_symbol) \
> > > > *(.no_trim_symbol) \
> > > > - *(.modinfo) \
> > > > /* ld.bfd warns about .gnu.version* even when not emitted */ \
> > > > *(.gnu.version*) \
> > > >
> > > > diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> > > > index 4f2d4c3fb7372..e2ceeb9e168d4 100644
> > > > --- a/scripts/Makefile.vmlinux
> > > > +++ b/scripts/Makefile.vmlinux
> > > > @@ -86,7 +86,7 @@ endif
> > > > # vmlinux
> > > > # ---------------------------------------------------------------------------
> > > >
> > > > -remove-section-y :=
> > > > +remove-section-y := .modinfo
> > > > remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> > > >
> > > > quiet_cmd_strip_relocs = OBJCOPY $@
> > > > diff --git a/scripts/mksysmap b/scripts/mksysmap
> > > > index 3accbdb269ac7..a607a0059d119 100755
> > > > --- a/scripts/mksysmap
> > > > +++ b/scripts/mksysmap
> > > > @@ -79,6 +79,9 @@
> > > > / _SDA_BASE_$/d
> > > > / _SDA2_BASE_$/d
> > > >
> > > > +# MODULE_INFO()
> > > > +/ __UNIQUE_ID_modinfo[0-9]*$/d
> > > > +
> > > > # ---------------------------------------------------------------------------
> > > > # Ignored patterns
> > > > # (symbols that contain the pattern are ignored)
> > > > --
> > > > 2.50.1
> > > >
> > >
> > > Hi Alexey,
> > >
> > > with this patch applied, I still get a warning from objcpy as Masahiro
> > > and Stephen wrote [1,2]
> > >
> > > SORTTAB vmlinux.unstripped
> > > + sorttable vmlinux.unstripped
> > > + nm -S vmlinux.unstripped
> > > + ./scripts/sorttable -s .tmp_vmlinux.nm-sort vmlinux.unstripped
> > > + is_enabled CONFIG_KALLSYMS
> > > + grep -q ^CONFIG_KALLSYMS=y include/config/auto.conf
> > > + cmp -s System.map .tmp_vmlinux2.syms
> > > + echo vmlinux.unstripped: ../scripts/link-vmlinux.sh
> > > # OBJCOPY vmlinux
> > > objcopy --remove-section=.modinfo vmlinux.unstripped vmlinux
> > > objcopy: vmlinux.unstripped: warning: empty loadable segment detected at vaddr=0xffff8000807a0000, is this intentional?
> > >
> > > (arm64, allnoconfig)
> > >
> > > Kind regards,
> > > Nicolas
> > >
> > >
> > > [1]: https://lore.kernel.org/linux-kbuild/CAK7LNAR-gD2H6Kk-rZjo0R3weTHCGTm0a=u2tRH1WWW6Sx6=RQ@mail.gmail.com/
> > > [2]: https://lore.kernel.org/lkml/20250730164047.7c4a731a@canb.auug.org.au/
> > >
> >
> > Hm. I missed that. I need to investigate how to fix this. Nothing comes
> > to mind right now.
>
> Same here. Only thing I could find until now is
>
> https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/diff/scripts/link-vmlinux.sh?id=90ceddcb495008ac8ba7a3dce297841efcd7d584
>
> where '2>/dev/null' is appended exactly to prevent this very warning.
> But for me, it doesn't feel good doing that when stripping to vmlinux.
Yes, that's not a very good approach. It will hide other errors that will
definitely need to be seen. I think the commit you mentioned is actually
incorrect. I think there should be a different solution.
I think in the case of .modinfo, we can change the flag in the section
since we are going to delete it anyway.
diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
index dbbe3bf0cf23..9a118b31d0dc 100644
--- a/scripts/Makefile.vmlinux
+++ b/scripts/Makefile.vmlinux
@@ -87,7 +87,8 @@ remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
remove-symbols := -w --strip-symbol='__mod_device_table__*'
quiet_cmd_strip_relocs = OBJCOPY $@
- cmd_strip_relocs = $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
+ cmd_strip_relocs = $(OBJCOPY) $(patsubst %,--set-section-flags %=noload,$(remove-section-y)) $< && \
+ $(OBJCOPY) $(addprefix --remove-section=,$(remove-section-y)) \
$(remove-symbols) $< $@
targets += vmlinux
--
Rgrds, legion
^ permalink raw reply related
* Re: [PATCH v7 3/8] kbuild: keep .modinfo section in vmlinux.unstripped
From: Nicolas Schier @ 2025-09-16 9:36 UTC (permalink / raw)
To: Alexey Gladkov
Cc: Nathan Chancellor, Petr Pavlu, Luis Chamberlain, Sami Tolvanen,
Daniel Gomez, linux-kernel, linux-modules, linux-kbuild,
Masahiro Yamada
In-Reply-To: <aMkN1m55vejTii_H@example.org>
On Tue, Sep 16, 2025 at 09:12:22AM +0200, Alexey Gladkov wrote:
> On Mon, Sep 15, 2025 at 07:56:16AM +0200, Nicolas Schier wrote:
> > On Mon, Aug 18, 2025 at 06:54:57PM +0200, Alexey Gladkov wrote:
> > > From: Masahiro Yamada <masahiroy@kernel.org>
> > >
> > > Keep the .modinfo section during linking, but strip it from the final
> > > vmlinux.
> > >
> > > Adjust scripts/mksysmap to exclude modinfo symbols from kallsyms.
> > >
> > > This change will allow the next commit to extract the .modinfo section
> > > from the vmlinux.unstripped intermediate.
> > >
> > > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > > ---
> > > include/asm-generic/vmlinux.lds.h | 2 +-
> > > scripts/Makefile.vmlinux | 2 +-
> > > scripts/mksysmap | 3 +++
> > > 3 files changed, 5 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> > > index ae2d2359b79e9..cfa63860dfd4c 100644
> > > --- a/include/asm-generic/vmlinux.lds.h
> > > +++ b/include/asm-generic/vmlinux.lds.h
> > > @@ -831,6 +831,7 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
> > >
> > > /* Required sections not related to debugging. */
> > > #define ELF_DETAILS \
> > > + .modinfo : { *(.modinfo) } \
> > > .comment 0 : { *(.comment) } \
> > > .symtab 0 : { *(.symtab) } \
> > > .strtab 0 : { *(.strtab) } \
> > > @@ -1044,7 +1045,6 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
> > > *(.discard.*) \
> > > *(.export_symbol) \
> > > *(.no_trim_symbol) \
> > > - *(.modinfo) \
> > > /* ld.bfd warns about .gnu.version* even when not emitted */ \
> > > *(.gnu.version*) \
> > >
> > > diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> > > index 4f2d4c3fb7372..e2ceeb9e168d4 100644
> > > --- a/scripts/Makefile.vmlinux
> > > +++ b/scripts/Makefile.vmlinux
> > > @@ -86,7 +86,7 @@ endif
> > > # vmlinux
> > > # ---------------------------------------------------------------------------
> > >
> > > -remove-section-y :=
> > > +remove-section-y := .modinfo
> > > remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> > >
> > > quiet_cmd_strip_relocs = OBJCOPY $@
> > > diff --git a/scripts/mksysmap b/scripts/mksysmap
> > > index 3accbdb269ac7..a607a0059d119 100755
> > > --- a/scripts/mksysmap
> > > +++ b/scripts/mksysmap
> > > @@ -79,6 +79,9 @@
> > > / _SDA_BASE_$/d
> > > / _SDA2_BASE_$/d
> > >
> > > +# MODULE_INFO()
> > > +/ __UNIQUE_ID_modinfo[0-9]*$/d
> > > +
> > > # ---------------------------------------------------------------------------
> > > # Ignored patterns
> > > # (symbols that contain the pattern are ignored)
> > > --
> > > 2.50.1
> > >
> >
> > Hi Alexey,
> >
> > with this patch applied, I still get a warning from objcpy as Masahiro
> > and Stephen wrote [1,2]
> >
> > SORTTAB vmlinux.unstripped
> > + sorttable vmlinux.unstripped
> > + nm -S vmlinux.unstripped
> > + ./scripts/sorttable -s .tmp_vmlinux.nm-sort vmlinux.unstripped
> > + is_enabled CONFIG_KALLSYMS
> > + grep -q ^CONFIG_KALLSYMS=y include/config/auto.conf
> > + cmp -s System.map .tmp_vmlinux2.syms
> > + echo vmlinux.unstripped: ../scripts/link-vmlinux.sh
> > # OBJCOPY vmlinux
> > objcopy --remove-section=.modinfo vmlinux.unstripped vmlinux
> > objcopy: vmlinux.unstripped: warning: empty loadable segment detected at vaddr=0xffff8000807a0000, is this intentional?
> >
> > (arm64, allnoconfig)
> >
> > Kind regards,
> > Nicolas
> >
> >
> > [1]: https://lore.kernel.org/linux-kbuild/CAK7LNAR-gD2H6Kk-rZjo0R3weTHCGTm0a=u2tRH1WWW6Sx6=RQ@mail.gmail.com/
> > [2]: https://lore.kernel.org/lkml/20250730164047.7c4a731a@canb.auug.org.au/
> >
>
> Hm. I missed that. I need to investigate how to fix this. Nothing comes
> to mind right now.
Same here. Only thing I could find until now is
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/diff/scripts/link-vmlinux.sh?id=90ceddcb495008ac8ba7a3dce297841efcd7d584
where '2>/dev/null' is appended exactly to prevent this very warning.
But for me, it doesn't feel good doing that when stripping to vmlinux.
--
Nicolas
^ permalink raw reply
* Re: [PATCH v7 3/8] kbuild: keep .modinfo section in vmlinux.unstripped
From: Alexey Gladkov @ 2025-09-16 7:12 UTC (permalink / raw)
To: Nicolas Schier
Cc: Nathan Chancellor, Petr Pavlu, Luis Chamberlain, Sami Tolvanen,
Daniel Gomez, linux-kernel, linux-modules, linux-kbuild,
Masahiro Yamada
In-Reply-To: <aMeqgPVfJcjBLhl8@levanger>
On Mon, Sep 15, 2025 at 07:56:16AM +0200, Nicolas Schier wrote:
> On Mon, Aug 18, 2025 at 06:54:57PM +0200, Alexey Gladkov wrote:
> > From: Masahiro Yamada <masahiroy@kernel.org>
> >
> > Keep the .modinfo section during linking, but strip it from the final
> > vmlinux.
> >
> > Adjust scripts/mksysmap to exclude modinfo symbols from kallsyms.
> >
> > This change will allow the next commit to extract the .modinfo section
> > from the vmlinux.unstripped intermediate.
> >
> > Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
> > ---
> > include/asm-generic/vmlinux.lds.h | 2 +-
> > scripts/Makefile.vmlinux | 2 +-
> > scripts/mksysmap | 3 +++
> > 3 files changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> > index ae2d2359b79e9..cfa63860dfd4c 100644
> > --- a/include/asm-generic/vmlinux.lds.h
> > +++ b/include/asm-generic/vmlinux.lds.h
> > @@ -831,6 +831,7 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
> >
> > /* Required sections not related to debugging. */
> > #define ELF_DETAILS \
> > + .modinfo : { *(.modinfo) } \
> > .comment 0 : { *(.comment) } \
> > .symtab 0 : { *(.symtab) } \
> > .strtab 0 : { *(.strtab) } \
> > @@ -1044,7 +1045,6 @@ defined(CONFIG_AUTOFDO_CLANG) || defined(CONFIG_PROPELLER_CLANG)
> > *(.discard.*) \
> > *(.export_symbol) \
> > *(.no_trim_symbol) \
> > - *(.modinfo) \
> > /* ld.bfd warns about .gnu.version* even when not emitted */ \
> > *(.gnu.version*) \
> >
> > diff --git a/scripts/Makefile.vmlinux b/scripts/Makefile.vmlinux
> > index 4f2d4c3fb7372..e2ceeb9e168d4 100644
> > --- a/scripts/Makefile.vmlinux
> > +++ b/scripts/Makefile.vmlinux
> > @@ -86,7 +86,7 @@ endif
> > # vmlinux
> > # ---------------------------------------------------------------------------
> >
> > -remove-section-y :=
> > +remove-section-y := .modinfo
> > remove-section-$(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS) += '.rel*'
> >
> > quiet_cmd_strip_relocs = OBJCOPY $@
> > diff --git a/scripts/mksysmap b/scripts/mksysmap
> > index 3accbdb269ac7..a607a0059d119 100755
> > --- a/scripts/mksysmap
> > +++ b/scripts/mksysmap
> > @@ -79,6 +79,9 @@
> > / _SDA_BASE_$/d
> > / _SDA2_BASE_$/d
> >
> > +# MODULE_INFO()
> > +/ __UNIQUE_ID_modinfo[0-9]*$/d
> > +
> > # ---------------------------------------------------------------------------
> > # Ignored patterns
> > # (symbols that contain the pattern are ignored)
> > --
> > 2.50.1
> >
>
> Hi Alexey,
>
> with this patch applied, I still get a warning from objcpy as Masahiro
> and Stephen wrote [1,2]
>
> SORTTAB vmlinux.unstripped
> + sorttable vmlinux.unstripped
> + nm -S vmlinux.unstripped
> + ./scripts/sorttable -s .tmp_vmlinux.nm-sort vmlinux.unstripped
> + is_enabled CONFIG_KALLSYMS
> + grep -q ^CONFIG_KALLSYMS=y include/config/auto.conf
> + cmp -s System.map .tmp_vmlinux2.syms
> + echo vmlinux.unstripped: ../scripts/link-vmlinux.sh
> # OBJCOPY vmlinux
> objcopy --remove-section=.modinfo vmlinux.unstripped vmlinux
> objcopy: vmlinux.unstripped: warning: empty loadable segment detected at vaddr=0xffff8000807a0000, is this intentional?
>
> (arm64, allnoconfig)
>
> Kind regards,
> Nicolas
>
>
> [1]: https://lore.kernel.org/linux-kbuild/CAK7LNAR-gD2H6Kk-rZjo0R3weTHCGTm0a=u2tRH1WWW6Sx6=RQ@mail.gmail.com/
> [2]: https://lore.kernel.org/lkml/20250730164047.7c4a731a@canb.auug.org.au/
>
Hm. I missed that. I need to investigate how to fix this. Nothing comes
to mind right now.
--
Rgrds, legion
^ permalink raw reply
* Re: [PATCH 2/4] PCI: Add KUnit tests for FIXUP quirks
From: Brian Norris @ 2025-09-15 20:25 UTC (permalink / raw)
To: Tzung-Bi Shih
Cc: Bjorn Helgaas, Luis Chamberlain, Petr Pavlu, Daniel Gomez,
linux-pci, David Gow, Rae Moar, linux-kselftest, linux-kernel,
linux-modules, Johannes Berg, Sami Tolvanen, Richard Weinberger,
Wei Liu, Brendan Higgins, kunit-dev, Anton Ivanov, linux-um
In-Reply-To: <aMfJCbld_TMHPTbD@google.com>
Hi,
On Mon, Sep 15, 2025 at 08:06:33AM +0000, Tzung-Bi Shih wrote:
> On Fri, Sep 12, 2025 at 03:59:33PM -0700, Brian Norris wrote:
> > +static int test_config_read(struct pci_bus *bus, unsigned int devfn, int where,
> > + int size, u32 *val)
> > +{
> > + if (PCI_SLOT(devfn) > 0)
> > + return PCIBIOS_DEVICE_NOT_FOUND;
> > +
> > + if (where + size > TEST_CONF_SIZE)
> > + return PCIBIOS_BUFFER_TOO_SMALL;
> > +
> > + if (size == 1)
> > + *val = test_readb(test_conf_space + where);
> > + else if (size == 2)
> > + *val = test_readw(test_conf_space + where);
> > + else if (size == 4)
> > + *val = test_readl(test_conf_space + where);
> > +
> > + return PCIBIOS_SUCCESSFUL;
>
> To handle cases where size might be a value other than {1, 2, 4}, would a
> switch statement with a default case be more robust here?
I was patterning based on pci_generic_config_read() and friends, but I
see that those use an 'else' for the last block, where I used an 'else
if'.
I suppose I could switch to 'else'. I'm not sure 'switch/case' is much
better.
> > +static int test_config_write(struct pci_bus *bus, unsigned int devfn, int where,
> > + int size, u32 val)
> > +{
> > + if (PCI_SLOT(devfn) > 0)
> > + return PCIBIOS_DEVICE_NOT_FOUND;
> > +
> > + if (where + size > TEST_CONF_SIZE)
> > + return PCIBIOS_BUFFER_TOO_SMALL;
> > +
> > + if (size == 1)
> > + test_writeb(test_conf_space + where, val);
> > + else if (size == 2)
> > + test_writew(test_conf_space + where, val);
> > + else if (size == 4)
> > + test_writel(test_conf_space + where, val);
> > +
> > + return PCIBIOS_SUCCESSFUL;
>
> Same here.
>
> > +static struct pci_dev *hook_device_early;
> > +static struct pci_dev *hook_device_header;
> > +static struct pci_dev *hook_device_final;
> > +static struct pci_dev *hook_device_enable;
> > +
> > +static void pci_fixup_early_hook(struct pci_dev *pdev)
> > +{
> > + hook_device_early = pdev;
> > +}
> > +DECLARE_PCI_FIXUP_EARLY(TEST_VENDOR_ID, TEST_DEVICE_ID, pci_fixup_early_hook);
> > [...]
> > +static int pci_fixup_test_init(struct kunit *test)
> > +{
> > + hook_device_early = NULL;
> > + hook_device_header = NULL;
> > + hook_device_final = NULL;
> > + hook_device_enable = NULL;
> > +
> > + return 0;
> > +}
>
> FWIW: if the probe is synchronous and the thread is the same task_struct,
> the module level variables can be eliminated by using:
>
> test->priv = kunit_kzalloc(...);
> KUNIT_ASSERT_PTR_NE(...);
>
> And in the hooks, kunit_get_current_test() returns the struct kunit *.
Ah, good suggestion, will give that a shot.
> > +static void pci_fixup_match_test(struct kunit *test)
> > +{
> > + struct device *dev = kunit_device_register(test, DEVICE_NAME);
> > +
> > + KUNIT_ASSERT_PTR_NE(test, NULL, dev);
> > +
> > + test_conf_space = kunit_kzalloc(test, TEST_CONF_SIZE, GFP_KERNEL);
> > + KUNIT_ASSERT_PTR_NE(test, NULL, test_conf_space);
>
> The common initialization code can be moved to pci_fixup_test_init().
>
> > + struct pci_host_bridge *bridge = devm_pci_alloc_host_bridge(dev, 0);
> > +
> > + KUNIT_ASSERT_PTR_NE(test, NULL, bridge);
> > + bridge->ops = &test_ops;
>
> The `bridge` allocation can be moved to .init() too.
>
> > + KUNIT_EXPECT_PTR_EQ(test, NULL, hook_device_early);
> > + KUNIT_EXPECT_PTR_EQ(test, NULL, hook_device_header);
> > + KUNIT_EXPECT_PTR_EQ(test, NULL, hook_device_final);
> > + KUNIT_EXPECT_PTR_EQ(test, NULL, hook_device_enable);
>
> Does it really need to check them? They are just initialized by .init().
Probably not. I wrote these before there were multiple test cases and an
.init() function, and I didn't reconsider them afterward. And they'll be
especially pointless once these move into a kzalloc'd private structure.
Thanks for the suggestions.
Brian
^ permalink raw reply
* Re: [PATCH 0/4] PCI: Add support and tests for FIXUP quirks in modules
From: Brian Norris @ 2025-09-15 18:41 UTC (permalink / raw)
To: Christoph Hellwig
Cc: Bjorn Helgaas, Luis Chamberlain, Petr Pavlu, Daniel Gomez,
linux-pci, David Gow, Rae Moar, linux-kselftest, linux-kernel,
linux-modules, Johannes Berg, Sami Tolvanen, Richard Weinberger,
Wei Liu, Brendan Higgins, kunit-dev, Anton Ivanov, linux-um
In-Reply-To: <aMgZJgU7p57KC0DL@infradead.org>
Hi Christoph,
On Mon, Sep 15, 2025 at 06:48:22AM -0700, Christoph Hellwig wrote:
> On Fri, Sep 12, 2025 at 03:59:31PM -0700, Brian Norris wrote:
> > This series primarily adds support for DECLARE_PCI_FIXUP_*() in modules.
> > There are a few drivers that already use this, and so they are
> > presumably broken when built as modules.
>
> That's a reall bad idea, because it allows random code to insert quirks
> not even bound to the hardware they support.
I see fixups in controller drivers here:
drivers/pci/controller/dwc/pci-imx6.c
drivers/pci/controller/dwc/pci-keystone.c
drivers/pci/controller/dwc/pcie-qcom.c
drivers/pci/controller/pci-loongson.c
drivers/pci/controller/pci-tegra.c
drivers/pci/controller/pcie-iproc-bcma.c
drivers/pci/controller/pcie-iproc.c
Are any of those somehow wrong?
And if they are not wrong, then is this a good reason to disallow making
these drivers modular? (Yes, few of them are currently modular; but I
don't see why that *must* be the case.)
I agree, as with many kernel features, there are plenty of ways to use
them incorrectly. But I'm just trying to patch over one rough edge about
how to use them incorrectly, and I don't really see why it's such a bad
idea.
> So no, modules should not allow quirks, but the kernel should probably
> be nice enough to fail compilation when someone is attemping that
> instead of silently ignoring the quirks.
Sure, if consensus says we should not support this, I'd definitely like
to make this failure mode more obvious -- likely a build error.
Thanks for your thoughts,
Brian
^ permalink raw reply
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox