From patchwork Thu Jun 30 16:35:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fabio M. De Francesco" X-Patchwork-Id: 12902021 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 E477DC433EF for ; Thu, 30 Jun 2022 16:35:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4C3E88E0001; Thu, 30 Jun 2022 12:35:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 41D318E0006; Thu, 30 Jun 2022 12:35:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 261258E0001; Thu, 30 Jun 2022 12:35:38 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 0F8928E0006 for ; Thu, 30 Jun 2022 12:35:38 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id DA184203DA for ; Thu, 30 Jun 2022 16:35:37 +0000 (UTC) X-FDA: 79635453114.11.50E337B Received: from mail-wm1-f53.google.com (mail-wm1-f53.google.com [209.85.128.53]) by imf27.hostedemail.com (Postfix) with ESMTP id F2EAC40018; Thu, 30 Jun 2022 16:35:35 +0000 (UTC) Received: by mail-wm1-f53.google.com with SMTP id n185so11675451wmn.4; Thu, 30 Jun 2022 09:35:35 -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:mime-version :content-transfer-encoding; bh=lZIrTmlOnvUkLrFbSOhPtwGibISpt/RODIchaEd1CDY=; b=gvOxH2z87z7QsFkRgTQuNhQyyz+dHV1+8rh1sM7GpDupM74IOa6Ym2zyVx4Y0mEnkA xFy3h+4BLgQAGQb7kHWwxfMcgIUz4Tef84LuOZORClSobvlsqYZZA4JRBDfKNY3iS9A8 W3vDemOPYtYp6bt4LA+muwinmH5c50oo9YbK3ghNa7sz/mzg54ZgVTtrFKX2Cgzw+P3N ELSRjvVF4ivQ1YmTMe+MNMmYKoyNYpV+LtXu6h2BXUafKGQrVOGF0X6LVvrsdTzc/XfD EcDDOVPqA+9w2kvc7GCTWMKYCQjY0KUvF3eMQA1meIaibaLIqLPbyUm6YJoKiAbmsj+a uGnA== 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:mime-version :content-transfer-encoding; bh=lZIrTmlOnvUkLrFbSOhPtwGibISpt/RODIchaEd1CDY=; b=3xcfNKp6g3ZGugXXmZcYebclgHA3C7/jnTIxtmfWYVpGpidm6SsG7bUmHZmPNWRE8P Z4d0Gr/5qHvY5fxVFWe/CrG+kMz+mCyT1S1tJU1Xh5iVB2lJLeq9NhcDlDu3mIXHsrRg QkzhozVTPhlUbEO+irM6V5LH8D+Yk8GuUsipyn4l9dKR/MsLg1xonM/MFq3D1yblYr2w om43l0UKHIeCsiXlIB8sXhfPfrnEcsqAUQGCx5aAwQ7ZwDGHxggCOpZX15T8Jg+TkG01 tKzGS2YS0C2DbD3pgjhdpHbUcQrn7+V3y8dszw9Kz0p6RYafJp5VKuAUXpK0iSXSAHe8 /Dfg== X-Gm-Message-State: AJIora+jyE0dX/pkLVtVlBMn7703JB4tXSJqQfTLMsU47Jfh14sMsqWv jJVwtQMoEPB21ax77BAyPgpTweSXepeACg== X-Google-Smtp-Source: AGRyM1sQNe4+WIPmqW10XET/JjOyzodgMYKlJLfdcugPO9fE6FCvfEevPFPhlgS/sBSR469fLSNDFQ== X-Received: by 2002:a1c:4b11:0:b0:3a0:4270:fcfa with SMTP id y17-20020a1c4b11000000b003a04270fcfamr12974836wma.53.1656606933805; Thu, 30 Jun 2022 09:35:33 -0700 (PDT) Received: from localhost.localdomain (host-87-6-98-182.retail.telecomitalia.it. [87.6.98.182]) by smtp.gmail.com with ESMTPSA id u3-20020a05600c210300b003a044fe7fe7sm7112303wml.9.2022.06.30.09.35.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jun 2022 09:35:32 -0700 (PDT) From: "Fabio M. De Francesco" To: 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 Cc: "Fabio M. De Francesco" , Ira Weiny Subject: [PATCH] fs: Replace kmap{,_atomic}() with kmap_local_page() Date: Thu, 30 Jun 2022 18:35:27 +0200 Message-Id: <20220630163527.9776-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1656606936; a=rsa-sha256; cv=none; b=T4GdZw7MCrQOU78JECzeZEWPN7VLN6PhsfsgAbCMEDO3z31gavauVs6cgYnkWEW4/eFU6Q fkJ8wPkhPniPcknCTUpR95IeXO82E7gGimaeW7zP0ztoVNCPnt3Ptdly17dse+OamOsFsY cx+z4Ia8bdUI83kjNK/pwbYDEjsXC+w= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gvOxH2z8; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of fmdefrancesco@gmail.com designates 209.85.128.53 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=1656606936; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=lZIrTmlOnvUkLrFbSOhPtwGibISpt/RODIchaEd1CDY=; b=6+uaQwRUNT/CfIt032YzOKu8pGzFiGt58KGOHPNw8d+xpdx9E2N15XMsri1KDwOk/cOD/M 2VrQoAl0Ulg29ql3tvgavpXNZpHrARVM6AjbeAhvoeQKaUvmbJNQ9HR4BIP11QmmHrdtJ9 aDyAu/IL16Iu7E6MDoCui6fGrtP8EDE= X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: F2EAC40018 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=gvOxH2z8; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of fmdefrancesco@gmail.com designates 209.85.128.53 as permitted sender) smtp.mailfrom=fmdefrancesco@gmail.com X-Rspam-User: X-Stat-Signature: stuz5776jdeumm83irngndxti6zi94ie X-HE-Tag: 1656606935-802184 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: 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. Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco Reviewed-by: Ira Weiny --- 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);