2021-09-01 02:39:24

by Tong Tiangen

[permalink] [raw]
Subject: [PATCH -next v3 0/3] riscv: Fix two vdso issue

v3->v2:
Adapt to the latest code.

v2->v1:
Add patch "Refactor asm/vdso.h" to avoid vdso.lds syntax error if
CONFIG_GENERIC_TIME_VSYSCALL=n.

1) Move vdso data page up front and introduce enum vvar_pages, This makes it
easier to introduce new feature TIME_NS.

2) In arch_setup_additional_pages(), make Wait for the lock in the killable mode
and return with EINTR if the task got killed while waiting.

Tong Tiangen (3):
riscv/vdso: Refactor asm/vdso.h
riscv/vdso: Move vdso data page up front
riscv/vdso: make arch_setup_additional_pages wait for mmap_sem for
write killable

arch/riscv/include/asm/syscall.h | 1 +
arch/riscv/include/asm/vdso.h | 15 ++++-----
arch/riscv/kernel/syscall_table.c | 1 -
arch/riscv/kernel/vdso.c | 53 +++++++++++++++++++------------
arch/riscv/kernel/vdso/vdso.lds.S | 3 +-
5 files changed, 42 insertions(+), 31 deletions(-)

--
2.18.0.huawei.25


2021-09-01 02:52:15

by Tong Tiangen

[permalink] [raw]
Subject: [PATCH -next v3 3/3] riscv/vdso: make arch_setup_additional_pages wait for mmap_sem for write killable

riscv architectures relying on mmap_sem for write in their
arch_setup_additional_pages. If the waiting task gets killed by the oom killer
it would block oom_reaper from asynchronous address space reclaim and reduce
the chances of timely OOM resolving. Wait for the lock in the killable mode
and return with EINTR if the task got killed while waiting.

Signed-off-by: Tong Tiangen <[email protected]>
---
arch/riscv/kernel/vdso.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/riscv/kernel/vdso.c b/arch/riscv/kernel/vdso.c
index e7bd92d8749b..b70956d80408 100644
--- a/arch/riscv/kernel/vdso.c
+++ b/arch/riscv/kernel/vdso.c
@@ -77,7 +77,9 @@ int arch_setup_additional_pages(struct linux_binprm *bprm,

vdso_len = (vdso_pages + VVAR_NR_PAGES) << PAGE_SHIFT;

- mmap_write_lock(mm);
+ if (mmap_write_lock_killable(mm))
+ return -EINTR;
+
vdso_base = get_unmapped_area(NULL, 0, vdso_len, 0, 0);
if (IS_ERR_VALUE(vdso_base)) {
ret = vdso_base;
--
2.18.0.huawei.25

2021-09-28 02:23:24

by Liu Shixin

[permalink] [raw]
Subject: Re: [PATCH -next v3 0/3] riscv: Fix two vdso issue

On 2021/9/1 10:46, Tong Tiangen wrote:
> v3->v2:
> Adapt to the latest code.
>
> v2->v1:
> Add patch "Refactor asm/vdso.h" to avoid vdso.lds syntax error if
> CONFIG_GENERIC_TIME_VSYSCALL=n.
>
> 1) Move vdso data page up front and introduce enum vvar_pages, This makes it
> easier to introduce new feature TIME_NS.
>
> 2) In arch_setup_additional_pages(), make Wait for the lock in the killable mode
> and return with EINTR if the task got killed while waiting.
>
> Tong Tiangen (3):
> riscv/vdso: Refactor asm/vdso.h
> riscv/vdso: Move vdso data page up front
> riscv/vdso: make arch_setup_additional_pages wait for mmap_sem for
> write killable
>
> arch/riscv/include/asm/syscall.h | 1 +
> arch/riscv/include/asm/vdso.h | 15 ++++-----
> arch/riscv/kernel/syscall_table.c | 1 -
> arch/riscv/kernel/vdso.c | 53 +++++++++++++++++++------------
> arch/riscv/kernel/vdso/vdso.lds.S | 3 +-
> 5 files changed, 42 insertions(+), 31 deletions(-)
>

Test-by: Liu Shixin <[email protected]>

