Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3823435imw; Mon, 18 Jul 2022 15:21:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1srpju73J/Zm2hG+j1xIJRJ9Mhjs8hBdBtJDpxPm+gaL/mGfYu6Px2km3ppmSxzfeLe/wGw X-Received: by 2002:a05:6402:270d:b0:43a:d1e8:460b with SMTP id y13-20020a056402270d00b0043ad1e8460bmr39402233edd.40.1658182909633; Mon, 18 Jul 2022 15:21:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658182909; cv=none; d=google.com; s=arc-20160816; b=Rar19zdo2NM/xi0uoiqdkoW6xzAVjvJtzIgAWKh/eAb3peZcOav/x5lUSajmZA0E7t f9khF6GQkKLDT4/LUdhUeiFozLgxguAqcOsQFopNBUHwoivhhn+yWy+2u7yvDp86fWoV YYqy1fV5ch9Widvevy1bu6vyYUHBqMARdJjb+ct+2jRYquj+G57ID280LrA2NBgqbH27 1oUL1PvQ/0b026xP87sVZHLrCNpYBSHRHShBm0A8tGi6CWWJodXG6sVByv/EIj08u/U6 L00+5CoMIjcLry98B5V6vVI6b7ecHoi89tN6be7uJWEUdBI1mlUMgXgJZKZb7c5gwM51 F9rQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=iN+8ckeB+moKTuuo5xeEEoN4N4ajBlWTzFr+sY0u/zk=; b=qY1pUgTyK/C6OTSN1Q9GvVsf87PekgrjRyMBWaM0YC6TsIL1Q3MrcAhkw4os17gqTP hveMmV3PfQIOKZibVPerqh5i3MGSEhCHNTQ/lX+RgfA+B3vLmJUiQfY7s5ZzjDiclvgq 3sD/WGMIUDOYTi9bkuh2rCOqHwx3VG1fbLJozjqQTZryNa/DXrVgCAp/MVAQh4C9IhoC Zaq3GTihTT6q/SZpyhU4RIGImXcP8kaQagGv4EXf04eEoWXtLteyA0dBz0ikTziN+AfE wg6xV27ov8gOIzNx7SNnHTrHxuhbXJQNSLyxolIR4LQphLbfViSzGdfJqMIh2KGUGFxz W+Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20210309 header.b="A5/4af9d"; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb18-20020a1709077e9200b0072aed50f0ffsi18795027ejc.663.2022.07.18.15.21.24; Mon, 18 Jul 2022 15:21:49 -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=@infradead.org header.s=bombadil.20210309 header.b="A5/4af9d"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234683AbiGRWT5 (ORCPT + 99 others); Mon, 18 Jul 2022 18:19:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbiGRWT4 (ORCPT ); Mon, 18 Jul 2022 18:19:56 -0400 Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 941F0220D6; Mon, 18 Jul 2022 15:19:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Sender:In-Reply-To: Content-Transfer-Encoding:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description; bh=iN+8ckeB+moKTuuo5xeEEoN4N4ajBlWTzFr+sY0u/zk=; b=A5/4af9dxXQ8ntBSgoGZGyzwFP 1wknE3xceMJ46Gvk8mIRYD6PiSgL4IOVKNo/juSig7ZnVyDs8whTQ3nQDPeT/ZhDjNGlPzCjvlZqd Dv44aB9nqAzwzjlZnwdTvznrb6uN0LLN6WEALbYwPuG/v7NyNrnuW8+tINZWVYjzL5nUFUFCo7tsb ZKnvP78rBOVE3J+tNqBuOklRM/dwqZb4XHLEnR5N06io8aTwvYn/xR01HRr4KDEf6bgOoXBT6k2By C1iAL0GknWxIuDEHXidJ9c7fgkowMQm+1YHN/SZQTTEzEq097K7OtE7TNUT/Rj55mkJmu2yAaaIk3 t5xFTtHQ==; Received: from mcgrof by bombadil.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1oDZ5i-00241Q-6z; Mon, 18 Jul 2022 22:19:50 +0000 Date: Mon, 18 Jul 2022 15:19:50 -0700 From: Luis Chamberlain To: "Fabio M. De Francesco" , Matthew Wilcox , Song Liu , Takashi Iwai , Adam Manzanares , Davidlohr Bueso Cc: linux-modules@vger.kernel.org, linux-kernel@vger.kernel.org, Ira Weiny Subject: Re: [PATCH] module: Replace kmap() with kmap_local_page() Message-ID: References: <20220718002645.28817-1-fmdefrancesco@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20220718002645.28817-1-fmdefrancesco@gmail.com> Sender: Luis Chamberlain X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE 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 Mon, Jul 18, 2022 at 02:26:45AM +0200, Fabio M. De Francesco wrote: > kmap() is being deprecated in favor of kmap_local_page(). > > 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. Neat! > With kmap_local_page() the mappings are per thread, CPU local, can take > page faults, and can be called from any context (including interrupts). Yes but the mapping can only be accessed from within this thread and the thread is bound to the CPU while the mapping is active. So, what if we get a preemption during decompression here? What happens? > It is faster than kmap() in kernels with HIGHMEM enabled. Its use in > module_gzip_decompress() and in module_xz_decompress() is safe and > should be preferred. > > Therefore, replace kmap() with kmap_local_page(). While this churn is going on everywhere I was wondering why not go ahead and adopt kmap_local_folio() instead? Luis > Tested on a QEMU/KVM x86_32 VM with 4GB RAM, booting kernels with > HIGHMEM64GB enabled. Modules compressed with XZ or GZIP decompress > properly. > > Suggested-by: Ira Weiny > Signed-off-by: Fabio M. De Francesco > --- > kernel/module/decompress.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/kernel/module/decompress.c b/kernel/module/decompress.c > index 2fc7081dd7c1..4d0bcb3d9e44 100644 > --- a/kernel/module/decompress.c > +++ b/kernel/module/decompress.c > @@ -119,10 +119,10 @@ static ssize_t module_gzip_decompress(struct load_info *info, > goto out_inflate_end; > } > > - s.next_out = kmap(page); > + s.next_out = kmap_local_page(page); > s.avail_out = PAGE_SIZE; > rc = zlib_inflate(&s, 0); > - kunmap(page); > + kunmap_local(s.next_out); > > new_size += PAGE_SIZE - s.avail_out; > } while (rc == Z_OK); > @@ -178,11 +178,11 @@ static ssize_t module_xz_decompress(struct load_info *info, > goto out; > } > > - xz_buf.out = kmap(page); > + xz_buf.out = kmap_local_page(page); > xz_buf.out_pos = 0; > xz_buf.out_size = PAGE_SIZE; > xz_ret = xz_dec_run(xz_dec, &xz_buf); > - kunmap(page); > + kunmap_local(xz_buf.out); > > new_size += xz_buf.out_pos; > } while (xz_buf.out_pos == PAGE_SIZE && xz_ret == XZ_OK); > -- > 2.37.1 >