Received: by 10.192.165.156 with SMTP id m28csp141222imm; Tue, 17 Apr 2018 07:49:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+rtonZFhjpi9yS380Mfw4GYK73KaQ+gQi1jmirrT7PWhiUhmY1j1kCENSci/v8EU+K95f5 X-Received: by 2002:a17:902:6b4c:: with SMTP id g12-v6mr2341697plt.148.1523976563046; Tue, 17 Apr 2018 07:49:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523976563; cv=none; d=google.com; s=arc-20160816; b=yulRxYuBGxU+yIvw5hsnSGLhHyc2d/HYPUmLxI8fKIjxALjxxipH+f30bUpBw/MfQ5 VWXCfoUATTkzj8dT4XIDIVOn/Ti1iXk4hQhPmXw0ZCd3vcCYh/M5gWuh60MMVtqtlsl5 WTrInA39TvcqgchVVOCGyHWVdJO5+Cgg5yXC8Ks2eMIBSqAaIcTBZEv9/yBkV8DeMVHQ QxsK1FxhosBkGqXKAw9Qa+vks7oZOMErQvJU2XXbejFJSFxUEhZ06dH9Klxt12VRUlZX pb0cxY9TX91Ml4g2GDMblwm2DwvQqgzcIJju0S8a50K6Q5kErMWzDJ/x0kWRrMFM28/r FZAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=o/YaK/1nN8qcf1AzcE5wUtvhy1Gtwd7ONGpBrfr+BrY=; b=C5qQfIbf6BcQ0J3YXfq+2hFByQMuLEyMBlI85+2Y7pujwM2weiAXrhUZqn9I9kAknV Mos6NyQHI9Xwv3TFb0wvlKhzY8qZVzt80sMkerHtgM534kr9+Kd3EUJ8Z0ih3qr9vDA3 hvK62UjKfNwpRVLga5h2AbkgM3G3+U5Cbu5V1ZFrQz4AdX82Hw3WN7XvcmFXm2hvf4JB j6y4Qn0p07PZ4JE9uU2bvrM6sGly167bOpFnbPF2yw71IxrErIMc2QpSyHOt5Zz1U8D0 q0sQ5hGWnaGQn0hYSUrVFmcSJ/UN2NWy92oJOsIt8rbCxJ6DaAYPNiDHZcVKXUfCfSco sGsw== 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=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p12si462637pgv.598.2018.04.17.07.49.08; Tue, 17 Apr 2018 07:49:22 -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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752765AbeDQOrq (ORCPT + 99 others); Tue, 17 Apr 2018 10:47:46 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:53546 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753348AbeDQOeE (ORCPT ); Tue, 17 Apr 2018 10:34:04 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3HEUu1F107398 for ; Tue, 17 Apr 2018 10:34:04 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hdjrh06vg-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Tue, 17 Apr 2018 10:34:02 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 17 Apr 2018 15:33:59 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 17 Apr 2018 15:33:50 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3HEXoeU49741974; Tue, 17 Apr 2018 14:33:50 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 17301A4053; Tue, 17 Apr 2018 15:25:59 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DF412A404D; Tue, 17 Apr 2018 15:25:56 +0100 (BST) Received: from nimbus.lab.toulouse-stg.fr.ibm.com (unknown [9.145.171.143]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 17 Apr 2018 15:25:56 +0100 (BST) From: Laurent Dufour To: 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 , 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 , David Rientjes , Jerome Glisse , Ganesh Mahendran Cc: 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, paulmck@linux.vnet.ibm.com, Tim Chen , linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: [PATCH v10 05/25] mm: introduce pte_spinlock for FAULT_FLAG_SPECULATIVE Date: Tue, 17 Apr 2018 16:33:11 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523975611-15978-1-git-send-email-ldufour@linux.vnet.ibm.com> References: <1523975611-15978-1-git-send-email-ldufour@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18041714-0040-0000-0000-0000044E8E46 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041714-0041-0000-0000-000020F2D705 Message-Id: <1523975611-15978-6-git-send-email-ldufour@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-04-17_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1804170131 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- mm/memory.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/mm/memory.c b/mm/memory.c index 4528bd584b7a..0b9a51f80e0e 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -2288,6 +2288,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, @@ -3804,8 +3811,8 @@ static int 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; @@ -3998,8 +4005,8 @@ static int 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.7.4