Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp7315121ybi; Mon, 22 Jul 2019 10:51:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqzH5Uf4ByQh+lM4IZJ2ustagJAXmUNmv3fc6RvAzAlQRFBJ1qoGhlpU/xGU2zVzw6ZC+Elr X-Received: by 2002:a17:90b:d8f:: with SMTP id bg15mr78013984pjb.65.1563817860615; Mon, 22 Jul 2019 10:51:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563817860; cv=none; d=google.com; s=arc-20160816; b=U+ANw1c2WqmdRG4DJhdTK0XrgsYoqpbJ144Szktp2bRS8LYCyOY5gvKtLNhuH5Ls7z oZPzyc3t7t160XWOSY/61ljuSkmipzDxfUvUNseEQ4GjcYTtV9x0C/2uBgZc52ARMKNs CbBvxtM/yAhHEvidKzuog4uUOV0U2GZb1Eu5js9zUE4Q3Cv6DHetbyaUqvtZNlaxanRF VxXVaKqzFBbcNYiS3msDmPGHQniojLqKbsbIBJjkVXga0HuWWgn1J8C6r8TDeolCV5h2 pzLHXvCyk3Za6G3QdNvItpbGTxWwkWLCMrpiyIGC9kb1PdWHgH3N9bubipHYCdOFLKwo 4h6Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=RwZIBmGpe6Ch1OhMIQEtezoTZ92I3yKQeRZwjwn0rdg=; b=scGzr6QiznPc7xDOtJAllK6/VTtlK/pPdG1k3JYnGtlQ5Lys95+0n4tv5DNNAmajfJ Y2MWf24d27w63o7pkD3TEN5eczLYsS6Za5JrpNmPjIe/NYNDdWcsntnSm49ae3yjxruw 7VyOuHn9S++5xBf04oOFID0/T4/o9UAEmFiLW1kMnnkIDhPX+4XA9wnfEUR3y6opa25j 2E1BoVPa9VI79Zpi3L4GjWWyP7BIQLWFfjYkg2V+qIf4SWJRABPAZvz7sPOYr07dNrGn XMt1GvTaG9v/bVeHoZ2fqOI/wUMZSDavXTD5rKk9mQRWfYDYP4t6BWYhE+ixWkLTtbKF xb7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=juK0GCh0; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m129si9751417pfm.15.2019.07.22.10.50.44; Mon, 22 Jul 2019 10:51:00 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=juK0GCh0; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731241AbfGVRWO (ORCPT + 99 others); Mon, 22 Jul 2019 13:22:14 -0400 Received: from mail-vs1-f67.google.com ([209.85.217.67]:44577 "EHLO mail-vs1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728233AbfGVRWN (ORCPT ); Mon, 22 Jul 2019 13:22:13 -0400 Received: by mail-vs1-f67.google.com with SMTP id v129so26698922vsb.11; Mon, 22 Jul 2019 10:22:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=RwZIBmGpe6Ch1OhMIQEtezoTZ92I3yKQeRZwjwn0rdg=; b=juK0GCh0oGkF8/qRwfMrY4o0UWQT7ucEH7fpdfVlk9ZyzemrMFDoJrl3IxM6HwYfQg GUa/3zrr3j1P/CczbEAu0wXPrIKSnGQiQupv+9X/2AS/7WuzgaTMTML/z1Zd817vfVFg Pu6A8O63YCtKFubGdDAgY17XBKhEntxodyMgyueVWyzNMKMx8phdH/KBT1mzvKLXOmzT LAzmyxvVDBRhcADNrafe6TJhODZTrsjIUBlCDyJO1iCXZvFJvtdIUlTP+ymkjwxIyngz YyvDpfpksbKKksRkeLAMEH71pSgakrTgqGGh/QjZzuA+Wz4mizVqFDTOnw+OhcwRPQGL cuxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=RwZIBmGpe6Ch1OhMIQEtezoTZ92I3yKQeRZwjwn0rdg=; b=Fb68t9Brd2Dx69a418YpqASOolJ/k1t2jDlqrNiNINPYpU1HRYlFTGZ9+Vm/dzl/Hd cro6vclkvtmj7MTzIGLaKMkWv2E4hVSTrbOxWqiB+3sEAQbZ2ET19MZZA7hLJmng8Shd f2CpcCwQtTJWKZ2aWo4Xy0DGdeOEY3rrnjm7/KNFN3fEpjzwZRQBR55e0SgtS8cO9HA6 EcRGIqOU0KlR4nXggdzlW7FLSFrbKoOvSrTopbF55SEdhcHBDbsMGGweS1s4MzmJ06kh EJXIsqWTuTdoFVx8Nk5qwstbOxHAjgWzXMc++RwSVH5zEvIYwQgw2hoxZcXaUago+9N6 mA1w== X-Gm-Message-State: APjAAAUUQNBH/AMQlpKqMnQFJHqLVd/1ybHBriV51j7Sj3001zMC7QjO Cx88IKQ+hHchqVpZD01kIfpEZJE4nQ== X-Received: by 2002:a67:c113:: with SMTP id d19mr3770488vsj.89.1563816132534; Mon, 22 Jul 2019 10:22:12 -0700 (PDT) Received: from kmo-pixel (c-71-234-172-214.hsd1.vt.comcast.net. [71.234.172.214]) by smtp.gmail.com with ESMTPSA id v5sm44538591vsi.24.2019.07.22.10.22.11 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 22 Jul 2019 10:22:11 -0700 (PDT) Date: Mon, 22 Jul 2019 13:22:09 -0400 From: Kent Overstreet To: Coly Li Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-bcache@vger.kernel.org Subject: Re: [PATCH 12/12] closures: fix a race on wakeup from closure_sync Message-ID: <20190722172209.GA25176@kmo-pixel> References: <20190610191420.27007-1-kent.overstreet@gmail.com> <20190610191420.27007-13-kent.overstreet@gmail.com> <8381178e-4c1e-e0fe-430b-a459be1a9389@suse.de> <48527b97-e39a-0791-e038-d9f2ec28943e@suse.de> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <48527b97-e39a-0791-e038-d9f2ec28943e@suse.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 18, 2019 at 03:46:46PM +0800, Coly Li wrote: > On 2019/7/16 6:47 下午, Coly Li wrote: > > Hi Kent, > > > > On 2019/6/11 3:14 上午, Kent Overstreet wrote: > >> Signed-off-by: Kent Overstreet > > Acked-by: Coly Li > > > > And also I receive report for suspicious closure race condition in > > bcache, and people ask for having this patch into Linux v5.3. > > > > So before this patch gets merged into upstream, I plan to rebase it to > > drivers/md/bcache/closure.c at this moment. Of cause the author is you. > > > > When lib/closure.c merged into upstream, I will rebase all closure usage > > from bcache to use lib/closure.{c,h}. > > Hi Kent, > > The race bug reporter replies me that the closure race bug is very rare > to reproduce, after applying the patch and testing, they are not sure > whether their closure race problem is fixed or not. > > And I notice rcu_read_lock()/rcu_read_unlock() is used here, but it is > not clear to me what is the functionality of the rcu read lock in > closure_sync_fn(). I believe you have reason to use the rcu stuffs here, > could you please provide some hints to help me to understand the change > better ? The race was when a thread using closure_sync() notices cl->s->done == 1 before the thread calling closure_put() calls wake_up_process(). Then, it's possible for that thread to return and exit just before wake_up_process() is called - so we're trying to wake up a process that no longer exists. rcu_read_lock() is sufficient to protect against this, as there's an rcu barrier somewhere in the process teardown path.