Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp8270308ybn; Tue, 1 Oct 2019 05:55:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqzIhMlosBIxpLdtxwQEk2DwMIejB4wacNFZTbNiDTp4egGmsRyeApLXanC0pn2An6i8Oo8D X-Received: by 2002:aa7:c897:: with SMTP id p23mr25451878eds.199.1569934515060; Tue, 01 Oct 2019 05:55:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569934515; cv=none; d=google.com; s=arc-20160816; b=piAfJSNew0rJYrCfFVB3LiDRZ27Tvnc+V/TksL4gntQ8ru+bq06zVnNMC2jtnNqkRO PJ8BOZQDfh/6zEOZ+l9k+k0WC/62HwH1QndWxwnvSRYoXn/CDBVlNLzUWB+tyM+ruhrP yzrCDxr7mnYEBKa0Y5Ya5g+Pjuxg3A1ISA9YeYphktRR530stGdbQm3UuHzarTzScfE8 PLoVO+8I8yAxLEPYfWno9p6BSam8T/0oP8g7ZxXmP1HvQl9jrCPFRR8LVQtMslrkze7A 0p1Q5/zLMNL1l6gkXDltvClvSQH0OnP2B9Lu1dwUZO5TlmO2y9RcnNaewM9IOmfOYgKe ZfAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=sSUv9aXsgskl7OPuJXZ1HVY6Uf5fZv87/3bYFNsTRGE=; b=WF59tNE3pF+9T/LRwRy/Fr+wSke+GjgNl0V75sy5wXh6n+ndd7hgZN2NYPRkMi/CPn lfWxQW9TPGM2e2hgUmqMyyO4pEDXyOmfdLcVE5KEQch5NjRz2ryAK0QnY/YKiQ4EsZ0T +cQ14GkqLd7V23f/7PpAb3WIq61fv/zs8QsApsiUaUxbv8WLz0oO1A/tjmIF+MyrWjz+ Oej44Rw2fnXNzIZcRoWEFtOpc2AqpjjIgiqGI/0630umBTupmm6nUVTXNZ8bJ8YivfvD ArKKNw0aLX1T4L6H3ytgP4ey6rQ86SC4DTRp5yF198eapIf4ZtNAsFLZwr5lkJhOyKek 5M7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KD7GKKfx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x51si9202862eda.272.2019.10.01.05.54.50; Tue, 01 Oct 2019 05:55:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=KD7GKKfx; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388111AbfJAMyU (ORCPT + 99 others); Tue, 1 Oct 2019 08:54:20 -0400 Received: from mail.kernel.org ([198.145.29.99]:43910 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726464AbfJAMyU (ORCPT ); Tue, 1 Oct 2019 08:54:20 -0400 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9F2E321872; Tue, 1 Oct 2019 12:54:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569934459; bh=qdFT2iQGfLY4YITal90NGC2PaaAOxSUOpd1IJ8jDa4A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=KD7GKKfxZ54dCseOBe5DG+Yohm1Gco/g7LjKC3gCbHAP9ww1Hb9AcIC5WGiQnooAO +x0gIphzaT3nFyIhopIKkTQYByBH1dMoWYdlUT9AwlNE1MQujO3FhOhYP2Owa+U82x DR9GDDoMON4RQpr++Mr7UPWmm3BFFpcOkOmqmfNY= Date: Tue, 1 Oct 2019 13:54:13 +0100 From: Will Deacon To: Jia He Cc: Catalin Marinas , 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, Punit Agrawal , Thomas Gleixner , Andrew Morton , hejianet@gmail.com, Kaly Xin Subject: Re: [PATCH v10 3/3] mm: fix double page fault on arm64 if PTE_AF is cleared Message-ID: <20191001125413.mhxa6qszwnuhglky@willie-the-truck> References: <20190930015740.84362-1-justin.he@arm.com> <20190930015740.84362-4-justin.he@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190930015740.84362-4-justin.he@arm.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 30, 2019 at 09:57:40AM +0800, Jia He wrote: > When we tested pmdk unit test [1] vmmalloc_fork TEST1 in arm64 guest, there > will be a double page fault in __copy_from_user_inatomic of cow_user_page. > > Below call trace is from arm64 do_page_fault for debugging purpose > [ 110.016195] Call trace: > [ 110.016826] do_page_fault+0x5a4/0x690 > [ 110.017812] do_mem_abort+0x50/0xb0 > [ 110.018726] el1_da+0x20/0xc4 > [ 110.019492] __arch_copy_from_user+0x180/0x280 > [ 110.020646] do_wp_page+0xb0/0x860 > [ 110.021517] __handle_mm_fault+0x994/0x1338 > [ 110.022606] handle_mm_fault+0xe8/0x180 > [ 110.023584] do_page_fault+0x240/0x690 > [ 110.024535] do_mem_abort+0x50/0xb0 > [ 110.025423] el0_da+0x20/0x24 > > The pte info before __copy_from_user_inatomic is (PTE_AF is cleared): > [ffff9b007000] pgd=000000023d4f8003, pud=000000023da9b003, pmd=000000023d4b3003, pte=360000298607bd3 > > 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." > > This patch fix it by calling pte_mkyoung. Also, the parameter is > changed because vmf should be passed to cow_user_page() > > Add a WARN_ON_ONCE when __copy_from_user_inatomic() returns error > in case there can be some obscure use-case.(by Kirill) > > [1] https://github.com/pmem/pmdk/tree/master/src/test/vmmalloc_fork > > Signed-off-by: Jia He > Reported-by: Yibo Cai > Reviewed-by: Catalin Marinas > Acked-by: Kirill A. Shutemov > --- > mm/memory.c | 99 +++++++++++++++++++++++++++++++++++++++++++++-------- > 1 file changed, 84 insertions(+), 15 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index b1ca51a079f2..1f56b0118ef5 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -118,6 +118,13 @@ int randomize_va_space __read_mostly = > 2; > #endif > > +#ifndef arch_faults_on_old_pte > +static inline bool arch_faults_on_old_pte(void) > +{ > + return false; > +} > +#endif Kirill has acked this, so I'm happy to take the patch as-is, however isn't it the case that /most/ architectures will want to return true for arch_faults_on_old_pte()? In which case, wouldn't it make more sense for that to be the default, and have x86 and arm64 provide an override? For example, aren't most architectures still going to hit the double fault scenario even with your patch applied? Will