From patchwork Thu Aug 9 23:36:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 10562137 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9D08D13BB for ; Thu, 9 Aug 2018 23:36:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89006289DD for ; Thu, 9 Aug 2018 23:36:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B5842BB3A; Thu, 9 Aug 2018 23:36:56 +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,UNPARSEABLE_RELAY 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 D8AC4289DD for ; Thu, 9 Aug 2018 23:36:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE3976B000D; Thu, 9 Aug 2018 19:36:54 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id E91776B0010; Thu, 9 Aug 2018 19:36:54 -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 D82CC6B0266; Thu, 9 Aug 2018 19:36:54 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pl0-f71.google.com (mail-pl0-f71.google.com [209.85.160.71]) by kanga.kvack.org (Postfix) with ESMTP id 97A746B000D for ; Thu, 9 Aug 2018 19:36:54 -0400 (EDT) Received: by mail-pl0-f71.google.com with SMTP id j1-v6so4553675pld.23 for ; Thu, 09 Aug 2018 16:36:54 -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:message-id:in-reply-to:references; bh=SieF3IXAtGzjYc0c9H6/bJPFf5KkOkiCZmqBBgLq4E8=; b=MynHFXDxYrhZmtD3ckvhbQ6DGam/9/GFEa9tfCYEA8d7YYpdOz+DLx32ESvcGtq7vS luUAlzyGlczsgDtWG9XfEaZ2ltwAzydQ3IitnfjND9u+Bq5mRjinPqB5orcajzSqk1YD hXqS3MurnnTF6DxV8nj0brLo5Ay3I+vrtsBMu6GgI/OlVLPPJTXcEbZthtBIMN3Rm6op zfdovRedU4pMnuowtB35v2iCyEQKkhoTfOfC1RBNgQ+W/7yufPFtYGh2yhnKFq3l4UfH x6zBWTy0OLPZb7xix1Q6CbZGVqZ0OrMZemtqovSGzrRPWnrvRMldWWNWsOBFfAAEH3Ix 8XiQ== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Gm-Message-State: AOUpUlF2LLs8WZO9H+GR6V2dkVmxi7mQLZJaOkMx9uJpEwdPfCrhadPQ Zd5ni/1V8ghn5bv2mp8RxBSDFgckXUXRMXdQDUL5e+SDaV7RMbosxRFTFNMZbCrE0zqo7vca3ZT BB3fySwfSXnxiQa87xYzS6Wr695ohmQO6WB9lHNl1dvQMQtkbG+XHpBOVeMxndeY1/Q== X-Received: by 2002:a62:6746:: with SMTP id b67-v6mr4360832pfc.243.1533857814287; Thu, 09 Aug 2018 16:36:54 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwO7VPYiZjkeIqNz3CNQpGYOdlzKLZ5/gBHNeahWgJXFZcvHwfrYLYcYrJIZNXyjYYOYJNN X-Received: by 2002:a62:6746:: with SMTP id b67-v6mr4360797pfc.243.1533857813195; Thu, 09 Aug 2018 16:36:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533857813; cv=none; d=google.com; s=arc-20160816; b=hpn7BNIKiFQJZDoPta68bf32UEtxlzFOD+8kgPNgbfgwdRBPGCXl6fCKMjm+O8sslQ TpxnSwqUDQ24TAUxzMyeoFKbFGlG5VidGktCUhXSoGRz7vofmKQ5vLdn+3YipeOwbC1x 639BRzGFedQZtkRLHSlXVEbjSCsA5lnn4CFVvkh9yoWoIobPdLe7fUGOgeSkLLO2EHPg Z3TNBu5dcYDSwINI8lo4XrvsB1j2P5G/gtgfAFYa4EPMrtsmfZReA+e1tAMnNBalqqTz ZNjgZwZZ3fPhih70dZwL2VN5ThxsCabf3H6EdDUWJHPBfXcTIOE4kBk77k1Nv2AwCLjN cGjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=SieF3IXAtGzjYc0c9H6/bJPFf5KkOkiCZmqBBgLq4E8=; b=OVBoGrSRDOfub4Godt5yZHLdRhbD7ktCjk9Pfx/sgGSB2e6dyN8IJEBpwFS7Zj+tn5 eJkkSaFcpA6WO3iI+yQkOUh+xHb0Gi4e1Y/JjyTCyTwBdBMGBz8mFiYGjvhPSKsvwTA/ YXqTDajUSdgN9GX8a2e66mm8evgg/8TWDmV3RO1vULwo70PjuAwoP5iEKxPJUcMOBeBC gF+2ZzHRX/aOr30F0e6GmSFenk9HHf+q+xmMG0VoalDiA+6UeMKTcFimJoaqP/TF9+KV sR/KU77fXkGkQ1bxcHuvSlyWxTsNrkexMX6Y8reQRhPGrjG28M5Kha4CJVdPlWXda86I RxzQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: from out4436.biz.mail.alibaba.com (out4436.biz.mail.alibaba.com. [47.88.44.36]) by mx.google.com with ESMTPS id g27-v6si8502766pgm.208.2018.08.09.16.36.51 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Aug 2018 16:36:53 -0700 (PDT) Received-SPF: pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) client-ip=47.88.44.36; Authentication-Results: mx.google.com; spf=pass (google.com: domain of yang.shi@linux.alibaba.com designates 47.88.44.36 as permitted sender) smtp.mailfrom=yang.shi@linux.alibaba.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=alibaba.com X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e01422;MF=yang.shi@linux.alibaba.com;NM=1;PH=DS;RN=15;SR=0;TI=SMTPD_---0T6MWc.W_1533857777; Received: from e19h19392.et15sqa.tbsite.net(mailfrom:yang.shi@linux.alibaba.com fp:SMTPD_---0T6MWc.W_1533857777) by smtp.aliyun-inc.com(127.0.0.1); Fri, 10 Aug 2018 07:36:27 +0800 From: Yang Shi To: mhocko@kernel.org, willy@infradead.org, ldufour@linux.vnet.ibm.com, kirill@shutemov.name, vbabka@suse.cz, akpm@linux-foundation.org, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, alexander.shishkin@linux.intel.com, jolsa@redhat.com, namhyung@kernel.org Cc: yang.shi@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC v7 PATCH 4/4] mm: unmap special vmas with regular do_munmap() Date: Fri, 10 Aug 2018 07:36:03 +0800 Message-Id: <1533857763-43527-5-git-send-email-yang.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1533857763-43527-1-git-send-email-yang.shi@linux.alibaba.com> References: <1533857763-43527-1-git-send-email-yang.shi@linux.alibaba.com> 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 Unmapping vmas, which have VM_HUGETLB | VM_PFNMAP flag set or have uprobes set, need get done with write mmap_sem held since they may update vm_flags. So, it might be not safe enough to deal with these kind of special mappings with read mmap_sem. Deal with such mappings with regular do_munmap() call. Michal suggested to make this as a separate patch for safer and more bisectable sake. Cc: Michal Hocko Signed-off-by: Yang Shi --- mm/mmap.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/mm/mmap.c b/mm/mmap.c index 2234d5a..06cb83c 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -2766,6 +2766,16 @@ static inline void munlock_vmas(struct vm_area_struct *vma, } } +static inline bool can_zap_with_rlock(struct vm_area_struct *vma) +{ + if ((vma->vm_file && + vma_has_uprobes(vma, vma->vm_start, vma->vm_end)) || + (vma->vm_flags | (VM_HUGETLB | VM_PFNMAP))) + return false; + + return true; +} + /* * Zap pages with read mmap_sem held * @@ -2808,6 +2818,17 @@ static int do_munmap_zap_rlock(struct mm_struct *mm, unsigned long start, goto out; } + /* + * Unmapping vmas, which have VM_HUGETLB | VM_PFNMAP flag set or + * have uprobes set, need get done with write mmap_sem held since + * they may update vm_flags. Deal with such mappings with regular + * do_munmap() call. + */ + for (vma = start_vma; vma && vma->vm_start < end; vma = vma->vm_next) { + if (!can_zap_with_rlock(vma)) + goto regular_path; + } + /* Handle mlocked vmas */ if (mm->locked_vm) { vma = start_vma; @@ -2828,6 +2849,9 @@ static int do_munmap_zap_rlock(struct mm_struct *mm, unsigned long start, return 0; +regular_path: + ret = do_munmap(mm, start, len, uf); + out: up_write(&mm->mmap_sem); return ret;