Received: by 10.223.185.116 with SMTP id b49csp1039088wrg; Fri, 16 Feb 2018 11:16:32 -0800 (PST) X-Google-Smtp-Source: AH8x224CaKrLFHwQEKOXFnJoPnHbBSWquY4VLZ9NrTWhG7glsWiTGXlahIakcpQnkHsCIg8lZoRB X-Received: by 10.99.140.70 with SMTP id q6mr5819036pgn.51.1518808592529; Fri, 16 Feb 2018 11:16:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518808592; cv=none; d=google.com; s=arc-20160816; b=D5Qj/AtPHLHi4YNiSGr4mENAjF0042DwQxhgVsvpBxg8r8RahBs6WUy2xYR+WgLVKp dxnTFbE/dxY2iS42KQSqKLET8wHUkQ2MQfEGQV/hTMlIOND0ueWScL/tb5xBoDFXr2Sj mkO4MKsLtqWEG6cQn+EzObI3uOQtxJ49xwCG3lm1JUjBq3wco+cIaIIQG1t4VblO04gj PQofbEz1JnLTmO/DgcHnl8P3dgTn4ut6kVfVndS8gyG4G/xKAlUakSR08xw34y03XztB 2Mm5OfjKeFZqPEIAYwksbvbny+pcDe44kfRC26q/yRm7jx8RHWFr3UuAHQbWak2RTqaK y5jA== 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=5oc7MuQSvb3iQo1oSa6kXdgDizCQc3uiMbkn/N3sPPU=; b=q42TKx/R5iKiMlFzKsw8AVyWmdTt1t4ipwGZqrdCiVbXD6bX1D7pzdcOzRSWDFsh3i Px/69kb53U8bNAjkz/6hGBOv6/Wpu24ettUP7iAi3vP/pzKAR2ignQn94jioDRY97NUH U2WzfV0ISgR7yKIr6R3VCoMaC5ossXnrMDZtHciKruae/zqcpEQDJT0ZNorvCIFey6on 3JUG+2nSV2Kb1mU+VmZKHfG+GLmgwPxVUp5qLQITDSk/3Qd+5Wmwb+jr6jqOxQgkAkRb kRVBJ1nIx+7TuBBxi0nwioi5SuYvAbKXfhto/XWxCCTIoRZLEi6iMSl595H8PBljSOpq aoBg== 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 q76si456857pfj.189.2018.02.16.11.16.18; Fri, 16 Feb 2018 11:16:32 -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; 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 S1755805AbeBPP0c (ORCPT + 99 others); Fri, 16 Feb 2018 10:26:32 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:35318 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755387AbeBPP02 (ORCPT ); Fri, 16 Feb 2018 10:26:28 -0500 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w1GFOEqD078195 for ; Fri, 16 Feb 2018 10:26:28 -0500 Received: from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com [195.75.94.111]) by mx0a-001b2d01.pphosted.com with ESMTP id 2g61dm9fac-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 16 Feb 2018 10:26:26 -0500 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 16 Feb 2018 15:26:24 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 16 Feb 2018 15:26:15 -0000 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w1GFQF3Y44171326; Fri, 16 Feb 2018 15:26:15 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 191C142049; Fri, 16 Feb 2018 15:18:59 +0000 (GMT) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0C3E442041; Fri, 16 Feb 2018 15:18:57 +0000 (GMT) Received: from nimbus.lab.toulouse-stg.fr.ibm.com (unknown [9.145.186.2]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 16 Feb 2018 15:18:56 +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 v8 10/24] mm: Protect SPF handler against anon_vma changes Date: Fri, 16 Feb 2018 16:25:24 +0100 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518794738-4186-1-git-send-email-ldufour@linux.vnet.ibm.com> References: <1518794738-4186-1-git-send-email-ldufour@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18021615-0020-0000-0000-000003F8814F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18021615-0021-0000-0000-0000428C8545 Message-Id: <1518794738-4186-11-git-send-email-ldufour@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2018-02-16_06:,, 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-1802160183 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 3cc1a13417cf..e37af9af4202 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