From patchwork Thu Dec 22 14:52:03 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 9485099 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C90CE600BA for ; Thu, 22 Dec 2016 14:54:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B848728113 for ; Thu, 22 Dec 2016 14:54:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AB31528174; Thu, 22 Dec 2016 14:54:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0010428113 for ; Thu, 22 Dec 2016 14:54:15 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cK4jT-0005Ld-F0; Thu, 22 Dec 2016 14:52:35 +0000 Received: from lgeamrelo11.lge.com ([156.147.23.51]) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cK4jP-00056o-Ds for linux-arm-kernel@lists.infradead.org; Thu, 22 Dec 2016 14:52:32 +0000 Received: from unknown (HELO lgeamrelo02.lge.com) (156.147.1.126) by 156.147.23.51 with ESMTP; 22 Dec 2016 23:52:04 +0900 X-Original-SENDERIP: 156.147.1.126 X-Original-MAILFROM: minchan@kernel.org Received: from unknown (HELO bbox) (10.177.223.161) by 156.147.1.126 with ESMTP; 22 Dec 2016 23:52:04 +0900 X-Original-SENDERIP: 10.177.223.161 X-Original-MAILFROM: minchan@kernel.org Date: Thu, 22 Dec 2016 23:52:03 +0900 From: Minchan Kim To: "Kirill A. Shutemov" Subject: Re: [PATCH] mm: pmd dirty emulation in page fault handler Message-ID: <20161222145203.GA18970@bbox> References: <1482364101-16204-1-git-send-email-minchan@kernel.org> <20161222081713.GA32480@node.shutemov.name> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20161222081713.GA32480@node.shutemov.name> User-Agent: Mutt/1.5.24 (2015-08-30) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161222_065231_900197_126B1932 X-CRM114-Status: GOOD ( 16.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arch@vger.kernel.org, Jason Evans , Catalin Marinas , Will Deacon , "\[4.5+\]" , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, Andreas Schwab , Andrew Morton , "Kirill A . Shutemov" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hello, On Thu, Dec 22, 2016 at 11:17:13AM +0300, Kirill A. Shutemov wrote: < snip > > > diff --git a/mm/memory.c b/mm/memory.c > > index 36c774f..7408ddc 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -3637,18 +3637,20 @@ static int __handle_mm_fault(struct vm_area_struct *vma, unsigned long address, > > if (pmd_protnone(orig_pmd) && vma_is_accessible(vma)) > > return do_huge_pmd_numa_page(&vmf, orig_pmd); > > > > - if ((vmf.flags & FAULT_FLAG_WRITE) && > > - !pmd_write(orig_pmd)) { > > - ret = wp_huge_pmd(&vmf, orig_pmd); > > - if (!(ret & VM_FAULT_FALLBACK)) > > + if (vmf.flags & FAULT_FLAG_WRITE) { > > + if (!pmd_write(orig_pmd)) { > > + ret = wp_huge_pmd(&vmf, orig_pmd); > > + if (ret == VM_FAULT_FALLBACK) > > In theory, more than one flag can be set and it would lead to > false-negative. Bit check was the right thing. > > And I don't understand why do you need to change code in > __handle_mm_fault() at all. > From what I see change to huge_pmd_set_accessed() should be enough. Yeb. Thanks for the review. Here v2 goes. From b3ec95c0df91ad113525968a4a6b53030fd0b48d Mon Sep 17 00:00:00 2001 From: Minchan Kim Date: Thu, 22 Dec 2016 23:43:49 +0900 Subject: [PATCH v2] mm: pmd dirty emulation in page fault handler Andreas reported [1] made a test in jemalloc hang in THP mode in arm64. http://lkml.kernel.org/r/mvmmvfy37g1.fsf@hawking.suse.de The problem is page fault handler supports only accessed flag emulation for THP page of SW-dirty/accessed architecture. This patch enables dirty-bit emulation for those architectures. Without it, MADV_FREE makes application hang by repeated fault forever. [1] b8d3c4c3009d, mm/huge_memory.c: don't split THP page when MADV_FREE syscall is called Cc: Jason Evans Cc: Kirill A. Shutemov Cc: Will Deacon Cc: Catalin Marinas Cc: linux-arch@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: [4.5+] Fixes: b8d3c4c3009d ("mm/huge_memory.c: don't split THP page when MADV_FREE syscall is called") Reported-by: Andreas Schwab Signed-off-by: Minchan Kim Acked-by: Kirill A. Shutemov --- * from v1 * Remove __handle_mm_fault part - Kirill mm/huge_memory.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 10eedbf..29ec8a4 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -883,15 +883,17 @@ void huge_pmd_set_accessed(struct vm_fault *vmf, pmd_t orig_pmd) { pmd_t entry; unsigned long haddr; + bool write = vmf->flags & FAULT_FLAG_WRITE; vmf->ptl = pmd_lock(vmf->vma->vm_mm, vmf->pmd); if (unlikely(!pmd_same(*vmf->pmd, orig_pmd))) goto unlock; entry = pmd_mkyoung(orig_pmd); + if (write) + entry = pmd_mkdirty(entry); haddr = vmf->address & HPAGE_PMD_MASK; - if (pmdp_set_access_flags(vmf->vma, haddr, vmf->pmd, entry, - vmf->flags & FAULT_FLAG_WRITE)) + if (pmdp_set_access_flags(vmf->vma, haddr, vmf->pmd, entry, write)) update_mmu_cache_pmd(vmf->vma, vmf->address, vmf->pmd); unlock: