Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1088688yba; Thu, 18 Apr 2019 15:07:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxi7GIsduJjDhk1Qo7xVyMmmwdnajwvfXh5o5shx+V+4A+pNr4cTmAiuCEui42SggU8mKaP X-Received: by 2002:a65:63d5:: with SMTP id n21mr339428pgv.330.1555625266393; Thu, 18 Apr 2019 15:07:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555625266; cv=none; d=google.com; s=arc-20160816; b=CQyvb90XLeoqK0CbdYXoxPdOfdNkBdFAVly1ZMnDpye6aK26Qia90DY2+WwPxXFMVk 36wBCy0K9nNkrw9VhQniygkFE9bXmQihKXhWryi6cX2avZqG72iYSwEV4Sgi+5bKpfbN e0yNWWio1bki3W7tCKIGFmYmky6qNZGkrdwouKAiP+npR8DHEM9J8dhrER5NIFMQDTPn vLTSL42GnuAYGTSaFami5cR6t2gjJA9ParrWDKMJ9XeY3wc3ouE00abMn8Qr/iqKwB5h kXxoD/R4yT90CWTLXKszYc1EBhn6MnQ1H2QCcdMpGiuWwgF+g/JChdczLPs+nhvg0pfK yh+w== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=kjaqv1yERcNZ6s1PEC8wCbequ+KYSzl8PjfiI4bSXoA=; b=smmPp+xX7UTw0LV8Qn58h5gFJ0AbRmf9+j6ctzUlrJvY/3oFcGde2NU1zxe/R8mPED C/4aoVf/wGvlu1JMHrO9NaU6r4OIDwfVp6X3xtZlqF2wlftMF8R+NNxd85vWzu4XZWvw msu88zJ8uYERFhNAS/BE6zCuPj27+cN5u/f3pPLhMCvvOjnlQl9hnS4mJLwcS2Iu96zW i4Q/N3vxnjsAxIAtpimlYYfUv8jwB1DOzvgmYlEUTa57Wjw9xQPkDFeqMoU4pZ7JG1Dz yh4+qfNgmREcOWneJARjIeYLXdNdQgILHVW6ejrQNRRZqAH18luh41PxQUtGTD8RBJr/ NQ6A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i3si2771697pgq.350.2019.04.18.15.07.30; Thu, 18 Apr 2019 15:07:46 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726296AbfDRWFw (ORCPT + 99 others); Thu, 18 Apr 2019 18:05:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:48116 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726026AbfDRWFw (ORCPT ); Thu, 18 Apr 2019 18:05:52 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F3EE7301EA88; Thu, 18 Apr 2019 22:05:50 +0000 (UTC) Received: from redhat.com (unknown [10.20.6.236]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 46F5A600C5; Thu, 18 Apr 2019 22:05:47 +0000 (UTC) Date: Thu, 18 Apr 2019 18:05:45 -0400 From: Jerome Glisse To: Laurent Dufour Cc: akpm@linux-foundation.org, mhocko@kernel.org, peterz@infradead.org, kirill@shutemov.name, ak@linux.intel.com, dave@stgolabs.net, jack@suse.cz, Matthew Wilcox , aneesh.kumar@linux.ibm.com, benh@kernel.crashing.org, mpe@ellerman.id.au, paulus@samba.org, Thomas Gleixner , Ingo Molnar , hpa@zytor.com, Will Deacon , Sergey Senozhatsky , sergey.senozhatsky.work@gmail.com, Andrea Arcangeli , Alexei Starovoitov , kemi.wang@intel.com, Daniel Jordan , David Rientjes , Ganesh Mahendran , Minchan Kim , Punit Agrawal , vinayak menon , Yang Shi , zhong jiang , Haiyan Song , Balbir Singh , sj38.park@gmail.com, Michel Lespinasse , Mike Rapoport , linux-kernel@vger.kernel.org, linux-mm@kvack.org, haren@linux.vnet.ibm.com, npiggin@gmail.com, paulmck@linux.vnet.ibm.com, Tim Chen , linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: Re: [PATCH v12 06/31] mm: introduce pte_spinlock for FAULT_FLAG_SPECULATIVE Message-ID: <20190418220545.GF11645@redhat.com> References: <20190416134522.17540-1-ldufour@linux.ibm.com> <20190416134522.17540-7-ldufour@linux.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20190416134522.17540-7-ldufour@linux.ibm.com> User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 18 Apr 2019 22:05:51 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Apr 16, 2019 at 03:44:57PM +0200, Laurent Dufour wrote: > When handling page fault without holding the mmap_sem the fetch of the > pte lock pointer and the locking will have to be done while ensuring > that the VMA is not touched in our back. > > So move the fetch and locking operations in a dedicated function. > > Signed-off-by: Laurent Dufour Reviewed-by: J?r?me Glisse > --- > mm/memory.c | 15 +++++++++++---- > 1 file changed, 11 insertions(+), 4 deletions(-) > > diff --git a/mm/memory.c b/mm/memory.c > index fc3698d13cb5..221ccdf34991 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -2073,6 +2073,13 @@ int apply_to_page_range(struct mm_struct *mm, unsigned long addr, > } > EXPORT_SYMBOL_GPL(apply_to_page_range); > > +static inline bool pte_spinlock(struct vm_fault *vmf) > +{ > + vmf->ptl = pte_lockptr(vmf->vma->vm_mm, vmf->pmd); > + spin_lock(vmf->ptl); > + return true; > +} > + > static inline bool pte_map_lock(struct vm_fault *vmf) > { > vmf->pte = pte_offset_map_lock(vmf->vma->vm_mm, vmf->pmd, > @@ -3656,8 +3663,8 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) > * validation through pte_unmap_same(). It's of NUMA type but > * the pfn may be screwed if the read is non atomic. > */ > - vmf->ptl = pte_lockptr(vma->vm_mm, vmf->pmd); > - spin_lock(vmf->ptl); > + if (!pte_spinlock(vmf)) > + return VM_FAULT_RETRY; > if (unlikely(!pte_same(*vmf->pte, vmf->orig_pte))) { > pte_unmap_unlock(vmf->pte, vmf->ptl); > goto out; > @@ -3850,8 +3857,8 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) > if (pte_protnone(vmf->orig_pte) && vma_is_accessible(vmf->vma)) > return do_numa_page(vmf); > > - vmf->ptl = pte_lockptr(vmf->vma->vm_mm, vmf->pmd); > - spin_lock(vmf->ptl); > + if (!pte_spinlock(vmf)) > + return VM_FAULT_RETRY; > entry = vmf->orig_pte; > if (unlikely(!pte_same(*vmf->pte, entry))) > goto unlock; > -- > 2.21.0 >