From patchwork Fri Oct 11 14:09:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia He X-Patchwork-Id: 11185607 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 50AE0912 for ; Fri, 11 Oct 2019 14:09:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 24C9F20679 for ; Fri, 11 Oct 2019 14:09:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 24C9F20679 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 494BB8E0001; Fri, 11 Oct 2019 10:09:55 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 41CB36B0006; Fri, 11 Oct 2019 10:09:55 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E3128E0001; Fri, 11 Oct 2019 10:09:55 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 066016B0005 for ; Fri, 11 Oct 2019 10:09:54 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with SMTP id 9D409824CA36 for ; Fri, 11 Oct 2019 14:09:54 +0000 (UTC) X-FDA: 76031687508.09.flesh71_9065a86d88329 X-Spam-Summary: 2,0,0,713286c8a2851fdc,d41d8cd98f00b204,justin.he@arm.com,:catalin.marinas@arm.com:will@kernel.org:mark.rutland@arm.com:james.morse@arm.com:maz@kernel.org:willy@infradead.org:kirill.shutemov@linux.intel.com:linux-arm-kernel@lists.infradead.org:linux-kernel@vger.kernel.org::suzuki.poulose@arm.com:bp@alien8.de:hpa@zytor.com:x86@kernel.org:tglx@linutronix.de:akpm@linux-foundation.org:hejianet@gmail.com:kaly.xin@arm.com:nd@arm.com:justin.he@arm.com,RULES_HIT:41:355:379:541:968:988:989:1260:1261:1345:1437:1534:1542:1711:1730:1747:1777:1792:1801:2198:2199:2393:2559:2562:2693:2901:3138:3139:3140:3141:3142:3353:3865:3866:3867:3868:3870:3871:4605:5007:6117:6119:6120:6261:6737:7901:7903:7904:8634:10004:11026:11473:11657:11658:11914:12043:12048:12291:12296:12297:12438:12679:12895:14096:14394:14721:21080:21220:21433:21451:21627:21795:30051:30054:30070,0,RBL:217.140.110.172:@arm.com:.lbl8.mailshell.net-62.2.0.100 64.100.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:no ne,Domai X-HE-Tag: flesh71_9065a86d88329 X-Filterd-Recvd-Size: 3527 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Fri, 11 Oct 2019 14:09:52 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0F814142F; Fri, 11 Oct 2019 07:09:51 -0700 (PDT) Received: from localhost.localdomain (entos-thunderx2-02.shanghai.arm.com [10.169.40.54]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 7A8693F68E; Fri, 11 Oct 2019 07:09:46 -0700 (PDT) From: Jia He To: Catalin Marinas , Will Deacon , Mark Rutland , James Morse , Marc Zyngier , Matthew Wilcox , "Kirill A. Shutemov" , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Suzuki Poulose , Borislav Petkov , "H. Peter Anvin" , x86@kernel.org Cc: Thomas Gleixner , Andrew Morton , hejianet@gmail.com, Kaly Xin , nd@arm.com, Jia He Subject: [PATCH v12 0/4] fix double page fault in cow_user_page for pfn mapping Date: Fri, 11 Oct 2019 22:09:35 +0800 Message-Id: <20191011140939.6115-1-justin.he@arm.com> X-Mailer: git-send-email 2.17.1 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When we tested pmdk unit test vmmalloc_fork TEST1 in arm64 guest, there will be a double page fault in __copy_from_user_inatomic of cow_user_page. As told by Catalin: "On arm64 without hardware Access Flag, copying from user will fail because the pte is old and cannot be marked young. So we always end up with zeroed page after fork() + CoW for pfn mappings. we don't always have a hardware-managed access flag on arm64." -Changes v12: refine PATCH 01, remove the !! since C languages can convert unsigned to bool (Catalin) v11: refine cpu_has_hw_af in PATCH 01(Will Deacon, Suzuki) change the default return value to true in arch_faults_on_old_pte add PATCH 03 for overriding arch_faults_on_old_pte(false) on x86 v10: add r-b from Catalin and a-b from Kirill in PATCH 03 remoe Reported-by in PATCH 01 v9: refactor cow_user_page for indention optimization (Catalin) hold the ptl longer (Catalin) v8: change cow_user_page's return type (Matthew) v7: s/pte_spinlock/pte_offset_map_lock (Kirill) v6: fix error case of returning with spinlock taken (Catalin) move kmap_atomic to avoid handling kunmap_atomic v5: handle the case correctly when !pte_same fix kbuild test failed v4: introduce cpu_has_hw_af (Suzuki) bail out if !pte_same (Kirill) v3: add vmf->ptl lock/unlock (Kirill A. Shutemov) add arch_faults_on_old_pte (Matthew, Catalin) v2: remove FAULT_FLAG_WRITE when setting pte access flag (Catalin) Jia He (4): arm64: cpufeature: introduce helper cpu_has_hw_af() arm64: mm: implement arch_faults_on_old_pte() on arm64 x86/mm: implement arch_faults_on_old_pte() stub on x86 mm: fix double page fault on arm64 if PTE_AF is cleared arch/arm64/include/asm/cpufeature.h | 14 ++++ arch/arm64/include/asm/pgtable.h | 14 ++++ arch/x86/include/asm/pgtable.h | 6 ++ mm/memory.c | 104 ++++++++++++++++++++++++---- 4 files changed, 123 insertions(+), 15 deletions(-)