2015-04-13 09:56:45

by Laurent Dufour

[permalink] [raw]
Subject: [RESEND PATCH v3 0/2] Tracking user space vDSO remaping

CRIU is recreating the process memory layout by remapping the checkpointee
memory area on top of the current process (criu). This includes remapping
the vDSO to the place it has at checkpoint time.

However some architectures like powerpc are keeping a reference to the vDSO
base address to build the signal return stack frame by calling the vDSO
sigreturn service. So once the vDSO has been moved, this reference is no
more valid and the signal frame built later are not usable.

This patch serie is introducing a new mm hook 'arch_remap' which is called
when mremap is done and the mm lock still hold. The next patch is adding the
vDSO remap and unmap tracking to the powerpc architecture.

Resending
- rebased on 4.0.0

Changes in v3:
--------------
- Fixed grammatical error in a comment of the second patch.
Thanks again, Ingo.

Changes in v2:
--------------
- Following the Ingo Molnar's advice, enabling the call to arch_remap through
the __HAVE_ARCH_REMAP macro. This reduces considerably the first patch.

Laurent Dufour (2):
mm: Introducing arch_remap hook
powerpc/mm: Tracking vDSO remap

arch/powerpc/include/asm/mmu_context.h | 36 +++++++++++++++++++++++++++++++++-
mm/mremap.c | 19 ++++++++++++------
2 files changed, 48 insertions(+), 7 deletions(-)

--
1.9.1


2015-04-13 09:56:50

by Laurent Dufour

[permalink] [raw]
Subject: [RESEND PATCH v3 1/2] mm: Introducing arch_remap hook

Some architecture would like to be triggered when a memory area is moved
through the mremap system call.

This patch is introducing a new arch_remap mm hook which is placed in the
path of mremap, and is called before the old area is unmapped (and the
arch_unmap hook is called).

The architectures which need to call this hook should define
__HAVE_ARCH_REMAP in their asm/mmu_context.h and provide the arch_remap
service with the following prototype:
void arch_remap(struct mm_struct *mm,
unsigned long old_start, unsigned long old_end,
unsigned long new_start, unsigned long new_end);

Signed-off-by: Laurent Dufour <[email protected]>
Reviewed-by: Ingo Molnar <[email protected]>
---
mm/mremap.c | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/mm/mremap.c b/mm/mremap.c
index 2dc44b1cb1df..009db5565893 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -25,6 +25,7 @@

#include <asm/cacheflush.h>
#include <asm/tlbflush.h>
+#include <asm/mmu_context.h>

#include "internal.h"

@@ -286,13 +287,19 @@ static unsigned long move_vma(struct vm_area_struct *vma,
old_len = new_len;
old_addr = new_addr;
new_addr = -ENOMEM;
- } else if (vma->vm_file && vma->vm_file->f_op->mremap) {
- err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
- if (err < 0) {
- move_page_tables(new_vma, new_addr, vma, old_addr,
- moved_len, true);
- return err;
+ } else {
+ if (vma->vm_file && vma->vm_file->f_op->mremap) {
+ err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
+ if (err < 0) {
+ move_page_tables(new_vma, new_addr, vma,
+ old_addr, moved_len, true);
+ return err;
+ }
}
+#ifdef __HAVE_ARCH_REMAP
+ arch_remap(mm, old_addr, old_addr+old_len,
+ new_addr, new_addr+new_len);
+#endif
}

/* Conceal VM_ACCOUNT so old reservation is not undone */
--
1.9.1

2015-04-13 09:56:52

by Laurent Dufour

[permalink] [raw]
Subject: [RESEND PATCH v3 2/2] powerpc/mm: Tracking vDSO remap

Some processes (CRIU) are moving the vDSO area using the mremap system
call. As a consequence the kernel reference to the vDSO base address is
no more valid and the signal return frame built once the vDSO has been
moved is not pointing to the new sigreturn address.

This patch handles vDSO remapping and unmapping.

Signed-off-by: Laurent Dufour <[email protected]>
Reviewed-by: Ingo Molnar <[email protected]>
---
arch/powerpc/include/asm/mmu_context.h | 36 +++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/mmu_context.h b/arch/powerpc/include/asm/mmu_context.h
index 73382eba02dc..7d315c1898d4 100644
--- a/arch/powerpc/include/asm/mmu_context.h
+++ b/arch/powerpc/include/asm/mmu_context.h
@@ -8,7 +8,6 @@
#include <linux/spinlock.h>
#include <asm/mmu.h>
#include <asm/cputable.h>
-#include <asm-generic/mm_hooks.h>
#include <asm/cputhreads.h>

/*
@@ -109,5 +108,40 @@ static inline void enter_lazy_tlb(struct mm_struct *mm,
#endif
}

+static inline void arch_dup_mmap(struct mm_struct *oldmm,
+ struct mm_struct *mm)
+{
+}
+
+static inline void arch_exit_mmap(struct mm_struct *mm)
+{
+}
+
+static inline void arch_unmap(struct mm_struct *mm,
+ struct vm_area_struct *vma,
+ unsigned long start, unsigned long end)
+{
+ if (start <= mm->context.vdso_base && mm->context.vdso_base < end)
+ mm->context.vdso_base = 0;
+}
+
+static inline void arch_bprm_mm_init(struct mm_struct *mm,
+ struct vm_area_struct *vma)
+{
+}
+
+#define __HAVE_ARCH_REMAP
+static inline void arch_remap(struct mm_struct *mm,
+ unsigned long old_start, unsigned long old_end,
+ unsigned long new_start, unsigned long new_end)
+{
+ /*
+ * mremap() doesn't allow moving multiple vmas so we can limit the
+ * check to old_start == vdso_base.
+ */
+ if (old_start == mm->context.vdso_base)
+ mm->context.vdso_base = new_start;
+}
+
#endif /* __KERNEL__ */
#endif /* __ASM_POWERPC_MMU_CONTEXT_H */
--
1.9.1

2015-04-13 11:59:34

by Kirill A. Shutemov

[permalink] [raw]
Subject: Re: [RESEND PATCH v3 1/2] mm: Introducing arch_remap hook

