Re: [PATCH 2/2] kernel/signal.c: explicitly initialize si_code and use ksig->info uniformly

From: Oleg Nesterov
Date: Thu Feb 22 2024 - 14:11:28 EST


On 02/23, wenyang.linux@xxxxxxxxxxx wrote:
>
> From: Wen Yang <wenyang.linux@xxxxxxxxxxx>
>
> By explicitly initializing ksig->info.si_code and uniformly using ksig->info,
> get_signal() function could be slightly optimized, as folowes:

I don't understand. Why do you think it will be optimized? in what sense?

> clear_siginfo(&ksig->info);
> ksig->info.si_signo = signr = SIGKILL; --> missed si_code

because we do not need to set .si_code in this case?

> sigdelset(&current->pending.signal, SIGKILL);
> trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO, --> unnecessary SEND_SIG_NOINFO

Why do you think the usage of SEND_SIG_NOINFO is "unnecessary" or bad?
To me this looks good.

> @@ -2732,8 +2732,9 @@ bool get_signal(struct ksignal *ksig)
> signal->group_exec_task) {
> clear_siginfo(&ksig->info);
> ksig->info.si_signo = signr = SIGKILL;
> + ksig->info.si_code = SI_USER;
> sigdelset(&current->pending.signal, SIGKILL);
> - trace_signal_deliver(SIGKILL, SEND_SIG_NOINFO,
> + trace_signal_deliver(SIGKILL, &ksig->info,

Well. to me this look like the minor but unnecessary pessimization.

AFAICS, we do not need to initialize .si_code. The usage if ksig->info
instead of ksig->info means that TP_STORE_SIGINFO() will actually read
the memory.

Sorry, I don't understand the point at all :/

and it seems that we can simply kill clear_siginfo(), but this is
another story.

Oleg.