From patchwork Fri Sep 22 12:02:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395699 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36BDECD4F5B for ; Fri, 22 Sep 2023 12:02:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C88DD6B02C1; Fri, 22 Sep 2023 08:02:43 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C12DB6B02C2; Fri, 22 Sep 2023 08:02:43 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A64A16B02C3; Fri, 22 Sep 2023 08:02:43 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 966B26B02C1 for ; Fri, 22 Sep 2023 08:02:43 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 68923810BD for ; Fri, 22 Sep 2023 12:02:43 +0000 (UTC) X-FDA: 81264096606.28.52D143F Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf27.hostedemail.com (Postfix) with ESMTP id 2A6304004F for ; Fri, 22 Sep 2023 12:02:39 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FMzP6vg1; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695384160; a=rsa-sha256; cv=none; b=3a+YElHjvlKgDuUTp7/cPI+OHeg6u5VGYIpaH5j7gulZvwwiRqJAnVEk+YfKU+CgOkxGTA xUIn0KdZ2bp7Au7ceLTg3f/baQ+5mv5p8vpR48Sq8nWJUUe+bmKH94L8dmdS6DPra1iK1e yFmhWcHBF+OUVB9lvJM8NE0k6N80fUY= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=FMzP6vg1; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf27.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695384160; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LZvLwoc939E6B4TZcwRPSf2buY4OlPtMZfRg4M/9mP0=; b=efHeS6wLooeKnfdR7hH3rjG08CeVjxXUBkhAan/9d2PF9Nu8BhSD3pFOrxPuDxFH8Jt1eJ yQqXaiecwwgzkmcrJZ/viQ+hI4Z+vheItTNG052xPBxWM5YpCvafIfzh6gVDH5PvwtzwK3 jVf/GHChPHiN3YFJaxzvSeYMC5SigPU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695384159; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LZvLwoc939E6B4TZcwRPSf2buY4OlPtMZfRg4M/9mP0=; b=FMzP6vg1XwFIxbOA5n7rK1GQ1DPPKHAuduWQIsC9Cs5z5KF4lL+GxwKE3ANyBiHUL6ZgcF vgpU0qf/4wmIKIGfl7WpJe6Vs/oUxBYfeCi290lxH3mCjEM9q14uWYbfkLpL0lMWYWrM4X /sVecALT51uQLX2nh7RLZ+RAOUIXjls= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-396-9KECr8cHMfC82Ed_BGv0kQ-1; Fri, 22 Sep 2023 08:02:35 -0400 X-MC-Unique: 9KECr8cHMfC82Ed_BGv0kQ-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 4981C803470; Fri, 22 Sep 2023 12:02:34 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9AA7310F1BE8; Fri, 22 Sep 2023 12:02:32 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 01/13] iov_iter: Remove last_offset from iov_iter as it was for ITER_PIPE Date: Fri, 22 Sep 2023 13:02:15 +0100 Message-ID: <20230922120227.1173720-2-dhowells@redhat.com> In-Reply-To: <20230922120227.1173720-1-dhowells@redhat.com> References: <20230922120227.1173720-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 2A6304004F X-Stat-Signature: e7rmzrhdboofa4fdk77bj9c1i784r4pf X-HE-Tag: 1695384159-673304 X-HE-Meta: U2FsdGVkX18S0uYyJ38ncG8gdxcqMf9jKBDzcsxNovpibPQUuatOGvffTeLSCoPhhP+VA0TW/Dl8RiYZ75wIUUC3Xr+IPycyI8Ehn4iTzycyOP5Mnlfd9FiL91RKcB7+ZwHErlcOEGRLs8BB8KXGr5tx73AQJGgMB50xbLnvl4BWXgJhYx8hA17Inl5lb3Gs5xWrAw6WlQgDqs5T684Pezwey15nppWXdaDlcCm9dC/eUmwf3bij2VuFmlbRajbeXi6WZgPyYGhKvPDuse4lGK02SHK6Q9t8yJv9yloQ7Hq4Qll29729l7PuXGBlHylrAAydYzxRP1SuOKHb8uDSaxJOKO4fT2jCLGwY4oAjs6go9clBf47TmfRHPAhLBz/Nv7o6Dz4ZO7fXpPr3bokkaeC6VjIbi0vAU2TW2QcmKZFMwz0XmqHFI9SXKJ1tbXXTrxV8aZ0vfjp7vrU1jwUuyhs8rFgicRMY5Khho+NuEU3xgem2K0KLbh2oDNaDvEpPlQh0ud0/8Md4Dvr0GFE5dJBwRaoW5bwydebVBQ0u03iqhsdyfE421njNANcW79vl1a4uc2nC1CylyRrcrsUO4tdo6Zw5FBFkzize/Yn2Zx2GBp0W/QC2RK5s86C8UACKBC47oa3x/Rxaeo7NZr07Fgi7m9PgUz/5Qs6ZpmNtOLvzDveoYmamIn/6GinZmTfVcnf3qlGdySFaGW/zkOyKEwX9yLaFyY2qnvXb01eC5w/vIQaZAab2MXF5M4QrzSDsLIeU4mNuYx0+vRaQBOSyPVo2+otOX9Uj55Hx7N22XUwN4Azq0Lu2MfYZzZcze12OTtK1xcJs99QllvEqAfSBRLxPL/7g1BVF+3OabNq3IciDs3i8wZoUK21rVyf5qvTZIo7S1i0eVriBM7m5dMUEhaF/PVW+/q+GnzP+3TqOp93XjbW9BRS2cwFFUsmDiyeuCR3nOQUSgiR2JuXNlax ZUEO09Zw 23p9m5G/hp7nqE0HJbyHSlhjrL76Up94+9LHPK+5el1xNHNuh1gjtHQn73VPaX6oeqxIVTCk80r7WsNnVgXDFRTPhBLjE43O3/qBTA8ib7O7Nb3rgD/m58fpDkIapnocafFI0KAFnA2Uc8bb7m0X8MhAd6vUon7ONpcaHHr4nplAwyui1pNDuNu4l6vuEE8LwhgLFgiIfeKLYYNJM+P/O10Ix665H/qxaIbITM+XrLPH7PV4bDRCKEGePN5zoFwMNtNY7fzsv9F3d6pJuj+hoV+jjXECd/wEMnoyCsFCLjpx4uMpALIOU4gkwA8WdGuexK08xWSLb62nn++Uck/LRL65/bnHH8Bh5Zl3ks3I1MRYDI1Bfon1BXWKf8NkPfFrZjA06oHUmiEn+4aQVySKAZS09f5OMjHk/VttdOYylWTVq3HwTOmU4f5Cag4OKKw3HYs6jMgZmjMeoRbwZFbT/CP9nYn84h9NmLihAikjNt0yJuBEdv8nB3my4HHKEoh7t3MtT/5Jwnm9H4zicswcs+SZqT20BEOR+nHvv2t2q2q5IaGodj13jMS98IsS0cobMtDumlSY52seUZqU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Now that ITER_PIPE has been removed, iov_iter::last_offset is no longer used, so remove it. Signed-off-by: David Howells cc: Alexander Viro cc: Jens Axboe cc: Christoph Hellwig cc: Christian Brauner cc: Matthew Wilcox cc: Linus Torvalds cc: David Laight cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- include/linux/uio.h | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index 42bce38a8e87..2000e42a6586 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -44,10 +44,7 @@ struct iov_iter { bool nofault; bool data_source; bool user_backed; - union { - size_t iov_offset; - int last_offset; - }; + size_t iov_offset; /* * Hack alert: overlay ubuf_iovec with iovec + count, so * that the members resolve correctly regardless of the type From patchwork Fri Sep 22 12:02:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395700 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A5B4CD4F5B for ; Fri, 22 Sep 2023 12:02:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B025F6B02C4; Fri, 22 Sep 2023 08:02:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A8AAC6B02C5; Fri, 22 Sep 2023 08:02:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92C3F6B02C6; Fri, 22 Sep 2023 08:02:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 7CA316B02C4 for ; Fri, 22 Sep 2023 08:02:46 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 505141CAE87 for ; Fri, 22 Sep 2023 12:02:46 +0000 (UTC) X-FDA: 81264096732.02.488B480 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf09.hostedemail.com (Postfix) with ESMTP id 735E314002E for ; Fri, 22 Sep 2023 12:02:44 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=L+Oqe1NY; spf=pass (imf09.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695384164; a=rsa-sha256; cv=none; b=op60KoXWqx/ndOdbr2IYZQ4BgkIAzgwL/OUgat2zSZcPmPuX8a8WWu8JC5NvZwwVbKtDjN 7lgJ1iDYF9e3cBo8tQGSQ0fOCY+jNhTkA4iVVDJV4+KywVh63Hl4PJ59o/v1JSA7KUzhEJ ysP0ODK3r49nW3Trgh0aBCUou7pW3ro= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=L+Oqe1NY; spf=pass (imf09.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695384164; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oQ7llY41C7nXc6PO5+rWDb67yJZYIoiIAsyEYwhjg+w=; b=g6uHxxwFLY6AGliTDudpLC8jHyjDNxHrnleQDBeGq6N19C7b2JdoFz43pREnrko+w69fO5 6758rxZrkPHg2MhcL7s6jMvdRhCQU6en1/KOulmxRdAhaL19i53ze5R70OyXnrvXYH1Aql CFZF+Cn+7GzrlxueOxj1BI979A912Lk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695384163; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oQ7llY41C7nXc6PO5+rWDb67yJZYIoiIAsyEYwhjg+w=; b=L+Oqe1NYFS80I82W4WiOnmGWxqLWO028hlNp9dztI09N2+LNZBijCv97QzHaCpFVENWyVL loZWLlJzPHMUcA7PSzFLlqDR1ViBUYHkSgG3GoQAhK9OWX5U8r3qVuy5AJGY0W3mDnnWr9 6uAWQ6L9+Sn3oQFxhafURjj1JzfiqCc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-295-8-QZXS7iNU2GtXgc29v2FQ-1; Fri, 22 Sep 2023 08:02:37 -0400 X-MC-Unique: 8-QZXS7iNU2GtXgc29v2FQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9E637185A78E; Fri, 22 Sep 2023 12:02:36 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id DF47A40C6EBF; Fri, 22 Sep 2023 12:02:34 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Dan Williams Subject: [PATCH v6 02/13] iov_iter: Be consistent about the __user tag on copy_mc_to_user() Date: Fri, 22 Sep 2023 13:02:16 +0100 Message-ID: <20230922120227.1173720-3-dhowells@redhat.com> In-Reply-To: <20230922120227.1173720-1-dhowells@redhat.com> References: <20230922120227.1173720-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 735E314002E X-Stat-Signature: 9uycj678d3tzmtk7osezdppn73o3s77i X-Rspam-User: X-HE-Tag: 1695384164-238031 X-HE-Meta: U2FsdGVkX1/IWV+K7NBAjefcx88M5dWF9Wy7ok0MlwQIWGb7xOR/USuyJHV+HqRxmPlhJCv60ZL4wxTcJahp9zNNVUPXoWdc0fVVkQKvzh9BatTq41+JPbT/qOUJaxM9/ppHHfe+BL9uunM1qOJUSaBp0QvnLUFBv0+bjSlImvdREkZW9unS/waWFl6FWWPKvjf0Lguvydyujem8+lPuCQNR/eYr2ixvHVaOsUcQYUVhpoFFfFrgqnBOCdtf3w9zvZLITdVcwLsfHfXh/yIQbMDi1//cFPaZDqSnmPnlhgIlJzPofPf+T1dqZGuA3MEd2vEnfJK+pG3XRBL6qy5V0Ow2HEufAzra4kSukAmT//ExxgNp0NJKEqi4+O5qppwxdEoQLmfylH3D8O3ikpx2yyznhw8gbRsTep3JeAeCbaIJZskBEFiSc8sHMGBlObbhirxPfaCjR8zuvgVVAZr767MmY+52YMzZKOtHmU6jGpgk3YVlzUwkODQkLOnTJ1NP+VUC/ZGB4Ac7nP5nefGxoy0P/LmQbM97ExEilwmAQDfgt+Q742pJsiGkIocnWs93qFm71UxGWYUCrZI/EDryo6QCjei5d+rrj4PHFIMW5GOf0/o4vXoHGTk3S5PviiL9ClGox+67ZC1qySvvnjNYiWARBTJP0LCWeNrLF5JebJFMd4oRi05Ih79SZeioRtqvfAFlGx/cH024vmffRgcxhb9HkSRwbZHPu5oHG4AWFIqCCCYST6S5p2b9QPa7AI5ygUY+tJtSHjmWAikI6sHiZ0ma5wTyO+tgJ2GNMS4ho61ofTwe2gOWdwXsCZuHkEoDnzeuHjZU/9udwhciUhvZb5N+0glNNYjwsHExleSS71icN0awCv8Ze6NRGa252hMB8Cs2LYUVW78RIrZBU4p62hiJtD4H8nXbLDC5hJZuLFbri3G0LwbzSNFT47HMQMTEhznfplEgycs3zljeJrs nf6JNQgr lGt+FOdAnJ2qeTyIg2pRIMspqOp+wNFQeW/UJFfyHDdwIyGjhXvwx8ec+t+TF80JrYG4igj1bdU7AOO/0tCSu6YHsonX5S06j1H2BahWf+qUjbtR3j3e124U5eZTlOZFJ6vjtbzxwYt0HNlCZY44RuvGAn09wCGmp51C12RTF9YdojPWzdkiXEuN+b1DHTiL4hBYosKaXXl2w6NzcuXB2J54u1TXk20qcwbxrLiX1uqS0fYTwGutcrlKBBr/rEsQ2UHj5du4/I6UIipJzHiMuebwqKxWQTAUVEjKv5euaD7Tf26oZiBKXdeArhL2edWuzJ510XH6woV4piL0lZnjgGPJWQF3VyDq+sQn3DUSvXCD+NjwNlRrkJdwcw+tc6sMI1BA7buNj02QRkUEuLEQw/ZZ/f2Q7B/PGqpNRjzM12aG2d0Om9gp7DbOtmLFGqVZRa4duiDiIg7lfjSndZZkkIqKfExAycWMnWPhP7ltIWY2Np8nLGbj6LqyaK+zg+kUOftNA3A9oncGV+P1DEqhtYX6g1gpBr7pfxjaEmLtaINsIsMYmIc14r6DCT3dk3AH4TjazH4+MlztnpM7UwX69cJjJglxXyK/MgEIA X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: copy_mc_to_user() has the destination marked __user on powerpc, but not on x86; the latter results in a sparse warning in lib/iov_iter.c. Fix this by applying the tag on x86 too. Fixes: ec6347bb4339 ("x86, powerpc: Rename memcpy_mcsafe() to copy_mc_to_{user, kernel}()") Signed-off-by: David Howells cc: Dan Williams cc: Alexander Viro cc: Jens Axboe cc: Christoph Hellwig cc: Christian Brauner cc: Matthew Wilcox cc: Linus Torvalds cc: David Laight cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- arch/x86/include/asm/uaccess.h | 2 +- arch/x86/lib/copy_mc.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h index 8bae40a66282..5c367c1290c3 100644 --- a/arch/x86/include/asm/uaccess.h +++ b/arch/x86/include/asm/uaccess.h @@ -496,7 +496,7 @@ copy_mc_to_kernel(void *to, const void *from, unsigned len); #define copy_mc_to_kernel copy_mc_to_kernel unsigned long __must_check -copy_mc_to_user(void *to, const void *from, unsigned len); +copy_mc_to_user(void __user *to, const void *from, unsigned len); #endif /* diff --git a/arch/x86/lib/copy_mc.c b/arch/x86/lib/copy_mc.c index 80efd45a7761..6e8b7e600def 100644 --- a/arch/x86/lib/copy_mc.c +++ b/arch/x86/lib/copy_mc.c @@ -70,23 +70,23 @@ unsigned long __must_check copy_mc_to_kernel(void *dst, const void *src, unsigne } EXPORT_SYMBOL_GPL(copy_mc_to_kernel); -unsigned long __must_check copy_mc_to_user(void *dst, const void *src, unsigned len) +unsigned long __must_check copy_mc_to_user(void __user *dst, const void *src, unsigned len) { unsigned long ret; if (copy_mc_fragile_enabled) { __uaccess_begin(); - ret = copy_mc_fragile(dst, src, len); + ret = copy_mc_fragile((__force void *)dst, src, len); __uaccess_end(); return ret; } if (static_cpu_has(X86_FEATURE_ERMS)) { __uaccess_begin(); - ret = copy_mc_enhanced_fast_string(dst, src, len); + ret = copy_mc_enhanced_fast_string((__force void *)dst, src, len); __uaccess_end(); return ret; } - return copy_user_generic(dst, src, len); + return copy_user_generic((__force void *)dst, src, len); } From patchwork Fri Sep 22 12:02:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395701 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 12A66C04AAB for ; Fri, 22 Sep 2023 12:02:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 07E1B6B02C5; Fri, 22 Sep 2023 08:02:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 004496B02C6; Fri, 22 Sep 2023 08:02:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E0F046B02C7; Fri, 22 Sep 2023 08:02:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id CBDCD6B02C5 for ; Fri, 22 Sep 2023 08:02:48 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id A2CF7B4583 for ; Fri, 22 Sep 2023 12:02:48 +0000 (UTC) X-FDA: 81264096816.12.8C73DFE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id C6A3920035 for ; Fri, 22 Sep 2023 12:02:45 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IO1dDP3e; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695384165; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7BA8QLNemiJIXUC+XXC0PAivfRO0j2uaFr7AQHg4nPM=; b=UE2+w09hleewaJcOsZmRs41ASdocfk3IhrZmkdLJhOeWgGPiv6A5yhn7fwWNmO0UsVRYsn pXxzvMO5OeYBbiWecF/dZUGh9jgkf2pRXSBQv3AeohXdvC0XNIHW5IFDiTFnJZjnDWm4PZ 0MNb1zoHHJdIjgyt3foVUpy85ahCJ1o= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IO1dDP3e; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695384165; a=rsa-sha256; cv=none; b=6I41ohNYuEZ8L4mfyNJcf0LUtXAIrhcpkVD/cHvXFCqM0JkyZzKqtaBSJsWsN3D5Botczz 2b0E1xfx27TKbti9UxUloxCX5C35+oH8m2T9lc4TlN9knfIvJu39jhcLHgVAKu6Yc0Q3KX D79wjBQQBoCThK88EGz8gdqOA2whHwA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695384165; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7BA8QLNemiJIXUC+XXC0PAivfRO0j2uaFr7AQHg4nPM=; b=IO1dDP3etDIUgSVMHmWumrWh0mMiZgmUyegLeO+q9CzDv0dErv1wo9jMQjtpAZ1JMWsBKo UuXMPbxS/5vBiEN521ytolwruWcf5yr4L43lFZtaB32iMPRekwcNsyidZW4tAnpFVF73oN AgdUp0RrQ+8O5spKwi1Kl5yGF6TsEEo= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-578-VMVqFlzOOAy8DJUDv5pSRw-1; Fri, 22 Sep 2023 08:02:41 -0400 X-MC-Unique: VMVqFlzOOAy8DJUDv5pSRw-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0CD583816C82; Fri, 22 Sep 2023 12:02:40 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 590362156701; Fri, 22 Sep 2023 12:02:37 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jaroslav Kysela , Takashi Iwai , Oswald Buddenhagen , Suren Baghdasaryan , Kuninori Morimoto , alsa-devel@alsa-project.org Subject: [PATCH v6 03/13] sound: Fix snd_pcm_readv()/writev() to use iov access functions Date: Fri, 22 Sep 2023 13:02:17 +0100 Message-ID: <20230922120227.1173720-4-dhowells@redhat.com> In-Reply-To: <20230922120227.1173720-1-dhowells@redhat.com> References: <20230922120227.1173720-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspam-User: X-Stat-Signature: urz17zjy7homa6uxycarbq7bxmwpj6mu X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: C6A3920035 X-HE-Tag: 1695384165-691758 X-HE-Meta: U2FsdGVkX18mcrFTnOjhUZ6AB2IYam7bqcmWIoZikH2AhLYuzGhVEL5K0g1bgdWJTmL1C1ovzuyCZl2F5NXixjdebBSwzpSCxH4bhremVYnzBfO6DVmWuVtBvd/E2kmK+qpGOqvoIz5xvgTFGGAeJumcZixy3PhvAJ/5f5CDOcpFLd4yxgm4dkBngj9ASklSPGm+3xRFzp+GvhtlZJp1OSGEr2B5YlXYjHrzWQftEKm9t3XlpkhfOJUtwvAGRczcmbAx3E/XNB9Pr1jcTqJQPOaVmL0s0bwKD74VrPPRcq2r/EKY2MX4nc37o9vQptQyFAU1PvtPfsOGp8hpT9LI38WlyUZuIQohYSPRmMtAsVKyVx3n1QFaiIUTk89wVA71/4EFG4oFl8luaIvdTLxsCLqAxkgc1WmWABBUtglAdeG0PTzKHyQsgiF/t5q3jUhvlIksdNXuFSXXK/r6Mow1NsWg+BFIHu01fn1m+DuezcjcoS7e/oz1a8qifMAWW1Dn/KPk0yStX15Rys1SBIuD2t2VrQNc0m5WJiwo8Dh1397dMe9tgXBPOqAfNnmDWfjNooCPR8EmHuzah/bzl2WNeah8FjgDc1DUGFLay3TOti1sMJ6E59QtTO0L/m5lqJmewGuKyxqiOMPZPki9MARQdtVbO8JvivgZicliiNQFg3auQVjOEExTKFXV40waz5PPwJe7kkEJq5TIjzHUDWzcJuwqEjS7dktX3kj/6I50vq8AEQXHZ7bY+cIKihpRe+KvYqkJRcz5NutkYq/YgEAKwnI0cULPpMGR3CX9hGRIlCgnq0KdUh+md8RiLeApwNDUFIYCZ3kd1Koff/GA+IkpH+JpfEew9Igmr2Y/QevERHIuUZsAIOPmEGHf5VrB09ufhzM9TTbe+IZ9M86hsutkSxF3IOIEl7QAVvuKxmMoujNpMQnn1JVedmo+uyBkoyLWCYyPaXvdsrD03kQ0m7V hYUkdKGX nYA9NzfvGCoMMKECl7HDyyx4F16/fHX3Wnp97xsJw+NkD802fbvo0hytNfYM0Cy69Zc/1+Rh2L6d6DSqBELY9fynYRz/gmHz9q7K5NdED49dBgP/jNKg9KGrN4Qy4mfsH6XKOUNVdKJd/6hDK7SwzAqZqh0bHGIpoGbBTSCFesqZKf2+RepudS5ybBbj4pYww/EA/N/T5SEvi2azd5AKfVOp7Nok9OvpqvFWPColk63OdX0RLVR/E5Lvzoha9fhzwIeAf8dWRDAH2GjsB9DKmzYWoubDd2xOzFgsGo+8u2yUx18oK94tmfcWR8F1rK6DFQk3lXZT1Mtzh3Hg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Fix snd_pcm_readv()/writev() to use iov access functions rather than poking at the iov_iter internals directly. Signed-off-by: David Howells Reviewed-by: Jaroslav Kysela Reviewed-by: Takashi Iwai cc: Oswald Buddenhagen cc: Jens Axboe cc: Suren Baghdasaryan cc: Kuninori Morimoto cc: alsa-devel@alsa-project.org --- sound/core/pcm_native.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c index bd9ddf412b46..9a69236fa207 100644 --- a/sound/core/pcm_native.c +++ b/sound/core/pcm_native.c @@ -3527,7 +3527,7 @@ static ssize_t snd_pcm_readv(struct kiocb *iocb, struct iov_iter *to) if (runtime->state == SNDRV_PCM_STATE_OPEN || runtime->state == SNDRV_PCM_STATE_DISCONNECTED) return -EBADFD; - if (!to->user_backed) + if (!user_backed_iter(to)) return -EINVAL; if (to->nr_segs > 1024 || to->nr_segs != runtime->channels) return -EINVAL; @@ -3567,7 +3567,7 @@ static ssize_t snd_pcm_writev(struct kiocb *iocb, struct iov_iter *from) if (runtime->state == SNDRV_PCM_STATE_OPEN || runtime->state == SNDRV_PCM_STATE_DISCONNECTED) return -EBADFD; - if (!from->user_backed) + if (!user_backed_iter(from)) return -EINVAL; if (from->nr_segs > 128 || from->nr_segs != runtime->channels || !frame_aligned(runtime, iov->iov_len)) From patchwork Fri Sep 22 12:02:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395702 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A88DC04AAB for ; Fri, 22 Sep 2023 12:02:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DEAFF6B02C8; Fri, 22 Sep 2023 08:02:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D73576B02C9; Fri, 22 Sep 2023 08:02:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C13BF6B02CA; Fri, 22 Sep 2023 08:02:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id ADA0E6B02C8 for ; Fri, 22 Sep 2023 08:02:51 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7ECF11A1008 for ; Fri, 22 Sep 2023 12:02:51 +0000 (UTC) X-FDA: 81264096942.22.DADFBDD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf21.hostedemail.com (Postfix) with ESMTP id 8039A1C0044 for ; Fri, 22 Sep 2023 12:02:48 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=f0Aphdli; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695384168; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=j/K7bby96tUMA/iC07lWusXqTlhgR9zlJgJ7++h0ZQI=; b=OuphWCjZdp7UX9hQQgNJN9WhEv5abZ16V4Crew9r3WHtsqlxDNvTyedqNZVtbCCtB/Cjlt WhWQfJvBVdTx2XZxDogH7xrXgUrLqC3qO0rGLm8hqwvJbIUPBpSYEUxEcBE/WBnmq97r+A WicE+bbqKPba0A2vX+XOJxHYe/ZMbSI= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=f0Aphdli; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf21.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695384168; a=rsa-sha256; cv=none; b=QB+JN8pNFYrJH6JZdXvcHYfCiQDGnVMzrz7CnWES0atAeiba434TalOniZAZuWkWiCzZBI 37WyJQClRST1/S6cZHaoJvhQYq2q0AzDbGuh9kWZXwdePhz027VDBSXZu/KPEfi6IrCKxf nqYe2jB5aEhM+fze8FOvhMCiVtBYSXo= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695384167; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=j/K7bby96tUMA/iC07lWusXqTlhgR9zlJgJ7++h0ZQI=; b=f0AphdliAb1hv6cAOvrk79VKuRoMOUGfkm5jARoBysxyIjsPw9e5rJ/Y+u7L3efyNguivI DEv5FkIFUyviOaLW9Ph102CGICxcuP6bf5fjlAAkHXInPW8nmMkjLhGdl9CSHIfBXM/7VY tVR9WVEjcFGMHySXtil7SWOnH0Rnheo= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-160-cipZYxGtNhaQj5TKw06UkQ-1; Fri, 22 Sep 2023 08:02:43 -0400 X-MC-Unique: cipZYxGtNhaQj5TKw06UkQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C824A1C01731; Fri, 22 Sep 2023 12:02:42 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FF4820268D6; Fri, 22 Sep 2023 12:02:40 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Dennis Dalessandro , Jason Gunthorpe , Leon Romanovsky , linux-rdma@vger.kernel.org Subject: [PATCH v6 04/13] infiniband: Use user_backed_iter() to see if iterator is UBUF/IOVEC Date: Fri, 22 Sep 2023 13:02:18 +0100 Message-ID: <20230922120227.1173720-5-dhowells@redhat.com> In-Reply-To: <20230922120227.1173720-1-dhowells@redhat.com> References: <20230922120227.1173720-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Queue-Id: 8039A1C0044 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 6hpzaiyhwrpdyy6jsconaxfumer4ps7r X-HE-Tag: 1695384168-773324 X-HE-Meta: U2FsdGVkX19YwEYThE/7yJ5nFTELKbcrxmJFQVwsxZhyIIJ8roggYHRanIiUPhA/AiDXUExJzR0II6/SxWG5gcMr8fP2Y/o9s5aqDbvNUTC3FIQkgy1dHFTxssGQ3ml9fOknOMjwtjYgLckALigF3M2IuIAFuCWU3JYy+77S1cFp6v6VCwWU/I+zGn6wryPflHgjXNhUB/EwaG6+zZQX2xTP7urQ7sqBqdabtLRZ96AYrFJa3zp+7MBPqz2t0ILsAEi+VDZZHkzJhgeDR16fQ38gZnJbXjJLrFvqj+6ziqdggwJM7oj0x2mls/XSmb8dByTZv/Y6S6vPv1tvCjJmkFqry5cmsQHDgb+TQS51Eeh9NF4c8D36YFL+iaHvfErUVDwpSkDjTjK9MLLa7hqNVnBSxaNQOkzTgQUGyiioPs+VNWK65bNDENRDO2BYT0EOkhii6P/iJ0k4mhCXXO4n0iq4KhttOWeDu2pkWiMVUmnJpucdMTzt54MKJFHxQMBkvYNKuL/jauQ3kuh+cckZhqYuCU8iRW3M7SLyL7ZGb+63XYiJwnrPkLB3n3WQn9ZkJdzyyIXJ1k8PQtAqjK4i1Zf1BbwMZyWFpQx9Xog2HvidbjIMQQq+b6cREV8TbA6b9d95A2knZErUG30pBeK2FqxOVR+nFdSJBSGzuJvhvf5L4eLMEXbUopZ5OL7EJ0r16eiRIDiUUCVFKb8zS0YSLMfeiHIB7pdasQGvwEUnoKluxJayKhA9UbyJVV5stRFgfbVwkJEMkXszhQ1N/lHPyMk+HyS7HtKnyBbBGC5LDxIhzqYleUtIJ2bNUz2WXXdLg7ijsQD2MqZarxJkkP1mEFAl8bmf+0ndnCeAlg7vEEkGTAl/AUcCJjIZ/UXMqzFstf5j5oCSdu8vVbeI9g1tTQ0pO00QgSJx8a4twPAcHhFQJH6VGpRfQBp3njwCJN4EIH41UXCwF4clIp4Og2Z fXv/7+Pg MDLjBy6H389lraST7vYFlCC0jnw3kGBdAAgrYixJby9mAmF2qLAbYEO1RWHY33/5MtVG2M93tqaAufxpa3/gjUPaL8XWquPLaMVlYmAuuObaUmPVzzwgRVshLxct/o+QDC0nkf32pkOcg6SC07eeGec1Pup0GuvEecCOsR10777D6iwV0G6DP/TkYMlDl45Lp385o5JGcO8Hu8k3tM2Fq0pF4twz1HVJXKwUsI8RVmwB9wG6AFP83nSJENE1A742ZClfP4o7degJU23EarhjxQLUTyJgZEZKVjCt5C0OFGsgGOMsmU6E1RD20IwTdqnSN84Noh5TAEL70lEouIHoshHh8uu+yHmyF2tTrhSrbSDc/9g52xSgwFeOPo2G+s5feLLIqNS+5ceEjfVE= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use user_backed_iter() to see if iterator is UBUF/IOVEC rather than poking inside the iterator. Signed-off-by: David Howells cc: Dennis Dalessandro cc: Jason Gunthorpe cc: Leon Romanovsky cc: linux-rdma@vger.kernel.org --- drivers/infiniband/hw/hfi1/file_ops.c | 2 +- drivers/infiniband/hw/qib/qib_file_ops.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/hfi1/file_ops.c b/drivers/infiniband/hw/hfi1/file_ops.c index a5ab22cedd41..788fc249234f 100644 --- a/drivers/infiniband/hw/hfi1/file_ops.c +++ b/drivers/infiniband/hw/hfi1/file_ops.c @@ -267,7 +267,7 @@ static ssize_t hfi1_write_iter(struct kiocb *kiocb, struct iov_iter *from) if (!HFI1_CAP_IS_KSET(SDMA)) return -EINVAL; - if (!from->user_backed) + if (!user_backed_iter(from)) return -EINVAL; idx = srcu_read_lock(&fd->pq_srcu); pq = srcu_dereference(fd->pq, &fd->pq_srcu); diff --git a/drivers/infiniband/hw/qib/qib_file_ops.c b/drivers/infiniband/hw/qib/qib_file_ops.c index 152952127f13..29e4c59aa23b 100644 --- a/drivers/infiniband/hw/qib/qib_file_ops.c +++ b/drivers/infiniband/hw/qib/qib_file_ops.c @@ -2244,7 +2244,7 @@ static ssize_t qib_write_iter(struct kiocb *iocb, struct iov_iter *from) struct qib_ctxtdata *rcd = ctxt_fp(iocb->ki_filp); struct qib_user_sdma_queue *pq = fp->pq; - if (!from->user_backed || !from->nr_segs || !pq) + if (!user_backed_iter(from) || !from->nr_segs || !pq) return -EINVAL; return qib_user_sdma_writev(rcd, pq, iter_iov(from), from->nr_segs); From patchwork Fri Sep 22 12:02:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395703 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F31FC04AAB for ; Fri, 22 Sep 2023 12:02:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED34F6B02CB; Fri, 22 Sep 2023 08:02:53 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id E81FE6B02CC; Fri, 22 Sep 2023 08:02:53 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CFD8A6B02CD; Fri, 22 Sep 2023 08:02:53 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id B924C6B02CB for ; Fri, 22 Sep 2023 08:02:53 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 8E2621A1058 for ; Fri, 22 Sep 2023 12:02:53 +0000 (UTC) X-FDA: 81264097026.04.917A473 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf14.hostedemail.com (Postfix) with ESMTP id C8F1B100043 for ; Fri, 22 Sep 2023 12:02:51 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="DsCAw0U/"; spf=pass (imf14.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695384171; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=oQjxv/qWpzFGTlwOWGQlwUCcgnofDI2I99l4qJgz63Y=; b=HYSyNc9L7lJOSp4/4vIvED1raL9psUyIX8vy+7UPIM8nzM4NHNvHTJdrxO4jkF6UPJH3ca /fTH9ogbyCQAI76xg4Iiti3naefLvRABXU0Ze+QdvYIXRIA3yR5EXHaopuBTBCFF2aTuZn mkxt1D/FKEOIhvorKV+J06Cfij/Sp/o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695384171; a=rsa-sha256; cv=none; b=dSInPbQRZE7ou+H8ye+5w386+nAEJ9MblWhPm8ISOth0alpL3Au3q9R+Y4/7GvOJa6Q8pJ UA3vtMKV7B76Qyb8oBycdgwCms6d5GxjCZLyNe7TejhQxzzw2LhDl7bba7X1ULWYZrhyfV aYY09AG9DYSybnFE6eGQjhEuIMBZ+2A= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="DsCAw0U/"; spf=pass (imf14.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695384171; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=oQjxv/qWpzFGTlwOWGQlwUCcgnofDI2I99l4qJgz63Y=; b=DsCAw0U/QkEjFbhuV0GnJV3ipW2KBE2veIKEyNx+4oFtPoWWSg0/r7xxnuT4OJz3vggb6D x4HFgttpsnJZn2zcDdFd+/tY0TzJA65lqbohGjMWUK9ZtqxovM/elEr0WDS2FcEJXPusNj 7NtFjJCwoASn+k3M0JWOU+a6GYUUj+o= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-383-AeRfjP2MMb6jmnzsRdIcog-1; Fri, 22 Sep 2023 08:02:46 -0400 X-MC-Unique: AeRfjP2MMb6jmnzsRdIcog-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B51B3C13505; Fri, 22 Sep 2023 12:02:45 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B15651E3; Fri, 22 Sep 2023 12:02:43 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 05/13] iov_iter: Renumber ITER_* constants Date: Fri, 22 Sep 2023 13:02:19 +0100 Message-ID: <20230922120227.1173720-6-dhowells@redhat.com> In-Reply-To: <20230922120227.1173720-1-dhowells@redhat.com> References: <20230922120227.1173720-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspamd-Queue-Id: C8F1B100043 X-Rspam-User: X-Stat-Signature: rqxqbfrzebnx9kth1mt1ad9c93dbm6b8 X-Rspamd-Server: rspam03 X-HE-Tag: 1695384171-97198 X-HE-Meta: U2FsdGVkX19AsEYra6+r0PvFTmlFba1LjfJiiDWx/VKGLVZuQrMM7By6+exVBvBgazcrVRjQ5gAbZOg5GwdIxSLxY7ASXmcNcJbVpMsaObdqm9bSx5GrfSi94bAKp81EQWUDyZg6q8KdnYpzQulJv5oK6ayj/p+IbhzJ1/djX4kMcsyvv61EFNYwccIPaofOMH4cBpXNcmgfQo5r8vuuVR2zPKEJNcFCVINVW+Lj8q2CWXTzOyYIQ5mZu0JpadB4r+eFMh2S/fTXP//g7ql/FRrJ07DNyb2GDmLU2CLYUi/cTOpJUBcfJuClOl4DT7Mr5/JmVsBggD6In08sLKoYhTwjc5WBJnUDc3BbGsnXRi3EGWjoCFq7i2PxQy6aCbbg1KFciV6iu3MY/Tn5QWVqLXsE3EwzEgC257GuBiNX7+yB4p2QF3jGMSoQH+YKJw9FT5IHghqyzwCiSJxmquLZqGLVeGA0i2UR1OkYyczlC4L1SrJb24m8hgnj6BOnjspmRbzEbXXihJxMgEjlGETMeFrNx03KNOulyoJouJhHfoDQjKGSbw27hvQUF9lvWRCwRvQNuAoR5EkIooO2wNRlNAYXqJAOPi0v/mgTE8la6GCLzda1qd0b5Rfb2kQsgAL77A5dXrLkjR2QQByBg8cU67NKlg8irKehmrcKAmFXmMT2setn3PLGNjfWoayc0ZTdfZPdVhxgb4my8DgL9glG93ffNM4qPxA+K19UdYB3ycII+yia6xo5uQ0BUkd9fE7YkDY7MRhHXytplvKHV9Cn4/qrxen27N3shcgyPMRkM9ZjtBP4W6DuB5XNkg7kez4xgO9peQyKrKy8SzEys6CLKHdaqoTTL3fW+hd/6Qhg+scHgIaC8VDuarPriu19Lhg7HhE8zcHPJApSq2fVmFrPAgQtAWAhtvQlh1MkcQJqBUr91kzn+99s6b0hICk6YLEBs03LcsyW7TwORczWh0Z wqBSSW6+ pRP+BpMorIAiVXElbk/KLTcRsfUSDFYDkmPtbNNwwSvfqizlbCu7oxUxDOcVvZoBtW8LJOIAcWHVXA2k8D2WYkjEi0NHssDii4NUkzJUaf16umqpO3Y7t72BiEgWCLLlIxhjf8OEFAH63QJMUm3veinOoOVrheX5+5Y3hzXDR7aYbJge29Xnk11FBcRtpEmkW5s283YEjtabR3eabAvIylVoviToiGuGRtIwLz6QAt3T7YGccl4IKw6I2c2KYOKKJaC4bchrRrMXjUVJlneDEBBAeWWL1O1zzam5gEei1Rtnyp2micxXrCs+Iyt8ncHAq1I3axZJ1a6Ka2N2SBZcLRJxnfW3rzDm15cdfAm+MSzLl9Z/YGAnXJXz+UvKZ1+ceQ3vi7z5Ld56G2F7ImAwMzWmPP+icxyjoKn4SmxIujdEsnbdXKszRdi4FV2ip+Z2v8vY76ThlH4xkq7t1h9+gsXwqryeNm1EX6R0oHKVfQ814dgjlERja9QGr1j+jOR015qfh3Qyp3O5bCaOwdqgr+Doyb1U24mH0Op9vU7FYzR7smaMs1d7gwi5XHZO3lGP8y8btWUJeuxyLFKI= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Renumber the ITER_* iterator-type constants to put things in the same order as in the iteration functions and to group user-backed iterators at the bottom. Signed-off-by: David Howells cc: Alexander Viro cc: Jens Axboe cc: Christoph Hellwig cc: Christian Brauner cc: Matthew Wilcox cc: Linus Torvalds cc: David Laight cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- include/linux/uio.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index 2000e42a6586..bef8e56aa45c 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -21,12 +21,12 @@ struct kvec { enum iter_type { /* iter types */ + ITER_UBUF, ITER_IOVEC, - ITER_KVEC, ITER_BVEC, + ITER_KVEC, ITER_XARRAY, ITER_DISCARD, - ITER_UBUF, }; #define ITER_SOURCE 1 // == WRITE From patchwork Fri Sep 22 12:02:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395704 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4A61BC04AAB for ; Fri, 22 Sep 2023 12:03:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 205C36B02CC; Fri, 22 Sep 2023 08:02:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 116AB6B02CD; Fri, 22 Sep 2023 08:02:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EFA556B02CE; Fri, 22 Sep 2023 08:02:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id DF2836B02CC for ; Fri, 22 Sep 2023 08:02:54 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B9CA7A10E8 for ; Fri, 22 Sep 2023 12:02:54 +0000 (UTC) X-FDA: 81264097068.09.2A4B6F1 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf02.hostedemail.com (Postfix) with ESMTP id 020598003A for ; Fri, 22 Sep 2023 12:02:52 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TPS5iQ50; spf=pass (imf02.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695384173; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=4obcSyEH8f0LI+hqbulIObwIk6RPpIYigX0Ml5LHEtM=; b=AQOkFuosioaIDsvkXvjTRuBtJpu0ZqDgs3I99t7B22BEeygqZ9rZ6gbmfc5ZFfQYIZVt4I owxtct/1PrliJJU7FJ6fWSxdjejSqkbVV284qKy5pdPqGwsr8jlqmaWm5iKgSMFc0VSBaG 036CPU40a5N+vbKkmxG9V2aJyG07qlM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695384173; a=rsa-sha256; cv=none; b=MNGQKTWsRxZuU+I6De4mG7rbD6TLklF2cCSWNj6j1CVM38cypDwJbMDSBg/2hyZLsCCOeT xRo0wvVHrWGf8qWku7fg1wb0inmFzSft9WaNovPMgF+avjihYk+VCLO+hpe9Ags8D+HKqx udfnull3yeEaBzGk4s01EeN9b93iJCs= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=TPS5iQ50; spf=pass (imf02.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695384172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4obcSyEH8f0LI+hqbulIObwIk6RPpIYigX0Ml5LHEtM=; b=TPS5iQ5067BJzAECWHAtKm/kdhoCDBGEKGNd50ojZ7Y1ncBbeIfMJehG7GX9x7JZ8ccKtN jU3pnYKUYQtkT1PybKTNVedwInRq+de7Af36vjk9okQFUzQrLI0qpeDnFsRBvfcA3P2J3x KV7GmESoIw8uqrX7q4GVNUCZ1MHjRjU= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-183-mKXZqPWoOu676PZGhvpTxw-1; Fri, 22 Sep 2023 08:02:48 -0400 X-MC-Unique: mKXZqPWoOu676PZGhvpTxw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 7EEDD185A79B; Fri, 22 Sep 2023 12:02:47 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id D33FBC15BB8; Fri, 22 Sep 2023 12:02:45 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 06/13] iov_iter: Derive user-backedness from the iterator type Date: Fri, 22 Sep 2023 13:02:20 +0100 Message-ID: <20230922120227.1173720-7-dhowells@redhat.com> In-Reply-To: <20230922120227.1173720-1-dhowells@redhat.com> References: <20230922120227.1173720-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Rspamd-Queue-Id: 020598003A X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: 9taykbfy1wukk6xb9kh3fnkfcef4jdy6 X-HE-Tag: 1695384172-317294 X-HE-Meta: U2FsdGVkX1/slIMi73mKqxj6TRo6HjFvjbTIQFIkF1WKBsFCfqCMussMUZwHhzICNOHU8wF7BmYTsIZghoQ7+KWlOKLkUklqXNIiwjTNWDjuUEUgy7AP7/bvnjxTQ5hg5jbMONq9T6YWxtE9y0Ghodn6LuspkRFCUkEfJ0Z/F2fNM1GhnQx91iZS0BZihueVj9JvANEVAdhcf8TdrLz77mGItjrq6jFbvJ1j8xunO4jJt7KuhXiEkxpoGyuhqpf8CElN8XfWGXuizqFY1X22iHbpYPNqmGz2By5905X3XFrbyTH9TQ4NqwWKGQ0Ie/AC1lW9pWquEMFm78f0mgYh5E0bvYN6JZj90g7E5ILHPiHXycJ+p549hf+5kXCN68CZcGZloXVf0wGyip5IziPgou37LKVpQk6A4KkZ9gCGzud23c1i8hkZ+AHqYmwkUq8vW5RgNTouR2Vm6zn0S2dkwXgK9lpqr+jU+7+pRovtjgH9qRb99EAwRUAfowI5bNMCaksS+tnz/D31iFDP84ixya/ixNr1c8t8wBqCH6oUGcfHY/krr5DW+OMSEcUDOQXuaqJ6CrWdJnr7tKVIpnTvo1/yahufP+fZXOQAvtuDbT4sY3CyncLE3IxpKkZNdgg77GV4LnwPmD0NyHWqupGvHQf2U8SOwRZndDoJQhM7+fZb6H8r9+7lvsQ8yFgVP1vKAk3eHmu946o8/fiR4Nd6yghgoxXr8CtHgf8iBjBWhuxxLlPDDdBXyg/Cp182yDwXCBMLe1Y4LFx4GbiG2w65ZCCi/ea0k8AfCaYIOl+zJThrfMP0nxaqH2M9fz7CoikkUcH6saz1rjcIjVAfF2587daqFzTeveV+w8cs/NEx+zbHws6cTcD6HRScSBAia2H4owlLMpMfFNwpAoAfsfFRPtMIIPu6AwvnNY5xyRzyN0Dh+F4RkTPi6C+ElaELbti9MBNdqnlyVjgEpJqG4xV 3BoPlZ7t 7jQ17ZYw77RBZLzHuVqfCIlxFu1s5HgRefgVAmVKKw3lkEz+PQuTTwoHCeKqwhzE8bK9XEpLrPzTVpJovhuEyVJccJOYv3p4p3H876DTk7qwgxf1V2GSJZGaFflxFwC+lXCW1LISAZ3vmmkqc7VwcfJPqzihMo9GNhFYhK0YmI2yy3xTkGOKiaCNIjIzoOBH0+FFYNH8/aSzGMInHKsPfj5XNZuhDoZiysWLZWyvxiuKeQ8ozd3iTLESfyGXFneCzgbGiwzM8DOdphVQEOXBqypJ9m6Zma3H1yLQusLzSDmlUU2TlSETWY8tBchd8xM8IalQ/QxJNRqLvOxwCv1BxSbdxDZu+fnppuqmRBDUz3cfAcPA7YOtHDP+H5Cs0siMQt2d7cUoUCUfPJ65hW2/x8yrtSPJjczCaqdqU4kgrTPbW7jQn38mypv0J9TkmpOImkfCCG98COLHlZex+YtIdJOvSFoR9j6w2JtavI3osXkXlEOrhQqKF7MKEOggX5BZ6w6BBLrwonwDF5Uk24GHZ6HmWXu9KkUvNzIDRdU7uXedH1Q7GWRQjws/0gFRh5TW1zuaG2U1fNqZn/M0= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Use the iterator type to determine whether an iterator is user-backed or not rather than using a special flag for it. Now that ITER_UBUF and ITER_IOVEC are 0 and 1, they can be checked with a single comparison. Signed-off-by: David Howells cc: Alexander Viro cc: Jens Axboe cc: Christoph Hellwig cc: Christian Brauner cc: Matthew Wilcox cc: Linus Torvalds cc: David Laight cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- include/linux/uio.h | 4 +--- lib/iov_iter.c | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index bef8e56aa45c..65d9143f83c8 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -43,7 +43,6 @@ struct iov_iter { bool copy_mc; bool nofault; bool data_source; - bool user_backed; size_t iov_offset; /* * Hack alert: overlay ubuf_iovec with iovec + count, so @@ -140,7 +139,7 @@ static inline unsigned char iov_iter_rw(const struct iov_iter *i) static inline bool user_backed_iter(const struct iov_iter *i) { - return i->user_backed; + return iter_is_ubuf(i) || iter_is_iovec(i); } /* @@ -380,7 +379,6 @@ static inline void iov_iter_ubuf(struct iov_iter *i, unsigned int direction, *i = (struct iov_iter) { .iter_type = ITER_UBUF, .copy_mc = false, - .user_backed = true, .data_source = direction, .ubuf = buf, .count = count, diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 27234a820eeb..227c9f536b94 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -290,7 +290,6 @@ void iov_iter_init(struct iov_iter *i, unsigned int direction, .iter_type = ITER_IOVEC, .copy_mc = false, .nofault = false, - .user_backed = true, .data_source = direction, .__iov = iov, .nr_segs = nr_segs, From patchwork Fri Sep 22 12:02:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395705 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5392BCD4F5B for ; Fri, 22 Sep 2023 12:03:05 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 622146B02CE; Fri, 22 Sep 2023 08:02:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D3546B02CD; Fri, 22 Sep 2023 08:02:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D9156B02D0; Fri, 22 Sep 2023 08:02:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 142D46B02CE for ; Fri, 22 Sep 2023 08:02:55 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E3645B385E for ; Fri, 22 Sep 2023 12:02:54 +0000 (UTC) X-FDA: 81264097068.09.DCC5C6C Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf06.hostedemail.com (Postfix) with ESMTP id D63A4180043 for ; Fri, 22 Sep 2023 12:02:52 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=e5xQtKa7; spf=pass (imf06.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695384173; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=saXGiomC5bnv9RAKI0XpVlyY0MbcRBlM5OC3bKVXk+c=; b=60baE6DqZOc98iQmJZ38smAqo7DjKMlSM3ooIZyMD9APpF1gGaFk1jY9MUeS8hubBmolWv eoGn4K+OOWjrAehD36x865gxmqLD0jm2b8hy2jF+W/FTYkt4pZa1SAPHC9YDW+Q9DXzYqL Mb/Jl6+1/YSMxpDWian7pTpjOIE5zBw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695384173; a=rsa-sha256; cv=none; b=3N0WGWNcXhy/u5UsJHu5INqm4efDVUoWcnndKGQ5A1tZrPDnET26dACyPWHjGNgs2qRQH3 mJJ3J303DRFtaW9jTnGeAAPbDmxK0LE0kvoP97vG8uaZnrDjGc2s9S8NAlTN95q523IKLK wc8+gJEQI4BGGhI2vmveQz5RZbDPlhs= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=e5xQtKa7; spf=pass (imf06.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695384172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=saXGiomC5bnv9RAKI0XpVlyY0MbcRBlM5OC3bKVXk+c=; b=e5xQtKa732RvZTTbMvfWJoKC3uIPR0xFThgd55oAKHZsg+v/o9xWS8YBr3mMfhpz/Ppd3m /JQoza7gH6cly4ohAn0AzbCF4PR9b5hCNsrVeNY7f6hsUxe2YatNZSshC/iGjmdkE5UWy2 FqM7nKXjEtP4Td4HTvPCBvLsfGFLqGw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-605-Uzf8Tf3PNy2PcdE_MgiMuQ-1; Fri, 22 Sep 2023 08:02:50 -0400 X-MC-Unique: Uzf8Tf3PNy2PcdE_MgiMuQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 01A67101AA6F; Fri, 22 Sep 2023 12:02:50 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1F763492C37; Fri, 22 Sep 2023 12:02:48 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 07/13] iov_iter: Convert iterate*() to inline funcs Date: Fri, 22 Sep 2023 13:02:21 +0100 Message-ID: <20230922120227.1173720-8-dhowells@redhat.com> In-Reply-To: <20230922120227.1173720-1-dhowells@redhat.com> References: <20230922120227.1173720-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Rspamd-Queue-Id: D63A4180043 X-Rspam-User: X-Stat-Signature: 6cq85qucwtda5jgtrpdr5s96fiydfwdm X-Rspamd-Server: rspam03 X-HE-Tag: 1695384172-61459 X-HE-Meta: U2FsdGVkX19cZm2W2t07t0Df43MQDpEtSokd17PSlluK+EYg6NQvFGD2N3/x5xDDcXaSuPVnSyZM4JaWfyUiZC5sSHvxMhUuM58Kcf1tV/Tbe3ltZ+o/sMnsRR7oZN6+tpiw8c8BBUtEz7iTZpaQB/+Z9DyT4fCxlixRYRdrvBVQtZgMPwmYUbszI09u0eIhtAToht/uA5JdhksadR1UXBxB57aKRpOTF4j6ZByJu7cLdo17rwVvHdOskqW+A3mp3IBsvP/E34a6lc28EN2TnqYWDcZpaAsyw8HFYzsxoWLwgs4B8nBdQURBdtYpZ9RBk/ZmoRv4zuyaoLQDLw3NrqXLlEDWOh9ttNTe0ZY2qrFaZd8S7TTbtzASGIusS63gj27mzuUZI5wdkwkmI30jyqjbkf6KSlMErUvqNfGFSYIbcs/Cu3DiMatF3TG/VGvQPqHJDed2861mtcCFvjIsf+MTUSZgsBXC0O0MV5eLWvPQkIEqffX9YkB2WX0/hpteUxntwi9YdtDBjtU7+Z38m7XZejXYpeqnrtNpQlMiZ6SVawcYialOohqTyXn+peyos8f5/rTw/O4L/jQfD/Bnie/xRsFp23fUiBiFWmWczIkWz5pYMSffk4AfD4Il4dP1XkoDNrRfKeLVUBtRPvSvDsppwZvr/+9Du6fEktQjOoQeAWKc8ygN6kDkprqDHRRWisaYHqIEVbiYxCF+1xR9gQRIsh1tfMkjxdu2zZ9hfNThtFai/k2J6jm8SOdjbOp1hmF0+C/EkbEpDakc36rIa1WEefhCQReen/jx7Kea8ct6NLAmNJfSPyMpf1VLPdnFuadb0kCnCsi545vRDK6iX0jNKEn2osd+999U4VoZsQBU/Od/HOYb2FL/waG/5SPXtDeMAW2b13AU4HwwDEv7F2Ng1W6WTFII0eSo18iv2ngWLJZUbI5+3qpFCiHVWyuhOXcdanheX24vCbLzUhd AgGh080O hE7vZ4xGcSu2GaV3Gfp5vyO6g89jeO588wY18zfuIMIuJrfdVYfaoVNsnPOkm4afB19vI9E0C2Dy58A5S9qATlFCWkDkRCmrtUrR7Nre0Loj629UnRT6/LZAxVdxyDdOax9wLte3zMTT249nXCYeGpKlJxexl8K24XdMW3qdb4tboWuq5asfmQgszjydsYZXORyoSFJW6XqSaABKXrz+naHLF6AteU7HH0hWk2C0GFcbiCpa63gseTPgoKaEX8ZjETcUYTdOoaG/0xpXL4km9evrX8XecyrcpP8Gy4YITphAtmudN411veYHScuY2l3MjEy8wFcbkc/03CtcNnvpajde2FWdrautuoVnN4tvtVRrisonjQyraOg30KR+s5GIJbkjdlygpv2x4BLkLGNQnYF7Ukbt5gfXuwM81GRY9oKqj4/K3DEqllO99ASG4+EhWq2V/sKRZg0su7WbL6Hn+hgac/Lz5Nc5oX+LcrVcjkqQwZN3LZNRAPyS+R6L+E/zca0eey04Xlw7fIi5NDjVT57wDdS1MeafQdPj1E0+NtyEKKuPzOOZNW3JtlMQlv0v4aQbHjTiNBmoP20K9D9lRyHjl6VbLxjmnz69iZBk9nNFkKv4X/C7yuETR7VSVFnWwCh16blkT4TaohzZZK4XHJLD6lrEsW6NZzQzB X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Convert the iov_iter iteration macros to inline functions to make the code easier to follow. The functions are marked __always_inline as we don't want to end up with indirect calls in the code. This, however, leaves dealing with ->copy_mc in an awkard situation since the step function (memcpy_from_iter_mc()) needs to test the flag in the iterator, but isn't passed the iterator. This will be dealt with in a follow-up patch. The variable names in the per-type iterator functions have been harmonised as much as possible and made clearer as to the variable purpose. The iterator functions are also moved to a header file so that other operations that need to scan over an iterator can be added. For instance, the rbd driver could use this to scan a buffer to see if it is all zeros and libceph could use this to generate a crc. Signed-off-by: David Howells cc: Alexander Viro cc: Jens Axboe cc: Christoph Hellwig cc: Christian Brauner cc: Matthew Wilcox cc: Linus Torvalds cc: David Laight cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org Link: https://lore.kernel.org/r/3710261.1691764329@warthog.procyon.org.uk/ # v1 Link: https://lore.kernel.org/r/855.1692047347@warthog.procyon.org.uk/ # v2 Link: https://lore.kernel.org/r/20230816120741.534415-1-dhowells@redhat.com/ # v3 --- Notes: Changes ======= ver #5) - Merge in patch to move iteration framework to a header file. - Move "iter->count - progress" into individual iteration subfunctions. include/linux/iov_iter.h | 274 ++++++++++++++++++++++++++ lib/iov_iter.c | 416 ++++++++++++++++----------------------- 2 files changed, 449 insertions(+), 241 deletions(-) create mode 100644 include/linux/iov_iter.h diff --git a/include/linux/iov_iter.h b/include/linux/iov_iter.h new file mode 100644 index 000000000000..270454a6703d --- /dev/null +++ b/include/linux/iov_iter.h @@ -0,0 +1,274 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* I/O iterator iteration building functions. + * + * Copyright (C) 2023 Red Hat, Inc. All Rights Reserved. + * Written by David Howells (dhowells@redhat.com) + */ + +#ifndef _LINUX_IOV_ITER_H +#define _LINUX_IOV_ITER_H + +#include +#include + +typedef size_t (*iov_step_f)(void *iter_base, size_t progress, size_t len, + void *priv, void *priv2); +typedef size_t (*iov_ustep_f)(void __user *iter_base, size_t progress, size_t len, + void *priv, void *priv2); + +/* + * Handle ITER_UBUF. + */ +static __always_inline +size_t iterate_ubuf(struct iov_iter *iter, size_t len, void *priv, void *priv2, + iov_ustep_f step) +{ + void __user *base = iter->ubuf; + size_t progress = 0, remain; + + remain = step(base + iter->iov_offset, 0, len, priv, priv2); + progress = len - remain; + iter->iov_offset += progress; + iter->count -= progress; + return progress; +} + +/* + * Handle ITER_IOVEC. + */ +static __always_inline +size_t iterate_iovec(struct iov_iter *iter, size_t len, void *priv, void *priv2, + iov_ustep_f step) +{ + const struct iovec *p = iter->__iov; + size_t progress = 0, skip = iter->iov_offset; + + do { + size_t remain, consumed; + size_t part = min(len, p->iov_len - skip); + + if (likely(part)) { + remain = step(p->iov_base + skip, progress, part, priv, priv2); + consumed = part - remain; + progress += consumed; + skip += consumed; + len -= consumed; + if (skip < p->iov_len) + break; + } + p++; + skip = 0; + } while (len); + + iter->nr_segs -= p - iter->__iov; + iter->__iov = p; + iter->iov_offset = skip; + iter->count -= progress; + return progress; +} + +/* + * Handle ITER_KVEC. + */ +static __always_inline +size_t iterate_kvec(struct iov_iter *iter, size_t len, void *priv, void *priv2, + iov_step_f step) +{ + const struct kvec *p = iter->kvec; + size_t progress = 0, skip = iter->iov_offset; + + do { + size_t remain, consumed; + size_t part = min(len, p->iov_len - skip); + + if (likely(part)) { + remain = step(p->iov_base + skip, progress, part, priv, priv2); + consumed = part - remain; + progress += consumed; + skip += consumed; + len -= consumed; + if (skip < p->iov_len) + break; + } + p++; + skip = 0; + } while (len); + + iter->nr_segs -= p - iter->kvec; + iter->kvec = p; + iter->iov_offset = skip; + iter->count -= progress; + return progress; +} + +/* + * Handle ITER_BVEC. + */ +static __always_inline +size_t iterate_bvec(struct iov_iter *iter, size_t len, void *priv, void *priv2, + iov_step_f step) +{ + const struct bio_vec *p = iter->bvec; + size_t progress = 0, skip = iter->iov_offset; + + do { + size_t remain, consumed; + size_t offset = p->bv_offset + skip, part; + void *kaddr = kmap_local_page(p->bv_page + offset / PAGE_SIZE); + + part = min3(len, + (size_t)(p->bv_len - skip), + (size_t)(PAGE_SIZE - offset % PAGE_SIZE)); + remain = step(kaddr + offset % PAGE_SIZE, progress, part, priv, priv2); + kunmap_local(kaddr); + consumed = part - remain; + len -= consumed; + progress += consumed; + skip += consumed; + if (skip >= p->bv_len) { + skip = 0; + p++; + } + if (remain) + break; + } while (len); + + iter->nr_segs -= p - iter->bvec; + iter->bvec = p; + iter->iov_offset = skip; + iter->count -= progress; + return progress; +} + +/* + * Handle ITER_XARRAY. + */ +static __always_inline +size_t iterate_xarray(struct iov_iter *iter, size_t len, void *priv, void *priv2, + iov_step_f step) +{ + struct folio *folio; + size_t progress = 0; + loff_t start = iter->xarray_start + iter->iov_offset; + pgoff_t index = start / PAGE_SIZE; + XA_STATE(xas, iter->xarray, index); + + rcu_read_lock(); + xas_for_each(&xas, folio, ULONG_MAX) { + size_t remain, consumed, offset, part, flen; + + if (xas_retry(&xas, folio)) + continue; + if (WARN_ON(xa_is_value(folio))) + break; + if (WARN_ON(folio_test_hugetlb(folio))) + break; + + offset = offset_in_folio(folio, start + progress); + flen = min(folio_size(folio) - offset, len); + + while (flen) { + void *base = kmap_local_folio(folio, offset); + + part = min_t(size_t, flen, + PAGE_SIZE - offset_in_page(offset)); + remain = step(base, progress, part, priv, priv2); + kunmap_local(base); + + consumed = part - remain; + progress += consumed; + len -= consumed; + + if (remain || len == 0) + goto out; + flen -= consumed; + offset += consumed; + } + } + +out: + rcu_read_unlock(); + iter->iov_offset += progress; + iter->count -= progress; + return progress; +} + +/* + * Handle ITER_DISCARD. + */ +static __always_inline +size_t iterate_discard(struct iov_iter *iter, size_t len, void *priv, void *priv2, + iov_step_f step) +{ + size_t progress = len; + + iter->count -= progress; + return progress; +} + +/** + * iterate_and_advance2 - Iterate over an iterator + * @iter: The iterator to iterate over. + * @len: The amount to iterate over. + * @priv: Data for the step functions. + * @priv2: More data for the step functions. + * @ustep: Function for UBUF/IOVEC iterators; given __user addresses. + * @step: Function for other iterators; given kernel addresses. + * + * Iterate over the next part of an iterator, up to the specified length. The + * buffer is presented in segments, which for kernel iteration are broken up by + * physical pages and mapped, with the mapped address being presented. + * + * Two step functions, @step and @ustep, must be provided, one for handling + * mapped kernel addresses and the other is given user addresses which have the + * potential to fault since no pinning is performed. + * + * The step functions are passed the address and length of the segment, @priv, + * @priv2 and the amount of data so far iterated over (which can, for example, + * be added to @priv to point to the right part of a second buffer). The step + * functions should return the amount of the segment they didn't process (ie. 0 + * indicates complete processsing). + * + * This function returns the amount of data processed (ie. 0 means nothing was + * processed and the value of @len means processes to completion). + */ +static __always_inline +size_t iterate_and_advance2(struct iov_iter *iter, size_t len, void *priv, + void *priv2, iov_ustep_f ustep, iov_step_f step) +{ + if (unlikely(iter->count < len)) + len = iter->count; + if (unlikely(!len)) + return 0; + + if (likely(iter_is_ubuf(iter))) + return iterate_ubuf(iter, len, priv, priv2, ustep); + if (likely(iter_is_iovec(iter))) + return iterate_iovec(iter, len, priv, priv2, ustep); + if (iov_iter_is_bvec(iter)) + return iterate_bvec(iter, len, priv, priv2, step); + if (iov_iter_is_kvec(iter)) + return iterate_kvec(iter, len, priv, priv2, step); + if (iov_iter_is_xarray(iter)) + return iterate_xarray(iter, len, priv, priv2, step); + return iterate_discard(iter, len, priv, priv2, step); +} + +/** + * iterate_and_advance - Iterate over an iterator + * @iter: The iterator to iterate over. + * @len: The amount to iterate over. + * @priv: Data for the step functions. + * @ustep: Function for UBUF/IOVEC iterators; given __user addresses. + * @step: Function for other iterators; given kernel addresses. + * + * As iterate_and_advance2(), but priv2 is always NULL. + */ +static __always_inline +size_t iterate_and_advance(struct iov_iter *iter, size_t len, void *priv, + iov_ustep_f ustep, iov_step_f step) +{ + return iterate_and_advance2(iter, len, priv, NULL, ustep, step); +} + +#endif /* _LINUX_IOV_ITER_H */ diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 227c9f536b94..65374ee91ecd 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -13,189 +13,69 @@ #include #include #include +#include -/* covers ubuf and kbuf alike */ -#define iterate_buf(i, n, base, len, off, __p, STEP) { \ - size_t __maybe_unused off = 0; \ - len = n; \ - base = __p + i->iov_offset; \ - len -= (STEP); \ - i->iov_offset += len; \ - n = len; \ -} - -/* covers iovec and kvec alike */ -#define iterate_iovec(i, n, base, len, off, __p, STEP) { \ - size_t off = 0; \ - size_t skip = i->iov_offset; \ - do { \ - len = min(n, __p->iov_len - skip); \ - if (likely(len)) { \ - base = __p->iov_base + skip; \ - len -= (STEP); \ - off += len; \ - skip += len; \ - n -= len; \ - if (skip < __p->iov_len) \ - break; \ - } \ - __p++; \ - skip = 0; \ - } while (n); \ - i->iov_offset = skip; \ - n = off; \ -} - -#define iterate_bvec(i, n, base, len, off, p, STEP) { \ - size_t off = 0; \ - unsigned skip = i->iov_offset; \ - while (n) { \ - unsigned offset = p->bv_offset + skip; \ - unsigned left; \ - void *kaddr = kmap_local_page(p->bv_page + \ - offset / PAGE_SIZE); \ - base = kaddr + offset % PAGE_SIZE; \ - len = min(min(n, (size_t)(p->bv_len - skip)), \ - (size_t)(PAGE_SIZE - offset % PAGE_SIZE)); \ - left = (STEP); \ - kunmap_local(kaddr); \ - len -= left; \ - off += len; \ - skip += len; \ - if (skip == p->bv_len) { \ - skip = 0; \ - p++; \ - } \ - n -= len; \ - if (left) \ - break; \ - } \ - i->iov_offset = skip; \ - n = off; \ -} - -#define iterate_xarray(i, n, base, len, __off, STEP) { \ - __label__ __out; \ - size_t __off = 0; \ - struct folio *folio; \ - loff_t start = i->xarray_start + i->iov_offset; \ - pgoff_t index = start / PAGE_SIZE; \ - XA_STATE(xas, i->xarray, index); \ - \ - len = PAGE_SIZE - offset_in_page(start); \ - rcu_read_lock(); \ - xas_for_each(&xas, folio, ULONG_MAX) { \ - unsigned left; \ - size_t offset; \ - if (xas_retry(&xas, folio)) \ - continue; \ - if (WARN_ON(xa_is_value(folio))) \ - break; \ - if (WARN_ON(folio_test_hugetlb(folio))) \ - break; \ - offset = offset_in_folio(folio, start + __off); \ - while (offset < folio_size(folio)) { \ - base = kmap_local_folio(folio, offset); \ - len = min(n, len); \ - left = (STEP); \ - kunmap_local(base); \ - len -= left; \ - __off += len; \ - n -= len; \ - if (left || n == 0) \ - goto __out; \ - offset += len; \ - len = PAGE_SIZE; \ - } \ - } \ -__out: \ - rcu_read_unlock(); \ - i->iov_offset += __off; \ - n = __off; \ -} - -#define __iterate_and_advance(i, n, base, len, off, I, K) { \ - if (unlikely(i->count < n)) \ - n = i->count; \ - if (likely(n)) { \ - if (likely(iter_is_ubuf(i))) { \ - void __user *base; \ - size_t len; \ - iterate_buf(i, n, base, len, off, \ - i->ubuf, (I)) \ - } else if (likely(iter_is_iovec(i))) { \ - const struct iovec *iov = iter_iov(i); \ - void __user *base; \ - size_t len; \ - iterate_iovec(i, n, base, len, off, \ - iov, (I)) \ - i->nr_segs -= iov - iter_iov(i); \ - i->__iov = iov; \ - } else if (iov_iter_is_bvec(i)) { \ - const struct bio_vec *bvec = i->bvec; \ - void *base; \ - size_t len; \ - iterate_bvec(i, n, base, len, off, \ - bvec, (K)) \ - i->nr_segs -= bvec - i->bvec; \ - i->bvec = bvec; \ - } else if (iov_iter_is_kvec(i)) { \ - const struct kvec *kvec = i->kvec; \ - void *base; \ - size_t len; \ - iterate_iovec(i, n, base, len, off, \ - kvec, (K)) \ - i->nr_segs -= kvec - i->kvec; \ - i->kvec = kvec; \ - } else if (iov_iter_is_xarray(i)) { \ - void *base; \ - size_t len; \ - iterate_xarray(i, n, base, len, off, \ - (K)) \ - } \ - i->count -= n; \ - } \ -} -#define iterate_and_advance(i, n, base, len, off, I, K) \ - __iterate_and_advance(i, n, base, len, off, I, ((void)(K),0)) - -static int copyout(void __user *to, const void *from, size_t n) +static __always_inline +size_t copy_to_user_iter(void __user *iter_to, size_t progress, + size_t len, void *from, void *priv2) { if (should_fail_usercopy()) - return n; - if (access_ok(to, n)) { - instrument_copy_to_user(to, from, n); - n = raw_copy_to_user(to, from, n); + return len; + if (access_ok(iter_to, len)) { + from += progress; + instrument_copy_to_user(iter_to, from, len); + len = raw_copy_to_user(iter_to, from, len); } - return n; + return len; } -static int copyout_nofault(void __user *to, const void *from, size_t n) +static __always_inline +size_t copy_to_user_iter_nofault(void __user *iter_to, size_t progress, + size_t len, void *from, void *priv2) { - long res; + ssize_t res; if (should_fail_usercopy()) - return n; - - res = copy_to_user_nofault(to, from, n); + return len; - return res < 0 ? n : res; + from += progress; + res = copy_to_user_nofault(iter_to, from, len); + return res < 0 ? len : res; } -static int copyin(void *to, const void __user *from, size_t n) +static __always_inline +size_t copy_from_user_iter(void __user *iter_from, size_t progress, + size_t len, void *to, void *priv2) { - size_t res = n; + size_t res = len; if (should_fail_usercopy()) - return n; - if (access_ok(from, n)) { - instrument_copy_from_user_before(to, from, n); - res = raw_copy_from_user(to, from, n); - instrument_copy_from_user_after(to, from, n, res); + return len; + if (access_ok(iter_from, len)) { + to += progress; + instrument_copy_from_user_before(to, iter_from, len); + res = raw_copy_from_user(to, iter_from, len); + instrument_copy_from_user_after(to, iter_from, len, res); } return res; } +static __always_inline +size_t memcpy_to_iter(void *iter_to, size_t progress, + size_t len, void *from, void *priv2) +{ + memcpy(iter_to, from + progress, len); + return 0; +} + +static __always_inline +size_t memcpy_from_iter(void *iter_from, size_t progress, + size_t len, void *to, void *priv2) +{ + memcpy(to + progress, iter_from, len); + return 0; +} + /* * fault_in_iov_iter_readable - fault in iov iterator for reading * @i: iterator @@ -312,23 +192,29 @@ size_t _copy_to_iter(const void *addr, size_t bytes, struct iov_iter *i) return 0; if (user_backed_iter(i)) might_fault(); - iterate_and_advance(i, bytes, base, len, off, - copyout(base, addr + off, len), - memcpy(base, addr + off, len) - ) - - return bytes; + return iterate_and_advance(i, bytes, (void *)addr, + copy_to_user_iter, memcpy_to_iter); } EXPORT_SYMBOL(_copy_to_iter); #ifdef CONFIG_ARCH_HAS_COPY_MC -static int copyout_mc(void __user *to, const void *from, size_t n) -{ - if (access_ok(to, n)) { - instrument_copy_to_user(to, from, n); - n = copy_mc_to_user((__force void *) to, from, n); +static __always_inline +size_t copy_to_user_iter_mc(void __user *iter_to, size_t progress, + size_t len, void *from, void *priv2) +{ + if (access_ok(iter_to, len)) { + from += progress; + instrument_copy_to_user(iter_to, from, len); + len = copy_mc_to_user(iter_to, from, len); } - return n; + return len; +} + +static __always_inline +size_t memcpy_to_iter_mc(void *iter_to, size_t progress, + size_t len, void *from, void *priv2) +{ + return copy_mc_to_kernel(iter_to, from + progress, len); } /** @@ -361,22 +247,20 @@ size_t _copy_mc_to_iter(const void *addr, size_t bytes, struct iov_iter *i) return 0; if (user_backed_iter(i)) might_fault(); - __iterate_and_advance(i, bytes, base, len, off, - copyout_mc(base, addr + off, len), - copy_mc_to_kernel(base, addr + off, len) - ) - - return bytes; + return iterate_and_advance(i, bytes, (void *)addr, + copy_to_user_iter_mc, memcpy_to_iter_mc); } EXPORT_SYMBOL_GPL(_copy_mc_to_iter); #endif /* CONFIG_ARCH_HAS_COPY_MC */ -static void *memcpy_from_iter(struct iov_iter *i, void *to, const void *from, - size_t size) +static size_t memcpy_from_iter_mc(void *iter_from, size_t progress, + size_t len, void *to, void *priv2) { - if (iov_iter_is_copy_mc(i)) - return (void *)copy_mc_to_kernel(to, from, size); - return memcpy(to, from, size); + struct iov_iter *iter = priv2; + + if (iov_iter_is_copy_mc(iter)) + return copy_mc_to_kernel(to + progress, iter_from, len); + return memcpy_from_iter(iter_from, progress, len, to, priv2); } size_t _copy_from_iter(void *addr, size_t bytes, struct iov_iter *i) @@ -386,30 +270,46 @@ size_t _copy_from_iter(void *addr, size_t bytes, struct iov_iter *i) if (user_backed_iter(i)) might_fault(); - iterate_and_advance(i, bytes, base, len, off, - copyin(addr + off, base, len), - memcpy_from_iter(i, addr + off, base, len) - ) - - return bytes; + return iterate_and_advance2(i, bytes, addr, i, + copy_from_user_iter, + memcpy_from_iter_mc); } EXPORT_SYMBOL(_copy_from_iter); +static __always_inline +size_t copy_from_user_iter_nocache(void __user *iter_from, size_t progress, + size_t len, void *to, void *priv2) +{ + return __copy_from_user_inatomic_nocache(to + progress, iter_from, len); +} + size_t _copy_from_iter_nocache(void *addr, size_t bytes, struct iov_iter *i) { if (WARN_ON_ONCE(!i->data_source)) return 0; - iterate_and_advance(i, bytes, base, len, off, - __copy_from_user_inatomic_nocache(addr + off, base, len), - memcpy(addr + off, base, len) - ) - - return bytes; + return iterate_and_advance(i, bytes, addr, + copy_from_user_iter_nocache, + memcpy_from_iter); } EXPORT_SYMBOL(_copy_from_iter_nocache); #ifdef CONFIG_ARCH_HAS_UACCESS_FLUSHCACHE +static __always_inline +size_t copy_from_user_iter_flushcache(void __user *iter_from, size_t progress, + size_t len, void *to, void *priv2) +{ + return __copy_from_user_flushcache(to + progress, iter_from, len); +} + +static __always_inline +size_t memcpy_from_iter_flushcache(void *iter_from, size_t progress, + size_t len, void *to, void *priv2) +{ + memcpy_flushcache(to + progress, iter_from, len); + return 0; +} + /** * _copy_from_iter_flushcache - write destination through cpu cache * @addr: destination kernel address @@ -431,12 +331,9 @@ size_t _copy_from_iter_flushcache(void *addr, size_t bytes, struct iov_iter *i) if (WARN_ON_ONCE(!i->data_source)) return 0; - iterate_and_advance(i, bytes, base, len, off, - __copy_from_user_flushcache(addr + off, base, len), - memcpy_flushcache(addr + off, base, len) - ) - - return bytes; + return iterate_and_advance(i, bytes, addr, + copy_from_user_iter_flushcache, + memcpy_from_iter_flushcache); } EXPORT_SYMBOL_GPL(_copy_from_iter_flushcache); #endif @@ -508,10 +405,9 @@ size_t copy_page_to_iter_nofault(struct page *page, unsigned offset, size_t byte void *kaddr = kmap_local_page(page); size_t n = min(bytes, (size_t)PAGE_SIZE - offset); - iterate_and_advance(i, n, base, len, off, - copyout_nofault(base, kaddr + offset + off, len), - memcpy(base, kaddr + offset + off, len) - ) + n = iterate_and_advance(i, bytes, kaddr, + copy_to_user_iter_nofault, + memcpy_to_iter); kunmap_local(kaddr); res += n; bytes -= n; @@ -554,14 +450,25 @@ size_t copy_page_from_iter(struct page *page, size_t offset, size_t bytes, } EXPORT_SYMBOL(copy_page_from_iter); -size_t iov_iter_zero(size_t bytes, struct iov_iter *i) +static __always_inline +size_t zero_to_user_iter(void __user *iter_to, size_t progress, + size_t len, void *priv, void *priv2) { - iterate_and_advance(i, bytes, base, len, count, - clear_user(base, len), - memset(base, 0, len) - ) + return clear_user(iter_to, len); +} - return bytes; +static __always_inline +size_t zero_to_iter(void *iter_to, size_t progress, + size_t len, void *priv, void *priv2) +{ + memset(iter_to, 0, len); + return 0; +} + +size_t iov_iter_zero(size_t bytes, struct iov_iter *i) +{ + return iterate_and_advance(i, bytes, NULL, + zero_to_user_iter, zero_to_iter); } EXPORT_SYMBOL(iov_iter_zero); @@ -586,10 +493,9 @@ size_t copy_page_from_iter_atomic(struct page *page, size_t offset, } p = kmap_atomic(page) + offset; - iterate_and_advance(i, n, base, len, off, - copyin(p + off, base, len), - memcpy_from_iter(i, p + off, base, len) - ) + n = iterate_and_advance2(i, n, p, i, + copy_from_user_iter, + memcpy_from_iter_mc); kunmap_atomic(p); copied += n; offset += n; @@ -1180,32 +1086,64 @@ ssize_t iov_iter_get_pages_alloc2(struct iov_iter *i, } EXPORT_SYMBOL(iov_iter_get_pages_alloc2); +static __always_inline +size_t copy_from_user_iter_csum(void __user *iter_from, size_t progress, + size_t len, void *to, void *priv2) +{ + __wsum next, *csum = priv2; + + next = csum_and_copy_from_user(iter_from, to + progress, len); + *csum = csum_block_add(*csum, next, progress); + return next ? 0 : len; +} + +static __always_inline +size_t memcpy_from_iter_csum(void *iter_from, size_t progress, + size_t len, void *to, void *priv2) +{ + __wsum *csum = priv2; + + *csum = csum_and_memcpy(to + progress, iter_from, len, *csum, progress); + return 0; +} + size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i) { - __wsum sum, next; - sum = *csum; if (WARN_ON_ONCE(!i->data_source)) return 0; - - iterate_and_advance(i, bytes, base, len, off, ({ - next = csum_and_copy_from_user(base, addr + off, len); - sum = csum_block_add(sum, next, off); - next ? 0 : len; - }), ({ - sum = csum_and_memcpy(addr + off, base, len, sum, off); - }) - ) - *csum = sum; - return bytes; + return iterate_and_advance2(i, bytes, addr, csum, + copy_from_user_iter_csum, + memcpy_from_iter_csum); } EXPORT_SYMBOL(csum_and_copy_from_iter); +static __always_inline +size_t copy_to_user_iter_csum(void __user *iter_to, size_t progress, + size_t len, void *from, void *priv2) +{ + __wsum next, *csum = priv2; + + next = csum_and_copy_to_user(from + progress, iter_to, len); + *csum = csum_block_add(*csum, next, progress); + return next ? 0 : len; +} + +static __always_inline +size_t memcpy_to_iter_csum(void *iter_to, size_t progress, + size_t len, void *from, void *priv2) +{ + __wsum *csum = priv2; + + *csum = csum_and_memcpy(iter_to, from + progress, len, *csum, progress); + return 0; +} + size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *_csstate, struct iov_iter *i) { struct csum_state *csstate = _csstate; - __wsum sum, next; + __wsum sum; if (WARN_ON_ONCE(i->data_source)) return 0; @@ -1219,14 +1157,10 @@ size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *_csstate, } sum = csum_shift(csstate->csum, csstate->off); - iterate_and_advance(i, bytes, base, len, off, ({ - next = csum_and_copy_to_user(addr + off, base, len); - sum = csum_block_add(sum, next, off); - next ? 0 : len; - }), ({ - sum = csum_and_memcpy(base, addr + off, len, sum, off); - }) - ) + + bytes = iterate_and_advance2(i, bytes, (void *)addr, &sum, + copy_to_user_iter_csum, + memcpy_to_iter_csum); csstate->csum = csum_shift(sum, csstate->off); csstate->off += bytes; return bytes; From patchwork Fri Sep 22 12:02:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395706 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3ED1BC04AAB for ; Fri, 22 Sep 2023 12:03:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D0E26B02CD; Fri, 22 Sep 2023 08:02:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 730B26B02D0; Fri, 22 Sep 2023 08:02:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5F8DD6B02D1; Fri, 22 Sep 2023 08:02:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 47E7C6B02CD for ; Fri, 22 Sep 2023 08:02:58 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 180941CAC27 for ; Fri, 22 Sep 2023 12:02:58 +0000 (UTC) X-FDA: 81264097236.06.D6F4B77 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf28.hostedemail.com (Postfix) with ESMTP id 245F3C0010 for ; Fri, 22 Sep 2023 12:02:55 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=M7yuaAEg; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695384176; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gfSLwCbdFMwywMZPFTO5hx480mND9O9O9B3C6PwfVhs=; b=GvXs7wUI4UfP/wgad/f+cyJKycbgbQWk5c/bpDtbUad7sXhMiAzPVydEd8kEApIS7xTSWT mRp0ewIUEgA/ASvU45FzovNU4wu4Pz1TzoyRqVnNpya5k1E3ISHpd5IN9EiEow6tIDotrA U59H0w7RTsTJAeDwQX+l7wxrQ6QRunE= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=M7yuaAEg; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf28.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695384176; a=rsa-sha256; cv=none; b=1vpvj/pK0jBZCtI92R8NhhLXmJ21BeeTqCMwKUk+3O1ZsuasQFxfWtdqakLfvTPEH+hWk7 acm+LfQV+S+vdH+/P6kwnIUu/BA1FA8NiydQaCDgkg0L5ykQjpf3mg/+TTZAFviMKnUFF1 Zod1j8AW379NoaAwFO30AeHS2IUTZSw= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695384175; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gfSLwCbdFMwywMZPFTO5hx480mND9O9O9B3C6PwfVhs=; b=M7yuaAEgK3qs9gftqg8WBpT4KwPOSPwYyuojEW8l+JMt3yVRAMvdazx/1MZSMNaWvPNC98 JhHkUPH7+WCFieAydxUac4r8Q1nWy9W6wNG6Q8AuyvURkhNYo7Ptavr/kvN4TZ61hl4y16 I+c9MBnHvWREgvPmXfHwMcDre19WvIE= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-136-d7Mhfh32MBiW5Kow5NUZRQ-1; Fri, 22 Sep 2023 08:02:53 -0400 X-MC-Unique: d7Mhfh32MBiW5Kow5NUZRQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 533BA1C0172F; Fri, 22 Sep 2023 12:02:52 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id ADFF220268D6; Fri, 22 Sep 2023 12:02:50 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 08/13] iov_iter: Don't deal with iter->copy_mc in memcpy_from_iter_mc() Date: Fri, 22 Sep 2023 13:02:22 +0100 Message-ID: <20230922120227.1173720-9-dhowells@redhat.com> In-Reply-To: <20230922120227.1173720-1-dhowells@redhat.com> References: <20230922120227.1173720-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Queue-Id: 245F3C0010 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: nspiq5jb753fbs385r75j5ua1phrihwq X-HE-Tag: 1695384175-918973 X-HE-Meta: U2FsdGVkX18FLsgDU/IN/hCXIOzOrI2DwT+a8zfOofBfLeOWlWDLgVlB2RrFN1eReNYHE0JcoyskIiqJyPxLl3M5uFpzVXkj686ncFL2xmzuJ8qhAwgu1/qbYr8xPCbtw84OQvx52KqmmD0wrcdySx7G9MRnVCah5vL5A7rjuI1HgrhQh6mGBhL1Ya0zUvc+HlFY3qpEgA8BuEONNze4jmkCGIn98GzH4WDR2jIvlw374el6fHeY59S2wNaFid67ow6cBn/8IioIAHGQ+hBd9lXzYbUC+Eei3r4cVj0YcRtw8tITaScHK2eD3uMSjG8Pw8IoRjmZ5BVRzX+U0RmsDA+unxryq3cViLcParVggf8vmHUxEGzzVVVPlCxRb40BcgrnlWZyS5gs4IJtMSlazT8pzAPQaHMdgr9ocRIh4FDhQdVgNqN5dyjatIEuvUJH7OoGfUGZqTsJ8BHzmuyP2NKJ1GRR3x0UOj/9QFPS77Jbkhl6GaFBMB4awBMj5ihHyn7eGXUbajji/VEChztnc84dD3SyQspCGCloGx6JqpKFqx9Uq1TBu1PcqcwkdWkLKsp+D84ghJ4DSI29RtRHPfZUuvIjE9rhnOB68xl6spEp7s5E8KCJoiG+tv5VWhedhyp3u9AC3WqaIroQm6NVHlMGoaWS0wKaYO1/aF/YWRNUlt1UiYynh3i+yrFuejWvzbYKo3M7Lh7umwjzLpLIjkEIsQbAOGZFQMVntb6XrkWRZ0GQie7tDz6H0aQO2XIiQ5it57/KAnIlwo2SGoGFfC+mwE/UgDI0/2hLlMnyQFEQshV2RsWNYj+zji7YYY35fSWJCHx835/BVSG7KiA3wXWYScAK0FmwAlr5OnTQwS7zz0Yi39jeUUaVtXLvWmXqdE47We15j0QjiHAi3mLKFfGZt9tF5nW/AXmHfsn4f7+sPXSefRcxJMldhRoAPjTA4u8snUQwUMNkL7fFFdE +v0ySPOz mIEVrTU2C7pmlfK1IcTHTrdqWOpQ+1eYIPnpnkPxkrhn1iShaI2MezvJi8gkgR418vkl+ntEdrqoDQjHWi6HCC8fzTtfjkw4neauSMRDnyqqMsTfNoNGC98GmrSD1ju15hVelu4hgXQYkYFIgRdeJEtWZOPt2oZmKg/+78rnotukWdp37FYZW+NSmxXpkV1XFIexQ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: iter->copy_mc is only used with a bvec iterator and only by dump_emit_page() in fs/coredump.c so rather than handle this in memcpy_from_iter_mc() where it is checked repeatedly by _copy_from_iter() and copy_page_from_iter_atomic(), --- lib/iov_iter.c | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 65374ee91ecd..943aa3cfd7b3 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -253,14 +253,33 @@ size_t _copy_mc_to_iter(const void *addr, size_t bytes, struct iov_iter *i) EXPORT_SYMBOL_GPL(_copy_mc_to_iter); #endif /* CONFIG_ARCH_HAS_COPY_MC */ -static size_t memcpy_from_iter_mc(void *iter_from, size_t progress, - size_t len, void *to, void *priv2) +static __always_inline +size_t memcpy_from_iter_mc(void *iter_from, size_t progress, + size_t len, void *to, void *priv2) +{ + return copy_mc_to_kernel(to + progress, iter_from, len); +} + +static size_t __copy_from_iter_mc(void *addr, size_t bytes, struct iov_iter *i) { - struct iov_iter *iter = priv2; + size_t progress; - if (iov_iter_is_copy_mc(iter)) - return copy_mc_to_kernel(to + progress, iter_from, len); - return memcpy_from_iter(iter_from, progress, len, to, priv2); + if (unlikely(i->count < bytes)) + bytes = i->count; + if (unlikely(!bytes)) + return 0; + progress = iterate_bvec(i, bytes, addr, NULL, memcpy_from_iter_mc); + i->count -= progress; + return progress; +} + +static __always_inline +size_t __copy_from_iter(void *addr, size_t bytes, struct iov_iter *i) +{ + if (unlikely(iov_iter_is_copy_mc(i))) + return __copy_from_iter_mc(addr, bytes, i); + return iterate_and_advance(i, bytes, addr, + copy_from_user_iter, memcpy_from_iter); } size_t _copy_from_iter(void *addr, size_t bytes, struct iov_iter *i) @@ -270,9 +289,7 @@ size_t _copy_from_iter(void *addr, size_t bytes, struct iov_iter *i) if (user_backed_iter(i)) might_fault(); - return iterate_and_advance2(i, bytes, addr, i, - copy_from_user_iter, - memcpy_from_iter_mc); + return __copy_from_iter(addr, bytes, i); } EXPORT_SYMBOL(_copy_from_iter); @@ -493,9 +510,7 @@ size_t copy_page_from_iter_atomic(struct page *page, size_t offset, } p = kmap_atomic(page) + offset; - n = iterate_and_advance2(i, n, p, i, - copy_from_user_iter, - memcpy_from_iter_mc); + __copy_from_iter(p, n, i); kunmap_atomic(p); copied += n; offset += n; From patchwork Fri Sep 22 12:02:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395707 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1786BC04AAB for ; Fri, 22 Sep 2023 12:03:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id CD9CD6B02D2; Fri, 22 Sep 2023 08:03:02 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C89066B02D3; Fri, 22 Sep 2023 08:03:02 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B50226B02D4; Fri, 22 Sep 2023 08:03:02 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id A254B6B02D2 for ; Fri, 22 Sep 2023 08:03:02 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7C0AE1208FA for ; Fri, 22 Sep 2023 12:03:02 +0000 (UTC) X-FDA: 81264097404.13.E868035 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf21.hostedemail.com (Postfix) with ESMTP id BE14A1C003F for ; Fri, 22 Sep 2023 12:03:00 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ze64qI14; spf=pass (imf21.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695384180; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=hYOoT+N3+ZXg5kUOP5JOmaiFuOq7EbJgQKHzR3cvg3M=; b=n+QaYk8qhsBj0jd1R2IgZS0oySst0RxQ6sXjZoNGbjrafVdpPvRVXPbbsZiFriLWdA/aMj Bkx9BWirHT/xUJZbx/FzUZFS1I0wISPsGwYY7+0kKn5PHAHuCWEv7qyWxoVNhsYn9brWro d8ko2c1e7r2ULLHnrmvNT7O3G9pUPwc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695384180; a=rsa-sha256; cv=none; b=OsXXmcikzl9+sbOKMY7pUgTwQOSnhP9IQnZFoEw7gSFjKZJ6/2/dRChIQkdz1yMbIzirM6 E0TjCSnBqz+8b0v4KESJB/bIYfCUVcn0zJUWYETAZE+4jWkI+XXLirpyxID6ze6lvCYA4e Cw0IN7QvRUOFtP85d9p7R96uqR0dj5M= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ze64qI14; spf=pass (imf21.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695384180; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hYOoT+N3+ZXg5kUOP5JOmaiFuOq7EbJgQKHzR3cvg3M=; b=Ze64qI14DzFauZjffgCEL9ceUbC2jVZ4UCR2qkzRndrUDAOevJlV+WlbBotlXBY1SHd5sL FzufHUtDHN1V6X613UnEK4lZf0Q+tprSgkoKgvlXpzUxsmPAIuLwydwRjahi6rgO7C9nQ2 s6Q8gCy94m54x7nWUpLLbFnSWvF6Sn8= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-619-ZTcYAYuYMcqv6NQGNev8hg-1; Fri, 22 Sep 2023 08:02:55 -0400 X-MC-Unique: ZTcYAYuYMcqv6NQGNev8hg-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9DF423816C89; Fri, 22 Sep 2023 12:02:54 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFD0D711282; Fri, 22 Sep 2023 12:02:52 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 09/13] iov_iter: Add a kernel-type iterator-only iteration function Date: Fri, 22 Sep 2023 13:02:23 +0100 Message-ID: <20230922120227.1173720-10-dhowells@redhat.com> In-Reply-To: <20230922120227.1173720-1-dhowells@redhat.com> References: <20230922120227.1173720-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Stat-Signature: 3bxxnt7s6ggs57gjtj4e7pjzq3o1i7z7 X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: BE14A1C003F X-Rspam-User: X-HE-Tag: 1695384180-659036 X-HE-Meta: U2FsdGVkX1/HkTjK8SaYuKa1wVNDvQq6ZZrnRQhphoGCUaIQgSHS+C7863ycgpydTibVGkKJcg6SHJ3xqYSawBq9SSR05Dnn4bQWDpPO4/zIGBEoUDu/d6hq2d9mZtFmPdRM3/2rOeo0YhGlpdm2dpbs3iI6M8bnyf5Lk0qLnmvCKlIBstUqNwS3vgTC30kQoUe889gZ5/7cb6hqWIR4llc9J2Hnu+JSKcnrMh0hf54k5Sy1ceKky6Cm5byZPReadcKN1o4PC5agIj0eDjXXVzcnE+snopA+AEDbrENc7/NV53dCxMuLo/nwbzhAlfXiThZNeOWm+XcKSR/P9YzKdEdOCkWlFhzDXMIQZgFJfEgZZxbiZS1dXMYa+/gWcIlLbWcwyy8Ao/CUIqeYIV0Fld1kuEKvLefC1rC8BNkjFdNzLRUPhQfzdKdQtcTtLewH4nnchdc7FWPGD8iGKwXPniJGU3oMlMljMg8yXH+vJM4MLLLMGLEg83nGCdE0Yt5mC81J8TDLEdRviN2AtrJyFC07Pa+SQTmBlE+vgGTdh9R7MuqWs5hHhgodjmV15vOhBh3VozqveIJBvZEyYfo6kVs1Xjvp/pB8Unfk1DClHaI075TDjBbtW6PsRYtwOJy4mP2BdXZP7nNxvKmRfR+fdwMX5WWX+vqX+oZumLwVNkbPfg0M4iIKXyg/8brpkDWynHplGv3xAsdZNIDPVl6UQoh69GSF4HlKygpS1gwOmBXc6Qr8b53647eHnfeKgl6bpyDF6QV9qX9pUW2QMETq/+/1ef5dxvRhvAGkKJe7KbNdsykhcMRgmmw9fAkGed0eK85VR43YMpMlyDBHpmOwh3Nl1sOw11Uwor+cLpRhzSy31ASYvoDURP8bdxt8+Sk7NaUOxZYLt+VK1yJsTyYLCddbUAt+mSaa4tn4zbzarnLNkciZLUCtDE82XMBl4KndOHe3PEWLm71gD+t0s7h lKXEp45M b0kyflfeAXCMxcq40cuFCIp/aQMB8Z5WsJlJlf2Sm9k5BzSO0jPB7s/18WN2+YSZtjF/FeWTmlWoIloPRqTlUc5BOxpeWkNeGyvDjuOqhQwcH2HvAlv3G8x0KN0vliYlMcogUzz2FqXv+Yl24JGYUkq+Lh1FAK+TD8hZrGkOSz/zJdRHC5FsOsHvTHcbzMlcVr2QvFrXtS8qj/b1C98YdwfLjjK2z3fA0i6F4VWXoHZkzUiypUNkLfV7h3zCj/Ge3Oz/9P9yWGwztRMkwzqgBJffTRnpsv76lIYavqXBs7uUhSgPfB43c4to6tpupYsQC3ziPkdtmAlNHPnvrfsoY648x2lxomQEXbS0EarwV1mHCqUx1JRYWYX61c2o8sC9d/BZ2eLD8ghGWpbJIGyTObu2Kw+XmRbK/Zc5PdaCyvFHWeg8KceNOtxP/D9b2nINE2rs/yxtK6rclYH+8fHIAOoYNzgtFwL4c1+H+mvJuaCQR23L0uXvHxky8Nmmv93B1h/voO6wbNnXSenHMuAbhzMDfvB0SVQ9Al7ozlkpSBCS6i9VQgpU+I+Tb84+cHT/Pa6d6lUA57FJiBRg= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Add an iteration function that can only iterate over kernel internal-type iterators (ie. BVEC, KVEC, XARRAY) and not user-backed iterators (ie. UBUF and IOVEC). This allows for smaller iterators to be built when it is known the caller won't have a user-backed iterator. Signed-off-by: David Howells cc: Alexander Viro cc: Jens Axboe cc: Christoph Hellwig cc: Christian Brauner cc: Matthew Wilcox cc: Linus Torvalds cc: David Laight cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- Notes: Changes ======= ver #6) - Document the priv2 arg of iterate_and_advance_kernel(). include/linux/iov_iter.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/include/linux/iov_iter.h b/include/linux/iov_iter.h index 270454a6703d..d8733dc22b54 100644 --- a/include/linux/iov_iter.h +++ b/include/linux/iov_iter.h @@ -271,4 +271,36 @@ size_t iterate_and_advance(struct iov_iter *iter, size_t len, void *priv, return iterate_and_advance2(iter, len, priv, NULL, ustep, step); } +/** + * iterate_and_advance_kernel - Iterate over a kernel iterator + * @iter: The iterator to iterate over. + * @len: The amount to iterate over. + * @priv: Data for the step functions. + * @priv2: More data for the step functions. + * @step: Processing function; given kernel addresses. + * + * Like iterate_and_advance2(), but rejected UBUF and IOVEC iterators and does + * not take a user-step function. + */ +static __always_inline +size_t iterate_and_advance_kernel(struct iov_iter *iter, size_t len, void *priv, + void *priv2, iov_step_f step) +{ + if (unlikely(iter->count < len)) + len = iter->count; + if (unlikely(!len)) + return 0; + + if (iov_iter_is_bvec(iter)) + return iterate_bvec(iter, len, priv, priv2, step); + if (iov_iter_is_kvec(iter)) + return iterate_kvec(iter, len, priv, priv2, step); + if (iov_iter_is_xarray(iter)) + return iterate_xarray(iter, len, priv, priv2, step); + if (iov_iter_is_discard(iter)) + return iterate_discard(iter, len, priv, priv2, step); + WARN_ON_ONCE(1); + return 0; +} + #endif /* _LINUX_IOV_ITER_H */ From patchwork Fri Sep 22 12:02:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395708 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4783EC04AAB for ; Fri, 22 Sep 2023 12:03:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 49A676B02D3; Fri, 22 Sep 2023 08:03:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 44A0B6B02D4; Fri, 22 Sep 2023 08:03:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2C33B6B02D5; Fri, 22 Sep 2023 08:03:04 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 19A546B02D3 for ; Fri, 22 Sep 2023 08:03:04 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id D5D4B140A10 for ; Fri, 22 Sep 2023 12:03:03 +0000 (UTC) X-FDA: 81264097446.21.E91FCF7 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf22.hostedemail.com (Postfix) with ESMTP id D0702C001D for ; Fri, 22 Sep 2023 12:03:01 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=T+UkqY68; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695384181; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=wIy5c31/DaOl6Dg3RGFXufcZuyPPQA8lBpT8O0G10n8=; b=P6GgXTfeQ1bo7gMA/LH2P9ZyJJS9v+O57gvHdi5gh3SmCuJX+KF7Sa4x4ihKjXVkcGqs3m 4De4gqvN5Z43s6tl3HQykFWtCEENRQmi0Wj+mk+vF9T48cFu9E+7mVU4XKyNlL3Yx6ttyT Aer/mEMCUhK7BW4p3gxSgnX/q8qxrEo= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=T+UkqY68; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf22.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695384181; a=rsa-sha256; cv=none; b=1hHhLwFImRIwNEscs4UVtZE45Ggxy9U6X8nwbxTjUbi4hLHvonq5IvB0ErXCbKfMc1gOgc hT2SER+Erezu47hB/Ew9QgRYpr7fqTSeNCkgp5uQYVuQ5gK4InnHG4RTMuoss3q0/EcpSk FUTj9QpTvaF/JA2ilJHX6bdBban6Inc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695384181; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=wIy5c31/DaOl6Dg3RGFXufcZuyPPQA8lBpT8O0G10n8=; b=T+UkqY68TcJsjpbADevjzGX9epdOQhDdDKaU6rlSe7EUsC8qKAGjz4moec4POPiCj+5m20 HEkqMo5yCxVx7r7mmkbO2sGnw9wE5NBmz1F3j2YEG3qWUOIG9VIl5Sjkujc0Ext5iR2ct+ OyHDJPeCuv4lWFk8FqKU0NjMZsJ3hJw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-440-pc8cXPA_OZOHFZz0kV5OcQ-1; Fri, 22 Sep 2023 08:02:57 -0400 X-MC-Unique: pc8cXPA_OZOHFZz0kV5OcQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id EA1881814507; Fri, 22 Sep 2023 12:02:56 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4799F40C6EBF; Fri, 22 Sep 2023 12:02:55 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v6 10/13] iov_iter, net: Move csum_and_copy_to/from_iter() to net/ Date: Fri, 22 Sep 2023 13:02:24 +0100 Message-ID: <20230922120227.1173720-11-dhowells@redhat.com> In-Reply-To: <20230922120227.1173720-1-dhowells@redhat.com> References: <20230922120227.1173720-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Queue-Id: D0702C001D X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: tzyf33tijotfbutdho7qy6rju7dq1g64 X-HE-Tag: 1695384181-977752 X-HE-Meta: U2FsdGVkX191OnIBIi9E5nbJLW/JyQeH0MuxvD8kCeKp4wACR6EuHkhRPbG5P5JWQv5ongtFTbVO+ZFVSU3adGA/XYPZ7bIZYvEOtqDHfa2uBrxnL0cxtq7lc6+FtuXhHBsnMvPggguBJCJ7ZQo1V2rVbyk1SjpA8NmpurNLOlnt7Bi0RQ6S8wAFlF2sZC5ckQSrYXQME/Ud/KtsLmWy5PDBREEWiq+pbGqKJtEXiGawHOUDBTI7xLjN+OwQt3Z7Hn5esOu0Rbzl7THwCkXpHqchqG/suESh38oG2PqgKP8uJd5Oj4yfVZHkBEd3YErR6wQEgeBlmkOqBlEiSCQtIfImNOJd5dlGwPZCR3D1axkmG9WkGrIO3gMpavMxGhfmCCZInZrDYK98hr1KxKq2+4GG2oPv9vZPhZwJLHAKd7udjibOJjCusOnKDwuPbowxw8p+SuaTwKCdI5eLwep/WHfYvHow9hZKFZNUBhLOfHi7grxk9S95gcse4H3nplcugxiTf3svvFVqsYD+zUtovAaYY8e3szwnrwdKvtTFoXuAkIEG9vsPd+OV9s+9XUJavW+8U+lQT3ZFn4QDglLYFuzov6KasWx7oDhDnjscDj+f6hE6YLDAdcRhpIb40frBoawpRJXuT3fXbyQURJa4bSVMJvVJy7dhqV5YxAe9Gtz3/0RQQCqdq1bECljU27pjRjE1hexvsSY9/rBZ+aDtmENDT7qW+7xVwlISV57pZVDbsMSXUSUNYBQVguAyUhZRNLvSpFW9hbCSfgnhWQJQ5wMixpRghm17iKAred9ItvCQn0PezOqZzWwgdhBCDszaDkUVSTgaw8hkOVXUW2JjWZu05esIHknJVXGQGCOfyLYFHyD5B22ysmqZq/mVwOVnLqpHWY9UrRbxUMA8qjo+C5nip9fKzmtLBC0q0Q367iJZHcnAu60j+kccwkAfVL5SHbmtV/UM8WuCP1uZ+2t 7rF8DAPP 7y9TucygsMz8G5/VOIFlfTxL0kuUZUQUCcc/2HjgKvc3kBdTq32jICTpvMz1GAsHv/6N7JCkZk09f8OlNi5YxAUkAsRSuo4L1XL8I9ebIIqWIx1LDPb3fus32Wr+H1VkMUFPZB+cBf7Z6ccLs4oQwV0TKXxBqRmafRbSOdgNQAt8dSOoZQas0SxhC75vc3QMnJeAniwrevkNGVjfTUUhmIel5hRiEklE3OQL6 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Move csum_and_copy_to/from_iter() to net code now that the iteration framework can be #included. Signed-off-by: David Howells --- include/linux/skbuff.h | 25 ++++++++++++ include/linux/uio.h | 18 --------- lib/iov_iter.c | 89 ------------------------------------------ net/core/datagram.c | 50 +++++++++++++++++++++++- net/core/skbuff.c | 33 ++++++++++++++++ 5 files changed, 107 insertions(+), 108 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 4174c4b82d13..d0656cc11c16 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3679,6 +3679,31 @@ static inline int __must_check skb_put_padto(struct sk_buff *skb, unsigned int l return __skb_put_padto(skb, len, true); } +static inline __wsum csum_and_memcpy(void *to, const void *from, size_t len, + __wsum sum, size_t off) +{ + __wsum next = csum_partial_copy_nocheck(from, to, len); + return csum_block_add(sum, next, off); +} + +struct csum_state { + __wsum csum; + size_t off; +}; + +size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i); + +static __always_inline __must_check +bool csum_and_copy_from_iter_full(void *addr, size_t bytes, + __wsum *csum, struct iov_iter *i) +{ + size_t copied = csum_and_copy_from_iter(addr, bytes, csum, i); + if (likely(copied == bytes)) + return true; + iov_iter_revert(i, copied); + return false; +} + static inline int skb_add_data(struct sk_buff *skb, struct iov_iter *from, int copy) { diff --git a/include/linux/uio.h b/include/linux/uio.h index 65d9143f83c8..0a5426c97e02 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -338,24 +338,6 @@ iov_iter_npages_cap(struct iov_iter *i, int maxpages, size_t max_bytes) return npages; } -struct csum_state { - __wsum csum; - size_t off; -}; - -size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *csstate, struct iov_iter *i); -size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i); - -static __always_inline __must_check -bool csum_and_copy_from_iter_full(void *addr, size_t bytes, - __wsum *csum, struct iov_iter *i) -{ - size_t copied = csum_and_copy_from_iter(addr, bytes, csum, i); - if (likely(copied == bytes)) - return true; - iov_iter_revert(i, copied); - return false; -} size_t hash_and_copy_to_iter(const void *addr, size_t bytes, void *hashp, struct iov_iter *i); diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 943aa3cfd7b3..fef934a8745d 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -179,13 +178,6 @@ void iov_iter_init(struct iov_iter *i, unsigned int direction, } EXPORT_SYMBOL(iov_iter_init); -static __wsum csum_and_memcpy(void *to, const void *from, size_t len, - __wsum sum, size_t off) -{ - __wsum next = csum_partial_copy_nocheck(from, to, len); - return csum_block_add(sum, next, off); -} - size_t _copy_to_iter(const void *addr, size_t bytes, struct iov_iter *i) { if (WARN_ON_ONCE(i->data_source)) @@ -1101,87 +1093,6 @@ ssize_t iov_iter_get_pages_alloc2(struct iov_iter *i, } EXPORT_SYMBOL(iov_iter_get_pages_alloc2); -static __always_inline -size_t copy_from_user_iter_csum(void __user *iter_from, size_t progress, - size_t len, void *to, void *priv2) -{ - __wsum next, *csum = priv2; - - next = csum_and_copy_from_user(iter_from, to + progress, len); - *csum = csum_block_add(*csum, next, progress); - return next ? 0 : len; -} - -static __always_inline -size_t memcpy_from_iter_csum(void *iter_from, size_t progress, - size_t len, void *to, void *priv2) -{ - __wsum *csum = priv2; - - *csum = csum_and_memcpy(to + progress, iter_from, len, *csum, progress); - return 0; -} - -size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, - struct iov_iter *i) -{ - if (WARN_ON_ONCE(!i->data_source)) - return 0; - return iterate_and_advance2(i, bytes, addr, csum, - copy_from_user_iter_csum, - memcpy_from_iter_csum); -} -EXPORT_SYMBOL(csum_and_copy_from_iter); - -static __always_inline -size_t copy_to_user_iter_csum(void __user *iter_to, size_t progress, - size_t len, void *from, void *priv2) -{ - __wsum next, *csum = priv2; - - next = csum_and_copy_to_user(from + progress, iter_to, len); - *csum = csum_block_add(*csum, next, progress); - return next ? 0 : len; -} - -static __always_inline -size_t memcpy_to_iter_csum(void *iter_to, size_t progress, - size_t len, void *from, void *priv2) -{ - __wsum *csum = priv2; - - *csum = csum_and_memcpy(iter_to, from + progress, len, *csum, progress); - return 0; -} - -size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *_csstate, - struct iov_iter *i) -{ - struct csum_state *csstate = _csstate; - __wsum sum; - - if (WARN_ON_ONCE(i->data_source)) - return 0; - if (unlikely(iov_iter_is_discard(i))) { - // can't use csum_memcpy() for that one - data is not copied - csstate->csum = csum_block_add(csstate->csum, - csum_partial(addr, bytes, 0), - csstate->off); - csstate->off += bytes; - return bytes; - } - - sum = csum_shift(csstate->csum, csstate->off); - - bytes = iterate_and_advance2(i, bytes, (void *)addr, &sum, - copy_to_user_iter_csum, - memcpy_to_iter_csum); - csstate->csum = csum_shift(sum, csstate->off); - csstate->off += bytes; - return bytes; -} -EXPORT_SYMBOL(csum_and_copy_to_iter); - size_t hash_and_copy_to_iter(const void *addr, size_t bytes, void *hashp, struct iov_iter *i) { diff --git a/net/core/datagram.c b/net/core/datagram.c index 176eb5834746..37c89d0933b7 100644 --- a/net/core/datagram.c +++ b/net/core/datagram.c @@ -50,7 +50,7 @@ #include #include #include -#include +#include #include #include @@ -716,6 +716,54 @@ int zerocopy_sg_from_iter(struct sk_buff *skb, struct iov_iter *from) } EXPORT_SYMBOL(zerocopy_sg_from_iter); +static __always_inline +size_t copy_to_user_iter_csum(void __user *iter_to, size_t progress, + size_t len, void *from, void *priv2) +{ + __wsum next, *csum = priv2; + + next = csum_and_copy_to_user(from + progress, iter_to, len); + *csum = csum_block_add(*csum, next, progress); + return next ? 0 : len; +} + +static __always_inline +size_t memcpy_to_iter_csum(void *iter_to, size_t progress, + size_t len, void *from, void *priv2) +{ + __wsum *csum = priv2; + + *csum = csum_and_memcpy(iter_to, from + progress, len, *csum, progress); + return 0; +} + +static size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *_csstate, + struct iov_iter *i) +{ + struct csum_state *csstate = _csstate; + __wsum sum; + + if (WARN_ON_ONCE(i->data_source)) + return 0; + if (unlikely(iov_iter_is_discard(i))) { + // can't use csum_memcpy() for that one - data is not copied + csstate->csum = csum_block_add(csstate->csum, + csum_partial(addr, bytes, 0), + csstate->off); + csstate->off += bytes; + return bytes; + } + + sum = csum_shift(csstate->csum, csstate->off); + + bytes = iterate_and_advance2(i, bytes, (void *)addr, &sum, + copy_to_user_iter_csum, + memcpy_to_iter_csum); + csstate->csum = csum_shift(sum, csstate->off); + csstate->off += bytes; + return bytes; +} + /** * skb_copy_and_csum_datagram - Copy datagram to an iovec iterator * and update a checksum. diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 4eaf7ed0d1f4..5dbdfce2d05f 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -62,6 +62,7 @@ #include #include #include +#include #include #include @@ -6931,3 +6932,35 @@ ssize_t skb_splice_from_iter(struct sk_buff *skb, struct iov_iter *iter, return spliced ?: ret; } EXPORT_SYMBOL(skb_splice_from_iter); + +static __always_inline +size_t memcpy_from_iter_csum(void *iter_from, size_t progress, + size_t len, void *to, void *priv2) +{ + __wsum *csum = priv2; + + *csum = csum_and_memcpy(to + progress, iter_from, len, *csum, progress); + return 0; +} + +static __always_inline +size_t copy_from_user_iter_csum(void __user *iter_from, size_t progress, + size_t len, void *to, void *priv2) +{ + __wsum next, *csum = priv2; + + next = csum_and_copy_from_user(iter_from, to + progress, len); + *csum = csum_block_add(*csum, next, progress); + return next ? 0 : len; +} + +size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, + struct iov_iter *i) +{ + if (WARN_ON_ONCE(!i->data_source)) + return 0; + return iterate_and_advance2(i, bytes, addr, csum, + copy_from_user_iter_csum, + memcpy_from_iter_csum); +} +EXPORT_SYMBOL(csum_and_copy_from_iter); From patchwork Fri Sep 22 12:02:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395709 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AEDBCD4F5B for ; Fri, 22 Sep 2023 12:03:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A41A86B02D5; Fri, 22 Sep 2023 08:03:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F04C6B02D6; Fri, 22 Sep 2023 08:03:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 869926B02D7; Fri, 22 Sep 2023 08:03:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6CAD46B02D5 for ; Fri, 22 Sep 2023 08:03:10 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 474381CAEBB for ; Fri, 22 Sep 2023 12:03:10 +0000 (UTC) X-FDA: 81264097740.19.0954354 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 7E151A0039 for ; Fri, 22 Sep 2023 12:03:08 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ecjndrne; spf=pass (imf25.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695384188; a=rsa-sha256; cv=none; b=awFeekj4Rb95mQymdvPkgPPcEMV28M9bs3VZahAswZBBj0wfGYSMLplat4HWbkftvbii1G /M/XpTukq6it/9orHc5tETjbvkMghUUHBG2sQXj9BezbDqjuzqLvWDUq08uXNCkAUvzE+p 3H0+HCTc3Hw8PixMO5XtNfiMBNoEvWQ= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ecjndrne; spf=pass (imf25.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695384188; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=i+29vAFZrXF9naWng0ipN/2z31gEil+IMifE0VymLF4=; b=YfqHS6Twmct0Gegh6/J0vLKhOybhWBYwT/lR0Vo1Givq//dqvuxLj4e/Ehg+vn3CKuNyWl 9bI/9AzgB1NxZ2O1fx9wvaxojsckBV7XlxgL+Aj6jycF/uwNQIeC/SkARB0jNjCe083bQC 69X1WisT4nqpgIeKfV/oP1QPdsrpUlg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695384187; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=i+29vAFZrXF9naWng0ipN/2z31gEil+IMifE0VymLF4=; b=EcjndrneaDCzFMJP+nm2WTSUbeivCV2F2X6cdro+I5werZF1x9LyYc8qaQDrehYZTi20iO R+i0x3RkApsBypLQfMoxazN6kUIsi0Gzo6pXGmY1jPJVEqZ6RAQddEOxJB6ak6BNd0922y 18p8wjL9fP6UCy3d46iaDCT9uMMPFtk= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-142-CaRM41xMMG6W6r4YEJltnA-1; Fri, 22 Sep 2023 08:03:00 -0400 X-MC-Unique: CaRM41xMMG6W6r4YEJltnA-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B3A55811E96; Fri, 22 Sep 2023 12:02:59 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id AA91D20268D6; Fri, 22 Sep 2023 12:02:57 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [PATCH v6 11/13] iov_iter, net: Fold in csum_and_memcpy() Date: Fri, 22 Sep 2023 13:02:25 +0100 Message-ID: <20230922120227.1173720-12-dhowells@redhat.com> In-Reply-To: <20230922120227.1173720-1-dhowells@redhat.com> References: <20230922120227.1173720-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 7E151A0039 X-Stat-Signature: qki8ce1z9w4mnskea8d4n1e4iyakwsmf X-Rspam-User: X-HE-Tag: 1695384188-712468 X-HE-Meta: U2FsdGVkX18hno7Ix5tqdGJKn/ORjNxLyEvtzbCu4RgmMf52K9hMIMW2RoaJhr1YDgSRR+OvNLA4bMuImuzKIXC3oOZzn4YqO7C0/1VK01Xg6Ia898Vxwt0qXCqwxVgiy+DyfS5P2jhSzh0YqYh1sasxL9N0HDtt8Q05amm5J0shNeqJ5LelU4N2iMjPBTwFcyDyJ4U7xS/ZmYAYsvreSJgadi5OLPngKejo9K6/BKiPLYV4zI8/Mnp6oi2bVE3L2NaT+qTY9qW70AVAc12p5RSmXRiFtHzyp2E61mJLEnCDVNZ6+BQqhinstUk7N3Pr/tBcrZanmBZfEUA3yatR7Rg+yJQixw4ut8STaOfNYyto44fEFJgwmYH+XDRWfUFtmcGjIKMVXGdsaCDbrii7XglcZcP7yCaCWpNzmuD25EjT2MS35oMW+q+jgxL5XbK19+04Tlv3LiU5p2htTLwdTMc5iUJCvzz3CzdB3Z+tA4CB3l2sLdUWcFXYgnxINw9/ay2Fi1Xl2Za2cdJ6BZXhzXUt2cdGCUp90lWODstgH9oQCTxBXJqxntR71ByA54T3N7YyJIFYPVeaghlBEj6gs6bt5AfQU7pw0IUHRpy9gSGOGgV3AD3Nwedr+XGkjYdloFpdmf5fR7XRa+mPqqIM6bdXNy5FIETr6wiw8ukF3XN+lDP/bnJmeyNFFvZeDNQPw17V6ObExSFe/wKfU7cBRr/KGHH93YcuUsyiwNH6UovwucLHstWYf+UImKhaGSnyqZ2jA//b0wtAQCK9g1ThET+B9AJrwfTHE2gkSgqsY+zuko8ZrNcaE7/2JKMxcK1N7EW/24DRh7+oAoftNuYnbbB2ePVpKKVP74UcZszgXs2z7bwnp8PT4V0ap726IMifLXEBFmLGDXoY2U1mRiP2X5DJT8vzyYAqQLPlamJJDv2hSuy7Ucu1HHjcWfqJ+Od1kiLQ334GCDhq3YeHy1r qQW16LpS OTa0DVj3sbHFpYn7eF6WYR6aKoPUGaIS/OfAHpRer7caunOHycwdibuIfdvFDf2nquvGzFPW5wpg8K0SvYUG4bKl7t/574+yVtVKv7sAbVvjoVEIiAlrfceE5LWBPC/7lNfqgPCy3i6WRPQq+Wr/HQfpRLDDeGw62JyVagbRRN3TJ13ijOR/Gw9EbVE6JmYiTjCIwZ1uWDbu90pZoHi7SSu70zTtupmqTcunSp2XaaWnkQ0sRvddoFLW6UIhRv0qlB7lxIu/LTv1+DAkAMnoBRkUMwPvsj7fByrMZMK3DMu6Rgqw2C0Owxqh7vuz6Qln+Zb8YHz4VrXCV/rqXFLqZY+5rS8td9dv4oqGuhviDTEmYJV7z2dt0pgi6cNY5Gy09vOGezGr3AEnp96UUek7cMEUvTHIrUGY2itGn5on/omSrLUcj8vHuEd55z94Ae6PYD0jtpJMXz2RqxdVPUv6W/qHe2gPYhxigee8e0isqLhnq/Oa00TKirxuI6aILFw681S5/fzOV3BvrZhI+cy7mXUVBTZd4CSOAF2yZj32371kSOMorxnVF4c7SyTncmEsryvOCC5gwVr9bVOMdXQ58hnK4jQV3kvHelkwsNdWMKww6EviCEk61qSeYNMo+rGK5ZgqfrXag7PjGjjpAP5S6OclMvhncW2RIfPXs X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Fold csum_and_memcpy() in to its callers. Signed-off-by: David Howells cc: Alexander Viro cc: Jens Axboe cc: Christoph Hellwig cc: Christian Brauner cc: Matthew Wilcox cc: Linus Torvalds cc: David Laight cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org cc: netdev@vger.kernel.org --- include/linux/skbuff.h | 7 ------- net/core/datagram.c | 3 ++- net/core/skbuff.c | 3 ++- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index d0656cc11c16..c81ef5d76953 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3679,13 +3679,6 @@ static inline int __must_check skb_put_padto(struct sk_buff *skb, unsigned int l return __skb_put_padto(skb, len, true); } -static inline __wsum csum_and_memcpy(void *to, const void *from, size_t len, - __wsum sum, size_t off) -{ - __wsum next = csum_partial_copy_nocheck(from, to, len); - return csum_block_add(sum, next, off); -} - struct csum_state { __wsum csum; size_t off; diff --git a/net/core/datagram.c b/net/core/datagram.c index 37c89d0933b7..452620dd41e4 100644 --- a/net/core/datagram.c +++ b/net/core/datagram.c @@ -732,8 +732,9 @@ size_t memcpy_to_iter_csum(void *iter_to, size_t progress, size_t len, void *from, void *priv2) { __wsum *csum = priv2; + __wsum next = csum_partial_copy_nocheck(from, iter_to, len); - *csum = csum_and_memcpy(iter_to, from + progress, len, *csum, progress); + *csum = csum_block_add(*csum, next, progress); return 0; } diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 5dbdfce2d05f..3efed86321db 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6938,8 +6938,9 @@ size_t memcpy_from_iter_csum(void *iter_from, size_t progress, size_t len, void *to, void *priv2) { __wsum *csum = priv2; + __wsum next = csum_partial_copy_nocheck(iter_from, to + progress, len); - *csum = csum_and_memcpy(to + progress, iter_from, len, *csum, progress); + *csum = csum_block_add(*csum, next, progress); return 0; } From patchwork Fri Sep 22 12:02:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395711 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1463CD4F5B for ; Fri, 22 Sep 2023 12:03:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 894E66B02D6; Fri, 22 Sep 2023 08:03:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7F7E76B02D9; Fri, 22 Sep 2023 08:03:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 647496B02D6; Fri, 22 Sep 2023 08:03:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 415EA6B02D8 for ; Fri, 22 Sep 2023 08:03:12 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 160A11CAE9F for ; Fri, 22 Sep 2023 12:03:12 +0000 (UTC) X-FDA: 81264097824.11.5C72487 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf03.hostedemail.com (Postfix) with ESMTP id 4CF9D20024 for ; Fri, 22 Sep 2023 12:03:08 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IXIMVSUD; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695384188; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OEnm3txfdKWMLGG8rrdFEcQBV2WWgkp8Kq4P7DhBB1I=; b=6N+Ph3QMrWe4qaRl/OHSGwibv9/K2tq1VuzcqrtQ8oZR1yzpd7deVF9WyhSz3zy4SQdVYz Zq0RZdkAX2xwvJr9+bi3V5gJ/TnvWKb4ZDwk2WgoWckLEGP7quzWsIj1rIyowzzGe+WSVG OHFT45VjvkMFhyzZtjjXyAhRRMR8UZY= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=IXIMVSUD; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf03.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695384188; a=rsa-sha256; cv=none; b=UVU/r18AIXHzfD0QO3y7Wwuq3rNlXMaMQKH/X1tcZ6xwzF1cLfp6xqNKZJlfqJOLkhorJO 3OOzdu1C4vVhjccGYq84HwhBC3k4pdvpPf5oCrVSoSksjAXF7OKCK76owcXJCByay95Xg8 U6OfohsGrYzuQIFZxYj+GlRlea0z1c8= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695384187; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OEnm3txfdKWMLGG8rrdFEcQBV2WWgkp8Kq4P7DhBB1I=; b=IXIMVSUDFrWuBSDNg9ygs40Tv+ZwasQ4bnB0bPWIZONC356y+HjwrX2kGswWYjCY5kt8C6 o8M243ii48K6pScGx2kHFSRtcnzi92ZIVH5WM5al5t2dcRFcAoxiTXGgOzdpOucKZs8zCj SOjATEw+p8R+5XPbKm7tlNAcLhI9Svw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-342-_gvf6TzuMjGxNRBZi_i66w-1; Fri, 22 Sep 2023 08:03:03 -0400 X-MC-Unique: _gvf6TzuMjGxNRBZi_i66w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 6BC2B185A790; Fri, 22 Sep 2023 12:03:02 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5A4EC20268D7; Fri, 22 Sep 2023 12:03:00 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [PATCH v6 12/13] iov_iter, net: Merge csum_and_copy_from_iter{,_full}() together Date: Fri, 22 Sep 2023 13:02:26 +0100 Message-ID: <20230922120227.1173720-13-dhowells@redhat.com> In-Reply-To: <20230922120227.1173720-1-dhowells@redhat.com> References: <20230922120227.1173720-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 4CF9D20024 X-Stat-Signature: k44bub6a7phnx8hseihzigfkhz1bqrjf X-Rspam-User: X-HE-Tag: 1695384188-235202 X-HE-Meta: U2FsdGVkX1+om2qAhfL2y7dRZxTGAQ43g9K+EycJLpeiHcLd/J+ukNj/X2U9W1W8BFM9NhnwQLiXOqYXXNHHm3xDZMP9hI2MnJEzvwBNLKK7LiLNw38NP/JtUzZS7wiUNcQGxDIjnsNCZmnSNKuPiVCmV/JcXz7Y5HVuS09CN7r96P/E10aEh7qzFHvTekgvR43JE7eYl4GxNgNub2i310TXH8ZX9PKA4q4eKbQnTcds+6H9MyoFZSyopQmH7DseeqOVGI9W+1V7Aj3ugV1VoHSryEnvMTVZgNjcAaF9yKDsr4Sehwc0UHXJz2fL0cNo4qiU/AlPgTyO9OkRtKIsSv4krZkbWQMgSsgQ5zrnE/+Agv9/bD77xvLdohRvhac6B3yW+ZfkriQ8qGX1npjotxz7nYvE8yTNj16vxbk7A8J9R5YZb7iW02DZsyaW3n//b6thZnzl8yrBgfilS91oBtt1EUBRPd3hV5Te/jwFWohIXd/IXW0R0nxAYpY1mH0KYQeE4Dyp/G0Uh00S3PDZTji3exoUUxDyPLc7JbvunX5pHmrQmQLNYwD8p1Ds1PCZTcylRO4rDBaXFSYcOFqWC9CQBco9uZNq+2K4Tjqm49eerXikjjO13xQvuQ0PgWqjf3XNk6gOOtuuP+0SnLv1Rlmc5WJLJT60qXvUmNltjtOK1Ui/BdBH6QMiPSfYv5f0GmyJ8QF+DguO0+9QHji3k51egXaKKMok+UGg6Fi/5G42FuT5a4HIqpVjOZwu2Au6F5Jpnfmjjgs3Fy2GSVTEqLvZAryJlc28B7o1EOKLhrxzjeSV8W2JCpHZ1/gaYlW/w0qa9wNqKj4AFFMZg6FFW1UKMfEgA4ZBPKtyXuR9ked9K0zL1wFYR8hrQunaB5NSS+IaikCMAhvLK1zO8l5ld7W8tmxpPq0Ix1K8hjYb2zq6RYKrW+znk+FHo2qhIYJKkO4LYNF+t3vmNvcSxCg 0qjm3mHc 19IkbImj/buMlsP0l2PyCHQ9YYUhnls614Wuz19xEqYwqSs2xWgYCoFH/Xc59nW2bgDdw53qXjz2rFvuX4NGjuBGHAIbKFwcxbDl2TfH/mroErhbb2y+aEG7mx6Iw+PqpDcAFUg1pfUaRiQNAHX6G1L1/XpgI+peL7hY/qrQ6EezMp4VZoalorpsOmBKvvnq6A8pObiyuK80Xm8Dj1JwyCNXoSIcXXDAflsY8osbope1bNS4HdEHGjPsTkpEPxKStKedJDOHZMXFFL1ZHLK3JgiNmQGomhOjF3aVbW2LpN1olNTUtMCBl87jxJ32TUq/dgh49xjdFrBtciG4LmWqRqZ25NSIkBuoFtoYas36HBFGx8L/PPtZTO6SyPXIW4v58ity7zcm/6eJz1hx0MZc9MCJgCmvTtBdrICjjE5ya7s97SrQ3luaJD0UfV4kxKfLgSZ4AVznShuOn7jSl+8daUxSrkNtcosRIafzTNb9U8hiKWjqE1Ct/N3o/fZVBftC05XRigIa3x3jkIXDxdLcUXzFFViRBAVpR1pJK8+tH6eX7eEE5b+PpPAHetQi1fTb8dCSpsM6ztsYPsMxf3XrY5d5qNWXxkLKbxN+KnN8TSwbmwX4L7pSx3/96qMCKbBnYJ3P7DQgG05mVxW8ymS0JlJ1+XAUDHc/cUnnR X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Move csum_and_copy_from_iter_full() out of line and then merge csum_and_copy_from_iter() into its only caller. Signed-off-by: David Howells cc: Alexander Viro cc: Jens Axboe cc: Christoph Hellwig cc: Christian Brauner cc: Matthew Wilcox cc: Linus Torvalds cc: David Laight cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org cc: netdev@vger.kernel.org --- include/linux/skbuff.h | 19 ++----------------- net/core/datagram.c | 5 +++++ net/core/skbuff.c | 20 +++++++++++++------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index c81ef5d76953..be402f55f6d6 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -3679,23 +3679,8 @@ static inline int __must_check skb_put_padto(struct sk_buff *skb, unsigned int l return __skb_put_padto(skb, len, true); } -struct csum_state { - __wsum csum; - size_t off; -}; - -size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i); - -static __always_inline __must_check -bool csum_and_copy_from_iter_full(void *addr, size_t bytes, - __wsum *csum, struct iov_iter *i) -{ - size_t copied = csum_and_copy_from_iter(addr, bytes, csum, i); - if (likely(copied == bytes)) - return true; - iov_iter_revert(i, copied); - return false; -} +bool csum_and_copy_from_iter_full(void *addr, size_t bytes, __wsum *csum, struct iov_iter *i) + __must_check; static inline int skb_add_data(struct sk_buff *skb, struct iov_iter *from, int copy) diff --git a/net/core/datagram.c b/net/core/datagram.c index 452620dd41e4..722311eeee18 100644 --- a/net/core/datagram.c +++ b/net/core/datagram.c @@ -738,6 +738,11 @@ size_t memcpy_to_iter_csum(void *iter_to, size_t progress, return 0; } +struct csum_state { + __wsum csum; + size_t off; +}; + static size_t csum_and_copy_to_iter(const void *addr, size_t bytes, void *_csstate, struct iov_iter *i) { diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 3efed86321db..2bfa6a7ba244 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6955,13 +6955,19 @@ size_t copy_from_user_iter_csum(void __user *iter_from, size_t progress, return next ? 0 : len; } -size_t csum_and_copy_from_iter(void *addr, size_t bytes, __wsum *csum, - struct iov_iter *i) +bool csum_and_copy_from_iter_full(void *addr, size_t bytes, + __wsum *csum, struct iov_iter *i) { + size_t copied; + if (WARN_ON_ONCE(!i->data_source)) - return 0; - return iterate_and_advance2(i, bytes, addr, csum, - copy_from_user_iter_csum, - memcpy_from_iter_csum); + return false; + copied = iterate_and_advance2(i, bytes, addr, csum, + copy_from_user_iter_csum, + memcpy_from_iter_csum); + if (likely(copied == bytes)) + return true; + iov_iter_revert(i, copied); + return false; } -EXPORT_SYMBOL(csum_and_copy_from_iter); +EXPORT_SYMBOL(csum_and_copy_from_iter_full); From patchwork Fri Sep 22 12:02:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395710 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC915CD4F5B for ; Fri, 22 Sep 2023 12:03:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6484D6B02D8; Fri, 22 Sep 2023 08:03:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D0726B02DB; Fri, 22 Sep 2023 08:03:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44D1B6B02D9; Fri, 22 Sep 2023 08:03:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 2D4476B02D6 for ; Fri, 22 Sep 2023 08:03:12 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 02506810D5 for ; Fri, 22 Sep 2023 12:03:11 +0000 (UTC) X-FDA: 81264097824.15.A7F3B7E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf15.hostedemail.com (Postfix) with ESMTP id 2038BA0056 for ; Fri, 22 Sep 2023 12:03:09 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Hud4A50b; spf=pass (imf15.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695384190; a=rsa-sha256; cv=none; b=aAf6QUkB0CCewKHU+7tgDpya9iBBR5p1MVqhsptHqPP2Wl/BmT93jYWNdauR99pydsdEl9 H4p7b0u73gxE27L2HtsP624HVn2izOA5IISjSZOrEI/ty2EjW5TLYVAB1D2fi/OOm833ry o/eGMD8ZOlWmi1IGTGOngaxWnP2Ddwk= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Hud4A50b; spf=pass (imf15.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695384190; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=IFANTKBqjctjMhYlR9DlpaXTtUIzXQ6esPI4cVawB1c=; b=l03KcXdFf+T8vwjFZB2NYEKTVAV0GjpBASzGJ2iJP/BaLUVQXoSCvwviiElZfY9PAnaCjq DWEpbDFc8ZYMCiWdgYUoJkVRVDeIzZwqu0fwrY3QsJq3gqZuSqm3+KkM3J/GXJZ+jY0G/8 Ql6gMNktMBkkb+p/h55zbqXm2htoXJI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695384189; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IFANTKBqjctjMhYlR9DlpaXTtUIzXQ6esPI4cVawB1c=; b=Hud4A50bwwRJTYJDo//yyPJ+Iq9lWs82AXubdCphe06Pzt+Vcv8cZwCpU1ucXvAi5/pE/1 ktOulKJJ+Hwfx7nMo66MMXMzNxjT6fLY8DdxZX/KbbhBXtqAQro7PfRMVgFFC0JEayKjEA mDPHWsfMQmgtDTUJrQ1VTdTNf9jap7k= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-453-H4_9D-FgOQa1s3eUdZamVw-1; Fri, 22 Sep 2023 08:03:06 -0400 X-MC-Unique: H4_9D-FgOQa1s3eUdZamVw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 3B74285A5BA; Fri, 22 Sep 2023 12:03:05 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 25F1420268D7; Fri, 22 Sep 2023 12:03:03 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , Christoph Hellwig , Christian Brauner , David Laight , Matthew Wilcox , Jeff Layton , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Subject: [PATCH v6 13/13] iov_iter, net: Move hash_and_copy_to_iter() to net/ Date: Fri, 22 Sep 2023 13:02:27 +0100 Message-ID: <20230922120227.1173720-14-dhowells@redhat.com> In-Reply-To: <20230922120227.1173720-1-dhowells@redhat.com> References: <20230922120227.1173720-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 2038BA0056 X-Stat-Signature: jwp1rdgc688z7hmkjdexq94w3uckct1u X-Rspam-User: X-HE-Tag: 1695384189-503544 X-HE-Meta: U2FsdGVkX1+42pWD5wZ/P0hzkYecWJPMQUQZ6OXnupiMqJmoNjlHQ04yuLQPTe6urSTolgo8ZVSEmbilQIU1GtYsHvHjSwgLiMUXca/D3b9yDj2sDJkdNOWTFf/VdWbhusiDsArMToLzsw0qhKCxMQyRDRehUhXhIqN1Nifs4o3GAXh8cIdl4DzloObYbAIq+KomY9I+IU31QfPEKEfBuiLATpUpF2l26ec/T8TM/LCjXL3XCejy+VzgAsG1yHgqaQiYxJCYWYbgSQ8La8dQN8hXo9LlwsllPAm4Bt1NA6o2N192sdVCUlKdhoZvhq4Ps01TA0AqH2PWf+c0uaVgNG5l+LtxFEh6g4Dd2Dbtl7D9d89p23Wm3VVXI57cw9md+FNR1G714TTUFHXBi44NA73wpb/05qpWMcLrkNuG/6uP+hBZ0AYmsnPw+wVIbYY0JnV+c9oMsOs7FMov2AagV07SNBcK8GUgUJtOGb5wAi7qaFwkm4ebXKSxwZm9FZZgJLaRHc3IOYuv424skUpCAVYqT1DDf/J4wQhEu4WjxGa1sD7kIOUvjEtJJsHBTQY0yCUWCNQKpdxMeDSZpXbHLjc5DKlp0Jy/qkXax3dy+iCfv46Q8rD8oqDmJG9HQBm3aA0oEQnIYS18pkXNjXgsy3DLaw5S0uQ89yRzu+lJf9tltOCCmdCBZKFG7l8SKT3yuRJDAVaCkRyL+a6tu3IWHoyWR8McO6TvCQNhfHo4sOYqzxkQJtK20Fdugwsdr4PmwUcFTzOtm3Vpa15tn6DkztKUHp2p6dJaIz3iIIURiV8IutuxdZBYbYbFSBjJHguoRdMXbDXU0bTmEizpmds0wLlyMHNpAGyCGb/GZZ8A63F9EDmkfleoEt2FEybHQ1LFdxgMYPPLsbR06oO7WLp+Hpjx2/GmC2qFnlPh7P2dYYz1vUC/VQb8JEpX9Z7JPLxK1CJkdXbrqaHv3XEVu5b JJio0dn/ C8Ja3VhFAtwH6tQ6V+rSQ4x6E+4yNjmsr41116TU699Setyyb1YWtlwTc0BS9QZ3If+AB1SWx5A0A5nBzV0di/btyg3AKiBJe/uSPZgqgu9/83ublRH4lRICjPVVgT4lIe4WD5nBjeQQUT3JVhbjzFPiYmLg0DVGxmmiyNFI9o0sPjgDJ8iiaOmSfxNoDzwiuNE4QuE6Du+fbjCgz6GmFwo6n4Tkgh2pKSMxSeyk1f+GW88fS0gzRJdHgSxWjb4sudKnOY/Ck4eVfTBwpErJchwUrYisl52D0PcnXXbpffQilGq7WT48paFBt03t109dgrUlGLFee/jo+MrtfXtlLut9sKAXArPs16SVptTJ1ibgvCfIZHVs1gDZyKNGpAMI95T8YAcjpNknorwP8zm8ZPOhXcBFGDg4ZzW3daec/YnShYHQX9SVc7lbCPPvouESC9GGbjc7mj96oCmyWfIZqPZfg0DUhIVw3y09TiUp69KPI8y4x9axBct2YUbGwTlzCDyNSEy09Smwr78KRNOkLr2fX3ZjmtyBibTqw5plcbZNfhrr/YS4/Ft3quSJK4GEopVVt2GWUFPGj7bgF0jHDi0PNbSOTYqZCtg7Uyx/Td/7ije4cMBWUAw68POeTE+xu7BliHJBKz4H1Bb+KRdyq8nBx5N8ZyGzOwBz3 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Move hash_and_copy_to_iter() to be with its only caller in networking code. Signed-off-by: David Howells cc: Alexander Viro cc: Jens Axboe cc: Christoph Hellwig cc: Christian Brauner cc: Matthew Wilcox cc: Linus Torvalds cc: David Laight cc: "David S. Miller" cc: Eric Dumazet cc: Jakub Kicinski cc: Paolo Abeni cc: linux-block@vger.kernel.org cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org cc: netdev@vger.kernel.org --- include/linux/uio.h | 3 --- lib/iov_iter.c | 20 -------------------- net/core/datagram.c | 19 +++++++++++++++++++ 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/include/linux/uio.h b/include/linux/uio.h index 0a5426c97e02..b6214cbf2a43 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -338,9 +338,6 @@ iov_iter_npages_cap(struct iov_iter *i, int maxpages, size_t max_bytes) return npages; } -size_t hash_and_copy_to_iter(const void *addr, size_t bytes, void *hashp, - struct iov_iter *i); - struct iovec *iovec_from_user(const struct iovec __user *uvector, unsigned long nr_segs, unsigned long fast_segs, struct iovec *fast_iov, bool compat); diff --git a/lib/iov_iter.c b/lib/iov_iter.c index fef934a8745d..2547c96d56c7 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-2.0-only -#include #include #include #include @@ -1093,25 +1092,6 @@ ssize_t iov_iter_get_pages_alloc2(struct iov_iter *i, } EXPORT_SYMBOL(iov_iter_get_pages_alloc2); -size_t hash_and_copy_to_iter(const void *addr, size_t bytes, void *hashp, - struct iov_iter *i) -{ -#ifdef CONFIG_CRYPTO_HASH - struct ahash_request *hash = hashp; - struct scatterlist sg; - size_t copied; - - copied = copy_to_iter(addr, bytes, i); - sg_init_one(&sg, addr, copied); - ahash_request_set_crypt(hash, &sg, NULL, copied); - crypto_ahash_update(hash); - return copied; -#else - return 0; -#endif -} -EXPORT_SYMBOL(hash_and_copy_to_iter); - static int iov_npages(const struct iov_iter *i, int maxpages) { size_t skip = i->iov_offset, size = i->count; diff --git a/net/core/datagram.c b/net/core/datagram.c index 722311eeee18..103d46fa0eeb 100644 --- a/net/core/datagram.c +++ b/net/core/datagram.c @@ -61,6 +61,7 @@ #include #include #include +#include /* * Is a socket 'connection oriented' ? @@ -489,6 +490,24 @@ static int __skb_datagram_iter(const struct sk_buff *skb, int offset, return 0; } +static size_t hash_and_copy_to_iter(const void *addr, size_t bytes, void *hashp, + struct iov_iter *i) +{ +#ifdef CONFIG_CRYPTO_HASH + struct ahash_request *hash = hashp; + struct scatterlist sg; + size_t copied; + + copied = copy_to_iter(addr, bytes, i); + sg_init_one(&sg, addr, copied); + ahash_request_set_crypt(hash, &sg, NULL, copied); + crypto_ahash_update(hash); + return copied; +#else + return 0; +#endif +} + /** * skb_copy_and_hash_datagram_iter - Copy datagram to an iovec iterator * and update a hash.