From mboxrd@z Thu Jan 1 00:00:00 1970 From: Oleg Nesterov Subject: Re: [Bug #14388] keyboard under X with 2.6.31 Date: Thu, 15 Oct 2009 21:00:24 +0200 Message-ID: <20091015190024.GA31559@redhat.com> References: <4AD4F548.2030506@microgate.com> <1255478932.19056.24.camel@localhost.localdomain> <4AD51D6B.7010509@microgate.com> <20091014125846.1a3c8d40@lxorguk.ukuu.org.uk> <87aazsh80x.fsf@devron.myhome.or.jp> Mime-Version: 1.0 Return-path: Content-Disposition: inline In-Reply-To: <87aazsh80x.fsf@devron.myhome.or.jp> Sender: linux-kernel-owner@vger.kernel.org List-ID: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: OGAWA Hirofumi Cc: Linus Torvalds , Alan Cox , Paul Fulghum , Boyan , "Rafael J. Wysocki" , Linux Kernel Mailing List , Kernel Testers List , Dmitry Torokhov , Ed Tomlinson 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.