From patchwork Thu May 17 11:06:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Dufour X-Patchwork-Id: 10406425 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CD92C60247 for ; Thu, 17 May 2018 11:08:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD52928859 for ; Thu, 17 May 2018 11:08:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B136A2886D; Thu, 17 May 2018 11:08:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 281FA28887 for ; Thu, 17 May 2018 11:08:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 148726B04C3; Thu, 17 May 2018 07:07:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0AC956B04C4; Thu, 17 May 2018 07:07:43 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E44BC6B04C5; Thu, 17 May 2018 07:07:42 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-wr0-f200.google.com (mail-wr0-f200.google.com [209.85.128.200]) by kanga.kvack.org (Postfix) with ESMTP id 7EE476B04C3 for ; Thu, 17 May 2018 07:07:42 -0400 (EDT) Received: by mail-wr0-f200.google.com with SMTP id p14-v6so2792875wre.21 for ; Thu, 17 May 2018 04:07:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:in-reply-to:references:message-id; bh=ByIm54ljWX/DQhJMrCKKAWxURuJyds85KCY7dCd/XLs=; b=kXM7tJ2AK07YunVT5CgY+smdBrutPm1jxaq4bMNOaQHGswpC76LvPwMgDUHG9k1Rhv j0PkyMY7TgDiauvcQpr/VBS6EgHrLzLBtLSQqay/kR3lGHFZX3xHL4eFa8MGVXM3W8wf /xQry2Q+It3tVt8VYqBCwneA4FKyvuu8qn6P5oKbI0AAwdftihEo53uL8oBVqZ0g8/hT avVZcJ7gcdB/WuU9dtehK96GiLzXSKGjy4cyeof/bef/sPMmwjS38qe7eXTSzC4w6imW nQNRL160jaB5shmWk+PcrckogkFwvKeJeBpFOGMaf49olqWY0qvFd5YfkMooJxLxRcoj IW1g== X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 148.163.158.5 is neither permitted nor denied by best guess record for domain of ldufour@linux.vnet.ibm.com) smtp.mailfrom=ldufour@linux.vnet.ibm.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com X-Gm-Message-State: ALKqPwfm+svAgSSVhikMiq9D+NyUckjT5Z5kFCnpwa2bSCmqsz2unFXm y6Q/c1PfauW1eoBN9zdLj3oOsYfLLgqkYLe7inA+i7wC9Rphlu+QDmryn4PHcNOeZGXpzcp4qNe edXopWhW+15awbglWBYTPrNQ4TGbRVRYOJlkJpaJvZSOyqtTIZBUbybZb5fNodeY= X-Received: by 2002:a50:ad69:: with SMTP id z38-v6mr6476452edc.306.1526555262071; Thu, 17 May 2018 04:07:42 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo2iholkqEgPQWbMl6g+CRbYSpd0esDPTnjuNoOhHB24w5oieaumgrosxHK/Ift1JLGzfFo X-Received: by 2002:a50:ad69:: with SMTP id z38-v6mr6476374edc.306.1526555261097; Thu, 17 May 2018 04:07:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526555261; cv=none; d=google.com; s=arc-20160816; b=fHWaPO299bFM0VEANMKo67XhGRlRHGmIeISbQv7YSyjDG4c44AjaICPdLxePgsqPc4 wxguz7r+pkX9YDnWZnPz1pu2vz8z1bYpw+JIEhJQK5D1z7tW9m8GP1/YL5gaWPlHS286 eskFlEGvCdTDIiROEz2/bCpdLcmDelDtFW/21faoescsIUTAQJB4wfSu46CAHocPiWVG KPz8kNUK70AozFsEpvBZ7/VYBmyY6iuQp3U8nLIgkkMbwZGE2EO7FivcMt59FtcCnYOh WNYJs7TZo8aw0kAl2jbZwEbz1oK46ywLMmOic4qyfhyjXMfSXA5y6cwUUdjlOObuQnin hz1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:references:in-reply-to:date:subject:cc:to:from :arc-authentication-results; bh=ByIm54ljWX/DQhJMrCKKAWxURuJyds85KCY7dCd/XLs=; b=XY7FBitx0qkZ5oXe7yJm3EKyCG0Wew7D14XZTMMfY6mkcneXn2bTZssMKd2sv9txVB EwsMzTXkSBR9DSmmJ76uW9qPwcuSBacAa5znElXdswBvWrAadTaa6z9S6ZNCZT5/oUhA EuVmDqqsmmThFOzRVN2dfPpAgKfyPjo+ka+ORnwkl+5SL50LhafIQX2F13vDXNM5Ned7 eZ4RqqWT/Ni4gv3Vj/JqDZT/G6/+8hWvCy2rKfyp0NwybIDMohiF3pHpAes4/oyK38cT goohu+VZbz9awaE2NywJe/cF5DkdAYkDfV1Bg+Y5hSkgI3t/OTJiYktDDZKpHJOW7ld/ b3Jw== ARC-Authentication-Results: i=1; mx.google.com; spf=neutral (google.com: 148.163.158.5 is neither permitted nor denied by best guess record for domain of ldufour@linux.vnet.ibm.com) smtp.mailfrom=ldufour@linux.vnet.ibm.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com. [148.163.158.5]) by mx.google.com with ESMTPS id o90-v6si4947510eda.128.2018.05.17.04.07.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 May 2018 04:07:41 -0700 (PDT) Received-SPF: neutral (google.com: 148.163.158.5 is neither permitted nor denied by best guess record for domain of ldufour@linux.vnet.ibm.com) client-ip=148.163.158.5; Authentication-Results: mx.google.com; spf=neutral (google.com: 148.163.158.5 is neither permitted nor denied by best guess record for domain of ldufour@linux.vnet.ibm.com) smtp.mailfrom=ldufour@linux.vnet.ibm.com; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w4HB4XqO179646 for ; Thu, 17 May 2018 07:07:39 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0b-001b2d01.pphosted.com with ESMTP id 2j157622ga-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 17 May 2018 07:07:39 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 17 May 2018 12:07:11 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 17 May 2018 12:07:04 +0100 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w4HB73IX4063610 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 17 May 2018 11:07:03 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D22774C063; Thu, 17 May 2018 11:58:51 +0100 (BST) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 994724C05A; Thu, 17 May 2018 11:58:50 +0100 (BST) Received: from nimbus.lab.toulouse-stg.fr.ibm.com (unknown [9.101.4.33]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 17 May 2018 11:58:50 +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 , khandual@linux.vnet.ibm.com, aneesh.kumar@linux.vnet.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 , Jerome Glisse , Ganesh Mahendran , Minchan Kim , Punit Agrawal , vinayak menon , Yang Shi Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, haren@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 v11 12/26] mm: protect SPF handler against anon_vma changes Date: Thu, 17 May 2018 13:06:19 +0200 X-Mailer: git-send-email 2.7.4 In-Reply-To: <1526555193-7242-1-git-send-email-ldufour@linux.vnet.ibm.com> References: <1526555193-7242-1-git-send-email-ldufour@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 18051711-0044-0000-0000-000005537517 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18051711-0045-0000-0000-00002894E8F2 Message-Id: <1526555193-7242-13-git-send-email-ldufour@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-05-17_05:, , 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-1805170100 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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 551a1916da5d..d0b5f14cfe69 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,