linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mips/mm: Add page soft dirty tracking
@ 2020-04-21  9:15 Guoyun Sun
  2020-04-26 16:54 ` Thomas Bogendoerfer
  2020-04-29  1:41 ` kbuild test robot
  0 siblings, 2 replies; 6+ messages in thread
From: Guoyun Sun @ 2020-04-21  9:15 UTC (permalink / raw)
  To: Thomas Bogendoerfer, Paul Burton
  Cc: Daniel Silsby, Jiaxun Yang, Paul Cercueil, Dmitry Korotin,
	Andrew Morton, Steven Price, Geert Uytterhoeven, Mike Rapoport,
	Anshuman Khandual, linux-mips, linux-kernel, Guoyun Sun,
	TieZhu Yang, Xuefeng Li

User space checkpoint and restart tool (CRIU) needs the page's change
to be soft tracked. This allows to do a pre checkpoint and then dump
only touched pages.

Signed-off-by: Guoyun Sun <sunguoyun@loongson.cn>
---
 arch/mips/Kconfig                    |  1 +
 arch/mips/include/asm/pgtable-bits.h |  8 ++++--
 arch/mips/include/asm/pgtable.h      | 48 ++++++++++++++++++++++++++++++++++--
 3 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
index 690718b..642fb47 100644
--- a/arch/mips/Kconfig
+++ b/arch/mips/Kconfig
@@ -491,6 +491,7 @@ config MACH_LOONGSON64
 	select COMMON_CLK
 	select USE_OF
 	select BUILTIN_DTB
+	select HAVE_ARCH_SOFT_DIRTY
 	help
 	  This enables the support of Loongson-2/3 family of machines.
 
diff --git a/arch/mips/include/asm/pgtable-bits.h b/arch/mips/include/asm/pgtable-bits.h
index 4da79b8..d43fb6f 100644
--- a/arch/mips/include/asm/pgtable-bits.h
+++ b/arch/mips/include/asm/pgtable-bits.h
@@ -55,6 +55,7 @@ enum pgtable_bits {
 #if defined(CONFIG_ARCH_HAS_PTE_SPECIAL)
 	_PAGE_SPECIAL_SHIFT,
 #endif
+	_PAGE_SOFT_DIRTY_SHIFT,
 };
 
 /*
@@ -84,6 +85,7 @@ enum pgtable_bits {
 #if defined(CONFIG_ARCH_HAS_PTE_SPECIAL)
 	_PAGE_SPECIAL_SHIFT,
 #endif
+	_PAGE_SOFT_DIRTY_SHIFT,
 };
 
 #elif defined(CONFIG_CPU_R3K_TLB)
@@ -99,6 +101,7 @@ enum pgtable_bits {
 #if defined(CONFIG_ARCH_HAS_PTE_SPECIAL)
 	_PAGE_SPECIAL_SHIFT,
 #endif
+	_PAGE_SOFT_DIRTY_SHIFT,
 
 	/* Used by TLB hardware (placed in EntryLo) */
 	_PAGE_GLOBAL_SHIFT = 8,
@@ -125,7 +128,7 @@ enum pgtable_bits {
 #if defined(CONFIG_ARCH_HAS_PTE_SPECIAL)
 	_PAGE_SPECIAL_SHIFT,
 #endif
-
+	_PAGE_SOFT_DIRTY_SHIFT,
 	/* Used by TLB hardware (placed in EntryLo*) */
 #if defined(CONFIG_CPU_HAS_RIXI)
 	_PAGE_NO_EXEC_SHIFT,
@@ -152,6 +155,7 @@ enum pgtable_bits {
 #else
 # define _PAGE_SPECIAL		0
 #endif
+#define _PAGE_SOFT_DIRTY	(1 << _PAGE_SOFT_DIRTY_SHIFT)
 
 /* Used by TLB hardware (placed in EntryLo*) */
 #if defined(CONFIG_XPA)
@@ -269,6 +273,6 @@ static inline uint64_t pte_to_entrylo(unsigned long pte_val)
 #define __WRITEABLE	(_PAGE_SILENT_WRITE | _PAGE_WRITE | _PAGE_MODIFIED)
 
 #define _PAGE_CHG_MASK	(_PAGE_ACCESSED | _PAGE_MODIFIED |	\
-			 _PFN_MASK | _CACHE_MASK)
+			 _PAGE_SOFT_DIRTY | _PFN_MASK | _CACHE_MASK)
 
 #endif /* _ASM_PGTABLE_BITS_H */
diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
index f1801e7..64b07ff 100644
--- a/arch/mips/include/asm/pgtable.h
+++ b/arch/mips/include/asm/pgtable.h
@@ -400,7 +400,7 @@ static inline pte_t pte_mkwrite(pte_t pte)
 
 static inline pte_t pte_mkdirty(pte_t pte)
 {
-	pte_val(pte) |= _PAGE_MODIFIED;
+	pte_val(pte) |= _PAGE_MODIFIED | _PAGE_SOFT_DIRTY;
 	if (pte_val(pte) & _PAGE_WRITE)
 		pte_val(pte) |= _PAGE_SILENT_WRITE;
 	return pte;
@@ -423,6 +423,30 @@ static inline pte_t pte_mkhuge(pte_t pte)
 	return pte;
 }
 #endif /* CONFIG_MIPS_HUGE_TLB_SUPPORT */
+
+#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
+static inline bool 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
+
+#endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */
+
 #endif
 
 /*
@@ -579,7 +603,7 @@ static inline pmd_t pmd_mkclean(pmd_t pmd)
 
 static inline pmd_t pmd_mkdirty(pmd_t pmd)
 {
-	pmd_val(pmd) |= _PAGE_MODIFIED;
+	pmd_val(pmd) |= _PAGE_MODIFIED | _PAGE_SOFT_DIRTY;
 	if (pmd_val(pmd) & _PAGE_WRITE)
 		pmd_val(pmd) |= _PAGE_SILENT_WRITE;
 
@@ -608,6 +632,26 @@ static inline pmd_t pmd_mkyoung(pmd_t pmd)
 	return pmd;
 }
 
+#ifdef CONFIG_HAVE_ARCH_SOFT_DIRTY
+static inline int pmd_soft_dirty(pmd_t pmd)
+{
+	return !!(pmd_val(pmd) & _PAGE_SOFT_DIRTY);
+}
+
+static inline pmd_t pmd_mksoft_dirty(pmd_t pmd)
+{
+	pmd_val(pmd) |= _PAGE_SOFT_DIRTY;
+	return pmd;
+}
+
+static inline pmd_t pmd_clear_soft_dirty(pmd_t pmd)
+{
+	pmd_val(pmd) &= ~(_PAGE_SOFT_DIRTY);
+	return pmd;
+}
+
+#endif /* CONFIG_HAVE_ARCH_SOFT_DIRTY */
+
 /* Extern to avoid header file madness */
 extern pmd_t mk_pmd(struct page *page, pgprot_t prot);
 
-- 
2.1.0


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

* Re: [PATCH] mips/mm: Add page soft dirty tracking
  2020-04-21  9:15 [PATCH] mips/mm: Add page soft dirty tracking Guoyun Sun
@ 2020-04-26 16:54 ` Thomas Bogendoerfer
  2020-04-26 17:09   ` Paul Cercueil
  2020-04-26 17:10   ` Jiaxun Yang
  2020-04-29  1:41 ` kbuild test robot
  1 sibling, 2 replies; 6+ messages in thread
From: Thomas Bogendoerfer @ 2020-04-26 16:54 UTC (permalink / raw)
  To: Guoyun Sun
  Cc: Paul Burton, Daniel Silsby, Jiaxun Yang, Paul Cercueil,
	Dmitry Korotin, Andrew Morton, Steven Price, Geert Uytterhoeven,
	Mike Rapoport, Anshuman Khandual, linux-mips, linux-kernel,
	TieZhu Yang, Xuefeng Li

On Tue, Apr 21, 2020 at 05:15:27PM +0800, Guoyun Sun wrote:
> User space checkpoint and restart tool (CRIU) needs the page's change
> to be soft tracked. This allows to do a pre checkpoint and then dump
> only touched pages.
> 
> Signed-off-by: Guoyun Sun <sunguoyun@loongson.cn>
> ---
>  arch/mips/Kconfig                    |  1 +
>  arch/mips/include/asm/pgtable-bits.h |  8 ++++--
>  arch/mips/include/asm/pgtable.h      | 48 ++++++++++++++++++++++++++++++++++--

