Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1518531iog; Tue, 14 Jun 2022 07:38:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s50DwWZlcdDkznNmHELisoSHlf0BTH+x7G00FKjyrL8JIkD33jcgYS1g3o8MSETRwTdRmh X-Received: by 2002:a17:90a:bd89:b0:1e3:50de:5ccf with SMTP id z9-20020a17090abd8900b001e350de5ccfmr4987312pjr.104.1655217525456; Tue, 14 Jun 2022 07:38:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655217525; cv=none; d=google.com; s=arc-20160816; b=lZsoYTjcPMWoRB8XvmFlDdfpI28CkKUgLYTPmkxm0GhD3wTkN9bzOSUy0SolGuhF+S 8RhDm5/kk3367ndBi+g4eKckrVjP+oaPYCF1ev2tOJr1Lu0NAKiW7e7lHZ/EUBX4lAAF OS2rHBNCPswCoOAnALvha0dKXrR9k4KeaBqxUd/enji4+hk5qVUnb2vpL+GsFAKTWnG9 ekl1/y2RXoGMYhJMxCS3Ip2FqI6Mp6VBFWS5/HFaCklkxyqAGZKUUn/vHy1jbALapDjo V/2bCrYCprkkr6xijJcMj4ppC4s4XdU8lBNowrySHt0IFBnc1LZk3wnvO+2fLooOoLgW Ib2Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:mail-followup-to :reply-to:message-id:subject:cc:to:from:date:dkim-signature :dkim-signature; bh=9sUM5JezTgOeH5YJB4qMver/nDgsiIG+jHJ6CxJ8KWo=; b=1KfN05vv06Od/gIKI30PhI2G3K48DFrMNfDOcCyVub27XcNsteVUX2FeQS10IHzdEe Xaf/SDjtzLYYecFBL1Agm3v8cteWfk7AxVHFfEZhAtiKFRv4wfhNmbaM3zZawfD805RE vAwLS4uCzIf2CGgvHMsLNPmVgTR8jJ3IoYpMixuSprxjaRSFUmoByaXl5ifO8CfzJBX4 t7cFterHceMWBc6fQUfCpSBJ7IBNQqOjVqEiF9ONGkukrvnpiXrBAXdkwvxEi5/M6PAU 3dQCpZ6UG4KkercUDwhGZwCcZ6FwzFQMta4SC3Wb+A7PMQgdppQOP5QZCbwcyx/kXfR+ S8yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=AHIc1T+T; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=lX0I1syt; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h10-20020a056a00218a00b0050dd86727b8si14995963pfi.349.2022.06.14.07.38.33; Tue, 14 Jun 2022 07:38:45 -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.cz header.s=susede2_rsa header.b=AHIc1T+T; dkim=neutral (no key) header.i=@suse.cz header.s=susede2_ed25519 header.b=lX0I1syt; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343607AbiFNO37 (ORCPT + 99 others); Tue, 14 Jun 2022 10:29:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244639AbiFNO35 (ORCPT ); Tue, 14 Jun 2022 10:29:57 -0400 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C5523615E; Tue, 14 Jun 2022 07:29:56 -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 BEC371F930; Tue, 14 Jun 2022 14:29:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1655216994; h=from:from:reply-to: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=9sUM5JezTgOeH5YJB4qMver/nDgsiIG+jHJ6CxJ8KWo=; b=AHIc1T+T63d/dp4JPI0aPXI1J/Ffvkhgx7JM2UYhD8elN+0r+3Ifs6Zwg+7ULyghHhiiUh YibkkXoirEqLwGb6CsleFLJh0ahhdn+M8hJP8upt3BMf2Gf3HpuUDfgxsASJFHkjVJTCAV kz3izirGp2dwYelsC7ghMHp4B0Fr1VI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1655216994; h=from:from:reply-to: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=9sUM5JezTgOeH5YJB4qMver/nDgsiIG+jHJ6CxJ8KWo=; b=lX0I1sytpWX/NIHU0zaVY6xhxK9HYG/KBdugW8wblolTfSY7A1Tzt4qT/olWouWPCNuvr+ EHSGJU2RJ+IvSmCg== 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 69A61139EC; Tue, 14 Jun 2022 14:29:54 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id HbrBGGKbqGJDRQAAMHmgww (envelope-from ); Tue, 14 Jun 2022 14:29:54 +0000 Date: Tue, 14 Jun 2022 16:25:21 +0200 From: David Sterba To: "Fabio M. De Francesco" Cc: dsterba@suse.cz, Chris Mason , Josef Bacik , David Sterba , Nick Terrell , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Filipe Manana , Ira Weiny , Andrew Morton Subject: Re: [PATCH] btrfs: Replace kmap() with kmap_local_page() in zstd.c Message-ID: <20220614142521.GN20633@twin.jikos.cz> Reply-To: dsterba@suse.cz Mail-Followup-To: dsterba@suse.cz, "Fabio M. De Francesco" , Chris Mason , Josef Bacik , David Sterba , Nick Terrell , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org, Filipe Manana , Ira Weiny , Andrew Morton References: <20220611135203.27992-1-fmdefrancesco@gmail.com> <20220613183913.GD20633@twin.jikos.cz> <1936552.usQuhbGJ8B@opensuse> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1936552.usQuhbGJ8B@opensuse> User-Agent: Mutt/1.5.23.1-rc1 (2014-03-12) 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 Tue, Jun 14, 2022 at 01:22:50AM +0200, Fabio M. De Francesco wrote: > On luned? 13 giugno 2022 20:39:13 CEST David Sterba wrote: > > On Sat, Jun 11, 2022 at 03:52:03PM +0200, Fabio M. De Francesco wrote: > > > The use of kmap() is being deprecated in favor of kmap_local_page(). > With > > > kmap_local_page(), the mapping is per thread, CPU local and not > globally > > > visible. > > > > > > Therefore, use kmap_local_page() / kunmap_local() in zstd.c because in > > > this file the mappings are per thread and are not visible in other > > > contexts; meanwhile refactor zstd_compress_pages() to comply with > nested > > > local mapping / unmapping ordering rules. > > > > > > Tested with xfstests on a QEMU + KVM 32 bits VM with 4GB of RAM and > > > HIGHMEM64G enabled. > > > > > > Cc: Filipe Manana > > > Suggested-by: Ira Weiny > > > Signed-off-by: Fabio M. De Francesco > > > --- > > > > > > @@ -477,15 +479,16 @@ int zstd_compress_pages(struct list_head *ws, > struct address_space *mapping, > > > /* Check if we need more input */ > > > if (workspace->in_buf.pos == workspace->in_buf.size) { > > > tot_in += PAGE_SIZE; > > > - kunmap(in_page); > > > + kunmap_local(workspace->out_buf.dst); > > > + kunmap_local((void *)workspace->in_buf.src); > > > > Why is the cast needed? > > As I wrote in an email I sent some days ago ("[RFC PATCH] btrfs: Replace > kmap() with kmap_local_page() in zstd.c")[1] I get a series of errors like > the following: > > /usr/src/git/kernels/linux/fs/btrfs/zstd.c:547:33: warning: passing > argument 1 of '__kunmap_local' discards 'const' qualifier from pointer > target type [-Wdiscarded-qualifiers] > 547 | kunmap_local(workspace->in_buf.src); > | ~~~~~~~~~~~~~~~~~^~~~ > /usr/src/git/kernels/linux/include/linux/highmem-internal.h:284:17: note: > in definition of macro 'kunmap_local' > 284 | __kunmap_local(__addr); \ > | ^~~~~~ > /usr/src/git/kernels/linux/include/linux/highmem-internal.h:92:41: note: > expected 'void *' but argument is of type 'const void *' > 92 | static inline void __kunmap_local(void *vaddr) > | ~~~~~~^~~~~ > > Therefore, this is a (bad?) hack to make these changes compile. I think it's a bad practice and that API that does not modify parameters should declare the pointers const. Type casts should be used in justified cases and not to paper over fixable issues. > A better solution is changing the prototype of __kunmap_local(); I > suppose that Andrew won't object, but who knows? > > (+Cc Andrew Morton). > > I was waiting for your comments. At now I've done about 15 conversions > across the kernel but it's the first time I had to pass a pointer to const > void to kunmap_local(). Therefore, I was not sure if changing the API were > better suited (however I have already discussed this with Ira). IMHO it should be fixed in the API.