From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 503A7C433B4 for ; Mon, 5 Apr 2021 16:05:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2E36C613D3 for ; Mon, 5 Apr 2021 16:05:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242120AbhDEQFf (ORCPT ); Mon, 5 Apr 2021 12:05:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:57682 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241958AbhDEQFb (ORCPT ); Mon, 5 Apr 2021 12:05:31 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 10924613DA; Mon, 5 Apr 2021 16:05:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617638724; bh=Pnu4XLT048i01pPL7dUpm0pczXeNSgGFed1aJZ2t7Wc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FxePwx7IPWUlKbMJXhHYqL1OdpYkYg66aUNzLF4/akhVXRS0zsFypaAbyzJXltCGk Hs2B/omW8SfnfbgrCG+aXgnSR1tt7WqCa0zq7JyDH5c6iGxaoOBAMqmB0vrrbom2Dw FJbggzSt9dM37d6agex3PxIMI2bru5WVoMDOtFs+n2eUTIbe0BvaoiIT2VuaQZySpR cvcfXuEN3os5HIp7vMxZU6inMGpoP1MylT9qVqTmekgvG9BHasH08j+oE4geYhCJRY HMa1Cup3dEEDNKs6lgaP5yf20Df7MyXhKnsmTibDDc7QvGsLJoLCgP0/WO70P03csg wmpp2axtZz6bg== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Yufen Yu , Keith Busch , Ming Lei , Jens Axboe , Sasha Levin , linux-block@vger.kernel.org Subject: [PATCH AUTOSEL 4.19 7/8] block: only update parent bi_status when bio fail Date: Mon, 5 Apr 2021 12:05:14 -0400 Message-Id: <20210405160515.269020-7-sashal@kernel.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210405160515.269020-1-sashal@kernel.org> References: <20210405160515.269020-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org From: Yufen Yu [ Upstream commit 3edf5346e4f2ce2fa0c94651a90a8dda169565ee ] For multiple split bios, if one of the bio is fail, the whole should return error to application. But we found there is a race between bio_integrity_verify_fn and bio complete, which return io success to application after one of the bio fail. The race as following: split bio(READ) kworker nvme_complete_rq blk_update_request //split error=0 bio_endio bio_integrity_endio queue_work(kintegrityd_wq, &bip->bip_work); bio_integrity_verify_fn bio_endio //split bio __bio_chain_endio if (!parent->bi_status) nvme_irq blk_update_request //parent error=7 req_bio_endio bio->bi_status = 7 //parent bio parent->bi_status = 0 parent->bi_end_io() // return bi_status=0 The bio has been split as two: split and parent. When split bio completed, it depends on kworker to do endio, while bio_integrity_verify_fn have been interrupted by parent bio complete irq handler. Then, parent bio->bi_status which have been set in irq handler will overwrite by kworker. In fact, even without the above race, we also need to conside the concurrency beteen mulitple split bio complete and update the same parent bi_status. Normally, multiple split bios will be issued to the same hctx and complete from the same irq vector. But if we have updated queue map between multiple split bios, these bios may complete on different hw queue and different irq vector. Then the concurrency update parent bi_status may cause the final status error. Suggested-by: Keith Busch Signed-off-by: Yufen Yu Reviewed-by: Ming Lei Link: https://lore.kernel.org/r/20210331115359.1125679-1-yuyufen@huawei.com Signed-off-by: Jens Axboe Signed-off-by: Sasha Levin --- block/bio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/bio.c b/block/bio.c index 3d757055305f..fe749404ef93 100644 --- a/block/bio.c +++ b/block/bio.c @@ -314,7 +314,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) parent->bi_status = bio->bi_status; bio_put(bio); return parent; -- 2.30.2