From patchwork Fri Dec 23 07:53:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 9487249 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 779B2601D2 for ; Fri, 23 Dec 2016 07:56:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6690F27DF9 for ; Fri, 23 Dec 2016 07:56:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 570D027E22; Fri, 23 Dec 2016 07:56:10 +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 CC5A527DF9 for ; Fri, 23 Dec 2016 07:56:09 +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 1cKKfg-0002GO-DJ; Fri, 23 Dec 2016 07:53:44 +0000 Received: from lgeamrelo13.lge.com ([156.147.23.53]) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1cKKfb-00028E-J5 for linux-arm-kernel@lists.infradead.org; Fri, 23 Dec 2016 07:53:41 +0000 Received: from unknown (HELO lgemrelse7q.lge.com) (156.147.1.151) by 156.147.23.53 with ESMTP; 23 Dec 2016 16:53:14 +0900 X-Original-SENDERIP: 156.147.1.151 X-Original-MAILFROM: minchan@kernel.org Received: from unknown (HELO localhost.localdomain) (10.177.223.161) by 156.147.1.151 with ESMTP; 23 Dec 2016 16:53:13 +0900 X-Original-SENDERIP: 10.177.223.161 X-Original-MAILFROM: minchan@kernel.org From: Minchan Kim To: Andrew Morton Subject: [PATCH v3] mm: pmd dirty emulation in page fault handler Date: Fri, 23 Dec 2016 16:53:07 +0900 Message-Id: <1482479587-4823-1-git-send-email-minchan@kernel.org> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161222_235339_989331_2A5F6C34 X-CRM114-Status: UNSURE ( 8.60 ) X-CRM114-Notice: Please train this message. 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 , Minchan Kim , Catalin Marinas , Will Deacon , linux-kernel@vger.kernel.org, "\[4.5+\]" , linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, "Kirill A . Shutemov" MIME-Version: 1.0 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 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-and-Tested-by: Andreas Schwab Acked-by: Kirill A. Shutemov Signed-off-by: Minchan Kim --- * from v2 * Add acked-by/tested-by * 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: