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 F3156C43334 for ; Sat, 23 Jul 2022 01:02:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 49A2D6B0071; Fri, 22 Jul 2022 21:02:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 45F006B0073; Fri, 22 Jul 2022 21:02:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 34D9F6B0074; Fri, 22 Jul 2022 21:02:38 -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 263ED6B0071 for ; Fri, 22 Jul 2022 21:02:38 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 007DD120DD1 for ; Sat, 23 Jul 2022 01:02:37 +0000 (UTC) X-FDA: 79716564396.28.F9D7030 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) by imf31.hostedemail.com (Postfix) with ESMTP id 234B22008D; Sat, 23 Jul 2022 01:02:36 +0000 (UTC) Received: by mail-ed1-f48.google.com with SMTP id x91so7611012ede.1; Fri, 22 Jul 2022 18:02:36 -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=jlyu+Ezdns1o/Dl+mNDx1dSSzCArmmCHe5zOulHCgYY=; b=PZsBl5ooCfsAyfBssviyiVR5Tq1jj7pKvSq+8EIYiuLRuANId3eEJ8Cfne0oRH5tST cNckwvwkYNCJil7c4bHdQwdq+1j/ZICMbKPDmupGpGkjuYuypwIlqr25b/2zb8nGj+L7 8X6BT7i0cfdvLYah+oB/+uw18/v7O2tlssjrHraunx39DcQd6oIsFM91LN1KRUjOeySk 107g886IDOhDMfSuVZ8M22SN2x2lCSM95MlNgPfYmjNiwur+gHG+g9710+/nPbgwn0jJ VB2nk9BZ+suPliZX/YIqKiK3alTptYuhcFjUg7RbgvcF8nWJZFV9um7H8k3hL7Y+Q5TY PsjA== 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=jlyu+Ezdns1o/Dl+mNDx1dSSzCArmmCHe5zOulHCgYY=; b=5CJpDdntARVQrIxd/eqUzNLgX9MUsvTJjg9hI3mGs9s4rxMVgVv48itqz7pFbIG3oP JJscxzzRA09s66l+eODFsv2XPRLMPhO/3NG33CFsmY5triQWN6i4ZciIJVqK18KIWR9m fZX02ZmzULDdm5bJ4G27qVu4SpzKbjQms2JUasNsBlfkuLB1Gmc/184/y0LTHzq0l7CH 7N9L0FdE5I+ouMfWeMr2ieaypWJIN77to1HDlIOfA7+6+haQ0v5Zmk/fKT5wC8+q0Dby enAC9a0EYtYMnmc+zGJ40pu4yfF4I3XYxu6/PaltesLpRI9MhguqwqAG+N5AdH/bBnEp +0+A== X-Gm-Message-State: AJIora8seshpSCVb3syUpQVhBB0d5HbObNvkST37IVLcLcWZN0TxbE8E e71IHLHOoBMPGDgZ681Qt7g= X-Google-Smtp-Source: AGRyM1sAMP8KHkAWh5bS378ppL8TdO4StC0sEC6TB/Rq2m5BGNgizfRRhPByQs8fPv0/46kAMhGelA== X-Received: by 2002:a05:6402:524d:b0:43a:72fe:76b7 with SMTP id t13-20020a056402524d00b0043a72fe76b7mr2211131edd.398.1658538155443; Fri, 22 Jul 2022 18:02:35 -0700 (PDT) Received: from opensuse.localnet (host-79-56-6-250.retail.telecomitalia.it. [79.56.6.250]) by smtp.gmail.com with ESMTPSA id r10-20020a1709061baa00b0071cef8bafc3sm2549153ejg.1.2022.07.22.18.02.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Jul 2022 18:02:34 -0700 (PDT) From: "Fabio M. De Francesco" To: Ira Weiny Cc: Benjamin LaHaise , Alexander Viro , Eric Biederman , 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: Call kmap_local_page() in copy_string_kernel() Date: Sat, 23 Jul 2022 03:02:32 +0200 Message-ID: <2115146.irdbgypaU6@opensuse> In-Reply-To: References: <20220710100136.25496-1-fmdefrancesco@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" ARC-Authentication-Results: i=1; imf31.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=PZsBl5oo; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf31.hostedemail.com: domain of fmdefrancesco@gmail.com designates 209.85.208.48 as permitted sender) smtp.mailfrom=fmdefrancesco@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1658538157; 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=jlyu+Ezdns1o/Dl+mNDx1dSSzCArmmCHe5zOulHCgYY=; b=n7MuIQpjeIBJ3bg78+CF5+wBHIkaV5rt79RtQCe2qwCcdWAPrDBE+4HnUNahUimyuHM/Fe YrSJd7VwtVxas7MDnqqVo5yYWbB6Ovx2IinMLp1xxKuEmlUpLBRoemdjbtx9Iv9Ywcwn2z XYnszEEC77DkRvY3iKPAigp01Jkbhko= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658538157; a=rsa-sha256; cv=none; b=dwxl5hdAvWkroOE2KaoVugRnHjzCXMIxTcZt+vxGWGVVHev+8LbIfrT8YJN4uNXwvN8mFG 0rQZtfn+l/Nc+bcGNWyYH7iJ2wfKhl/iNM+Bu5R2tcIFOIyZ5LOIdVTIBBEgWTzN6KvX6C OBkLT39ljRhIrc2zdCd9IISm51pynCE= X-Rspam-User: X-Stat-Signature: wa97efyx7jj5irdf8i4fpggnka736stf X-Rspamd-Queue-Id: 234B22008D Authentication-Results: imf31.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=PZsBl5oo; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf31.hostedemail.com: domain of fmdefrancesco@gmail.com designates 209.85.208.48 as permitted sender) smtp.mailfrom=fmdefrancesco@gmail.com X-Rspamd-Server: rspam04 X-HE-Tag: 1658538156-393810 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 venerd=C3=AC 22 luglio 2022 02:14:20 CEST Ira Weiny wrote: > On Sun, Jul 10, 2022 at 12:01:36PM +0200, Fabio M. De Francesco wrote: > > The use of kmap_atomic() is being deprecated in favor of=20 kmap_local_page(). > >=20 > > With kmap_local_page(), the mappings are per thread, CPU local, not > > globally visible and can take page faults. Furthermore, the mappings=20 can be > > acquired from any context (including interrupts). > >=20 > > Therefore, use kmap_local_page() in copy_string_kernel() instead of > > kmap_atomic(). > >=20 > > Tested with xfstests on a QEMU + KVM 32-bits VM booting a kernel with > > HIGHMEM64GB enabled. > >=20 > > Suggested-by: Ira Weiny > > Signed-off-by: Fabio M. De Francesco > > --- > >=20 > > I sent a first patch to fs/exec.c for converting kmap() and=20 kmap_atomic() > > to kmap_local_page(): > > https://lore.kernel.org/lkml/20220630163527.9776-1-fmdefrancesco@gmail.= com/ > >=20 > > Some days ago, Ira Weiny, while he was reviewing that patch, made me=20 notice > > that I had overlooked a second kmap_atomic() in the same file (thanks): > > https://lore.kernel.org/lkml/YsiQptk19txHrG4c@iweiny-desk3/ > >=20 > > I've been asked to send this as an additional change. This is why there= =20 will > > not be any second version of that previous patch. > >=20 > > fs/exec.c | 4 ++-- > > 1 file changed, 2 insertions(+), 2 deletions(-) > >=20 > > diff --git a/fs/exec.c b/fs/exec.c > > index 4a2129c0d422..5fa652ca5823 100644 > > --- a/fs/exec.c > > +++ b/fs/exec.c > > @@ -639,11 +639,11 @@ int copy_string_kernel(const char *arg, struct=20 linux_binprm *bprm) > > page =3D get_arg_page(bprm, pos, 1); > > if (!page) > > return -E2BIG; > > - kaddr =3D kmap_atomic(page); > > + kaddr =3D kmap_local_page(page); > > flush_arg_page(bprm, pos & PAGE_MASK, page); >=20 > I really question why we can't use memcpy_to_page() here and move the > flush_arg_page() prior to the mapping? >=20 > flush_arg_page() only calls flush_cache_page() which does not need the > mapping to work correctly AFAICT. You're right here. I'm sorry for being so lazy and not checking that=20 flush_arg_page() does not need to be called while the task holds the local= =20 mapping :-( In v2 I'll move flush_arg_page() one line above memcpy_to_page(). Thanks for your comment, =46abio >=20 > Ira >=20 > > memcpy(kaddr + offset_in_page(pos), arg,=20 bytes_to_copy); > > flush_dcache_page(page); > > - kunmap_atomic(kaddr); > > + kunmap_local(kaddr); > > put_arg_page(page); > > } > > =20 > > --=20 > > 2.36.1 > >=20 >=20