linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] mm: soft-dirty bits for s390
@ 2015-09-21 15:22 Martin Schwidefsky
  2015-09-21 15:22 ` [PATCH 1/2] mm: add architecture primitives for software dirty bit clearing Martin Schwidefsky
  2015-09-21 15:22 ` [PATCH 2/2] s390/mm: implement soft-dirty bits for user memory change tracking Martin Schwidefsky
  0 siblings, 2 replies; 7+ messages in thread
From: Martin Schwidefsky @ 2015-09-21 15:22 UTC (permalink / raw)
  To: Cyrill Gorcunov, linux-mm, linux-arch; +Cc: Martin Schwidefsky

Greetings,

this patch set of two adds memory change tracking alias soft-dirty
feature to the s390 architecture.

The first patch is a cleanup of the existing x86 support, it adds two
arch specific functions pte_clear_soft_dirty and pmd_clear_soft_dirty
to complement the other xxx_soft_dirty functions. This removes the
use of a x86 specific function in fs/proc/tasm_mmu.c.

The second patch is the s390 arch support.

Tested on x86 and s390, seems to work as intended for both platforms.
If the first patch is acceptable I can queue the set on the linux-s390
tree for the 4.4 merge window in a couple of weeks.

Martin Schwidefsky (2):
  mm: add architecture primitives for software dirty bit clearing
  s390/mm: implement soft-dirty bits for user memory change tracking

 arch/s390/Kconfig               |  1 +
 arch/s390/include/asm/pgtable.h | 59 ++++++++++++++++++++++++++++++++++++++---
 arch/s390/mm/hugetlbpage.c      |  2 ++
 arch/x86/include/asm/pgtable.h  | 10 +++++++
 fs/proc/task_mmu.c              |  4 +--
 include/asm-generic/pgtable.h   | 10 +++++++
 6 files changed, 80 insertions(+), 6 deletions(-)

-- 
1.9.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/2] mm: add architecture primitives for software dirty bit clearing
  2015-09-21 15:22 [PATCH 0/2] mm: soft-dirty bits for s390 Martin Schwidefsky
@ 2015-09-21 15:22 ` Martin Schwidefsky
  2015-09-21 19:48   ` Cyrill Gorcunov
  2015-09-21 15:22 ` [PATCH 2/2] s390/mm: implement soft-dirty bits for user memory change tracking Martin Schwidefsky
  1 sibling, 1 reply; 7+ messages in thread
From: Martin Schwidefsky @ 2015-09-21 15:22 UTC (permalink / raw)
  To: Cyrill Gorcunov, linux-mm, linux-arch; +Cc: Martin Schwidefsky

There are primitives to create and query the software dirty bits
in a pte or pmd. But the clearing of the software dirty bits is done
in common code with x86 specific page table functions.

Add the missing architecture primitives to clear the software dirty
bits to allow the feature to be used on non-x86 systems, e.g. the
s390 architecture.

Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
---
 arch/x86/include/asm/pgtable.h | 10 ++++++++++
 fs/proc/task_mmu.c             |  4 ++--
 include/asm-generic/pgtable.h  | 10 ++++++++++
 3 files changed, 22 insertions(+), 2 deletions(-)

diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index 867da5b..81e144d 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -318,6 +318,16 @@ static inline pmd_t pmd_mksoft_dirty(pmd_t pmd)
 	return pmd_set_flags(pmd, _PAGE_SOFT_DIRTY);
 }
 
+static inline pte_t pte_clear_soft_dirty(pte_t pte)
+{
+	return pte_clear_flags(pte, _PAGE_SOFT_DIRTY);
+}
+
+static inline pmd_t pmd_clear_soft_dirty(pmd_t pmd)
+{
+	return pmd_clear_flags(pmd, _PAGE_SOFT_DIRTY);
+}
+
 #endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */
 
 /*
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index e2d46ad..b029d42 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -754,7 +754,7 @@ static inline void clear_soft_dirty(struct vm_area_struct *vma,
 
 	if (pte_present(ptent)) {
 		ptent = pte_wrprotect(ptent);
-		ptent = pte_clear_flags(ptent, _PAGE_SOFT_DIRTY);
+		ptent = pte_clear_soft_dirty(ptent);
 	} else if (is_swap_pte(ptent)) {
 		ptent = pte_swp_clear_soft_dirty(ptent);
 	}
@@ -768,7 +768,7 @@ static inline void clear_soft_dirty_pmd(struct vm_area_struct *vma,
 	pmd_t pmd = *pmdp;
 
 	pmd = pmd_wrprotect(pmd);
-	pmd = pmd_clear_flags(pmd, _PAGE_SOFT_DIRTY);
+	pmd = pmd_clear_soft_dirty(pmd);
 
 	if (vma->vm_flags & VM_SOFTDIRTY)
 		vma->vm_flags &= ~VM_SOFTDIRTY;
diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
index 29c57b2..f167cdd 100644
--- a/include/asm-generic/pgtable.h
+++ b/include/asm-generic/pgtable.h
@@ -482,6 +482,16 @@ static inline pmd_t pmd_mksoft_dirty(pmd_t pmd)
 	return pmd;
 }
 
+static inline pte_t pte_clear_soft_dirty(pte_t pte)
+{
+	return pte;
+}
+
+static inline pmd_t pmd_clear_soft_dirty(pmd_t pmd)
+{
+	return pmd;
+}
+
 static inline pte_t pte_swp_mksoft_dirty(pte_t pte)
 {
 	return pte;
-- 
1.9.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/2] s390/mm: implement soft-dirty bits for user memory change tracking
  2015-09-21 15:22 [PATCH 0/2] mm: soft-dirty bits for s390 Martin Schwidefsky
  2015-09-21 15:22 ` [PATCH 1/2] mm: add architecture primitives for software dirty bit clearing Martin Schwidefsky
