Re: [PATCH v1 1/3] printk: honor the max_reason field in kmsg_dumper

From: Sergey Senozhatsky
Date: Mon May 04 2020 - 21:02:29 EST


On (20/05/02 10:35), Pavel Tatashin wrote:
[..]
> +static bool always_kmsg_dump;
> +module_param_named(always_kmsg_dump, always_kmsg_dump, bool, S_IRUGO | S_IWUSR);
>
> /**
> * kmsg_dump_register - register a kernel log dumper.
> @@ -3106,6 +3108,12 @@ int kmsg_dump_register(struct kmsg_dumper *dumper)
> spin_lock_irqsave(&dump_list_lock, flags);
> /* Don't allow registering multiple times */
> if (!dumper->registered) {
> + if (!dumper->max_reason) {
> + if (always_kmsg_dump)
> + dumper->max_reason = KMSG_DUMP_MAX;
> + else
> + dumper->max_reason = KMSG_DUMP_OOPS;
> + }
> dumper->registered = 1;
> list_add_tail_rcu(&dumper->list, &dump_list);
> err = 0;

[..]

> @@ -3157,12 +3162,9 @@ void kmsg_dump(enum kmsg_dump_reason reason)
> struct kmsg_dumper *dumper;
> unsigned long flags;
>
> - if ((reason > KMSG_DUMP_OOPS) && !always_kmsg_dump)
> - return;
> -
> rcu_read_lock();
> list_for_each_entry_rcu(dumper, &dump_list, list) {
> - if (dumper->max_reason && reason > dumper->max_reason)
> + if (reason > dumper->max_reason)
> continue;

Why always_kmsg_dump check moved from the dumper loop entry point to the
dumper registration code? What if the user change always_ksmsg_dump
dynamically via sysfs?

-ss