From owner-svn-src-head@FreeBSD.ORG Tue May 26 01:40:34 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 1F689EFA; Tue, 26 May 2015 01:40:34 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E86AD16; Tue, 26 May 2015 01:40:33 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t4Q1eXDI001380; Tue, 26 May 2015 01:40:33 GMT (envelope-from delphij@FreeBSD.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t4Q1eXlj001379; Tue, 26 May 2015 01:40:33 GMT (envelope-from delphij@FreeBSD.org) Message-Id: <201505260140.t4Q1eXlj001379@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: delphij set sender to delphij@FreeBSD.org using -f From: Xin LI Date: Tue, 26 May 2015 01:40:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r283551 - head/sys/kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 26 May 2015 01:40:34 -0000 Author: delphij Date: Tue May 26 01:40:33 2015 New Revision: 283551 URL: https://svnweb.freebsd.org/changeset/base/283551 Log: MFuser/delphij/zfs-arc-rebase@r281754: In r256613, taskqueue_enqueue_locked() have been modified to release the task queue lock before returning. In r276665, taskqueue_drain_all() will call taskqueue_enqueue_locked() to insert the barrier task into the queue, but did not reacquire the lock after it but later code expects the lock still being held (e.g. TQ_SLEEP()). The barrier task is special and if we release then reacquire the lock, there would be a small race window where a high priority task could sneak into the queue. Looking more closely, the race seems to be tolerable but is undesirable from semantics standpoint. To solve this, in taskqueue_drain_tq_queue(), instead of directly calling taskqueue_enqueue_locked(), insert the barrier task directly without releasing the lock. Modified: head/sys/kern/subr_taskqueue.c Directory Properties: head/ (props changed) head/sys/ (props changed) Modified: head/sys/kern/subr_taskqueue.c ============================================================================== --- head/sys/kern/subr_taskqueue.c Tue May 26 01:30:09 2015 (r283550) +++ head/sys/kern/subr_taskqueue.c Tue May 26 01:40:33 2015 (r283551) @@ -323,17 +323,16 @@ taskqueue_drain_tq_queue(struct taskqueu return; /* - * Enqueue our barrier with the lowest possible priority - * so we are inserted after all current tasks. + * Enqueue our barrier after all current tasks, but with + * the highest priority so that newly queued tasks cannot + * pass it. Because of the high priority, we can not use + * taskqueue_enqueue_locked directly (which drops the lock + * anyway) so just insert it at tail while we have the + * queue lock. */ - TASK_INIT(&t_barrier, 0, taskqueue_task_nop_fn, &t_barrier); - taskqueue_enqueue_locked(queue, &t_barrier); - - /* - * Raise the barrier's priority so newly queued tasks cannot - * pass it. - */ - t_barrier.ta_priority = USHRT_MAX; + TASK_INIT(&t_barrier, USHRT_MAX, taskqueue_task_nop_fn, &t_barrier); + STAILQ_INSERT_TAIL(&queue->tq_queue, &t_barrier, ta_link); + t_barrier.ta_pending = 1; /* * Once the barrier has executed, all previously queued tasks