Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752136AbdFNNwF (ORCPT ); Wed, 14 Jun 2017 09:52:05 -0400 Received: from mga02.intel.com ([134.134.136.20]:13881 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751990AbdFNNwC (ORCPT ); Wed, 14 Jun 2017 09:52:02 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,340,1493708400"; d="scan'208";a="867901381" From: "Kirill A. Shutemov" To: Andrew Morton , Vlastimil Babka , Vineet Gupta , Russell King , Will Deacon , Catalin Marinas , Ralf Baechle , "David S. Miller" , Heiko Carstens Cc: "Aneesh Kumar K . V" , Martin Schwidefsky , Andrea Arcangeli , linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCH 3/3] mm, thp: Do not loose dirty bit in __split_huge_pmd_locked() Date: Wed, 14 Jun 2017 16:51:43 +0300 Message-Id: <20170614135143.25068-4-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170614135143.25068-1-kirill.shutemov@linux.intel.com> References: <20170614135143.25068-1-kirill.shutemov@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1785 Lines: 58 Until pmdp_invalidate() pmd entry is present and CPU can update it, setting dirty. Currently, we tranfer dirty bit to page too early and there is window when we can miss dirty bit. Let's call SetPageDirty() after pmdp_invalidate(). Signed-off-by: Kirill A. Shutemov --- mm/huge_memory.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index a84909cf20d3..c4ee5c890910 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -1928,7 +1928,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, struct page *page; pgtable_t pgtable; pmd_t _pmd; - bool young, write, dirty, soft_dirty; + bool young, write, soft_dirty; unsigned long addr; int i; @@ -1965,7 +1965,6 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, page_ref_add(page, HPAGE_PMD_NR - 1); write = pmd_write(*pmd); young = pmd_young(*pmd); - dirty = pmd_dirty(*pmd); soft_dirty = pmd_soft_dirty(*pmd); pmdp_huge_split_prepare(vma, haddr, pmd); @@ -1995,8 +1994,6 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, if (soft_dirty) entry = pte_mksoft_dirty(entry); } - if (dirty) - SetPageDirty(page + i); pte = pte_offset_map(&_pmd, addr); BUG_ON(!pte_none(*pte)); set_pte_at(mm, addr, pte, entry); @@ -2046,6 +2043,14 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, * pmd_populate. */ pmdp_invalidate(vma, haddr, pmd); + + /* + * Transfer dirty bit to page after pmd invalidated, so CPU would not + * be able to set it under us. + */ + if (pmd_dirty(*pmd)) + SetPageDirty(page); + pmd_populate(mm, pmd, pgtable); if (freeze) { -- 2.11.0