Received: by 2002:ac0:b08d:0:0:0:0:0 with SMTP id l13csp1963016imc; Fri, 22 Feb 2019 14:47:55 -0800 (PST) X-Google-Smtp-Source: AHgI3IYn7AESCAxHEtoJoY5cA7v77m5hjzzzpEF6djix7kXYOLTpMU4/OMyyhGKSm37cNUDKqMoS X-Received: by 2002:a17:902:bcc6:: with SMTP id o6mr6453562pls.39.1550875674923; Fri, 22 Feb 2019 14:47:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550875674; cv=none; d=google.com; s=arc-20160816; b=MJ35fN3/DOmGpDv7R9Wuzun7YFw0sHWcOJN+/Kc5ZRGYbr/J0t8Vv1SynpBAdaKwGl kMPjVGVK/NBg3YdJKiT+qe6nIqMsi07oE/LuXd4+eOeueVIyJe+5A9SfOzIzYdlInrLk fk14uV3NtjXU5fEKg83xHdyRljnPdfcu1sDppWp5B/stoHtgqSaXYs5vuNWQpgcfadUH zJe+WMYbZqdiRmW++ZGLVm8vJtnWaYAJTKByInC+Q617Q+ZXtXPzNnZSOnqfoB362q0C mCrYmK9tVoYa+iTNzXY7FGFZkANnkmAuHavAf1VIQnrjpyJV9NnNKyWoxBwWiAcOd/hA xxEQ== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=qBOSh5c7P0DEQBU9HztfFzFFVSGGT9iqvgwTysEDZ3U=; b=d2HjowgP79fkNTXRwm+/2b2Sb5RTnLmXrmvb/B29V02PCjn2/lwIfgF39HhmPxmi2k +boKYbD6RJCCUAOT2ge4E4Yyg2OV3PsfjIcFSnB+b7KuuOck5d0N6kqpQJ8Kx/VHF91U D07MnREFCDWQLnA2tiY0+Kp6TtgASPp3FHQiIkwBQSepv0+DUhUUOR6QQ7pDtnWu0arr s35q3b8EZchzkhrxiNkdZha2zBleP5ZrnL/wY6DVGOcCyVr0yjaB4C/5D20cpkbo+zKM rCji0AhxMtNfSuT0Z8TFWFEH2JH/fI5lq4zj+048wx7dxD6MJazg8/yWAfHbL7Ln1wsp g0fA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=QcJLEAEe; 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 k70si2360767pgd.74.2019.02.22.14.47.39; Fri, 22 Feb 2019 14:47:54 -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; dkim=pass header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=QcJLEAEe; 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 S1726845AbfBVWrA (ORCPT + 99 others); Fri, 22 Feb 2019 17:47:00 -0500 Received: from mail-it1-f196.google.com ([209.85.166.196]:54627 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725936AbfBVWq7 (ORCPT ); Fri, 22 Feb 2019 17:46:59 -0500 Received: by mail-it1-f196.google.com with SMTP id w18so4013922itj.4 for ; Fri, 22 Feb 2019 14:46:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=qBOSh5c7P0DEQBU9HztfFzFFVSGGT9iqvgwTysEDZ3U=; b=QcJLEAEeUd7dHTFjrmu5J1pPK23qzxO8b+mAM9TGI2otq5DCfhGPIus0A9V62GCf04 NQMnKorZORY9/fqn/0BSG5IDYo75c8nAldZvrueIXHt40JhO2V2f0X0Hd0VfyXthG+EV QtBe1n5iX8g4UQ62tuqDAoUC2KuiCWZ1h2UyaTmbHK6AIJR4miJCzZo1Lt5psl/yOhrB aiAAD+gUUy963dA5KQjfXY329+Zss3ONR2dUotStCWyImFsF7UxK86m1pFmR0sra5r4R Q1mFOZqhhAvaEoUe3xviOKinowNolJBtwXEkGSzghpCSvWffrs73iiInK7De/pztdSi4 D9Rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=qBOSh5c7P0DEQBU9HztfFzFFVSGGT9iqvgwTysEDZ3U=; b=p4b/DEogcy4Bls6bxjCPlHA8vX530DdiMbvU9i/W+Y5HA/ud4R60B+2BFjGMwECFDd KAaSnyBdwlu4XGSFsDR0IzykBulJVWeJTO3UwBCct7ampE28MbczKwuJaoxT9QrHlIYD 2FQnrKQbPK2OG+TIVlTR1uxoxGqp9cRzGnhaOExm6JfohBR3oVcgbY5vbHj+A4HiScCm VV1J6MCghHNtHoyJ1WVeN+oHpKdwG3iqVaIUr/BrColcXADcjkb8pzFJgfostT49Oo1s CtBdTt+mgx6193jPt6gzX9Ds+M7tQ7yAzIEyvAGfGxzEqGy76eS9oTfc9XLY2QgmML1c 7pew== X-Gm-Message-State: AHQUAub8cqudHkJ+Mv9M7HGtg6i+uGE6nz6pxUIpuswzFUnQEInP3bkD 1Vx0pDfyw4F6r1fOy6XDJ1ZGT7m+sDJfmg== X-Received: by 2002:a02:9dd:: with SMTP id 90mr2811280jam.21.1550875618032; Fri, 22 Feb 2019 14:46:58 -0800 (PST) Received: from [172.19.131.32] ([8.46.76.24]) by smtp.gmail.com with ESMTPSA id l19sm1031645iob.46.2019.02.22.14.46.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Feb 2019 14:46:57 -0800 (PST) Subject: Re: block: be more careful about status in __bio_chain_endio To: Mike Snitzer , NeilBrown Cc: linux-block@vger.kernel.org, device-mapper development , Milan Broz , Linux Kernel Mailing List References: <70cda2a3-f246-d45b-f600-1f9d15ba22ff@gmail.com> <87eflmpqkb.fsf@notabene.neil.brown.name> <20190222211006.GA10987@redhat.com> From: Jens Axboe Message-ID: <7f0aeb7b-fdaa-0625-f785-05c342047550@kernel.dk> Date: Fri, 22 Feb 2019 15:46:43 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190222211006.GA10987@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/22/19 2:10 PM, Mike Snitzer wrote: > On Thu, Feb 15 2018 at 4:09am -0500, > NeilBrown wrote: > >> >> If two bios are chained under the one parent (with bio_chain()) >> it is possible that one will succeed and the other will fail. >> __bio_chain_endio must ensure that the failure error status >> is reported for the whole, rather than the success. >> >> It currently tries to be careful, but this test is racy. >> If both children finish at the same time, they might both see that >> parent->bi_status as zero, and so will assign their own status. >> If the assignment to parent->bi_status by the successful bio happens >> last, the error status will be lost which can lead to silent data >> corruption. >> >> Instead, __bio_chain_endio should only assign a non-zero status >> to parent->bi_status. There is then no need to test the current >> value of parent->bi_status - a test that would be racy anyway. >> >> Note that this bug hasn't been seen in practice. It was only discovered >> by examination after a similar bug was found in dm.c >> >> Signed-off-by: NeilBrown >> --- >> block/bio.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/block/bio.c b/block/bio.c >> index e1708db48258..ad77140edc6f 100644 >> --- a/block/bio.c >> +++ b/block/bio.c >> @@ -312,7 +312,7 @@ static struct bio *__bio_chain_endio(struct bio *bio) >> { >> struct bio *parent = bio->bi_private; >> >> - if (!parent->bi_status) >> + if (bio->bi_status) >> parent->bi_status = bio->bi_status; >> bio_put(bio); >> return parent; >> -- >> 2.14.0.rc0.dirty >> > > Reviewed-by: Mike Snitzer > > Jens, this one slipped through the crack just over a year ago. > It is available in patchwork here: > https://patchwork.kernel.org/patch/10220727/ Should this be: if (!parent->bi_status && bio->bi_status) parent->bi_status = bio->bi_status; perhaps? -- Jens Axboe