2022-10-18 04:30:41

by Gao Xiang

[permalink] [raw]
Subject: [PATCH] erofs: use kmap_local_page() only for erofs_bread()

Convert all mapped erofs_bread() users to use kmap_local_page()
instead of kmap() or kmap_atomic().

Signed-off-by: Gao Xiang <[email protected]>
---
fs/erofs/data.c | 8 ++------
fs/erofs/internal.h | 3 +--
fs/erofs/xattr.c | 8 ++++----
fs/erofs/zmap.c | 4 ++--
4 files changed, 9 insertions(+), 14 deletions(-)

diff --git a/fs/erofs/data.c b/fs/erofs/data.c
index fe8ac0e163f7..3873395173b5 100644
--- a/fs/erofs/data.c
+++ b/fs/erofs/data.c
@@ -13,9 +13,7 @@
void erofs_unmap_metabuf(struct erofs_buf *buf)
{
if (buf->kmap_type == EROFS_KMAP)
- kunmap(buf->page);
- else if (buf->kmap_type == EROFS_KMAP_ATOMIC)
- kunmap_atomic(buf->base);
+ kunmap_local(buf->page);
buf->base = NULL;
buf->kmap_type = EROFS_NO_KMAP;
}
@@ -54,9 +52,7 @@ void *erofs_bread(struct erofs_buf *buf, struct inode *inode,
}
if (buf->kmap_type == EROFS_NO_KMAP) {
if (type == EROFS_KMAP)
- buf->base = kmap(page);
- else if (type == EROFS_KMAP_ATOMIC)
- buf->base = kmap_atomic(page);
+ buf->base = kmap_local_page(page);
buf->kmap_type = type;
} else if (buf->kmap_type != type) {
DBG_BUGON(1);
diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
index 1701df48c446..67dc8e177211 100644
--- a/fs/erofs/internal.h
+++ b/fs/erofs/internal.h
@@ -253,8 +253,7 @@ static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)

enum erofs_kmap_type {
EROFS_NO_KMAP, /* don't map the buffer */
- EROFS_KMAP, /* use kmap() to map the buffer */
- EROFS_KMAP_ATOMIC, /* use kmap_atomic() to map the buffer */
+ EROFS_KMAP, /* use kmap_local_page() to map the buffer */
};

struct erofs_buf {
diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c
index 8106bcb5a38d..a62fb8a3318a 100644
--- a/fs/erofs/xattr.c
+++ b/fs/erofs/xattr.c
@@ -148,7 +148,7 @@ static inline int xattr_iter_fixup(struct xattr_iter *it)

it->blkaddr += erofs_blknr(it->ofs);
it->kaddr = erofs_read_metabuf(&it->buf, it->sb, it->blkaddr,
- EROFS_KMAP_ATOMIC);
+ EROFS_KMAP);
if (IS_ERR(it->kaddr))
return PTR_ERR(it->kaddr);
it->ofs = erofs_blkoff(it->ofs);
@@ -174,7 +174,7 @@ static int inline_xattr_iter_begin(struct xattr_iter *it,
it->ofs = erofs_blkoff(iloc(sbi, vi->nid) + inline_xattr_ofs);

it->kaddr = erofs_read_metabuf(&it->buf, inode->i_sb, it->blkaddr,
- EROFS_KMAP_ATOMIC);
+ EROFS_KMAP);
if (IS_ERR(it->kaddr))
return PTR_ERR(it->kaddr);
return vi->xattr_isize - xattr_header_sz;
@@ -368,7 +368,7 @@ static int shared_getxattr(struct inode *inode, struct getxattr_iter *it)

it->it.ofs = xattrblock_offset(sbi, vi->xattr_shared_xattrs[i]);
it->it.kaddr = erofs_read_metabuf(&it->it.buf, sb, blkaddr,
- EROFS_KMAP_ATOMIC);
+ EROFS_KMAP);
if (IS_ERR(it->it.kaddr))
return PTR_ERR(it->it.kaddr);
it->it.blkaddr = blkaddr;
@@ -580,7 +580,7 @@ static int shared_listxattr(struct listxattr_iter *it)

