From patchwork Tue Sep 15 14:55:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 260829 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 85CC7C43461 for ; Tue, 15 Sep 2020 23:05:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55988206DC for ; Tue, 15 Sep 2020 23:05:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727379AbgIOXE5 convert rfc822-to-8bit (ORCPT ); Tue, 15 Sep 2020 19:04:57 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.86.151]:27881 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727277AbgIOOzX (ORCPT ); Tue, 15 Sep 2020 10:55:23 -0400 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-73-k-A8mJujN9e8Iji4iGTvBQ-1; Tue, 15 Sep 2020 15:55:09 +0100 X-MC-Unique: k-A8mJujN9e8Iji4iGTvBQ-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 15 Sep 2020 15:55:09 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Tue, 15 Sep 2020 15:55:09 +0100 From: David Laight To: "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "io-uring@vger.kernel.org" , Jens Axboe , "David S. Miller" , Al Viro , linux-fsdevel Subject: [PATCH 1/9 next] mm:process_vm_access Call import_iovec() instead of rw_copy_check_uvector() Thread-Topic: [PATCH 1/9 next] mm:process_vm_access Call import_iovec() instead of rw_copy_check_uvector() Thread-Index: AdaLbkkTBW5in2pQRDCVHbW9ZQK6vQ== Date: Tue, 15 Sep 2020 14:55:08 +0000 Message-ID: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: aculab.com Content-Language: en-US Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This is the only direct call of rw_copy_check_uvector(). Removing it lets rw_copy_check_uvector() be inlined into import_iovec() and the horrid calling conventions fixed. Signed-off-by: David Laight --- mm/process_vm_access.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c index 29c052099aff..1cc3d6f66b31 100644 --- a/mm/process_vm_access.c +++ b/mm/process_vm_access.c @@ -264,7 +264,7 @@ static ssize_t process_vm_rw(pid_t pid, struct iovec iovstack_r[UIO_FASTIOV]; struct iovec *iov_l = iovstack_l; struct iovec *iov_r = iovstack_r; - struct iov_iter iter; + struct iov_iter iter_l, iter_r; ssize_t rc; int dir = vm_write ? WRITE : READ; @@ -272,23 +272,24 @@ static ssize_t process_vm_rw(pid_t pid, return -EINVAL; /* Check iovecs */ - rc = import_iovec(dir, lvec, liovcnt, UIO_FASTIOV, &iov_l, &iter); + rc = import_iovec(dir, lvec, liovcnt, UIO_FASTIOV, &iov_l, &iter_l); if (rc < 0) return rc; - if (!iov_iter_count(&iter)) + if (!iov_iter_count(&iter_l)) goto free_iovecs; - rc = rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt, UIO_FASTIOV, - iovstack_r, &iov_r); + rc = import_iovec(CHECK_IOVEC_ONLY, rvec, riovcnt, UIO_FASTIOV, &iov_r, &iter_r); if (rc <= 0) goto free_iovecs; - rc = process_vm_rw_core(pid, &iter, iov_r, riovcnt, flags, vm_write); + rc = process_vm_rw_core(pid, &iter_l, iter_r.iov, iter_r.nr_segs, + flags, vm_write); free_iovecs: if (iov_r != iovstack_r) kfree(iov_r); - kfree(iov_l); + if (iov_l != iovstack_l) + kfree(iov_l); return rc; } @@ -322,30 +323,30 @@ compat_process_vm_rw(compat_pid_t pid, struct iovec iovstack_r[UIO_FASTIOV]; struct iovec *iov_l = iovstack_l; struct iovec *iov_r = iovstack_r; - struct iov_iter iter; + struct iov_iter iter_l, iter_r; ssize_t rc = -EFAULT; int dir = vm_write ? WRITE : READ; if (flags != 0) return -EINVAL; - rc = compat_import_iovec(dir, lvec, liovcnt, UIO_FASTIOV, &iov_l, &iter); + rc = compat_import_iovec(dir, lvec, liovcnt, UIO_FASTIOV, &iov_l, &iter_l); if (rc < 0) return rc; - if (!iov_iter_count(&iter)) + if (!iov_iter_count(&iter_l)) goto free_iovecs; - rc = compat_rw_copy_check_uvector(CHECK_IOVEC_ONLY, rvec, riovcnt, - UIO_FASTIOV, iovstack_r, - &iov_r); + rc = compat_import_iovec(0, rvec, riovcnt, UIO_FASTIOV, &iov_r, &iter_r); if (rc <= 0) goto free_iovecs; - rc = process_vm_rw_core(pid, &iter, iov_r, riovcnt, flags, vm_write); + rc = process_vm_rw_core(pid, &iter_l, iter_r.iov, iter_r.nr_segs, + flags, vm_write); free_iovecs: if (iov_r != iovstack_r) kfree(iov_r); - kfree(iov_l); + if (iov_l != iovstack_l) + kfree(iov_l); return rc; } From patchwork Tue Sep 15 14:55:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 260830 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC871C43461 for ; Tue, 15 Sep 2020 23:04:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B85F821655 for ; Tue, 15 Sep 2020 23:04:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727350AbgIOXEF convert rfc822-to-8bit (ORCPT ); Tue, 15 Sep 2020 19:04:05 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([207.82.80.151]:22882 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727347AbgIOOzZ (ORCPT ); Tue, 15 Sep 2020 10:55:25 -0400 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-228-UwHUunUMNimNqcwZQRPI5A-1; Tue, 15 Sep 2020 15:55:21 +0100 X-MC-Unique: UwHUunUMNimNqcwZQRPI5A-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 15 Sep 2020 15:55:20 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Tue, 15 Sep 2020 15:55:20 +0100 From: David Laight To: "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "io-uring@vger.kernel.org" , Jens Axboe , "David S. Miller" , Al Viro , linux-fsdevel Subject: [PATCH 4/9 next] fs/io_uring Don't use the return value from import_iovec(). Thread-Topic: [PATCH 4/9 next] fs/io_uring Don't use the return value from import_iovec(). Thread-Index: AdaLbe1b5RzSfSnfQoqJG9wxedvDFg== Date: Tue, 15 Sep 2020 14:55:20 +0000 Message-ID: <0dc67994b6b2478caa3d96a9e24d2bfb@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: aculab.com Content-Language: en-US Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This is the only code that relies on import_iovec() returning iter.count on success. This allows a better interface to import_iovec(). Signed-off-by: David Laight Reviewed-by: Pavel Begunkov --- fs/io_uring.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index 3790c7fe9fee..0df43882e4b3 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -2824,7 +2824,7 @@ static ssize_t __io_import_iovec(int rw, struct io_kiocb *req, ret = import_single_range(rw, buf, sqe_len, *iovec, iter); *iovec = NULL; - return ret < 0 ? ret : sqe_len; + return ret; } if (req->flags & REQ_F_BUFFER_SELECT) { @@ -2853,7 +2853,7 @@ static ssize_t io_import_iovec(int rw, struct io_kiocb *req, if (!req->io) return __io_import_iovec(rw, req, iovec, iter, needs_lock); *iovec = NULL; - return iov_iter_count(&req->io->rw.iter); + return 0; } static inline loff_t *io_kiocb_ppos(struct kiocb *kiocb) @@ -3123,7 +3123,7 @@ static int io_read(struct io_kiocb *req, bool force_nonblock, if (ret < 0) return ret; iov_count = iov_iter_count(iter); - io_size = ret; + io_size = iov_count; req->result = io_size; ret = 0; @@ -3246,7 +3246,7 @@ static int io_write(struct io_kiocb *req, bool force_nonblock, if (ret < 0) return ret; iov_count = iov_iter_count(iter); - io_size = ret; + io_size = iov_count; req->result = io_size; /* Ensure we clear previously set non-block flag */ From patchwork Tue Sep 15 14:55:24 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 260863 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B6C9C433E2 for ; Tue, 15 Sep 2020 14:57:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B479420732 for ; Tue, 15 Sep 2020 14:57:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726245AbgIOO4n convert rfc822-to-8bit (ORCPT ); Tue, 15 Sep 2020 10:56:43 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.86.151]:29387 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727354AbgIOOz3 (ORCPT ); Tue, 15 Sep 2020 10:55:29 -0400 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-37-dfVtB9cCPvahLiPigLatfA-1; Tue, 15 Sep 2020 15:55:25 +0100 X-MC-Unique: dfVtB9cCPvahLiPigLatfA-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 15 Sep 2020 15:55:24 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Tue, 15 Sep 2020 15:55:24 +0100 From: David Laight To: "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "io-uring@vger.kernel.org" , Jens Axboe , "David S. Miller" , Al Viro , linux-fsdevel Subject: [PATCH 5/9 next] scsi: Use iovec_import() instead of import_iovec(). Thread-Topic: [PATCH 5/9 next] scsi: Use iovec_import() instead of import_iovec(). Thread-Index: AdaLbdBrrJnvb+q4Sa6RtPibF1KBcw== Date: Tue, 15 Sep 2020 14:55:24 +0000 Message-ID: <27be46ece36c42d6a7dabf62c6ac7a98@AcuMS.aculab.com> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0.001 X-Mimecast-Originator: aculab.com Content-Language: en-US Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org iovec_import() has a safer calling convention than import_iovec(). Signed-off-by: David Laight --- block/scsi_ioctl.c | 14 ++++++++------ drivers/scsi/sg.c | 14 +++++++------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c index ef722f04f88a..0343918a84d3 100644 --- a/block/scsi_ioctl.c +++ b/block/scsi_ioctl.c @@ -331,20 +331,22 @@ static int sg_io(struct request_queue *q, struct gendisk *bd_disk, ret = 0; if (hdr->iovec_count) { struct iov_iter i; - struct iovec *iov = NULL; + struct iovec *iov; #ifdef CONFIG_COMPAT if (in_compat_syscall()) - ret = compat_import_iovec(rq_data_dir(rq), + iov = compat_iovec_import(rq_data_dir(rq), hdr->dxferp, hdr->iovec_count, - 0, &iov, &i); + NULL, &i); else #endif - ret = import_iovec(rq_data_dir(rq), + iov = iovec_import(rq_data_dir(rq), hdr->dxferp, hdr->iovec_count, - 0, &iov, &i); - if (ret < 0) + NULL, &i); + if (IS_ERR(iov)) { + ret = PTR_ERR(iov); goto out_free_cdb; + } /* SG_IO howto says that the shorter of the two wins */ iov_iter_truncate(&i, hdr->dxfer_len); diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c index 20472aaaf630..1dbc0a74add5 100644 --- a/drivers/scsi/sg.c +++ b/drivers/scsi/sg.c @@ -1817,19 +1817,19 @@ sg_start_req(Sg_request *srp, unsigned char *cmd) } if (iov_count) { - struct iovec *iov = NULL; + struct iovec *iov; struct iov_iter i; #ifdef CONFIG_COMPAT if (in_compat_syscall()) - res = compat_import_iovec(rw, hp->dxferp, iov_count, - 0, &iov, &i); + iov = compat_iovec_import(rw, hp->dxferp, iov_count, + NULL, &i); else #endif - res = import_iovec(rw, hp->dxferp, iov_count, - 0, &iov, &i); - if (res < 0) - return res; + iov = iovec_import(rw, hp->dxferp, iov_count, + NULL, &i); + if (IS_ERR(iov)) + return PTR_ERR(iov); iov_iter_truncate(&i, hp->dxfer_len); if (!iov_iter_count(&i)) { From patchwork Tue Sep 15 14:55:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 260832 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7474DC433E2 for ; Tue, 15 Sep 2020 23:02:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A09520770 for ; Tue, 15 Sep 2020 23:02:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727562AbgIOXCI convert rfc822-to-8bit (ORCPT ); Tue, 15 Sep 2020 19:02:08 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([185.58.86.151]:48142 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727309AbgIOOzu (ORCPT ); Tue, 15 Sep 2020 10:55:50 -0400 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-5-ZlNQaq51PdSjWG-hec5MQA-1; Tue, 15 Sep 2020 15:55:31 +0100 X-MC-Unique: ZlNQaq51PdSjWG-hec5MQA-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 15 Sep 2020 15:55:31 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Tue, 15 Sep 2020 15:55:31 +0100 From: David Laight To: "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "io-uring@vger.kernel.org" , Jens Axboe , "David S. Miller" , Al Viro , linux-fsdevel Subject: [PATCH 7/9 next] mm/process_vm_access: Use iovec_import() instead of import_iovec(). Thread-Topic: [PATCH 7/9 next] mm/process_vm_access: Use iovec_import() instead of import_iovec(). Thread-Index: AdaLbliE1LQuFgQoRvuMh1ueXN8hpw== Date: Tue, 15 Sep 2020 14:55:30 +0000 Message-ID: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org iovec_import() has a safer calling convention than import_iovec(). Signed-off-by: David Laight --- mm/process_vm_access.c | 81 ++++++++++++++++++++++-------------------- 1 file changed, 42 insertions(+), 39 deletions(-) diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c index 1cc3d6f66b31..048637944d47 100644 --- a/mm/process_vm_access.c +++ b/mm/process_vm_access.c @@ -260,10 +260,10 @@ static ssize_t process_vm_rw(pid_t pid, unsigned long riovcnt, unsigned long flags, int vm_write) { - struct iovec iovstack_l[UIO_FASTIOV]; - struct iovec iovstack_r[UIO_FASTIOV]; - struct iovec *iov_l = iovstack_l; - struct iovec *iov_r = iovstack_r; + struct iovec_cache cache_l; + struct iovec_cache cache_r; + struct iovec *iov_l; + struct iovec *iov_r; struct iov_iter iter_l, iter_r; ssize_t rc; int dir = vm_write ? WRITE : READ; @@ -272,24 +272,25 @@ static ssize_t process_vm_rw(pid_t pid, return -EINVAL; /* Check iovecs */ - rc = import_iovec(dir, lvec, liovcnt, UIO_FASTIOV, &iov_l, &iter_l); - if (rc < 0) - return rc; - if (!iov_iter_count(&iter_l)) - goto free_iovecs; - - rc = import_iovec(CHECK_IOVEC_ONLY, rvec, riovcnt, UIO_FASTIOV, &iov_r, &iter_r); - if (rc <= 0) - goto free_iovecs; - - rc = process_vm_rw_core(pid, &iter_l, iter_r.iov, iter_r.nr_segs, - flags, vm_write); + iov_l = iovec_import(dir, lvec, liovcnt, &cache_l, &iter_l); + if (IS_ERR(iov_l)) + return PTR_ERR(iov_l); + if (!iov_iter_count(&iter_l)) { + rc = 0; + goto free_iovec_l; + } -free_iovecs: - if (iov_r != iovstack_r) + iov_r = iovec_import(CHECK_IOVEC_ONLY, rvec, riovcnt, &cache_r, &iter_r); + if (IS_ERR(iov_r)) { + rc = PTR_ERR(iov_r); + } else { + rc = process_vm_rw_core(pid, &iter_l, iter_r.iov, + iter_r.nr_segs, flags, vm_write); kfree(iov_r); - if (iov_l != iovstack_l) - kfree(iov_l); + } + +free_iovec_l: + kfree(iov_l); return rc; } @@ -319,10 +320,10 @@ compat_process_vm_rw(compat_pid_t pid, unsigned long riovcnt, unsigned long flags, int vm_write) { - struct iovec iovstack_l[UIO_FASTIOV]; - struct iovec iovstack_r[UIO_FASTIOV]; - struct iovec *iov_l = iovstack_l; - struct iovec *iov_r = iovstack_r; + struct iovec_cache cache_l; + struct iovec_cache cache_r; + struct iovec *iov_l; + struct iovec *iov_r; struct iov_iter iter_l, iter_r; ssize_t rc = -EFAULT; int dir = vm_write ? WRITE : READ; @@ -330,23 +331,25 @@ compat_process_vm_rw(compat_pid_t pid, if (flags != 0) return -EINVAL; - rc = compat_import_iovec(dir, lvec, liovcnt, UIO_FASTIOV, &iov_l, &iter_l); - if (rc < 0) - return rc; - if (!iov_iter_count(&iter_l)) - goto free_iovecs; - rc = compat_import_iovec(0, rvec, riovcnt, UIO_FASTIOV, &iov_r, &iter_r); - if (rc <= 0) - goto free_iovecs; - - rc = process_vm_rw_core(pid, &iter_l, iter_r.iov, iter_r.nr_segs, - flags, vm_write); + iov_l = compat_iovec_import(dir, lvec, liovcnt, &cache_l, &iter_l); + if (IS_ERR(iov_l)) + return PTR_ERR(iov_l); + if (!iov_iter_count(&iter_l)) { + rc = 0; + goto free_iovec_l; + } -free_iovecs: - if (iov_r != iovstack_r) + iov_r = compat_iovec_import(0, rvec, riovcnt, &cache_r, &iter_r); + if (IS_ERR(iov_r)) { + rc = PTR_ERR(iov_r); + } else { + rc = process_vm_rw_core(pid, &iter_l, iter_r.iov, + iter_r.nr_segs, flags, vm_write); kfree(iov_r); - if (iov_l != iovstack_l) - kfree(iov_l); + } + +free_iovec_l: + kfree(iov_l); return rc; } From patchwork Tue Sep 15 14:55:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Laight X-Patchwork-Id: 260831 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36A30C2D0E3 for ; Tue, 15 Sep 2020 23:02:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 09420206DC for ; Tue, 15 Sep 2020 23:02:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727448AbgIOXCC convert rfc822-to-8bit (ORCPT ); Tue, 15 Sep 2020 19:02:02 -0400 Received: from eu-smtp-delivery-151.mimecast.com ([207.82.80.151]:27049 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727363AbgIOOzv (ORCPT ); Tue, 15 Sep 2020 10:55:51 -0400 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-212-ouC9VtsePgW0zmxTBHC3SA-1; Tue, 15 Sep 2020 15:55:35 +0100 X-MC-Unique: ouC9VtsePgW0zmxTBHC3SA-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 15 Sep 2020 15:55:34 +0100 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Tue, 15 Sep 2020 15:55:34 +0100 From: David Laight To: "linux-kernel@vger.kernel.org" , "netdev@vger.kernel.org" , "io-uring@vger.kernel.org" , Jens Axboe , "David S. Miller" , Al Viro , linux-fsdevel Subject: [PATCH 8/9 next] fs: Use iovec_import() instead of import_iovec(). Thread-Topic: [PATCH 8/9 next] fs: Use iovec_import() instead of import_iovec(). Thread-Index: AdaLblh1gZNjsQwuQPyq7LxxRCu5GQ== Date: Tue, 15 Sep 2020 14:55:34 +0000 Message-ID: Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0.002 X-Mimecast-Originator: aculab.com Content-Language: en-US Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org iovec_import() has a safer calling convention than import_iovec(). Signed-off-by: David Laight --- fs/aio.c | 34 ++++++++++++------------ fs/read_write.c | 69 ++++++++++++++++++++++++++----------------------- fs/splice.c | 22 +++++++++------- 3 files changed, 65 insertions(+), 60 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index d5ec30385566..909c03143374 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -1477,24 +1477,20 @@ static int aio_prep_rw(struct kiocb *req, const struct iocb *iocb) return 0; } -static ssize_t aio_setup_rw(int rw, const struct iocb *iocb, - struct iovec **iovec, bool vectored, bool compat, +static struct iovec *aio_setup_rw(int rw, const struct iocb *iocb, + struct iovec_cache *cache, bool vectored, bool compat, struct iov_iter *iter) { void __user *buf = (void __user *)(uintptr_t)iocb->aio_buf; size_t len = iocb->aio_nbytes; - if (!vectored) { - ssize_t ret = import_single_range(rw, buf, len, *iovec, iter); - *iovec = NULL; - return ret; - } + if (!vectored) + return ERR_PTR(import_single_range(rw, buf, len, cache->iov, iter)); #ifdef CONFIG_COMPAT if (compat) - return compat_import_iovec(rw, buf, len, UIO_FASTIOV, iovec, - iter); + return compat_iovec_import(rw, buf, len, cache, iter); #endif - return import_iovec(rw, buf, len, UIO_FASTIOV, iovec, iter); + return iovec_import(rw, buf, len, cache, iter); } static inline void aio_rw_done(struct kiocb *req, ssize_t ret) @@ -1520,8 +1516,9 @@ static inline void aio_rw_done(struct kiocb *req, ssize_t ret) static int aio_read(struct kiocb *req, const struct iocb *iocb, bool vectored, bool compat) { - struct iovec inline_vecs[UIO_FASTIOV], *iovec = inline_vecs; + struct iovec_cache cache; struct iov_iter iter; + struct iovec *iovec; struct file *file; int ret; @@ -1535,9 +1532,9 @@ static int aio_read(struct kiocb *req, const struct iocb *iocb, if (unlikely(!file->f_op->read_iter)) return -EINVAL; - ret = aio_setup_rw(READ, iocb, &iovec, vectored, compat, &iter); - if (ret < 0) - return ret; + iovec = aio_setup_rw(READ, iocb, &cache, vectored, compat, &iter); + if (IS_ERR(iovec)) + return PTR_ERR(iovec); ret = rw_verify_area(READ, file, &req->ki_pos, iov_iter_count(&iter)); if (!ret) aio_rw_done(req, call_read_iter(file, req, &iter)); @@ -1548,8 +1545,9 @@ static int aio_read(struct kiocb *req, const struct iocb *iocb, static int aio_write(struct kiocb *req, const struct iocb *iocb, bool vectored, bool compat) { - struct iovec inline_vecs[UIO_FASTIOV], *iovec = inline_vecs; + struct iovec_cache cache; struct iov_iter iter; + struct iovec *iovec; struct file *file; int ret; @@ -1563,9 +1561,9 @@ static int aio_write(struct kiocb *req, const struct iocb *iocb, if (unlikely(!file->f_op->write_iter)) return -EINVAL; - ret = aio_setup_rw(WRITE, iocb, &iovec, vectored, compat, &iter); - if (ret < 0) - return ret; + iovec = aio_setup_rw(WRITE, iocb, &cache, vectored, compat, &iter); + if (IS_ERR(iovec)) + return PTR_ERR(iovec); ret = rw_verify_area(WRITE, file, &req->ki_pos, iov_iter_count(&iter)); if (!ret) { /* diff --git a/fs/read_write.c b/fs/read_write.c index e5e891a88442..6e3d4a646f3c 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -884,35 +884,38 @@ EXPORT_SYMBOL(vfs_iter_write); ssize_t vfs_readv(struct file *file, const struct iovec __user *vec, unsigned long vlen, loff_t *pos, rwf_t flags) { - struct iovec iovstack[UIO_FASTIOV]; - struct iovec *iov = iovstack; + struct iovec_cache cache; struct iov_iter iter; + struct iovec *iov; ssize_t ret; - ret = import_iovec(READ, vec, vlen, ARRAY_SIZE(iovstack), &iov, &iter); - if (ret >= 0) { - ret = do_iter_read(file, &iter, pos, flags); - kfree(iov); - } + iov = iovec_import(READ, vec, vlen, &cache, &iter); + if (IS_ERR(iov)) + return PTR_ERR(iov); + + ret = do_iter_read(file, &iter, pos, flags); + kfree(iov); return ret; } static ssize_t vfs_writev(struct file *file, const struct iovec __user *vec, unsigned long vlen, loff_t *pos, rwf_t flags) { - struct iovec iovstack[UIO_FASTIOV]; - struct iovec *iov = iovstack; + struct iovec_cache cache; struct iov_iter iter; + struct iovec *iov; ssize_t ret; - ret = import_iovec(WRITE, vec, vlen, ARRAY_SIZE(iovstack), &iov, &iter); - if (ret >= 0) { - file_start_write(file); - ret = do_iter_write(file, &iter, pos, flags); - file_end_write(file); - kfree(iov); - } + iov = iovec_import(WRITE, vec, vlen, &cache, &iter); + if (IS_ERR(iov)) + return PTR_ERR(iov); + + file_start_write(file); + ret = do_iter_write(file, &iter, pos, flags); + file_end_write(file); + + kfree(iov); return ret; } @@ -1073,16 +1076,17 @@ static size_t compat_readv(struct file *file, const struct compat_iovec __user *vec, unsigned long vlen, loff_t *pos, rwf_t flags) { - struct iovec iovstack[UIO_FASTIOV]; - struct iovec *iov = iovstack; + struct iovec_cache cache; struct iov_iter iter; + struct iovec *iov; ssize_t ret; - ret = compat_import_iovec(READ, vec, vlen, UIO_FASTIOV, &iov, &iter); - if (ret >= 0) { - ret = do_iter_read(file, &iter, pos, flags); - kfree(iov); - } + iov = compat_iovec_import(READ, vec, vlen, &cache, &iter); + if (IS_ERR(iov)) + return PTR_ERR(iov); + + ret = do_iter_read(file, &iter, pos, flags); + kfree(iov); if (ret > 0) add_rchar(current, ret); inc_syscr(current); @@ -1181,18 +1185,19 @@ static size_t compat_writev(struct file *file, const struct compat_iovec __user *vec, unsigned long vlen, loff_t *pos, rwf_t flags) { - struct iovec iovstack[UIO_FASTIOV]; - struct iovec *iov = iovstack; + struct iovec_cache cache; struct iov_iter iter; + struct iovec *iov; ssize_t ret; - ret = compat_import_iovec(WRITE, vec, vlen, UIO_FASTIOV, &iov, &iter); - if (ret >= 0) { - file_start_write(file); - ret = do_iter_write(file, &iter, pos, flags); - file_end_write(file); - kfree(iov); - } + iov = compat_iovec_import(WRITE, vec, vlen, &cache, &iter); + if (IS_ERR(iov)) + return PTR_ERR(iov); + + file_start_write(file); + ret = do_iter_write(file, &iter, pos, flags); + file_end_write(file); + kfree(iov); if (ret > 0) add_wchar(current, ret); inc_syscw(current); diff --git a/fs/splice.c b/fs/splice.c index d7c8a7c4db07..ec1a825525d0 100644 --- a/fs/splice.c +++ b/fs/splice.c @@ -1349,9 +1349,9 @@ static long do_vmsplice(struct file *f, struct iov_iter *iter, unsigned int flag SYSCALL_DEFINE4(vmsplice, int, fd, const struct iovec __user *, uiov, unsigned long, nr_segs, unsigned int, flags) { - struct iovec iovstack[UIO_FASTIOV]; - struct iovec *iov = iovstack; + struct iovec_cache cache; struct iov_iter iter; + struct iovec *iov; ssize_t error; struct fd f; int type; @@ -1361,9 +1361,10 @@ SYSCALL_DEFINE4(vmsplice, int, fd, const struct iovec __user *, uiov, if (error) return error; - error = import_iovec(type, uiov, nr_segs, - ARRAY_SIZE(iovstack), &iov, &iter); - if (error >= 0) { + iov = iovec_import(type, uiov, nr_segs, &cache, &iter); + if (IS_ERR(iov)) { + error = PTR_ERR(iov); + } else { error = do_vmsplice(f.file, &iter, flags); kfree(iov); } @@ -1375,9 +1376,9 @@ SYSCALL_DEFINE4(vmsplice, int, fd, const struct iovec __user *, uiov, COMPAT_SYSCALL_DEFINE4(vmsplice, int, fd, const struct compat_iovec __user *, iov32, unsigned int, nr_segs, unsigned int, flags) { - struct iovec iovstack[UIO_FASTIOV]; - struct iovec *iov = iovstack; + struct iovec_cache cache; struct iov_iter iter; + struct iovec *iov; ssize_t error; struct fd f; int type; @@ -1387,9 +1388,10 @@ COMPAT_SYSCALL_DEFINE4(vmsplice, int, fd, const struct compat_iovec __user *, io if (error) return error; - error = compat_import_iovec(type, iov32, nr_segs, - ARRAY_SIZE(iovstack), &iov, &iter); - if (error >= 0) { + iov = compat_iovec_import(type, iov32, nr_segs, &cache, &iter); + if (IS_ERR(iov)) { + error = PTR_ERR(iov); + } else { error = do_vmsplice(f.file, &iter, flags); kfree(iov); }