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]
Message-ID: <1936552.usQuhbGJ8B@opensuse>
Date:   Tue, 14 Jun 2022 01:22:50 +0200
From:   "Fabio M. De Francesco" <fmdefrancesco@...il.com>
To:     dsterba@...e.cz
Cc:     "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>, linux-btrfs@...r.kernel.org,
        linux-kernel@...r.kernel.org, Filipe Manana <fdmanana@...nel.org>,
        Ira Weiny <ira.weiny@...el.com>,
        Andrew Morton <akpm@...ux-foundation.org>
Subject: Re: [PATCH] btrfs: Replace kmap() with kmap_local_page() in zstd.c

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 <fdmanana@...nel.org>
> > Suggested-by: Ira Weiny <ira.weiny@...el.com>
> > Signed-off-by: Fabio M. De Francesco <fmdefrancesco@...il.com>
> > ---
> > 
> > @@ -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.
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).

> I see that it leads to a warning but we pass a
> const buffer and that breaks the API contract as in kunmap it would be
> accessed as non-const and potentially changed without warning or
> compiler error. If kunmap_local does not touch the buffer

Yes, correct, kunmap_local() does _not_ touch the buffer.

> and 'const
> void*' would work too, then it should be fixed.

I'll send an RFC patch for changing __kunmap_local() and the other
functions of the calls chain down to kunmap_local_indexed().
Furthermore, changes to kunmap_local_indexed() prototype require also 
changes to __kunmap_atomic() (if I recall correctly...).

Thanks for your review,

Fabio


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