it->it.ofs = xattrblock_offset(sbi, vi->xattr_shared_xattrs[i]);
it->it.kaddr = erofs_read_metabuf(&it->it.buf, sb, blkaddr,
- EROFS_KMAP_ATOMIC);
+ EROFS_KMAP);
if (IS_ERR(it->it.kaddr))
return PTR_ERR(it->it.kaddr);
it->it.blkaddr = blkaddr;
diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c
index 0bb66927e3d0..749a5ac943f4 100644
--- a/fs/erofs/zmap.c
+++ b/fs/erofs/zmap.c
@@ -178,7 +178,7 @@ static int legacy_load_cluster_from_disk(struct z_erofs_maprecorder *m,
unsigned int advise, type;

m->kaddr = erofs_read_metabuf(&m->map->buf, inode->i_sb,
- erofs_blknr(pos), EROFS_KMAP_ATOMIC);
+ erofs_blknr(pos), EROFS_KMAP);
if (IS_ERR(m->kaddr))
return PTR_ERR(m->kaddr);

@@ -416,7 +416,7 @@ static int compacted_load_cluster_from_disk(struct z_erofs_maprecorder *m,
out:
pos += lcn * (1 << amortizedshift);
m->kaddr = erofs_read_metabuf(&m->map->buf, inode->i_sb,
- erofs_blknr(pos), EROFS_KMAP_ATOMIC);
+ erofs_blknr(pos), EROFS_KMAP);
if (IS_ERR(m->kaddr))
return PTR_ERR(m->kaddr);
return unpack_compacted_index(m, amortizedshift, pos, lookahead);
--
2.24.4


2022-10-18 07:18:06

by Jingbo Xu

[permalink] [raw]
Subject: Re: [PATCH] erofs: use kmap_local_page() only for erofs_bread()



On 10/18/22 11:55 AM, Gao Xiang wrote:
> Convert all mapped erofs_bread() users to use kmap_local_page()
> instead of kmap() or kmap_atomic().
>
> Signed-off-by: Gao Xiang <[email protected]>

LGTM.

Reviewed-by: Jingbo Xu <[email protected]>