On Mon, Apr 13, 2015 at 11:56:27AM +0200, Laurent Dufour wrote:
> Some architecture would like to be triggered when a memory area is moved
> through the mremap system call.
>
> This patch is introducing a new arch_remap mm hook which is placed in the
> path of mremap, and is called before the old area is unmapped (and the
> arch_unmap hook is called).
>
> The architectures which need to call this hook should define
> __HAVE_ARCH_REMAP in their asm/mmu_context.h and provide the arch_remap
> service with the following prototype:
> void arch_remap(struct mm_struct *mm,
> unsigned long old_start, unsigned long old_end,
> unsigned long new_start, unsigned long new_end);
>
> Signed-off-by: Laurent Dufour <[email protected]>
> Reviewed-by: Ingo Molnar <[email protected]>
> ---
> mm/mremap.c | 19 +++++++++++++------
> 1 file changed, 13 insertions(+), 6 deletions(-)
>
> diff --git a/mm/mremap.c b/mm/mremap.c
> index 2dc44b1cb1df..009db5565893 100644
> --- a/mm/mremap.c
> +++ b/mm/mremap.c
> @@ -25,6 +25,7 @@
>
> #include <asm/cacheflush.h>
> #include <asm/tlbflush.h>
> +#include <asm/mmu_context.h>
>
> #include "internal.h"
>
> @@ -286,13 +287,19 @@ static unsigned long move_vma(struct vm_area_struct *vma,
> old_len = new_len;
> old_addr = new_addr;
> new_addr = -ENOMEM;
> - } else if (vma->vm_file && vma->vm_file->f_op->mremap) {
> - err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
> - if (err < 0) {
> - move_page_tables(new_vma, new_addr, vma, old_addr,
> - moved_len, true);
> - return err;
> + } else {
> + if (vma->vm_file && vma->vm_file->f_op->mremap) {
> + err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
> + if (err < 0) {
> + move_page_tables(new_vma, new_addr, vma,
> + old_addr, moved_len, true);
> + return err;
> + }
> }
> +#ifdef __HAVE_ARCH_REMAP

It would be cleaner to provide dummy arch_remap() for !__HAVE_ARCH_REMAP
in some generic header.


> + arch_remap(mm, old_addr, old_addr+old_len,
> + new_addr, new_addr+new_len);

Spaces around '+'?

> +#endif
> }
>
> /* Conceal VM_ACCOUNT so old reservation is not undone */
> --
> 1.9.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

--
Kirill A. Shutemov

2015-04-13 12:41:43

by Laurent Dufour

[permalink] [raw]
Subject: Re: [RESEND PATCH v3 1/2] mm: Introducing arch_remap hook

On 13/04/2015 13:58, Kirill A. Shutemov wrote:
> On Mon, Apr 13, 2015 at 11:56:27AM +0200, Laurent Dufour wrote:
>> Some architecture would like to be triggered when a memory area is moved
>> through the mremap system call.
>>
>> This patch is introducing a new arch_remap mm hook which is placed in the
>> path of mremap, and is called before the old area is unmapped (and the
>> arch_unmap hook is called).
>>
>> The architectures which need to call this hook should define
>> __HAVE_ARCH_REMAP in their asm/mmu_context.h and provide the arch_remap
>> service with the following prototype:
>> void arch_remap(struct mm_struct *mm,
>> unsigned long old_start, unsigned long old_end,
>> unsigned long new_start, unsigned long new_end);
>>
>> Signed-off-by: Laurent Dufour <[email protected]>
>> Reviewed-by: Ingo Molnar <[email protected]>
>> ---
>> mm/mremap.c | 19 +++++++++++++------
>> 1 file changed, 13 insertions(+), 6 deletions(-)
>>
>> diff --git a/mm/mremap.c b/mm/mremap.c
>> index 2dc44b1cb1df..009db5565893 100644
>> --- a/mm/mremap.c
>> +++ b/mm/mremap.c
>> @@ -25,6 +25,7 @@
>>
>> #include <asm/cacheflush.h>
>> #include <asm/tlbflush.h>
>> +#include <asm/mmu_context.h>
>>
>> #include "internal.h"
>>
>> @@ -286,13 +287,19 @@ static unsigned long move_vma(struct vm_area_struct *vma,
>> old_len = new_len;
>> old_addr = new_addr;
>> new_addr = -ENOMEM;
>> - } else if (vma->vm_file && vma->vm_file->f_op->mremap) {
>> - err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
>> - if (err < 0) {
>> - move_page_tables(new_vma, new_addr, vma, old_addr,
>> - moved_len, true);
>> - return err;
>> + } else {
>> + if (vma->vm_file && vma->vm_file->f_op->mremap) {
>> + err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
>> + if (err < 0) {
>> + move_page_tables(new_vma, new_addr, vma,
>> + old_addr, moved_len, true);
>> + return err;
>> + }
>> }
>> +#ifdef __HAVE_ARCH_REMAP
>
> It would be cleaner to provide dummy arch_remap() for !__HAVE_ARCH_REMAP
> in some generic header.

The idea was to not impact all the architectures as arch_unmap(),
arch_dup_mmap() or arch_exit_mmap() implies.

I look at the headers where such a dummy arch_remap could be put but I
can't figure out one which will not impact all the architecture.
What about defining a dummy service earlier in mm/remap.c in the case
__HAVE_ARCH_REMAP is not defined ?
Something like :
#ifndef __HAVE_ARCH_REMAP
static inline void void arch_remap(struct mm_struct *mm,
unsigned long old_start,
unsigned long old_end,
unsigned long new_start,
unsigned long new_end)
{
}
#endif

>
>
>> + arch_remap(mm, old_addr, old_addr+old_len,
>> + new_addr, new_addr+new_len);
>
> Spaces around '+'?

Nice catch ;)

Thanks,
Laurent.

>
>> +#endif
>> }
>>
>> /* Conceal VM_ACCOUNT so old reservation is not undone */
>> --
>> 1.9.1
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
>> the body of a message to [email protected]
>> More majordomo info at http://vger.kernel.org/majordomo-info.html
>> Please read the FAQ at http://www.tux.org/lkml/
>

2015-04-13 13:14:36

by Kirill A. Shutemov

[permalink] [raw]
Subject: Re: [RESEND PATCH v3 1/2] mm: Introducing arch_remap hook

On Mon, Apr 13, 2015 at 02:41:22PM +0200, Laurent Dufour wrote:
> On 13/04/2015 13:58, Kirill A. Shutemov wrote:
> > On Mon, Apr 13, 2015 at 11:56:27AM +0200, Laurent Dufour wrote:
> >> Some architecture would like to be triggered when a memory area is moved
> >> through the mremap system call.
> >>
> >> This patch is introducing a new arch_remap mm hook which is placed in the
> >> path of mremap, and is called before the old area is unmapped (and the
> >> arch_unmap hook is called).
> >>
> >> The architectures which need to call this hook should define
> >> __HAVE_ARCH_REMAP in their asm/mmu_context.h and provide the arch_remap
> >> service with the following prototype:
> >> void arch_remap(struct mm_struct *mm,
> >> unsigned long old_start, unsigned long old_end,
> >> unsigned long new_start, unsigned long new_end);
> >>
> >> Signed-off-by: Laurent Dufour <[email protected]>
> >> Reviewed-by: Ingo Molnar <[email protected]>
> >> ---
> >> mm/mremap.c | 19 +++++++++++++------
> >> 1 file changed, 13 insertions(+), 6 deletions(-)
> >>
> >> diff --git a/mm/mremap.c b/mm/mremap.c
> >> index 2dc44b1cb1df..009db5565893 100644
> >> --- a/mm/mremap.c
> >> +++ b/mm/mremap.c
> >> @@ -25,6 +25,7 @@
> >>
> >> #include <asm/cacheflush.h>
> >> #include <asm/tlbflush.h>
> >> +#include <asm/mmu_context.h>
> >>
> >> #include "internal.h"
> >>
> >> @@ -286,13 +287,19 @@ static unsigned long move_vma(struct vm_area_struct *vma,
> >> old_len = new_len;
> >> old_addr = new_addr;
> >> new_addr = -ENOMEM;
> >> - } else if (vma->vm_file && vma->vm_file->f_op->mremap) {
> >> - err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
> >> - if (err < 0) {
> >> - move_page_tables(new_vma, new_addr, vma, old_addr,
> >> - moved_len, true);
> >> - return err;
> >> + } else {
> >> + if (vma->vm_file && vma->vm_file->f_op->mremap) {
> >> + err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
> >> + if (err < 0) {
> >> + move_page_tables(new_vma, new_addr, vma,
> >> + old_addr, moved_len, true);
> >> + return err;
> >> + }
> >> }
> >> +#ifdef __HAVE_ARCH_REMAP
> >
> > It would be cleaner to provide dummy arch_remap() for !__HAVE_ARCH_REMAP
> > in some generic header.
>
> The idea was to not impact all the architectures as arch_unmap(),
> arch_dup_mmap() or arch_exit_mmap() implies.
>
> I look at the headers where such a dummy arch_remap could be put but I
> can't figure out one which will not impact all the architecture.
> What about defining a dummy service earlier in mm/remap.c in the case
> __HAVE_ARCH_REMAP is not defined ?
> Something like :
> #ifndef __HAVE_ARCH_REMAP
> static inline void void arch_remap(struct mm_struct *mm,
> unsigned long old_start,
> unsigned long old_end,
> unsigned long new_start,
> unsigned long new_end)
> {
> }
> #endif

Or just #define arch_remap(...) do { } while (0)

--
Kirill A. Shutemov

2015-04-13 13:21:29

by Laurent Dufour

[permalink] [raw]
Subject: Re: [RESEND PATCH v3 1/2] mm: Introducing arch_remap hook

On 13/04/2015 15:13, Kirill A. Shutemov wrote:
> On Mon, Apr 13, 2015 at 02:41:22PM +0200, Laurent Dufour wrote:
>> On 13/04/2015 13:58, Kirill A. Shutemov wrote:
>>> On Mon, Apr 13, 2015 at 11:56:27AM +0200, Laurent Dufour wrote:
>>>> Some architecture would like to be triggered when a memory area is moved
>>>> through the mremap system call.
>>>>
>>>> This patch is introducing a new arch_remap mm hook which is placed in the
>>>> path of mremap, and is called before the old area is unmapped (and the
>>>> arch_unmap hook is called).
>>>>
>>>> The architectures which need to call this hook should define
>>>> __HAVE_ARCH_REMAP in their asm/mmu_context.h and provide the arch_remap
>>>> service with the following prototype:
>>>> void arch_remap(struct mm_struct *mm,
>>>> unsigned long old_start, unsigned long old_end,
>>>> unsigned long new_start, unsigned long new_end);
>>>>
>>>> Signed-off-by: Laurent Dufour <[email protected]>
>>>> Reviewed-by: Ingo Molnar <[email protected]>
>>>> ---
>>>> mm/mremap.c | 19 +++++++++++++------
>>>> 1 file changed, 13 insertions(+), 6 deletions(-)
>>>>
>>>> diff --git a/mm/mremap.c b/mm/mremap.c
>>>> index 2dc44b1cb1df..009db5565893 100644
>>>> --- a/mm/mremap.c
>>>> +++ b/mm/mremap.c
>>>> @@ -25,6 +25,7 @@
>>>>
>>>> #include <asm/cacheflush.h>
>>>> #include <asm/tlbflush.h>
>>>> +#include <asm/mmu_context.h>
>>>>
>>>> #include "internal.h"
>>>>
>>>> @@ -286,13 +287,19 @@ static unsigned long move_vma(struct vm_area_struct *vma,
>>>> old_len = new_len;
>>>> old_addr = new_addr;
>>>> new_addr = -ENOMEM;
>>>> - } else if (vma->vm_file && vma->vm_file->f_op->mremap) {
>>>> - err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
>>>> - if (err < 0) {
>>>> - move_page_tables(new_vma, new_addr, vma, old_addr,
>>>> - moved_len, true);
>>>> - return err;
>>>> + } else {
>>>> + if (vma->vm_file && vma->vm_file->f_op->mremap) {
>>>> + err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
>>>> + if (err < 0) {
>>>> + move_page_tables(new_vma, new_addr, vma,
>>>> + old_addr, moved_len, true);
>>>> + return err;
>>>> + }
>>>> }
>>>> +#ifdef __HAVE_ARCH_REMAP
>>>
>>> It would be cleaner to provide dummy arch_remap() for !__HAVE_ARCH_REMAP
>>> in some generic header.
>>
>> The idea was to not impact all the architectures as arch_unmap(),
>> arch_dup_mmap() or arch_exit_mmap() implies.
>>
>> I look at the headers where such a dummy arch_remap could be put but I
>> can't figure out one which will not impact all the architecture.
>> What about defining a dummy service earlier in mm/remap.c in the case
>> __HAVE_ARCH_REMAP is not defined ?
>> Something like :
>> #ifndef __HAVE_ARCH_REMAP
>> static inline void void arch_remap(struct mm_struct *mm,
>> unsigned long old_start,
>> unsigned long old_end,
>> unsigned long new_start,
>> unsigned long new_end)
>> {
>> }
>> #endif
>
> Or just #define arch_remap(...) do { } while (0)
>

I guessed you wanted the arch_remap() prototype to be exposed somewhere
in the code.

To be honest, I can't find the benefit of defining a dummy arch_remap()
in mm/remap.c if __HAVE_ARCH_REMAP is not defined instead of calling it
in move_vma if __HAVE_ARCH_REMAP is defined.
Is it really what you want ?

Thanks,
Laurent.

2015-04-13 13:36:04

by Pavel Emelyanov

[permalink] [raw]
Subject: Re: [RESEND PATCH v3 1/2] mm: Introducing arch_remap hook

On 04/13/2015 04:21 PM, Laurent Dufour wrote:
> On 13/04/2015 15:13, Kirill A. Shutemov wrote:
>> On Mon, Apr 13, 2015 at 02:41:22PM +0200, Laurent Dufour wrote:
>>> On 13/04/2015 13:58, Kirill A. Shutemov wrote:
>>>> On Mon, Apr 13, 2015 at 11:56:27AM +0200, Laurent Dufour wrote:
>>>>> Some architecture would like to be triggered when a memory area is moved
>>>>> through the mremap system call.
>>>>>
>>>>> This patch is introducing a new arch_remap mm hook which is placed in the
>>>>> path of mremap, and is called before the old area is unmapped (and the
>>>>> arch_unmap hook is called).
>>>>>
>>>>> The architectures which need to call this hook should define
>>>>> __HAVE_ARCH_REMAP in their asm/mmu_context.h and provide the arch_remap
>>>>> service with the following prototype:
>>>>> void arch_remap(struct mm_struct *mm,
>>>>> unsigned long old_start, unsigned long old_end,
>>>>> unsigned long new_start, unsigned long new_end);
>>>>>
>>>>> Signed-off-by: Laurent Dufour <[email protected]>
>>>>> Reviewed-by: Ingo Molnar <[email protected]>
>>>>> ---
>>>>> mm/mremap.c | 19 +++++++++++++------
>>>>> 1 file changed, 13 insertions(+), 6 deletions(-)
>>>>>
>>>>> diff --git a/mm/mremap.c b/mm/mremap.c
>>>>> index 2dc44b1cb1df..009db5565893 100644
>>>>> --- a/mm/mremap.c
>>>>> +++ b/mm/mremap.c
>>>>> @@ -25,6 +25,7 @@
>>>>>
>>>>> #include <asm/cacheflush.h>
>>>>> #include <asm/tlbflush.h>
>>>>> +#include <asm/mmu_context.h>
>>>>>
>>>>> #include "internal.h"
>>>>>
>>>>> @@ -286,13 +287,19 @@ static unsigned long move_vma(struct vm_area_struct *vma,
>>>>> old_len = new_len;
>>>>> old_addr = new_addr;
>>>>> new_addr = -ENOMEM;
>>>>> - } else if (vma->vm_file && vma->vm_file->f_op->mremap) {
>>>>> - err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
>>>>> - if (err < 0) {
>>>>> - move_page_tables(new_vma, new_addr, vma, old_addr,
>>>>> - moved_len, true);
>>>>> - return err;
>>>>> + } else {
>>>>> + if (vma->vm_file && vma->vm_file->f_op->mremap) {
>>>>> + err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
>>>>> + if (err < 0) {
>>>>> + move_page_tables(new_vma, new_addr, vma,
>>>>> + old_addr, moved_len, true);
>>>>> + return err;
>>>>> + }
>>>>> }
>>>>> +#ifdef __HAVE_ARCH_REMAP
>>>>
>>>> It would be cleaner to provide dummy arch_remap() for !__HAVE_ARCH_REMAP
>>>> in some generic header.
>>>
>>> The idea was to not impact all the architectures as arch_unmap(),
>>> arch_dup_mmap() or arch_exit_mmap() implies.
>>>
>>> I look at the headers where such a dummy arch_remap could be put but I
>>> can't figure out one which will not impact all the architecture.
>>> What about defining a dummy service earlier in mm/remap.c in the case
>>> __HAVE_ARCH_REMAP is not defined ?
>>> Something like :
>>> #ifndef __HAVE_ARCH_REMAP
>>> static inline void void arch_remap(struct mm_struct *mm,
>>> unsigned long old_start,
>>> unsigned long old_end,
>>> unsigned long new_start,
>>> unsigned long new_end)
>>> {
>>> }
>>> #endif
>>
>> Or just #define arch_remap(...) do { } while (0)
>>
>
> I guessed you wanted the arch_remap() prototype to be exposed somewhere
> in the code.
>
> To be honest, I can't find the benefit of defining a dummy arch_remap()
> in mm/remap.c if __HAVE_ARCH_REMAP is not defined instead of calling it
> in move_vma if __HAVE_ARCH_REMAP is defined.
> Is it really what you want ?

I think Kirill meant something like e.g. the arch_enter_lazy_mmu_mode()
is implemented and called in mm/mremap.c -- the "generic" part is in the
include/asm-generic/pgtable.h and those architectures willing to have
their own implementation are in arch/$arch/...

Kirill, if I'm right with it, can you suggest the header where to put
the "generic" mremap hook's (empty) body?

-- Pavel

2015-04-13 14:03:45

by Kirill A. Shutemov

[permalink] [raw]
Subject: Re: [RESEND PATCH v3 1/2] mm: Introducing arch_remap hook

On Mon, Apr 13, 2015 at 04:35:21PM +0300, Pavel Emelyanov wrote:
> On 04/13/2015 04:21 PM, Laurent Dufour wrote:
> > On 13/04/2015 15:13, Kirill A. Shutemov wrote:
> >> On Mon, Apr 13, 2015 at 02:41:22PM +0200, Laurent Dufour wrote:
> >>> On 13/04/2015 13:58, Kirill A. Shutemov wrote:
> >>>> On Mon, Apr 13, 2015 at 11:56:27AM +0200, Laurent Dufour wrote:
> >>>>> Some architecture would like to be triggered when a memory area is moved
> >>>>> through the mremap system call.
> >>>>>
> >>>>> This patch is introducing a new arch_remap mm hook which is placed in the
> >>>>> path of mremap, and is called before the old area is unmapped (and the
> >>>>> arch_unmap hook is called).
> >>>>>
> >>>>> The architectures which need to call this hook should define
> >>>>> __HAVE_ARCH_REMAP in their asm/mmu_context.h and provide the arch_remap
> >>>>> service with the following prototype:
> >>>>> void arch_remap(struct mm_struct *mm,
> >>>>> unsigned long old_start, unsigned long old_end,
> >>>>> unsigned long new_start, unsigned long new_end);
> >>>>>
> >>>>> Signed-off-by: Laurent Dufour <[email protected]>
> >>>>> Reviewed-by: Ingo Molnar <[email protected]>
> >>>>> ---
> >>>>> mm/mremap.c | 19 +++++++++++++------
> >>>>> 1 file changed, 13 insertions(+), 6 deletions(-)
> >>>>>
> >>>>> diff --git a/mm/mremap.c b/mm/mremap.c
> >>>>> index 2dc44b1cb1df..009db5565893 100644
> >>>>> --- a/mm/mremap.c
> >>>>> +++ b/mm/mremap.c
> >>>>> @@ -25,6 +25,7 @@
> >>>>>
> >>>>> #include <asm/cacheflush.h>
> >>>>> #include <asm/tlbflush.h>
> >>>>> +#include <asm/mmu_context.h>
> >>>>>
> >>>>> #include "internal.h"
> >>>>>
> >>>>> @@ -286,13 +287,19 @@ static unsigned long move_vma(struct vm_area_struct *vma,
> >>>>> old_len = new_len;
> >>>>> old_addr = new_addr;
> >>>>> new_addr = -ENOMEM;
> >>>>> - } else if (vma->vm_file && vma->vm_file->f_op->mremap) {
> >>>>> - err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
> >>>>> - if (err < 0) {
> >>>>> - move_page_tables(new_vma, new_addr, vma, old_addr,
> >>>>> - moved_len, true);
> >>>>> - return err;
> >>>>> + } else {
> >>>>> + if (vma->vm_file && vma->vm_file->f_op->mremap) {
> >>>>> + err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
> >>>>> + if (err < 0) {
> >>>>> + move_page_tables(new_vma, new_addr, vma,
> >>>>> + old_addr, moved_len, true);
> >>>>> + return err;
> >>>>> + }
> >>>>> }
> >>>>> +#ifdef __HAVE_ARCH_REMAP
> >>>>
> >>>> It would be cleaner to provide dummy arch_remap() for !__HAVE_ARCH_REMAP
> >>>> in some generic header.
> >>>
> >>> The idea was to not impact all the architectures as arch_unmap(),
> >>> arch_dup_mmap() or arch_exit_mmap() implies.
> >>>
> >>> I look at the headers where such a dummy arch_remap could be put but I
> >>> can't figure out one which will not impact all the architecture.
> >>> What about defining a dummy service earlier in mm/remap.c in the case
> >>> __HAVE_ARCH_REMAP is not defined ?
> >>> Something like :
> >>> #ifndef __HAVE_ARCH_REMAP
> >>> static inline void void arch_remap(struct mm_struct *mm,
> >>> unsigned long old_start,
> >>> unsigned long old_end,
> >>> unsigned long new_start,
> >>> unsigned long new_end)
> >>> {
> >>> }
> >>> #endif
> >>
> >> Or just #define arch_remap(...) do { } while (0)
> >>
> >
> > I guessed you wanted the arch_remap() prototype to be exposed somewhere
> > in the code.
> >
> > To be honest, I can't find the benefit of defining a dummy arch_remap()
> > in mm/remap.c if __HAVE_ARCH_REMAP is not defined instead of calling it
> > in move_vma if __HAVE_ARCH_REMAP is defined.
> > Is it really what you want ?
>
> I think Kirill meant something like e.g. the arch_enter_lazy_mmu_mode()
> is implemented and called in mm/mremap.c -- the "generic" part is in the
> include/asm-generic/pgtable.h and those architectures willing to have
> their own implementation are in arch/$arch/...
>
> Kirill, if I'm right with it, can you suggest the header where to put
> the "generic" mremap hook's (empty) body?

I initially thought it would be enough to put it into
<asm-generic/mmu_context.h>, expecting it works as
<asm-generic/pgtable.h>. But that's not the case.

It probably worth at some point rework all <asm/mmu_context.h> to include
<asm-generic/mmu_context.h> at the end as we do for <asm/pgtable.h>.
But that's outside the scope of the patchset, I guess.

I don't see any better candidate for such dummy header. :-/

--
Kirill A. Shutemov

2015-04-13 14:11:31

by Laurent Dufour

[permalink] [raw]
Subject: Re: [RESEND PATCH v3 1/2] mm: Introducing arch_remap hook

On 13/04/2015 16:02, Kirill A. Shutemov wrote:
> On Mon, Apr 13, 2015 at 04:35:21PM +0300, Pavel Emelyanov wrote:
>> On 04/13/2015 04:21 PM, Laurent Dufour wrote:
>>> On 13/04/2015 15:13, Kirill A. Shutemov wrote:
>>>> On Mon, Apr 13, 2015 at 02:41:22PM +0200, Laurent Dufour wrote:
>>>>> On 13/04/2015 13:58, Kirill A. Shutemov wrote:
>>>>>> On Mon, Apr 13, 2015 at 11:56:27AM +0200, Laurent Dufour wrote:
>>>>>>> Some architecture would like to be triggered when a memory area is moved
>>>>>>> through the mremap system call.
>>>>>>>
>>>>>>> This patch is introducing a new arch_remap mm hook which is placed in the
>>>>>>> path of mremap, and is called before the old area is unmapped (and the
>>>>>>> arch_unmap hook is called).
>>>>>>>
>>>>>>> The architectures which need to call this hook should define
>>>>>>> __HAVE_ARCH_REMAP in their asm/mmu_context.h and provide the arch_remap
>>>>>>> service with the following prototype:
>>>>>>> void arch_remap(struct mm_struct *mm,
>>>>>>> unsigned long old_start, unsigned long old_end,
>>>>>>> unsigned long new_start, unsigned long new_end);
>>>>>>>
>>>>>>> Signed-off-by: Laurent Dufour <[email protected]>
>>>>>>> Reviewed-by: Ingo Molnar <[email protected]>
>>>>>>> ---
>>>>>>> mm/mremap.c | 19 +++++++++++++------
>>>>>>> 1 file changed, 13 insertions(+), 6 deletions(-)
>>>>>>>
>>>>>>> diff --git a/mm/mremap.c b/mm/mremap.c
>>>>>>> index 2dc44b1cb1df..009db5565893 100644
>>>>>>> --- a/mm/mremap.c
>>>>>>> +++ b/mm/mremap.c
>>>>>>> @@ -25,6 +25,7 @@
>>>>>>>
>>>>>>> #include <asm/cacheflush.h>
>>>>>>> #include <asm/tlbflush.h>
>>>>>>> +#include <asm/mmu_context.h>
>>>>>>>
>>>>>>> #include "internal.h"
>>>>>>>
>>>>>>> @@ -286,13 +287,19 @@ static unsigned long move_vma(struct vm_area_struct *vma,
>>>>>>> old_len = new_len;
>>>>>>> old_addr = new_addr;
>>>>>>> new_addr = -ENOMEM;
>>>>>>> - } else if (vma->vm_file && vma->vm_file->f_op->mremap) {
>>>>>>> - err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
>>>>>>> - if (err < 0) {
>>>>>>> - move_page_tables(new_vma, new_addr, vma, old_addr,
>>>>>>> - moved_len, true);
>>>>>>> - return err;
>>>>>>> + } else {
>>>>>>> + if (vma->vm_file && vma->vm_file->f_op->mremap) {
>>>>>>> + err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
>>>>>>> + if (err < 0) {
>>>>>>> + move_page_tables(new_vma, new_addr, vma,
>>>>>>> + old_addr, moved_len, true);
>>>>>>> + return err;
>>>>>>> + }
>>>>>>> }
>>>>>>> +#ifdef __HAVE_ARCH_REMAP
>>>>>>
>>>>>> It would be cleaner to provide dummy arch_remap() for !__HAVE_ARCH_REMAP
>>>>>> in some generic header.
>>>>>
>>>>> The idea was to not impact all the architectures as arch_unmap(),
>>>>> arch_dup_mmap() or arch_exit_mmap() implies.
>>>>>
>>>>> I look at the headers where such a dummy arch_remap could be put but I
>>>>> can't figure out one which will not impact all the architecture.
>>>>> What about defining a dummy service earlier in mm/remap.c in the case
>>>>> __HAVE_ARCH_REMAP is not defined ?
>>>>> Something like :
>>>>> #ifndef __HAVE_ARCH_REMAP
>>>>> static inline void void arch_remap(struct mm_struct *mm,
>>>>> unsigned long old_start,
>>>>> unsigned long old_end,
>>>>> unsigned long new_start,
>>>>> unsigned long new_end)
>>>>> {
>>>>> }
>>>>> #endif
>>>>
>>>> Or just #define arch_remap(...) do { } while (0)
>>>>
>>>
>>> I guessed you wanted the arch_remap() prototype to be exposed somewhere
>>> in the code.
>>>
>>> To be honest, I can't find the benefit of defining a dummy arch_remap()
>>> in mm/remap.c if __HAVE_ARCH_REMAP is not defined instead of calling it
>>> in move_vma if __HAVE_ARCH_REMAP is defined.
>>> Is it really what you want ?
>>
>> I think Kirill meant something like e.g. the arch_enter_lazy_mmu_mode()
>> is implemented and called in mm/mremap.c -- the "generic" part is in the
>> include/asm-generic/pgtable.h and those architectures willing to have
>> their own implementation are in arch/$arch/...
>>
>> Kirill, if I'm right with it, can you suggest the header where to put
>> the "generic" mremap hook's (empty) body?
>
> I initially thought it would be enough to put it into
> <asm-generic/mmu_context.h>, expecting it works as
> <asm-generic/pgtable.h>. But that's not the case.
>
> It probably worth at some point rework all <asm/mmu_context.h> to include
> <asm-generic/mmu_context.h> at the end as we do for <asm/pgtable.h>.
> But that's outside the scope of the patchset, I guess.
>
> I don't see any better candidate for such dummy header. :-/

Clearly, I'm not confortable with a rewrite of <asm/mmu_context.h> :(

So what about this patch, is this v3 acceptable ?

Cheers,
Laurent.

2015-04-13 14:29:14

by Kirill A. Shutemov

[permalink] [raw]
Subject: Re: [RESEND PATCH v3 1/2] mm: Introducing arch_remap hook

On Mon, Apr 13, 2015 at 04:11:19PM +0200, Laurent Dufour wrote:
> On 13/04/2015 16:02, Kirill A. Shutemov wrote:
> > On Mon, Apr 13, 2015 at 04:35:21PM +0300, Pavel Emelyanov wrote:
> >> On 04/13/2015 04:21 PM, Laurent Dufour wrote:
> >>> On 13/04/2015 15:13, Kirill A. Shutemov wrote:
> >>>> On Mon, Apr 13, 2015 at 02:41:22PM +0200, Laurent Dufour wrote:
> >>>>> On 13/04/2015 13:58, Kirill A. Shutemov wrote:
> >>>>>> On Mon, Apr 13, 2015 at 11:56:27AM +0200, Laurent Dufour wrote:
> >>>>>>> Some architecture would like to be triggered when a memory area is moved
> >>>>>>> through the mremap system call.
> >>>>>>>
> >>>>>>> This patch is introducing a new arch_remap mm hook which is placed in the
> >>>>>>> path of mremap, and is called before the old area is unmapped (and the
> >>>>>>> arch_unmap hook is called).
> >>>>>>>
> >>>>>>> The architectures which need to call this hook should define
> >>>>>>> __HAVE_ARCH_REMAP in their asm/mmu_context.h and provide the arch_remap
> >>>>>>> service with the following prototype:
> >>>>>>> void arch_remap(struct mm_struct *mm,
> >>>>>>> unsigned long old_start, unsigned long old_end,
> >>>>>>> unsigned long new_start, unsigned long new_end);
> >>>>>>>
> >>>>>>> Signed-off-by: Laurent Dufour <[email protected]>
> >>>>>>> Reviewed-by: Ingo Molnar <[email protected]>
> >>>>>>> ---
> >>>>>>> mm/mremap.c | 19 +++++++++++++------
> >>>>>>> 1 file changed, 13 insertions(+), 6 deletions(-)
> >>>>>>>
> >>>>>>> diff --git a/mm/mremap.c b/mm/mremap.c
> >>>>>>> index 2dc44b1cb1df..009db5565893 100644
> >>>>>>> --- a/mm/mremap.c
> >>>>>>> +++ b/mm/mremap.c
> >>>>>>> @@ -25,6 +25,7 @@
> >>>>>>>
> >>>>>>> #include <asm/cacheflush.h>
> >>>>>>> #include <asm/tlbflush.h>
> >>>>>>> +#include <asm/mmu_context.h>
> >>>>>>>
> >>>>>>> #include "internal.h"
> >>>>>>>
> >>>>>>> @@ -286,13 +287,19 @@ static unsigned long move_vma(struct vm_area_struct *vma,
> >>>>>>> old_len = new_len;
> >>>>>>> old_addr = new_addr;
> >>>>>>> new_addr = -ENOMEM;
> >>>>>>> - } else if (vma->vm_file && vma->vm_file->f_op->mremap) {
> >>>>>>> - err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
> >>>>>>> - if (err < 0) {
> >>>>>>> - move_page_tables(new_vma, new_addr, vma, old_addr,
> >>>>>>> - moved_len, true);
> >>>>>>> - return err;
> >>>>>>> + } else {
> >>>>>>> + if (vma->vm_file && vma->vm_file->f_op->mremap) {
> >>>>>>> + err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
> >>>>>>> + if (err < 0) {
> >>>>>>> + move_page_tables(new_vma, new_addr, vma,
> >>>>>>> + old_addr, moved_len, true);
> >>>>>>> + return err;
> >>>>>>> + }
> >>>>>>> }
> >>>>>>> +#ifdef __HAVE_ARCH_REMAP
> >>>>>>
> >>>>>> It would be cleaner to provide dummy arch_remap() for !__HAVE_ARCH_REMAP
> >>>>>> in some generic header.
> >>>>>
> >>>>> The idea was to not impact all the architectures as arch_unmap(),
> >>>>> arch_dup_mmap() or arch_exit_mmap() implies.
> >>>>>
> >>>>> I look at the headers where such a dummy arch_remap could be put but I
> >>>>> can't figure out one which will not impact all the architecture.
> >>>>> What about defining a dummy service earlier in mm/remap.c in the case
> >>>>> __HAVE_ARCH_REMAP is not defined ?
> >>>>> Something like :
> >>>>> #ifndef __HAVE_ARCH_REMAP
> >>>>> static inline void void arch_remap(struct mm_struct *mm,
> >>>>> unsigned long old_start,
> >>>>> unsigned long old_end,
> >>>>> unsigned long new_start,
> >>>>> unsigned long new_end)
> >>>>> {
> >>>>> }
> >>>>> #endif
> >>>>
> >>>> Or just #define arch_remap(...) do { } while (0)
> >>>>
> >>>
> >>> I guessed you wanted the arch_remap() prototype to be exposed somewhere
> >>> in the code.
> >>>
> >>> To be honest, I can't find the benefit of defining a dummy arch_remap()
> >>> in mm/remap.c if __HAVE_ARCH_REMAP is not defined instead of calling it
> >>> in move_vma if __HAVE_ARCH_REMAP is defined.
> >>> Is it really what you want ?
> >>
> >> I think Kirill meant something like e.g. the arch_enter_lazy_mmu_mode()
> >> is implemented and called in mm/mremap.c -- the "generic" part is in the
> >> include/asm-generic/pgtable.h and those architectures willing to have
> >> their own implementation are in arch/$arch/...
> >>
> >> Kirill, if I'm right with it, can you suggest the header where to put
> >> the "generic" mremap hook's (empty) body?
> >
> > I initially thought it would be enough to put it into
> > <asm-generic/mmu_context.h>, expecting it works as
> > <asm-generic/pgtable.h>. But that's not the case.
> >
> > It probably worth at some point rework all <asm/mmu_context.h> to include
> > <asm-generic/mmu_context.h> at the end as we do for <asm/pgtable.h>.
> > But that's outside the scope of the patchset, I guess.
> >
> > I don't see any better candidate for such dummy header. :-/
>
> Clearly, I'm not confortable with a rewrite of <asm/mmu_context.h> :(
>
> So what about this patch, is this v3 acceptable ?

Acked-by: Kirill A. Shutemov <[email protected]>

--
Kirill A. Shutemov

2015-04-13 14:32:46

by Pavel Emelyanov

[permalink] [raw]
Subject: Re: [RESEND PATCH v3 1/2] mm: Introducing arch_remap hook

>>> I initially thought it would be enough to put it into
>>> <asm-generic/mmu_context.h>, expecting it works as
>>> <asm-generic/pgtable.h>. But that's not the case.
>>>
>>> It probably worth at some point rework all <asm/mmu_context.h> to include
>>> <asm-generic/mmu_context.h> at the end as we do for <asm/pgtable.h>.
>>> But that's outside the scope of the patchset, I guess.
>>>
>>> I don't see any better candidate for such dummy header. :-/
>>
>> Clearly, I'm not confortable with a rewrite of <asm/mmu_context.h> :(
>>
>> So what about this patch, is this v3 acceptable ?
>
> Acked-by: Kirill A. Shutemov <[email protected]>

Other than the #ifdef thing, the same:

Acked-by: Pavel Emelyanov <[email protected]>

2015-04-13 15:27:45

by Laurent Dufour

[permalink] [raw]
Subject: Re: [RESEND PATCH v3 1/2] mm: Introducing arch_remap hook

On 13/04/2015 16:32, Pavel Emelyanov wrote:
>>>> I initially thought it would be enough to put it into
>>>> <asm-generic/mmu_context.h>, expecting it works as
>>>> <asm-generic/pgtable.h>. But that's not the case.
>>>>
>>>> It probably worth at some point rework all <asm/mmu_context.h> to include
>>>> <asm-generic/mmu_context.h> at the end as we do for <asm/pgtable.h>.
>>>> But that's outside the scope of the patchset, I guess.
>>>>
>>>> I don't see any better candidate for such dummy header. :-/
>>>
>>> Clearly, I'm not confortable with a rewrite of <asm/mmu_context.h> :(
>>>
>>> So what about this patch, is this v3 acceptable ?
>>
>> Acked-by: Kirill A. Shutemov <[email protected]>
>
> Other than the #ifdef thing, the same:
>
> Acked-by: Pavel Emelyanov <[email protected]>
>

Thanks Kirill and Pavel.

Should I send a new version fixing the spaces around the plus sign ?

Cheers,
Laurent.

2015-04-13 20:59:54

by Andrew Morton

[permalink] [raw]
Subject: Re: [RESEND PATCH v3 1/2] mm: Introducing arch_remap hook

On Mon, 13 Apr 2015 17:02:19 +0300 "Kirill A. Shutemov" <[email protected]> wrote:

> > Kirill, if I'm right with it, can you suggest the header where to put
> > the "generic" mremap hook's (empty) body?
>
> I initially thought it would be enough to put it into
> <asm-generic/mmu_context.h>, expecting it works as
> <asm-generic/pgtable.h>. But that's not the case.
>
> It probably worth at some point rework all <asm/mmu_context.h> to include
> <asm-generic/mmu_context.h> at the end as we do for <asm/pgtable.h>.
> But that's outside the scope of the patchset, I guess.
>
> I don't see any better candidate for such dummy header. :-/

Do away with __HAVE_ARCH_REMAP and do it like this:

arch/x/include/asm/y.h:

extern void arch_remap(...);
#define arch_remap arch_remap

include/linux/z.h:

#include <asm/y.h>

#ifndef arch_remap
static inline void arch_remap(...) { }
#define arch_remap arch_remap
#endif

2015-04-14 09:26:30

by Laurent Dufour

[permalink] [raw]
Subject: Re: [RESEND PATCH v3 1/2] mm: Introducing arch_remap hook

On 13/04/2015 22:59, Andrew Morton wrote:
> On Mon, 13 Apr 2015 17:02:19 +0300 "Kirill A. Shutemov" <[email protected]> wrote:
>
>>> Kirill, if I'm right with it, can you suggest the header where to put
>>> the "generic" mremap hook's (empty) body?
>>
>> I initially thought it would be enough to put it into
>> <asm-generic/mmu_context.h>, expecting it works as
>> <asm-generic/pgtable.h>. But that's not the case.
>>
>> It probably worth at some point rework all <asm/mmu_context.h> to include
>> <asm-generic/mmu_context.h> at the end as we do for <asm/pgtable.h>.
>> But that's outside the scope of the patchset, I guess.
>>
>> I don't see any better candidate for such dummy header. :-/
>
> Do away with __HAVE_ARCH_REMAP and do it like this:
>
> arch/x/include/asm/y.h:
>
> extern void arch_remap(...);
> #define arch_remap arch_remap
>
> include/linux/z.h:
>
> #include <asm/y.h>
>
> #ifndef arch_remap
> static inline void arch_remap(...) { }
> #define arch_remap arch_remap
> #endif

Hi Andrew,

I like your idea, but I can't find any good candidate for <asm/y.h> and
<linux/z.h>.

I tried with <linux/mm.h> and <asm/mmu_context.h> but
<asm/mmu_context.h> is already including <linux/mm.h>.

Do you have any suggestion ?

Another option could be to do it like the actual arch_unmap() in
<asm-generic/mm_hooks.h> but this is the opposite of your idea, and Ingo
was not comfortable with this idea due to the impact of the other
architectures.

Cheers,
Laurent.

2015-04-14 19:39:05

by Andrew Morton

[permalink] [raw]
Subject: Re: [RESEND PATCH v3 1/2] mm: Introducing arch_remap hook

On Tue, 14 Apr 2015 11:26:13 +0200 Laurent Dufour <[email protected]> wrote:

> > Do away with __HAVE_ARCH_REMAP and do it like this:
> >
> > arch/x/include/asm/y.h:
> >
> > extern void arch_remap(...);
> > #define arch_remap arch_remap
> >
> > include/linux/z.h:
> >
> > #include <asm/y.h>
> >
> > #ifndef arch_remap
> > static inline void arch_remap(...) { }
> > #define arch_remap arch_remap
> > #endif
>
> Hi Andrew,
>
> I like your idea, but I can't find any good candidate for <asm/y.h> and
> <linux/z.h>.
>
> I tried with <linux/mm.h> and <asm/mmu_context.h> but
> <asm/mmu_context.h> is already including <linux/mm.h>.
>
> Do you have any suggestion ?
>
> Another option could be to do it like the actual arch_unmap() in
> <asm-generic/mm_hooks.h> but this is the opposite of your idea, and Ingo
> was not comfortable with this idea due to the impact of the other
> architectures.

I don't see any appropriate header files for this. mman.h is kinda
close.

So we create new header files, that's not a problem. I'm torn between

a) include/linux/mm-arch-hooks.h (and 31
arch/X/include/asm/mm-arch-hooks.h). Mandate: mm stuff which can be
overridded by arch

versus

b) include/linux/mremap.h (+31), with a narrower mandate.


This comes up fairly regularly so I suspect a) is better. We'll add
things to it over time, and various bits of existing ad-hackery can be
moved over as cleanups.

2015-04-15 11:58:07

by Laurent Dufour

[permalink] [raw]
Subject: Re: [RESEND PATCH v3 1/2] mm: Introducing arch_remap hook

On 14/04/2015 21:38, Andrew Morton wrote:
> On Tue, 14 Apr 2015 11:26:13 +0200 Laurent Dufour <[email protected]> wrote:
>
>>> Do away with __HAVE_ARCH_REMAP and do it like this:
>>>
>>> arch/x/include/asm/y.h:
>>>
>>> extern void arch_remap(...);
>>> #define arch_remap arch_remap
>>>
>>> include/linux/z.h:
>>>
>>> #include <asm/y.h>
>>>
>>> #ifndef arch_remap
>>> static inline void arch_remap(...) { }
>>> #define arch_remap arch_remap
>>> #endif
>>
>> Hi Andrew,
>>
>> I like your idea, but I can't find any good candidate for <asm/y.h> and
>> <linux/z.h>.
>>
>> I tried with <linux/mm.h> and <asm/mmu_context.h> but
>> <asm/mmu_context.h> is already including <linux/mm.h>.
>>
>> Do you have any suggestion ?
>>
>> Another option could be to do it like the actual arch_unmap() in
>> <asm-generic/mm_hooks.h> but this is the opposite of your idea, and Ingo
>> was not comfortable with this idea due to the impact of the other
>> architectures.
>
> I don't see any appropriate header files for this. mman.h is kinda
> close.
>
> So we create new header files, that's not a problem. I'm torn between
>
> a) include/linux/mm-arch-hooks.h (and 31
> arch/X/include/asm/mm-arch-hooks.h). Mandate: mm stuff which can be
> overridded by arch
>
> versus
>
> b) include/linux/mremap.h (+31), with a narrower mandate.
>
>
> This comes up fairly regularly so I suspect a) is better. We'll add
> things to it over time, and various bits of existing ad-hackery can be
> moved over as cleanups.

Thanks for the advice,

I'll do a), starting with the arch_remap macro, adding the 30 "empty"
arch/x/include/asm/mm-arch-hooks.h files, and implementing arch_remap
for powerpc.

Then, if the first patch is accepted, I may move the arch_*() stuff
defined in include/asm-generic/mm_hooks.h into
include/linux/mm-arch-hooks.h and filled some
arch/X/include/asm/mm-arch-hooks.h. The file
include/asm-generic/mm_hooks.h will then become empty, and been removed.

Cheers,
Laurent.


* Anglais - d?tect?
* Fran?ais
* Anglais

* Fran?ais
* Anglais

<javascript:void(0);>

2015-04-15 14:17:13

by Laurent Dufour

[permalink] [raw]
Subject: [PATCH v5 0/3] Tracking user space vDSO remaping

CRIU is recreating the process memory layout by remapping the checkpointee
memory area on top of the current process (criu). This includes remapping
the vDSO to the place it has at checkpoint time.

However some architectures like powerpc are keeping a reference to the vDSO
base address to build the signal return stack frame by calling the vDSO
sigreturn service. So once the vDSO has been moved, this reference is no
more valid and the signal frame built later are not usable.

This patch serie is introducing a new mm hook framework, and a new
arch_remap hook which is called when mremap is done and the mm lock still
hold. The next patch is adding the vDSO remap and unmap tracking to the
powerpc architecture.

Changes in v5:
- Jumping over v4 which was too complex (PowerPC part) for the need.
- Introducing new mm hook framework as suggested by Andrew Morton.

Changes in v4:
- Reviewing the PowerPC part of the patch to handle partial unmap and remap
of the vDSO.

Changes in v3:
- Fixed grammatical error in a comment of the second patch.
Thanks again, Ingo.

Changes in v2:
--------------
- Following the Ingo Molnar's advice, enabling the call to arch_remap through
the __HAVE_ARCH_REMAP macro. This reduces considerably the first patch.

Laurent Dufour (3):
mm: New mm hook framework
mm: New arch_remap hook
powerpc/mm: Tracking vDSO remap

arch/alpha/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/arc/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/arm/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/arm64/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/avr32/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/blackfin/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/c6x/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/cris/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/frv/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/hexagon/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/ia64/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/m32r/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/m68k/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/metag/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/microblaze/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/mips/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/mn10300/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/nios2/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/openrisc/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/parisc/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/powerpc/include/asm/mm-arch-hooks.h | 28 ++++++++++++++++++++++++++++
arch/powerpc/include/asm/mmu_context.h | 23 ++++++++++++++++++++++-
arch/s390/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/score/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/sh/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/sparc/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/tile/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/um/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/unicore32/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/x86/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/xtensa/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
include/linux/mm-arch-hooks.h | 25 +++++++++++++++++++++++++
mm/mremap.c | 17 +++++++++++------
33 files changed, 521 insertions(+), 7 deletions(-)
create mode 100644 arch/alpha/include/asm/mm-arch-hooks.h
create mode 100644 arch/arc/include/asm/mm-arch-hooks.h
create mode 100644 arch/arm/include/asm/mm-arch-hooks.h
create mode 100644 arch/arm64/include/asm/mm-arch-hooks.h
create mode 100644 arch/avr32/include/asm/mm-arch-hooks.h
create mode 100644 arch/blackfin/include/asm/mm-arch-hooks.h
create mode 100644 arch/c6x/include/asm/mm-arch-hooks.h
create mode 100644 arch/cris/include/asm/mm-arch-hooks.h
create mode 100644 arch/frv/include/asm/mm-arch-hooks.h
create mode 100644 arch/hexagon/include/asm/mm-arch-hooks.h
create mode 100644 arch/ia64/include/asm/mm-arch-hooks.h
create mode 100644 arch/m32r/include/asm/mm-arch-hooks.h
create mode 100644 arch/m68k/include/asm/mm-arch-hooks.h
create mode 100644 arch/metag/include/asm/mm-arch-hooks.h
create mode 100644 arch/microblaze/include/asm/mm-arch-hooks.h
create mode 100644 arch/mips/include/asm/mm-arch-hooks.h
create mode 100644 arch/mn10300/include/asm/mm-arch-hooks.h
create mode 100644 arch/nios2/include/asm/mm-arch-hooks.h
create mode 100644 arch/openrisc/include/asm/mm-arch-hooks.h
create mode 100644 arch/parisc/include/asm/mm-arch-hooks.h
create mode 100644 arch/powerpc/include/asm/mm-arch-hooks.h
create mode 100644 arch/s390/include/asm/mm-arch-hooks.h
create mode 100644 arch/score/include/asm/mm-arch-hooks.h
create mode 100644 arch/sh/include/asm/mm-arch-hooks.h
create mode 100644 arch/sparc/include/asm/mm-arch-hooks.h
create mode 100644 arch/tile/include/asm/mm-arch-hooks.h
create mode 100644 arch/um/include/asm/mm-arch-hooks.h
create mode 100644 arch/unicore32/include/asm/mm-arch-hooks.h
create mode 100644 arch/x86/include/asm/mm-arch-hooks.h
create mode 100644 arch/xtensa/include/asm/mm-arch-hooks.h
create mode 100644 include/linux/mm-arch-hooks.h

--
1.9.1

2015-04-15 14:17:58

by Laurent Dufour

[permalink] [raw]
Subject: [PATCH v5 1/3] mm: New mm hook framework

This patch introduces a new set of header file to manage mm hooks:
- per architecture empty header file (arch/x/include/asm/mm-arch-hooks.h)
- a generic header (include/linux/mm-arch-hooks.h)

The architecture which need to overwrite a hook as to redefine it in its
header file, while architecture which doesn't need have nothing to do.

The default hooks are defined in the generic header and are used in the case
the architecture is not defining it.

In a next step, mm hooks defined in include/asm-generic/mm_hooks.h should be
moved here.

Signed-off-by: Laurent Dufour <[email protected]>
Suggested-by: Andrew Morton <[email protected]>
---
arch/alpha/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/arc/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/arm/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/arm64/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/avr32/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/blackfin/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/c6x/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/cris/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/frv/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/hexagon/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/ia64/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/m32r/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/m68k/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/metag/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/microblaze/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/mips/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/mn10300/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/nios2/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/openrisc/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/parisc/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/powerpc/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/s390/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/score/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/sh/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/sparc/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/tile/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/um/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/unicore32/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/x86/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
arch/xtensa/include/asm/mm-arch-hooks.h | 15 +++++++++++++++
include/linux/mm-arch-hooks.h | 16 ++++++++++++++++
31 files changed, 466 insertions(+)
create mode 100644 arch/alpha/include/asm/mm-arch-hooks.h
create mode 100644 arch/arc/include/asm/mm-arch-hooks.h
create mode 100644 arch/arm/include/asm/mm-arch-hooks.h
create mode 100644 arch/arm64/include/asm/mm-arch-hooks.h
create mode 100644 arch/avr32/include/asm/mm-arch-hooks.h
create mode 100644 arch/blackfin/include/asm/mm-arch-hooks.h
create mode 100644 arch/c6x/include/asm/mm-arch-hooks.h
create mode 100644 arch/cris/include/asm/mm-arch-hooks.h
create mode 100644 arch/frv/include/asm/mm-arch-hooks.h
create mode 100644 arch/hexagon/include/asm/mm-arch-hooks.h
create mode 100644 arch/ia64/include/asm/mm-arch-hooks.h
create mode 100644 arch/m32r/include/asm/mm-arch-hooks.h
create mode 100644 arch/m68k/include/asm/mm-arch-hooks.h
create mode 100644 arch/metag/include/asm/mm-arch-hooks.h
create mode 100644 arch/microblaze/include/asm/mm-arch-hooks.h
create mode 100644 arch/mips/include/asm/mm-arch-hooks.h
create mode 100644 arch/mn10300/include/asm/mm-arch-hooks.h
create mode 100644 arch/nios2/include/asm/mm-arch-hooks.h
create mode 100644 arch/openrisc/include/asm/mm-arch-hooks.h
create mode 100644 arch/parisc/include/asm/mm-arch-hooks.h
create mode 100644 arch/powerpc/include/asm/mm-arch-hooks.h
create mode 100644 arch/s390/include/asm/mm-arch-hooks.h
create mode 100644 arch/score/include/asm/mm-arch-hooks.h
create mode 100644 arch/sh/include/asm/mm-arch-hooks.h
create mode 100644 arch/sparc/include/asm/mm-arch-hooks.h
create mode 100644 arch/tile/include/asm/mm-arch-hooks.h
create mode 100644 arch/um/include/asm/mm-arch-hooks.h
create mode 100644 arch/unicore32/include/asm/mm-arch-hooks.h
create mode 100644 arch/x86/include/asm/mm-arch-hooks.h
create mode 100644 arch/xtensa/include/asm/mm-arch-hooks.h
create mode 100644 include/linux/mm-arch-hooks.h

diff --git a/arch/alpha/include/asm/mm-arch-hooks.h b/arch/alpha/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..b07fd862fec3
--- /dev/null
+++ b/arch/alpha/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_ALPHA_MM_ARCH_HOOKS_H
+#define _ASM_ALPHA_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_ALPHA_MM_ARCH_HOOKS_H */
diff --git a/arch/arc/include/asm/mm-arch-hooks.h b/arch/arc/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..c37541c5f8ba
--- /dev/null
+++ b/arch/arc/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_ARC_MM_ARCH_HOOKS_H
+#define _ASM_ARC_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_ARC_MM_ARCH_HOOKS_H */
diff --git a/arch/arm/include/asm/mm-arch-hooks.h b/arch/arm/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..7056660c7cc4
--- /dev/null
+++ b/arch/arm/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_ARM_MM_ARCH_HOOKS_H
+#define _ASM_ARM_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_ARM_MM_ARCH_HOOKS_H */
diff --git a/arch/arm64/include/asm/mm-arch-hooks.h b/arch/arm64/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..562b655f5ba9
--- /dev/null
+++ b/arch/arm64/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_ARM64_MM_ARCH_HOOKS_H
+#define _ASM_ARM64_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_ARM64_MM_ARCH_HOOKS_H */
diff --git a/arch/avr32/include/asm/mm-arch-hooks.h b/arch/avr32/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..145452ffbdad
--- /dev/null
+++ b/arch/avr32/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_AVR32_MM_ARCH_HOOKS_H
+#define _ASM_AVR32_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_AVR32_MM_ARCH_HOOKS_H */
diff --git a/arch/blackfin/include/asm/mm-arch-hooks.h b/arch/blackfin/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..1c5211ec338f
--- /dev/null
+++ b/arch/blackfin/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_BLACKFIN_MM_ARCH_HOOKS_H
+#define _ASM_BLACKFIN_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_BLACKFIN_MM_ARCH_HOOKS_H */
diff --git a/arch/c6x/include/asm/mm-arch-hooks.h b/arch/c6x/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..bb3c4a6ce8e9
--- /dev/null
+++ b/arch/c6x/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_C6X_MM_ARCH_HOOKS_H
+#define _ASM_C6X_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_C6X_MM_ARCH_HOOKS_H */
diff --git a/arch/cris/include/asm/mm-arch-hooks.h b/arch/cris/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..314f774db2b0
--- /dev/null
+++ b/arch/cris/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_CRIS_MM_ARCH_HOOKS_H
+#define _ASM_CRIS_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_CRIS_MM_ARCH_HOOKS_H */
diff --git a/arch/frv/include/asm/mm-arch-hooks.h b/arch/frv/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..51d13a870404
--- /dev/null
+++ b/arch/frv/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_FRV_MM_ARCH_HOOKS_H
+#define _ASM_FRV_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_FRV_MM_ARCH_HOOKS_H */
diff --git a/arch/hexagon/include/asm/mm-arch-hooks.h b/arch/hexagon/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..05e8b939e416
--- /dev/null
+++ b/arch/hexagon/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_HEXAGON_MM_ARCH_HOOKS_H
+#define _ASM_HEXAGON_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_HEXAGON_MM_ARCH_HOOKS_H */
diff --git a/arch/ia64/include/asm/mm-arch-hooks.h b/arch/ia64/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..ab4b5c698322
--- /dev/null
+++ b/arch/ia64/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_IA64_MM_ARCH_HOOKS_H
+#define _ASM_IA64_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_IA64_MM_ARCH_HOOKS_H */
diff --git a/arch/m32r/include/asm/mm-arch-hooks.h b/arch/m32r/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..6d60b4750f41
--- /dev/null
+++ b/arch/m32r/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_M32R_MM_ARCH_HOOKS_H
+#define _ASM_M32R_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_M32R_MM_ARCH_HOOKS_H */
diff --git a/arch/m68k/include/asm/mm-arch-hooks.h b/arch/m68k/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..7e8709bc90ae
--- /dev/null
+++ b/arch/m68k/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_M68K_MM_ARCH_HOOKS_H
+#define _ASM_M68K_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_M68K_MM_ARCH_HOOKS_H */
diff --git a/arch/metag/include/asm/mm-arch-hooks.h b/arch/metag/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..b0072b2eb0de
--- /dev/null
+++ b/arch/metag/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_METAG_MM_ARCH_HOOKS_H
+#define _ASM_METAG_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_METAG_MM_ARCH_HOOKS_H */
diff --git a/arch/microblaze/include/asm/mm-arch-hooks.h b/arch/microblaze/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..5c4065911bda
--- /dev/null
+++ b/arch/microblaze/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_MICROBLAZE_MM_ARCH_HOOKS_H
+#define _ASM_MICROBLAZE_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_MICROBLAZE_MM_ARCH_HOOKS_H */
diff --git a/arch/mips/include/asm/mm-arch-hooks.h b/arch/mips/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..b5609fe8e475
--- /dev/null
+++ b/arch/mips/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_MIPS_MM_ARCH_HOOKS_H
+#define _ASM_MIPS_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_MIPS_MM_ARCH_HOOKS_H */
diff --git a/arch/mn10300/include/asm/mm-arch-hooks.h b/arch/mn10300/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..e2029a652f4c
--- /dev/null
+++ b/arch/mn10300/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_MN10300_MM_ARCH_HOOKS_H
+#define _ASM_MN10300_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_MN10300_MM_ARCH_HOOKS_H */
diff --git a/arch/nios2/include/asm/mm-arch-hooks.h b/arch/nios2/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..d7290dc68558
--- /dev/null
+++ b/arch/nios2/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_NIOS2_MM_ARCH_HOOKS_H
+#define _ASM_NIOS2_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_NIOS2_MM_ARCH_HOOKS_H */
diff --git a/arch/openrisc/include/asm/mm-arch-hooks.h b/arch/openrisc/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..6d33cb555fe1
--- /dev/null
+++ b/arch/openrisc/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_OPENRISC_MM_ARCH_HOOKS_H
+#define _ASM_OPENRISC_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_OPENRISC_MM_ARCH_HOOKS_H */
diff --git a/arch/parisc/include/asm/mm-arch-hooks.h b/arch/parisc/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..654ec63b0ee9
--- /dev/null
+++ b/arch/parisc/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_PARISC_MM_ARCH_HOOKS_H
+#define _ASM_PARISC_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_PARISC_MM_ARCH_HOOKS_H */
diff --git a/arch/powerpc/include/asm/mm-arch-hooks.h b/arch/powerpc/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..63091a19de9f
--- /dev/null
+++ b/arch/powerpc/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_POWERPC_MM_ARCH_HOOKS_H
+#define _ASM_POWERPC_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_POWERPC_MM_ARCH_HOOKS_H */
diff --git a/arch/s390/include/asm/mm-arch-hooks.h b/arch/s390/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..07680b2f3c59
--- /dev/null
+++ b/arch/s390/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_S390_MM_ARCH_HOOKS_H
+#define _ASM_S390_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_S390_MM_ARCH_HOOKS_H */
diff --git a/arch/score/include/asm/mm-arch-hooks.h b/arch/score/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..5e38689f189a
--- /dev/null
+++ b/arch/score/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_SCORE_MM_ARCH_HOOKS_H
+#define _ASM_SCORE_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_SCORE_MM_ARCH_HOOKS_H */
diff --git a/arch/sh/include/asm/mm-arch-hooks.h b/arch/sh/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..18087298b728
--- /dev/null
+++ b/arch/sh/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_SH_MM_ARCH_HOOKS_H
+#define _ASM_SH_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_SH_MM_ARCH_HOOKS_H */
diff --git a/arch/sparc/include/asm/mm-arch-hooks.h b/arch/sparc/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..b89ba44c16f1
--- /dev/null
+++ b/arch/sparc/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_SPARC_MM_ARCH_HOOKS_H
+#define _ASM_SPARC_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_SPARC_MM_ARCH_HOOKS_H */
diff --git a/arch/tile/include/asm/mm-arch-hooks.h b/arch/tile/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..d1709ea774f7
--- /dev/null
+++ b/arch/tile/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_TILE_MM_ARCH_HOOKS_H
+#define _ASM_TILE_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_TILE_MM_ARCH_HOOKS_H */
diff --git a/arch/um/include/asm/mm-arch-hooks.h b/arch/um/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..a7c8b0dfdd4e
--- /dev/null
+++ b/arch/um/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_UM_MM_ARCH_HOOKS_H
+#define _ASM_UM_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_UM_MM_ARCH_HOOKS_H */
diff --git a/arch/unicore32/include/asm/mm-arch-hooks.h b/arch/unicore32/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..4d79a850c509
--- /dev/null
+++ b/arch/unicore32/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_UNICORE32_MM_ARCH_HOOKS_H
+#define _ASM_UNICORE32_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_UNICORE32_MM_ARCH_HOOKS_H */
diff --git a/arch/x86/include/asm/mm-arch-hooks.h b/arch/x86/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..4e881a342236
--- /dev/null
+++ b/arch/x86/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_X86_MM_ARCH_HOOKS_H
+#define _ASM_X86_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_X86_MM_ARCH_HOOKS_H */
diff --git a/arch/xtensa/include/asm/mm-arch-hooks.h b/arch/xtensa/include/asm/mm-arch-hooks.h
new file mode 100644
index 000000000000..d2e5cfd3dd02
--- /dev/null
+++ b/arch/xtensa/include/asm/mm-arch-hooks.h
@@ -0,0 +1,15 @@
+/*
+ * Architecture specific mm hooks
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef _ASM_XTENSA_MM_ARCH_HOOKS_H
+#define _ASM_XTENSA_MM_ARCH_HOOKS_H
+
+#endif /* _ASM_XTENSA_MM_ARCH_HOOKS_H */
diff --git a/include/linux/mm-arch-hooks.h b/include/linux/mm-arch-hooks.h
new file mode 100644
index 000000000000..63005e367abd
--- /dev/null
+++ b/include/linux/mm-arch-hooks.h
@@ -0,0 +1,16 @@
+/*
+ * Generic mm no-op hooks.
+ *
+ * Copyright (C) 2015, IBM Corporation
+ * Author: Laurent Dufour <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#ifndef _LINUX_MM_ARCH_HOOKS_H
+#define _LINUX_MM_ARCH_HOOKS_H
+
+#include <asm/mm-arch-hooks.h>
+
+#endif /* _LINUX_MM_ARCH_HOOKS_H */
--
1.9.1

2015-04-15 14:17:31

by Laurent Dufour

[permalink] [raw]
Subject: [PATCH v5 2/3] mm: New arch_remap hook

Some architecture would like to be triggered when a memory area is moved
through the mremap system call.

This patch is introducing a new arch_remap mm hook which is placed in the
path of mremap, and is called before the old area is unmapped (and the
arch_unmap hook is called).

Signed-off-by: Laurent Dufour <[email protected]>
---
include/linux/mm-arch-hooks.h | 9 +++++++++
mm/mremap.c | 17 +++++++++++------
2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/include/linux/mm-arch-hooks.h b/include/linux/mm-arch-hooks.h
index 63005e367abd..4efc3f56e6df 100644
--- a/include/linux/mm-arch-hooks.h
+++ b/include/linux/mm-arch-hooks.h
@@ -13,4 +13,13 @@

#include <asm/mm-arch-hooks.h>

+#ifndef arch_remap
+static inline void arch_remap(struct mm_struct *mm,
+ unsigned long old_start, unsigned long old_end,
+ unsigned long new_start, unsigned long new_end)
+{
+}
+#define arch_remap arch_remap
+#endif
+
#endif /* _LINUX_MM_ARCH_HOOKS_H */
diff --git a/mm/mremap.c b/mm/mremap.c
index 2dc44b1cb1df..7597af900d07 100644
--- a/mm/mremap.c
+++ b/mm/mremap.c
@@ -22,6 +22,7 @@
#include <linux/mmu_notifier.h>
#include <linux/sched/sysctl.h>
#include <linux/uaccess.h>
+#include <linux/mm-arch-hooks.h>

#include <asm/cacheflush.h>
#include <asm/tlbflush.h>
@@ -286,13 +287,17 @@ static unsigned long move_vma(struct vm_area_struct *vma,
old_len = new_len;
old_addr = new_addr;
new_addr = -ENOMEM;
- } else if (vma->vm_file && vma->vm_file->f_op->mremap) {
- err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
- if (err < 0) {
- move_page_tables(new_vma, new_addr, vma, old_addr,
- moved_len, true);
- return err;
+ } else {
+ if (vma->vm_file && vma->vm_file->f_op->mremap) {
+ err = vma->vm_file->f_op->mremap(vma->vm_file, new_vma);
+ if (err < 0) {
+ move_page_tables(new_vma, new_addr, vma,
+ old_addr, moved_len, true);
+ return err;
+ }
}
+ arch_remap(mm, old_addr, old_addr + old_len,
+ new_addr, new_addr + new_len);
}

/* Conceal VM_ACCOUNT so old reservation is not undone */
--
1.9.1

2015-04-15 14:17:25

by Laurent Dufour

[permalink] [raw]
Subject: [PATCH v5 3/3] powerpc/mm: Tracking vDSO remap

Some processes (CRIU) are moving the vDSO area using the mremap system
call. As a consequence the kernel reference to the vDSO base address is
no more valid and the signal return frame built once the vDSO has been
moved is not pointing to the new sigreturn address.

This patch handles vDSO remapping and unmapping.

Signed-off-by: Laurent Dufour <[email protected]>
Reviewed-by: Ingo Molnar <[email protected]>
---
arch/powerpc/include/asm/mm-arch-hooks.h | 13 +++++++++++++
arch/powerpc/include/asm/mmu_context.h | 23 ++++++++++++++++++++++-
2 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/arch/powerpc/include/asm/mm-arch-hooks.h b/arch/powerpc/include/asm/mm-arch-hooks.h
index 63091a19de9f..f2a2da895897 100644
--- a/arch/powerpc/include/asm/mm-arch-hooks.h
+++ b/arch/powerpc/include/asm/mm-arch-hooks.h
@@ -12,4 +12,17 @@
#ifndef _ASM_POWERPC_MM_ARCH_HOOKS_H
#define _ASM_POWERPC_MM_ARCH_HOOKS_H

+static inline void arch_remap(struct mm_struct *mm,
+ unsigned long old_start, unsigned long old_end,
+ unsigned long new_start, unsigned long new_end)
+{
+ /*
+ * mremap() doesn't allow moving multiple vmas so we can limit the
+ * check to old_start == vdso_base.
+ */
+ if (old_start == mm->context.vdso_base)
+ mm->context.vdso_base = new_start;
+}
+#define arch_remap arch_remap
+
#endif /* _ASM_POWERPC_MM_ARCH_HOOKS_H */
diff --git a/arch/powerpc/include/asm/mmu_context.h b/arch/powerpc/include/asm/mmu_context.h
index 73382eba02dc..825cb232eab6 100644
--- a/arch/powerpc/include/asm/mmu_context.h
+++ b/arch/powerpc/include/asm/mmu_context.h
@@ -8,7 +8,6 @@
#include <linux/spinlock.h>
#include <asm/mmu.h>
#include <asm/cputable.h>
-#include <asm-generic/mm_hooks.h>
#include <asm/cputhreads.h>

/*
@@ -109,5 +108,27 @@ static inline void enter_lazy_tlb(struct mm_struct *mm,
#endif
}

+static inline void arch_dup_mmap(struct mm_struct *oldmm,
+ struct mm_struct *mm)
+{
+}
+
+static inline void arch_exit_mmap(struct mm_struct *mm)
+{
+}
+
+static inline void arch_unmap(struct mm_struct *mm,
+ struct vm_area_struct *vma,
+ unsigned long start, unsigned long end)
+{
+ if (start <= mm->context.vdso_base && mm->context.vdso_base < end)
+ mm->context.vdso_base = 0;
+}
+
+static inline void arch_bprm_mm_init(struct mm_struct *mm,
+ struct vm_area_struct *vma)
+{
+}
+
#endif /* __KERNEL__ */
#endif /* __ASM_POWERPC_MMU_CONTEXT_H */
--
1.9.1