From patchwork Thu Apr 21 19:05:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 12822280 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 A8E8BC433F5 for ; Thu, 21 Apr 2022 19:05:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 93B606B0073; Thu, 21 Apr 2022 15:05:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8C4846B0074; Thu, 21 Apr 2022 15:05:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6A9146B0078; Thu, 21 Apr 2022 15:05:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id 4A8956B0074 for ; Thu, 21 Apr 2022 15:05:54 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay13.hostedemail.com (Postfix) with ESMTP id 1806F60F83 for ; Thu, 21 Apr 2022 19:05:54 +0000 (UTC) X-FDA: 79381815828.21.BDEFADE Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf25.hostedemail.com (Postfix) with ESMTP id 46DA7A0028 for ; Thu, 21 Apr 2022 19:05:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650567953; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CFWmGejx79OEDDZnBB2ZFPlGKsCZX9RSPrZd1rTZXn0=; b=O2pbzWAEFaGpmhYxfA+qaQ+fDgYCho3anTYF32h6Ripz6DQUfaQcvOFBCMxhMp9i+Le+I7 edqBQoVu/uQXXFKgrjiiYdv90mmKXmWfjXtYuEEkFRvp3sOKoHuesjHGvT+pUU/6BtfIbj /f5i4Mspzjiunz/EDtmNTI4WOnfcD9Q= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-660-V_2KtmyYOi2dcxdzsPsvNA-1; Thu, 21 Apr 2022 15:05:49 -0400 X-MC-Unique: V_2KtmyYOi2dcxdzsPsvNA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5A5DC811E90; Thu, 21 Apr 2022 19:05:48 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.22.16.253]) by smtp.corp.redhat.com (Postfix) with ESMTP id A61EFC27E81; Thu, 21 Apr 2022 19:05:47 +0000 (UTC) From: Nico Pache To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alexander Viro , Andrew Morton , Nicholas Piggin , Logan Gunthorpe , Hari Bathini , "Aneesh Kumar K.V" , "Matthew Wilcox (Oracle)" , Yang Shi , Miaohe Lin , William Kucharski , Hugh Dickins Subject: [RFC 1/3] mm: change vma_is_anonymous to vma_is_private_anon Date: Thu, 21 Apr 2022 15:05:31 -0400 Message-Id: <20220421190533.1601879-2-npache@redhat.com> In-Reply-To: <20220421190533.1601879-1-npache@redhat.com> References: <20220421190533.1601879-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Rspam-User: X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 46DA7A0028 X-Stat-Signature: f3qyc7imowx78eb7teytfxx839x66ngz Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=O2pbzWAE; spf=none (imf25.hostedemail.com: domain of npache@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1650567950-945385 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: The vma_is_anonymous function isn't fully indicative of what it checks. Without having full knowledge of the mmap process, one may incorrectly assume this covers all types of anonymous memory; which is not the case. No functional changes. Cc: Michael Ellerman Cc: Benjamin Herrenschmidt Cc: Paul Mackerras Cc: Alexander Viro Cc: Andrew Morton Cc: Nicholas Piggin Cc: Logan Gunthorpe Cc: Hari Bathini Cc: "Aneesh Kumar K.V" Cc: "Matthew Wilcox (Oracle)" Cc: Yang Shi Cc: Miaohe Lin Cc: William Kucharski Cc: Hugh Dickins Signed-off-by: Nico Pache --- arch/powerpc/mm/book3s64/pgtable.c | 2 +- fs/userfaultfd.c | 2 +- include/linux/huge_mm.h | 2 +- include/linux/mm.h | 2 +- mm/gup.c | 4 ++-- mm/huge_memory.c | 10 +++++----- mm/madvise.c | 4 ++-- mm/memory.c | 10 +++++----- mm/migrate_device.c | 6 +++--- mm/mincore.c | 2 +- mm/mmap.c | 4 ++-- mm/oom_kill.c | 2 +- mm/userfaultfd.c | 8 ++++---- 13 files changed, 29 insertions(+), 29 deletions(-) diff --git a/arch/powerpc/mm/book3s64/pgtable.c b/arch/powerpc/mm/book3s64/pgtable.c index 052e6590f84f..c8fd68a7965d 100644 --- a/arch/powerpc/mm/book3s64/pgtable.c +++ b/arch/powerpc/mm/book3s64/pgtable.c @@ -479,7 +479,7 @@ int pmd_move_must_withdraw(struct spinlock *new_pmd_ptl, struct vm_area_struct *vma) { if (radix_enabled()) - return (new_pmd_ptl != old_pmd_ptl) && vma_is_anonymous(vma); + return (new_pmd_ptl != old_pmd_ptl) && vma_is_private_anon(vma); return true; } diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index aa0c47cb0d16..d3fe2c26874a 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1269,7 +1269,7 @@ static inline bool vma_can_userfault(struct vm_area_struct *vma, return false; } - return vma_is_anonymous(vma) || is_vm_hugetlb_page(vma) || + return vma_is_private_anon(vma) || is_vm_hugetlb_page(vma) || vma_is_shmem(vma); } diff --git a/include/linux/huge_mm.h b/include/linux/huge_mm.h index 2999190adc22..40493f53562c 100644 --- a/include/linux/huge_mm.h +++ b/include/linux/huge_mm.h @@ -119,7 +119,7 @@ static inline bool transhuge_vma_suitable(struct vm_area_struct *vma, unsigned long haddr) { /* Don't have to check pgoff for anonymous vma */ - if (!vma_is_anonymous(vma)) { + if (!vma_is_private_anon(vma)) { if (!IS_ALIGNED((vma->vm_start >> PAGE_SHIFT) - vma->vm_pgoff, HPAGE_PMD_NR)) return false; diff --git a/include/linux/mm.h b/include/linux/mm.h index e34edb775334..9a01d053853b 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -623,7 +623,7 @@ static inline void vma_set_anonymous(struct vm_area_struct *vma) vma->vm_ops = NULL; } -static inline bool vma_is_anonymous(struct vm_area_struct *vma) +static inline bool vma_is_private_anon(struct vm_area_struct *vma) { return !vma->vm_ops; } diff --git a/mm/gup.c b/mm/gup.c index f598a037eb04..7cd3ef329ea2 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -398,7 +398,7 @@ static struct page *no_page_table(struct vm_area_struct *vma, * be zero-filled if handle_mm_fault() actually did handle it. */ if ((flags & FOLL_DUMP) && - (vma_is_anonymous(vma) || !vma->vm_ops->fault)) + (vma_is_private_anon(vma) || !vma->vm_ops->fault)) return ERR_PTR(-EFAULT); return NULL; } @@ -913,7 +913,7 @@ static int check_vma_flags(struct vm_area_struct *vma, unsigned long gup_flags) if (vm_flags & (VM_IO | VM_PFNMAP)) return -EFAULT; - if (gup_flags & FOLL_ANON && !vma_is_anonymous(vma)) + if (gup_flags & FOLL_ANON && !vma_is_private_anon(vma)) return -EFAULT; if ((gup_flags & FOLL_LONGTERM) && vma_is_fsdax(vma)) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index c468fee595ff..81c2123aeffe 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -82,7 +82,7 @@ bool transparent_hugepage_active(struct vm_area_struct *vma) if (!transhuge_vma_suitable(vma, addr)) return false; - if (vma_is_anonymous(vma)) + if (vma_is_private_anon(vma)) return __transparent_hugepage_enabled(vma); if (vma_is_shmem(vma)) return shmem_huge_enabled(vma); @@ -1035,7 +1035,7 @@ int copy_huge_pmd(struct mm_struct *dst_mm, struct mm_struct *src_mm, int ret = -ENOMEM; /* Skip if can be re-fill on fault */ - if (!vma_is_anonymous(dst_vma)) + if (!vma_is_private_anon(dst_vma)) return 0; pgtable = pte_alloc_one(dst_mm); @@ -1622,7 +1622,7 @@ static inline int pmd_move_must_withdraw(spinlock_t *new_pmd_ptl, * * We also don't deposit and withdraw tables for file pages. */ - return (new_pmd_ptl != old_pmd_ptl) && vma_is_anonymous(vma); + return (new_pmd_ptl != old_pmd_ptl) && vma_is_private_anon(vma); } #endif @@ -1799,7 +1799,7 @@ int change_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd, } ret = HPAGE_PMD_NR; set_pmd_at(mm, addr, pmd, entry); - BUG_ON(vma_is_anonymous(vma) && !preserve_write && pmd_write(entry)); + BUG_ON(vma_is_private_anon(vma) && !preserve_write && pmd_write(entry)); unlock: spin_unlock(ptl); return ret; @@ -1957,7 +1957,7 @@ static void __split_huge_pmd_locked(struct vm_area_struct *vma, pmd_t *pmd, count_vm_event(THP_SPLIT_PMD); - if (!vma_is_anonymous(vma)) { + if (!vma_is_private_anon(vma)) { old_pmd = pmdp_huge_clear_flush_notify(vma, haddr, pmd); /* * We are going to unmap this huge page. So diff --git a/mm/madvise.c b/mm/madvise.c index 1873616a37d2..23771875ae9d 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -543,7 +543,7 @@ static void madvise_pageout_page_range(struct mmu_gather *tlb, static inline bool can_do_pageout(struct vm_area_struct *vma) { - if (vma_is_anonymous(vma)) + if (vma_is_private_anon(vma)) return true; if (!vma->vm_file) return false; @@ -725,7 +725,7 @@ static int madvise_free_single_vma(struct vm_area_struct *vma, struct mmu_gather tlb; /* MADV_FREE works for only anon vma at the moment */ - if (!vma_is_anonymous(vma)) + if (!vma_is_private_anon(vma)) return -EINVAL; range.start = max(vma->vm_start, start_addr); diff --git a/mm/memory.c b/mm/memory.c index 76e3af9639d9..fcb599bc5c33 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4494,7 +4494,7 @@ static vm_fault_t do_numa_page(struct vm_fault *vmf) static inline vm_fault_t create_huge_pmd(struct vm_fault *vmf) { - if (vma_is_anonymous(vmf->vma)) + if (vma_is_private_anon(vmf->vma)) return do_huge_pmd_anonymous_page(vmf); if (vmf->vma->vm_ops->huge_fault) return vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PMD); @@ -4504,7 +4504,7 @@ static inline vm_fault_t create_huge_pmd(struct vm_fault *vmf) /* `inline' is required to avoid gcc 4.1.2 build error */ static inline vm_fault_t wp_huge_pmd(struct vm_fault *vmf) { - if (vma_is_anonymous(vmf->vma)) { + if (vma_is_private_anon(vmf->vma)) { if (userfaultfd_huge_pmd_wp(vmf->vma, vmf->orig_pmd)) return handle_userfault(vmf, VM_UFFD_WP); return do_huge_pmd_wp_page(vmf); @@ -4527,7 +4527,7 @@ static vm_fault_t create_huge_pud(struct vm_fault *vmf) #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \ defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD) /* No support for anonymous transparent PUD pages yet */ - if (vma_is_anonymous(vmf->vma)) + if (vma_is_private_anon(vmf->vma)) goto split; if (vmf->vma->vm_ops->huge_fault) { vm_fault_t ret = vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PUD); @@ -4546,7 +4546,7 @@ static vm_fault_t wp_huge_pud(struct vm_fault *vmf, pud_t orig_pud) { #ifdef CONFIG_TRANSPARENT_HUGEPAGE /* No support for anonymous transparent PUD pages yet */ - if (vma_is_anonymous(vmf->vma)) + if (vma_is_private_anon(vmf->vma)) return VM_FAULT_FALLBACK; if (vmf->vma->vm_ops->huge_fault) return vmf->vma->vm_ops->huge_fault(vmf, PE_SIZE_PUD); @@ -4621,7 +4621,7 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) } if (!vmf->pte) { - if (vma_is_anonymous(vmf->vma)) + if (vma_is_private_anon(vmf->vma)) return do_anonymous_page(vmf); else return do_fault(vmf); diff --git a/mm/migrate_device.c b/mm/migrate_device.c index 70c7dc05bbfc..4a4068c410f7 100644 --- a/mm/migrate_device.c +++ b/mm/migrate_device.c @@ -40,7 +40,7 @@ static int migrate_vma_collect_hole(unsigned long start, unsigned long addr; /* Only allow populating anonymous memory. */ - if (!vma_is_anonymous(walk->vma)) + if (!vma_is_private_anon(walk->vma)) return migrate_vma_collect_skip(start, end, walk); for (addr = start; addr < end; addr += PAGE_SIZE) { @@ -120,7 +120,7 @@ static int migrate_vma_collect_pmd(pmd_t *pmdp, pte = *ptep; if (pte_none(pte)) { - if (vma_is_anonymous(vma)) { + if (vma_is_private_anon(vma)) { mpfn = MIGRATE_PFN_MIGRATE; migrate->cpages++; } @@ -518,7 +518,7 @@ static void migrate_vma_insert_page(struct migrate_vma *migrate, pte_t *ptep; /* Only allow populating anonymous memory */ - if (!vma_is_anonymous(vma)) + if (!vma_is_private_anon(vma)) goto abort; pgdp = pgd_offset(mm, addr); diff --git a/mm/mincore.c b/mm/mincore.c index 9122676b54d6..5aa4a1358ac1 100644 --- a/mm/mincore.c +++ b/mm/mincore.c @@ -156,7 +156,7 @@ static int mincore_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end, static inline bool can_do_mincore(struct vm_area_struct *vma) { - if (vma_is_anonymous(vma)) + if (vma_is_private_anon(vma)) return true; if (!vma->vm_file) return false; diff --git a/mm/mmap.c b/mm/mmap.c index 3aa839f81e63..a2968669fd4e 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3189,7 +3189,7 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma) * using the existing file pgoff checks and manipulations. * Similarly in do_mmap and in do_brk_flags. */ - if (vma_is_anonymous(vma)) { + if (vma_is_private_anon(vma)) { BUG_ON(vma->anon_vma); vma->vm_pgoff = vma->vm_start >> PAGE_SHIFT; } @@ -3217,7 +3217,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, * If anonymous vma has not yet been faulted, update new pgoff * to match new location, to increase its chance of merging. */ - if (unlikely(vma_is_anonymous(vma) && !vma->anon_vma)) { + if (unlikely(vma_is_private_anon(vma) && !vma->anon_vma)) { pgoff = addr >> PAGE_SHIFT; faulted_in_anon_vma = false; } diff --git a/mm/oom_kill.c b/mm/oom_kill.c index 7ec38194f8e1..aa3e68934fcb 100644 --- a/mm/oom_kill.c +++ b/mm/oom_kill.c @@ -536,7 +536,7 @@ bool __oom_reap_task_mm(struct mm_struct *mm) * we do not want to block exit_mmap by keeping mm ref * count elevated without a good reason. */ - if (vma_is_anonymous(vma) || !(vma->vm_flags & VM_SHARED)) { + if (vma_is_private_anon(vma) || !(vma->vm_flags & VM_SHARED)) { struct mmu_notifier_range range; struct mmu_gather tlb; diff --git a/mm/userfaultfd.c b/mm/userfaultfd.c index 0cb8e5ef1713..c94f81bd109b 100644 --- a/mm/userfaultfd.c +++ b/mm/userfaultfd.c @@ -540,9 +540,9 @@ static __always_inline ssize_t __mcopy_atomic(struct mm_struct *dst_mm, err = -EINVAL; /* * shmem_zero_setup is invoked in mmap for MAP_ANONYMOUS|MAP_SHARED but - * it will overwrite vm_ops, so vma_is_anonymous must return false. + * it will overwrite vm_ops, so vma_is_private_anon must return false. */ - if (WARN_ON_ONCE(vma_is_anonymous(dst_vma) && + if (WARN_ON_ONCE(vma_is_private_anon(dst_vma) && dst_vma->vm_flags & VM_SHARED)) goto out_unlock; @@ -561,7 +561,7 @@ static __always_inline ssize_t __mcopy_atomic(struct mm_struct *dst_mm, return __mcopy_atomic_hugetlb(dst_mm, dst_vma, dst_start, src_start, len, mcopy_mode); - if (!vma_is_anonymous(dst_vma) && !vma_is_shmem(dst_vma)) + if (!vma_is_private_anon(dst_vma) && !vma_is_shmem(dst_vma)) goto out_unlock; if (!vma_is_shmem(dst_vma) && mcopy_mode == MCOPY_ATOMIC_CONTINUE) goto out_unlock; @@ -717,7 +717,7 @@ int mwriteprotect_range(struct mm_struct *dst_mm, unsigned long start, goto out_unlock; if (!userfaultfd_wp(dst_vma)) goto out_unlock; - if (!vma_is_anonymous(dst_vma)) + if (!vma_is_private_anon(dst_vma)) goto out_unlock; if (enable_wp) From patchwork Thu Apr 21 19:05:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 12822279 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 D0E02C433EF for ; Thu, 21 Apr 2022 19:05:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 437B16B0072; Thu, 21 Apr 2022 15:05:54 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BF666B0073; Thu, 21 Apr 2022 15:05:54 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 210666B0074; Thu, 21 Apr 2022 15:05:54 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 0C0C66B0072 for ; Thu, 21 Apr 2022 15:05:54 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay12.hostedemail.com (Postfix) with ESMTP id AF687121791 for ; Thu, 21 Apr 2022 19:05:53 +0000 (UTC) X-FDA: 79381815786.19.36B4643 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf12.hostedemail.com (Postfix) with ESMTP id 9C20440027 for ; Thu, 21 Apr 2022 19:05:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650567952; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AmYL0y+hCk1491gF9Io/zt26uV8J/a8ENaiSiyYWeXE=; b=US67dKAykGHeilAvg4PrEzZLpli1baWt6J9IhFG/NLMvpGpLk/zqrzmKWdTabrvyn4AS3d JpjqA5deyv8M/WOFps2cA/ksFsH/N9+g4VSGMMW2BV+36E7b4EQivN1d1Lii1RudXXFNN9 TsSk3XMnVtbm32x8C+4Yipevl9yYHqw= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-325-NMYJwTonP3e0DVRyVtnEXg-1; Thu, 21 Apr 2022 15:05:49 -0400 X-MC-Unique: NMYJwTonP3e0DVRyVtnEXg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E83BA85A5BC; Thu, 21 Apr 2022 19:05:48 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.22.16.253]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6E8CAC2812A; Thu, 21 Apr 2022 19:05:48 +0000 (UTC) From: Nico Pache To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: Andrew Morton , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , =?utf-8?q?Andr=C3=A9_Almeida?= , Arjan van de Ven , Ulrich Drepper Subject: [RFC 2/3] futex: exit: Print a warning when futex_cleanup fails Date: Thu, 21 Apr 2022 15:05:32 -0400 Message-Id: <20220421190533.1601879-3-npache@redhat.com> In-Reply-To: <20220421190533.1601879-1-npache@redhat.com> References: <20220421190533.1601879-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 X-Rspam-User: X-Rspamd-Queue-Id: 9C20440027 X-Stat-Signature: odobt66jkuxibwswtxkiijm4gotszcwd Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=US67dKAy; spf=none (imf12.hostedemail.com: domain of npache@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Rspamd-Server: rspam01 X-HE-Tag: 1650567949-691232 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: The futex_cleanup routines currently fails silently. Allow the futex_cleanup routines to fail more verbosely so we can leave a message behind for easier debugging/error detecting. Fixes: 0771dfefc9e5 ("[PATCH] lightweight robust futexes: core") Cc: Andrew Morton Cc: Thomas Gleixner Cc: Ingo Molnar Cc: Peter Zijlstra Cc: Darren Hart Cc: Davidlohr Bueso Cc: "André Almeida" Cc: Arjan van de Ven Cc: Ulrich Drepper Signed-off-by: Nico Pache --- kernel/futex/core.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/kernel/futex/core.c b/kernel/futex/core.c index b22ef1efe751..8a62eb1b5d77 100644 --- a/kernel/futex/core.c +++ b/kernel/futex/core.c @@ -760,9 +760,9 @@ static inline int fetch_robust_entry(struct robust_list __user **entry, * Walk curr->robust_list (very carefully, it's a userspace list!) * and mark any locks found there dead, and notify any waiters. * - * We silently return on any sign of list-walking problem. + * We return false on any sign of list-walking problem. */ -static void exit_robust_list(struct task_struct *curr) +static bool exit_robust_list(struct task_struct *curr) { struct robust_list_head __user *head = curr->robust_list; struct robust_list __user *entry, *next_entry, *pending; @@ -771,23 +771,25 @@ static void exit_robust_list(struct task_struct *curr) unsigned long futex_offset; int rc; + if (!futex_cmpxchg_enabled) + return false; /* * Fetch the list head (which was registered earlier, via * sys_set_robust_list()): */ if (fetch_robust_entry(&entry, &head->list.next, &pi)) - return; + return false; /* * Fetch the relative futex offset: */ if (get_user(futex_offset, &head->futex_offset)) - return; + return false; /* * Fetch any possibly pending lock-add first, and handle it * if it exists: */ if (fetch_robust_entry(&pending, &head->list_op_pending, &pip)) - return; + return false; next_entry = NULL; /* avoid warning with gcc */ while (entry != &head->list) { @@ -803,10 +805,10 @@ static void exit_robust_list(struct task_struct *curr) if (entry != pending) { if (handle_futex_death((void __user *)entry + futex_offset, curr, pi, HANDLE_DEATH_LIST)) - return; + return false; } if (rc) - return; + return false; entry = next_entry; pi = next_pi; /* @@ -819,9 +821,10 @@ static void exit_robust_list(struct task_struct *curr) } if (pending) { - handle_futex_death((void __user *)pending + futex_offset, + return handle_futex_death((void __user *)pending + futex_offset, curr, pip, HANDLE_DEATH_PENDING); } + return true; } #ifdef CONFIG_COMPAT @@ -854,9 +857,9 @@ compat_fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **ent * Walk curr->robust_list (very carefully, it's a userspace list!) * and mark any locks found there dead, and notify any waiters. * - * We silently return on any sign of list-walking problem. + * We return false on any sign of list-walking problem. */ -static void compat_exit_robust_list(struct task_struct *curr) +static bool compat_exit_robust_list(struct task_struct *curr) { struct compat_robust_list_head __user *head = curr->compat_robust_list; struct robust_list __user *entry, *next_entry, *pending; @@ -866,24 +869,26 @@ static void compat_exit_robust_list(struct task_struct *curr) compat_long_t futex_offset; int rc; + if (!futex_cmpxchg_enabled) + return false; /* * Fetch the list head (which was registered earlier, via * sys_set_robust_list()): */ if (compat_fetch_robust_entry(&uentry, &entry, &head->list.next, &pi)) - return; + return false; /* * Fetch the relative futex offset: */ if (get_user(futex_offset, &head->futex_offset)) - return; + return false; /* * Fetch any possibly pending lock-add first, and handle it * if it exists: */ if (compat_fetch_robust_entry(&upending, &pending, &head->list_op_pending, &pip)) - return; + return false; next_entry = NULL; /* avoid warning with gcc */ while (entry != (struct robust_list __user *) &head->list) { @@ -902,10 +907,10 @@ static void compat_exit_robust_list(struct task_struct *curr) if (handle_futex_death(uaddr, curr, pi, HANDLE_DEATH_LIST)) - return; + return false; } if (rc) - return; + return false; uentry = next_uentry; entry = next_entry; pi = next_pi; @@ -920,8 +925,9 @@ static void compat_exit_robust_list(struct task_struct *curr) if (pending) { void __user *uaddr = futex_uaddr(pending, futex_offset); - handle_futex_death(uaddr, curr, pip, HANDLE_DEATH_PENDING); + return handle_futex_death(uaddr, curr, pip, HANDLE_DEATH_PENDING); } + return true; } #endif @@ -1007,13 +1013,15 @@ static inline void exit_pi_state_list(struct task_struct *curr) { } static void futex_cleanup(struct task_struct *tsk) { if (unlikely(tsk->robust_list)) { - exit_robust_list(tsk); + if (!exit_robust_list(tsk)) + pr_info("futex: exit_robust_list failed"); tsk->robust_list = NULL; } #ifdef CONFIG_COMPAT if (unlikely(tsk->compat_robust_list)) { - compat_exit_robust_list(tsk); + if (!compat_exit_robust_list(tsk)) + pr_info("futex: compat_exit_robust_list failed"); tsk->compat_robust_list = NULL; } #endif From patchwork Thu Apr 21 19:05:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nico Pache X-Patchwork-Id: 12822281 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 423A7C433EF for ; Thu, 21 Apr 2022 19:06:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C4A896B0074; Thu, 21 Apr 2022 15:06:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD2FD6B0075; Thu, 21 Apr 2022 15:06:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A4CEF6B0078; Thu, 21 Apr 2022 15:06:01 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id 8BA106B0074 for ; Thu, 21 Apr 2022 15:06:01 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6254921547 for ; Thu, 21 Apr 2022 19:06:01 +0000 (UTC) X-FDA: 79381816122.09.836E9A5 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf13.hostedemail.com (Postfix) with ESMTP id 661082002F for ; Thu, 21 Apr 2022 19:05:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1650567960; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rCckTxEGpZ1EVMsAo2ha3TZ2uY37q9vb0mlqr9I+LWs=; b=ZH5NfegcnpjpOMGJp4ebjVdkrE/BV/BrUJl84y9Zi+CWErCo/hkDItqqsCIGAcxTdAKb1P N2QpgvF5g0VdFMvlspIlqh6Z2Ud3r7pGl9qrIlHSXsucEnT+gS9z0ys9HAgxCInydQ0WGW J4N4C6NSGIV0yEuVOW2AYT4gJyomfEY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-133-RCwAzGfcNrObe1TDu-_vuA-1; Thu, 21 Apr 2022 15:05:53 -0400 X-MC-Unique: RCwAzGfcNrObe1TDu-_vuA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 61D49811E9B; Thu, 21 Apr 2022 19:05:50 +0000 (UTC) Received: from localhost.localdomain.com (unknown [10.22.16.253]) by smtp.corp.redhat.com (Postfix) with ESMTP id 04D7EC27E81; Thu, 21 Apr 2022 19:05:48 +0000 (UTC) From: Nico Pache To: linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: David Rientjes , Michal Hocko , Andrea Arcangeli Subject: [RFC 3/3] exit: Check for MMF_OOM_SKIP in exit_mmap Date: Thu, 21 Apr 2022 15:05:33 -0400 Message-Id: <20220421190533.1601879-4-npache@redhat.com> In-Reply-To: <20220421190533.1601879-1-npache@redhat.com> References: <20220421190533.1601879-1-npache@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=ZH5Nfegc; spf=none (imf13.hostedemail.com: domain of npache@redhat.com has no SPF policy when checking 170.10.129.124) smtp.mailfrom=npache@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-Stat-Signature: 4shcqnr14f4tbw34rn5effroq1p7xtjf X-Rspamd-Queue-Id: 661082002F X-Rspamd-Server: rspam04 X-Rspam-User: X-HE-Tag: 1650567958-253752 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: The MMF_OOM_SKIP bit is used to indicate weather a mm_struct can not be invalided or has already been invalided. exit_mmap currently calls __oom_reap_task_mm unconditionally despite the fact that the oom reaper may have already called this. Add a check for the MMF_OOM_SKIP bit being set in exit_mmap to avoid unnessary calls to the invalidate code. A slight race can occur on the MMF_OOM_SKIP bit that will still allow this to run twice. My testing has shown an ~66% decrease in double calls to _oom_reap_task_mm. Fixes: 27ae357fa82b ("mm, oom: fix concurrent munlock and oom reaper unmap, v3") Cc: David Rientjes Cc: Michal Hocko Cc: Andrea Arcangeli Signed-off-by: Nico Pache --- mm/mmap.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/mmap.c b/mm/mmap.c index a2968669fd4e..b867f408dacd 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -3113,7 +3113,8 @@ void exit_mmap(struct mm_struct *mm) /* mm's last user has gone, and its about to be pulled down */ mmu_notifier_release(mm); - if (unlikely(mm_is_oom_victim(mm))) { + if (unlikely(mm_is_oom_victim(mm)) && + !test_bit(MMF_OOM_SKIP, &mm->flags)) { /* * Manually reap the mm to free as much memory as possible. * Then, as the oom reaper does, set MMF_OOM_SKIP to disregard