From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753443AbYK0UQA (ORCPT ); Thu, 27 Nov 2008 15:16:00 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752416AbYK0UPv (ORCPT ); Thu, 27 Nov 2008 15:15:51 -0500 Received: from mx2.redhat.com ([66.187.237.31]:54910 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752301AbYK0UPv (ORCPT ); Thu, 27 Nov 2008 15:15:51 -0500 Date: Thu, 27 Nov 2008 21:13:58 +0100 From: Oleg Nesterov To: Davide Libenzi Cc: Tejun Heo , Eric Van Hensbergen , Ron Minnich , Ingo Molnar , Christoph Hellwig , Miklos Szeredi , Brad Boyer , Al Viro , Roland McGrath , Mauro Carvalho Chehab , Andrew Morton , Linux Kernel Mailing List Subject: Re: [PATCH] poll: allow f_op->poll to sleep, take#5 Message-ID: <20081127201358.GA19874@redhat.com> References: <20081125173032.GA21539@redhat.com> <492CD1AB.3000802@kernel.org> <492CD358.2020603@gmail.com> <492CEF04.6070100@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11/26, Davide Libenzi wrote: > > w1) WR dev->events > w2) WR triggered (1) > w3) WMB > w4) WR task->state (RUNNING) > ... > That is, an MB before w3 (triggered=1) and a set_mb(triggered,0) at > s5+s6. The spinlock on the queue taken before entering pollwake() is not > enough to guarantee the required ordering, since a LOCK is no guarantee > that operations before it are visible after the LOCK. > Without the MB at w2, it could happen [w3, s5, s7, w1] that will make us > miss the event *and* sleep. I think you are very right. Actually, this is just like W: fill_data(&DATA); wmb(); DATA_is_ready = 1; // triggered wake_up(wq); S: set_current_state(state); if (DATA_is_ready) ret = poll(&DATA); else schedule(); without wmb() above poll(&DATA) can obviously return the wrong value. Oleg.