Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LMkxr-00067d-BV for qemu-devel@nongnu.org; Tue, 13 Jan 2009 10:13:59 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1LMkxp-000665-JS for qemu-devel@nongnu.org; Tue, 13 Jan 2009 10:13:58 -0500 Received: from [199.232.76.173] (port=57953 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LMkxp-00065u-FP for qemu-devel@nongnu.org; Tue, 13 Jan 2009 10:13:57 -0500 Received: from savannah.gnu.org ([199.232.41.3]:56687 helo=sv.gnu.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1LMkxp-00049X-14 for qemu-devel@nongnu.org; Tue, 13 Jan 2009 10:13:57 -0500 Received: from cvs.savannah.gnu.org ([199.232.41.69]) by sv.gnu.org with esmtp (Exim 4.63) (envelope-from ) id 1LMkxn-0002qD-HY for qemu-devel@nongnu.org; Tue, 13 Jan 2009 15:13:55 +0000 Received: from aliguori by cvs.savannah.gnu.org with local (Exim 4.63) (envelope-from ) id 1LMkxm-0002q3-TZ for qemu-devel@nongnu.org; Tue, 13 Jan 2009 15:13:55 +0000 MIME-Version: 1.0 Errors-To: aliguori Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit From: Anthony Liguori Message-Id: Date: Tue, 13 Jan 2009 15:13:54 +0000 Subject: [Qemu-devel] [6278] Fix race in POSIX AIO emulation (Jan Kiszka) Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Revision: 6278 http://svn.sv.gnu.org/viewvc/?view=rev&root=qemu&revision=6278 Author: aliguori Date: 2009-01-13 15:13:53 +0000 (Tue, 13 Jan 2009) Log Message: ----------- Fix race in POSIX AIO emulation (Jan Kiszka) When we cancel an AIO request that is already being processed by aio_thread, qemu_paio_cancel should return QEMU_PAIO_NOTCANCELED as long as aio_thread isn't done with this request. But as the latter currently updates aiocb->ret after every block of the request, we may report QEMU_PAIO_ALLDONE too early. Futhermore, in case some zero-length request should have been queued, aiocb->ret is never set to != -EINPROGRESS and callers like raw_aio_cancel could get stuck in an endless loop. Fix those issues by updating aiocb->ret _after_ the request has been fully processed. This also simplifies the locking. Signed-off-by: Jan Kiszka Signed-off-by: Anthony Liguori Modified Paths: -------------- trunk/posix-aio-compat.c Modified: trunk/posix-aio-compat.c =================================================================== --- trunk/posix-aio-compat.c 2009-01-12 21:33:22 UTC (rev 6277) +++ trunk/posix-aio-compat.c 2009-01-13 15:13:53 UTC (rev 6278) @@ -81,21 +81,16 @@ if (len == -1 && errno == EINTR) continue; else if (len == -1) { - pthread_mutex_lock(&lock); - aiocb->ret = -errno; - pthread_mutex_unlock(&lock); + offset = -errno; break; } else if (len == 0) break; offset += len; - - pthread_mutex_lock(&lock); - aiocb->ret = offset; - pthread_mutex_unlock(&lock); } pthread_mutex_lock(&lock); + aiocb->ret = offset; idle_threads++; pthread_mutex_unlock(&lock);