Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp5927834rwl; Wed, 22 Mar 2023 04:23:52 -0700 (PDT) X-Google-Smtp-Source: AKy350by87Z8SleJrHQR4CyE5KrIYQx8U8ldGOojNSnG6UfUgWuxW7TZd29ppT3aRdtu4pjp0gWi X-Received: by 2002:a17:902:fac4:b0:1a0:57df:864f with SMTP id ld4-20020a170902fac400b001a057df864fmr1374059plb.16.1679484232375; Wed, 22 Mar 2023 04:23:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679484232; cv=none; d=google.com; s=arc-20160816; b=UW+/8E/asPV9C52PxlD8gai7zdo7cthhHYdF4+zJr3HAXB3bQQK1wqEK94FXu9DFmD Fyei5A7RIhi2GAJ9UMaRLn/Gbu2xXRnoQ0pg9x5x4ZUXKpEsVjH1A907WP0xkYOtKwo7 ePzmq+PlEt9r0sv+pMW7CwdEgwRuIS4Zyd/oopZUxqd3p0mpjkUfrOjgCrfHCdTq3AAs 6XR/LErhk/85GIbbGVukySajrcyCNVPkGKwSzVgES5+oaUEL94FqSKy/HSRnwU3mP0pN QYlJK4QcJM3P8+HhVPVXBF2yJ6UFod7kVBsEPyi+TJq2VDgBiJOK7PfYLZu0M0Vp+J2r rRsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=PtfuFWofT6zWs9wizodfMqROAedt5NIA2iASaJ8aIFA=; b=lYisJqxjtGoPw+fWuRuZASfhxZ/o9/iKxiYgAkkjSz8WykWKy8HMAQDR9F3crVRkyK 5rAGFnltJGpDBrnvqr4ujfNW9I+Wxbf2i7TUfGU71Igh+1Er7x4k799WfozTY88AnL1V in7IHMPlp52pIlX2wswtmvXQACP8KSl15ba6CdGxSMjP7Vhh7JM2ISX08Xt+7DLMpWfI y45VBsJqx6DGpwRvdar+mibasD0OC4fzQunhi1flKRjWaJGk7U/Dirj6Jk+DavM/blh+ XZlh6B4bF+J1U9ceRkb+kLA3b/ZADD+Rht9l4Db3k8UJ+LVNeSc0z+gw8k68ZCrAe6C/ 2q2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Xhi37l1C; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y13-20020a170902cacd00b0019ced5a540csi14056098pld.370.2023.03.22.04.23.40; Wed, 22 Mar 2023 04:23:52 -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=@gmail.com header.s=20210112 header.b=Xhi37l1C; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230287AbjCVLGU (ORCPT + 99 others); Wed, 22 Mar 2023 07:06:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229584AbjCVLGT (ORCPT ); Wed, 22 Mar 2023 07:06:19 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FD4647403; Wed, 22 Mar 2023 04:06:18 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id l12so16570100wrm.10; Wed, 22 Mar 2023 04:06:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679483176; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=PtfuFWofT6zWs9wizodfMqROAedt5NIA2iASaJ8aIFA=; b=Xhi37l1CUKKylXAxNFEF0ItUK/OoMdH4RfIpyIabWD0a4ZcN6E04FZ2ZpQBHlhPFv2 JAeqFKXy1Q6iQ5P6JDql0qdzM7c4YSdcrImzHFbPn/5Vfc7N5PsYevGG6EqV1YPjCP32 bCZCuI14sD2xLjmz+hexrv5KzHyjoDLukO+7iK4VlFLYuxvZFNP+ilKgYs+c7XIWmRh/ nz+zqMGYXrv/dRsMfudfmrL0c1wwR0SYsDHXwme3dC5ynIJ5HT4W3GrvZicEhtd1wI07 Buu31VCWxztVEbmiwwF3WRA/YmxskzgnbzaZy58Tz0ynv5qw3VdqVXH1pyUN42IJu3W5 cYAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679483176; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=PtfuFWofT6zWs9wizodfMqROAedt5NIA2iASaJ8aIFA=; b=8Q2fAi7/TW6xGMJ3cynahfRnESHhQEZdYr+9eJYA6bhANC19mg6iGjhZZ4sgwSmYAd oLOcu23bsqYeeD2qWvah71PHBJ4KjktOfhbv9xOjqWzc27udWDI8sx2rLndGSBEntbvf ve05MTRNYT2d3jwW6Oy1x4WlKUJ52VY2ndoiKd8CWome1kBTSEqF0ByB+0vXFviwEYsJ 785AFsMYXNfX2+bnmaTqKsEa/E+u2uls8TyM95Yb6gzG1iZg6wmZKfS09pcWFgU1p5ea 9LgrR9KCpHtn3AIr5b9X7i2hXA9Lh7wPf36r3dWd3+UNtMm65ggafwHnFIAitOqNXkX3 0j+Q== X-Gm-Message-State: AO0yUKVJICeDyaejBQK1Gl3J+V+oZ+7GzrqPTFsdfhLEaKgbGVfsZ0i1 GcWxw5Hcla06mbc/2EMOFLE= X-Received: by 2002:a5d:5221:0:b0:2cd:e089:398d with SMTP id i1-20020a5d5221000000b002cde089398dmr1286694wra.5.1679483176335; Wed, 22 Mar 2023 04:06:16 -0700 (PDT) Received: from localhost ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.gmail.com with ESMTPSA id m9-20020adffa09000000b002c70d97af78sm13647255wrr.85.2023.03.22.04.06.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Mar 2023 04:06:15 -0700 (PDT) Date: Wed, 22 Mar 2023 11:06:14 +0000 From: Lorenzo Stoakes To: Baoquan He 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-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS 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, 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. Thanks for raising this!! > > > > 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 > > > > >