From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F3A1AC6FD1C for ; Wed, 22 Mar 2023 13:21:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8D88D6B0071; Wed, 22 Mar 2023 09:21:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 861686B0072; Wed, 22 Mar 2023 09:21:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 701D76B007B; Wed, 22 Mar 2023 09:21:31 -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 56CAD6B0071 for ; Wed, 22 Mar 2023 09:21:31 -0400 (EDT) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0DBFAA0421 for ; Wed, 22 Mar 2023 13:21:31 +0000 (UTC) X-FDA: 80596595982.14.C411551 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 DEC5B180020 for ; Wed, 22 Mar 2023 13:21:28 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ds+jQFai; spf=pass (imf06.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@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=1679491289; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=tBcYyBVP35lI8VuEVG7gg0YDcUirlWVb624TvOLVCvM=; b=EbAmGza+iKgrhN12L91t9hZWqp1PjQ7trqlTARsHZpa5LZMxbNzDmPDKI+0e9DpIjgHNv7 8iJZWSG0W5Mn13GHY+uPh/YiP0V+8yzjsJLRZ11Co7Np6gHFvfb8nVo/gL3c6eQ0PHKBJA RuZDP1KsZSEcCI7oYHWFdxGRAAhZbLE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ds+jQFai; spf=pass (imf06.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679491289; a=rsa-sha256; cv=none; b=mYm2+QQZYEWHDPcJyBHl3jOX/t1+yXONiI/2dGz535mevla9jMe3+4A12PnucT9SgtQvle fOzYgLXu30TR8tYjIi7LMKZkwgpSvgAgZdgkJ5DsLb5TxetboP3t6RwUvni6+LGtnuMoyZ ErW6SMnmugQnS0H+wCQg+2nMF3Qhk2k= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679491288; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=tBcYyBVP35lI8VuEVG7gg0YDcUirlWVb624TvOLVCvM=; b=ds+jQFaiYUxsOMXcLxF3PEQ1hR29raKzyR+z4ev1SnQ6urhb+uIjwj5v5gucsTxImyKjSH bgAeRseVknPSrxwv3FkZOq0pXTmrizVhoTblEPjAxEdUqCF+C2hIyHu+7D/dmQxbgozs2b seZhY9mcChnnzwRUvjR9pGLMZzmuNuc= 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-527-qsMQBnY7MmKyiZvRoAcjnQ-1; Wed, 22 Mar 2023 09:21:24 -0400 X-MC-Unique: qsMQBnY7MmKyiZvRoAcjnQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 0FE77800B23; Wed, 22 Mar 2023 13:21:24 +0000 (UTC) Received: from localhost (ovpn-13-195.pek2.redhat.com [10.72.13.195]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3917840C6E67; Wed, 22 Mar 2023 13:21:22 +0000 (UTC) Date: Wed, 22 Mar 2023 21:21:19 +0800 From: Baoquan He To: Lorenzo Stoakes Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andrew Morton , Uladzislau Rezki , Matthew Wilcox , David Hildenbrand , Liu Shixin , Jiri Olsa , Jens Axboe , Alexander Viro Subject: Re: [PATCH v4 3/4] iov_iter: add copy_page_to_iter_atomic() Message-ID: References: <31482908634cbb68adafedb65f0b21888c194a1b.1679431886.git.lstoakes@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.2 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: DEC5B180020 X-Stat-Signature: qjee3uy9461qsj4thu7d8tkayj9sxofp X-Rspam-User: X-HE-Tag: 1679491288-512275 X-HE-Meta: U2FsdGVkX1/VRVuyV828qUIM3eYQI7NfjQ/a84Ni+LKY7kIijLlmwM+YxaeQZiQWljwNIASRBzUEVzIgIkMrJlI+T3IKER0GFlWVx3pht9dbjXX9PrvYRb0IvQxo76jZRsXzmsOFpBCrTbSBBbq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aHvtvHFogrKRYeCwt8IVJrMcqjJc0hqxc= 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: On 03/22/23 at 11:06am, Lorenzo Stoakes wrote: > On Wed, Mar 22, 2023 at 10:32:47AM +0000, Lorenzo Stoakes wrote: > > > I am a little confused about the name of this new function. In its > > > conterpart, copy_page_from_iter_atomic(), kmap_atomic()/kunmpa_atomic() > > > are used. With them, if CONFIG_HIGHMEM=n, it's like below: > > > > The reason for this is that:- > > > > 1. kmap_atomic() explicitly states that it is now deprecated and must no longer > > be used, and kmap_local_page() should be used instead:- > > > > * kmap_atomic - Atomically map a page for temporary usage - Deprecated! > > > > * Do not use in new code. Use kmap_local_page() instead. > > > > 2. kmap_local_page() explicitly states that it can be used in any context:- > > > > * Can be invoked from any context, including interrupts. > > > > I wanted follow this advice as strictly as I could, hence the change. However, > > we do need preemption/pagefaults explicitly disabled in this context (we are > > happy to fail if the faulted in pages are unmapped in meantime), and I didn't > > check the internals to make sure. > > > > So I think for safety it is better to use k[un]map_atomic() here, I'll respin > > and put that back in, good catch! > > > > Actually, given we have preemption disabled due to the held spinlock, I think > it'd be better to add a copy_page_to_iter_nofault() that uses > copy_to_user_nofault() which will disable pagefaults thus have exactly the > equivalent behaviour, more explicitly and without the use of a deprecated > function. Sounds a great idea, that let us be able to avoid using kmap_atomic. > > > > > > > static inline void *kmap_atomic(struct page *page) > > > { > > > if (IS_ENABLED(CONFIG_PREEMPT_RT)) > > > migrate_disable(); > > > else > > > preempt_disable(); > > > pagefault_disable(); > > > return page_address(page); > > > } > > > > > > But kmap_local_page() is only having page_address(), the code block > > > between kmap_local_page() and kunmap_local() is also atomic, it's a > > > little messy in my mind. > > > > > > static inline void *kmap_local_page(struct page *page) > > > { > > > return page_address(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; > > > > -- > > > > 2.39.2 > > > > > > > >