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 D38E4C2BB41 for ; Tue, 16 Aug 2022 19:08:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2B97F6B0073; Tue, 16 Aug 2022 15:08:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 242AC8D0002; Tue, 16 Aug 2022 15:08:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0BBDF8D0001; Tue, 16 Aug 2022 15:08:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id EBF1C6B0073 for ; Tue, 16 Aug 2022 15:08:49 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AC3A41408B1 for ; Tue, 16 Aug 2022 19:08:49 +0000 (UTC) X-FDA: 79806392778.02.8E63F57 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) by imf06.hostedemail.com (Postfix) with ESMTP id 1C34D1801A2 for ; Tue, 16 Aug 2022 19:08:47 +0000 (UTC) Received: by mail-pg1-f173.google.com with SMTP id c24so10048612pgg.11 for ; Tue, 16 Aug 2022 12:08:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc; bh=nssVLWGkSozCP2prxT0MLzeStZK7aNTTPyXYDkMAmNY=; b=dTA84z7jwhcwlnw4Kaod43Raw7zJOjVO3Y2P5TI4q6HuZXPkle236cvUxikwrR1IK/ U4j4cn24hVd4sl7B/K0bF4vF9rnk1HwMZa3QyrC5mdRETd5IaEDZDcD+pWZOqBpNGeHo 59sY34hNBZUfCkaobNGgsdWVMmj10MO0HtGzM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc; bh=nssVLWGkSozCP2prxT0MLzeStZK7aNTTPyXYDkMAmNY=; b=6eb1zjF3FxUp3BczT8CjN9w0TuljHX6URIpNOkmHqGorsr1rXzAn5+wGvf7JpVd/Ui sP8vdE5UOJwxpne0j3N/e87m+I3sBzwor1qJlSiFO+0tWureuoI8JLFB8XE5w+A85/yN ZssR0FHR3LdYaCE7s6vDM7JaoMAASyts8jqaLZx+8olh7PgOfXR4RYZVxaPFzW/f7fZu NgM0SkPr+RbmBEFnOVAVBm5VCkpeVly8UQhfWNsS3YfDrhmWM/4VFaxfmtUBuYg8Z7Yj hi9UifI9GwrANfa0hF3xhP94XVK/PS2pouURFEwTYX3tI6KsyEZdVMqok/CWIYi1GNrs TcZQ== X-Gm-Message-State: ACgBeo1EJJ1hkd5CMWycXzyh58K7WTRRChEcrHfTt1n8QjpZmvWQQBop c2qC2HNphlVUYz00joGrzHXbPA== X-Google-Smtp-Source: AA6agR4YtXTGF4jQT4B50vbSzKctSMj1hbrPKLGlAvMXXD20DDT7x4n08bEJKh2CHXm2IxfCt+g0tQ== X-Received: by 2002:a05:6a00:2192:b0:52f:6541:6819 with SMTP id h18-20020a056a00219200b0052f65416819mr22396569pfi.83.1660676926841; Tue, 16 Aug 2022 12:08:46 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id f12-20020a170902684c00b0016c454598b5sm9360527pln.167.2022.08.16.12.08.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 12:08:45 -0700 (PDT) Date: Tue, 16 Aug 2022 12:08:44 -0700 From: Kees Cook To: "Fabio M. De Francesco" Cc: Alexander Viro , Eric Biederman , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Ira Weiny Subject: Re: [PATCH v2] fs: Replace kmap{,_atomic}() with kmap_local_page() Message-ID: <202208161208.705E007@keescook> References: <20220803182856.28246-1-fmdefrancesco@gmail.com> <8143586.NyiUUSuA9g@opensuse> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <8143586.NyiUUSuA9g@opensuse> ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660676928; a=rsa-sha256; cv=none; b=L5Qy/ID1xI3+ElW5c+tt0iwifnjUCmMxgwuFswdsZHZDvwzG0pZBuL94JZMapInvvQIJJm GqUo/R3qSVeoPnA1WFjbqoh2tUInNrdspTfKFbSxvWz5qzCrWof5qDpoPGFqdLmPDIL7Sw xyBuxVeDdyvYqU7bQ9nHwfnV6SGgY74= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=dTA84z7j; spf=pass (imf06.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.173 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660676928; 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=nssVLWGkSozCP2prxT0MLzeStZK7aNTTPyXYDkMAmNY=; b=zQRgtJ67i9ZcjX9sLjIC5xEwLbotjeZgUw4PCHF8yrElmZPB1Eu9h1fH+pcN8W7sCDSIY2 6/JBQiBotMZxKcR52X/sk4Ubk9JzaFw7/43WH859CVsPh991Wna77O8/GxvrOCzySspR3w bHsUIUa5pz9uEl6cTL4z8L4CEhqBBNQ= X-Stat-Signature: tktk8o1p65917xmsf6zqq3d89sehp1my X-Rspamd-Queue-Id: 1C34D1801A2 Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=dTA84z7j; spf=pass (imf06.hostedemail.com: domain of keescook@chromium.org designates 209.85.215.173 as permitted sender) smtp.mailfrom=keescook@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspam-User: X-Rspamd-Server: rspam03 X-HE-Tag: 1660676927-432564 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 Sat, Aug 13, 2022 at 03:36:53PM +0200, Fabio M. De Francesco wrote: > On mercoledì 3 agosto 2022 20:28:56 CEST Fabio M. De Francesco wrote: > > The use of kmap() and kmap_atomic() are being deprecated in favor of > > kmap_local_page(). > > > > There are two main problems with kmap(): (1) It comes with an overhead as > > mapping space is restricted and protected by a global lock for > > synchronization and (2) it also requires global TLB invalidation when the > > kmap’s pool wraps and it might block when the mapping space is fully > > utilized until a slot becomes available. > > > > With kmap_local_page() the mappings are per thread, CPU local, can take > > page faults, and can be called from any context (including interrupts). > > It is faster than kmap() in kernels with HIGHMEM enabled. Furthermore, > > the tasks can be preempted and, when they are scheduled to run again, the > > kernel virtual addresses are restored and are still valid. > > > > Since the use of kmap_local_page() in exec.c is safe, it should be > > preferred everywhere in exec.c. > > > > As said, since kmap_local_page() can be also called from atomic context, > > and since remove_arg_zero() doesn't (and shouldn't ever) rely on an > > implicit preempt_disable(), this function can also safely replace > > kmap_atomic(). > > > > Therefore, replace kmap() and kmap_atomic() with kmap_local_page() in > > fs/exec.c. > > > > Tested with xfstests on a QEMU/KVM x86_32 VM, 6GB RAM, booting a kernel > > with HIGHMEM64GB enabled. > > > > Cc: Eric W. Biederman > > Suggested-by: Ira Weiny > > Reviewed-by: Ira Weiny > > Signed-off-by: Fabio M. De Francesco > > --- > > > > v1->v2: Added more information to the commit log to address some > > objections expressed by Eric W. Biederman[1] in reply to v1. No changes > > have been made to the code. Forwarded a tag from Ira Weiny (thanks!). > > > > [1] > > https://lore.kernel.org/lkml/8735fmqcfz.fsf@email.froward.int.ebiederm.org/ > > > > fs/exec.c | 14 +++++++------- > > 1 file changed, 7 insertions(+), 7 deletions(-) > > > > Hi Kees, > > After that thread about the report from Syzbot, and the subsequent discussion, > I noticed that you didn't yet take this other patch for exec.c. > > I suppose that the two patches would better go out together. So I'm writing > for sending a gentle ping. > > As I said, no changes have been made to the code with respect to v1 (which I > submitted in June). However, later I thought that adding more information > might have helped reviewers and maintainers to better understand the why of > this patch. Oops, thanks for the ping. I'll pull this now. -- Kees Cook