> ---
> fs/erofs/data.c | 8 ++------
> fs/erofs/internal.h | 3 +--
> fs/erofs/xattr.c | 8 ++++----
> fs/erofs/zmap.c | 4 ++--
> 4 files changed, 9 insertions(+), 14 deletions(-)
>
> diff --git a/fs/erofs/data.c b/fs/erofs/data.c
> index fe8ac0e163f7..3873395173b5 100644
> --- a/fs/erofs/data.c
> +++ b/fs/erofs/data.c
> @@ -13,9 +13,7 @@
> void erofs_unmap_metabuf(struct erofs_buf *buf)
> {
> if (buf->kmap_type == EROFS_KMAP)
> - kunmap(buf->page);
> - else if (buf->kmap_type == EROFS_KMAP_ATOMIC)
> - kunmap_atomic(buf->base);
> + kunmap_local(buf->page);
> buf->base = NULL;
> buf->kmap_type = EROFS_NO_KMAP;
> }
> @@ -54,9 +52,7 @@ void *erofs_bread(struct erofs_buf *buf, struct inode *inode,
> }
> if (buf->kmap_type == EROFS_NO_KMAP) {
> if (type == EROFS_KMAP)
> - buf->base = kmap(page);
> - else if (type == EROFS_KMAP_ATOMIC)
> - buf->base = kmap_atomic(page);
> + buf->base = kmap_local_page(page);
> buf->kmap_type = type;
> } else if (buf->kmap_type != type) {
> DBG_BUGON(1);
> diff --git a/fs/erofs/internal.h b/fs/erofs/internal.h
> index 1701df48c446..67dc8e177211 100644
> --- a/fs/erofs/internal.h
> +++ b/fs/erofs/internal.h
> @@ -253,8 +253,7 @@ static inline int erofs_wait_on_workgroup_freezed(struct erofs_workgroup *grp)
>
> enum erofs_kmap_type {
> EROFS_NO_KMAP, /* don't map the buffer */
> - EROFS_KMAP, /* use kmap() to map the buffer */
> - EROFS_KMAP_ATOMIC, /* use kmap_atomic() to map the buffer */
> + EROFS_KMAP, /* use kmap_local_page() to map the buffer */
> };
>
> struct erofs_buf {
> diff --git a/fs/erofs/xattr.c b/fs/erofs/xattr.c
> index 8106bcb5a38d..a62fb8a3318a 100644
> --- a/fs/erofs/xattr.c
> +++ b/fs/erofs/xattr.c
> @@ -148,7 +148,7 @@ static inline int xattr_iter_fixup(struct xattr_iter *it)
>
> it->blkaddr += erofs_blknr(it->ofs);
> it->kaddr = erofs_read_metabuf(&it->buf, it->sb, it->blkaddr,
> - EROFS_KMAP_ATOMIC);
> + EROFS_KMAP);
> if (IS_ERR(it->kaddr))
> return PTR_ERR(it->kaddr);
> it->ofs = erofs_blkoff(it->ofs);
> @@ -174,7 +174,7 @@ static int inline_xattr_iter_begin(struct xattr_iter *it,
> it->ofs = erofs_blkoff(iloc(sbi, vi->nid) + inline_xattr_ofs);
>
> it->kaddr = erofs_read_metabuf(&it->buf, inode->i_sb, it->blkaddr,
> - EROFS_KMAP_ATOMIC);
> + EROFS_KMAP);
> if (IS_ERR(it->kaddr))
> return PTR_ERR(it->kaddr);
> return vi->xattr_isize - xattr_header_sz;
> @@ -368,7 +368,7 @@ static int shared_getxattr(struct inode *inode, struct getxattr_iter *it)
>
> it->it.ofs = xattrblock_offset(sbi, vi->xattr_shared_xattrs[i]);
> it->it.kaddr = erofs_read_metabuf(&it->it.buf, sb, blkaddr,
> - EROFS_KMAP_ATOMIC);
> + EROFS_KMAP);
> if (IS_ERR(it->it.kaddr))
> return PTR_ERR(it->it.kaddr);
> it->it.blkaddr = blkaddr;
> @@ -580,7 +580,7 @@ static int shared_listxattr(struct listxattr_iter *it)
>
> it->it.ofs = xattrblock_offset(sbi, vi->xattr_shared_xattrs[i]);
> it->it.kaddr = erofs_read_metabuf(&it->it.buf, sb, blkaddr,
> - EROFS_KMAP_ATOMIC);
> + EROFS_KMAP);
> if (IS_ERR(it->it.kaddr))
> return PTR_ERR(it->it.kaddr);
> it->it.blkaddr = blkaddr;
> diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c
> index 0bb66927e3d0..749a5ac943f4 100644
> --- a/fs/erofs/zmap.c
> +++ b/fs/erofs/zmap.c
> @@ -178,7 +178,7 @@ static int legacy_load_cluster_from_disk(struct z_erofs_maprecorder *m,
> unsigned int advise, type;
>
> m->kaddr = erofs_read_metabuf(&m->map->buf, inode->i_sb,
> - erofs_blknr(pos), EROFS_KMAP_ATOMIC);
> + erofs_blknr(pos), EROFS_KMAP);
> if (IS_ERR(m->kaddr))
> return PTR_ERR(m->kaddr);
>
> @@ -416,7 +416,7 @@ static int compacted_load_cluster_from_disk(struct z_erofs_maprecorder *m,
> out:
> pos += lcn * (1 << amortizedshift);
> m->kaddr = erofs_read_metabuf(&m->map->buf, inode->i_sb,
> - erofs_blknr(pos), EROFS_KMAP_ATOMIC);
> + erofs_blknr(pos), EROFS_KMAP);
> if (IS_ERR(m->kaddr))
> return PTR_ERR(m->kaddr);
> return unpack_compacted_index(m, amortizedshift, pos, lookahead);

