From patchwork Fri Feb 23 15:59:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13569353 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5F5D782D7D for ; Fri, 23 Feb 2024 15:59:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.153.30 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703997; cv=none; b=bRCMgDT7EuFuuEhUmaJR36uTHciLT1eADLAzWSBAmTGQ62bJs4xic1EfLZEis4aTSCG/+MA65mDfqKkJHrtc609SIOSuugvH5aSOcCgFfePDx/3EWSE3i8WjqVXtEhAZDeQvfIkkk3QFc/HNDGHukPhLqKUPj6mLjmYEZvYTH94= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703997; c=relaxed/simple; bh=QhJk5WCim3ppStJXdISlPyPXyOJjRwsz4DNi8IZIEJs=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=LsTp7qJaXZwOa1njRW6LijvsjCe04+D3MVfLwstpgxXXQChbiKiIToPWrrsQ32wE2Om+LbAZ0xqhaQmC+eSasvP9GmvBlj9Y43esG0+XcSJ8vewi1O/ayDkel75t3tII9QwkXg3EeDtEUEhfQJQvDnFBeOhJfokdv+dLtyipe6I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=RPQ/6m3a; arc=none smtp.client-ip=67.231.153.30 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="RPQ/6m3a" Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.17.1.19/8.17.1.19) with ESMTP id 41N36YH9008854 for ; Fri, 23 Feb 2024 07:59:55 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=s2048-2021-q4; bh=1NfP6xsV93KEOWBV/kWyr+viXR/FDP+NGbmg2sv08/I=; b=RPQ/6m3a+t3t5dviozTmEmY4mQDtjq/mn7hMzH+OuGMMS5qi1ndrRugB+ijSFaGPuVSj 3DOeJ5SLtbfmvITmHCWtRY3ZrktDCEdJwz1oXHGD0C/hZ0rzYostapdfdJsZuxaoyo+d tL1afHOcMiOozlJelD++eFRTOTGfj01aTp1sqpQEtvjUgi6MHTuAYf/GKY8w4OPGsI+h gfAlSrDJ08sL9IJM1ohd+OfTp2lSXmIY2iWn/B8/BRURGdsJbvtW7fXVtoLpg41WZ1SQ C9Yx1uYK+s7DAsjR2VJajUGUzPDZI5SJRX5vmaAiJleJnRcALK88GYMTcFBnlx2G4rAw WQ== Received: from mail.thefacebook.com ([163.114.132.120]) by m0089730.ppops.net (PPS) with ESMTPS id 3wek5m3a08-13 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 23 Feb 2024 07:59:55 -0800 Received: from twshared53729.38.frc1.facebook.com (2620:10d:c085:208::f) by mail.thefacebook.com (2620:10d:c085:11d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Fri, 23 Feb 2024 07:59:25 -0800 Received: by devbig007.nao1.facebook.com (Postfix, from userid 544533) id 9FFE42574FA41; Fri, 23 Feb 2024 07:59:12 -0800 (PST) From: Keith Busch To: CC: , , , , Keith Busch , Christoph Hellwig Subject: [PATCHv4 1/4] block: blkdev_issue_secure_erase loop style Date: Fri, 23 Feb 2024 07:59:07 -0800 Message-ID: <20240223155910.3622666-2-kbusch@meta.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223155910.3622666-1-kbusch@meta.com> References: <20240223155910.3622666-1-kbusch@meta.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: pkhawA1H3ttzLhS9_9rE4WZe98jMem4v X-Proofpoint-GUID: pkhawA1H3ttzLhS9_9rE4WZe98jMem4v X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-23_02,2024-02-23_01,2023-05-22_02 From: Keith Busch Use consistent coding style in this file. All the other loops for the same purpose use "while (nr_sects)", so they win. Reviewed-by: Ming Lei Reviewed-by: Christoph Hellwig Signed-off-by: Keith Busch --- block/blk-lib.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index e59c3069e8351..91770da2239f2 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -322,7 +322,7 @@ int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector, return -EPERM; blk_start_plug(&plug); - for (;;) { + while (nr_sects) { unsigned int len = min_t(sector_t, nr_sects, max_sectors); bio = blk_next_bio(bio, bdev, 0, REQ_OP_SECURE_ERASE, gfp); @@ -331,13 +331,12 @@ int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector, sector += len; nr_sects -= len; - if (!nr_sects) { - ret = submit_bio_wait(bio); - bio_put(bio); - break; - } cond_resched(); } + if (bio) { + ret = submit_bio_wait(bio); + bio_put(bio); + } blk_finish_plug(&plug); return ret; From patchwork Fri Feb 23 15:59:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13569352 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D18D1405C7 for ; Fri, 23 Feb 2024 15:59:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.145.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703973; cv=none; b=fcSv4QxHBmJ5YJ/3F43x/hcNjDC8s7VACtOnw4J+VS8ahE9O/HDaBUJN3RIV6xkmAEYZ+qcLyKUbQEJj2cxpUe9noDKtQP6v2SaYNlsRNjLshFG3hgwtTbCE9MWjTNKqSZWMZ30vT5APYTOawoBHFwGcCaRsHleWVmmvg0sFK+I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703973; c=relaxed/simple; bh=qjkfnx3lXgo+eKjLYIdsMj7wig4Syy+Jn8U+Yl45WWg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=nkqyh9dt7gu4s55njcsnIw/8G/nJZES2NxncmTKpIFeQi5QnNBTiV+Y5nLJQ1QzlEdvSexSJf9qwo24r4Mfk/M1EH6uhzpe7mLvZN0bFka/gnUPvbjFn6dxa9Uf/Sz+BUPSN3dbAtjpNQJui0eMINB4I0P749ohJpqPM0TV/kg4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=NcuUrRqS; arc=none smtp.client-ip=67.231.145.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="NcuUrRqS" Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41NEi8Rm022671 for ; Fri, 23 Feb 2024 07:59:31 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=s2048-2021-q4; bh=UvajsDIOtKJqeFO4f5D1zhd0cD5+h19KssvbIm8LbRU=; b=NcuUrRqSSQ4DtgXJ8CqwcKly4vVFLSqC8JEl2Ml2ctigiMZ7Q1hIA1YUhsvZIvuRRM40 ek8lEqcOEgm4X1r0MmsVvKGSvMYQg9oBqTEzELFMc31UVBOujxEk6b2p5p61yat+5GDk SnUjufRy1ymWQ7gx3mKI1Ys3vzYnLbsLvgDiNPPgT5i6KE1LgvuYINQTRXZAxYgQDMtL eTte3T/76xyxbWwIkeaUI1pssCp3D+GySpLLjPA/K8ntHHRbM7J3o4+VzpN0TkPOgfPP 7SH4Twk6yQspdhVhpY9+psU3SPrd6hpMT+KdtHjmrEEKekMdByxSIV1+nKBQDlyCB0Jo fA== Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3webyke4e9-12 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 23 Feb 2024 07:59:31 -0800 Received: from twshared34526.07.ash9.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:21d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Fri, 23 Feb 2024 07:59:26 -0800 Received: by devbig007.nao1.facebook.com (Postfix, from userid 544533) id E94CB2574FA44; Fri, 23 Feb 2024 07:59:12 -0800 (PST) From: Keith Busch To: CC: , , , , Keith Busch Subject: [PATCHv4 2/4] block: cleanup __blkdev_issue_write_zeroes Date: Fri, 23 Feb 2024 07:59:08 -0800 Message-ID: <20240223155910.3622666-3-kbusch@meta.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223155910.3622666-1-kbusch@meta.com> References: <20240223155910.3622666-1-kbusch@meta.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: GMDdntjW-9yHp09rvDcgx1CoHsesfu_3 X-Proofpoint-GUID: GMDdntjW-9yHp09rvDcgx1CoHsesfu_3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-23_02,2024-02-23_01,2023-05-22_02 From: Keith Busch Use min to calculate the next number of sectors like everyone else. Reviewed-by: Ming Lei Signed-off-by: Keith Busch Reviewed-by: Christoph Hellwig --- block/blk-lib.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index 91770da2239f2..a6954eafb8c8a 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -120,31 +120,28 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev, struct bio **biop, unsigned flags) { struct bio *bio = *biop; - unsigned int max_write_zeroes_sectors; + unsigned int max_sectors; if (bdev_read_only(bdev)) return -EPERM; - /* Ensure that max_write_zeroes_sectors doesn't overflow bi_size */ - max_write_zeroes_sectors = bdev_write_zeroes_sectors(bdev); + /* Ensure that max_sectors doesn't overflow bi_size */ + max_sectors = bdev_write_zeroes_sectors(bdev); - if (max_write_zeroes_sectors == 0) + if (max_sectors == 0) return -EOPNOTSUPP; while (nr_sects) { + unsigned int len = min_t(sector_t, nr_sects, max_sectors); + bio = blk_next_bio(bio, bdev, 0, REQ_OP_WRITE_ZEROES, gfp_mask); bio->bi_iter.bi_sector = sector; if (flags & BLKDEV_ZERO_NOUNMAP) bio->bi_opf |= REQ_NOUNMAP; - if (nr_sects > max_write_zeroes_sectors) { - bio->bi_iter.bi_size = max_write_zeroes_sectors << 9; - nr_sects -= max_write_zeroes_sectors; - sector += max_write_zeroes_sectors; - } else { - bio->bi_iter.bi_size = nr_sects << 9; - nr_sects = 0; - } + bio->bi_iter.bi_size = len << SECTOR_SHIFT; + nr_sects -= len; + sector += len; cond_resched(); } From patchwork Fri Feb 23 15:59:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13569354 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C962782D7D for ; Fri, 23 Feb 2024 15:59:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.153.30 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708704000; cv=none; b=mhY42jdjgQXdT0i2XYF5jmrQULGNKzuQLi1iO4sMUL+m0I+gg7fsC8d4k1KCSbcei3V3Xz/w/zgN8GOBR8SaapWy32Sikg9yjXDNJH0UtKIf9ahPCWvrDEJNovXgzGLYiN8ATgqbDGr3r+yQlPGSxOOrFo/6J5dX1V0mcE8i4Vs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708704000; c=relaxed/simple; bh=RFU7AQr6deKdQR+3toeNP+aMAS4K4nKfTYZSYGjPEY8=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=GU/hP0MB2k1qatOJPSANrbe3ElQzoJE2EgMPFo6xH6QBI0QeR1dXNjam51k8mckZ/ktrfX3ByML1f7kZsC2wgMICoo/FQ8xEPLGDZ4H9Q/Mvq5VElMVH4mRLb0Rxi9hv0Jt7YNgtTSXRulOt1Omr6rFxiTgYrvwcrr4RL8wSgNs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=FiL4UK+u; arc=none smtp.client-ip=67.231.153.30 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="FiL4UK+u" Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.17.1.19/8.17.1.19) with ESMTP id 41N36YHD008854 for ; Fri, 23 Feb 2024 07:59:57 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=s2048-2021-q4; bh=KCV1GsxIVZ+O9ooNXDBBSvmGvB+u+6vYvN8LgYXZGIg=; b=FiL4UK+unYmTJ27tsErylDHTb3QJlL1h7AJLo9ZgqnmmqGMp1DZmJX/EqKLeE7GPdqUf /8OEfI2Wuij7IwGt41Z31k+TrajfeAYBIzVVeD7gKjD2rfbTfLtfOsinQL01rfUJu01i nAgAoXAM2FJcgHBRDCV3L4aoUnuxHxtGmxeOeHy5tp2QZEXGJeHSkU2W4eOAwWQnURHn 6fREpphrii1PgDAWOQsK8DxFHVon9QhiqpuAWxkEy6QafviqAstMPfb6O7TXuJFj6px7 +Sjw28La/ALoq6tfcklP5e1pb1lO8lLsDYhBehNF2CMEox9qX0g5DYdtSO5yRYFe7/IS Eg== Received: from mail.thefacebook.com ([163.114.132.120]) by m0089730.ppops.net (PPS) with ESMTPS id 3wek5m3a08-17 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 23 Feb 2024 07:59:57 -0800 Received: from twshared34526.07.ash9.facebook.com (2620:10d:c085:108::4) by mail.thefacebook.com (2620:10d:c085:11d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Fri, 23 Feb 2024 07:59:26 -0800 Received: by devbig007.nao1.facebook.com (Postfix, from userid 544533) id 593692574FA47; Fri, 23 Feb 2024 07:59:13 -0800 (PST) From: Keith Busch To: CC: , , , , Keith Busch , Christoph Hellwig Subject: [PATCHv4 3/4] block: io wait hang check helper Date: Fri, 23 Feb 2024 07:59:09 -0800 Message-ID: <20240223155910.3622666-4-kbusch@meta.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223155910.3622666-1-kbusch@meta.com> References: <20240223155910.3622666-1-kbusch@meta.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: tJfWC8qxaIhPKvt8tOv7b73JdbcG7fqT X-Proofpoint-GUID: tJfWC8qxaIhPKvt8tOv7b73JdbcG7fqT X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-23_02,2024-02-23_01,2023-05-22_02 From: Keith Busch This is the same in two places, and another will be added soon. Create a helper for it. Reviewed-by: Ming Lei Reviewed-by: Christoph Hellwig Signed-off-by: Keith Busch --- block/bio.c | 12 +----------- block/blk-mq.c | 19 +++---------------- block/blk.h | 13 +++++++++++++ 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/block/bio.c b/block/bio.c index 00847ff1415c3..496867b51609f 100644 --- a/block/bio.c +++ b/block/bio.c @@ -16,7 +16,6 @@ #include #include #include -#include #include #include @@ -1371,21 +1370,12 @@ int submit_bio_wait(struct bio *bio) { DECLARE_COMPLETION_ONSTACK_MAP(done, bio->bi_bdev->bd_disk->lockdep_map); - unsigned long hang_check; bio->bi_private = &done; bio->bi_end_io = submit_bio_wait_endio; bio->bi_opf |= REQ_SYNC; submit_bio(bio); - - /* Prevent hang_check timer from firing at us during very long I/O */ - hang_check = sysctl_hung_task_timeout_secs; - if (hang_check) - while (!wait_for_completion_io_timeout(&done, - hang_check * (HZ/2))) - ; - else - wait_for_completion_io(&done); + blk_wait_io(&done); return blk_status_to_errno(bio->bi_status); } diff --git a/block/blk-mq.c b/block/blk-mq.c index 6abb4ce46baa1..45f994c100446 100644 --- a/block/blk-mq.c +++ b/block/blk-mq.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -1409,22 +1408,10 @@ blk_status_t blk_execute_rq(struct request *rq, bool at_head) blk_mq_insert_request(rq, at_head ? BLK_MQ_INSERT_AT_HEAD : 0); blk_mq_run_hw_queue(hctx, false); - if (blk_rq_is_poll(rq)) { + if (blk_rq_is_poll(rq)) blk_rq_poll_completion(rq, &wait.done); - } else { - /* - * Prevent hang_check timer from firing at us during very long - * I/O - */ - unsigned long hang_check = sysctl_hung_task_timeout_secs; - - if (hang_check) - while (!wait_for_completion_io_timeout(&wait.done, - hang_check * (HZ/2))) - ; - else - wait_for_completion_io(&wait.done); - } + else + blk_wait_io(&wait.done); return wait.ret; } diff --git a/block/blk.h b/block/blk.h index 7c30e2ac8ebcd..6c2749d122ab5 100644 --- a/block/blk.h +++ b/block/blk.h @@ -4,6 +4,7 @@ #include #include /* for max_pfn/max_low_pfn */ +#include #include #include #include "blk-crypto-internal.h" @@ -71,6 +72,18 @@ static inline int bio_queue_enter(struct bio *bio) return __bio_queue_enter(q, bio); } +static inline void blk_wait_io(struct completion *done) +{ + /* Prevent hang_check timer from firing at us during very long I/O */ + unsigned long timeout = sysctl_hung_task_timeout_secs * HZ / 2; + + if (timeout) + while (!wait_for_completion_io_timeout(done, timeout)) + ; + else + wait_for_completion_io(done); +} + #define BIO_INLINE_VECS 4 struct bio_vec *bvec_alloc(mempool_t *pool, unsigned short *nr_vecs, gfp_t gfp_mask); From patchwork Fri Feb 23 15:59:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13569350 Received: from mx0a-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA5E881AD3 for ; Fri, 23 Feb 2024 15:59:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=67.231.153.30 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703964; cv=none; b=PyYZVbqjEKdL3oiFZHbIMR4NvAE3TYF05OJqIC3cn8m9YpRGMTqwqq6+SPxpuWUJzYK0m58rCGSceCx+PqiGmxJIMrmDWWifElTBFBQjk1MxkYpihrpmLkALVKzAiBSEf4rlLQggRVe6upVe+Ozzhv0CbBQ6qve2lYrvyOlalp8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708703964; c=relaxed/simple; bh=xLidHQGevw3+hdgp5Aw1xJdduckx5iJ5szsvVyNZdCc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BsZ4bB9JH/YE2wHcQNaRBNe56lcIHBm4iawTma+rXQPxiUC/FZzRQLZqny47nsICxLSe8sgallXBIXXjpt0Ex1Z4sqv4bikPr/wi/i0OBwnfxhOA0Givh+oSlk32fjeKxsGlAZkKZjhrbBqUAixF6VOf1hPYETyldhC6oeHgW78= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com; spf=pass smtp.mailfrom=meta.com; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b=n0m5KK4C; arc=none smtp.client-ip=67.231.153.30 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=meta.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=meta.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=meta.com header.i=@meta.com header.b="n0m5KK4C" Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.17.1.19/8.17.1.19) with ESMTP id 41N36YH0008854 for ; Fri, 23 Feb 2024 07:59:21 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=meta.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=s2048-2021-q4; bh=X7lDYXI0dpywXrFiieUIh3nLJG0yEH5eUraiJMVUVo8=; b=n0m5KK4Cr/5ntgTr9Es/r00sSstkODj2ewAGkvMdx70ctsLuAZ/xVKlz1E3m3Zor/Hl8 jR2E/F1g5t/AB/zzNJcrpPEPwdTQsQU6m87WZiUeI+idGKVUGOEek90QvqqElUUyfhU6 Le7CMpMUY2ZVvNrbuP9zGa2qDwpU9yV73fyptu6XM37h3pI4VnKipNV2a1birtTxpDli K4RVRvD8ZZXE54odIgxFVwXNtrxSxz3696CCi/fK3pQCWc3xmgAwjwyn9LUazjwxiQ13 zhaReK5vzJcTOnX2Z4f5wkSYe6zZ2Xd1wUnniCrBuuJavdGxxe6vLvdI5t9DZHmxi2Ud 0Q== Received: from mail.thefacebook.com ([163.114.132.120]) by m0089730.ppops.net (PPS) with ESMTPS id 3wek5m3a08-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 23 Feb 2024 07:59:21 -0800 Received: from twshared1676.08.ash9.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c085:11d::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.35; Fri, 23 Feb 2024 07:59:19 -0800 Received: by devbig007.nao1.facebook.com (Postfix, from userid 544533) id E54D72574FA4C; Fri, 23 Feb 2024 07:59:13 -0800 (PST) From: Keith Busch To: CC: , , , , Keith Busch , Conrad Meyer Subject: [PATCHv4 4/4] blk-lib: check for kill signal Date: Fri, 23 Feb 2024 07:59:10 -0800 Message-ID: <20240223155910.3622666-5-kbusch@meta.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240223155910.3622666-1-kbusch@meta.com> References: <20240223155910.3622666-1-kbusch@meta.com> Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: qKIKOUFUtHE8N2ixCi6SbLTEQKLKiecL X-Proofpoint-GUID: qKIKOUFUtHE8N2ixCi6SbLTEQKLKiecL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-23_02,2024-02-23_01,2023-05-22_02 From: Keith Busch Some of these block operations can access a significant capacity and take longer than the user expected. A user may change their mind about wanting to run that command and attempt to kill the process and do something else with their device. But since the task is uninterruptable, they have to wait for it to finish, which could be many hours. Check for a fatal signal at each iteration so the user doesn't have to wait for their regretted operation to complete naturally. Reported-by: Conrad Meyer Tested-by: Nilay Shroff Signed-off-by: Keith Busch Reviewed-by: Christoph Hellwig --- block/blk-lib.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index a6954eafb8c8a..dc8e35d0a51d6 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -35,6 +35,26 @@ static sector_t bio_discard_limit(struct block_device *bdev, sector_t sector) return round_down(UINT_MAX, discard_granularity) >> SECTOR_SHIFT; } +static void await_bio_endio(struct bio *bio) +{ + complete(bio->bi_private); + bio_put(bio); +} + +/* + * await_bio_chain - ends @bio and waits for every chained bio to complete + */ +static void await_bio_chain(struct bio *bio) +{ + DECLARE_COMPLETION_ONSTACK_MAP(done, + bio->bi_bdev->bd_disk->lockdep_map); + + bio->bi_private = &done; + bio->bi_end_io = await_bio_endio; + bio_endio(bio); + blk_wait_io(&done); +} + int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, sector_t nr_sects, gfp_t gfp_mask, struct bio **biop) { @@ -77,6 +97,10 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, * is disabled. */ cond_resched(); + if (fatal_signal_pending(current)) { + await_bio_chain(bio); + return -EINTR; + } } *biop = bio; @@ -143,6 +167,10 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev, nr_sects -= len; sector += len; cond_resched(); + if (fatal_signal_pending(current)) { + await_bio_chain(bio); + return -EINTR; + } } *biop = bio; @@ -187,6 +215,10 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev, break; } cond_resched(); + if (fatal_signal_pending(current)) { + await_bio_chain(bio); + return -EINTR; + } } *biop = bio; @@ -277,7 +309,7 @@ int blkdev_issue_zeroout(struct block_device *bdev, sector_t sector, bio_put(bio); } blk_finish_plug(&plug); - if (ret && try_write_zeroes) { + if (ret && ret != -EINTR && try_write_zeroes) { if (!(flags & BLKDEV_ZERO_NOFALLBACK)) { try_write_zeroes = false; goto retry; @@ -329,6 +361,12 @@ int blkdev_issue_secure_erase(struct block_device *bdev, sector_t sector, sector += len; nr_sects -= len; cond_resched(); + if (fatal_signal_pending(current)) { + await_bio_chain(bio); + ret = -EINTR; + bio = NULL; + break; + } } if (bio) { ret = submit_bio_wait(bio);