Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp6816098rwl; Wed, 22 Mar 2023 16:32:16 -0700 (PDT) X-Google-Smtp-Source: AK7set92fAc9wWVg9OJcQe5DLc9wtcE8fxgA/sOaY8CvvBpHVvKJtYUqCEQb2bhfYKrf1Cbrumwm X-Received: by 2002:a17:90a:191:b0:237:24eb:99d8 with SMTP id 17-20020a17090a019100b0023724eb99d8mr5795485pjc.19.1679527936529; Wed, 22 Mar 2023 16:32:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679527936; cv=none; d=google.com; s=arc-20160816; b=xL0G2SomaDqHpoBvyC5rbPC7cJDStCQbAsCroQi0mE8YhJsJtXpv8vxAXNkCtWU/1f ag0iYBXgaVWh0mVECyP/Pdy42GfdGN0R4CtPUUM1exEAkWWNIt6RJs6vdChiHop9SaBt vM7R6VBZkuy1zXCb4YZBWNPm1iGUxT3JgMc/o41ztPer0g7eAeKoafpoWQ9olKNrTYMh dIVT0gKyAQ7sY2LG24VNB/lYvBgn6fA9YnDzIdSy8tskPuqvF6FU85K2H82JW5kDZjF/ r1W/HD0IAfcxMaMUf03+3UZgkK54jVd6QH+j3gExgOMAjmhGSk7l2StcbEoo0JlLDSjF oBIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=QnMj4Cg4XLzspjdq0Y6GPmvksW96U7OeggwBEfM48lM=; b=oekvBnbA8HwvREb8nOmnzZkKm3VbwBPlEPWtzgXxK0iAcZnoLd55R6VMAQP1MQQtLN AV2NdIx8xrZ2W21V9Vsgc9H3kCOLmOTLAFMyFRJS0I7cexJk/9FbsQVDp03veJtrEddd ThcugXeVMm7ARmT1wubx4S0as1GCO1x5gwu+WJ1ToSbBsPm4LO5ScwkUQ3IW1fKhTqNR O9cjTdptMxsjN6q26Edy1CzWCitN7FlZ9MTP5s7mr8e+s82C5oPh1BKjFqkbCvH3dA6O omizrR+PG6UOibyoQcvOURDQx80MwO6/xIP6UYrXhznQz0DCGEEnyIQiE/NSpXgLAJ69 Sh4Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b="0PzHbX/k"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r2-20020a170902c60200b0019f3aa7b548si15612863plr.379.2023.03.22.16.32.04; Wed, 22 Mar 2023 16:32:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b="0PzHbX/k"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229672AbjCVX0o (ORCPT + 99 others); Wed, 22 Mar 2023 19:26:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229480AbjCVX0n (ORCPT ); Wed, 22 Mar 2023 19:26:43 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC26B1BEC; Wed, 22 Mar 2023 16:26:41 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A49D9B81E62; Wed, 22 Mar 2023 23:26:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 10B2AC433EF; Wed, 22 Mar 2023 23:26:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1679527599; bh=PvIEo4Lf1POS3kVtjH8cLfsNhEYtiLJKFfz0aZKzwSM=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=0PzHbX/kfHRh5+bu7xghczsZa99c+fGo2bnzHhG3i7q13VtDBccPHPNhCatPGTBOO y/4F5/pdgZZHabfcHlKj/aP3569ph+JCKXILDvRLMeg0VsOXuXbLqTBvWCdZWpNEz0 IMzfc8n3mBPxPANIMVnt6+Z7/cPNZ4MCbxA+KE+A= Date: Wed, 22 Mar 2023 16:26:38 -0700 From: Andrew Morton To: Jens Axboe Cc: David Howells , Stephen Rothwell , Linux Kernel Mailing List , Linux Next Mailing List , Lorenzo Stoakes Subject: Re: linux-next: manual merge of the block tree with the mm tree Message-Id: <20230322162638.d940201434ac3a3a29968979@linux-foundation.org> In-Reply-To: <82ade7f2-017e-af6b-2fb3-eb1a3f570505@kernel.dk> References: <20230323100204.0917cecf@canb.auug.org.au> <3431084.1679526799@warthog.procyon.org.uk> <82ade7f2-017e-af6b-2fb3-eb1a3f570505@kernel.dk> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 22 Mar 2023 17:15:48 -0600 Jens Axboe wrote: > On 3/22/23 5:13 PM, David Howells wrote: > > Stephen Rothwell wrote: > > > >> + if (unlikely(iov_iter_is_pipe(i))) { > >> + copied = copy_page_to_iter_pipe(page, offset, bytes, i); > >> + goto out; > >> + } > > > > This bit would need to be removed from copy_page_to_iter_atomic() as the two > > functions it calls should be removed by the patch in the block tree. > > Maybe it'd be better to consolidate rather than split the changes over > two trees? fyi, Lorenzo has sent out v7 of this series. I'll be pushing this in an hour or so. After which I suggest Stephen removes those (now) two lines and sends out one of his "build fix" emails which can be the basis for Linus's resolution. Or I can just steal "iov_iter: Kill ITER_PIPE"... From: Lorenzo Stoakes Subject: iov_iter: add copy_page_to_iter_nofault() Date: Wed, 22 Mar 2023 18:57:03 +0000 Provide a means to copy a page to user space from an iterator, aborting if a page fault would occur. This supports compound pages, but may be passed a tail page with an offset extending further into the compound page, so we cannot pass a folio. This allows for this function to be called from atomic context and _try_ to user pages if they are faulted in, aborting if not. The function does not use _copy_to_iter() in order to not specify might_fault(), this is similar to copy_page_from_iter_atomic(). This is being added in order that an iteratable form of vread() can be implemented while holding spinlocks. Link: https://lkml.kernel.org/r/19734729defb0f498a76bdec1bef3ac48a3af3e8.1679511146.git.lstoakes@gmail.com Signed-off-by: Lorenzo Stoakes Cc: Alexander Viro Cc: Baoquan He Cc: David Hildenbrand Cc: Jens Axboe Cc: Jiri Olsa Cc: Liu Shixin Cc: Matthew Wilcox (Oracle) Cc: Uladzislau Rezki (Sony) Signed-off-by: Andrew Morton --- --- a/include/linux/uio.h~iov_iter-add-copy_page_to_iter_nofault +++ a/include/linux/uio.h @@ -173,6 +173,8 @@ static inline size_t copy_folio_to_iter( { return copy_page_to_iter(&folio->page, offset, bytes, i); } +size_t copy_page_to_iter_nofault(struct page *page, unsigned offset, + size_t bytes, struct iov_iter *i); static __always_inline __must_check size_t copy_to_iter(const void *addr, size_t bytes, struct iov_iter *i) --- a/lib/iov_iter.c~iov_iter-add-copy_page_to_iter_nofault +++ a/lib/iov_iter.c @@ -172,6 +172,18 @@ static int copyout(void __user *to, cons return n; } +static int copyout_nofault(void __user *to, const void *from, size_t n) +{ + long res; + + if (should_fail_usercopy()) + return n; + + res = copy_to_user_nofault(to, from, n); + + return res < 0 ? n : res; +} + static int copyin(void *to, const void __user *from, size_t n) { size_t res = n; @@ -734,6 +746,42 @@ size_t copy_page_to_iter(struct page *pa } EXPORT_SYMBOL(copy_page_to_iter); +size_t copy_page_to_iter_nofault(struct page *page, unsigned offset, size_t bytes, + struct iov_iter *i) +{ + size_t res = 0; + + if (!page_copy_sane(page, offset, bytes)) + return 0; + if (WARN_ON_ONCE(i->data_source)) + return 0; + if (unlikely(iov_iter_is_pipe(i))) + return copy_page_to_iter_pipe(page, offset, bytes, i); + page += offset / PAGE_SIZE; // first subpage + offset %= PAGE_SIZE; + while (1) { + 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) + ) + kunmap_local(kaddr); + res += n; + bytes -= n; + if (!bytes || !n) + break; + offset += n; + if (offset == PAGE_SIZE) { + page++; + offset = 0; + } + } + return res; +} +EXPORT_SYMBOL(copy_page_to_iter_nofault); + size_t copy_page_from_iter(struct page *page, size_t offset, size_t bytes, struct iov_iter *i) { _