From patchwork Mon Jul 31 17:12:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13335317 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 0B1F2C04A94 for ; Mon, 31 Jul 2023 17:12:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0536280085; Mon, 31 Jul 2023 13:12:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9679D28007A; Mon, 31 Jul 2023 13:12:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B939280085; Mon, 31 Jul 2023 13:12:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6954428007A for ; Mon, 31 Jul 2023 13:12:47 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 1B9BB1A020C for ; Mon, 31 Jul 2023 17:12:47 +0000 (UTC) X-FDA: 81072551574.29.B67CCC0 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf21.hostedemail.com (Postfix) with ESMTP id 4E8631C000B for ; Mon, 31 Jul 2023 17:12:45 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=f9Xkv4qD; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of 3jOvHZAYKCK8hjgTcQVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3jOvHZAYKCK8hjgTcQVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690823565; a=rsa-sha256; cv=none; b=0rYoCR59q1Hgm1oRxTWxRPuhEoYogaD1MfMduCW3CkDKnd5nQJFlEbxWDzzidjfEqb2Hpq RMk7xZhPI4n6v7zycIycldlJy1HnLKNkdP1+rLMaD0qf1430Xl8rSi5K+quik6Z45Zvqzo eXrh1HP8cNlSX90MiXUnCFLwdZO5pLs= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=f9Xkv4qD; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf21.hostedemail.com: domain of 3jOvHZAYKCK8hjgTcQVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3jOvHZAYKCK8hjgTcQVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690823565; 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=k54nr7y8sT8Wz3UIefWJCe/J3ZJoLd0MPdD7SX1yxV4=; b=5IlJfbvLwIcs7ccS/vnc1OwFaGVeEbMmQvzglY2ePtw74nGVdy/ed9jo+jdgGOV/xNiXO5 1CTH1kRGDZzyEGD1cTW3ExJxiixDF6lLQagDzJzxGTx7tUlJnvVUkNQRZ+auS9ysBajg24 ZV7d0WoxEZBUQ1PIJCI9NUMnFfGUTSw= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-c8f360a07a2so3571367276.2 for ; Mon, 31 Jul 2023 10:12:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690823564; x=1691428364; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=k54nr7y8sT8Wz3UIefWJCe/J3ZJoLd0MPdD7SX1yxV4=; b=f9Xkv4qDndAI0YdOZ2cqpuzigjJkWQ867WFypP7OSwCe0TjMpUnPnkD5Y6ryh7F15Y M9Q14b7Q7rdYUncpsFgbIcnXrps3cXu/n5nLbGedhZ45/p7BeS8PbqD3FkLK8kNSVcWe sJK2CotFttBgUzcy2VXRjvFzjM5g8hEPvN+5TMKbT+Soi/X9AdWfs7huzDn319kCX/N6 GMp6dPMzi2Z4psHXbwS83zAFVmyMj0uFSK8waScyRdzBafY4I+1PCGfjiTaar6EOvw8g 4FjFEveEJTGYSjlmO9UfUzptyPCWrdDCvasot5Lp1U7AI3L7Llir4ep5LDCt1MtOBHu3 6mFw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690823564; x=1691428364; 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=k54nr7y8sT8Wz3UIefWJCe/J3ZJoLd0MPdD7SX1yxV4=; b=OAjaO1yHe4O4G8Tcs7xEWn6ZRMxEelejWX9aB4XAPI0y12OejjkN1+Oo1F+5qkJsOr cjkRb0n6BZB6TWgxskTmOGZRcGNKOg+NK29D0z48dAA7N2vFnIReHbbiAqwXh4agtQPz AQJQuzvnT0xb8QzFhZUTb8E+PHcGrSCj0mLbruVuB3zOcHX+PpuPWvFRpIfanzLfg5MY 4Ncy4NrkexQXfFlaMFVpi6Nal5mRLdkLl80NhfIh8rnjTfLzRND/Tkvlqr/hA4Ycs2Fy Mr4Ph7hNla9lKuFAT8BPK6VmDvP3jljc0GnF3KzL04gzfEuC0r31kyPUYU8GrV+w+LFc EGWA== X-Gm-Message-State: ABy/qLb6/rVo8EPtKxo5cNybSg2itwmcOhpvTB3PaCHJfIRe5COZX8qq AOq9u7grv4McsPL1ZIRODNw+GE8OIMM= X-Google-Smtp-Source: APBJJlFUd/WIRrMRABoKwcapNJpdOFT19YiYMf0HEPYfoNPTpuOYC63k+ANMx6Qm9ThWVSfUuBUUFqFSUIk= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:d4d3:7e41:cb80:21ea]) (user=surenb job=sendgmr) by 2002:a05:6902:11ca:b0:d09:b19:fe2c with SMTP id n10-20020a05690211ca00b00d090b19fe2cmr63888ybu.12.1690823564414; Mon, 31 Jul 2023 10:12:44 -0700 (PDT) Date: Mon, 31 Jul 2023 10:12:29 -0700 In-Reply-To: <20230731171233.1098105-1-surenb@google.com> Mime-Version: 1.0 References: <20230731171233.1098105-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.487.g6d72f3e995-goog Message-ID: <20230731171233.1098105-4-surenb@google.com> Subject: [PATCH 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 X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 4E8631C000B X-Stat-Signature: fns3aha1o553jqoh7prxfmsigwewg8es X-HE-Tag: 1690823565-56096 X-HE-Meta: U2FsdGVkX1+2bhnNIa52AN29YsQsvyo+XXM+Wg7qHBlFaUellx0yESmsJrImVOrRNkce7Ej5QvgHicTYq1n8g+tJMyJJAKTPxK6XYcJv2POahEhMVQ8wQk7KIWGulIQHwiTDiLk7JnvZ/zFBk6Z2QpPfRu8Om9Y/Nw0v6YMSI5yxzrF8EZx59JlUijMML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axrLoLeVuoY/ycC7nLjo6Voem9M6OT2EVD2hjiq3pFit8lYxd5hs+Xx/Qyi97HNWIq+2eKsU9a7OrpNcsgxR28DrgLTK38z218+VwDJxqOci4r3H5sVC0Ej7MC8b3jVJn+2Xt+rj6ki9785ZhxwS1u3e0y8lpfLf0RIGHIfSmoYBemjI+wp1VFaJgkzD/aexGqfZHsqP3iPXBrjfN6mNcmozPHdNVu/Qwo7hDtuYM8fFA2r6VD9EDSP9I8462tS6Vp52nBJjX1EbdjjPeok4ZRhqrg1H1fr74f7hoCcMU8M66XB8H+CTrkt8J1KraDmgKy88ypT+/klUfPLE+l9DQwNAZz+JOVFr74CIXc= 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 --- 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); }