From patchwork Wed Oct 9 08:42:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jia He X-Patchwork-Id: 11180801 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 9D7DB14ED for ; Wed, 9 Oct 2019 08:43:16 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 726D3206C0 for ; Wed, 9 Oct 2019 08:43:16 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="pNLWL11k" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 726D3206C0 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Owner; bh=gP5b7ftToRncLGUPupvt3sHuOazbsB8Rg7V5XhdWr9w=; b=pNL WL11kNCtJbIqEGkrccnWlRUcaMDgULTJBSo4vVWAqx8LDMwWBJMaoC8v12vhoiTzYxJZhX2hdckec JGYgC8UbMuU0eKptGjeqDpHjSeXxNSMsCH0IhPC3oT22tOo863Wc18WL1ejdp7Y4K0y3+lNmeQSF/ dOETj8dbDNGmxSzfW3+D651m/wpafBJQPOMzYHdHSN933w02W7AFcHiSL7/ayjcCSWQbYNYyjmIel sKsMIDKCWZEzcVf6moz0swznnRlqA9jNuddrrR+2B0YBy46NYjmfWtLPsaGVevjgcNmDO1e8ObifG 9kIFhnInOTgsyj9DmCR+e66G1Arwiig==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iI7Yw-0004VF-Uo; Wed, 09 Oct 2019 08:43:14 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92.2 #3 (Red Hat Linux)) id 1iI7Yt-0004Ua-HA for linux-arm-kernel@lists.infradead.org; Wed, 09 Oct 2019 08:43:12 +0000 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 67EC6337; Wed, 9 Oct 2019 01:43:09 -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 B69F03F68E; Wed, 9 Oct 2019 01:43:04 -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 Subject: [PATCH v11 0/4] fix double page fault in cow_user_page for pfn mapping Date: Wed, 9 Oct 2019 16:42:42 +0800 Message-Id: <20191009084246.123354-1-justin.he@arm.com> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191009_014311_617012_CB77B281 X-CRM114-Status: UNSURE ( 9.58 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jia He , Kaly Xin , hejianet@gmail.com, Thomas Gleixner , nd@arm.com, Andrew Morton MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org 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 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(-)