From patchwork Mon Mar 20 23:42:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13182035 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 2CD44C6FD1C for ; Mon, 20 Mar 2023 23:43:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B8E226B007D; Mon, 20 Mar 2023 19:43:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B17BA6B007E; Mon, 20 Mar 2023 19:43:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8F66D6B0080; Mon, 20 Mar 2023 19:43:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 7FC9E6B007D for ; Mon, 20 Mar 2023 19:43:07 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3D5B7160F87 for ; Mon, 20 Mar 2023 23:43:07 +0000 (UTC) X-FDA: 80590904814.24.2BE8CE2 Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by imf06.hostedemail.com (Postfix) with ESMTP id 6252C180008 for ; Mon, 20 Mar 2023 23:43:05 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=joYGkNHD; spf=pass (imf06.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.52 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679355785; 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=b4AaWDqV89kHBZGOLd4BouvpuEGkoHHTR7oX6vXaXkQ=; b=6mhqaeytS0NS5lSQDJENt8kYAas0F8ZVkIy1334jBiXXSaxb/yOsel4XnQLWb/Lf6sOTZM +TpuwXneaT/9njwD+zTiQ1RTfUCrQnEv9yRWkGDFNim2NJTjNOMtpgUUli1CAs0sIigbeC +xoOjJ4o8wt4iGRDscgNeidJp/iF1Iw= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=joYGkNHD; spf=pass (imf06.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.128.52 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679355785; a=rsa-sha256; cv=none; b=dQNTNwffUgJKvlXuGTTf7E8brxOWsNkyenmIn8wYDmqWv4qYFq08VrdJFdv15cwZhEdRBR 1X6IBrAn7R1jYvJiJ2u15I2jj3QHXcsCUaS/fD8iJzu4mu6WY9PEJx5VT8eWUl1bJ5zwrI qJuQqQmlAU5EeHUemUTxmbkguWGJdF0= Received: by mail-wm1-f52.google.com with SMTP id w11so7489259wmo.2 for ; Mon, 20 Mar 2023 16:43:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679355784; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=b4AaWDqV89kHBZGOLd4BouvpuEGkoHHTR7oX6vXaXkQ=; b=joYGkNHDTIsLDeWPgNoFM1Q2okpaE69pfNRmsJ+y/FqybsxiiD+p7xTXMJv2UFV0A4 61fb425zxzibhUQzrQsMe+rvlxgYOETUMHea7etZsESI8rZOo4ch6rs8uwDgEw4AZwQq WptL6DO4Mh3xD3x/xEpN4MzKVjKbqOFOuXI8KHNI2LyUGuRKrkBrDQzECkZx7pRpslH5 mDklMyfPXPFzXOVbZnRQD9T7rso1xeq9+UI4bd/sNZgmWlqJJWEsu0WvCuvldUOHOgsz ISy5IEqLL/JqGRLSc/sCbOBrebzi6Wz+mu3+a8zo1CDe3MyBUJbx31A/G3Kquds1CT5J UH7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679355784; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=b4AaWDqV89kHBZGOLd4BouvpuEGkoHHTR7oX6vXaXkQ=; b=YMaWGDUpWqMqPylv2ebh7w5ySwua36jqbHXPr2Q7ml29ZieIbIFRQXkNk7uPNFBCTr mZgX3BWFZGIZa8gLsObh4thavqoFHGcNUBG7BN1MNkZcKgXjPI+pbrSDWnOQLagWYHRp pECi3rnmYwVFFf5UjddZ5JjSvG7gpCLDFbtc421Z5sHnRUoaaZC5rX+OiEAksWuuKawW FnC+byEuyrb0lx7slMETjGBD2HxdseoKO82Tu76NELgdpae71M1KWVo4XalfCN2HScTx qsGnv6Pk1XUOEyQ1v6QHxMlXlqMoI7sI05CInhdLnoGmKMJFhpnd8QJwMYoRreP+NNx3 uXCA== X-Gm-Message-State: AO0yUKWxXD/qA1wnzP7NE3nAz5S2cR+4o3v/ND0Yp7ZtEKP5mJSu5liA D909cF2MR88sAR3qmdKLDB1CmwsB02c= X-Google-Smtp-Source: AK7set9UWWC6CCPypNwh9/g+mA241iJtMd+z1H8zy+rUDOsZ1zyTSPvDhBDWMVBAvr03Fg0Tb8CvAA== X-Received: by 2002:a05:600c:296:b0:3ea:f873:13aa with SMTP id 22-20020a05600c029600b003eaf87313aamr773429wmk.40.1679355783915; Mon, 20 Mar 2023 16:43:03 -0700 (PDT) Received: from lucifer.home (host86-146-209-214.range86-146.btcentralplus.com. [86.146.209.214]) by smtp.googlemail.com with ESMTPSA id u1-20020a05600c440100b003e209186c07sm17504541wmn.19.2023.03.20.16.43.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 16:43:02 -0700 (PDT) From: Lorenzo Stoakes To: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andrew Morton Cc: Baoquan He , Uladzislau Rezki , Matthew Wilcox , David Hildenbrand , Liu Shixin , Jiri Olsa , Jens Axboe , Alexander Viro , Lorenzo Stoakes Subject: [PATCH v3 3/4] iov_iter: add copy_page_to_iter_atomic() Date: Mon, 20 Mar 2023 23:42:44 +0000 Message-Id: <31482908634cbb68adafedb65f0b21888c194a1b.1679355227.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: t3ornyznjsgn6r8imh6rit7knu1n6oko X-Rspamd-Queue-Id: 6252C180008 X-HE-Tag: 1679355785-495869 X-HE-Meta: U2FsdGVkX1882XSzFlrTbT2seydQPnlp59MNwkL6iHs+MPeJX9t36igXqH1w8WXuGPQHGVKAttACIIRqW+ffR/GjLWd0TjGc9ajDqnuFmZYRqUZqoNhCZ78WBPhK2/KLRhm18RiXNOjrhXEfm0t8vLbtj7BOmN0TaFjGaPleLIq8aE4xSRIJS3OK6Rc1r7LC3Ovdk8GmBN+HarkhhBNBFOeJETCzC3eomH4JPYs1V+NdUYEjDCCz1LfDdcQyAd3psTwq/yn4Rp0q/+OfWsB0u8kfKm/qscPPjT0RUAQA5R2BSnu+zt+TeXss5VaxfdpOzHyJ5B7HUOrwZyhPtOYtmvd0Rf4UkVlL5V/wZW7inMlydoXfx9mNd50iSQK+98ozWoTYpSEO1UwIFbJ8JmKtllq77yy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bCNkZim2UPmTfh8LXbEWIrVwaxxUZcEPCL 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: Provide an atomic context equivalent for copy_page_to_iter(). This eschews the might_fault() check copies memory in the same way that copy_page_from_iter_atomic() does. This functions assumes a non-compound page, however this mimics the existing behaviour of copy_page_from_iter_atomic(). I am keeping the behaviour consistent between the two, deferring any such change to an explicit folio-fication effort. This is being added in order that an iteratable form of vread() can be implemented with known prefaulted pages to avoid the need for mutex locking. Signed-off-by: Lorenzo Stoakes --- include/linux/uio.h | 2 ++ lib/iov_iter.c | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/include/linux/uio.h b/include/linux/uio.h index 27e3fd942960..fab07103090f 100644 --- a/include/linux/uio.h +++ b/include/linux/uio.h @@ -154,6 +154,8 @@ static inline struct iovec iov_iter_iovec(const struct iov_iter *iter) size_t copy_page_from_iter_atomic(struct page *page, unsigned offset, size_t bytes, struct iov_iter *i); +size_t copy_page_to_iter_atomic(struct page *page, unsigned offset, + size_t bytes, struct iov_iter *i); void iov_iter_advance(struct iov_iter *i, size_t bytes); void iov_iter_revert(struct iov_iter *i, size_t bytes); size_t fault_in_iov_iter_readable(const struct iov_iter *i, size_t bytes); diff --git a/lib/iov_iter.c b/lib/iov_iter.c index 274014e4eafe..48ca1c5dfc04 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -821,6 +821,34 @@ size_t copy_page_from_iter_atomic(struct page *page, unsigned offset, size_t byt } EXPORT_SYMBOL(copy_page_from_iter_atomic); +size_t copy_page_to_iter_atomic(struct page *page, unsigned offset, size_t bytes, + struct iov_iter *i) +{ + char *kaddr = kmap_local_page(page); + char *p = kaddr + offset; + size_t copied = 0; + + if (!page_copy_sane(page, offset, bytes) || + WARN_ON_ONCE(i->data_source)) + goto out; + + if (unlikely(iov_iter_is_pipe(i))) { + copied = copy_page_to_iter_pipe(page, offset, bytes, i); + goto out; + } + + iterate_and_advance(i, bytes, base, len, off, + copyout(base, p + off, len), + memcpy(base, p + off, len) + ) + copied = bytes; + +out: + kunmap_local(kaddr); + return copied; +} +EXPORT_SYMBOL(copy_page_to_iter_atomic); + static void pipe_advance(struct iov_iter *i, size_t size) { struct pipe_inode_info *pipe = i->pipe;