Received: by 2002:a05:6a10:f3d0:0:0:0:0 with SMTP id a16csp174218pxv; Thu, 24 Jun 2021 05:35:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxjyByOk/nMB6Z0pxtTwxEmKQtkOFouXRdxgdxOzLhuGPMZuk1tFy5SFbGLnObAHwAGXXO8 X-Received: by 2002:a17:906:c1da:: with SMTP id bw26mr5057253ejb.253.1624538154745; Thu, 24 Jun 2021 05:35:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624538154; cv=none; d=google.com; s=arc-20160816; b=wwBOKRFpGntH/D0fCSf7LViJlHG8pBwwlrLdEQVaHfb0T9NsUA1a0rv2mZWdHNHSPj 9twejDriXU9CPFuTtSqQqVPioyfQIEfgukXttZfJ3wVrS3PZu8EgPen/QZw/1Qjp64Lb pLh00VaPf7KzAkcFwyy6QCej6tdri30+MirT/4Iy4PAWmMTnUzVvN7vMMTnrCHghNgfz 2Ns93aM1vYsY+fh7A8u9qhFQdkoie3YojUyrXUY79pu6cAuAo7JCwf2rTZyDy+Fyfa9M FhB3o+DDh2UiiBycJm213HBNhpOlBxATYhGhjQy1R47N/sCCdM587ieJVdVZ4V/Y7qAE LUpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=UUUXarb2xnaATprpWGSvTKdVqj+HoLO6sRysqz2WMUc=; b=HYqb+P1obVO3mNPwhGtAy2GwPUw981+PSiTjWflYKLjTlKQIcWFvFG3RSiVo0tv2gF DGXFhLNcQaSTgepob/A/dTls0ImK0N7nlAbOby9kf0lvBGd3xqJNMavj2CsXXhsAaCk5 d9vj1OROfsWrAgx1ldPQmXpW8ZFoehTRIWdbat1RVCj8G8vkr43CGf+AN/qxFVW3fh8P 7qvknKcMKSb45NMayfMnxEcE0uZ5cHb4QqEwube0jepSb14Xcb3j6vB/76rFUKQYOcwg n2K6NraqAdMiOJXWSb0XqJNYmnzDJOMFzsolJAofd65PR1vBA8Nvz6XZxL0+FPtsgZJX enOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synology.com header.s=123 header.b=gwALpyjV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synology.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b17si3135288edy.262.2021.06.24.05.35.31; Thu, 24 Jun 2021 05:35:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@synology.com header.s=123 header.b=gwALpyjV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=synology.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230188AbhFXMdj (ORCPT + 99 others); Thu, 24 Jun 2021 08:33:39 -0400 Received: from mail.synology.com ([211.23.38.101]:57720 "EHLO synology.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229505AbhFXMdd (ORCPT ); Thu, 24 Jun 2021 08:33:33 -0400 Received: from localhost.localdomain (unknown [10.17.210.104]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by synology.com (Postfix) with ESMTPSA id 78FDA157F371; Thu, 24 Jun 2021 20:31:13 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1624537873; bh=QAn28bZkU1zhptlirNyycdhlvS3W1aY4Z1E/pRqikQ8=; h=From:To:Cc:Subject:Date; b=gwALpyjVsrkZAw0xGAT4F9Lvmj1lColvw/hLx3/OFNJ6HglxTvjrMR/L6UIDZnarW ErLObRVzCSBzT8Vv/RU90j5Xhkn6FPPQ8D5g7T5ANHhYO1Izt3pkcyiu86TxxwEHNe PS2wXnDOTQu4tsNo87vN3whujS+3XpAN5YUGGK6s= From: edwardh To: axboe@kernel.dk, neilb@suse.com, hch@infradead.org Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, s3t@synology.com, bingjingc@synology.com, cccheng@synology.com, Edward Hsieh , Wade Liang Subject: [PATCH v4] block: fix trace completion for chained bio Date: Thu, 24 Jun 2021 20:30:30 +0800 Message-Id: <20210624123030.27014-1-edwardh@synology.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Synology-MCP-Status: no X-Synology-Spam-Flag: no X-Synology-Spam-Status: score=0, required 6, WHITELIST_FROM_ADDRESS 0 X-Synology-Virus-Status: no Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Edward Hsieh For chained bio, trace_block_bio_complete in bio_endio is currently called only by the parent bio once upon all chained bio completed. However, the sector and size for the parent bio are modified in bio_split. Therefore, the size and sector of the complete events might not match the queue events in blktrace. The original fix of bio completion trace ("block: trace completion of all bios.") wants multiple complete events to correspond to one queue event but missed this. The issue can be reproduced by md/raid5 read with bio cross chunks. To fix, move trace completion into the loop for every chained bio to call. Fixes: fbbaf700e7b1 ("block: trace completion of all bios.") Reviewed-by: Wade Liang Reviewed-by: BingJing Chang Signed-off-by: Edward Hsieh --- block/bio.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/block/bio.c b/block/bio.c index 44205dfb6b60..1fab762e079b 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1375,8 +1375,7 @@ static inline bool bio_remaining_done(struct bio *bio) * * bio_endio() can be called several times on a bio that has been chained * using bio_chain(). The ->bi_end_io() function will only be called the - * last time. At this point the BLK_TA_COMPLETE tracing event will be - * generated if BIO_TRACE_COMPLETION is set. + * last time. **/ void bio_endio(struct bio *bio) { @@ -1389,6 +1388,11 @@ void bio_endio(struct bio *bio) if (bio->bi_bdev) rq_qos_done_bio(bio->bi_bdev->bd_disk->queue, bio); + if (bio->bi_bdev && bio_flagged(bio, BIO_TRACE_COMPLETION)) { + trace_block_bio_complete(bio->bi_bdev->bd_disk->queue, bio); + bio_clear_flag(bio, BIO_TRACE_COMPLETION); + } + /* * Need to have a real endio function for chained bios, otherwise * various corner cases will break (like stacking block devices that @@ -1402,11 +1406,6 @@ void bio_endio(struct bio *bio) goto again; } - if (bio->bi_bdev && bio_flagged(bio, BIO_TRACE_COMPLETION)) { - trace_block_bio_complete(bio->bi_bdev->bd_disk->queue, bio); - bio_clear_flag(bio, BIO_TRACE_COMPLETION); - } - blk_throtl_bio_endio(bio); /* release cgroup info */ bio_uninit(bio); -- 2.31.1