From patchwork Thu Feb 22 19:19:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13567995 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 E653E548EB for ; Thu, 22 Feb 2024 19:20:55 +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=1708629657; cv=none; b=sdOmDccwHtFvbjnWUQSbM3nAdJ61JlwwKJv/cKgx9cfBbjcqCj8jsg3S76Cn1/HAsqB6Qu64/ll4kCumlmgC034guFV9xdUy4NxSZev7k36p30zrOmow4bRSumuwhBRVeeY3DfLKwwhUNw1JE0hsc1P+h/xNk/VtyQzGTfB/udE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708629657; c=relaxed/simple; bh=Vj+L3/70ajCUy8KeYpw+fGjzkFe8WDybhJ+VaEq7fGo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=k4zqN8NkNVkDeYFNKEht+RstPT17yGauFn9Ez9aSphAd0yOUTiro9rzXahR8O1blbj7KeTjCEBvz8U+rZI9mUYXr4VwbiNZ68aifd/ezpK4P/51HvWEC9GUipQzCjvmcUVNrntkF07q9kYaAvxz7F6zzhX2y65OaYaXwcsBN6jA= 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=EI9UisMd; 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="EI9UisMd" Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41MIcf4x017785 for ; Thu, 22 Feb 2024 11:20: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=4uYN0swH0MhsHnhs0GxmEssjHKom0NEX7OpTrV6hhm0=; b=EI9UisMdU9t4Iy3/wffbMT1HZG60juMXa77sjiSgtntFQib/JqAfS2rZEKTjs9Hw/O+Q zN/fNiZ4QR8k3ud+KZ1xShNNjT7XXmiMzH9MJBpb7FVfam5pXaatSoPC7ZO3c8LeCYrb D3EYm18MUPk7iCeknB0v8LPbcqSxJprjXIXlJ1/4zZGwub2iwyvX6UQpmr4uhIIlenka mz2XYXd+umkffhw0lb3i/kV9kgY6EcYGnTk3Y4ar6kCTIvXE4E6gIyzZHP7QLajjbdWZ SqoUFwCcEpkRzYuquzsMv3DIQyPiPJ1ncXTjKlV+0Csa3QZLVkqfpEXfFqg8Lxsd1+8W jQ== Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3we86y27jw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 22 Feb 2024 11:20:54 -0800 Received: from twshared6594.02.ash8.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; Thu, 22 Feb 2024 11:20:54 -0800 Received: by devbig007.nao1.facebook.com (Postfix, from userid 544533) id BAA5E256D9817; Thu, 22 Feb 2024 11:20:40 -0800 (PST) From: Keith Busch To: CC: , , , , Keith Busch Subject: [PATCHv3 1/4] block: blkdev_issue_secure_erase loop style Date: Thu, 22 Feb 2024 11:19:19 -0800 Message-ID: <20240222191922.2130580-2-kbusch@meta.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222191922.2130580-1-kbusch@meta.com> References: <20240222191922.2130580-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: OQKgYzbpuRnncnYA4j2_d8vBlgeLoU8b X-Proofpoint-GUID: OQKgYzbpuRnncnYA4j2_d8vBlgeLoU8b 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-22_15,2024-02-22_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. Signed-off-by: Keith Busch Reviewed-by: Ming Lei Reviewed-by: Christoph Hellwig --- 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 Thu Feb 22 19:19:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13567991 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 2269C14B824 for ; Thu, 22 Feb 2024 19:20:45 +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=1708629647; cv=none; b=t0+hLxhlelRBDFoJcO1yVhA+UyWIUAEtAhJo/7CvN7BEFpbRK/vs5JzTTnfif2rb1GFhuHFe27QqfyTyiwvxj/OJdz2oGbjh1gbod1r+ArQfF/BIhNk6AJUGo3/rhNOHO0dh0CjM3AB/l0T5lrFLey++y2s4Cdy1xbeh2o5Yyec= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708629647; c=relaxed/simple; bh=zQD6oPiqsC7ES4uENVtVntjfOaQK0Mmoqg5f8SzwZSc=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Ru4PTzGth6u15O9tQPX4YBnymkfm+WxcH6G2hzXwVbXi2SzcAC9xQ5SmHEWKG64dCuOQhBsBgmvGbnbxfC4n5pE2My5Eo7q3bKywnm3Vsv96n79aFjJsuoM1yNZEgj/Ih+tZZfpAugJjkxk1ESBvLOutKNHOCHQIWPw8Bt5YUgs= 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=XFLD5ZAB; 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="XFLD5ZAB" Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41MIvDoO012046 for ; Thu, 22 Feb 2024 11:20:45 -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=YtSiX6VZwe9+8caIFcZzz6t0+Mz/DJznXBZMA2Q+5tE=; b=XFLD5ZABNMEAZodgjd7Wy/rie81dpFTqsFFxKM0hfdvCIpNF//ZhI7Xmy/fFywkYX0Ye 1hdxcbIlV++ijj2Ug6ThULTd0nwkDKkqEdDRnIoG96gCCThXuAdKNsOjkcy3r+jwBfCC KjWt+m5dlyVwGS0ESYLrMXq6HQ6JsIHN0f0fdw20m7pSyN10loj6HmoNZkH0wiHPseyD xJv16hJ4qjsfubzCeeM00DaaCBLdX455+DxQxHiivTJYm92jF5B6g2iP8PgpYM3reuNV kpfmCcsapV4pqIKVIj+eGB3OXICvKVGo867KWHi7eIyrtVNSBaJBVApKEa1WuU5GeoqG fw== Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3wec0cr64e-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 22 Feb 2024 11:20:45 -0800 Received: from twshared53729.38.frc1.facebook.com (2620:10d:c085:208::f) 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; Thu, 22 Feb 2024 11:20:44 -0800 Received: by devbig007.nao1.facebook.com (Postfix, from userid 544533) id C6D7F256D9819; Thu, 22 Feb 2024 11:20:40 -0800 (PST) From: Keith Busch To: CC: , , , , Keith Busch Subject: [PATCHv3 2/4] block: __blkdev_issue_write_zeroes cleanup Date: Thu, 22 Feb 2024 11:19:20 -0800 Message-ID: <20240222191922.2130580-3-kbusch@meta.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222191922.2130580-1-kbusch@meta.com> References: <20240222191922.2130580-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-GUID: lntaIhGNhKEhZ3J2ljgTjPnIBA0chtWi X-Proofpoint-ORIG-GUID: lntaIhGNhKEhZ3J2ljgTjPnIBA0chtWi 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-22_15,2024-02-22_01,2023-05-22_02 From: Keith Busch Use min to calculate the next number of sectors like everyone else. Signed-off-by: Keith Busch Reviewed-by: Ming Lei --- block/blk-lib.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/block/blk-lib.c b/block/blk-lib.c index 91770da2239f2..d4c476cf3784a 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -132,19 +132,16 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev, return -EOPNOTSUPP; while (nr_sects) { + unsigned int len = min_t(sector_t, nr_sects, max_write_zeroes_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 << 9; + nr_sects -= len; + sector += len; cond_resched(); } From patchwork Thu Feb 22 19:19:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13567994 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 098EE548E7 for ; Thu, 22 Feb 2024 19:20:53 +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=1708629655; cv=none; b=BasBQcYuIOx0ohmezFuxveamnKMYplie+7G07mygUshhLTwPxXjG8OLPz8m5pa9QTsQcNDWbeLeJjrK3RNo7tCvFnc6JaZdAK4POelY+WJeSQ059smLHi+lhC8B8U1YQhR5q/8d/SHRhH5kEaEFcmtEvoWCLROM15FEcG8lR0Ts= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708629655; c=relaxed/simple; bh=4KrOyPsGb4c/FVjGG2d8PA8LLv9VDp3C+DZ7talCByU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PNyrw6aWI4MSL/As97Of3QNQ8JJmyeCDGy/LbZDF4IMxVE5SCyKhCLaAdfmaEi4lZ/eA2g5jCqr4rQLkrQhZq1hVWlry1iC6A1rIGNSG0F9ujJNxJM+wVjg+y5Rilg9Sb5NDTuV8WLhPHMRiM0eQ8pebWmM23hnxPEyNlU7Nl5M= 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=HNdn7z/S; 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="HNdn7z/S" Received: from pps.filterd (m0109334.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 41MIuwOF024346 for ; Thu, 22 Feb 2024 11:20:53 -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=dTantrnFDmtNVGA0OZDoz7KF6WPj9uJiz4rLaxasehc=; b=HNdn7z/S2czHOtzo6PrRyfvnNqgUGdl8xXwO6wW5HCrXTp/gpabUpOy6A1+4Ram2Ja9V WVwdL9Py+n5IRVdAArOV9t8fQ4YwvoYMF/pxxUnuOSkNNQoIkFmwEiv4KLPhD5fJ1VbY YLglGA/WTnpBCRsd1G54GYCWC+IKpafxMjKltmAAf1l/U4FB1J2h09O/k4sJdmdUkDVI /ybDawVQqQw1MfOpE+v75uiNuD4xpScJm2srj3RkpXk9uABx2QkTBtcLvFZpIB7yn3Rt Kdrq+vKpoI+1zSzImTEcYQUeSnFcCx9HM/6DKhfxCNSsr4yZhdBmAmQNl+TJaBpiHwnl fA== Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3wec0406ec-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 22 Feb 2024 11:20:53 -0800 Received: from twshared5578.09.ash9.facebook.com (2620:10d:c085:208::11) 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; Thu, 22 Feb 2024 11:20:49 -0800 Received: by devbig007.nao1.facebook.com (Postfix, from userid 544533) id D30DD256D981B; Thu, 22 Feb 2024 11:20:40 -0800 (PST) From: Keith Busch To: CC: , , , , Keith Busch Subject: [PATCHv3 3/4] block: introduce io wait hang check helper Date: Thu, 22 Feb 2024 11:19:21 -0800 Message-ID: <20240222191922.2130580-4-kbusch@meta.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222191922.2130580-1-kbusch@meta.com> References: <20240222191922.2130580-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-GUID: yqJzBNRG0WYWZl9uVsedjp8qLi0xy8jj X-Proofpoint-ORIG-GUID: yqJzBNRG0WYWZl9uVsedjp8qLi0xy8jj 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-22_15,2024-02-22_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. Signed-off-by: Keith Busch Reviewed-by: Ming Lei Reviewed-by: Christoph Hellwig --- 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 Thu Feb 22 19:19:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 13567992 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 843CA14B825 for ; Thu, 22 Feb 2024 19:20:49 +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=1708629651; cv=none; b=tAL4WqRLXjf7iCKtiOzElNxblUfAn87SJXaCuwGexXy46wlUHrIxC9Q9n9Pqnt90zExxElbFTP6CUo7ZSt+cFuCVPS1LixsztqE5Ljg1uvhAQVVY8w1Lw5FLTuM032vkeRUae+4Kqm1pXf/Lmzc19clskkllNRqXMSIvQLJ+hCs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708629651; c=relaxed/simple; bh=OBEz9ZCdXnqiKWBEbbFB06mYggcVCCD07bdDbxEOMmY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FwWOXSkjtgoxnbI9pgLO7AptSPSfkIFJJmtzOztw3HXGR+XST0wzQY5wBPqJFwodzvJwVo/Y0/nwql4T7+5GmO7awxivf2ss6tI6lTmc1FUiMNX8MoDEqd23AH112YuGgtGa1OQid6P/aBEPvahc62YeCu/Nw+oDJN/36GjIUfU= 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=NBLcXbK5; 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="NBLcXbK5" 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 41MItjC8005907 for ; Thu, 22 Feb 2024 11:20:48 -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=c86xmeQIxFBsbABJ3jGy9pjfHBbSNBBoE4yc3CKkrIc=; b=NBLcXbK5SRiq+mFtTmnD+B6q3GYW7B2iSawuIjPB0yff5cJuQrCZAsTOpB/MqcCnaXKA PsQNhqyEyBJe+uQ4GAFngeNk4UNB77HioMNCCzdr3eVvTvpwRKaZIEpgovu9e942wr+y T7Es9zbDqd/zm2Sv0LpAHbieVn4UkXXbrXNkD+HKWWgEvCr0TKdrLICrBcFdNL7H/9AO Mz6PYXOxkhhBxPJfgfB4qMDvZgr7lbERSJpDEwvBkVUCL72u6khVMtn42FrOfj1/qUmi 85peZ+uIv464qCTXF/uumFQq9AoenepMyOeh5vc/U54C0BXU8taTn035J0GA0yGsYeT0 Gw== Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3webyk86sm-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 22 Feb 2024 11:20:47 -0800 Received: from twshared53729.38.frc1.facebook.com (2620:10d:c085:208::f) 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; Thu, 22 Feb 2024 11:20:47 -0800 Received: by devbig007.nao1.facebook.com (Postfix, from userid 544533) id 1BF4E256D981E; Thu, 22 Feb 2024 11:20:41 -0800 (PST) From: Keith Busch To: CC: , , , , Keith Busch , Conrad Meyer Subject: [PATCHv3 4/4] blk-lib: check for kill signal Date: Thu, 22 Feb 2024 11:19:22 -0800 Message-ID: <20240222191922.2130580-5-kbusch@meta.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222191922.2130580-1-kbusch@meta.com> References: <20240222191922.2130580-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: IN06ZaXl27ybLfXoXo6DupIcMEXCp2kK X-Proofpoint-GUID: IN06ZaXl27ybLfXoXo6DupIcMEXCp2kK 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-22_15,2024-02-22_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 Signed-off-by: Keith Busch Reviewed-by: Ming Lei --- block/blk-lib.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/block/blk-lib.c b/block/blk-lib.c index d4c476cf3784a..9e594f641ce72 100644 --- a/block/blk-lib.c +++ b/block/blk-lib.c @@ -35,6 +35,23 @@ static sector_t bio_discard_limit(struct block_device *bdev, sector_t sector) return round_down(UINT_MAX, discard_granularity) >> SECTOR_SHIFT; } +static void abort_bio_endio(struct bio *bio) +{ + complete(bio->bi_private); + bio_put(bio); +} + +static void abort_bio(struct bio *bio) +{ + DECLARE_COMPLETION_ONSTACK_MAP(done, + bio->bi_bdev->bd_disk->lockdep_map); + + bio->bi_private = &done; + bio->bi_end_io = abort_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 +94,10 @@ int __blkdev_issue_discard(struct block_device *bdev, sector_t sector, * is disabled. */ cond_resched(); + if (fatal_signal_pending(current)) { + abort_bio(bio); + return -EINTR; + } } *biop = bio; @@ -143,6 +164,10 @@ static int __blkdev_issue_write_zeroes(struct block_device *bdev, nr_sects -= len; sector += len; cond_resched(); + if (fatal_signal_pending(current)) { + abort_bio(bio); + return -EINTR; + } } *biop = bio; @@ -187,6 +212,10 @@ static int __blkdev_issue_zero_pages(struct block_device *bdev, break; } cond_resched(); + if (fatal_signal_pending(current)) { + abort_bio(bio); + return -EINTR; + } } *biop = bio; @@ -329,6 +358,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)) { + abort_bio(bio); + ret = -EINTR; + bio = NULL; + break; + } } if (bio) { ret = submit_bio_wait(bio);