Received: by 10.213.65.68 with SMTP id h4csp503668imn; Tue, 13 Mar 2018 11:06:24 -0700 (PDT) X-Google-Smtp-Source: AG47ELvABHdAN64TYCR9XYvEMzCYVugTC5oCmov33Dqaj/s15aW9ADeAaYmcN7MrBM60z1kyqA41 X-Received: by 10.99.114.27 with SMTP id n27mr1167873pgc.177.1520964384876; Tue, 13 Mar 2018 11:06:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1520964384; cv=none; d=google.com; s=arc-20160816; b=omzmb2FCUs9Trk5Cw4RtdcU7DGfwXU0vKmTuZQ1r3md09KmpcJezFH7N0bmwB0hSMB m87ZJov/ad6XNrZntqDJknXVhtEHg52ntLsa2I1bhyzP95tjEsylqvbcczSaxDxLcDLp AY1k+G1d70n6i96bPITQ2zqu8mxEG1dR0+K1PWhrMxHZh3PbHKvk5AOVktmORWQ0U2l0 6V1VSxmcsj/96VlXFb2NwZhnwegiMx1bh+a1MqYyXCn/1Uba1CHLKwudA4ZGUZoZsCTk HEi2S2QS4LE3/htlt1U/XPMOON6wbHu+373SkBpCKA5OVokykR0wmDWhQn/cNUhvSyLE ivXw== 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=EcaqFEUQIlxTA9sHWqjkMEqgf0TpdyaNzuBfTqB6keM=; b=vW75xLLyWRDCeTmCeklITjBBFthvnc0sgtVGAeG+1qstlVuANQa+J2rgVBty4Sn4jj E5HdB9oxP1WGxbdwWXtdRTZqyEuwOGhEkNgB40i1xkA2XfUXJV7Bgzugn/SOQL627FSs VpSwwW8bD6YXNh9t1eSzGg4e056GmAt6bjJKNmTaPxf7pXNipYdPfpgHu0bKOreetDm+ 7rO9el+JyU4n7sVGMOnzNBhZMVrYYAOM3IqJDOlSMEnPxUSHun47Pmq0uGssamZkivad pckG7hvd+e9sAOQnoB0IDtVHP3OTMrsdU5jz+BOP9t63reSVTcvN5+XUxbV5ZWgAKzPX xPZQ== 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 q18si538447pfi.105.2018.03.13.11.06.09; Tue, 13 Mar 2018 11:06:24 -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 S1752668AbeCMSAe (ORCPT + 99 others); Tue, 13 Mar 2018 14:00:34 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:48046 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752451AbeCMSAa (ORCPT ); Tue, 13 Mar 2018 14:00:30 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2DHsLiL041438 for ; Tue, 13 Mar 2018 14:00:29 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gpj5ckmp8-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Tue, 13 Mar 2018 14:00:28 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 13 Mar 2018 18:00:26 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 13 Mar 2018 18:00:18 -0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2DI0IxS46465104; Tue, 13 Mar 2018 18:00:18 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 33D1A4204B; Tue, 13 Mar 2018 17:52:34 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 19A1A42041; Tue, 13 Mar 2018 17:52:33 +0000 (GMT) Received: from nimbus.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.33]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 13 Mar 2018 17:52:33 +0000 (GMT) From: Laurent Dufour To: 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 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, Tim Chen , linuxppc-dev@lists.ozlabs.org, x86@kernel.org Subject: [PATCH v9 10/24] mm: Protect SPF handler against anon_vma changes Date: Tue, 13 Mar 2018 18:59:40 +0100 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1520963994-28477-1-git-send-email-ldufour@linux.vnet.ibm.com> References: <1520963994-28477-1-git-send-email-ldufour@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18031318-0008-0000-0000-000004DD0192 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18031318-0009-0000-0000-00001E700184 Message-Id: <1520963994-28477-11-git-send-email-ldufour@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-03-13_08:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 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-1803130203 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The speculative page fault handler must be protected against anon_vma changes. This is because page_add_new_anon_rmap() is called during the speculative path. In addition, don't try speculative page fault if the VMA don't have an anon_vma structure allocated because its allocation should be protected by the mmap_sem. In __vma_adjust() when importer->anon_vma is set, there is no need to protect against speculative page faults since speculative page fault is aborted if the vma->anon_vma is not set. When calling page_add_new_anon_rmap() vma->anon_vma is necessarily valid since we checked for it when locking the pte and the anon_vma is removed once the pte is unlocked. So even if the speculative page fault handler is running concurrently with do_unmap(), as the pte is locked in unmap_region() - through unmap_vmas() - and the anon_vma unlinked later, because we check for the vma sequence counter which is updated in unmap_page_range() before locking the pte, and then in free_pgtables() so when locking the pte the change will be detected. Signed-off-by: Laurent Dufour --- mm/memory.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index d57749966fb8..0200340ef089 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -624,7 +624,9 @@ void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *vma, * Hide vma from rmap and truncate_pagecache before freeing * pgtables */ + vm_write_begin(vma); unlink_anon_vmas(vma); + vm_write_end(vma); unlink_file_vma(vma); if (is_vm_hugetlb_page(vma)) { @@ -638,7 +640,9 @@ void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *vma, && !is_vm_hugetlb_page(next)) { vma = next; next = vma->vm_next; + vm_write_begin(vma); unlink_anon_vmas(vma); + vm_write_end(vma); unlink_file_vma(vma); } free_pgd_range(tlb, addr, vma->vm_end, -- 2.7.4