Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1495837pxb; Thu, 4 Mar 2021 12:54:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJzib+aUb+aPeaa5H1TkTBKigC9c8eHievW/LTxL6veTOY+bwk1bnheQ7JyhtHkgZ85XIS5s X-Received: by 2002:a17:906:9be1:: with SMTP id de33mr6629829ejc.320.1614891246065; Thu, 04 Mar 2021 12:54:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614891246; cv=none; d=google.com; s=arc-20160816; b=ZoQFuwwRDHbXQMZHoLb8rhUmgWWEcxlB4vHYZP9SOF9evHR/odxFlsTGlm7L2D/HsS ZS3CAAgLj9qk2B6c/A367D0OTZdYJZnW11BjoeZ8jUakycDtAi6eSmrFjBGbKORHdAMQ A+9XnVVzp3WBL367i1KtjyQ4V2opJ2tYi/dSYMEu44XA/kf7Uh4iClMup5I1C8/art4U 4LWGH3yj/yF86IWlZFck4S5MmQ39TRSFPIKTctend4KODmNV1wrklvEVQu6gx3hr6pGh cQAJiLIpaVAccMLk2g8ErEo87GDh4teKMUQUM/bJN73Si/+QWkm3pvirFkmpKBQOQ+F7 v+rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=vnqx+Izbhhx0esS4DchQeUkca+YMMEbonjc1EvnX9ZU=; b=upqd2BH3T0GcAQ4dCHA5L9FfleSoa9cbmMRkmNG6oYe//V9mumGVybiuVH735oLSzh V6LU8UYjGw3JIw6Xyne72k6YhlUtJXxt2Ij+AD6a6dMH6waGmn+t3y5/4/6LY4hZt9Ps K5iANCoIT6wRvLKUxEgv3Ml3WVaBQLqCJJWomP3lisk9SFGLD0oU4IBvRC9Vuu/UGoQ9 Dh5/Uu0Dc21gDiWUedmY7z4I/qA+jq80ck75zZ9uKeEBZonAsyoBfPZG9Ytl4HqRIxKu prWKMKnPgwao8SnFuUjqU3khslk4XDNguZjnR1kb5n7NaL/zvR3/+uOm1d+LC7wijiO4 u+Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@synology.com header.s=123 header.b=NRkkX1Sd; 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 cd26si191203ejb.473.2021.03.04.12.53.43; Thu, 04 Mar 2021 12:54:05 -0800 (PST) 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=NRkkX1Sd; 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 S1357941AbhCCLhV (ORCPT + 99 others); Wed, 3 Mar 2021 06:37:21 -0500 Received: from mail.synology.com ([211.23.38.101]:37154 "EHLO synology.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1351597AbhCCDXT (ORCPT ); Tue, 2 Mar 2021 22:23:19 -0500 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 F1D19CE781B5; Wed, 3 Mar 2021 11:22:37 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synology.com; s=123; t=1614741758; bh=xgbf6WZCaD/FFIaA3Mp4FPHSkXy9rxV+ldX5NyY3vEA=; h=From:To:Cc:Subject:Date; b=NRkkX1SdcFPOTAJK1DDZbDb4N8NJ9nEPoLKHMNd+OxBA6DVJRsTrVXFnj+qssv2ZJ UeGATxekQtR6iTZdty0Az+OeBXevMpDNx5/9zfCYXqY44z6TfcX/0tvp22v9NQu7T1 40hxIajkCGd1Q+dUewYACnzsaN20+zzl2TWMRckA= From: edwardh To: axboe@kernel.dk, neilb@suse.com Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, s3t@synology.com, bingjingc@synology.com, cccheng@synology.com, Edward Hsieh Subject: [PATCH v2] block: fix trace completion for chained bio Date: Wed, 3 Mar 2021 11:22:06 +0800 Message-Id: <1614741726-28074-1-git-send-email-edwardh@synology.com> X-Mailer: git-send-email 2.7.4 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. md/raid5 read with bio cross chunks can reproduce this issue. 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 a1c4d29..2ff72cb 100644 --- a/block/bio.c +++ b/block/bio.c @@ -1397,8 +1397,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) { @@ -1411,6 +1410,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 @@ -1424,11 +1428,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.7.4