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 E5CC2C00140 for ; Tue, 2 Aug 2022 19:37:26 +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=45JgfRe+CWjDGcU8AbT5bsVYYCjWdG2sJd3W42Hx644=; b=tbDQrSzyezXdoUca1WWgK27ymk oqt6vt2OGa0E9aLvT1z5qPtm1ydOtTU8GTnTpe8I89qz/h5Z0sRfWj7E25C/vlviPoYFGS1YKxIZP nnGeJat/004xSfb+7jEWMYF0LvPYC4yVk7jA/SW6ixOtM+uIL3a/twqXwlSAmo296ClqzjkALwdYJ d2LfWbRFe7YSY65DdVayYysNBMg6V9fPv3LsT8smtw3/yARvTlcrQ7JXh77S9cMQKTbHX+EIyX7RC ho0VLaud4Rv7jIJdnYICd3Tqc32R++bUavNDbiT0J6TQncL/UvFxtFL4ZhCkLfgHgESmdPGWkQfVn u3u4YTLg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oIxhk-00Gx2u-0j; Tue, 02 Aug 2022 19:37:24 +0000 Received: from mx0b-00082601.pphosted.com ([67.231.153.30]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oIxhH-00Gwgq-ST for linux-nvme@lists.infradead.org; Tue, 02 Aug 2022 19:36:59 +0000 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 272I2V5b024385 for ; Tue, 2 Aug 2022 12:36:50 -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 3hn2cxwgyy-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Tue, 02 Aug 2022 12:36:50 -0700 Received: from snc-exhub201.TheFacebook.com (2620:10d:c085:21d::7) by snc-exhub203.TheFacebook.com (2620:10d:c085:21d::6) 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:48 -0700 Received: from twshared7556.02.ash8.facebook.com (2620:10d:c085:208::11) by mail.thefacebook.com (2620:10d:c085:21d::7) 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 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-ORIG-GUID: dg_8Urr-77Tow7KDW8YiSp0s6uBORPhu X-Proofpoint-GUID: dg_8Urr-77Tow7KDW8YiSp0s6uBORPhu 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220802_123656_089886_1A1A69F2 X-CRM114-Status: GOOD ( 19.47 ) 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 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; } =20 +#ifdef CONFIG_HAS_DMA +void *blkdev_dma_map(struct file *filp, struct bio_vec *bvec, int nr_vec= s) +{ + struct block_device *bdev =3D 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 =3D filp->private_data; + + return block_dma_unmap(bdev, dma_tag); +} +#endif + const struct file_operations def_blk_fops =3D { .open =3D blkdev_open, .release =3D blkdev_close, @@ -686,6 +702,10 @@ const struct file_operations def_blk_fops =3D { .splice_read =3D generic_file_splice_read, .splice_write =3D iter_file_splice_write, .fallocate =3D blkdev_fallocate, +#ifdef CONFIG_HAS_DMA + .dma_map =3D blkdev_dma_map, + .dma_unmap =3D blkdev_dma_unmap, +#endif }; =20 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, unsigne= d 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; =20 +#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; =20 struct inode_operations { @@ -3467,4 +3475,16 @@ extern int vfs_fadvise(struct file *file, loff_t o= ffset, loff_t len, extern int generic_fadvise(struct file *file, loff_t offset, loff_t len, int advice); =20 +#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 */ --=20 2.30.2