this breaks all 32bit builds where CPU support RIXI, because it overflows
pgtable_bits.

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

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

* Re: [PATCH] mips/mm: Add page soft dirty tracking
  2020-04-26 16:54 ` Thomas Bogendoerfer
@ 2020-04-26 17:09   ` Paul Cercueil
  2020-04-27  9:04     ` Thomas Bogendoerfer
  2020-04-26 17:10   ` Jiaxun Yang
  1 sibling, 1 reply; 6+ messages in thread
From: Paul Cercueil @ 2020-04-26 17:09 UTC (permalink / raw)
  To: Thomas Bogendoerfer
  Cc: Guoyun Sun, Paul Burton, Daniel Silsby, Jiaxun Yang,
	Dmitry Korotin, Andrew Morton, Steven Price, Geert Uytterhoeven,
	Mike Rapoport, Anshuman Khandual, linux-mips, linux-kernel,
	TieZhu Yang, Xuefeng Li

Hi Thomas,

Le dim. 26 avril 2020 à 18:54, Thomas Bogendoerfer 
<tsbogend@alpha.franken.de> a écrit :
> On Tue, Apr 21, 2020 at 05:15:27PM +0800, Guoyun Sun wrote:
>>  User space checkpoint and restart tool (CRIU) needs the page's 
>> change
>>  to be soft tracked. This allows to do a pre checkpoint and then dump
>>  only touched pages.
>> 
>>  Signed-off-by: Guoyun Sun <sunguoyun@loongson.cn>
>>  ---
>>   arch/mips/Kconfig                    |  1 +
>>   arch/mips/include/asm/pgtable-bits.h |  8 ++++--
>>   arch/mips/include/asm/pgtable.h      | 48 
>> ++++++++++++++++++++++++++++++++++--
> 
> this breaks all 32bit builds where CPU support RIXI, because it 
> overflows
> pgtable_bits.

I think we'd need to make PTEs 64-bit at some point.

We wanted to add support for huge-pages on 32-bit MIPS and faced the 
same issue.

-Paul

> Thomas.
> 
> --
> Crap can work. Given enough thrust pigs will fly, but it's not 
> necessarily a
> good idea.                                                [ RFC1925, 
> 2.3 ]



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

* Re: [PATCH] mips/mm: Add page soft dirty tracking
  2020-04-26 16:54 ` Thomas Bogendoerfer
  2020-04-26 17:09   ` Paul Cercueil
@ 2020-04-26 17:10   ` Jiaxun Yang
  1 sibling, 0 replies; 6+ messages in thread
From: Jiaxun Yang @ 2020-04-26 17:10 UTC (permalink / raw)
  To: Thomas Bogendoerfer, Guoyun Sun
  Cc: Paul Burton, Daniel Silsby, Paul Cercueil, Dmitry Korotin,
	Andrew Morton, Steven Price, Geert Uytterhoeven, Mike Rapoport,
	Anshuman Khandual, linux-mips, linux-kernel, TieZhu Yang,
	Xuefeng Li



于 2020年4月27日 GMT+08:00 上午12:54:42, Thomas Bogendoerfer <tsbogend@alpha.franken.de> 写到:
>On Tue, Apr 21, 2020 at 05:15:27PM +0800, Guoyun Sun wrote:
>> User space checkpoint and restart tool (CRIU) needs the page's change
>> to be soft tracked. This allows to do a pre checkpoint and then dump
>> only touched pages.
>> 
>> Signed-off-by: Guoyun Sun <sunguoyun@loongson.cn>
>> ---
>>  arch/mips/Kconfig                    |  1 +
>>  arch/mips/include/asm/pgtable-bits.h |  8 ++++--
>>  arch/mips/include/asm/pgtable.h      | 48 ++++++++++++++++++++++++++++++++++--
>
>this breaks all 32bit builds where CPU support RIXI, because it overflows
>pgtable_bits.

Probably make a fixup patch to guard
_PAGE_SOFT_DIRTY_SHIFT with
CONFIG_HAVE_ARCH_SOFT_DIRTY
would be a better option?

Btw: It's really selfish that only enable SOFT_DIRTY for Loongson
but occupied a bit in pagetable for all MIPS systems.

I'd suggest select HAVE_ARCH_SOFT_DIRTY for all 64BIT MIPS systems.
Or provide config options to let expert users decide what feature they need.

Thanks.

>
>Thomas.
>

-- 
Jiaxun Yang

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

* Re: [PATCH] mips/mm: Add page soft dirty tracking
  2020-04-26 17:09   ` Paul Cercueil
