Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp731134imm; Thu, 13 Sep 2018 06:58:45 -0700 (PDT) X-Received: by 2002:a65:464b:: with SMTP id k11-v6mr7294564pgr.448.1536846885934; Thu, 13 Sep 2018 06:54:45 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZsy1CPMknajQwyjdXdDhUNdMJ3hXqTkgF6zYfn67PEtWRj4zBArwBh2aUOtYtAYeyn9FrX X-Received: by 2002:a65:464b:: with SMTP id k11-v6mr7294533pgr.448.1536846885485; Thu, 13 Sep 2018 06:54:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536846885; cv=none; d=google.com; s=arc-20160816; b=DurJeEmCcWEqtiRTLz4PWIEv1FoMuV4HBn6U2nERfY9xo0AWHey6oKmZiClEgLXIZe KxbIWya6HT2ZeyIisLX+BPeItTEeDWuS4B5hxCKP6IEK1XkmWv3DVchj9UcjdOsaLQlQ WyW3JGqaT6WkTY6JJVTCh0V+FujEPjNsRRneGfm6bkVaYc6z5Aa8Lj3wc4RlsdsbgWf7 Mmg90gULR05McdO8tN2aoIgolH45C/j6XLFIV6PoXXLeZOybqYoq0u+L1RfBc6Zb5fWw 3CkIWLqKOnr6obc2ms/DhEMvcvPUesoAX0zAnK0RpGid0on7kpXUihJvY3c8RSlyQje6 K5og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=zctmWGcnmXznqHWzPFgNWUoZTv4Dst+sNXkzJl7LEFE=; b=MVUqV2epxaqhoOaZ3/umi1vcuFW67m+FLc2MEtEipMb9kRKWAb8sdlkWA6xL5hfQym 15pfmxOHgl1lval+veAs+z3gX78s67yNvFxz/N9Y3nmqPIT4yxf4W1oS7geVY4FlnRE4 9VHH+wRTGfTz896T7QhsEHts5xvEXzRuCdZzfev5+oni4c81G02iGl8sx6UmiCSeflPr PNT8HfgtVk1nmzkvAIk+PqlwUnq37dWYdjcH/lqCQdv+Fw8Yq5RBVHeNAoOiyWimjT9a /s2uaj8YfEJgC5g9Yy8LiIbUAZQI1NTn8z726YCtVZJWGuVwpo0c8giLxYv5vRVCYPHU rvZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t21-v6si3956978plj.261.2018.09.13.06.54.30; Thu, 13 Sep 2018 06:54:45 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731089AbeIMTCp (ORCPT + 99 others); Thu, 13 Sep 2018 15:02:45 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:33642 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730002AbeIMTCp (ORCPT ); Thu, 13 Sep 2018 15:02:45 -0400 Received: from localhost (ip-213-127-77-73.ip.prioritytelecom.net [213.127.77.73]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 29149D19; Thu, 13 Sep 2018 13:53:08 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Berg , Tejun Heo , Sasha Levin Subject: [PATCH 4.18 050/197] workqueue: re-add lockdep dependencies for flushing Date: Thu, 13 Sep 2018 15:29:59 +0200 Message-Id: <20180913131843.539392943@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20180913131841.568116777@linuxfoundation.org> References: <20180913131841.568116777@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Johannes Berg [ Upstream commit 87915adc3f0acdf03c776df42e308e5a155c19af ] In flush_work(), we need to create a lockdep dependency so that the following scenario is appropriately tagged as a problem: work_function() { mutex_lock(&mutex); ... } other_function() { mutex_lock(&mutex); flush_work(&work); // or cancel_work_sync(&work); } This is a problem since the work might be running and be blocked on trying to acquire the mutex. Similarly, in flush_workqueue(). These were removed after cross-release partially caught these problems, but now cross-release was reverted anyway. IMHO the removal was erroneous anyway though, since lockdep should be able to catch potential problems, not just actual ones, and cross-release would only have caught the problem when actually invoking wait_for_completion(). Fixes: fd1a5b04dfb8 ("workqueue: Remove now redundant lock acquisitions wrt. workqueue flushes") Signed-off-by: Johannes Berg Signed-off-by: Tejun Heo Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- kernel/workqueue.c | 8 ++++++++ 1 file changed, 8 insertions(+) --- a/kernel/workqueue.c +++ b/kernel/workqueue.c @@ -2652,6 +2652,9 @@ void flush_workqueue(struct workqueue_st if (WARN_ON(!wq_online)) return; + lock_map_acquire(&wq->lockdep_map); + lock_map_release(&wq->lockdep_map); + mutex_lock(&wq->mutex); /* @@ -2905,6 +2908,11 @@ static bool __flush_work(struct work_str if (WARN_ON(!wq_online)) return false; + if (!from_cancel) { + lock_map_acquire(&work->lockdep_map); + lock_map_release(&work->lockdep_map); + } + if (start_flush_work(work, &barr, from_cancel)) { wait_for_completion(&barr.done); destroy_work_on_stack(&barr.work);