Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp2120047imc; Fri, 22 Feb 2019 18:45:11 -0800 (PST) X-Google-Smtp-Source: AHgI3IajTsdseBIAXYh8AXLrLpm6nyI+kd3hU58cCK9rXzQ9n1eN4PCOeJWy6RpAcKoryHQQc1J5 X-Received: by 2002:a17:902:6681:: with SMTP id e1mr7268600plk.98.1550889911229; Fri, 22 Feb 2019 18:45:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550889911; cv=none; d=google.com; s=arc-20160816; b=Vd1ni0SmAVnUUARSBkuu+BaHjzumOjvb0JyFy+dvnqrEt3AtuVSEuWz8lhNwSxdD44 KKYmSvg/rAiU4bC9/uQFQrEznBQgnSoQbSYNcwOOLnnhdKDMGakw4l9a3Rh/83eBt7oO xwcvqu/NRBez63G3kFfUsaZAETDWGaXgpttEW4gveR6exFH1iK/dGxsZpg9ouLAmct0z NTxgDUsq59E26fmSu/4llE9rZ2pnfirK8cGk7hG5rkf76oseNWZcnJkiQLdd8oVIoTsI 1S1NhqYyDbDFiMhiAar6lTwdYm8icCgXtkROzl/auxZ3m8S7r7bSy1ZnpbJ6sQzRpdj+ pxyg== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Q+LU6GPK1stdUf8zLGcPWJeUTHtmwVHMcdyindJN/GI=; b=K1F6HhdnKOJNerK/dXm1PjOTSfXi1c3XAGlsLD7rZ5BsmAsgVpqYw/fMa6IxjU29fl 7c+G3F4Oc7t13uqfj6If94FSedQaZXQeTZKAlmF03P0giZFVbvUWnl95tnESMWISTx1R TtWhb0XcyoVrQOYoufkpEffRxmxvuidJgSqa+H9eKndJ4Wa5etaj4m0qaf4S8iVRKc78 OtJsYP7OgoDa8PgzFZtGZZGMJpYrS4lqJ5PUN4EkWuPWmK9mQspQSJHFM60qPEpjd84u T+M/Xi7WhDip1QiNlT7Dhe/79hv/wdC3MFMIdkD72GWttgkRrhDgPDUGrd4KZ/kVYJiT KzOA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g98si3043800plb.99.2019.02.22.18.44.44; Fri, 22 Feb 2019 18:45:11 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727587AbfBWCoJ (ORCPT + 99 others); Fri, 22 Feb 2019 21:44:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46364 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725821AbfBWCoI (ORCPT ); Fri, 22 Feb 2019 21:44:08 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 879493003B34; Sat, 23 Feb 2019 02:44:08 +0000 (UTC) Received: from localhost (unknown [10.18.25.174]) by smtp.corp.redhat.com (Postfix) with ESMTPS id E7362600CD; Sat, 23 Feb 2019 02:44:03 +0000 (UTC) Date: Fri, 22 Feb 2019 21:44:02 -0500 From: Mike Snitzer To: John Dorminy Cc: Jens Axboe , NeilBrown , linux-block@vger.kernel.org, device-mapper development , Milan Broz , Linux Kernel Mailing List Subject: Re: block: be more careful about status in __bio_chain_endio Message-ID: <20190223024402.GA12407@redhat.com> References: <70cda2a3-f246-d45b-f600-1f9d15ba22ff@gmail.com> <87eflmpqkb.fsf@notabene.neil.brown.name> <20190222211006.GA10987@redhat.com> <7f0aeb7b-fdaa-0625-f785-05c342047550@kernel.dk> <20190222235459.GA11726@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Sat, 23 Feb 2019 02:44:08 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 22 2019 at 9:02pm -0500, John Dorminy wrote: > I am perhaps not understanding the intricacies here, or not seeing a > barrier protecting it, so forgive me if I'm off base. I think reading > parent->bi_status here is unsafe. > Consider the following sequence of events on two threads. > > Thread 0 Thread 1 > In __bio_chain_endio: In __bio_chain_endio: > [A] Child 0 reads parent->bi_status, > no error. > Child bio 1 reads parent, no error seen > It sets parent->bi_status to an error > It calls bio_put. > Child bio 0 calls bio_put > [end __bio_chain_endio] [end __bio_chain_endio] > In bio_chain_endio(), bio_endio(parent) > is called, calling bio_remaining_done() > which decrements __bi_remaining to 1 > and returns false, so no further endio > stuff is done. > In bio_chain_endio(), bio_endio(parent) > is called, calling bio_remaining_done(), > decrementing parent->__bi_remaining to > 0, and continuing to finish parent. > Either for block tracing or for parent's > bi_end_io(), this thread tries to read > parent->bi_status again. > > The compiler or the CPU may cache the read from [A], and since there > are no intervening barriers, parent->bi_status is still believed on > thread 0 to be success. Thus the bio may still be falsely believed to > have completed successfully, even though child 1 set an error in it. > > Am I missing a subtlety here? Either neilb's original or even Jens' suggestion would be fine though. > if (!parent->bi_status && bio->bi_status) > parent->bi_status = bio->bi_status; Even if your scenario did play out (which I agree it looks possible) it'd just degenerate to neilb's version: > if (bio->bi_status) > parent->bi_status = bio->bi_status; Which also accomplishes fixing what Neil originally detailed in his patch header.