From patchwork Fri Apr 26 14:45:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13644920 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 04AE8C4345F for ; Fri, 26 Apr 2024 14:45:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 295C36B0099; Fri, 26 Apr 2024 10:45:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 246076B009B; Fri, 26 Apr 2024 10:45:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0E72D6B009C; Fri, 26 Apr 2024 10:45:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id D62376B0099 for ; Fri, 26 Apr 2024 10:45:17 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 936AA1C07E4 for ; Fri, 26 Apr 2024 14:45:17 +0000 (UTC) X-FDA: 82051955874.15.1A9E7BC Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf27.hostedemail.com (Postfix) with ESMTP id EF1434000B for ; Fri, 26 Apr 2024 14:45:15 +0000 (UTC) Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=H3Kru3bJ; spf=none (imf27.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714142716; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ahgxolPjR35rGtX1/SJWQbu72Aplypg3iRuwgc7l0ko=; b=oUR8+w8q7fHcyyo1AytOpPRaidmDrwqTXOIiiJWWbUrcFiJ78xsJN+HtEeFkHACGalpfnr s65h3BXkOJMurDKRSmGJqgU2Lnxap0kU9IN3FwP3UY0ol/MZRtbDervrX4wp0M9SGkYTnX ISAz1xYlX80MrLACvYgqAHdxmPBnDEg= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=H3Kru3bJ; spf=none (imf27.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714142716; a=rsa-sha256; cv=none; b=t4MUs27IXFBlZU5p61i9dKdI7+Ud7WxEyL45j8XYGEbyaUHC0pghSaUq9egvCbzUVM4xqX I+gXgx2siqqD2wVa5C54zOjlHclSAzwvXu8ftvT1oUXL5yej83hQlF36g28ULcO3btFm9p IIQYR9HoE4C7bSiwWZkVeUw0VvwccrI= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=ahgxolPjR35rGtX1/SJWQbu72Aplypg3iRuwgc7l0ko=; b=H3Kru3bJevR/UbQEi+rQZVHYBs 4jZpcvre5O2AGbp8OOvPMiDJkyyXKYEwehrbAEXn46zMrJ7KBuWpFNQeP5GvM2ym4Znpe2rFHtJGY msYEmfK9UvuayFULCI8kk6G7LUB6YPrB2Zx+N03fvRhfkOQQbI+vtr45609Tt2Kwn6FJlK1MeXJxS WMcWkh72E4cJosWiQFX1pYa+1vdoenBQAajpeUfrFZWmbzAJ9JWV2hofQM8juXYox4jLlGGaod9A5 tg72zpBJGzqFbzLuE2zjQPW+GvalGrwtimdgo9buMc+VIRx3vHv5q3cPTlFfAlqho5X7/s/abOeuJ CWaJ58PA==; Received: from willy by casper.infradead.org with local (Exim 4.97.1 #2 (Red Hat Linux)) id 1s0Mp2-00000005Pl4-1Nds; Fri, 26 Apr 2024 14:45:08 +0000 From: "Matthew Wilcox (Oracle)" To: Andrew Morton Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Suren Baghdasaryan , Peter Xu Subject: [PATCH 3/4] mm: Fix some minor per-VMA lock issues in userfaultfd Date: Fri, 26 Apr 2024 15:45:02 +0100 Message-ID: <20240426144506.1290619-4-willy@infradead.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240426144506.1290619-1-willy@infradead.org> References: <20240426144506.1290619-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Queue-Id: EF1434000B X-Stat-Signature: osc8j85jdistk14zmpctwsfoof9c6bc9 X-Rspam-User: X-Rspamd-Server: rspam07 X-HE-Tag: 1714142715-67426 X-HE-Meta: U2FsdGVkX19B9OjbNfUL+JXD3oygEBezV+G10ex74Kuw8Uk5dDmHrFBtHwsIDWYxmoWJcmAAaRqY2av0jeWcFobA1eah9iChm/q2LAgZ3vAxlSkpGQA2tFzolSXvUBzU23SMdTFEGUUoUrJ8ke3Qtyy1VNfjiyCCX6DbXjtVnUt80pzJ9ZR0/a3aEc1RlE6gKkojQydU+Ni17jQVCBWC4d+mvcgbCwnT/hD6gxWI/KzuK57psu9SJ0sPHQHD9e9/xK8Gp1jKNqNaYoVmVUrARVxgrGSPJiPA2RnHLQfkBY9xe7VyZXNFqxWQF6BjHHkw2KwZ6QDXxSztZezB6gG/3tUJztp3FcDXoyB+AqB4JQ0HPfcfVSiqg49ELk6RG+eyIrwW59YM9f8rf3Gf8tJrtbZtOFgsUyjUKGend2XShZyg36wLmn7OS69ywGHDHjTYyMQHurdeks2gtwoZXtigS1rWsX6L6fMeHFL1ew8t+dfkJTgY3SZ3w/YuDwpMvITZpHJ2MIk3NoTqlWc/6/UatIwsxlYlKbMbmAlHfM4Os7xcs9QEAY7rXwYHHCG97a/xmTCTDFuM5OnJkQvqTtxEzUK3zCtl6vHHE4EndyjxPgUrN48fS/l1u0YSk+whXqUdnP8/nmHPC8cqlDNC/e/adZv6IoArqkUmdSjRX/Yu801Xj2zuAE4uS722UCVDAnTdwojRVYOgdXfxrEcjNQ5ReLtYe3MG3kvl4NaFm9T3tDNZUhPnH2uZDzYo+mCkoJRxu3++mUlzjKFpCM+jYHGTV5i4gp0N6ek2veeD+skJzEU1v3uyXg3PEP0KJLFg+6q1py4HDLxJggkZeVONZgvAHELuGtHAunHjh1sc8yaPsgnm0FEgGPBjYkJi3wUoApr4Fx1KntQmewUaNyKfSB74QOPpn0+WGWED/xzb3DbQNfcgnPpmfazBxdkIGgiG8EsRrBeqoiRNtjHxa+zRU0Z eDyQz+e1 uTlMxmSFWEbpjDt72eUzgCW7nMl7LiZe9oVwpSsG9xbwSUFCbyzvn5aGVgCGfh5gq1GfmrUpb2j66un1L/fNvTom+5WzbAnDCp+BYH6OcUEdvA9jULuw90pHgF0FgIfagYy/965YWHSypkR/n4s9q9IOkioiNseJFSYbfL5EnfRA5r1mpQf6MRl+UMQ== 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: List-Subscribe: List-Unsubscribe: Rename lock_vma() to uffd_lock_vma() because it really is uffd specific. Remove comment referencing unlock_vma() which doesn't exist. Fix the comment about lock_vma_under_rcu() which I just made incorrect. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Suren Baghdasaryan --- mm/userfaultfd.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index e6486923263c..defa5109cc62 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -56,17 +56,16 @@ struct vm_area_struct *find_vma_and_prepare_anon(struct mm_struct *mm, #ifdef CONFIG_PER_VMA_LOCK /* - * lock_vma() - Lookup and lock vma corresponding to @address. + * uffd_lock_vma() - Lookup and lock vma corresponding to @address. * @mm: mm to search vma in. * @address: address that the vma should contain. * - * Should be called without holding mmap_lock. vma should be unlocked after use - * with unlock_vma(). + * Should be called without holding mmap_lock. * * Return: A locked vma containing @address, -ENOENT if no vma is found, or * -ENOMEM if anon_vma couldn't be allocated. */ -static struct vm_area_struct *lock_vma(struct mm_struct *mm, +static struct vm_area_struct *uffd_lock_vma(struct mm_struct *mm, unsigned long address) { struct vm_area_struct *vma; @@ -74,9 +73,8 @@ static struct vm_area_struct *lock_vma(struct mm_struct *mm, vma = lock_vma_under_rcu(mm, address); if (vma) { /* - * lock_vma_under_rcu() only checks anon_vma for private - * anonymous mappings. But we need to ensure it is assigned in - * private file-backed vmas as well. + * We know we're going to need to use anon_vma, so check + * that early. */ if (!(vma->vm_flags & VM_SHARED) && unlikely(!vma->anon_vma)) vma_end_read(vma); @@ -107,7 +105,7 @@ static struct vm_area_struct *uffd_mfill_lock(struct mm_struct *dst_mm, { struct vm_area_struct *dst_vma; - dst_vma = lock_vma(dst_mm, dst_start); + dst_vma = uffd_lock_vma(dst_mm, dst_start); if (IS_ERR(dst_vma) || validate_dst_vma(dst_vma, dst_start + len)) return dst_vma; @@ -1436,7 +1434,7 @@ static int uffd_move_lock(struct mm_struct *mm, struct vm_area_struct *vma; int err; - vma = lock_vma(mm, dst_start); + vma = uffd_lock_vma(mm, dst_start); if (IS_ERR(vma)) return PTR_ERR(vma); @@ -1451,7 +1449,7 @@ static int uffd_move_lock(struct mm_struct *mm, } /* - * Using lock_vma() to get src_vma can lead to following deadlock: + * Using uffd_lock_vma() to get src_vma can lead to following deadlock: * * Thread1 Thread2 * ------- ------- @@ -1473,7 +1471,7 @@ static int uffd_move_lock(struct mm_struct *mm, err = find_vmas_mm_locked(mm, dst_start, src_start, dst_vmap, src_vmap); if (!err) { /* - * See comment in lock_vma() as to why not using + * See comment in uffd_lock_vma() as to why not using * vma_start_read() here. */ down_read(&(*dst_vmap)->vm_lock->lock);