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 5A3B6C433EF for ; Thu, 30 Jun 2022 20:42:53 +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:Content-Type: Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date :Subject:CC:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8cc23F6j5+adqkGR+byTTk90kWs3qVOG0MzAZ27W60Y=; b=ci2OA+2z1BMcOwuNz4ztLOuwWq FacW4pvDkgZw7IZS7HWKLhBPXYS+DeUp7cRC0H12JTUqFLi2/n9kc7J8K5LlRO6BSNDECr0bCO2Z+ aih85zP/+1BWweySBw4xynTl1cCMzsfoe3QsgtnUOHSrfUIwqsaPr3OerXk/L+lG6IJsZwabPgZja IAX7QQdBRjButfyDHon42v794n0D02xr+GeLu6xSLWscgC42IU9JQOQup8nIPl9s5migfOpBbZPuC NZkGqtlAFdsJrqH9lVg9AovnbjbR/HLflnJGsuzdXp03TKHJnFoFNbp6RjW8+gjXBFS4OgKNECBr8 a6PWVp4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o70zv-001SzL-J9; Thu, 30 Jun 2022 20:42:47 +0000 Received: from mx0b-00082601.pphosted.com ([67.231.153.30] helo=mx0a-00082601.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o70zs-001SwN-62 for linux-nvme@lists.infradead.org; Thu, 30 Jun 2022 20:42:46 +0000 Received: from pps.filterd (m0089730.ppops.net [127.0.0.1]) by m0089730.ppops.net (8.17.1.5/8.17.1.5) with ESMTP id 25UJCLpr004575 for ; Thu, 30 Jun 2022 13:42:40 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=8cc23F6j5+adqkGR+byTTk90kWs3qVOG0MzAZ27W60Y=; b=nZ/r4lBidqjvrhNVFQl1SXA5uaXeC2qaTVM/NqD6HQ5Zc5C3T8nHE8LcV9SdHPPv6qJa j8YQbacbvqq7ezOALyZ+8KwoQcyNstDtX3Bigu74w6PH0FPNKDULJHYyEnVXclxadYMP w3+UI2zuCqUcakEpyOrXDWMYeDTZ3BOyGF0= Received: from mail.thefacebook.com ([163.114.132.120]) by m0089730.ppops.net (PPS) with ESMTPS id 3h195a4pv9-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 30 Jun 2022 13:42:40 -0700 Received: from twshared10560.18.frc3.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:11d::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Thu, 30 Jun 2022 13:42:38 -0700 Received: by devbig007.nao1.facebook.com (Postfix, from userid 544533) id 1E5DD5932DB7; Thu, 30 Jun 2022 13:42:30 -0700 (PDT) From: Keith Busch To: , , CC: , Kernel Team , , , , Keith Busch Subject: [PATCH 01/12] block: move direct io alignment check to common Date: Thu, 30 Jun 2022 13:42:01 -0700 Message-ID: <20220630204212.1265638-2-kbusch@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220630204212.1265638-1-kbusch@fb.com> References: <20220630204212.1265638-1-kbusch@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-GUID: XI2FHlSaACzTgyMMOsAHTZ3fTjjHcQXY X-Proofpoint-ORIG-GUID: XI2FHlSaACzTgyMMOsAHTZ3fTjjHcQXY X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.883,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-06-30_14,2022-06-28_01,2022-06-22_01 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220630_134244_404941_587BDF17 X-CRM114-Status: GOOD ( 17.69 ) 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 From: Keith Busch All direct io has the same setup and alignment check, so just do it once in common code. Signed-off-by: Keith Busch --- block/fops.c | 44 ++++++++++++++---------------------------- include/linux/blkdev.h | 7 +++++++ 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/block/fops.c b/block/fops.c index 86d3cab9bf93..f37af5924cef 100644 --- a/block/fops.c +++ b/block/fops.c @@ -42,28 +42,17 @@ static unsigned int dio_bio_write_op(struct kiocb *io= cb) return op; } =20 -static bool blkdev_dio_unaligned(struct block_device *bdev, loff_t pos, - struct iov_iter *iter) -{ - return pos & (bdev_logical_block_size(bdev) - 1) || - !bdev_iter_is_aligned(bdev, iter); -} - #define DIO_INLINE_BIO_VECS 4 =20 static ssize_t __blkdev_direct_IO_simple(struct kiocb *iocb, - struct iov_iter *iter, unsigned int nr_pages) + struct iov_iter *iter, unsigned int nr_pages, + struct block_device *bdev, loff_t pos) { - struct block_device *bdev =3D iocb->ki_filp->private_data; struct bio_vec inline_vecs[DIO_INLINE_BIO_VECS], *vecs; - loff_t pos =3D iocb->ki_pos; bool should_dirty =3D false; struct bio bio; ssize_t ret; =20 - if (blkdev_dio_unaligned(bdev, pos, iter)) - return -EINVAL; - if (nr_pages <=3D DIO_INLINE_BIO_VECS) vecs =3D inline_vecs; else { @@ -168,20 +157,15 @@ static void blkdev_bio_end_io(struct bio *bio) } =20 static ssize_t __blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *i= ter, - unsigned int nr_pages) + unsigned int nr_pages, struct block_device *bdev, loff_t pos) { - struct block_device *bdev =3D iocb->ki_filp->private_data; struct blk_plug plug; struct blkdev_dio *dio; struct bio *bio; bool is_read =3D (iov_iter_rw(iter) =3D=3D READ), is_sync; unsigned int opf =3D is_read ? REQ_OP_READ : dio_bio_write_op(iocb); - loff_t pos =3D iocb->ki_pos; int ret =3D 0; =20 - if (blkdev_dio_unaligned(bdev, pos, iter)) - return -EINVAL; - if (iocb->ki_flags & IOCB_ALLOC_CACHE) opf |=3D REQ_ALLOC_CACHE; bio =3D bio_alloc_bioset(bdev, nr_pages, opf, GFP_KERNEL, @@ -292,20 +276,15 @@ static void blkdev_bio_end_io_async(struct bio *bio= ) } =20 static ssize_t __blkdev_direct_IO_async(struct kiocb *iocb, - struct iov_iter *iter, - unsigned int nr_pages) + struct iov_iter *iter, unsigned int nr_pages, + struct block_device *bdev, loff_t pos) { - struct block_device *bdev =3D iocb->ki_filp->private_data; bool is_read =3D iov_iter_rw(iter) =3D=3D READ; unsigned int opf =3D is_read ? REQ_OP_READ : dio_bio_write_op(iocb); struct blkdev_dio *dio; struct bio *bio; - loff_t pos =3D iocb->ki_pos; int ret =3D 0; =20 - if (blkdev_dio_unaligned(bdev, pos, iter)) - return -EINVAL; - if (iocb->ki_flags & IOCB_ALLOC_CACHE) opf |=3D REQ_ALLOC_CACHE; bio =3D bio_alloc_bioset(bdev, nr_pages, opf, GFP_KERNEL, @@ -357,18 +336,25 @@ static ssize_t __blkdev_direct_IO_async(struct kioc= b *iocb, =20 static ssize_t blkdev_direct_IO(struct kiocb *iocb, struct iov_iter *ite= r) { + struct block_device *bdev =3D iocb->ki_filp->private_data; + loff_t pos =3D iocb->ki_pos; unsigned int nr_pages; =20 if (!iov_iter_count(iter)) return 0; + if (blkdev_dio_unaligned(bdev, pos, iter)) + return -EINVAL; =20 nr_pages =3D bio_iov_vecs_to_alloc(iter, BIO_MAX_VECS + 1); if (likely(nr_pages <=3D BIO_MAX_VECS)) { if (is_sync_kiocb(iocb)) - return __blkdev_direct_IO_simple(iocb, iter, nr_pages); - return __blkdev_direct_IO_async(iocb, iter, nr_pages); + return __blkdev_direct_IO_simple(iocb, iter, nr_pages, + bdev, pos); + return __blkdev_direct_IO_async(iocb, iter, nr_pages, bdev, + pos); } - return __blkdev_direct_IO(iocb, iter, bio_max_segs(nr_pages)); + return __blkdev_direct_IO(iocb, iter, bio_max_segs(nr_pages), bdev, + pos); } =20 static int blkdev_writepage(struct page *page, struct writeback_control = *wbc) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 22b12531aeb7..9d676adfaaa1 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1352,6 +1352,13 @@ static inline bool bdev_iter_is_aligned(struct blo= ck_device *bdev, bdev_logical_block_size(bdev) - 1); } =20 +static inline bool blkdev_dio_unaligned(struct block_device *bdev, loff_= t p, + struct iov_iter *iter) +{ + return p & (bdev_logical_block_size(bdev) - 1) || + !bdev_iter_is_aligned(bdev, iter); +} + static inline int blk_rq_aligned(struct request_queue *q, unsigned long = addr, unsigned int len) { --=20 2.30.2