Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp378785ybz; Wed, 29 Apr 2020 01:46:57 -0700 (PDT) X-Google-Smtp-Source: APiQypKuq16Y+CoekdlgEbtKdrHMAJflcP5g4DMrhPqO559/J4eRLtpAUF1Ek3RgQ0pEvNzq2r2E X-Received: by 2002:a17:906:35d0:: with SMTP id p16mr1534406ejb.77.1588150017076; Wed, 29 Apr 2020 01:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588150017; cv=none; d=google.com; s=arc-20160816; b=Gv+TKqIc4wrjt+0wCwaUJc+XkguU9qIbDVEMEGDLB7i3tQe1YgVEWK7amaA9+WWKaF WTuXBo5Vu5/8HqriaTas0sYiBwDhEWgzQubKj7lrdwiUsjRAiX4MQHkxxZiPbeW+NKWD HgyT9mvpzKyLk2BHDm/vRGk9uUaum6eKn/cEWE/zJv4aaTuWdaJ+YSH7VqFyshq0HIwV mT16DWzsV2jhxBAsVmAGmyz1g7hp7NbcIBMv+qQfjaeeCXZKsPPvqBQqJOklxfPZ8EEw mgtMHXxNQijpgkXwVVRVMRLgyEu7tCC6/qPNh9iJA9mqnOmO/RYA7iLHpYoOQg9OmO2/ 4VMQ== 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=rvvQCrCaUIEUGuDnQbz2W1jBkGU4hMUItTTvFxaxJuE=; b=WxSHe94CZ+FtZty2KcTrXkyZ5hJnF1NiyvL8P2kQBpYCSH7Y7ZTVon2uEjPwDN4Kha Hu8IJoAKzzXBSbNtxEwNFXx/d68xWXY8hEscApJHBa4AHaJhiPtCuRyh+Ce9xVhZaYxL dYwEb5pQbnyyg9bhgd0j1R7zAK8y3daKOp0EdamRDSFWHPEb3p5j6R9bYnvNY33LxM4Q Fi2x0SuZBWl3JosbKmhVziynnStsC3qr6Ks8yt8tKTblzbfGCKC4SSpnsb9o8NTps6X0 fE5O1eOMFErTGJCgf/8BSiCsmpf8Xo09P37zZKENotfuATMd/qgwDZUGYFzB7ridUjgO BVzw== 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 q12si3058670edc.303.2020.04.29.01.46.32; Wed, 29 Apr 2020 01:46:57 -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 S1726516AbgD2Ioz (ORCPT + 99 others); Wed, 29 Apr 2020 04:44:55 -0400 Received: from mail.loongson.cn ([114.242.206.163]:60904 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726345AbgD2Ioy (ORCPT ); Wed, 29 Apr 2020 04:44:54 -0400 Received: from localhost.cn (unknown [10.40.23.12]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9DxL2twPqleuLMtAA--.20S2; Wed, 29 Apr 2020 16:44:33 +0800 (CST) From: Guoyun Sun To: Thomas Bogendoerfer Cc: Jiaxun Yang , Andrew Morton , Paul Burton , Daniel Silsby , Paul Cercueil , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Guoyun Sun Subject: [PATCH v2] mips/mm: Add page soft dirty tracking Date: Wed, 29 Apr 2020 16:44:32 +0800 Message-Id: <1588149872-9780-1-git-send-email-sunguoyun@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf9DxL2twPqleuLMtAA--.20S2 X-Coremail-Antispam: 1UD129KBjvJXoWxCw1xuw4rXr17Gr47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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/include/asm/pgtable-bits.h | 20 +++++++++++++-- arch/mips/include/asm/pgtable.h | 48 ++++++++++++++++++++++++++++++++++-- 2 files changed, 64 insertions(+), 4 deletions(-) diff --git a/arch/mips/include/asm/pgtable-bits.h b/arch/mips/include/asm/pgtable-bits.h index 4da79b8..e26dc41 100644 --- a/arch/mips/include/asm/pgtable-bits.h +++ b/arch/mips/include/asm/pgtable-bits.h @@ -55,6 +55,9 @@ enum pgtable_bits { #if defined(CONFIG_ARCH_HAS_PTE_SPECIAL) _PAGE_SPECIAL_SHIFT, #endif +#if defined(CONFIG_HAVE_ARCH_SOFT_DIRTY) + _PAGE_SOFT_DIRTY_SHIFT, +#endif }; /* @@ -84,6 +87,9 @@ enum pgtable_bits { #if defined(CONFIG_ARCH_HAS_PTE_SPECIAL) _PAGE_SPECIAL_SHIFT, #endif +#if defined(CONFIG_HAVE_ARCH_SOFT_DIRTY) + _PAGE_SOFT_DIRTY_SHIFT, +#endif }; #elif defined(CONFIG_CPU_R3K_TLB) @@ -99,6 +105,9 @@ enum pgtable_bits { #if defined(CONFIG_ARCH_HAS_PTE_SPECIAL) _PAGE_SPECIAL_SHIFT, #endif +#if defined(CONFIG_HAVE_ARCH_SOFT_DIRTY) + _PAGE_SOFT_DIRTY_SHIFT, +#endif /* Used by TLB hardware (placed in EntryLo) */ _PAGE_GLOBAL_SHIFT = 8, @@ -125,7 +134,9 @@ enum pgtable_bits { #if defined(CONFIG_ARCH_HAS_PTE_SPECIAL) _PAGE_SPECIAL_SHIFT, #endif - +#if defined(CONFIG_HAVE_ARCH_SOFT_DIRTY) + _PAGE_SOFT_DIRTY_SHIFT, +#endif /* Used by TLB hardware (placed in EntryLo*) */ #if defined(CONFIG_CPU_HAS_RIXI) _PAGE_NO_EXEC_SHIFT, @@ -152,6 +163,11 @@ enum pgtable_bits { #else # define _PAGE_SPECIAL 0 #endif +#if defined(CONFIG_HAVE_ARCH_SOFT_DIRTY) +# define _PAGE_SOFT_DIRTY (1 << _PAGE_SOFT_DIRTY_SHIFT) +#else +# define _PAGE_SOFT_DIRTY 0 +#endif /* Used by TLB hardware (placed in EntryLo*) */ #if defined(CONFIG_XPA) @@ -269,6 +285,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 aab0ec1..9b01d2d 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 /* @@ -576,7 +600,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; @@ -605,6 +629,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