Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp186674ybg; Sun, 26 Jul 2020 01:06:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyPtWbu/2rJadHP36OEdufH3p6PYLsYkeUsqND3YqP7b20n0co2n8LkV9JJVWNIc6aiAJCX X-Received: by 2002:aa7:da4c:: with SMTP id w12mr15902797eds.122.1595750769492; Sun, 26 Jul 2020 01:06:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595750769; cv=none; d=google.com; s=arc-20160816; b=ShvYIiABXUptqb6Ju3kQ/SSewP4yoXp+XeO9nTsx+qhjvtRmITqXFAKa2eBhCmIag+ rYYNli9mf0BaHfbIRhgJDUlMVJdhlRQsnndRjloCEn6WhVSpm1pq9/B5MJmITmwrCS3m RQM30igwhNJ3HMJlSRUF5G+DFpCu8CyNOLDzMN/H3MgiWCbKPhhcNSx2YKd3jPcAI4O+ ZrcNnvLU1Dg9+2xN0MHTmcPp5tCVGtu7zC5eo5bS17iWgyUBjJhl9zAe0XB+ARXC4Hqv W+zdOsK8FMo/fZNZwVUhfo161DWJJGYPtB3MUfIE0YT5uDleOHoVYzutVtWBaFiiUN00 /5UA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=uA4FQsrIkLRkdrCG3z83PWBMBXkGDTH2tmffqjEZvWE=; b=KZjbkbz2vhV/nNZPE0IcHUsMmrmhEw5HYCPNS+FcVAbbyrzGSsJB9GPAbBQoYzZ6II TofSoST4fkxHyM9qIBwK1ueESZr7zuPjyGIPf69nfro371VqwXoP6iKGf2PiyMOBPk85 fFIYfU1ti4FixGu0rpSkXfGW6qXFT7FW6DMPM3o6lcT4N2Je3SK3t9lpVZGNV28CrCtd M2RXVh7V44corQyAamFCDmk5twY6pa157e77okas/UcnMzJTM3jzK/YLhBlS2S8cVJw9 hyCOsBxE2whZJw2iKbZF2k4mNHpwLMbfGbCuvN87PMu8BfPaTOrplkgIyN7LGA2+tC4v reHQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x2si4049070ejy.84.2020.07.26.01.05.47; Sun, 26 Jul 2020 01:06:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727034AbgGZIDI (ORCPT + 99 others); Sun, 26 Jul 2020 04:03:08 -0400 Received: from relay11.mail.gandi.net ([217.70.178.231]:35233 "EHLO relay11.mail.gandi.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725848AbgGZIDI (ORCPT ); Sun, 26 Jul 2020 04:03:08 -0400 Received: from localhost.localdomain (unknown [180.110.142.179]) (Authenticated sender: fly@kernel.page) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 107BC100007; Sun, 26 Jul 2020 08:02:59 +0000 (UTC) From: Pengfei Li To: akpm@linux-foundation.org Cc: bmt@zurich.ibm.com, dledford@redhat.com, willy@infradead.org, vbabka@suse.cz, kirill.shutemov@linux.intel.com, jgg@ziepe.ca, alex.williamson@redhat.com, cohuck@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Pengfei Li Subject: [PATCH 2/2] mm, util: account_locked_vm() does not hold mmap_lock Date: Sun, 26 Jul 2020 16:02:24 +0800 Message-Id: <20200726080224.205470-2-fly@kernel.page> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200726080224.205470-1-fly@kernel.page> References: <20200726080224.205470-1-fly@kernel.page> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since mm->locked_vm is already an atomic counter, account_locked_vm() does not need to hold mmap_lock. Signed-off-by: Pengfei Li --- drivers/vfio/vfio_iommu_type1.c | 8 ++------ mm/util.c | 15 +++------------ 2 files changed, 5 insertions(+), 18 deletions(-) diff --git a/drivers/vfio/vfio_iommu_type1.c b/drivers/vfio/vfio_iommu_type1.c index 78013be07fe7..53818fce78a6 100644 --- a/drivers/vfio/vfio_iommu_type1.c +++ b/drivers/vfio/vfio_iommu_type1.c @@ -376,12 +376,8 @@ static int vfio_lock_acct(struct vfio_dma *dma, long npage, bool async) if (!mm) return -ESRCH; /* process exited */ - ret = mmap_write_lock_killable(mm); - if (!ret) { - ret = __account_locked_vm(mm, abs(npage), npage > 0, dma->task, - dma->lock_cap); - mmap_write_unlock(mm); - } + ret = __account_locked_vm(mm, abs(npage), npage > 0, + dma->task, dma->lock_cap); if (async) mmput(mm); diff --git a/mm/util.c b/mm/util.c index 473add0dc275..320fdd537aea 100644 --- a/mm/util.c +++ b/mm/util.c @@ -424,8 +424,7 @@ void arch_pick_mmap_layout(struct mm_struct *mm, struct rlimit *rlim_stack) * @task: task used to check RLIMIT_MEMLOCK * @bypass_rlim: %true if checking RLIMIT_MEMLOCK should be skipped * - * Assumes @task and @mm are valid (i.e. at least one reference on each), and - * that mmap_lock is held as writer. + * Assumes @task and @mm are valid (i.e. at least one reference on each). * * Return: * * 0 on success @@ -437,8 +436,6 @@ int __account_locked_vm(struct mm_struct *mm, unsigned long pages, bool inc, unsigned long locked_vm, limit; int ret = 0; - mmap_assert_write_locked(mm); - locked_vm = atomic64_read(&mm->locked_vm); if (inc) { if (!bypass_rlim) { @@ -476,17 +473,11 @@ EXPORT_SYMBOL_GPL(__account_locked_vm); */ int account_locked_vm(struct mm_struct *mm, unsigned long pages, bool inc) { - int ret; - if (pages == 0 || !mm) return 0; - mmap_write_lock(mm); - ret = __account_locked_vm(mm, pages, inc, current, - capable(CAP_IPC_LOCK)); - mmap_write_unlock(mm); - - return ret; + return __account_locked_vm(mm, pages, inc, + current, capable(CAP_IPC_LOCK)); } EXPORT_SYMBOL_GPL(account_locked_vm); -- 2.26.2