--
Thanks,
Jingbo

2022-10-18 09:27:46

by kernel test robot

[permalink] [raw]
Subject: Re: [PATCH] erofs: use kmap_local_page() only for erofs_bread()

Hi Gao,

I love your patch! Yet something to improve:

[auto build test ERROR on xiang-erofs/dev-test]
[also build test ERROR on linus/master v6.1-rc1 next-20221018]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url: https://github.com/intel-lab-lkp/linux/commits/Gao-Xiang/erofs-use-kmap_local_page-only-for-erofs_bread/20221018-115613
base: https://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git dev-test
patch link: https://lore.kernel.org/r/20221018035536.114792-1-hsiangkao%40linux.alibaba.com
patch subject: [PATCH] erofs: use kmap_local_page() only for erofs_bread()
config: i386-randconfig-a003
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
# https://github.com/intel-lab-lkp/linux/commit/434a5b6093794608b7a4ed9ab12164b506dc883f
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Gao-Xiang/erofs-use-kmap_local_page-only-for-erofs_bread/20221018-115613
git checkout 434a5b6093794608b7a4ed9ab12164b506dc883f
# save the config file
mkdir build_dir && cp config build_dir/.config
make W=1 O=build_dir ARCH=i386 SHELL=/bin/bash fs/erofs/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]>

All errors (new ones prefixed by >>):

