From patchwork Thu Aug 3 17:26:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13340370 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 1B0C0C04FE0 for ; Thu, 3 Aug 2023 17:27:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A7F7B280282; Thu, 3 Aug 2023 13:27:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A2F7E28022C; Thu, 3 Aug 2023 13:27:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 834C6280282; Thu, 3 Aug 2023 13:27:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 69C0928022C for ; Thu, 3 Aug 2023 13:27:05 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2AE80120811 for ; Thu, 3 Aug 2023 17:27:05 +0000 (UTC) X-FDA: 81083474010.06.AAB084C Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf11.hostedemail.com (Postfix) with ESMTP id 47DB84002D for ; Thu, 3 Aug 2023 17:27:03 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="HHki6L/b"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 3ZuPLZAYKCIk574r0ot11tyr.p1zyv07A-zzx8npx.14t@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3ZuPLZAYKCIk574r0ot11tyr.p1zyv07A-zzx8npx.14t@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1691083623; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=LfajP5IIbFpg2Y7BQRxvk1sHiLCqjf/rsCkC3jBCtoI=; b=g3GT/1NE9RvGOgGhrq8GHhfZfkdTsc6rgNQz13x+buTiPx78TzwXm+tXSOAnzqaL1DQ0ff tOPCbAclMvlNsMyKZ4uayplHP7T1xkRMFNhu7u5q8IxWMiXGn6Tpte5ey7Bu5ucWFD29u9 jkUf4qmW/qb93AxH4v6jc02nosflTqM= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="HHki6L/b"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf11.hostedemail.com: domain of 3ZuPLZAYKCIk574r0ot11tyr.p1zyv07A-zzx8npx.14t@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3ZuPLZAYKCIk574r0ot11tyr.p1zyv07A-zzx8npx.14t@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1691083623; a=rsa-sha256; cv=none; b=IXf17ET56sA/1vy/VVRIwbPk8eEk8pzoFg3XNStJ9ZUc3uNBXXd93gxKVGpON4YMHLgHfL R1fFJzhLnvjZfU2JvYmM55o9wFViWnNuNh+t/ILXyyja4skRjQ00mgVMmejcln2CLl75WI aqXtdaIYcDk0IE8FLPEMPc79I1h/L0U= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-cf4cb742715so1285617276.2 for ; Thu, 03 Aug 2023 10:27:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691083622; x=1691688422; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=LfajP5IIbFpg2Y7BQRxvk1sHiLCqjf/rsCkC3jBCtoI=; b=HHki6L/bmVrbbgbTtB9WdMtyro9jT73+cCAxKEfbQcmR3qH9v6ec6CcbLdBDBiHtbD DgkXEJ1VQUd+cMDxmtIXTtXdoPNmy73uD9LZlwIoe2mdEcYq/BSd/gAhOgP0fAm/mz7/ 8v51YuDLWoZ2H6bS1nhWVnhqzAMn395dK93Vn63kHAx/qo6JPUNuF05lCgUdd7cwcCXg Le/Ctgs2wSzsf6ywyFYUPRCg/ETixmQpFAd/6SNe06GNe12jbStG/hoYgMj4KbT0T2lp njpni/PXfMsrjLG8JE43HZ3PBUxm8AfwfKRLkTOdqi08qFkN+w6s2O9SAGVXJ8RtvGZy fOVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691083622; x=1691688422; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LfajP5IIbFpg2Y7BQRxvk1sHiLCqjf/rsCkC3jBCtoI=; b=FoD8bRXtjuztfim7fJguSZhbfBGdFmVqvKeKMVmUYkJwp79VhL32CxGw8RlAf3/+NQ 6ewleoCH4fA6ZuOPY5NGCGFDlQRyyThkQ6+9tyUIDrIKg7WbSKymIzeomfY3PAKnYkeR AbD7VsqBjUZ2JmOra7CrYfQKud9pvzPRPtc4XwKZibaJkpV+qV8zWutrR2x34ZmeOfT3 rn/eMsjBw+H89zs3BdtboThs2Prlfk5EnEvGyhbqc80qTSumLL0iCAGeQDO7rE7Q6w1U XV9pFCYe3WNtUbMc16UVJKlIK3YzFsfpvTv8G924GGGqSJdzmi8XNIitj2qCeMbVMqZ5 1VwQ== X-Gm-Message-State: ABy/qLZ5NLVdFAr+cpi0zUSnSaD7D50DyPzQpd47kx0E8+8z9QPYFkH8 x4Oed8XgLvahx5VB2dP2fsOCBGNIWX0= X-Google-Smtp-Source: APBJJlERuzjun8O5+88x8UQezAzWCkSvC+SxUAPYIz16CZMGZKaq/Tmi2dNZnAJHx5Bu+iggd6tbtkFAIsk= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:3dec:ef9e:7bf4:7a6]) (user=surenb job=sendgmr) by 2002:a05:6902:569:b0:d11:3c58:2068 with SMTP id a9-20020a056902056900b00d113c582068mr132529ybt.2.1691083622391; Thu, 03 Aug 2023 10:27:02 -0700 (PDT) Date: Thu, 3 Aug 2023 10:26:48 -0700 In-Reply-To: <20230803172652.2849981-1-surenb@google.com> Mime-Version: 1.0 References: <20230803172652.2849981-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.585.gd2178a4bd4-goog Message-ID: <20230803172652.2849981-4-surenb@google.com> Subject: [PATCH v3 3/6] mm: replace mmap with vma write lock assertions when operating on a vma From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: torvalds@linux-foundation.org, jannh@google.com, willy@infradead.org, liam.howlett@oracle.com, david@redhat.com, peterx@redhat.com, ldufour@linux.ibm.com, vbabka@suse.cz, michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, hannes@cmpxchg.org, dave@stgolabs.net, hughd@google.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, stable@vger.kernel.org, Suren Baghdasaryan , "Liam R . Howlett" X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 47DB84002D X-Stat-Signature: h3g7bui3r7rqpyqy3gezoo9j53ji5e9g X-HE-Tag: 1691083623-295162 X-HE-Meta: U2FsdGVkX188CTnCQdrYPpjGnomeM6NHsP+MGH/A1zs/OWRNsjS2bwcHuhqO0cNqNFuwKV7lAexaDGyzuFSniXriSzsIOeX29wpKoqXGffL6qjNR4HOyVQ705TJct9gjsmQaoIi91LjEy/pzoVY09ClDloVlmMbnphutcoNcMPTf4HJUssRP0HznYc3KWaq+Ds0Eat8KVzyqMlFfLjJW9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W/1oXoPLSK3w0W8qADfsfzWycLHYZaDqpwlC6Uda0WTmDZEK3uCCsi7Gsiycx5bL4UV+ZLBvT6o9cJ2CfthP8cDeMwwmKeTx5yz7HoqxEtBhXlJ6gubfxWXJntwEgpOFyUF+ZFi50KJePVtWdoLpa8Y1FNniAVrffJ/I3pFNTrTOhjrAwKOjw+wU1yxs/88rU5by5N0SnjibvlboJYH60VnCXfiLRdTBVkBaji26Fl/vVQ5bolDxA5sE5DljyXDfewyXg7CD7w06cfSVZIOxMTnCejGqhxP/OE0GFDSr9V/3mw9dm092uu4eH9RNRcPRmQyJSATawaVihz8hr6WW0Fcx4aw3g0Xq 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: Vma write lock assertion always includes mmap write lock assertion and additional vma lock checks when per-VMA locks are enabled. Replace weaker mmap_assert_write_locked() assertions with stronger vma_assert_write_locked() ones when we are operating on a vma which is expected to be locked. Suggested-by: Jann Horn Signed-off-by: Suren Baghdasaryan Reviewed-by: Liam R. Howlett --- mm/hugetlb.c | 2 +- mm/khugepaged.c | 5 +++-- mm/memory.c | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 64a3239b6407..1d871a1167d8 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5028,7 +5028,7 @@ int copy_hugetlb_page_range(struct mm_struct *dst, struct mm_struct *src, src_vma->vm_start, src_vma->vm_end); mmu_notifier_invalidate_range_start(&range); - mmap_assert_write_locked(src); + vma_assert_write_locked(src_vma); raw_write_seqcount_begin(&src->write_protect_seq); } else { /* diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 78c8d5d8b628..1e43a56fba31 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1495,7 +1495,7 @@ static int set_huge_pmd(struct vm_area_struct *vma, unsigned long addr, }; VM_BUG_ON(!PageTransHuge(hpage)); - mmap_assert_write_locked(vma->vm_mm); + vma_assert_write_locked(vma); if (do_set_pmd(&vmf, hpage)) return SCAN_FAIL; @@ -1525,7 +1525,7 @@ static void collapse_and_free_pmd(struct mm_struct *mm, struct vm_area_struct *v pmd_t pmd; struct mmu_notifier_range range; - mmap_assert_write_locked(mm); + vma_assert_write_locked(vma); if (vma->vm_file) lockdep_assert_held_write(&vma->vm_file->f_mapping->i_mmap_rwsem); /* @@ -1570,6 +1570,7 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, unsigned long addr, int count = 0, result = SCAN_FAIL; int i; + /* Ensure vma can't change, it will be locked below after checks */ mmap_assert_write_locked(mm); /* Fast check before locking page if already PMD-mapped */ diff --git a/mm/memory.c b/mm/memory.c index 603b2f419948..652d99b9858a 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1312,7 +1312,7 @@ copy_page_range(struct vm_area_struct *dst_vma, struct vm_area_struct *src_vma) * Use the raw variant of the seqcount_t write API to avoid * lockdep complaining about preemptibility. */ - mmap_assert_write_locked(src_mm); + vma_assert_write_locked(src_vma); raw_write_seqcount_begin(&src_mm->write_protect_seq); }