Received: by 10.223.176.5 with SMTP id f5csp1994906wra; Sun, 4 Feb 2018 17:43:39 -0800 (PST) X-Google-Smtp-Source: AH8x227Zw2kbId/ou6razl0iFePusal/yBUNOOXGhXm1o2p3vy08oFKp5YzLOlJfuGrAUGTqMJhw X-Received: by 2002:a17:902:4324:: with SMTP id i33-v6mr5793342pld.39.1517795019069; Sun, 04 Feb 2018 17:43:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517795019; cv=none; d=google.com; s=arc-20160816; b=urBNGVW+B8bL0V0qA/8PI/0MgbEPPZzVpuulihzmOkGs+leBGD2Q7IEgmR+2Uf/45Q ay4oJY5XzdNxedW63TIzYhSF34AY4z2D90vbSkTodVF9hP/dgjAsCMhZdGBGgcPUmuDE kAL2Tpr7Nx4QRBq3FeukJjdYk+AnX8iKoNeyVsdjOmJKU+C9QE975EvxPKXwOfQhn4dd nKlK+G400poUSpdt2pOSBg9hFs+uMT2ecxjBGspaSq5+MA/MChh6GbFwZv3gGHUYwHIo n3i+cMCrAss3AMzf5r2nz5pwcQyfPxRyqPFuGBZdWys2o/BhSib/7g7AOmQ0GFnf5i8B VENg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=9WZZbLYklgcotXEMz0TUAwYR0lUDCir73jkP7TeuxZw=; b=g/OtK/lAjSBBSITzThs44qqbp00ocP9g9yCV1LOWYDEOO2OOwFUDWxpaDXhpQDG1l3 4jAt3zjri+ab0vEMH1/zpw9p0j4gR2ev6MAGsVf0mhxAZVBi6CsoRTw7RiuocFhbmcU2 /YODOVlBSdW3wnuKeHDG+ZR2kP5PNC2cmAmCDMyJzGuP8T68M7G8hSbHDGj7jPSs2kC/ xNGkvStX7sdgcRYCEXall/bsrHQ6e9D8+eN8oXFWClst9IKkQ2ZR6yDtEfXTzvbG0Q9W O9s6B0U5ccT3KGXGIOPGMpoJBRZSpVOxrqqv5g1Jg84y3g6EZCOFaUJh2ZeZj9vrlSIF ss6w== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o16si3253764pgd.125.2018.02.04.17.43.24; Sun, 04 Feb 2018 17:43:39 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752775AbeBEBlM (ORCPT + 99 others); Sun, 4 Feb 2018 20:41:12 -0500 Received: from mx2.suse.de ([195.135.220.15]:43458 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752654AbeBEB22 (ORCPT ); Sun, 4 Feb 2018 20:28:28 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6BA25ADF2; Mon, 5 Feb 2018 01:28:00 +0000 (UTC) From: Davidlohr Bueso To: akpm@linux-foundation.org, mingo@kernel.org Cc: peterz@infradead.org, ldufour@linux.vnet.ibm.com, jack@suse.cz, mhocko@kernel.org, kirill.shutemov@linux.intel.com, mawilcox@microsoft.com, mgorman@techsingularity.net, dave@stgolabs.net, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: [PATCH 20/64] mm/madvise: use mm locking wrappers Date: Mon, 5 Feb 2018 02:27:10 +0100 Message-Id: <20180205012754.23615-21-dbueso@wotan.suse.de> X-Mailer: git-send-email 2.12.3 In-Reply-To: <20180205012754.23615-1-dbueso@wotan.suse.de> References: <20180205012754.23615-1-dbueso@wotan.suse.de> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Davidlohr Bueso mmap_sem users are already aware of mmrange, thus a straightforward conversion. No changes in semantics. Signed-off-by: Davidlohr Bueso --- mm/madvise.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index eaec6bfc2b08..de8fb035955c 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -532,7 +532,7 @@ static long madvise_dontneed_free(struct vm_area_struct *vma, if (!userfaultfd_remove(vma, start, end)) { *prev = NULL; /* mmap_sem has been dropped, prev is stale */ - down_read(¤t->mm->mmap_sem); + mm_read_lock(current->mm, mmrange); vma = find_vma(current->mm, start); if (!vma) return -ENOMEM; @@ -582,7 +582,8 @@ static long madvise_dontneed_free(struct vm_area_struct *vma, */ static long madvise_remove(struct vm_area_struct *vma, struct vm_area_struct **prev, - unsigned long start, unsigned long end) + unsigned long start, unsigned long end, + struct range_lock *mmrange) { loff_t offset; int error; @@ -614,13 +615,13 @@ static long madvise_remove(struct vm_area_struct *vma, get_file(f); if (userfaultfd_remove(vma, start, end)) { /* mmap_sem was not released by userfaultfd_remove() */ - up_read(¤t->mm->mmap_sem); + mm_read_unlock(current->mm, mmrange); } error = vfs_fallocate(f, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, offset, end - start); fput(f); - down_read(¤t->mm->mmap_sem); + mm_read_lock(current->mm, mmrange); return error; } @@ -690,7 +691,7 @@ madvise_vma(struct vm_area_struct *vma, struct vm_area_struct **prev, { switch (behavior) { case MADV_REMOVE: - return madvise_remove(vma, prev, start, end); + return madvise_remove(vma, prev, start, end, mmrange); case MADV_WILLNEED: return madvise_willneed(vma, prev, start, end, mmrange); case MADV_FREE: @@ -809,6 +810,7 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) int write; size_t len; struct blk_plug plug; + DEFINE_RANGE_LOCK_FULL(mmrange); if (!madvise_behavior_valid(behavior)) return error; @@ -836,10 +838,10 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) write = madvise_need_mmap_write(behavior); if (write) { - if (down_write_killable(¤t->mm->mmap_sem)) + if (mm_write_lock_killable(current->mm, &mmrange)) return -EINTR; } else { - down_read(¤t->mm->mmap_sem); + mm_read_lock(current->mm, &mmrange); } /* @@ -889,9 +891,9 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) out: blk_finish_plug(&plug); if (write) - up_write(¤t->mm->mmap_sem); + mm_write_unlock(current->mm, &mmrange); else - up_read(¤t->mm->mmap_sem); + mm_read_unlock(current->mm, &mmrange); return error; } -- 2.13.6