Received: by 10.213.65.68 with SMTP id h4csp3949986imn; Tue, 3 Apr 2018 13:41:44 -0700 (PDT) X-Google-Smtp-Source: AIpwx487o43pCtTOIeBG79ab9to0nFpjNSkN8q6NxI8N8H19mk8VHKIWrG596h3GH0sOu8zAhgOO X-Received: by 10.99.52.11 with SMTP id b11mr9850642pga.377.1522788104124; Tue, 03 Apr 2018 13:41:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522788104; cv=none; d=google.com; s=arc-20160816; b=zhA1vunXMvgB2uAvXHsPBqbSsb/FqKDxkzWIKDmpzr+sjXwJxPNimWpbU+sMNv0Yhe aHOj/Ok3f5IvKwhJ+o9l8RHIK3vo5zy1CKi+8uEZWgN9+Wkc68fE/EpEpQlWDKHAbtdq IXZUuWZo/8jRHAxkb0lKzAPIU8Nh/UDRqHCx47yhsfyelf+rOFzBSZ9FWClNXKgv0Wum k+WHJEYBYZGN1kTPyqN2Coss6mTaNNYdNHfTZwUgvX/McjWA9sLr+ebsPcDKvsZxfnxu fM9Se5BE6l39fhIe4UdBNeJiVz0y5KtCNkoRvXYH/5bdTEs60PHVkq3+Bc2oWIIjXOOW JCrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date:dkim-signature :arc-authentication-results; bh=v2XLhIy3TmQ8TxMaHS++mAdsdyATS1ZP07ABYqYVKIs=; b=UPVPX+jwx7Tv3EhnHJNEFe/Gkx2c8yxnEQNS/7fvaGy4IdxzhIvXyKvUwo5Zx2IInR TZwPEzuTYRAVhr/8Vf/r34J9iGVUUjj12NFoaLvbwy+XnzwD71TSaBL0/Q7RSP8+mZsL ZwvP9UW02SdL2IpjrudGd0MUCNcPFEsdX7DiD57V9K5KS5VSbmOKB8CJxKWr1jsxvo0y noYMktCxl6E+uVMBfd6NxOgeWdtoy9H8rLXZAx9SYGkgRf/EX0dCz5uURqzzGHYGtuDD HG1Q3AmXzw/jeOw15lsPZYR6s1ZhQQ+tMazKNboWXHZBgeiPK2ThJrSf+EZMPtnBvoJz ZscA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=rMFK751j; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l27si2807660pfi.365.2018.04.03.13.41.29; Tue, 03 Apr 2018 13:41:44 -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=@google.com header.s=20161025 header.b=rMFK751j; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753128AbeDCUkW (ORCPT + 99 others); Tue, 3 Apr 2018 16:40:22 -0400 Received: from mail-pl0-f66.google.com ([209.85.160.66]:44291 "EHLO mail-pl0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752420AbeDCUkV (ORCPT ); Tue, 3 Apr 2018 16:40:21 -0400 Received: by mail-pl0-f66.google.com with SMTP id b6-v6so8613920pla.11 for ; Tue, 03 Apr 2018 13:40:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:in-reply-to:message-id:references :user-agent:mime-version; bh=v2XLhIy3TmQ8TxMaHS++mAdsdyATS1ZP07ABYqYVKIs=; b=rMFK751jCWjDndvmfCpElKgDvMdPqErT1eKz84m8YoehBonaGkiCQlNgQwRt63xRY+ Xb0jWG2sOde2E/5GbRfRPINTcLD4RqkdEFj1HxgV2jr7UjLvDY7g7MxMF7IhWz6HNxtc LDGSH4VegwFsUzwGL0zjoqJGlou6nDuwL8eLhJ35pa6qjyCEnQ8g2MiNHFulxvSeTSQ9 0t35j/BPfPkTRsBrBfaRPfQl4SXecnSzvGurW8exBqdkifl89wBULlhj6sncOUk8zsZ+ 0s66dFlOzXWIu+LQ3V1ZwPoV7nSVCJC9M7FRY1rjHfEGBzSrbSUX2qLn9dlcmyy9Cwip Y9KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:in-reply-to:message-id :references:user-agent:mime-version; bh=v2XLhIy3TmQ8TxMaHS++mAdsdyATS1ZP07ABYqYVKIs=; b=QxmucS9ZYUKqqt3Y4d8i1xdsZ/4sbaSZniUo32zXcLxnvU0Pkq7fbrf/bVbcrlT7So GFCOMft4vGJf5pLNGAI+GxhdtzU1nwpntIIysSJgsoIrm8uDu8RUcRY9jdAXGhqhJo3d bWO9AJ9KiIzGJvzLTsez+ZDifRtlKoiTiVRaQW2hMLn7LvfcFtFJ1bgrV/Xl2FWR+TP/ MxDU6LXqxV49own1INsMMyBsurWk6c6I/KUzCGUKpqrsCzfy7UXW8iqkr62dvK73E2XD hvbO7gMmJnOqpSlCZV+4lMuypx+MvZPfd99ArfFcEcthtXD9rbtkjkkdQXbH34Xw6CvH XYGw== X-Gm-Message-State: AElRT7FYdSifTnoXl0Zre9oFkqcRyICI6wTYVTTDtis5zcF+vMTa8mxY tztDU6R3EGoLp84o75whyGG9bg== X-Received: by 10.99.1.133 with SMTP id 127mr10246957pgb.24.1522788020265; Tue, 03 Apr 2018 13:40:20 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id 73sm5830544pgg.73.2018.04.03.13.40.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Apr 2018 13:40:19 -0700 (PDT) Date: Tue, 3 Apr 2018 13:40:18 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Jerome Glisse cc: Laurent Dufour , 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, Matthew Wilcox , 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 v9 06/24] mm: make pte_unmap_same compatible with SPF In-Reply-To: <20180403191005.GC5935@redhat.com> Message-ID: References: <1520963994-28477-1-git-send-email-ldufour@linux.vnet.ibm.com> <1520963994-28477-7-git-send-email-ldufour@linux.vnet.ibm.com> <20180403191005.GC5935@redhat.com> User-Agent: Alpine 2.20 (DEB 67 2015-01-07) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 3 Apr 2018, Jerome Glisse wrote: > > diff --git a/mm/memory.c b/mm/memory.c > > index 21b1212a0892..4bc7b0bdcb40 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -2309,21 +2309,29 @@ static bool pte_map_lock(struct vm_fault *vmf) > > * parts, do_swap_page must check under lock before unmapping the pte and > > * proceeding (but do_wp_page is only called after already making such a check; > > * and do_anonymous_page can safely check later on). > > + * > > + * pte_unmap_same() returns: > > + * 0 if the PTE are the same > > + * VM_FAULT_PTNOTSAME if the PTE are different > > + * VM_FAULT_RETRY if the VMA has changed in our back during > > + * a speculative page fault handling. > > */ > > -static inline int pte_unmap_same(struct mm_struct *mm, pmd_t *pmd, > > - pte_t *page_table, pte_t orig_pte) > > +static inline int pte_unmap_same(struct vm_fault *vmf) > > { > > - int same = 1; > > + int ret = 0; > > + > > #if defined(CONFIG_SMP) || defined(CONFIG_PREEMPT) > > if (sizeof(pte_t) > sizeof(unsigned long)) { > > - spinlock_t *ptl = pte_lockptr(mm, pmd); > > - spin_lock(ptl); > > - same = pte_same(*page_table, orig_pte); > > - spin_unlock(ptl); > > + if (pte_spinlock(vmf)) { > > + if (!pte_same(*vmf->pte, vmf->orig_pte)) > > + ret = VM_FAULT_PTNOTSAME; > > + spin_unlock(vmf->ptl); > > + } else > > + ret = VM_FAULT_RETRY; > > } > > #endif > > - pte_unmap(page_table); > > - return same; > > + pte_unmap(vmf->pte); > > + return ret; > > } > > > > static inline void cow_user_page(struct page *dst, struct page *src, unsigned long va, struct vm_area_struct *vma) > > @@ -2913,7 +2921,8 @@ int do_swap_page(struct vm_fault *vmf) > > int exclusive = 0; > > int ret = 0; > > > > - if (!pte_unmap_same(vma->vm_mm, vmf->pmd, vmf->pte, vmf->orig_pte)) > > + ret = pte_unmap_same(vmf); > > + if (ret) > > goto out; > > > > This change what do_swap_page() returns ie before it was returning 0 > when locked pte lookup was different from orig_pte. After this patch > it returns VM_FAULT_PTNOTSAME but this is a new return value for > handle_mm_fault() (the do_swap_page() return value is what ultimately > get return by handle_mm_fault()) > > Do we really want that ? This might confuse some existing user of > handle_mm_fault() and i am not sure of the value of that information > to caller. > > Note i do understand that you want to return retry if anything did > change from underneath and thus need to differentiate from when the > pte value are not the same. > I think VM_FAULT_RETRY should be handled appropriately for any user of handle_mm_fault() already, and would be surprised to learn differently. Khugepaged has the appropriate handling. I think the concern is whether a user is handling anything other than VM_FAULT_RETRY and VM_FAULT_ERROR (which VM_FAULT_PTNOTSAME is not set in)? I haven't done a full audit of the users.