@ 2015-09-21 15:22 ` Martin Schwidefsky
  1 sibling, 0 replies; 7+ messages in thread
From: Martin Schwidefsky @ 2015-09-21 15:22 UTC (permalink / raw)
  To: Cyrill Gorcunov, linux-mm, linux-arch; +Cc: Martin Schwidefsky

Use bit 2**1 of the pte and bit 2**14 of the pmd for the soft dirty
bit. The fault mechanism to do dirty tracking is already in place.

Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
---
 arch/s390/Kconfig               |  1 +
 arch/s390/include/asm/pgtable.h | 59 ++++++++++++++++++++++++++++++++++++++---
 arch/s390/mm/hugetlbpage.c      |  2 ++
 3 files changed, 58 insertions(+), 4 deletions(-)

diff --git a/arch/s390/Kconfig b/arch/s390/Kconfig
index 1d57000..44cb7de 100644
--- a/arch/s390/Kconfig
+++ b/arch/s390/Kconfig
@@ -118,6 +118,7 @@ config S390
 	select HAVE_ARCH_EARLY_PFN_TO_NID
 	select HAVE_ARCH_JUMP_LABEL
 	select HAVE_ARCH_SECCOMP_FILTER
+	select HAVE_ARCH_SOFT_DIRTY
 	select HAVE_ARCH_TRACEHOOK
 	select HAVE_ARCH_TRANSPARENT_HUGEPAGE
 	select HAVE_BPF_JIT if PACK_STACK && HAVE_MARCH_Z196_FEATURES
diff --git a/arch/s390/include/asm/pgtable.h b/arch/s390/include/asm/pgtable.h
index bdb2f51..4d7e2e9 100644
--- a/arch/s390/include/asm/pgtable.h
+++ b/arch/s390/include/asm/pgtable.h
@@ -193,9 +193,15 @@ static inline int is_module_addr(void *addr)
 #define _PAGE_UNUSED	0x080		/* SW bit for pgste usage state */
 #define __HAVE_ARCH_PTE_SPECIAL
 
+#ifdef CONFIG_MEM_SOFT_DIRTY
+#define _PAGE_SOFT_DIRTY 0x002		/* SW pte soft dirty bit */
+#else
+#define _PAGE_SOFT_DIRTY 0x000
+#endif
+
 /* Set of bits not changed in pte_modify */
 #define _PAGE_CHG_MASK		(PAGE_MASK | _PAGE_SPECIAL | _PAGE_DIRTY | \
-				 _PAGE_YOUNG)
+				 _PAGE_YOUNG | _PAGE_SOFT_DIRTY)
 
 /*
  * handle_pte_fault uses pte_present and pte_none to find out the pte type
@@ -285,6 +291,12 @@ static inline int is_module_addr(void *addr)
 #define _SEGMENT_ENTRY_READ	0x0002	/* SW segment read bit */
 #define _SEGMENT_ENTRY_WRITE	0x0001	/* SW segment write bit */
 
+#ifdef CONFIG_MEM_SOFT_DIRTY
+#define _SEGMENT_ENTRY_SOFT_DIRTY 0x4000 /* SW segment soft dirty bit */
+#else
+#define _SEGMENT_ENTRY_SOFT_DIRTY 0x0000 /* SW segment soft dirty bit */
+#endif
+
 /*
  * Segment table entry encoding (R = read-only, I = invalid, y = young bit):
  *				dy..R...I...wr
@@ -589,6 +601,43 @@ static inline int pmd_protnone(pmd_t pmd)
 }
 #endif
 
+static inline int pte_soft_dirty(pte_t pte)
+{
+	return pte_val(pte) & _PAGE_SOFT_DIRTY;
+}
+#define pte_swp_soft_dirty pte_soft_dirty
+
+static inline pte_t pte_mksoft_dirty(pte_t pte)
+{
+	pte_val(pte) |= _PAGE_SOFT_DIRTY;
+	return pte;
+}
+#define pte_swp_mksoft_dirty pte_mksoft_dirty
+
+static inline pte_t pte_clear_soft_dirty(pte_t pte)
+{
+	pte_val(pte) &= ~_PAGE_SOFT_DIRTY;
+	return pte;
+}
+#define pte_swp_clear_soft_dirty pte_clear_soft_dirty
+
+static inline int pmd_soft_dirty(pmd_t pmd)
+{
+	return pmd_val(pmd) & _SEGMENT_ENTRY_SOFT_DIRTY;
+}
+
+static inline pmd_t pmd_mksoft_dirty(pmd_t pmd)
+{
+	pmd_val(pmd) |= _SEGMENT_ENTRY_SOFT_DIRTY;
+	return pmd;
+}
+
+static inline pmd_t pmd_clear_soft_dirty(pmd_t pmd)
+{
+	pmd_val(pmd) &= ~_SEGMENT_ENTRY_SOFT_DIRTY;
+	return pmd;
+}
+
 static inline pgste_t pgste_get_lock(pte_t *ptep)
 {
 	unsigned long new = 0;
@@ -889,7 +938,7 @@ static inline pte_t pte_mkclean(pte_t pte)
 
 static inline pte_t pte_mkdirty(pte_t pte)
 {
-	pte_val(pte) |= _PAGE_DIRTY;
+	pte_val(pte) |= _PAGE_DIRTY | _PAGE_SOFT_DIRTY;
 	if (pte_val(pte) & _PAGE_WRITE)
 		pte_val(pte) &= ~_PAGE_PROTECT;
 	return pte;
@@ -1340,7 +1389,8 @@ static inline pmd_t pmd_mkclean(pmd_t pmd)
 static inline pmd_t pmd_mkdirty(pmd_t pmd)
 {
 	if (pmd_large(pmd)) {
-		pmd_val(pmd) |= _SEGMENT_ENTRY_DIRTY;
+		pmd_val(pmd) |= _SEGMENT_ENTRY_DIRTY |
+				_SEGMENT_ENTRY_SOFT_DIRTY;
 		if (pmd_val(pmd) & _SEGMENT_ENTRY_WRITE)
 			pmd_val(pmd) &= ~_SEGMENT_ENTRY_PROTECT;
 	}
@@ -1371,7 +1421,8 @@ static inline pmd_t pmd_modify(pmd_t pmd, pgprot_t newprot)
 	if (pmd_large(pmd)) {
 		pmd_val(pmd) &= _SEGMENT_ENTRY_ORIGIN_LARGE |
 			_SEGMENT_ENTRY_DIRTY | _SEGMENT_ENTRY_YOUNG |
-			_SEGMENT_ENTRY_LARGE | _SEGMENT_ENTRY_SPLIT;
+			_SEGMENT_ENTRY_LARGE | _SEGMENT_ENTRY_SPLIT |
+			_SEGMENT_ENTRY_SOFT_DIRTY;
 		pmd_val(pmd) |= massage_pgprot_pmd(newprot);
 		if (!(pmd_val(pmd) & _SEGMENT_ENTRY_DIRTY))
 			pmd_val(pmd) |= _SEGMENT_ENTRY_PROTECT;
diff --git a/arch/s390/mm/hugetlbpage.c b/arch/s390/mm/hugetlbpage.c
index fb4bf2c..f81096b 100644
--- a/arch/s390/mm/hugetlbpage.c
+++ b/arch/s390/mm/hugetlbpage.c
@@ -40,6 +40,7 @@ static inline pmd_t __pte_to_pmd(pte_t pte)
 		pmd_val(pmd) |= (pte_val(pte) & _PAGE_PROTECT);
 		pmd_val(pmd) |= (pte_val(pte) & _PAGE_DIRTY) << 10;
 		pmd_val(pmd) |= (pte_val(pte) & _PAGE_YOUNG) << 10;
+		pmd_val(pmd) |= (pte_val(pte) & _PAGE_SOFT_DIRTY) << 13;
 	} else
 		pmd_val(pmd) = _SEGMENT_ENTRY_INVALID;
 	return pmd;
@@ -78,6 +79,7 @@ static inline pte_t __pmd_to_pte(pmd_t pmd)
 		pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_PROTECT);
 		pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_DIRTY) >> 10;
 		pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_YOUNG) >> 10;
+		pte_val(pte) |= (pmd_val(pmd) & _SEGMENT_ENTRY_SOFT_DIRTY) >> 13;
 	} else
 		pte_val(pte) = _PAGE_INVALID;
 	return pte;
-- 
1.9.1

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] mm: add architecture primitives for software dirty bit clearing
  2015-09-21 15:22 ` [PATCH 1/2] mm: add architecture primitives for software dirty bit clearing Martin Schwidefsky
