From patchwork Tue Jul 26 17:38:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 12929592 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 78989C3F6B0 for ; Tue, 26 Jul 2022 17:38:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239437AbiGZRi2 (ORCPT ); Tue, 26 Jul 2022 13:38:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239438AbiGZRi1 (ORCPT ); Tue, 26 Jul 2022 13:38:27 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73F742E9F2 for ; Tue, 26 Jul 2022 10:38:24 -0700 (PDT) Received: from pps.filterd (m0109332.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 26QFUYDo009215 for ; Tue, 26 Jul 2022 10:38:23 -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=SomX9IGDRyQXLRBTlADstEaF266+E6DF73QSujOv+Ew=; b=j+lYmcL1s32BeahSXdU4ag48ouVrO0tXDF3jFQePs0sjjcTHSneXvo2OdVjBuuCNrZZ8 lRTIGAanKpY0HTCW3CHrfb53g1/16Po0igyVy/w7bVRlM0hrWytv4SVjBYyP5MdvBhfh hEkI+WflKnJcFTMW4AwVuoSCc91zzHgErUc= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3hj592n3c9-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 26 Jul 2022 10:38:23 -0700 Received: from twshared6324.05.ash7.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:11d::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.28; Tue, 26 Jul 2022 10:38:20 -0700 Received: by devbig007.nao1.facebook.com (Postfix, from userid 544533) id 52114698E4AA; Tue, 26 Jul 2022 10:38:15 -0700 (PDT) From: Keith Busch To: , , , CC: , , Alexander Viro , Keith Busch Subject: [PATCH 1/5] blk-mq: add ops to dma map bvec Date: Tue, 26 Jul 2022 10:38:10 -0700 Message-ID: <20220726173814.2264573-2-kbusch@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220726173814.2264573-1-kbusch@fb.com> References: <20220726173814.2264573-1-kbusch@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-ORIG-GUID: O3E-RXKXpzY6829TGCg6VzOOCZCcoHPP X-Proofpoint-GUID: O3E-RXKXpzY6829TGCg6VzOOCZCcoHPP 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-07-26_05,2022-07-26_01,2022-06-22_01 Precedence: bulk List-ID: X-Mailing-List: io-uring@vger.kernel.org From: Keith Busch The same buffer may be used for many subsequent IO's. Instead of setting up the mapping per-IO, provide an interface that can allow a buffer to be premapped just once and referenced again later. Signed-off-by: Keith Busch --- block/bdev.c | 20 ++++++++++++++++++++ include/linux/blk-mq.h | 13 +++++++++++++ include/linux/blkdev.h | 16 ++++++++++++++++ 3 files changed, 49 insertions(+) diff --git a/block/bdev.c b/block/bdev.c index ce05175e71ce..345176e12bb1 100644 --- a/block/bdev.c +++ b/block/bdev.c @@ -1069,3 +1069,23 @@ void sync_bdevs(bool wait) spin_unlock(&blockdev_superblock->s_inode_list_lock); iput(old_inode); } + +#ifdef CONFIG_HAS_DMA +void *block_dma_map(struct block_device *bdev, struct bio_vec *bvec, + int nr_vecs) +{ + struct request_queue *q = bdev_get_queue(bdev); + + if (q->mq_ops && q->mq_ops->dma_map) + return q->mq_ops->dma_map(q, bvec, nr_vecs); + return ERR_PTR(-EINVAL); +} + +void block_dma_unmap(struct block_device *bdev, void *dma_tag) +{ + struct request_queue *q = bdev_get_queue(bdev); + + if (q->mq_ops && q->mq_ops->dma_unmap) + return q->mq_ops->dma_unmap(q, dma_tag); +} +#endif diff --git a/include/linux/blk-mq.h b/include/linux/blk-mq.h index effee1dc715a..e10aabb36c2c 100644 --- a/include/linux/blk-mq.h +++ b/include/linux/blk-mq.h @@ -639,6 +639,19 @@ struct blk_mq_ops { */ void (*show_rq)(struct seq_file *m, struct request *rq); #endif + +#ifdef CONFIG_HAS_DMA + /** + * @dma_map: Create a dma mapping. On success, returns an opaque cookie + * that the can be referenced by the driver in future requests. + */ + void *(*dma_map)(struct request_queue *q, struct bio_vec *bvec, int nr_vecs); + + /** + * @dma_unmap: Tear down a previously created dma mapping. + */ + void (*dma_unmap)(struct request_queue *q, void *dma_tag); +#endif }; enum { diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index d04bdf549efa..47f7f6f430d9 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1526,4 +1526,20 @@ struct io_comp_batch { #define DEFINE_IO_COMP_BATCH(name) struct io_comp_batch name = { } +#ifdef CONFIG_HAS_DMA +void *block_dma_map(struct block_device *bdev, struct bio_vec *bvec, + int nr_vecs); +void block_dma_unmap(struct block_device *bdev, void *dma_tag); +#else +static inline void *block_dma_map(struct block_device *bdev, + struct bio_vec *bvec, int nr_vecs) +{ + return ERR_PTR(-ENOTSUPP); +} + +static inline void block_dma_unmap(struct block_device *bdev, void *dma_tag) +{ +} +#endif + #endif /* _LINUX_BLKDEV_H */