From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796130509; b=1JiTZ7XFOA8MMTvp/UJnBE07qLRRsMYwGDut0N8hVV+8sBwrbpoke1Q3fR1xYWUd/r/L tM6wDLV0NZyGKzFYILEnlHOGTgUauqTKwoUKs+71ly8IZb3WZwlQU4EseBfLuxD/aY6Dc J83JLOZDJ1uOT91r2BGqe36Vp31G61kVqJ5evWogWxVqfaR7aFu5OpDG5RjQZfQ1/kIlN qlFVQg541TIiY3Anv/QO25ZzXWU7AVKQnzEq1gauolov2QVnxbnJxEVkJUm18bKKOteQU nNLZjWROcb+gHcW7en/voVThMazcRvYetmAEc0nKzXijeKkiXEScVja65wfsFsT9n5w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796130509; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received: X-Received:Received:Message-ID:Date:MIME-Version:User-Agent: Content-Language:To:Cc:From:Subject:Content-Type: Content-Transfer-Encoding; bh=j24U3tMKPDcnDUu3qAdciWR7T/nLQeFOx+mRrz4HzyM=; b=OVxsR5io1mLPAjw0LnxasosCwsg+mmpGkbThWvjjkf62xzlYjNO+lVAG5fIz2y5UCjpE FXUquso27rYxhZwzIJaKMxyPlytOJgLdOGJTD9YF8yiAdFmv7bn6M7uoKfBM1qssegVfK 9iSXuZlYUJCclfPp0RFFBmDPt6/2UdjCliudRg9jBWL9mzKnOSmVWvRSjnxGY3Hft1kob HhFNxrZnUU9b0hN3TcxIwjiRnrJnp88gtnuqD55WbSdLTjBEO0SMtZa3t1ZgsqreajGpo BX1p5G9JtCfi7Eylc6m/6RFPNtlTxoguAL7wuhcBib1MV+7AbVyfxvcg65jdBO4Q5cA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bTy5Ew7n; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=PndOFhz9; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31A73606A31A for ; Tue, 1 Dec 2026 13:08:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 31A73606A31A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=bTy5Ew7n; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=google header.b=PndOFhz9 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1796130509; 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; bh=j24U3tMKPDcnDUu3qAdciWR7T/nLQeFOx+mRrz4HzyM=; b=bTy5Ew7nbhJzlFVThm4bAfR8DTwiLIcbDhWK2JlCPXYnTk9NIrxTE+QexWL7eAOgLw3KSV vlAPHL1uvUWOxiTw3AG7R5TSBViuhJWZ8FpJARByHkMRoiljCvRutCD0a4uKPIZocLLrnu RO4e8yVo05uex1RqTHTwoGaCp24pmPs= Received: from mail-lj1-f200.google.com (mail-lj1-f200.google.com [209.85.208.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-158-s4QjK4MCNQCGtSxrHVu_-A-1; Tue, 1 Dec 2026 13:08:26 +0000 X-MC-Unique: s4QjK4MCNQCGtSxrHVu_-A-1 X-Mimecast-MFC-AGG-ID: s4QjK4MCNQCGtSxrHVu_-A_1796130505 Received: by mail-lj1-f200.google.com with SMTP id 38308e7fff4ca-3ad09084d85so44333841fa.3 for ; Tue, 01 Dec 2026 05:08:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1796130505; x=1796735305; darn=vger.kernel.org; h=content-transfer-encoding:content-type:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=j24U3tMKPDcnDUu3qAdciWR7T/nLQeFOx+mRrz4HzyM=; b=PndOFhz99Fwgl5lN8HodA/RudPMyJ4rZ74Q4sePhyMS9pZ9hhrI4tw4RaXnhYuTqLU V51I3uIOV6KzJ6Gu/bliRpkQMQyPphA+CBReeEIwQOlc/aXVTaWLj6KcbWWmhtLbWGwf Xzg6SEv2cg9pWpj2xzo3UEglgVCQ/ZWSmvuueT+OCMSRH00WFw31iIopOm6D+2kCI/2U 7qi8Bk18iBD/ezhZy7i7kQMekeSgtEyqk1sBliNjTWLBTlXZUnHkJgOZOSV+Hmn1qXBb oF/l37Yw395JlL0Q3vudmDgNFWNrTITXIpZ0s29HOhBms+CQSN49sapJGegST7nyZ//A x2uA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796130505; x=1796735305; h=content-transfer-encoding:content-type:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=j24U3tMKPDcnDUu3qAdciWR7T/nLQeFOx+mRrz4HzyM=; b=U0s3CJCTDvu+bQH/vbTQ8aQ96wUiC3Nu/PwYN3fDAxtxylBVUg0jFCnRCHvqYNgPi5 fyg1pnA945wK6rjKYr41VOMAkcSm6l3w29rFeqlwt+ESzsLSgukWoyG13PbUkHEMGOW2 kde4pYf1jHF0z1u/N0FH2qmLlV/dxgixuUaQM2XtS3EGv4anRpIfT/U38HrS4IKeeZzr /WeKVBY4TwASyDCwscmCvq5Q0w4W7U3uR7BSeGQk69DbMCNEUdUjA2Gig9v488hbfJiM NuNjLTzzg3jnv17zW1OsfnWMljbUAq21hFF5h4rtQ1dBvBANHcMdJeQlJjnodsDMfDmO cErw== X-Forwarded-Encrypted: i=1; AL+hErFd5uwf04K1G482uAv+eMITLxbvTcPXJJswU+w95EV+YudzhHTGCXaScXb5bH8Rf59Za5GZEFLuNheL@vger.kernel.org X-Gm-Message-State: APuU4Z+ruTnMxB8WWH3sMIMB7C/Jt+dTvjweQi4FB3J6+SudNskrIUif y1kG9ddTGWDAWAw+KPYWwryaiIINlLf5sXHAkYSWW9Dp6z1yK+6sVKJTvIS7Rc6y6NQ8sGS4VeB WFU49uOLmwYS7FImP0VVhtxh+QPqHMaJqhRWpenLfhjS/DatzD3RK6n47avxqw0U= X-Gm-Gg: AZFdTZcN/OUbPvYWTxHJMnz/fxung0p+jniXSdNmh/SjM75WNLKFJPH7TCBWoHAYoXA z01HK45lYtqZlAAkysIO99lpx91x25OB7Rc9QNMltB9brgnxEo2LhwIjeLYoiCnqLwjuUHpYjjN Lee7DbFO7+smrTWYePKzAn3NDxVIueqwciQYUaX52zftuBjBfaO6MoqN4OL5zoKOcNc7bRgd9jD iAY1oysM+m0D6iN1QQ/RCV1Zh6w0/gzKo4HekwHv0zYD3Cs698qLtGUvb3HTOl+hYdJxg/JP+MF dwXuBNSQCKmkqbyJGk/rz1z8evZ/cDA5tRACPeYhomVwcrZ3VUPI/eIQGmDINrzYh/i5gs44zGm r7O7dQu7FXQYSY9IHywSW9yuqJsJ8GMLVNLxdzhg3H52h7X9NF06Jxuk9QzG+IGVGAdgW X-Received: by 2002:a05:6512:1247:b0:5c0:b5c:408d with SMTP id 2adb3069b0e04-5c1bc6f6c9dmr10628865e87.6.1796130504377; Tue, 01 Dec 2026 05:08:24 -0800 (PST) X-Received: by 2002:a05:6512:1247:b0:5c0:b5c:408d with SMTP id 2adb3069b0e04-5c1bc6f6c9dmr10628856e87.6.1796130503861; Tue, 01 Dec 2026 05:08:23 -0800 (PST) Received: from [192.168.50.139] ([23.160.248.161]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5c1bcf332e3sm8872074e87.1.2026.12.01.05.08.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Dec 2026 05:08:23 -0800 (PST) Message-ID: <3b82697c-06de-4854-a2be-0832435f7e83@redhat.com> Date: Tue, 1 Dec 2026 08:08:20 -0500 X-Mailing-List: linux-raid@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: song@kernel.org, yukuai@kernel.org, linux-raid@vger.kernel.org Cc: stable@vger.kernel.org From: Nigel Croxon Subject: [PATCH] md/raid1: keep write-intent bitmap dirty until write-behind, copy completes Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit When a write-intent bitmap is used together with --write-behind on a --write-mostly member, the on-disk bitmap dirty bit (and Events Cleared) can be cleared before the deferred write to the write-mostly member has actually reached the disk. If a crash or I/O error happens in that window, a later bitmap-based resync (e.g. --re-add) skips chunks that were never written to the write-mostly device, silently corrupting data while the array reports itself clean and in sync. Commit cd5fc653381811 ("md/md-bitmap: move bitmap_{start, end}write to md upper layer") moved the bitmap chunk start/end accounting into the md upper layer: md_clone_bio() starts it and md_end_clone_io() ends it when the master bio completes. For write-behind, raid1_end_write_request() ends the master bio early via call_bio_endio() as soon as the non-write-mostly mirrors are done (behind_remaining >= remaining - 1), while the write-mostly bio is still in flight. That early completion runs md_end_clone_io() -> md_bitmap_end() and clears the chunk too soon. Before that commit, raid1 ended the bitmap chunk in close_write(), which runs only once r1_bio->remaining == 0, i.e. after every member including the write-behind copy has completed. Restore that ordering for the write-behind case. Add md_io_clone->no_bitmap_end so a personality can tell the md upper layer not to end the bitmap chunk in md_end_clone_io(). raid1 sets it when arming behind I/O and ends the chunk itself in close_write(), using r1_bio->sector/sectors (raid1 has no ->bitmap_sector hook and md_account_bio() runs after the request is split, so they match the clone's offset/sectors). Fixes: cd5fc653381811 ("md/md-bitmap: move bitmap_{start, end}write to md upper layer") Reported-by: Yuki Inoguchi Signed-off-by: Nigel Croxon ---  drivers/md/md.c    |  3 ++-  drivers/md/md.h    |  6 ++++++  drivers/md/raid1.c | 31 ++++++++++++++++++++++++++++---  3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/drivers/md/md.c b/drivers/md/md.c index 03e35386a802..61ecb21c2781 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -9495,7 +9495,7 @@ static void md_end_clone_io(struct bio *bio)      struct completion *reshape_completion = bio->bi_private;      if (bio_data_dir(orig_bio) == WRITE && md_io_clone->sectors && -        md_bitmap_enabled(mddev, false)) +        !md_io_clone->no_bitmap_end && md_bitmap_enabled(mddev, false))          md_bitmap_end(mddev, md_io_clone);      if (bio->bi_status && !orig_bio->bi_status) @@ -9523,6 +9523,7 @@ static void md_clone_bio(struct mddev *mddev, struct bio **bio)      md_io_clone->orig_bio = *bio;      md_io_clone->mddev = mddev;      md_io_clone->sectors = 0; +    md_io_clone->no_bitmap_end = false;      if (blk_queue_io_stat(bdev->bd_disk->queue))          md_io_clone->start_time = bio_start_io_acct(*bio);      else diff --git a/drivers/md/md.h b/drivers/md/md.h index 6440da292105..b338368c0307 100644 --- a/drivers/md/md.h +++ b/drivers/md/md.h @@ -885,6 +885,12 @@ struct md_io_clone {      sector_t    offset;      unsigned long    sectors;      enum stat_group    rw; +    /* +     * When set, md_end_clone_io() will NOT end the write-intent bitmap +     * chunk for this clone; the personality (e.g. raid1 write-behind) ends +     * it itself once all member writes have completed. +     */ +    bool        no_bitmap_end;      struct bio    bio_clone;  }; diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c index 894efb50c6d5..0cfb9c91aa31 100644 --- a/drivers/md/raid1.c +++ b/drivers/md/raid1.c @@ -445,8 +445,21 @@ static void close_write(struct r1bio *r1_bio)          r1_bio->behind_master_bio = NULL;      } -    if (test_bit(R1BIO_BehindIO, &r1_bio->state)) +    if (test_bit(R1BIO_BehindIO, &r1_bio->state)) { +        /* +         * The write-intent bitmap chunk endwrite was deferred for this +         * write-behind request (md_io_clone->no_bitmap_end) so the dirty +         * bit stays set until the slow write-mostly copy is on disk.  All +         * members have now completed (r1_bio->remaining == 0), so end the +         * chunk here -- the pre-regression end point.  Otherwise the early +         * behind-write ACK would clear the bit while the write-mostly +         * write was still in flight, silently losing data on --re-add. +         */ +        if (md_bitmap_enabled(mddev, false)) +            mddev->bitmap_ops->end_write(mddev, r1_bio->sector, +                             r1_bio->sectors);          mddev->bitmap_ops->end_behind_write(mddev); +    }      md_write_end(mddev);  } @@ -1453,9 +1466,21 @@ static void raid1_start_write_behind(struct mddev *mddev, struct r1bio *r1_bio,      if (!stats.behind_wait && stats.behind_writes < max_write_behind)          alloc_behind_master_bio(r1_bio, bio); -    if (test_bit(R1BIO_BehindIO, &r1_bio->state)) -        mddev->bitmap_ops->start_behind_write(mddev); +    if (test_bit(R1BIO_BehindIO, &r1_bio->state)) { +        /* +         * Defer the bitmap chunk endwrite to close_write() for this +         * write-behind request.  Otherwise the md upper layer would end +         * it from md_end_clone_io() on the early behind-write ACK, while +         * the write-mostly copy is still in flight.  See close_write() +         * and md_io_clone->no_bitmap_end. +         */ +        struct md_io_clone *md_io_clone = +            container_of(r1_bio->master_bio, struct md_io_clone, +                     bio_clone); +        md_io_clone->no_bitmap_end = true; +        mddev->bitmap_ops->start_behind_write(mddev); +    }  }  static bool raid1_write_request(struct mddev *mddev, struct bio *bio, -- 2.47.3