From patchwork Tue Aug 2 19:36:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Busch X-Patchwork-Id: 12935003 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 CE944C25B08 for ; Tue, 2 Aug 2022 19:37:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233294AbiHBThD (ORCPT ); Tue, 2 Aug 2022 15:37:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233048AbiHBTgx (ORCPT ); Tue, 2 Aug 2022 15:36:53 -0400 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8429D52FF0 for ; Tue, 2 Aug 2022 12:36:50 -0700 (PDT) Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 272I2YN0027592 for ; Tue, 2 Aug 2022 12:36:49 -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=45JgfRe+CWjDGcU8AbT5bsVYYCjWdG2sJd3W42Hx644=; b=VRWp8lVZKF+xmCybnduOKK3I9fcMqM+QdV/5dx/xs2nyNiXNWhNpiLRQYuPPBob4+oy7 S5DM6erD8pyYVDiOrkeG3wR7x9h2iPVdwcYWKxgFoWAlQ5fxTeL2lSs136ApQuheOgdv hnXQmTL2EU2V/ZEBm9e/kSwUvPT4DVkrOYQ= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com (PPS) with ESMTPS id 3hpy36mmd0-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 02 Aug 2022 12:36:49 -0700 Received: from twshared7556.02.ash8.facebook.com (2620:10d:c085:208::f) 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; Tue, 2 Aug 2022 12:36:47 -0700 Received: by devbig007.nao1.facebook.com (Postfix, from userid 544533) id D80E86E59EFB; Tue, 2 Aug 2022 12:36:37 -0700 (PDT) From: Keith Busch To: , , , CC: , , Alexander Viro , Kernel Team , Keith Busch Subject: [PATCHv2 2/7] file: add ops to dma map bvec Date: Tue, 2 Aug 2022 12:36:28 -0700 Message-ID: <20220802193633.289796-3-kbusch@fb.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220802193633.289796-1-kbusch@fb.com> References: <20220802193633.289796-1-kbusch@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-GUID: qYEAQeNvbyj7urhnSn_QBk-ZauUWYzI6 X-Proofpoint-ORIG-GUID: qYEAQeNvbyj7urhnSn_QBk-ZauUWYzI6 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-08-02_14,2022-08-02_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, and implement for the block device file. Signed-off-by: Keith Busch --- block/fops.c | 20 ++++++++++++++++++++ fs/file.c | 15 +++++++++++++++ include/linux/fs.h | 20 ++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/block/fops.c b/block/fops.c index 29066ac5a2fa..db2d1e848f4b 100644 --- a/block/fops.c +++ b/block/fops.c @@ -670,6 +670,22 @@ static long blkdev_fallocate(struct file *file, int mode, loff_t start, return error; } +#ifdef CONFIG_HAS_DMA +void *blkdev_dma_map(struct file *filp, struct bio_vec *bvec, int nr_vecs) +{ + struct block_device *bdev = filp->private_data; + + return block_dma_map(bdev, bvec, nr_vecs); +} + +void blkdev_dma_unmap(struct file *filp, void *dma_tag) +{ + struct block_device *bdev = filp->private_data; + + return block_dma_unmap(bdev, dma_tag); +} +#endif + const struct file_operations def_blk_fops = { .open = blkdev_open, .release = blkdev_close, @@ -686,6 +702,10 @@ const struct file_operations def_blk_fops = { .splice_read = generic_file_splice_read, .splice_write = iter_file_splice_write, .fallocate = blkdev_fallocate, +#ifdef CONFIG_HAS_DMA + .dma_map = blkdev_dma_map, + .dma_unmap = blkdev_dma_unmap, +#endif }; static __init int blkdev_init(void) diff --git a/fs/file.c b/fs/file.c index 3bcc1ecc314a..767bf9d3205e 100644 --- a/fs/file.c +++ b/fs/file.c @@ -1307,3 +1307,18 @@ int iterate_fd(struct files_struct *files, unsigned n, return res; } EXPORT_SYMBOL(iterate_fd); + +#ifdef CONFIG_HAS_DMA +void *file_dma_map(struct file *file, struct bio_vec *bvec, int nr_vecs) +{ + if (file->f_op->dma_map) + return file->f_op->dma_map(file, bvec, nr_vecs); + return ERR_PTR(-EINVAL); +} + +void file_dma_unmap(struct file *file, void *dma_tag) +{ + if (file->f_op->dma_unmap) + return file->f_op->dma_unmap(file, dma_tag); +} +#endif diff --git a/include/linux/fs.h b/include/linux/fs.h index c0d99b5a166b..befd8ea5821a 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1964,6 +1964,10 @@ struct dir_context { struct iov_iter; struct io_uring_cmd; +#ifdef CONFIG_HAS_DMA +struct bio_vec; +#endif + struct file_operations { struct module *owner; loff_t (*llseek) (struct file *, loff_t, int); @@ -2006,6 +2010,10 @@ struct file_operations { loff_t len, unsigned int remap_flags); int (*fadvise)(struct file *, loff_t, loff_t, int); int (*uring_cmd)(struct io_uring_cmd *ioucmd, unsigned int issue_flags); +#ifdef CONFIG_HAS_DMA + void *(*dma_map)(struct file *, struct bio_vec *, int); + void (*dma_unmap)(struct file *, void *); +#endif } __randomize_layout; struct inode_operations { @@ -3467,4 +3475,16 @@ extern int vfs_fadvise(struct file *file, loff_t offset, loff_t len, extern int generic_fadvise(struct file *file, loff_t offset, loff_t len, int advice); +#ifdef CONFIG_HAS_DMA +void *file_dma_map(struct file *file, struct bio_vec *bvec, int nr_vecs); +void file_dma_unmap(struct file *file, void *dma_tag); +#else +static inline void *file_dma_map(struct file *file, struct bio_vec *bvec, + int nr_vecs) +{ + return ERR_PTR(-ENOTSUPP); +} +static inline void file_dma_unmap(struct file *file, void *dma_tag) {} +#endif + #endif /* _LINUX_FS_H */