On 10/16, OGAWA Hirofumi wrote:
>
> > +void flush_delayed_work(struct delayed_work *dwork)
> > +{
> > +   if (del_timer(&dwork->timer)) {
> > +           struct cpu_workqueue_struct *cwq;
> > +           cwq = wq_per_cpu(keventd_wq, get_cpu());
> > +           __queue_work(cwq, &dwork->work);
> > +           put_cpu();
> > +   }
> > +   flush_work(&dwork->work);
> > +}
> > +EXPORT_SYMBOL(flush_delayed_work);
> > +
> > +/**
>
> Sorry if I'm missing the point. Doesn't this have (possible) race with
> schedule_delayed_work() (i.e. by tty writer)?
>
>              cpu0                                      cpu1
>
>     if (del_timer(&dwork->timer)) {

If dwork->timer is pending - _PENDING must be set.
If del_timer() succeeds, nobody else can clear this bit.

>                                             // cpu0 doesn't set _PENDING
>                                             schedule_delayed_work()

and in this case schedule_delayed_work()->queue_delayed_work_on()
can't succeed because it does test_and_set_bit(_PENDING).


But. Since this helper was merged, I think it should use del_timer_sync()
to be correct. Yes, it is slower, but otherwise flush is racy.

And I think it should return a bolean to match flush_work(). IOW,

        int flush_delayed_work(struct delayed_work *dwork)
        {
                int requeued = false;

                if (del_timer(&dwork->timer)) {
                        struct cpu_workqueue_struct *cwq;
                        cwq = wq_per_cpu(keventd_wq, get_cpu());
                        __queue_work(cwq, &dwork->work);
                        put_cpu();

                        requeued = true;
                }

                return flush_work(&dwork->work) || requeued;
        }

Not that I think this is terribly important, but still.

I'll send the patch.

Oleg.

--
To unsubscribe from this list: send the line "unsubscribe kernel-testers" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to