From patchwork Sun Jul 10 10:01:36 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: 12912498 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 674A3C433EF for ; Sun, 10 Jul 2022 10:01:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 628C48E0005; Sun, 10 Jul 2022 06:01:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5AB648E0001; Sun, 10 Jul 2022 06:01:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 422CB8E0002; Sun, 10 Jul 2022 06:01:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 302B88E0001 for ; Sun, 10 Jul 2022 06:01:47 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id EF77C802C1 for ; Sun, 10 Jul 2022 10:01:46 +0000 (UTC) X-FDA: 79670748612.05.7DE1162 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) by imf29.hostedemail.com (Postfix) with ESMTP id 01E1B120065; Sun, 10 Jul 2022 10:01:45 +0000 (UTC) Received: by mail-wr1-f48.google.com with SMTP id a5so3570633wrx.12; Sun, 10 Jul 2022 03:01:45 -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=81hvwpBlfxQBH7APOHFnmGU6Oy26r79hMsY7b8ngUnA=; b=LaBR8No6eDA8e9Rql/Q8hpGkLLfuSD5/EMXQepcthh8cGp7UjbSFP1k9BsyzXUHnNy /Tpq4atRiIOMgSMJhXBMpDbldJ1g4b5k0jQCcLGn8jfGRoB7x/q/8CTNYecJfV/bu4Bo MERWiqyGTdkZFrXjwSPTS3Z7Yn+KmnzXcWrJiE8YusI2QP2MhVEHWCSDIj8F43mtTiYZ TEX0Th1RPImvZ0IVeKx1UMGztnYZGsQwur0HjBXDJzClOHfTYfzZhOg8rixDdLobrGug oZU4dhUGGW50vkkWM5cZ8x/txINWUWLWL80giRRZdFN9hqvwmfL00pFxL7khmpX45EwE onMw== 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=81hvwpBlfxQBH7APOHFnmGU6Oy26r79hMsY7b8ngUnA=; b=wjpmqNCbfmy1COZmB0ySGwJmUE9H8o/hLesBhJjfsof5CdOATGDOSE+EPKQuL8uwff tHMoFMHZIzoRNXI50gxe097LlsE8tlMjM6Lgnb2KTyGlz7fMu6j+Ms5b/FUTqBqqFEfU 9E2/H1zct7dbB7AahvV+GJAhKlXqREhxZ87g4Q4k6ZlVR1vHLF4RSF1PqSPPDdRaHucF 4Tm9/A0IaVtzECz3VgxHQYcqfY5H4cd9yAGy4phnBWAqbEHF454IMvZQdxhb/he2V3rp AnAxpfoUeaTwAeZlhVMoqqf1Y4frw2VG04mJFpZu8GsGULcux05n8YsjE+0M5DmMs3V+ 3buA== X-Gm-Message-State: AJIora96rAyjzRsZPwdJx6VOJZafKl6i+hI1uPlRfKTyQPq9duqzXfe7 gww5bcIyXX1PYTIyO2TNm62esqbS/iA1ow== X-Google-Smtp-Source: AGRyM1t1D8hDiyos2lkhzHSCdCKBxQy3yBejjsdGsbA5T1lQgpocurWl0ACdlPHS4JNTO6vo74nRPw== X-Received: by 2002:a05:6000:54f:b0:21b:944c:c70b with SMTP id b15-20020a056000054f00b0021b944cc70bmr12117283wrf.572.1657447303959; Sun, 10 Jul 2022 03:01:43 -0700 (PDT) Received: from localhost.localdomain (host-95-235-102-55.retail.telecomitalia.it. [95.235.102.55]) by smtp.gmail.com with ESMTPSA id r7-20020a05600c434700b003a2da6b2cbesm3502026wme.33.2022.07.10.03.01.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 10 Jul 2022 03:01:42 -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: Call kmap_local_page() in copy_string_kernel() Date: Sun, 10 Jul 2022 12:01:36 +0200 Message-Id: <20220710100136.25496-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1657447306; 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=81hvwpBlfxQBH7APOHFnmGU6Oy26r79hMsY7b8ngUnA=; b=jbGX644XxZYUMex1APrjZufxFfwjxgeudfh1Ii3UQGTZg3KQgMAWhNrrNXxoVhTeHYcy2I u7btFbq3uDIedA2t1vc59lIGXdVoc5Wzok1pUKCrdt8Hx4+pRxfl0z7EXk2dw+ttC2ES/g hvU3AU3hZuhiLQrDGbD5B/9Z5ZjMfb0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657447306; a=rsa-sha256; cv=none; b=xKDmeb5U+qJ/FFaDrFpZw7q3LBEcYnFvH/IlD2EVzUCSiv7a01qBwOjb7R2urPXn146dRV STEG/t7YBjj/JU8ALhLu7hKeKc5Sb/EoJQ/moYVCxsyrVshKlQpxJ6Va50HBptbxupCRr2 3K3vE2kdNyRVm6e8TZYhK71SKh84BdM= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=LaBR8No6; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of fmdefrancesco@gmail.com designates 209.85.221.48 as permitted sender) smtp.mailfrom=fmdefrancesco@gmail.com X-Stat-Signature: qkb7bkjtuxepah858jyqzgdkpe96mehq X-Rspam-User: Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=LaBR8No6; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of fmdefrancesco@gmail.com designates 209.85.221.48 as permitted sender) smtp.mailfrom=fmdefrancesco@gmail.com X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 01E1B120065 X-HE-Tag: 1657447305-178487 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_atomic() is being deprecated in favor of kmap_local_page(). With kmap_local_page(), the mappings are per thread, CPU local, not globally visible and can take page faults. Furthermore, the mappings can be acquired from any context (including interrupts). Therefore, use kmap_local_page() in copy_string_kernel() instead of kmap_atomic(). 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 --- I sent a first patch to fs/exec.c for converting kmap() and kmap_atomic() to kmap_local_page(): https://lore.kernel.org/lkml/20220630163527.9776-1-fmdefrancesco@gmail.com/ Some days ago, Ira Weiny, while he was reviewing that patch, made me notice that I had overlooked a second kmap_atomic() in the same file (thanks): https://lore.kernel.org/lkml/YsiQptk19txHrG4c@iweiny-desk3/ I've been asked to send this as an additional change. This is why there will not be any second version of that previous patch. fs/exec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 linux_binprm *bprm) page = get_arg_page(bprm, pos, 1); if (!page) return -E2BIG; - kaddr = kmap_atomic(page); + kaddr = kmap_local_page(page); flush_arg_page(bprm, pos & PAGE_MASK, page); memcpy(kaddr + offset_in_page(pos), arg, bytes_to_copy); flush_dcache_page(page); - kunmap_atomic(kaddr); + kunmap_local(kaddr); put_arg_page(page); }