@ 2015-09-21 19:48   ` Cyrill Gorcunov
  2015-09-22  7:35     ` Martin Schwidefsky
  0 siblings, 1 reply; 7+ messages in thread
From: Cyrill Gorcunov @ 2015-09-21 19:48 UTC (permalink / raw)
  To: Martin Schwidefsky; +Cc: linux-mm, linux-arch

On Mon, Sep 21, 2015 at 05:22:19PM +0200, Martin Schwidefsky wrote:
> There are primitives to create and query the software dirty bits
> in a pte or pmd. But the clearing of the software dirty bits is done
> in common code with x86 specific page table functions.
> 
> Add the missing architecture primitives to clear the software dirty
> bits to allow the feature to be used on non-x86 systems, e.g. the
> s390 architecture.
> 
> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>

Looks good to me. Thank you, Martin!
(I cant ack s390 part 'casuse I simply not familiar
 with the architecture).

Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] mm: add architecture primitives for software dirty bit clearing
  2015-09-21 19:48   ` Cyrill Gorcunov
@ 2015-09-22  7:35     ` Martin Schwidefsky
  2015-09-22  9:09       ` Cyrill Gorcunov
  0 siblings, 1 reply; 7+ messages in thread
From: Martin Schwidefsky @ 2015-09-22  7:35 UTC (permalink / raw)
  To: Cyrill Gorcunov; +Cc: linux-mm, linux-arch

On Mon, 21 Sep 2015 22:48:54 +0300
Cyrill Gorcunov <gorcunov@gmail.com> wrote:

> On Mon, Sep 21, 2015 at 05:22:19PM +0200, Martin Schwidefsky wrote:
> > There are primitives to create and query the software dirty bits
> > in a pte or pmd. But the clearing of the software dirty bits is done
> > in common code with x86 specific page table functions.
> > 
> > Add the missing architecture primitives to clear the software dirty
> > bits to allow the feature to be used on non-x86 systems, e.g. the
> > s390 architecture.
> > 
> > Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
> 
> Looks good to me. Thank you, Martin!
> (I cant ack s390 part 'casuse I simply not familiar
>  with the architecture).

Sure, the s390 patch just shows why the new arch functions are needed..

> Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>

Thanks. I have added both patches to the features branch of linux-s390
for the 4.4 merge window.

-- 
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] mm: add architecture primitives for software dirty bit clearing
  2015-09-22  7:35     ` Martin Schwidefsky
