Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp2094649imc; Fri, 22 Feb 2019 18:02:56 -0800 (PST) X-Google-Smtp-Source: AHgI3IYID/eCntjCXjF2PTZa4csoAMugFCPkd90MW6KUwo2XeDeGwkFShxvxBSccENLNjar8tuWd X-Received: by 2002:a17:902:6b8c:: with SMTP id p12mr7370068plk.282.1550887376397; Fri, 22 Feb 2019 18:02:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550887376; cv=none; d=google.com; s=arc-20160816; b=gRsSQxn8rff/L9hICSwUn+UeyoHP68zKHt4BuMYLjUey+ZzSTHbXeRkmME2aJQm/O4 6IKXH9yvQnvJ72t4YNop0gb/Gw72RJOZzrSTyyNzStDLSJehbmsipBEshJo+MYSYaTc4 MmdFP0XQXTXDa9CZxUlpwkJd+ib7F54POdiY9xn3Qnq2aGbiOp9eUprr8/9xBsf0fWt8 0sTn33IBWD4HieFhTf3cQEU6KiQCTLIVgw5+layxj81PXj2H15optFkWaNTbI/kk9RNt 2OPLUEhCKqIOzPCwT6yYh/ksskDlhX/Js23UCmGC5iw1zfOLBk2jsK3Ab+Q3BIAE1QlA l10Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version; bh=L5h5aKB9ypEsmCRZ2jB2Ch/NJ7tYai3CALCA/A6vD5M=; b=msdD/o6aP/iHxEuatxM7/BDZwuxS1yzEbq11XDrNvG0sPEoQmHU5ja4v6UIDuLMmV6 c0VWiz409T3ctI2sxTHdw58QitMWFBXwb7aPm3ipZHSaY9xCwHLs6vz29fyyXMXMFUYC hMkhqzQsCoAI0HOJNbG7il80mzPRSNsU48kl7DUq4SYbaZXq5qVja5lj8vqGRzJPKVIA Xb3qu1nNGNCzKpVBOt9REu9KV/xpGgpaeeYA5/TvN3PmNd7++WSGvur+09xyApzOnUmJ WnJSsm8+np/EZNqpIgFL8a/TGrmsS5GuiNKjUhK+EK9EawjNYsmrBFXJJmKKlueHIKcB sW3Q== 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 b98si2944358plb.230.2019.02.22.18.02.38; Fri, 22 Feb 2019 18:02:56 -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 S1727132AbfBWCCS (ORCPT + 99 others); Fri, 22 Feb 2019 21:02:18 -0500 Received: from mail-qt1-f172.google.com ([209.85.160.172]:33429 "EHLO mail-qt1-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725821AbfBWCCS (ORCPT ); Fri, 22 Feb 2019 21:02:18 -0500 Received: by mail-qt1-f172.google.com with SMTP id z39so4799199qtz.0 for ; Fri, 22 Feb 2019 18:02:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=L5h5aKB9ypEsmCRZ2jB2Ch/NJ7tYai3CALCA/A6vD5M=; b=pSB13+qOb0frKpN6kXwjNUGQRDbMjft8g1PZ2TEwmCw1zGJpTR6KHUzD4icf2do2Qb v13rTUdOKC+7i9qaLCq0Wl06E50d7Pu1aYY/ZCBaH/CwiJEHCRUHzYbLMMBHKaL3ZfC4 2DBmeW3NJU3FsSVlWTS379eZjVLlgHzKmt9tstA9UTgOke+Ln9VCh0TSRB/QNqYrsoS6 W8uFX0r6eGcO6gStdXzULVB18/xODqmYW5ZpdQ4iJzg3YkkrVVURMxAzUvjVGQcI9FlE BFzCWnx5Z7uP4tOZ09wvABhcsgRcXPUmoo5yk/TRjHvteI6HNjHA308dvfIiAMjDsEhP nN6Q== X-Gm-Message-State: AHQUAub6p4lFv1eYazMSuuRv2fSAa6MYwqiAXU3C8yZBVigTOi8GpYBe 3GYhPnxvsnJEMc5C5/mu7UXIe+uX3X01KAbTH5NAsg== X-Received: by 2002:ac8:2fda:: with SMTP id m26mr5525567qta.312.1550887337521; Fri, 22 Feb 2019 18:02:17 -0800 (PST) MIME-Version: 1.0 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> In-Reply-To: <20190222235459.GA11726@redhat.com> From: John Dorminy Date: Fri, 22 Feb 2019 21:02:06 -0500 Message-ID: Subject: Re: block: be more careful about status in __bio_chain_endio To: Mike Snitzer Cc: Jens Axboe , NeilBrown , linux-block@vger.kernel.org, device-mapper development , Milan Broz , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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?