Received: by 10.223.176.5 with SMTP id f5csp1093139wra; Tue, 6 Feb 2018 12:30:34 -0800 (PST) X-Google-Smtp-Source: AH8x225fqw7B5x/bbe3ss94Tq98xxbjaAI30DmBXGptPugAUgyCCxteg2eT6glkiOrTGujhHnC0L X-Received: by 2002:a17:902:8f8a:: with SMTP id z10-v6mr3454963plo.395.1517949034853; Tue, 06 Feb 2018 12:30:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517949034; cv=none; d=google.com; s=arc-20160816; b=oObckXXb2IqBd+15hDsP8KMoaOkOtW1pp2e2aoL3JST1DAgMLnF3K6xLt9tlrp3yPJ YXNDLKCQBJO1PbJFwFPVyYt3dWABTjlT2hyIn/sUmYE6T3vyMgu3xQZSUQ2N194aNYx5 OQO3aSZi2alHPoSw5oAohglZFO6YwunP4iHUq3itYik8QHyu/n+6/SI4HenUvpk+oq1u B1LkgbiALTuc2SV01TIhrafWoPs7eU7U7I9Iwa/1KF+ZdfqKwoAsn0LUPI0J51H2sNN6 sTQbAj7bi/4z2nFsvFNXD4J0DZWY1gumv42I0vbwjUMHsC2YPhcC+ASBXJbC9aZt9n/3 CWJA== 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:arc-authentication-results; bh=levTF5+QD975zp/9T2FZMmhwm14nohr7dRD+kfBB9BY=; b=R3Jl0iiWAgQbVIpzyq5YyeGnAyRkLRXtl+19lAWpJGPOQDIqFzb8q7i6hRz8/fau4i Y0t/PyEJEH6DMvcf+2ISudY4npmoHKz/SININesmj1CXAKzaamyanCX1DFogSVoAT2zM 3EQR4BBnBE+hjYt3fNkEYg22bfneKPRRP4IDqSdAOIPyZKWH70lXJFGOu0CkZxNso+bI tsOPdYYlVaxAuRDmpKiFLXNt9TDrbAoMBkIX1YRplOB6U4xy/Ytwufl20xDdJlNN7HGS eIM2zT65dvPtSdaZp69xUs50zes4qd7oGiRyOdCoRX9OxyKyqCtHHPcM2R6MR57/nJTT 15+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=f+C+BWX6; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h9si363582pgq.683.2018.02.06.12.30.20; Tue, 06 Feb 2018 12:30:34 -0800 (PST) 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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=f+C+BWX6; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753537AbeBFU3O (ORCPT + 99 others); Tue, 6 Feb 2018 15:29:14 -0500 Received: from bombadil.infradead.org ([65.50.211.133]:46871 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752962AbeBFU3F (ORCPT ); Tue, 6 Feb 2018 15:29:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=levTF5+QD975zp/9T2FZMmhwm14nohr7dRD+kfBB9BY=; b=f+C+BWX6cyu/iqN8fIDEOB8NH 3q9Zl6le19rR4yLEybOx9+RxNXwWgOlPFkE2y5xy9gMMxssqez0OGkpY034b/Fs4WLxEpkLFZNlgH hsKwopZm1k1F/58oe5FsF5XqNxy+ZigNhRRKdAYTxOoD0S4P22B0jxfC0/xaeywHpc3SVdcbx44IY uoX37kue/QR3nQV6uejwzIzXOVj1J5XX4u/IFxISfxIC3EFIGDBM1K1Rs2nlSdUpcIKdbo7+um66D 3oZSA2Wyj0/BugO1qoXMetq7g5YC4QSI0Lb9sVKzjFZnr3McK8gcahrTnH0fpa22FEGMLpEhZ1Dh4 IbczqQ1KA==; Received: from willy by bombadil.infradead.org with local (Exim 4.89 #1 (Red Hat Linux)) id 1ej9qy-0001YS-6S; Tue, 06 Feb 2018 20:28:32 +0000 Date: Tue, 6 Feb 2018 12:28:31 -0800 From: Matthew Wilcox To: Laurent Dufour Cc: paulmck@linux.vnet.ibm.com, peterz@infradead.org, akpm@linux-foundation.org, kirill@shutemov.name, ak@linux.intel.com, mhocko@kernel.org, dave@stgolabs.net, jack@suse.cz, benh@kernel.crashing.org, mpe@ellerman.id.au, paulus@samba.org, Thomas Gleixner , Ingo Molnar , hpa@zytor.com, Will Deacon , Sergey Senozhatsky , Andrea Arcangeli , Alexei Starovoitov , kemi.wang@intel.com, sergey.senozhatsky.work@gmail.com, Daniel Jordan , linux-kernel@vger.kernel.org, linux-mm@kvack.org, haren@linux.vnet.ibm.com, khandual@linux.vnet.ibm.com, npiggin@gmail.com, bsingharora@gmail.com, Tim Chen , linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: Re: [PATCH v7 04/24] mm: Dont assume page-table invariance during faults Message-ID: <20180206202831.GB16511@bombadil.infradead.org> References: <1517935810-31177-1-git-send-email-ldufour@linux.vnet.ibm.com> <1517935810-31177-5-git-send-email-ldufour@linux.vnet.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1517935810-31177-5-git-send-email-ldufour@linux.vnet.ibm.com> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 06, 2018 at 05:49:50PM +0100, Laurent Dufour wrote: > From: Peter Zijlstra > > One of the side effects of speculating on faults (without holding > mmap_sem) is that we can race with free_pgtables() and therefore we > cannot assume the page-tables will stick around. > > Remove the reliance on the pte pointer. > > Signed-off-by: Peter Zijlstra (Intel) > > In most of the case pte_unmap_same() was returning 1, which meaning that > do_swap_page() should do its processing. So in most of the case there will > be no impact. > > Now regarding the case where pte_unmap_safe() was returning 0, and thus > do_swap_page return 0 too, this happens when the page has already been > swapped back. This may happen before do_swap_page() get called or while in > the call to do_swap_page(). In that later case, the check done when > swapin_readahead() returns will detect that case. > > The worst case would be that a page fault is occuring on 2 threads at the > same time on the same swapped out page. In that case one thread will take > much time looping in __read_swap_cache_async(). But in the regular page > fault path, this is even worse since the thread would wait for semaphore to > be released before starting anything. > > [Remove only if !CONFIG_SPECULATIVE_PAGE_FAULT] > Signed-off-by: Laurent Dufour I have a great deal of trouble connecting all of the words above to the contents of the patch. > > +#ifndef CONFIG_SPECULATIVE_PAGE_FAULT > /* > * handle_pte_fault chooses page fault handler according to an entry which was > * read non-atomically. Before making any commitment, on those architectures > @@ -2311,6 +2312,7 @@ static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd, > pte_unmap(page_table); > return same; > } > +#endif /* CONFIG_SPECULATIVE_PAGE_FAULT */ > > static inline void cow_user_page(struct page *dst, struct page *src, unsigned long va, struct vm_area_struct *vma) > { > @@ -2898,11 +2900,13 @@ int do_swap_page(struct vm_fault *vmf) > swapcache = page; > } > > +#ifndef CONFIG_SPECULATIVE_PAGE_FAULT > if (!pte_unmap_same(vma->vm_mm, vmf->pmd, vmf->pte, vmf->orig_pte)) { > if (page) > put_page(page); > goto out; > } > +#endif > This feels to me like we want: #ifdef CONFIG_SPECULATIVE_PAGE_FAULT [current code] #else /* * Some words here which explains why we always want to return this * value if we support speculative page faults. */ static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd, pte_t *page_table, pte_t orig_pte) { return 1; } #endif instead of cluttering do_swap_page with an ifdef.