lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Fri, 17 Jun 2022 20:54:22 +0800
From:   Qu Wenruo <quwenruo.btrfs@....com>
To:     "Fabio M. De Francesco" <fmdefrancesco@...il.com>,
        Chris Mason <clm@...com>, Josef Bacik <josef@...icpanda.com>,
        David Sterba <dsterba@...e.com>,
        Nick Terrell <terrelln@...com>,
        Chris Down <chris@...isdown.name>,
        Filipe Manana <fdmanana@...e.com>, Qu Wenruo <wqu@...e.com>,
        Nikolay Borisov <nborisov@...e.com>,
        Gabriel Niebler <gniebler@...e.com>,
        Ira Weiny <ira.weiny@...el.com>, linux-btrfs@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [RFC PATCH v2 2/3] btrfs: Use kmap_local_page() on "out_page" in
 zlib_compress_pages()



On 2022/6/17 20:05, 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() for "out_page" in
> zlib_compress_pages() 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 <ira.weiny@...el.com>
> Signed-off-by: Fabio M. De Francesco <fmdefrancesco@...il.com>

Looks good to me.

Reviewed-by: Qu Wenruo <wqu@...e.com>

The change is just to use @cpage_out to indicate if it's mapped (NULL =
not mapped).

Just a small nit inlined below.

> ---
>   fs/btrfs/zlib.c | 20 +++++++++++---------
>   1 file changed, 11 insertions(+), 9 deletions(-)
>
> diff --git a/fs/btrfs/zlib.c b/fs/btrfs/zlib.c
> index 770c4c6bbaef..c7c69ce4a1a9 100644
> --- a/fs/btrfs/zlib.c
> +++ b/fs/btrfs/zlib.c
> @@ -97,8 +97,8 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
>   {
>   	struct workspace *workspace = list_entry(ws, struct workspace, list);
>   	int ret;
> -	char *data_in;
> -	char *cpage_out;
> +	char *data_in = NULL;

I didn't see any diff touching @data_in, any idea why it's initialized
to NULL?

Thanks,
Qu

> +	char *cpage_out = NULL;
>   	int nr_pages = 0;
>   	struct page *in_page = NULL;
>   	struct page *out_page = NULL;
> @@ -126,7 +126,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
>   		ret = -ENOMEM;
>   		goto out;
>   	}
> -	cpage_out = kmap(out_page);
> +	cpage_out = kmap_local_page(out_page);
>   	pages[0] = out_page;
>   	nr_pages = 1;
>
> @@ -196,7 +196,8 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
>   		 * the stream end if required
>   		 */
>   		if (workspace->strm.avail_out == 0) {
> -			kunmap(out_page);
> +			kunmap_local(cpage_out);
> +			cpage_out = NULL;
>   			if (nr_pages == nr_dest_pages) {
>   				out_page = NULL;
>   				ret = -E2BIG;
> @@ -207,7 +208,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
>   				ret = -ENOMEM;
>   				goto out;
>   			}
> -			cpage_out = kmap(out_page);
> +			cpage_out = kmap_local_page(out_page);
>   			pages[nr_pages] = out_page;
>   			nr_pages++;
>   			workspace->strm.avail_out = PAGE_SIZE;
> @@ -234,7 +235,8 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
>   			goto out;
>   		} else if (workspace->strm.avail_out == 0) {
>   			/* get another page for the stream end */
> -			kunmap(out_page);
> +			kunmap_local(cpage_out);
> +			cpage_out = NULL;
>   			if (nr_pages == nr_dest_pages) {
>   				out_page = NULL;
>   				ret = -E2BIG;
> @@ -245,7 +247,7 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
>   				ret = -ENOMEM;
>   				goto out;
>   			}
> -			cpage_out = kmap(out_page);
> +			cpage_out = kmap_local_page(out_page);
>   			pages[nr_pages] = out_page;
>   			nr_pages++;
>   			workspace->strm.avail_out = PAGE_SIZE;
> @@ -264,8 +266,8 @@ int zlib_compress_pages(struct list_head *ws, struct address_space *mapping,
>   	*total_in = workspace->strm.total_in;
>   out:
>   	*out_pages = nr_pages;
> -	if (out_page)
> -		kunmap(out_page);
> +	if (cpage_out)
> +		kunmap_local(cpage_out);
>
>   	if (in_page) {
>   		kunmap(in_page);

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