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 9A5A5C433EF for ; Thu, 30 Jun 2022 17:53:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D9E438E0003; Thu, 30 Jun 2022 13:53:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D324C8E0002; Thu, 30 Jun 2022 13:53:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B907A8E0005; Thu, 30 Jun 2022 13:53:17 -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 982548E0002 for ; Thu, 30 Jun 2022 13:53:17 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 6FDF0610ED for ; Thu, 30 Jun 2022 17:53:17 +0000 (UTC) X-FDA: 79635648834.10.83D8321 Received: from out02.mta.xmission.com (out02.mta.xmission.com [166.70.13.232]) by imf18.hostedemail.com (Postfix) with ESMTP id 6991A1C003A; Thu, 30 Jun 2022 17:53:14 +0000 (UTC) Received: from in02.mta.xmission.com ([166.70.13.52]:44732) by out02.mta.xmission.com with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o6yLn-0020mB-0Z; Thu, 30 Jun 2022 11:53:11 -0600 Received: from ip68-227-174-4.om.om.cox.net ([68.227.174.4]:58068 helo=email.froward.int.ebiederm.org.xmission.com) by in02.mta.xmission.com with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1o6yLl-001wdx-Pt; Thu, 30 Jun 2022 11:53:10 -0600 From: "Eric W. Biederman" To: "Fabio M. De Francesco" Cc: Benjamin LaHaise , Alexander Viro , Kees Cook , Dan Williams , Matthew Wilcox , Jan Kara , Jeff Layton , Chuck Lever , Jens Axboe , Pavel Begunkov , Thomas Gleixner , Paul Walmsley , Palmer Dabbelt , Albert Ou , Nathan Chancellor , Nick Desaulniers , Tom Rix , linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, nvdimm@lists.linux.dev, io-uring@vger.kernel.org, linux-riscv@lists.infradead.org, llvm@lists.linux.dev, Ira Weiny References: <20220630163527.9776-1-fmdefrancesco@gmail.com> Date: Thu, 30 Jun 2022 12:38:08 -0500 In-Reply-To: <20220630163527.9776-1-fmdefrancesco@gmail.com> (Fabio M. De Francesco's message of "Thu, 30 Jun 2022 18:35:27 +0200") Message-ID: <8735fmqcfz.fsf@email.froward.int.ebiederm.org> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-XM-SPF: eid=1o6yLl-001wdx-Pt;;;mid=<8735fmqcfz.fsf@email.froward.int.ebiederm.org>;;;hst=in02.mta.xmission.com;;;ip=68.227.174.4;;;frm=ebiederm@xmission.com;;;spf=softfail X-XM-AID: U2FsdGVkX19nGDcBXv1cJKDV99uQtYu50l8eqi94dLE= X-SA-Exim-Connect-IP: 68.227.174.4 X-SA-Exim-Mail-From: ebiederm@xmission.com Subject: Re: [PATCH] fs: Replace kmap{,_atomic}() with kmap_local_page() X-SA-Exim-Version: 4.2.1 (built Sat, 08 Feb 2020 21:53:50 +0000) X-SA-Exim-Scanned: Yes (on in02.mta.xmission.com) ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=xmission.com; spf=pass (imf18.hostedemail.com: domain of ebiederm@xmission.com designates 166.70.13.232 as permitted sender) smtp.mailfrom=ebiederm@xmission.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656611595; a=rsa-sha256; cv=none; b=7JtMtL88+R3xFaBLGJxzEOulEOnXCFvFn8YDf6ABX/nQCv5jKyeWPQPD4zcR1fpaav5/r3 +AgtGnb/QsBfC8W3tHj/KGU6ZL1OsEsf7SfJCbDOnDdK0ws0GiqFT4gh1u5h4UX17Ruxuf 72VariT1y+4AzcNKEfd7cLC6Dh1SoHM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656611595; 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; bh=RTzrkIa4l8KBmXELqRaiEbou3d+3mvwY2hlsOmLigyo=; b=uuUQTdDcRjoTfvxJtl5b0lKE40EzAu2lP9OYVE8gO9N2Am5YW+k54Lh6p7U9WOcLxAUBPz noTUZb4ut6SqNmwx271JQsbsiYH6LIr+5rnpRyR9JQ4fEGXxF4dJDzyPcMgga8HMYw97GN kl7Mc+EDVsbHkSIukYfK8iyI4+ITERg= X-Rspam-User: Authentication-Results: imf18.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=xmission.com; spf=pass (imf18.hostedemail.com: domain of ebiederm@xmission.com designates 166.70.13.232 as permitted sender) smtp.mailfrom=ebiederm@xmission.com X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 6991A1C003A X-Stat-Signature: iyh5p5bmfaecoq1prmeptzq4uukybssf X-HE-Tag: 1656611594-880195 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: "Fabio M. De Francesco" writes: > The use of kmap() and kmap_atomic() are being deprecated in favor of > kmap_local_page(). > > With kmap_local_page(), the mappings are per thread, CPU local and not > globally visible. Furthermore, the mappings can be acquired from any > context (including interrupts). > > Therefore, use kmap_local_page() in exec.c because these mappings are per > thread, CPU local, and not globally visible. > > Tested with xfstests on a QEMU + KVM 32-bits VM booting a kernel with > HIGHMEM64GB enabled. Can someone please refresh my memory on what is going on. I remember there were limitations that kmap_atomic had that are hard to meet so something I think it was kmap_local was invented and created to be the kmap_atomic replacement. What are the requirements on kmap_local? In copy_strings kmap is called in contexts that can sleep in page faults so any nearly any requirement except a thread local use is invalidated. As you have described kmap_local above it does not sound like kmap_local is safe in this context, but that could just be a problem in description that my poor memory does is not recalling the necessary details to correct. Eric > Suggested-by: Ira Weiny > Signed-off-by: Fabio M. De Francesco > --- > fs/exec.c | 14 +++++++------- > 1 file changed, 7 insertions(+), 7 deletions(-) > > diff --git a/fs/exec.c b/fs/exec.c > index 0989fb8472a1..4a2129c0d422 100644 > --- a/fs/exec.c > +++ b/fs/exec.c > @@ -583,11 +583,11 @@ static int copy_strings(int argc, struct user_arg_ptr argv, > > if (kmapped_page) { > flush_dcache_page(kmapped_page); > - kunmap(kmapped_page); > + kunmap_local(kaddr); > put_arg_page(kmapped_page); > } > kmapped_page = page; > - kaddr = kmap(kmapped_page); > + kaddr = kmap_local_page(kmapped_page); > kpos = pos & PAGE_MASK; > flush_arg_page(bprm, kpos, kmapped_page); > } > @@ -601,7 +601,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv, > out: > if (kmapped_page) { > flush_dcache_page(kmapped_page); > - kunmap(kmapped_page); > + kunmap_local(kaddr); > put_arg_page(kmapped_page); > } > return ret; > @@ -883,11 +883,11 @@ int transfer_args_to_stack(struct linux_binprm *bprm, > > for (index = MAX_ARG_PAGES - 1; index >= stop; index--) { > unsigned int offset = index == stop ? bprm->p & ~PAGE_MASK : 0; > - char *src = kmap(bprm->page[index]) + offset; > + char *src = kmap_local_page(bprm->page[index]) + offset; > sp -= PAGE_SIZE - offset; > if (copy_to_user((void *) sp, src, PAGE_SIZE - offset) != 0) > ret = -EFAULT; > - kunmap(bprm->page[index]); > + kunmap_local(src); > if (ret) > goto out; > } > @@ -1680,13 +1680,13 @@ int remove_arg_zero(struct linux_binprm *bprm) > ret = -EFAULT; > goto out; > } > - kaddr = kmap_atomic(page); > + kaddr = kmap_local_page(page); > > for (; offset < PAGE_SIZE && kaddr[offset]; > offset++, bprm->p++) > ; > > - kunmap_atomic(kaddr); > + kunmap_local(kaddr); > put_arg_page(page); > } while (offset == PAGE_SIZE);