Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp4533498ybz; Tue, 21 Apr 2020 02:18:48 -0700 (PDT) X-Google-Smtp-Source: APiQypKewzZ8fCcy7Px4lrl84dF57w5V6I6dlx8bVcLDx93lYX4C1wmRDgYcsYRDCgW+poSxt90d X-Received: by 2002:a05:6402:3125:: with SMTP id dd5mr12681262edb.208.1587460728747; Tue, 21 Apr 2020 02:18:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587460728; cv=none; d=google.com; s=arc-20160816; b=Lwr+L5K6B/PktZ890hZcYTDDLUP61VQUYwgNO1EJ8aGrogQDBzzNxIkEmAEWNd27b/ PsL2cnDrziIR0ilrZs9oIQ+bwj91V3HiEprObz40BSeaJalFAXl5+1UatS5aRl99C8UP iwer+MR2LV22pW1NI8yuxOLScRybyIxD3ffGR1nSe+EGl4ursOWtPI+HAGq3QqRU8L6k yBgWIN98gQf8fhKU8L3u79JXI+Rh/QQus1rI3Igt/I/CwO3m/9l2SB1rFfJpVTSix/Tl LYSnEOhutKZpbR09sgh830bGGNSdgeiLG15Mw2sq8uXFUOmVISXt3QB99HzGilCNfHlT juCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=Y+/8ZTmHkShhYb7LglPP5k8jIM4UVMcMGwhe378U3Rw=; b=Gp8G/cfwE+L1zSFp2/57s1lfYtfjNka7WfdogfzVMxuJc7vZQFxqXHCQjTmo6LW+Gd GgMKwCmpmKFrUFSoNkr/lvpuqGYcung73D4EyItz7X9jdhRnW1Z/I9+szmvfF6Bk4gXG Ekw0qLrY6xFAo5sAIW+bj+jDeoC8i8VMUQ3j4ZjLQcSbspcUzqmBgesWjL/5wJ86anDh 5CeYjGSvD6DTpaCi4DX8bdYUPxh5XL6r5fC+02zpeknb+VTc+2pCgjgxQFdnw6TDRLlK u+MU1NvWNoBISlc8hzP48kJNGbBLKzDAO/xaQbhG0+wlWizMDSqNK3GZsO9iiR2AwHzv O2kw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a8si1287997eds.377.2020.04.21.02.18.25; Tue, 21 Apr 2020 02:18:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727042AbgDUJQI (ORCPT + 99 others); Tue, 21 Apr 2020 05:16:08 -0400 Received: from mail.loongson.cn ([114.242.206.163]:36824 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726018AbgDUJQI (ORCPT ); Tue, 21 Apr 2020 05:16:08 -0400 Received: from localhost.loongson.cn (unknown [10.40.23.12]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dxr2uvuZ5eTnwqAA--.4S2; Tue, 21 Apr 2020 17:15:27 +0800 (CST) From: Guoyun Sun 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@vger.kernel.org, linux-kernel@vger.kernel.org, Guoyun Sun , TieZhu Yang , Xuefeng Li Subject: [PATCH] mips/mm: Add page soft dirty tracking Date: Tue, 21 Apr 2020 17:15:27 +0800 Message-Id: <1587460527-13986-1-git-send-email-sunguoyun@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf9Dxr2uvuZ5eT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Xa7VUb0D73UUUUU== X-CM-SenderInfo: 5vxqw3hr1x0qxorr0wxvrqhubq/ Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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