@ 2015-09-22  9:09       ` Cyrill Gorcunov
  2015-09-22 10:30         ` Martin Schwidefsky
  0 siblings, 1 reply; 7+ messages in thread
From: Cyrill Gorcunov @ 2015-09-22  9:09 UTC (permalink / raw)
  To: Martin Schwidefsky; +Cc: linux-mm, linux-arch, Andrew Morton, Pavel Emelyanov

On Tue, Sep 22, 2015 at 09:35:49AM +0200, Martin Schwidefsky wrote:
> > 
> > Looks good to me. Thank you, Martin!
> > (I cant ack s390 part 'casuse I simply not familiar
> >  with the architecture).
> 
> Sure, the s390 patch just shows why the new arch functions are needed..

A see, thanks!

> 
> > Acked-by: Cyrill Gorcunov <gorcunov@openvz.org>
> 
> Thanks. I have added both patches to the features branch of linux-s390
> for the 4.4 merge window.

The first patch (x86 and general helpers) seems better to go via
Andrew (CC'ed) becase they are not s390 only. And while these
changes are fine for me and you as far as I can say, lets them
floating around for some more review just to make sure we're not
missing something obvious.

And initially the soft-dirty feature has been hittin vanilla by
-mm tree so I suppose we should continue this way, though I
don't mind if it gonna be merged via pull request from s390
side but still ;)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/2] mm: add architecture primitives for software dirty bit clearing
  2015-09-22  9:09       ` Cyrill Gorcunov
@ 2015-09-22 10:30         ` Martin Schwidefsky
  0 siblings, 0 replies; 7+ messages in thread
