Re: [PATCH 4/6] kernel: add support for TIF_NOTIFY_SIGNAL

From: Jens Axboe
Date: Thu Oct 08 2020 - 10:07:59 EST


On 10/8/20 7:53 AM, Oleg Nesterov wrote:
> On 10/05, Jens Axboe wrote:
>>
>> static inline int signal_pending(struct task_struct *p)
>> {
>> +#ifdef TIF_NOTIFY_SIGNAL
>> + /*
>> + * TIF_NOTIFY_SIGNAL isn't really a signal, but it requires the same
>> + * behavior in terms of ensuring that we break out of wait loops
>> + * so that notify signal callbacks can be processed.
>> + */
>> + if (unlikely(test_tsk_thread_flag(p, TIF_NOTIFY_SIGNAL)))
>> + return 1;
>> +#endif
>> return task_sigpending(p);
>> }
>
> perhaps we can add test_tsk_thread_mask() later...

Yeah would be nice, and I bet there are a lot of cases in the kernel
that test multiple bits like that.

>> static inline void restore_saved_sigmask_unless(bool interrupted)
>> {
>> - if (interrupted)
>> + if (interrupted) {
>> +#ifdef TIF_NOTIFY_SIGNAL
>> + WARN_ON(!test_thread_flag(TIF_SIGPENDING) &&
>> + !test_thread_flag(TIF_NOTIFY_SIGNAL));
>> +#else
>> WARN_ON(!test_thread_flag(TIF_SIGPENDING));
>> - else
>> +#endif
>> + } else {
>> restore_saved_sigmask();
>> + }
>
> I'd suggest to simply do
>
> - WARN_ON(!test_thread_flag(TIF_SIGPENDING));
> + WARN_ON(!signal_pending(current);

Ah yes, that's much better. I'll make the edit.

>> --- a/kernel/entry/kvm.c
>> +++ b/kernel/entry/kvm.c
>> @@ -8,6 +8,9 @@ static int xfer_to_guest_mode_work(struct kvm_vcpu *vcpu, unsigned long ti_work)
>> do {
>> int ret;
>>
>> + if (ti_work & _TIF_NOTIFY_SIGNAL)
>> + tracehook_notify_signal();
>
> Can't really comment this change, but to me it would be more safe to
> simply return -EINTR.
>
> Or perhaps even better, treat _TIF_NOTIFY_SIGNAL and _TIF_SIGPENDING
> equally:
>
> - if (ti_work & _TIF_SIGPENDING) {
> + if (ti_work & (_TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL)) {
> kvm_handle_signal_exit(vcpu);
> return -EINTR;

Not sure I follow your logic here. Why treat it any different than
NOTIFY_RESUME from this perspective?

--
Jens Axboe