In file included from <command-line>:
In function 'erofs_unmap_metabuf',
inlined from 'erofs_put_metabuf' at fs/erofs/data.c:25:2,
inlined from 'erofs_iomap_end' at fs/erofs/data.c:320:3:
>> include/linux/compiler_types.h:357:45: error: call to '__compiletime_assert_318' declared with attribute error: BUILD_BUG_ON failed: __same_type((buf->page), struct page *)
357 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
include/linux/compiler_types.h:338:25: note: in definition of macro '__compiletime_assert'
338 | prefix ## suffix(); \
| ^~~~~~
include/linux/compiler_types.h:357:9: note: in expansion of macro '_compiletime_assert'
357 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:50:9: note: in expansion of macro 'BUILD_BUG_ON_MSG'
50 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
| ^~~~~~~~~~~~~~~~
include/linux/highmem-internal.h:283:9: note: in expansion of macro 'BUILD_BUG_ON'
283 | BUILD_BUG_ON(__same_type((__addr), struct page *)); \
| ^~~~~~~~~~~~
fs/erofs/data.c:16:17: note: in expansion of macro 'kunmap_local'
16 | kunmap_local(buf->page);
| ^~~~~~~~~~~~
fs/erofs/data.c: In function 'erofs_unmap_metabuf':
>> include/linux/compiler_types.h:357:45: error: call to '__compiletime_assert_318' declared with attribute error: BUILD_BUG_ON failed: __same_type((buf->page), struct page *)
357 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
include/linux/compiler_types.h:338:25: note: in definition of macro '__compiletime_assert'
338 | prefix ## suffix(); \
| ^~~~~~
include/linux/compiler_types.h:357:9: note: in expansion of macro '_compiletime_assert'
357 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:50:9: note: in expansion of macro 'BUILD_BUG_ON_MSG'
50 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
| ^~~~~~~~~~~~~~~~
include/linux/highmem-internal.h:283:9: note: in expansion of macro 'BUILD_BUG_ON'
283 | BUILD_BUG_ON(__same_type((__addr), struct page *)); \
| ^~~~~~~~~~~~
fs/erofs/data.c:16:17: note: in expansion of macro 'kunmap_local'
16 | kunmap_local(buf->page);
| ^~~~~~~~~~~~
In function 'erofs_unmap_metabuf',
inlined from 'erofs_put_metabuf' at fs/erofs/data.c:25:2:
>> include/linux/compiler_types.h:357:45: error: call to '__compiletime_assert_318' declared with attribute error: BUILD_BUG_ON failed: __same_type((buf->page), struct page *)
357 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^
include/linux/compiler_types.h:338:25: note: in definition of macro '__compiletime_assert'
338 | prefix ## suffix(); \
| ^~~~~~
include/linux/compiler_types.h:357:9: note: in expansion of macro '_compiletime_assert'
357 | _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
| ^~~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:39:37: note: in expansion of macro 'compiletime_assert'
39 | #define BUILD_BUG_ON_MSG(cond, msg) compiletime_assert(!(cond), msg)
| ^~~~~~~~~~~~~~~~~~
include/linux/build_bug.h:50:9: note: in expansion of macro 'BUILD_BUG_ON_MSG'
50 | BUILD_BUG_ON_MSG(condition, "BUILD_BUG_ON failed: " #condition)
| ^~~~~~~~~~~~~~~~
include/linux/highmem-internal.h:283:9: note: in expansion of macro 'BUILD_BUG_ON'
283 | BUILD_BUG_ON(__same_type((__addr), struct page *)); \
| ^~~~~~~~~~~~
fs/erofs/data.c:16:17: note: in expansion of macro 'kunmap_local'
16 | kunmap_local(buf->page);
| ^~~~~~~~~~~~


vim +/__compiletime_assert_318 +357 include/linux/compiler_types.h

eb5c2d4b45e3d2 Will Deacon 2020-07-21 343
eb5c2d4b45e3d2 Will Deacon 2020-07-21 344 #define _compiletime_assert(condition, msg, prefix, suffix) \
eb5c2d4b45e3d2 Will Deacon 2020-07-21 345 __compiletime_assert(condition, msg, prefix, suffix)
eb5c2d4b45e3d2 Will Deacon 2020-07-21 346
eb5c2d4b45e3d2 Will Deacon 2020-07-21 347 /**
eb5c2d4b45e3d2 Will Deacon 2020-07-21 348 * compiletime_assert - break build and emit msg if condition is false
eb5c2d4b45e3d2 Will Deacon 2020-07-21 349 * @condition: a compile-time constant condition to check
eb5c2d4b45e3d2 Will Deacon 2020-07-21 350 * @msg: a message to emit if condition is false
eb5c2d4b45e3d2 Will Deacon 2020-07-21 351 *
eb5c2d4b45e3d2 Will Deacon 2020-07-21 352 * In tradition of POSIX assert, this macro will break the build if the
eb5c2d4b45e3d2 Will Deacon 2020-07-21 353 * supplied condition is *false*, emitting the supplied error message if the
eb5c2d4b45e3d2 Will Deacon 2020-07-21 354 * compiler has support to do so.
eb5c2d4b45e3d2 Will Deacon 2020-07-21 355 */
eb5c2d4b45e3d2 Will Deacon 2020-07-21 356 #define compiletime_assert(condition, msg) \
eb5c2d4b45e3d2 Will Deacon 2020-07-21 @357 _compiletime_assert(condition, msg, __compiletime_assert_, __COUNTER__)
eb5c2d4b45e3d2 Will Deacon 2020-07-21 358

--
0-DAY CI Kernel Test Service
https://01.org/lkp


Attachments:
(No filename) (7.92 kB)
config (159.76 kB)
Download all attachments

2022-10-18 09:58:49

by Gao Xiang

[permalink] [raw]
Subject: Re: [PATCH] erofs: use kmap_local_page() only for erofs_bread()

On Tue, Oct 18, 2022 at 05:22:18PM +0800, kernel test robot wrote:
> Hi Gao,
>
> I love your patch! Yet something to improve:
>
> [auto build test ERROR on xiang-erofs/dev-test]
> [also build test ERROR on linus/master v6.1-rc1 next-20221018]

Thanks for the report, sorry for submitting an outdated version.
I'll merge the latest update and resend.

Thanks,
Gao Xiang