From patchwork Tue May 30 15:49:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Thumshirn X-Patchwork-Id: 13260541 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 872CAC7EE31 for ; Tue, 30 May 2023 15:51:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232734AbjE3PvK (ORCPT ); Tue, 30 May 2023 11:51:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232713AbjE3PuY (ORCPT ); Tue, 30 May 2023 11:50:24 -0400 Received: from esa4.hgst.iphmx.com (esa4.hgst.iphmx.com [216.71.154.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6185106; Tue, 30 May 2023 08:50:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1685461815; x=1716997815; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KgD+R+FU9CwRmwQAVm8lMGGwTIZNIyKz56pAeZ5nm90=; b=UY9dUsgQIxE7KH2X0HZ3jTKyGDRRsslYd2cPZ2WqrEswekL8pc96jtOF f5AclahUxpKkQ0dBrulvbW68JJ+SEOelsex3NofM17vKcTI5bIA+SepMc VOF/JSQNiz0TWJuWRy8c1hkZpeoZtn6Hsi+KR6taE/Ns38YCUyYLcYKaz lJ4nVi6zDVBGgwur7rjwn2tfA/YWEFAYqWTa2F3BbCdIMNOkIomxqWYsp mFK00KdQ+zxjyNJVpTI9KOaVhiXBvAaNyqYlaGC3rFjHRRoPKmGJ2zpkS BSgXscp2xZZ55yQx+GekAD6FgcYT+sRADqT85J6ryes+ZuNcImELUz+rn g==; X-IronPort-AV: E=Sophos;i="6.00,204,1681142400"; d="scan'208";a="230129850" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 30 May 2023 23:50:15 +0800 IronPort-SDR: REV29gJcGUf9Oqk0h/ulr/eZVRI9BVpGY/pAQueYQAS88IVToU6Nsc1bx/K+HrbJ8rUhg0/q9c R6GtJQGGlcViErVyfQ1CNnBNw49/wofqjrPN6iD9lmhYGqS2MbfFhEL92Y09F5qx4v1IYCfOi/ BtF2CPZ/74DJkWRV1EAGMfiFduiXUpDM56ot6fPtiBRKY5DLB6i4IKKU747INgFKkgjjJi/x3H +WpMp3fUNkjMAUKLAYcDv3MQN4Jkj7stxXfmWykYBSvPOPyqcEgQHAKtV5ogN87JILHt5wknVV 8GA= Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 30 May 2023 08:05:08 -0700 IronPort-SDR: 7c9W4va7M7i7mOYdzqZM8x7PuIzd8bUXS81kk72ffccwZ6ZkU4gnwE7FR84LvLjYB86fEAuYwt cXn5GwLOtz5LieaQs84gdIlp6RO2hZOK/Ic6UwD4MNGrVkqvJ5LsygmJvgCDU0mJKU4+2g9Rib NOa0IbGiRr60yWN5pk4jtqYmp4DsQOvrRO9O0wvUsb0lo8oWhw/bmV6Xf7GGSKfY/bdv8SGb7j X21UMdAublIFCrvsHnUfL3ViWaZJVFO/anGXJGxTYW7s2jPCdwz49/iJqACLwkL9I9X1q4xZdH KrA= WDCIronportException: Internal Received: from unknown (HELO redsun91.ssa.fujisawa.hgst.com) ([10.149.66.6]) by uls-op-cesaip02.wdc.com with ESMTP; 30 May 2023 08:50:12 -0700 From: Johannes Thumshirn To: Jens Axboe Cc: Christoph Hellwig , Hannes Reinecke , Chaitanya Kulkarni , Damien Le Moal , Ming Lei , linux-block@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, dm-devel@redhat.com, Song Liu , linux-raid@vger.kernel.org, Mike Snitzer , Matthew Wilcox , Dave Kleikamp , jfs-discussion@lists.sourceforge.net, cluster-devel@redhat.com, Bob Peterson , Andreas Gruenbacher , Mikulas Patocka , gouhao@uniontech.com, Johannes Thumshirn , Damien Le Moal Subject: [PATCH v6 15/20] md: raid1: check if adding pages to resync bio fails Date: Tue, 30 May 2023 08:49:18 -0700 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org Check if adding pages to resync bio fails and if bail out. As the comment above suggests this cannot happen, WARN if it actually happens. This way we can mark bio_add_pages as __must_check. Reviewed-by: Damien Le Moal Acked-by: Song Liu Signed-off-by: Johannes Thumshirn --- drivers/md/raid1-10.c | 11 ++++++----- drivers/md/raid10.c | 20 ++++++++++---------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/md/raid1-10.c b/drivers/md/raid1-10.c index e61f6cad4e08..cd349e69ed77 100644 --- a/drivers/md/raid1-10.c +++ b/drivers/md/raid1-10.c @@ -101,11 +101,12 @@ static void md_bio_reset_resync_pages(struct bio *bio, struct resync_pages *rp, struct page *page = resync_fetch_page(rp, idx); int len = min_t(int, size, PAGE_SIZE); - /* - * won't fail because the vec table is big - * enough to hold all these pages - */ - bio_add_page(bio, page, len, 0); + if (WARN_ON(!bio_add_page(bio, page, len, 0))) { + bio->bi_status = BLK_STS_RESOURCE; + bio_endio(bio); + return; + } + size -= len; } while (idx++ < RESYNC_PAGES && size > 0); } diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c index 4fcfcb350d2b..381c21f7fb06 100644 --- a/drivers/md/raid10.c +++ b/drivers/md/raid10.c @@ -3819,11 +3819,11 @@ static sector_t raid10_sync_request(struct mddev *mddev, sector_t sector_nr, for (bio= biolist ; bio ; bio=bio->bi_next) { struct resync_pages *rp = get_resync_pages(bio); page = resync_fetch_page(rp, page_idx); - /* - * won't fail because the vec table is big enough - * to hold all these pages - */ - bio_add_page(bio, page, len, 0); + if (WARN_ON(!bio_add_page(bio, page, len, 0))) { + bio->bi_status = BLK_STS_RESOURCE; + bio_endio(bio); + goto giveup; + } } nr_sectors += len>>9; sector_nr += len>>9; @@ -4997,11 +4997,11 @@ static sector_t reshape_request(struct mddev *mddev, sector_t sector_nr, if (len > PAGE_SIZE) len = PAGE_SIZE; for (bio = blist; bio ; bio = bio->bi_next) { - /* - * won't fail because the vec table is big enough - * to hold all these pages - */ - bio_add_page(bio, page, len, 0); + if (WARN_ON(!bio_add_page(bio, page, len, 0))) { + bio->bi_status = BLK_STS_RESOURCE; + bio_endio(bio); + return sectors_done; + } } sector_nr += len >> 9; nr_sectors += len >> 9;