From patchwork Sun Jul 24 21:25:23 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: 12927634 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 BA60FC433EF for ; Sun, 24 Jul 2022 21:25:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ADF398E0002; Sun, 24 Jul 2022 17:25:31 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A8E988E0001; Sun, 24 Jul 2022 17:25:31 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92ECB8E0002; Sun, 24 Jul 2022 17:25:31 -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 7ED278E0001 for ; Sun, 24 Jul 2022 17:25:31 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 45CB1801B1 for ; Sun, 24 Jul 2022 21:25:31 +0000 (UTC) X-FDA: 79723274862.30.827DE0E Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) by imf27.hostedemail.com (Postfix) with ESMTP id D506E400B5 for ; Sun, 24 Jul 2022 21:25:30 +0000 (UTC) Received: by mail-ed1-f41.google.com with SMTP id c72so8891768edf.8 for ; Sun, 24 Jul 2022 14:25:30 -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=lC6itZO6h011tufGF0rKTSSMKGZuI2C2c6Vn9aRdYFg=; b=Bh/Ij1mQwBqdj2pO9eQbj85IlSlZpmaQsCeCvxi76zd1z94ilOCMJYj6powy1+Uk7R 0A8cEzDopSPNSY7sYzCiug80nVV1N1OEQnk9za0t5rFBB5y1/nJllI/vbr/5fh38MDao xFJnm6kTIVWW2VXDlJsa8GRU7Xfon2JTc3CVbCZbr7SOVbR8w+tR7Ryhjpmg/b4CbVur ifJwaNZnhCsR+qv2GD00JBomeyh6tEbp1G4nTSVkHsrpoyHiKb7ZQ2R8+IA+b7551Wak VnBSbqqSS3+b+LTf8bHFVznXiidoDAO8SwqqOWOchJL7zeeIt3LOkILzvlnW3TauEROG saXQ== 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=lC6itZO6h011tufGF0rKTSSMKGZuI2C2c6Vn9aRdYFg=; b=wA6Us+IYxwzcRlkwp2lmsFDcxHhw5Ya44SQ7p1dxxxNzocfuJC3YfDej/AThubotxh jCCViYI60Fn794WzT9NjIq8pLxbEpOhTJYAII1QX/NAmU9vrgcyBuOn0g2DGtmzTDmLD 3xHPzCXXUXs/ZB1AlP4ZDMrUrRTBFKBr7qxIkoeQ8EgQBEhJVPPAtVI4exwCtIBRuqfV SuDvGVrvuPvf/XuXHyYBi5MEn6LPe+JkPZ1A7pU2Lea3pt9kJHfGcwxsk2dTIg968XsG 2h1mBNKStWQe7aRg89+/QE6Pg0MtfXJWFyVTbDsZEd2F1zeqZfecJfkj0uO2dwjLxTAZ gwVw== X-Gm-Message-State: AJIora/34ffAJyJPVn/5r2hHaHKd2GWgCHjXhvFdFuR4+Ep5mOek7lBr PvyYofw3RlaYqWufnWucexE= X-Google-Smtp-Source: AGRyM1uzMuqoSLsvWfhyGg9dK8pXT/P4aDk/xiw2TzDnM870HsPlUWlN/kA2pLsQ8GW563x3j52gog== X-Received: by 2002:a05:6402:16:b0:43a:f435:5d07 with SMTP id d22-20020a056402001600b0043af4355d07mr10321597edu.420.1658697929362; Sun, 24 Jul 2022 14:25:29 -0700 (PDT) Received: from localhost.localdomain (host-79-56-6-250.retail.telecomitalia.it. [79.56.6.250]) by smtp.gmail.com with ESMTPSA id ev6-20020a056402540600b0043af8007e7fsm6117001edb.3.2022.07.24.14.25.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Jul 2022 14:25:28 -0700 (PDT) From: "Fabio M. De Francesco" To: Eric Biederman , Kees Cook , Alexander Viro , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Fabio M. De Francesco" , Ira Weiny Subject: [PATCH v2] fs: Call kmap_local_page() in copy_string_kernel() Date: Sun, 24 Jul 2022 23:25:23 +0200 Message-Id: <20220724212523.13317-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.37.1 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1658697930; a=rsa-sha256; cv=none; b=A/mIL2HoFX2IpHBVzKb/qOnQ7IrM3YpOCC//ngOPMqKIGqZcUtsdEUYwgoeN1E8+du6CiK DBmXUfSdS71wSnASPxqnsXD0izI5+FUOrP4JO1mfjoQ1tkOaCdJUViz0YyGVb/EHHZImhR EY32+JbzoO0a+8ARdow7+ovLLQqpTsg= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="Bh/Ij1mQ"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of fmdefrancesco@gmail.com designates 209.85.208.41 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=1658697930; 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=lC6itZO6h011tufGF0rKTSSMKGZuI2C2c6Vn9aRdYFg=; b=nFJBkojt8STlmhEsjDGm+1FNEk/5rv2GdYwLv4X4yE/ACL5TItmBU7zqPrZv40GAErewHT UJnHsX2elObwDUSE7trFFzLDR8T//gViTiH3AO2cKJ0v6C2l85VBP/eR0oOoX/VH9q4NGn VfUjzwCJOEUlku8VRSIE4UYeNe+BXi8= Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b="Bh/Ij1mQ"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf27.hostedemail.com: domain of fmdefrancesco@gmail.com designates 209.85.208.41 as permitted sender) smtp.mailfrom=fmdefrancesco@gmail.com X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: D506E400B5 X-Stat-Signature: o8imfibb4utqcn1pugwd9fnerpp3ztxn X-HE-Tag: 1658697930-869182 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 and not globally visible. Furthermore, the mappings can be acquired from any context (including interrupts). Therefore, replace kmap_atomic() with kmap_local_page() in copy_string_kernel(). Instead of open-coding local mapping + memcpy(), use memcpy_to_page(). Delete a redundant call to flush_dcache_page(). Tested with xfstests on a QEMU/ KVM x86_32 VM, 6GB RAM, booting a kernel with HIGHMEM64GB enabled. Suggested-by: Ira Weiny Signed-off-by: Fabio M. De Francesco --- v1->v2: Instead of open-coding a local mapping + memcpy(), use memcpy_to_page() (thanks to Ira Weiny for his comment on v1). fs/exec.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index d20cb09476f3..eed899188333 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -630,7 +630,6 @@ int copy_string_kernel(const char *arg, struct linux_binprm *bprm) unsigned int bytes_to_copy = min_t(unsigned int, len, min_not_zero(offset_in_page(pos), PAGE_SIZE)); struct page *page; - char *kaddr; pos -= bytes_to_copy; arg -= bytes_to_copy; @@ -639,11 +638,8 @@ 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); 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); + memcpy_to_page(page, offset_in_page(pos), arg, bytes_to_copy); put_arg_page(page); }