Commit 0e2c0901 authored by Atish Patra's avatar Atish Patra Committed by Palmer Dabbelt

RISC-V: Acquire mmap lock before invoking walk_page_range

As per walk_page_range documentation, mmap lock should be acquired by the
caller before invoking walk_page_range. mmap_assert_locked gets triggered
without that. The details can be found here.

http://lists.infradead.org/pipermail/linux-riscv/2020-June/010335.html

Fixes: 395a21ff(riscv: add ARCH_HAS_SET_DIRECT_MAP support)
Signed-off-by: default avatarAtish Patra <atish.patra@wdc.com>
Reviewed-by: default avatarMichel Lespinasse <walken@google.com>
Reviewed-by: default avatarZong Li <zong.li@sifive.com>
Signed-off-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
parent e0d17c84
...@@ -151,6 +151,7 @@ int set_memory_nx(unsigned long addr, int numpages) ...@@ -151,6 +151,7 @@ int set_memory_nx(unsigned long addr, int numpages)
int set_direct_map_invalid_noflush(struct page *page) int set_direct_map_invalid_noflush(struct page *page)
{ {
int ret;
unsigned long start = (unsigned long)page_address(page); unsigned long start = (unsigned long)page_address(page);
unsigned long end = start + PAGE_SIZE; unsigned long end = start + PAGE_SIZE;
struct pageattr_masks masks = { struct pageattr_masks masks = {
...@@ -158,11 +159,16 @@ int set_direct_map_invalid_noflush(struct page *page) ...@@ -158,11 +159,16 @@ int set_direct_map_invalid_noflush(struct page *page)
.clear_mask = __pgprot(_PAGE_PRESENT) .clear_mask = __pgprot(_PAGE_PRESENT)
}; };
return walk_page_range(&init_mm, start, end, &pageattr_ops, &masks); mmap_read_lock(&init_mm);
ret = walk_page_range(&init_mm, start, end, &pageattr_ops, &masks);
mmap_read_unlock(&init_mm);
return ret;
} }
int set_direct_map_default_noflush(struct page *page) int set_direct_map_default_noflush(struct page *page)
{ {
int ret;
unsigned long start = (unsigned long)page_address(page); unsigned long start = (unsigned long)page_address(page);
unsigned long end = start + PAGE_SIZE; unsigned long end = start + PAGE_SIZE;
struct pageattr_masks masks = { struct pageattr_masks masks = {
...@@ -170,7 +176,11 @@ int set_direct_map_default_noflush(struct page *page) ...@@ -170,7 +176,11 @@ int set_direct_map_default_noflush(struct page *page)
.clear_mask = __pgprot(0) .clear_mask = __pgprot(0)
}; };
return walk_page_range(&init_mm, start, end, &pageattr_ops, &masks); mmap_read_lock(&init_mm);
ret = walk_page_range(&init_mm, start, end, &pageattr_ops, &masks);
mmap_read_unlock(&init_mm);
return ret;
} }
void __kernel_map_pages(struct page *page, int numpages, int enable) void __kernel_map_pages(struct page *page, int numpages, int enable)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment