Received: by 10.192.165.156 with SMTP id m28csp138562imm; Tue, 17 Apr 2018 07:46:46 -0700 (PDT) X-Google-Smtp-Source: AIpwx48SgbaeIrxtiaqcwQf7Eb5Suf8NfSm1PazP+HWYnwW883WgDzcc4VbkRP1uHjxJCxpDaIUQ X-Received: by 10.99.149.10 with SMTP id p10mr2001123pgd.217.1523976406550; Tue, 17 Apr 2018 07:46:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523976406; cv=none; d=google.com; s=arc-20160816; b=hY+T6iQPD/dQGf2UimL792H5alKw1+OIhNLCGzxGIP0do1SjmSk5DqpCx6klMsOdOd eE/7yJDHxIYpgvZ4L8d1a8nHICZfa5b3ku7udxBWfr9qzaJXFjxyQtWWesVsBI93Zb7+ f/q2ADMCUIFy7GHTUkiUx5wnWlCF04PlPD60C8H0wPpTZNSWStmRRkHK63bcopJe9XtO iE98c2lAFFiGSL1y5tixrhiH1LrcM88SnAdLD64sCOhiJTeMfFgax1pP2of0TQcUUNLH /AIpVc2lz7AAizD+5mL+JeLHz/y19yxim2mP/NgfU5WisBcAYuNwmUbDxcv3t0RUqzC9 R/4Q== 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=z/Y1QohqA1extWdr8PuVH0mI2rhSF1D/bRVKszuN/9A=; b=hykq8arnbJAbzji0Z0GOee9UjtmY4VSBH4HWzn+hzyw7zC2fcI8B5isoHzJ+pc6mne GVNVGuYW+f1I1TFzQVp1hWiUyS3ygAGPuZHNz0e+Jny2KAmuN5qTGCWuCXWepR2DZnM9 2NWZch3elxzxd3RsHbkXgwcsQ2FKObhCpMRHw2vg0gNjeD7vYwcrPYsUIeOyHkaheZk1 IuLp1HVQzX2LzlXea5EDZdcaiWtkcCUdNsfnvgiU+uyGxulNDc23zHZtC8yEhpkGfV9d NKe2VttGaR13YM6eoGWcPdkBC96inqxQ7IGqtFVQNdALrZLsjZPmOf4WqimlOjBIMEcj 98fw== 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 t25si2337797pfh.101.2018.04.17.07.46.32; Tue, 17 Apr 2018 07:46: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=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752992AbeDQOo5 (ORCPT + 99 others); Tue, 17 Apr 2018 10:44:57 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:34428 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752790AbeDQOeV (ORCPT ); Tue, 17 Apr 2018 10:34:21 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w3HEWNvW130893 for ; Tue, 17 Apr 2018 10:34:21 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2hdhtduq6y-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Tue, 17 Apr 2018 10:34:20 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 17 Apr 2018 15:34:18 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 17 Apr 2018 15:34:10 +0100 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w3HEY9g348169064; Tue, 17 Apr 2018 14:34:09 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8948CA4053; Tue, 17 Apr 2018 15:26:18 +0100 (BST) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6847DA4051; Tue, 17 Apr 2018 15:26:16 +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:26:16 +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 11/25] mm: protect SPF handler against anon_vma changes Date: Tue, 17 Apr 2018 16:33:17 +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-0008-0000-0000-000004EC506F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18041714-0009-0000-0000-00001E80552F Message-Id: <1523975611-15978-12-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=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-1804170131 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 f7fed053df80..f76f5027d251 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