@ 2020-04-27  9:04     ` Thomas Bogendoerfer
  0 siblings, 0 replies; 6+ messages in thread
From: Thomas Bogendoerfer @ 2020-04-27  9:04 UTC (permalink / raw)
  To: Paul Cercueil
  Cc: Guoyun Sun, Paul Burton, Daniel Silsby, Jiaxun Yang,
	Dmitry Korotin, Andrew Morton, Steven Price, Geert Uytterhoeven,
	Mike Rapoport, Anshuman Khandual, linux-mips, linux-kernel,
	TieZhu Yang, Xuefeng Li

On Sun, Apr 26, 2020 at 07:09:26PM +0200, Paul Cercueil wrote:
> >>  arch/mips/Kconfig                    |  1 +
> >>  arch/mips/include/asm/pgtable-bits.h |  8 ++++--
> >>  arch/mips/include/asm/pgtable.h      | 48
> >>++++++++++++++++++++++++++++++++++--
> >
> >this breaks all 32bit builds where CPU support RIXI, because it overflows
> >pgtable_bits.
> 
> I think we'd need to make PTEs 64-bit at some point.

I'm taking patches ;-) Any idea how much performance impact we might
see by this ?

Thomas.

-- 
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea.                                                [ RFC1925, 2.3 ]

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

* Re: [PATCH] mips/mm: Add page soft dirty tracking
  2020-04-21  9:15 [PATCH] mips/mm: Add page soft dirty tracking Guoyun Sun
  2020-04-26 16:54 ` Thomas Bogendoerfer
@ 2020-04-29  1:41 ` kbuild test robot
  1 sibling, 0 replies; 6+ messages in thread
From: kbuild test robot @ 2020-04-29  1:41 UTC (permalink / raw)
  To: Guoyun Sun, Thomas Bogendoerfer, Paul Burton, Daniel Silsby,
	Jiaxun Yang, Paul Cercueil, Dmitry Korotin, Andrew Morton,
	Steven Price, Geert Uytterhoeven, Mike Rapoport,
	Anshuman Khandual, linux-mips, linux-kernel, TieZhu Yang,
	Xuefeng Li
  Cc: kbuild-all, clang-built-linux, Linux Memory Management List,
	Daniel Silsby, Jiaxun Yang, Paul Cercueil, Dmitry Korotin,
	Andrew Morton, Steven Price, Geert Uytterhoeven, Mike Rapoport

[-- Attachment #1: Type: text/plain, Size: 1645 bytes --]

Hi Guoyun,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.7-rc3 next-20200428]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Guoyun-Sun/mips-mm-Add-page-soft-dirty-tracking/20200423-050636
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 18bf34080c4c3beb6699181986cc97dd712498fe
config: mips-randconfig-a001-20200428 (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project f30416fdde922eaa655934e050026930fefbd260)
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install mips cross compiling tool for clang build
        # apt-get install binutils-mips-linux-gnu
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=mips 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> ld.lld: error: undefined symbol: __compiletime_assert_148
   >>> referenced by init.c:453 (arch/mips/mm/init.c:453)
   >>>               mm/init.o:(mem_init) in archive arch/mips/built-in.a

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 26404 bytes --]

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

end of thread, other threads:[~2020-04-29  1:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-21  9:15 [PATCH] mips/mm: Add page soft dirty tracking Guoyun Sun
2020-04-26 16:54 ` Thomas Bogendoerfer
2020-04-26 17:09   ` Paul Cercueil
2020-04-27  9:04     ` Thomas Bogendoerfer
2020-04-26 17:10   ` Jiaxun Yang
2020-04-29  1:41 ` kbuild test robot

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).