Received: by 10.223.176.5 with SMTP id f5csp1993435wra; Sun, 4 Feb 2018 17:40:51 -0800 (PST) X-Google-Smtp-Source: AH8x227EhX1TqCVFNs03A52FF9wMP+5D109A9xDZAgEo7Ckb5gDd5ZT6RX/OWDJItKR+D03D5XBC X-Received: by 2002:a17:902:9a97:: with SMTP id w23-v6mr43038987plp.100.1517794851725; Sun, 04 Feb 2018 17:40:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517794851; cv=none; d=google.com; s=arc-20160816; b=XCGDZQcgMpAiVzCRj/Ck/hHrkJLdWGC7T8yAtN3G6SWaPc1o9XP4slAsb+Lr7Uv1+2 HWmy5M51FP4WHC+hxW3fGgiZtRVvCs6Nok+ZpFoG6bjyUEqeko70QweYQe1hIV+ghnME lg6Qpb264Ebmu9zKEYKr8FrTjI18pRGyj7Lkr5l8+hhxGt1Y8E8LqWwjZ7JpOu3Z+Ria STsD7n9ixxCK11SB3BqX6JqTbzITOid4zW1UKXya9oKXnWs6psIMGwcxDS3wUXe/W5xw S+Ok0jSROTyyHKEoMMEpk0p4kYKXYVWRvK4tzLTPnbQK0op3VnFEt5wh/cZmn3r7LLBt ERVg== 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=hyXoPwK6iGCo8oufKDWbW3HBrYPI4MNRy8I1IJ1W9AQ=; b=BonN3VWbf2iDTGlztlq3/LtKoHHG0TDuHdmT3J50m4dt+wBExxlqaNbp4+UANS230O aDuB1OAXIQPS1+BAxkFlrUO0sOtGoZIpb3Hsw4pc7iNvrTNnrnhqEMfVX3T8kJ5PaqsK wLaKWw5DIj3BZwzBH42fPniMSUsbuVY8dXQeNuRA1nNuwLY9pHku7QQ13ifg/++pdwFm eClj8oObpSAid+humWThN2+z442tjFqmyPFStt8k/6jYz+msrc0sbMLzc6aTIalMLK1s pOX9cKESeTGE203v/mpVLS0O2aqaOZBanHC2hGlg87Der2nBLDPwMKd63A7GVmDyWbFb RPcg== 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 u18-v6si2759734plq.228.2018.02.04.17.40.37; Sun, 04 Feb 2018 17:40:51 -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 S1753049AbeBEBja (ORCPT + 99 others); Sun, 4 Feb 2018 20:39:30 -0500 Received: from mx2.suse.de ([195.135.220.15]:43681 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752675AbeBEB23 (ORCPT ); Sun, 4 Feb 2018 20:28:29 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 8CC68ADF9; 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 21/64] mm: teach drop/take_all_locks() about range locking Date: Mon, 5 Feb 2018 02:27:11 +0100 Message-Id: <20180205012754.23615-22-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 And use the mm locking helpers. No changes in semantics. Signed-off-by: Davidlohr Bueso --- include/linux/mm.h | 6 ++++-- mm/mmap.c | 12 +++++++----- mm/mmu_notifier.c | 9 +++++---- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index fc4e7fdc3e76..0b9867e8a35d 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2198,8 +2198,10 @@ static inline int check_data_rlimit(unsigned long rlim, return 0; } -extern int mm_take_all_locks(struct mm_struct *mm); -extern void mm_drop_all_locks(struct mm_struct *mm); +extern int mm_take_all_locks(struct mm_struct *mm, + struct range_lock *mmrange); +extern void mm_drop_all_locks(struct mm_struct *mm, + struct range_lock *mmrange); extern void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file); extern struct file *get_mm_exe_file(struct mm_struct *mm); diff --git a/mm/mmap.c b/mm/mmap.c index f61d49cb791e..8f0eb88a5d5e 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3461,12 +3461,13 @@ static void vm_lock_mapping(struct mm_struct *mm, struct address_space *mapping) * * mm_take_all_locks() can fail if it's interrupted by signals. */ -int mm_take_all_locks(struct mm_struct *mm) +int mm_take_all_locks(struct mm_struct *mm, + struct range_lock *mmrange) { struct vm_area_struct *vma; struct anon_vma_chain *avc; - BUG_ON(down_read_trylock(&mm->mmap_sem)); + BUG_ON(mm_read_trylock(mm, mmrange)); mutex_lock(&mm_all_locks_mutex); @@ -3497,7 +3498,7 @@ int mm_take_all_locks(struct mm_struct *mm) return 0; out_unlock: - mm_drop_all_locks(mm); + mm_drop_all_locks(mm, mmrange); return -EINTR; } @@ -3541,12 +3542,13 @@ static void vm_unlock_mapping(struct address_space *mapping) * The mmap_sem cannot be released by the caller until * mm_drop_all_locks() returns. */ -void mm_drop_all_locks(struct mm_struct *mm) +void mm_drop_all_locks(struct mm_struct *mm, + struct range_lock *mmrange) { struct vm_area_struct *vma; struct anon_vma_chain *avc; - BUG_ON(down_read_trylock(&mm->mmap_sem)); + BUG_ON(mm_read_trylock(mm, mmrange)); BUG_ON(!mutex_is_locked(&mm_all_locks_mutex)); for (vma = mm->mmap; vma; vma = vma->vm_next) { diff --git a/mm/mmu_notifier.c b/mm/mmu_notifier.c index 3e8a1a10607e..da99c01b8149 100644 --- a/mm/mmu_notifier.c +++ b/mm/mmu_notifier.c @@ -274,6 +274,7 @@ static int do_mmu_notifier_register(struct mmu_notifier *mn, { struct mmu_notifier_mm *mmu_notifier_mm; int ret; + DEFINE_RANGE_LOCK_FULL(mmrange); BUG_ON(atomic_read(&mm->mm_users) <= 0); @@ -283,8 +284,8 @@ static int do_mmu_notifier_register(struct mmu_notifier *mn, goto out; if (take_mmap_sem) - down_write(&mm->mmap_sem); - ret = mm_take_all_locks(mm); + mm_write_lock(mm, &mmrange); + ret = mm_take_all_locks(mm, &mmrange); if (unlikely(ret)) goto out_clean; @@ -309,10 +310,10 @@ static int do_mmu_notifier_register(struct mmu_notifier *mn, hlist_add_head(&mn->hlist, &mm->mmu_notifier_mm->list); spin_unlock(&mm->mmu_notifier_mm->lock); - mm_drop_all_locks(mm); + mm_drop_all_locks(mm, &mmrange); out_clean: if (take_mmap_sem) - up_write(&mm->mmap_sem); + mm_write_unlock(mm, &mmrange); kfree(mmu_notifier_mm); out: BUG_ON(atomic_read(&mm->mm_users) <= 0); -- 2.13.6