Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp1163240iog; Sat, 18 Jun 2022 02:24:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vge33x9IHCkHJEsudyzDkwwVVvA7XHmTYjS9qcd1nb69FPIHThN2jaG86iARWEjhDowshH X-Received: by 2002:a05:6402:1d4a:b0:42e:93de:17f4 with SMTP id dz10-20020a0564021d4a00b0042e93de17f4mr17386535edb.8.1655544243516; Sat, 18 Jun 2022 02:24:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655544243; cv=none; d=google.com; s=arc-20160816; b=ddetd+s8HSgtmg8pcQZIwgDe1lB/3kJ2IybHtSlQ8TiNpVd/t6UO3+Rim9Z7jaBLz0 0dwwjgv6kd1p6efZRzfQHpF78mGCyfoPd6vEn1ZvaFXyIBpuhoeJriOxCS/5KvNfF6x5 9ZWDnF1aTkHksObqmlzD3J3U8NOEnA+BqzNTW2o0H8wF+GOZ0B5esdMnQApfjtqnGoir OOE4WSyB29w6IReE44CpjzkUj8h2qSoryOdXu6+nLZ8JjQt1ZCV7xyTN/dp7unYpHOiz +4XmHfLeQ2/oRnRcO0/Q83DYKtpb/83Hj4jzFCXYkuBbdwBZU//ajHxKvFZmT/nPU5gG ITjQ== 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 :message-id:date:subject:cc:to:from:dkim-signature; bh=dnShuNCC7vJwyx79q/xFZV5Bswk3kI4OzmQoFoQnuVM=; b=ejOGarRiZJq7swRhO0l2SJ1Jd++PGdxVy2vnkv5SaNTTjxOar9zMpsUE2xRbiw0zon bxBXqc6mLoJL5dpFuP/NepU2vlhXQy53j+s28wcIOb+bi1S6Cat5d/SsPWAP20fh+8Ub albFndGXS5xctiM+fib7wj088lXU+5CctvkTjfcsCQ4dk2/zaU9VIQHYvjqltB6EyYPB Q5Mm32loyb/oDi6dwAEA6ClbGEYzJmtyVxuJ66D+lr4arnabSYYPM03i+u99+Plz279q Unl5hupDNO/Jz19vp7lqFwhQEQP/GtMa2eQ8S1+zHHvXpULOtFnrJy46OoVhjlA86XdZ uqQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="e/JcgF2a"; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gs42-20020a1709072d2a00b00711cf82cc03si4022092ejc.830.2022.06.18.02.23.36; Sat, 18 Jun 2022 02:24:03 -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=@gmail.com header.s=20210112 header.b="e/JcgF2a"; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231136AbiFRJTO (ORCPT + 99 others); Sat, 18 Jun 2022 05:19:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231927AbiFRJTJ (ORCPT ); Sat, 18 Jun 2022 05:19:09 -0400 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B76902654B; Sat, 18 Jun 2022 02:19:08 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id ej4so5042700edb.7; Sat, 18 Jun 2022 02:19:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=dnShuNCC7vJwyx79q/xFZV5Bswk3kI4OzmQoFoQnuVM=; b=e/JcgF2akSWVnYgPWU/7toRYSXH0Ei2m6FY539tryc8COawWnTM5q1P5l3T4gWEHfd vLRDXtG7XraEeEpTm9MGP8zzfmagqSTbwotmISuzb0DRhGaHQrCmK6n/IbX/QFl96dJL TQiOo8Q+stPMK+jpgZv+Q/xp38EFksLxUos3jdudA1x5JVYQnLI0Yx1BT3BLW4wchsSv N3dwe8/Lsu3oJvnpRKHsV4l4ixPZwmg9cN0hymnjkqLG7T1HyzVTBuXd2yArLYrN1ZUZ UtNLosVgbL45q2t8zZ0cCQrntm9E2Aec6Xi5INR4+HtLOuNqfHUEJ1fryr9BGzzjz5cT kG4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=dnShuNCC7vJwyx79q/xFZV5Bswk3kI4OzmQoFoQnuVM=; b=rm6E6QcwBk5UDfdCwJsr9NL6XkgZbevZ6lw9hOiEcSaTdXBdCGeeNWYy2Y+EzXhQQI hAwiDPZ2/r0KQMEEST97euaMoB1koVeviZmatQW5JgeCPXH7j1+qKEhlYAdnMPrBS3yl 41pjt0yQEdfrPAtj/UjMEi/5ruf+gKbECc8cn8tLZ4lMNQo+kSgQCZmQEQl6A48uyqSS gSOGOFzVU0Cu9nyIDd0+eFTT1RytI+NFYrwKXqyJbGYgOF82lYHTxGbmxl3Qlq+22Y3t JShc/dRSscoIk4hP+gK0I7Y+mG1SUpN3Ubdfwn1HPHrI35pyfsJKnonOp4sKi3NnaUE7 byxg== X-Gm-Message-State: AJIora8sn322mrOEFlD/9sHt+k01LCsFZjy/6sN2bOc6d6ulpNeBAt9B TNSeh9vWmhv2hpByKJuYHvI= X-Received: by 2002:a05:6402:403:b0:434:eb49:218f with SMTP id q3-20020a056402040300b00434eb49218fmr17442869edv.426.1655543947288; Sat, 18 Jun 2022 02:19:07 -0700 (PDT) Received: from localhost.localdomain (host-87-6-98-182.retail.telecomitalia.it. [87.6.98.182]) by smtp.gmail.com with ESMTPSA id lb21-20020a170907785500b007219c20dcd8sm451956ejc.196.2022.06.18.02.19.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 18 Jun 2022 02:19:06 -0700 (PDT) From: "Fabio M. De Francesco" To: Chris Mason , Josef Bacik , David Sterba , Nick Terrell , Chris Down , Filipe Manana , Qu Wenruo , Nikolay Borisov , Gabriel Niebler , linux-btrfs@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Fabio M. De Francesco" , Ira Weiny Subject: [PATCH] btrfs: Convert zlib_decompress_bio() to use kmap_local_page() Date: Sat, 18 Jun 2022 11:19:01 +0200 Message-Id: <20220618091901.25034-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, 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 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 zlib_decompress_bio() because in this function the mappings are per thread and are not visible in other contexts. Tested with xfstests on QEMU + KVM 32-bits VM with 4GB of RAM and HIGHMEM64G enabled. This patch passes 26/26 tests of group "compress". Suggested-by: Ira Weiny Reviewed-by: Qu Wenruo Signed-off-by: Fabio M. De Francesco --- fs/btrfs/zlib.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c index 2cd4f6fb1537..966e17cea981 100644 --- a/fs/btrfs/zlib.c +++ b/fs/btrfs/zlib.c @@ -284,7 +284,7 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb) unsigned long buf_start; struct page **pages_in = cb->compressed_pages; - data_in = kmap(pages_in[page_in_index]); + data_in = kmap_local_page(pages_in[page_in_index]); workspace->strm.next_in = data_in; workspace->strm.avail_in = min_t(size_t, srclen, PAGE_SIZE); workspace->strm.total_in = 0; @@ -306,7 +306,7 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb) if (Z_OK != zlib_inflateInit2(&workspace->strm, wbits)) { pr_warn("BTRFS: inflateInit failed\n"); - kunmap(pages_in[page_in_index]); + kunmap_local(data_in); return -EIO; } while (workspace->strm.total_in < srclen) { @@ -333,13 +333,13 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb) if (workspace->strm.avail_in == 0) { unsigned long tmp; - kunmap(pages_in[page_in_index]); + kunmap_local(data_in); page_in_index++; if (page_in_index >= total_pages_in) { data_in = NULL; break; } - data_in = kmap(pages_in[page_in_index]); + data_in = kmap_local_page(pages_in[page_in_index]); workspace->strm.next_in = data_in; tmp = srclen - workspace->strm.total_in; workspace->strm.avail_in = min(tmp, PAGE_SIZE); @@ -352,7 +352,7 @@ int zlib_decompress_bio(struct list_head *ws, struct compressed_bio *cb) done: zlib_inflateEnd(&workspace->strm); if (data_in) - kunmap(pages_in[page_in_index]); + kunmap_local(data_in); if (!ret) zero_fill_bio(cb->orig_bio); return ret; -- 2.36.1