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 C4F04C43334 for ; Fri, 1 Jul 2022 10:10:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 607E06B0075; Fri, 1 Jul 2022 06:10:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 550616B0073; Fri, 1 Jul 2022 06:10:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3A1316B0073; Fri, 1 Jul 2022 06:10:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 1C8D96B0075 for ; Fri, 1 Jul 2022 06:10:40 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E549934495 for ; Fri, 1 Jul 2022 10:10:39 +0000 (UTC) X-FDA: 79638111798.29.C2C8FAC Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) by imf04.hostedemail.com (Postfix) with ESMTP id 1A99A40045; Fri, 1 Jul 2022 10:10:38 +0000 (UTC) Received: by mail-wm1-f49.google.com with SMTP id l40-20020a05600c1d2800b003a18adff308so1137992wms.5; Fri, 01 Jul 2022 03:10:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=u/VrgVPkgzQyMENrkjqrTLDR84XHdXIPxg7GPzE6OD8=; b=C/MmEOGhSRIfH+EXKc+5tPWL/j3KmXe2C9yF4G29xk8dw1gd61VTKWCyxtLAZxh4sb UE5/kL75GepM+uRycCWRLMpXDY85nUuyxC666CDf9pf73xgkHk37OmHMb05dNiVx0XRD Y2RQ3aefb1GLjqJCg6cZQpZGxI4W7dJG0I4Xu6isQM8oYWN5zHlwT3bNDD+2+f/IN2bz KEATzw78NNRNFuRMWf74dJWFfG1Alqj2WHdrZc3jvO2Hl91xEwPvZ3kICxcp5Cfi/xuH 4yHXD3gEhuMOCMB1ZHwCCLoRlSGDfeUmOl6kSlr2C0uRsfmgqcQT84oSp03pN2e/Ng4L 4JWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u/VrgVPkgzQyMENrkjqrTLDR84XHdXIPxg7GPzE6OD8=; b=3lKMLsFHuI/9oQ45Hht505bpxgJhE+SFk5lFLU4hBA8L+cA//7RzdXhCQrDIxAUA7I tHDAKW9xjWtEX3FybbHObHxcw1grB4c5cDuXG1vzBr5/lxg0cMYTHDFg62qwVIwiC3q0 nOnREDOsbs+d08FTvQH4IpD4xTZdYYQUfe/NqAx8Y4zPWER+G8G/X44BsVkXfUkmxtlV xjTIdexsSvuOW/zU0V6MXLuK8tlQ6sqDUyHyrseFCEcite65kGxKS6p37Lc6dMv0FTTq y5fI87vyJxMIQ5R/k7EcLnpKQiTPZE7lAxq+zKnGQsFK1A2VosLFj3wkX44jkEQfqD1p Mo6Q== X-Gm-Message-State: AJIora84keRYD4W4uXTYFj7aHj4kr5wpja/OULZ3DyrtLgrAjnmi5EPi dAX2ZmWSFkJFGMLb32Zqy2k= X-Google-Smtp-Source: AGRyM1stCxr1gM7DIYC9Nmu+TnueYLM+JhpsNdef1mUcnSairJRZL+vZe4MHLjaYJlH6VyT7URSq+Q== X-Received: by 2002:a05:600c:b51:b0:3a1:71b0:a115 with SMTP id k17-20020a05600c0b5100b003a171b0a115mr13622469wmr.41.1656670237475; Fri, 01 Jul 2022 03:10:37 -0700 (PDT) Received: from opensuse.localnet (host-79-53-109-127.retail.telecomitalia.it. [79.53.109.127]) by smtp.gmail.com with ESMTPSA id m12-20020adfe0cc000000b0021d4155cd6fsm3257748wri.53.2022.07.01.03.10.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Jul 2022 03:10:36 -0700 (PDT) From: "Fabio M. De Francesco" To: "Eric W. Biederman" , Ira Weiny 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 Subject: Re: [PATCH] fs: Replace kmap{,_atomic}() with kmap_local_page() Date: Fri, 01 Jul 2022 12:10:33 +0200 Message-ID: <3187836.aeNJFYEL58@opensuse> In-Reply-To: <8735fmqcfz.fsf@email.froward.int.ebiederm.org> References: <20220630163527.9776-1-fmdefrancesco@gmail.com> <8735fmqcfz.fsf@email.froward.int.ebiederm.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1656670239; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=u/VrgVPkgzQyMENrkjqrTLDR84XHdXIPxg7GPzE6OD8=; b=svjHJCGB0SOJQm1Um0gQENtrPVGKmB05vRKNkwLYq7CqIm6Wy/1YWXXF+/TZPr4nSj2WTA gc9HF6VtvtIB9leT00rTQv8solW5IMqGGlFaGBZ+2ViL6viGarg6tpo1mqJtMv6QvZZNxW n0IeZ/TRERnSysrIxMVeqKAph/WZRWw= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656670239; a=rsa-sha256; cv=none; b=DDEwaCbkFalOBfk54b6t1hm8p0ex+PHGrLb77Zzou9Y+tQEIjiiZBf/7yb7gWVe+9JGuMx 47ynSE+WM2xPI+kUykzX46TQmNDCjXTPFexHwDzluqbJwJzvH/3VrVEeftNqTp5SoAKYO4 urWAgfZP/FxrnDL+IodvxkaUWVM0H08= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="C/MmEOGh"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of fmdefrancesco@gmail.com designates 209.85.128.49 as permitted sender) smtp.mailfrom=fmdefrancesco@gmail.com X-Stat-Signature: ffjawk8agfygzb1txei7srfgp4ri71d1 X-Rspam-User: Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="C/MmEOGh"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf04.hostedemail.com: domain of fmdefrancesco@gmail.com designates 209.85.128.49 as permitted sender) smtp.mailfrom=fmdefrancesco@gmail.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 1A99A40045 X-HE-Tag: 1656670238-683982 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 gioved=C3=AC 30 giugno 2022 19:38:08 CEST Eric W. Biederman wrote: > "Fabio M. De Francesco" writes: >=20 > > 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=20 per > > thread, CPU local, and not globally visible. > > > > Tested with xfstests on a QEMU + KVM 32-bits VM booting a kernel with > > HIGHMEM64GB enabled. >=20 > Can someone please refresh my memory on what is going on. >=20 > 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. Please read highmem.rst. I've updated that document weeks ago: https://docs.kernel.org/vm/highmem.html?highlight=3Dhighmem Currently it contains many more information I can ever place here in order= =20 to answer your questions. Believe me, this is not by any means a way to elude your questions. I'm=20 pretty sure that by reading that document you'll have a clear vision on=20 what is going on :-) >=20 > What are the requirements on kmap_local? In copy_strings > kmap is called in contexts that can sleep in page faults No problems with kmap_local_page() with regard to page faults (again,=20 please read the above-mentioned document). =46rom that document... "It=E2=80=99s valid to take pagefaults in a local kmap region []". "Each call of kmap_atomic() in the kernel creates a non-preemptible section= =20 and disable pagefaults. This could be a source of unwanted latency.=20 Therefore users should prefer kmap_local_page() instead of kmap_atomic().". > so any > nearly any requirement except a thread local use is invalidated. >=20 > As you have described kmap_local above it does not sound like kmap_local > is safe in this context, Sorry, probably I should add that taking page faults is allowed. Would you= =20 prefer I send a v2 and add this information? Thanks, =46abio > but that could just be a problem in description > that my poor memory does is not recalling the necessary details to > correct. >=20 > Eric >=20 > > 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=20 user_arg_ptr argv, > > =20 > > if (kmapped_page) { > > =09 flush_dcache_page(kmapped_page); > > - kunmap(kmapped_page); > > + kunmap_local(kaddr); > > =09 put_arg_page(kmapped_page); > > } > > kmapped_page =3D page; > > - kaddr =3D kmap(kmapped_page); > > + kaddr =3D=20 kmap_local_page(kmapped_page); > > kpos =3D pos & PAGE_MASK; > > flush_arg_page(bprm, kpos,=20 kmapped_page); > > } > > @@ -601,7 +601,7 @@ static int copy_strings(int argc, struct=20 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=20 *bprm, > > =20 > > for (index =3D MAX_ARG_PAGES - 1; index >=3D stop; index--) { > > unsigned int offset =3D index =3D=3D stop ? bprm->p &=20 ~PAGE_MASK : 0; > > - char *src =3D kmap(bprm->page[index]) + offset; > > + char *src =3D kmap_local_page(bprm->page[index]) +=20 offset; > > sp -=3D PAGE_SIZE - offset; > > if (copy_to_user((void *) sp, src, PAGE_SIZE - offset)=20 !=3D 0) > > ret =3D -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 =3D -EFAULT; > > goto out; > > } > > - kaddr =3D kmap_atomic(page); > > + kaddr =3D kmap_local_page(page); > > =20 > > for (; offset < PAGE_SIZE && kaddr[offset]; > > offset++, bprm->p++) > > ; > > =20 > > - kunmap_atomic(kaddr); > > + kunmap_local(kaddr); > > put_arg_page(page); > > } while (offset =3D=3D PAGE_SIZE); >=20