Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp4002940rwb; Tue, 16 Aug 2022 12:32:16 -0700 (PDT) X-Google-Smtp-Source: AA6agR7TmghabwJKlou3/X0uY+nubcND6AwnqXhI04TzFd62tK9CmLpFWv6qeD9Z6LqW2tywoBmt X-Received: by 2002:a17:903:230e:b0:16f:784:ea3f with SMTP id d14-20020a170903230e00b0016f0784ea3fmr23171558plh.160.1660678336691; Tue, 16 Aug 2022 12:32:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660678336; cv=none; d=google.com; s=arc-20160816; b=tc4rc2i2EWfIEJxJUSkRN5C7RRQZLq4QL59vs7CYcm7XgL6Wd/QUq6ESi0cWrpbPoV ZH/RlqH26KURxHPZQ9yA5JP6C+yf0eis+mcjj/LElfrwj0aGflOBZSZhjLLZqbGSqtbN wJt7cmX/prOQKtd29v3vyDGt97rrsX/Xepqhu37Ixb/ZXAiIjk7vZscGhHpxeRT4Wc56 msWocnRg7e37VLBvfOLXNvd3bjbOo9uER7f+CWPzUS2rL3Ciz3TBH1xS8SXEW2FYV5ZW TfB9wsRbRa8Ux6nNxWxi5MM/aVO1W3wiQn7HHG6YCld+S+regPeXELI2lOuTmezy6QhV r9Ag== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=nssVLWGkSozCP2prxT0MLzeStZK7aNTTPyXYDkMAmNY=; b=Cxd47wdhmamW8a5xU6eIHwiJ+g7BsWJ/tLhf6Ck7vwgDjaktmIwYlYZ7rjWU3eFYqv SxayfZyREGb/1tkWz1tE54eCtuuoZmGT8ykaBvZ+mtgTgn2pWX6dfjbWjXACA+1MBQU6 IzlPKV0xRGQSeK18fexGJSjXwchooUPEAyi7l/ZUZPP7TWsj8zd8nOGwyQyl80+ihBSu u/Cmu+Zg3GAj9MeUQoCj3m17zVlj/U/JYzE3J/+4lYFND0rBlFXNaz+M14IuTbzKtDiX HPea5RBHZbctRsQBlGoAfPY2dM9Obpfn17jq9V6J7egGqcgZ1xgC1uujRobW99TFYJNI 8mCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dTA84z7j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p9-20020a1709026b8900b0017123d2abd5si12041163plk.457.2022.08.16.12.32.02; Tue, 16 Aug 2022 12:32:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=dTA84z7j; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236847AbiHPTJA (ORCPT + 99 others); Tue, 16 Aug 2022 15:09:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232426AbiHPTIu (ORCPT ); Tue, 16 Aug 2022 15:08:50 -0400 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F9BD53020 for ; Tue, 16 Aug 2022 12:08:47 -0700 (PDT) Received: by mail-pg1-x532.google.com with SMTP id 73so10052984pgb.9 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=DZbU6N2tIpqMQp+JbidtQf6/HK7r3O+KokpWroCVLHUAZGKL7l7NQucGsGhWxAAlcd DlrWt7cm6y3em+3WkFXBzeHFmfM1gXc6UO2VHBMxYW2W/LkGnTcdJsiUuQ5VXTmaFBMj 7d3VCj0NvRplNKPccUTjzkmg2eKkt/KWJ+P8Cr3/h9bwu3aDJ7lWUaWG/xYNqgTlvJLd aqlHAPFpfpGJ1Vypvn9/T+m1SYlP/xrn6rkPpD/HFJ1f35R+eKax7ohLfnkc4Wj3giTE GX3xcalPOkoDhWyafAqqjaqVY3j7a/ePzDwOGYDK9KLW6vjcnqYhVGjAOxLQysRjpTiP 6aqg== X-Gm-Message-State: ACgBeo1pPDzZu8Vb/1itbCbMrEmrv0sXr1s2ysDv4SnL6aeVsD0ALjmv WzvOeoA9VEl0FhUs5ywBwZzOo3TRGZ1yOw== 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> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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