Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp183606imw; Fri, 15 Jul 2022 00:30:56 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tUNbGsiR1ZTHAU91YbWAvQOd1jKgmuPpXgsh2XGZHAlyA99SBmovtpVN4ZqcoBO2YpLtJ3 X-Received: by 2002:a17:90b:278b:b0:1ef:b15e:61e3 with SMTP id pw11-20020a17090b278b00b001efb15e61e3mr20259603pjb.143.1657870255833; Fri, 15 Jul 2022 00:30:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657870255; cv=none; d=google.com; s=arc-20160816; b=HVs9ppTWbiiNH6XkNkhAxa45j/ZLOoEpSvp/IRv5ACuQzY8XXFAVT1UUe/dThaz+qq /fAwVfso+nAU/mI6AwlB2z2iKz1f/+3NUHvXHhSOAq/2o+cCpHPGZy5Q6btbh3YS9y3P Iogncz9QIf7DoFIbK0pDEbwNI03dIz9AA+rREZmfB4VBhvinqRELqr2P4ZwvfFYtDfe8 t5c7k1vb6uTXGu9uXkkaGZY0nZ26lg22wt5RWpKSjA/6ALdZXmtAWCpvnzyDPEnApc4s yhxXofQNfxSZod9m7OdA9a06HipzsgMkqt0+spxqkLr4YrNcruu7xg1yd+R6q3XKjALg ohCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:subject:cc:to:from:message-id :date:dkim-signature:dkim-signature; bh=8+AxnKMTC58vbic8Krxz7ulgXdK0s9k4FRLZIjqwtS8=; b=mtnVpKfXQOJE2XqYevnrez0FRW44PFDm1fmNHMxSQEjMJmBW1jKQYpbopGZXnpL0lu iDwMiKWY4v+CNQGDACRo6MIyswZLQM2bvMbLyCl8X8WMIY995xFQsxeM3V/LkUB9O8Fu 8sxU0CJgJRopfV3TNIo8QpQtYEzB++SElhNCMykZEsQ4BRZdjU4wSI6u6ATFEj3De6+p /vXzsipozteO4v+BZ8Jy6xlkIKRBJ6KfhfS9ewuDrAWen9dKf9CMA8Tidr9vHSV4ddK5 h8r11Q/ijmJ13V6Ap8Hfo7wR9B/vAOpjgiKaXF+/LLi+2zMDaeHeu6mIIRmZsMyWuh9E OsHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b="iaOyxd/4"; dkim=neutral (no key) header.i=@suse.de header.b=U4FvlXJI; 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=suse.de Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h16-20020a170902f71000b0016bf3b32fcfsi4408036plo.492.2022.07.15.00.30.40; Fri, 15 Jul 2022 00:30:55 -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=@suse.de header.s=susede2_rsa header.b="iaOyxd/4"; dkim=neutral (no key) header.i=@suse.de header.b=U4FvlXJI; 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=suse.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231169AbiGOG7q (ORCPT + 99 others); Fri, 15 Jul 2022 02:59:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229462AbiGOG7p (ORCPT ); Fri, 15 Jul 2022 02:59:45 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9A5D1A042; Thu, 14 Jul 2022 23:59:43 -0700 (PDT) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 876AE1FB95; Fri, 15 Jul 2022 06:59:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1657868382; h=from:from:reply-to: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; bh=8+AxnKMTC58vbic8Krxz7ulgXdK0s9k4FRLZIjqwtS8=; b=iaOyxd/49RYSd2zA3+0tNQUcTvDD7022BfqYOwY71q2807Coi19nzWtf3+/x7j2xnYYAd0 kHtX0gzc7szrPBCMRzkNTyQNuEzwKZW1zJ4LrbwXpdb7l7GTBMq2jh7q4HYo7Yum5HpwIY kc9CjGWU0W1zCv8lZLN0pta5lR5m30Q= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1657868382; h=from:from:reply-to: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; bh=8+AxnKMTC58vbic8Krxz7ulgXdK0s9k4FRLZIjqwtS8=; b=U4FvlXJIyPATwQjmF/yLObj/Ed82tlKb6s8Lyh0Vhr88mhfH39Sjuf+v6TgcDXvyyHfGkJ oXC2YvNu2X26V1BQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 4A9D613754; Fri, 15 Jul 2022 06:59:42 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +r1CEV4Q0WJSfgAAMHmgww (envelope-from ); Fri, 15 Jul 2022 06:59:42 +0000 Date: Fri, 15 Jul 2022 08:59:41 +0200 Message-ID: <878roux3mq.wl-tiwai@suse.de> From: Takashi Iwai To: "Fabio M. De Francesco" Cc: Shuah Khan , Greg Kroah-Hartman , Takashi Iwai , Luis Chamberlain , Tianfei zhang , Russ Weight , linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Ira Weiny , kernel test robot Subject: Re: [PATCH v2] firmware_loader: Replace kmap() with kmap_local_page() In-Reply-To: <20220714235030.12732-1-fmdefrancesco@gmail.com> References: <20220714235030.12732-1-fmdefrancesco@gmail.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) Emacs/27.2 Mule/6.0 MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=ISO-8859-7 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 Fri, 15 Jul 2022 01:50:30 +0200, Fabio M. De Francesco wrote: > > The use of 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) kmap() 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. > > kmap_local_page() is preferred over kmap() and kmap_atomic(). Where it > cannot mechanically replace the latters, code refactor should be considered > (special care must be taken if kernel virtual addresses are aliases in > different contexts). > > With kmap_local_page() the mappings are per thread, CPU local, can take > page faults, and can be called from any context (including interrupts). > > Call kmap_local_page() in firmware_loader wherever kmap() is currently > used. In firmware_rw() use the helpers copy_{from,to}_page() instead of > open coding the local mappings + memcpy(). > > Successfully tested with "firmware" selftests on a QEMU/KVM 32-bits VM > with 4GB RAM, booting a kernel with HIGHMEM64GB enabled. > > Cc: Greg Kroah-Hartman > Cc: Luis Chamberlain > Suggested-by: Ira Weiny > Signed-off-by: Fabio M. De Francesco Reviewed-by: Takashi Iwai thanks, Takashi > --- > > v1->v2: According to the comments from Greg Kroah-Hartman (thanks!), > extend the commit message adding information about why kmap() should be > avoided. Delete an unused variable left in the code of v1, which has been > Reported-by: kernel test robot > > drivers/base/firmware_loader/main.c | 4 ++-- > drivers/base/firmware_loader/sysfs.c | 10 ++++------ > 2 files changed, 6 insertions(+), 8 deletions(-) > > diff --git a/drivers/base/firmware_loader/main.c b/drivers/base/firmware_loader/main.c > index ac3f34e80194..7c3590fd97c2 100644 > --- a/drivers/base/firmware_loader/main.c > +++ b/drivers/base/firmware_loader/main.c > @@ -435,11 +435,11 @@ static int fw_decompress_xz_pages(struct device *dev, struct fw_priv *fw_priv, > > /* decompress onto the new allocated page */ > page = fw_priv->pages[fw_priv->nr_pages - 1]; > - 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); > fw_priv->size += xz_buf.out_pos; > /* partial decompression means either end or error */ > if (xz_buf.out_pos != PAGE_SIZE) > diff --git a/drivers/base/firmware_loader/sysfs.c b/drivers/base/firmware_loader/sysfs.c > index 5b0b85b70b6f..77bad32c481a 100644 > --- a/drivers/base/firmware_loader/sysfs.c > +++ b/drivers/base/firmware_loader/sysfs.c > @@ -242,19 +242,17 @@ static void firmware_rw(struct fw_priv *fw_priv, char *buffer, > loff_t offset, size_t count, bool read) > { > while (count) { > - void *page_data; > int page_nr = offset >> PAGE_SHIFT; > int page_ofs = offset & (PAGE_SIZE - 1); > int page_cnt = min_t(size_t, PAGE_SIZE - page_ofs, count); > > - page_data = kmap(fw_priv->pages[page_nr]); > - > if (read) > - memcpy(buffer, page_data + page_ofs, page_cnt); > + memcpy_from_page(buffer, fw_priv->pages[page_nr], > + page_ofs, page_cnt); > else > - memcpy(page_data + page_ofs, buffer, page_cnt); > + memcpy_to_page(fw_priv->pages[page_nr], page_ofs, > + buffer, page_cnt); > > - kunmap(fw_priv->pages[page_nr]); > buffer += page_cnt; > offset += page_cnt; > count -= page_cnt; > -- > 2.37.0 >