2021-09-28 02:32:13

by Tong Tiangen

[permalink] [raw]
Subject: Re: [PATCH -next v3 0/3] riscv: Fix two vdso issue

kindly ping.

On 2021/9/28 10:19, Liu Shixin wrote:
> On 2021/9/1 10:46, Tong Tiangen wrote:
>> v3->v2:
>> Adapt to the latest code.
>>
>> v2->v1:
>> Add patch "Refactor asm/vdso.h" to avoid vdso.lds syntax error if
>> CONFIG_GENERIC_TIME_VSYSCALL=n.
>>
>> 1) Move vdso data page up front and introduce enum vvar_pages, This makes it
>> easier to introduce new feature TIME_NS.
>>
>> 2) In arch_setup_additional_pages(), make Wait for the lock in the killable mode
>> and return with EINTR if the task got killed while waiting.
>>
>> Tong Tiangen (3):
>> riscv/vdso: Refactor asm/vdso.h
>> riscv/vdso: Move vdso data page up front
>> riscv/vdso: make arch_setup_additional_pages wait for mmap_sem for
>> write killable
>>
>> arch/riscv/include/asm/syscall.h | 1 +
>> arch/riscv/include/asm/vdso.h | 15 ++++-----
>> arch/riscv/kernel/syscall_table.c | 1 -
>> arch/riscv/kernel/vdso.c | 53 +++++++++++++++++++------------
>> arch/riscv/kernel/vdso/vdso.lds.S | 3 +-
>> 5 files changed, 42 insertions(+), 31 deletions(-)
>>
>
> Test-by: Liu Shixin <[email protected]>
> .
>

2021-09-29 10:18:16

by Kefeng Wang

[permalink] [raw]
Subject: Re: [PATCH -next v3 0/3] riscv: Fix two vdso issue

Hi Palmer, could this patchset be merged into v5.15, it fixes the
serious problems about the basic time api.

Sergey[1] does meet same issue too. Thanks.

[1]
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/

On 2021/9/1 10:46, Tong Tiangen wrote:
> v3->v2:
> Adapt to the latest code.
>
> v2->v1:
> Add patch "Refactor asm/vdso.h" to avoid vdso.lds syntax error if
> CONFIG_GENERIC_TIME_VSYSCALL=n.
>
> 1) Move vdso data page up front and introduce enum vvar_pages, This makes it
> easier to introduce new feature TIME_NS.
>
> 2) In arch_setup_additional_pages(), make Wait for the lock in the killable mode
> and return with EINTR if the task got killed while waiting.

Reviewed-by: Kefeng Wang <[email protected]>

2021-10-02 20:30:06

by Palmer Dabbelt

[permalink] [raw]
Subject: Re: [PATCH -next v3 0/3] riscv: Fix two vdso issue

On Tue, 31 Aug 2021 19:46:18 PDT (-0700), [email protected] wrote:
> v3->v2:
> Adapt to the latest code.
>
> v2->v1:
> Add patch "Refactor asm/vdso.h" to avoid vdso.lds syntax error if
> CONFIG_GENERIC_TIME_VSYSCALL=n.
>
> 1) Move vdso data page up front and introduce enum vvar_pages, This makes it
> easier to introduce new feature TIME_NS.
>
> 2) In arch_setup_additional_pages(), make Wait for the lock in the killable mode
> and return with EINTR if the task got killed while waiting.
>
> Tong Tiangen (3):
> riscv/vdso: Refactor asm/vdso.h
> riscv/vdso: Move vdso data page up front
> riscv/vdso: make arch_setup_additional_pages wait for mmap_sem for
> write killable
>
> arch/riscv/include/asm/syscall.h | 1 +
> arch/riscv/include/asm/vdso.h | 15 ++++-----
> arch/riscv/kernel/syscall_table.c | 1 -
> arch/riscv/kernel/vdso.c | 53 +++++++++++++++++++------------
> arch/riscv/kernel/vdso/vdso.lds.S | 3 +-
> 5 files changed, 42 insertions(+), 31 deletions(-)

Sorry, I thought this was targeted at for-next. I've put this on fixes
(not sure if my last copy went out, my mail client crashed).