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 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A202FCFC52A for ; Sat, 22 Nov 2025 12:01:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=JuZK2beRgEq+MC2I+vh3JTOKDyroWbZXDvE+0QrmUyk=; b=AIiuD3lOqvhdaFY4q2j0nLfKzG vI+4z5bZFy2VSrTRsLGa+uW5XL2bQ5nIYHjE8ut4vj6clLd+PpsKIcSNFpEvyMGYHz6IF6Yi8GCSj uGo7F98iwyK8bSMC3QSCFTu5/xvQ0h0dwIY2Jpx2f1ajzAXfvG4Abk0qndnBbwaz7pZ4OSl27h4V8 jzuli+j6u6zVAjd+MRukyvtntZLxMHEQWCSl40mMRhXVYcRebyUX3Zjzi7MohWtKqhyHHO3tc0s+R iUS4IU0F9CgTMhG5U680Sq5gwVZ6Rv8RkpKUfkcFGqzd3EGEKGVrmRkY0ldFScJuWw1OFSLe0YxHy P/pPohBw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vMmJ4-00000009WxE-2Ew7; Sat, 22 Nov 2025 12:01:34 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vMmJ0-00000009Wwf-0SuW for linux-nvme@lists.infradead.org; Sat, 22 Nov 2025 12:01:33 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1763812888; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=JuZK2beRgEq+MC2I+vh3JTOKDyroWbZXDvE+0QrmUyk=; b=HpA+Cd3hXKXlPgaK5i9n3BzJXJYSvYLTNikuiFjEtTiPrGAmhSzUylABI+oMSiBWfIkKCX J3IIFsBKNW/EhtEwfNEQ/TaVkW6rZzxlDOimLgllsEm4hiyNXpU0B7SDhhuMn7UWGcPgMP ZhOpKc6R7S6ukktq+qcKITRJ/gHqX/w= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-653-VC8oek4GOGiDUqoXurM1bg-1; Sat, 22 Nov 2025 07:01:26 -0500 X-MC-Unique: VC8oek4GOGiDUqoXurM1bg-1 X-Mimecast-MFC-AGG-ID: VC8oek4GOGiDUqoXurM1bg_1763812885 Received: from mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.17]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 28B171956080; Sat, 22 Nov 2025 12:01:24 +0000 (UTC) Received: from fedora (unknown [10.72.116.33]) by mx-prod-int-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 873C01940E82; Sat, 22 Nov 2025 12:01:14 +0000 (UTC) Date: Sat, 22 Nov 2025 20:01:08 +0800 From: Ming Lei To: Stephen Zhang Cc: linux-kernel@vger.kernel.org, linux-block@vger.kernel.org, nvdimm@lists.linux.dev, virtualization@lists.linux.dev, linux-nvme@lists.infradead.org, gfs2@lists.linux.dev, ntfs3@lists.linux.dev, linux-xfs@vger.kernel.org, zhangshida@kylinos.cn Subject: Re: Fix potential data loss and corruption due to Incorrect BIO Chain Handling Message-ID: References: <20251121081748.1443507-1-zhangshida@kylinos.cn> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Scanned-By: MIMEDefang 3.0 on 10.30.177.17 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251122_040130_565449_9900A833 X-CRM114-Status: GOOD ( 28.55 ) X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-nvme" Errors-To: linux-nvme-bounces+linux-nvme=archiver.kernel.org@lists.infradead.org On Sat, Nov 22, 2025 at 02:42:43PM +0800, Stephen Zhang wrote: > Ming Lei 于2025年11月22日周六 11:35写道: > > > > On Fri, Nov 21, 2025 at 04:17:39PM +0800, zhangshida wrote: > > > From: Shida Zhang > > > > > > Hello everyone, > > > > > > We have recently encountered a severe data loss issue on kernel version 4.19, > > > and we suspect the same underlying problem may exist in the latest kernel versions. > > > > > > Environment: > > > * **Architecture:** arm64 > > > * **Page Size:** 64KB > > > * **Filesystem:** XFS with a 4KB block size > > > > > > Scenario: > > > The issue occurs while running a MySQL instance where one thread appends data > > > to a log file, and a separate thread concurrently reads that file to perform > > > CRC checks on its contents. > > > > > > Problem Description: > > > Occasionally, the reading thread detects data corruption. Specifically, it finds > > > that stale data has been exposed in the middle of the file. > > > > > > We have captured four instances of this corruption in our production environment. > > > In each case, we observed a distinct pattern: > > > The corruption starts at an offset that aligns with the beginning of an XFS extent. > > > The corruption ends at an offset that is aligned to the system's `PAGE_SIZE` (64KB in our case). > > > > > > Corruption Instances: > > > 1. Start:`0x73be000`, **End:** `0x73c0000` (Length: 8KB) > > > 2. Start:`0x10791a000`, **End:** `0x107920000` (Length: 24KB) > > > 3. Start:`0x14535a000`, **End:** `0x145b70000` (Length: 8280KB) > > > 4. Start:`0x370d000`, **End:** `0x3710000` (Length: 12KB) > > > > > > After analysis, we believe the root cause is in the handling of chained bios, specifically > > > related to out-of-order io completion. > > > > > > Consider a bio chain where `bi_remaining` is decremented as each bio in the chain completes. > > > For example, > > > if a chain consists of three bios (bio1 -> bio2 -> bio3) with > > > bi_remaining count: > > > 1->2->2 > > > > Right. > > > > > if the bio completes in the reverse order, there will be a problem. > > > if bio 3 completes first, it will become: > > > 1->2->1 > > > > Yes. > > > > > then bio 2 completes: > > > 1->1->0 > > > > No, it is supposed to be 1->1->1. > > > > When bio 1 completes, it will become 0->0->0 > > > > bio3's `__bi_remaining` won't drop to zero until bio2's reaches > > zero, and bio2 won't be done until bio1 is ended. > > > > Please look at bio_endio(): > > > > void bio_endio(struct bio *bio) > > { > > again: > > if (!bio_remaining_done(bio)) > > return; > > ... > > if (bio->bi_end_io == bio_chain_endio) { > > bio = __bio_chain_endio(bio); > > goto again; > > } > > ... > > } > > > > Exactly, bio_endio handle the process perfectly, but it seems to forget > to check if the very first `__bi_remaining` drops to zero and proceeds to > the next bio: > ----- > static struct bio *__bio_chain_endio(struct bio *bio) > { > struct bio *parent = bio->bi_private; > > if (bio->bi_status && !parent->bi_status) > parent->bi_status = bio->bi_status; > bio_put(bio); > return parent; > } > > static void bio_chain_endio(struct bio *bio) > { > bio_endio(__bio_chain_endio(bio)); > } bio_chain_endio() never gets called really, which can be thought as `flag`, and it should have been defined as `WARN_ON_ONCE(1);` for not confusing people. So I don't think upstream kernel has the issue you described. Thanks, Ming