From: Martin Schwidefsky @ 2015-09-22 10:30 UTC (permalink / raw)
  To: Cyrill Gorcunov; +Cc: linux-mm, linux-arch, Andrew Morton, Pavel Emelyanov

On Tue, 22 Sep 2015 12:09:35 +0300
Cyrill Gorcunov <gorcunov@gmail.com> wrote:

> On Tue, Sep 22, 2015 at 09:35:49AM +0200, Martin Schwidefsky wrote:
> > Thanks. I have added both patches to the features branch of linux-s390
> > for the 4.4 merge window.
> 
> The first patch (x86 and general helpers) seems better to go via
> Andrew (CC'ed) becase they are not s390 only. And while these
> changes are fine for me and you as far as I can say, lets them
> floating around for some more review just to make sure we're not
> missing something obvious.
> 
> And initially the soft-dirty feature has been hittin vanilla by
> -mm tree so I suppose we should continue this way, though I
> don't mind if it gonna be merged via pull request from s390
> side but still ;)
 
Well, the patches will be included in linux-next automatically and
they will get a fair share of testing before the 4.4 merge window
opens. If the patches get picked up via -mm as well, be my guest.

-- 
blue skies,
   Martin.

"Reality continues to ruin my life." - Calvin.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-09-22 10:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-21 15:22 [PATCH 0/2] mm: soft-dirty bits for s390 Martin Schwidefsky
2015-09-21 15:22 ` [PATCH 1/2] mm: add architecture primitives for software dirty bit clearing Martin Schwidefsky
2015-09-21 19:48   ` Cyrill Gorcunov
2015-09-22  7:35     ` Martin Schwidefsky
2015-09-22  9:09       ` Cyrill Gorcunov
2015-09-22 10:30         ` Martin Schwidefsky
2015-09-21 15:22 ` [PATCH 2/2] s390/mm: implement soft-dirty bits for user memory change tracking Martin Schwidefsky

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).