From patchwork Tue Aug 1 22:07: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: 13337305 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 E5A59C0015E for ; Tue, 1 Aug 2023 22:07:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 81920280101; Tue, 1 Aug 2023 18:07:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 77B5F2800C8; Tue, 1 Aug 2023 18:07:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 53086280101; Tue, 1 Aug 2023 18:07:46 -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 3DB582800C8 for ; Tue, 1 Aug 2023 18:07:46 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 13B7840CE9 for ; Tue, 1 Aug 2023 22:07:46 +0000 (UTC) X-FDA: 81076923732.24.89C4E67 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf06.hostedemail.com (Postfix) with ESMTP id 4D762180013 for ; Tue, 1 Aug 2023 22:07:44 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=yfrnQPSj; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of 3L4LJZAYKCIY241oxlqyyqvo.mywvsx47-wwu5kmu.y1q@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3L4LJZAYKCIY241oxlqyyqvo.mywvsx47-wwu5kmu.y1q@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1690927664; a=rsa-sha256; cv=none; b=LONmZWBvenmPJRDiHjTIbX56XcxQ6APnUTYakJ/619mcsNdZpsicSjA8jmxPwMd1FmDPBT w97aS/HbEgNOR8rEow/sTXvsVT4fEPn80km8o49oy0HYA3s+hRPLx9k/VVkrTXZx0aDwll NVco40mtHKf2KWmDJhdKP2Pou6lKl7I= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b=yfrnQPSj; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf06.hostedemail.com: domain of 3L4LJZAYKCIY241oxlqyyqvo.mywvsx47-wwu5kmu.y1q@flex--surenb.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3L4LJZAYKCIY241oxlqyyqvo.mywvsx47-wwu5kmu.y1q@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1690927664; 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=4DFBzP3PjGN+0KSVb5wBxy1Zq6atXukCZSiVwP2lCA4=; b=ILHN+WZu131Ffm7fwpswqk+lT5oDPHKqe0p9vVO3d6ADFsFc7FY9FBpFVvBon1jwA1xBHj TBtkJR+hPhIcu5v36qavnAZkcEWIr9hGxM43FCzvugpkOKb4JcYmxnxb23Ct3OJZ5l0e0r y84cwQT8gzJHdytMzQFD5DE0AYxH7rw= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-d10792c7582so4979917276.3 for ; Tue, 01 Aug 2023 15:07:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1690927663; x=1691532463; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4DFBzP3PjGN+0KSVb5wBxy1Zq6atXukCZSiVwP2lCA4=; b=yfrnQPSjeIcEe1QiQGFJbsVHjwcAuLH5y1rpwsS9p+vhZ0UwR6PwXsX+lyRO8LZqne i0Gs4sb/UQu9JzPwvqM6DFSny+pA/wf1YWY/9cDzKMMSVuqNYknBZN4RDzqEJ+3tgA1o 9xqYOQ9YfNuN7rSMd/QL10WuKbuUb09YlooNQnxevr0KyYMiTseErJlZMTiswhp4rbGs 2EwfGVOHZ8kOe74pKMJDxDRfvODcH40dPPxzmE/4CBhsbsPSTt0MJcXPagBusQWf3TL+ 2RYrhvVai3uiHNprCu8Jx7kGArbzCMBXdmuc0K6o1xx5D3e1kBTjmNATzd4hCjxzlGtv 8JyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690927663; x=1691532463; 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=4DFBzP3PjGN+0KSVb5wBxy1Zq6atXukCZSiVwP2lCA4=; b=OLN8LHjW0bwjDpPGFWuWbygstNY/cIHWogmAbtBp9IlV/cclrvZs6WiN5A66cqb+Is siTg2+/BY5PfckEKuDq2u5IYGhq0XxDcEmKABebj5Itlr+tkBS7SaVNW0IDARjmQAMka h0Ezu3U0eGQ6fuUkTQ9BNAwACa4gMMR/cehU9DvbtBilzBcF0J4PqabuW1+h8sfdwAUL 4LN0E05M4i9+q73GHLmjODUtPHUnZs1VvjC0Ok/ZaAfj63ln4ake4aCJTOr0SyqKesGR EtIdv9/fMP1z8ZYGeOS13+8LJkrYUEcJDGekO70u3KEM1z/qbOUxFGJaUMg5PjyxrSQ/ rqHw== X-Gm-Message-State: ABy/qLbqdaXiPHFZ5kljQ7KgYzvHMFPMI7Pd6Y2536lkQw3yHbfCS8ob mInQsLtOjnTdqSHxLOHqBMjbiQOQYgs= X-Google-Smtp-Source: APBJJlFt7bPUCzTOSC2YtD5VNpVA2kL+fFs0SLmjXp2yCsxE/K0tlsB3vCbnSPBXi96wBKaf36lZ9Vrga8w= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:201:211c:a2ff:f17b:c5e9]) (user=surenb job=sendgmr) by 2002:a25:d246:0:b0:c61:7151:6727 with SMTP id j67-20020a25d246000000b00c6171516727mr103919ybg.10.1690927663525; Tue, 01 Aug 2023 15:07:43 -0700 (PDT) Date: Tue, 1 Aug 2023 15:07:29 -0700 In-Reply-To: <20230801220733.1987762-1-surenb@google.com> Mime-Version: 1.0 References: <20230801220733.1987762-1-surenb@google.com> X-Mailer: git-send-email 2.41.0.585.gd2178a4bd4-goog Message-ID: <20230801220733.1987762-4-surenb@google.com> Subject: [PATCH v2 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: 4D762180013 X-Stat-Signature: 3d9khq6sh54jrdgnentkgjh55nwbm5mc X-HE-Tag: 1690927664-336061 X-HE-Meta: U2FsdGVkX1+AX4WV5E0h2e9tYCC27DODZHWUAJljIqdsHT5NUVKO7wR7wmQXxrVa8Eif86VaID7SM/WGkqe0WAQftw51iWq0bgNQxR6XNxZ6qhmFySS3H51pjmBrLvn+csvSmWJKrRMiSELkcU2pDhqAj2jR8Hs/jBwTMRzNT2DMG0F3WiW10syXFjMvGLD1Vu13Vdg3G7mQHzYiep/j/ZBG/M4gLq63l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bAnCuSPTZ/GRMQb0Zjitsq/jVDqS/q38YvsiKDz49nAtXvMJ4VXWdxcxTrV+Oui38WcM3y4Av2dmhnxMB4cYrayhgnNOXHOG8U8xVjtEK8tk9a0fpL6VvDnmRmmdI6oDMw4vwpUAI5H79Hkw+rqwgQighV4MeF6tskeoZkFW8jCOio8y4S/uA1SIdWmsmScPn+yAXjImBYhZfPconh6R1oREqkUhJIsEo+yOC81NNFfj6hbTvql96h4BfO1H+Ss0+77rPJvLTtwX2lIRpAt53oEratqKH2Viqi4gdE06qYTW77w= 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); }