From patchwork Wed Jan 25 23:35:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Suren Baghdasaryan X-Patchwork-Id: 13116401 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 58636C54E94 for ; Wed, 25 Jan 2023 23:36:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 801086B0074; Wed, 25 Jan 2023 18:36:01 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7B0D76B0075; Wed, 25 Jan 2023 18:36:01 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 651396B0078; Wed, 25 Jan 2023 18:36:01 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 523686B0074 for ; Wed, 25 Jan 2023 18:36:01 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 2665116090A for ; Wed, 25 Jan 2023 23:36:01 +0000 (UTC) X-FDA: 80394931722.19.06BEB23 Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf09.hostedemail.com (Postfix) with ESMTP id 71AB2140016 for ; Wed, 25 Jan 2023 23:35:59 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=RbwMwJ+b; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 33rzRYwYKCMM130nwkpxxpun.lxvurw36-vvt4jlt.x0p@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=33rzRYwYKCMM130nwkpxxpun.lxvurw36-vvt4jlt.x0p@flex--surenb.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674689759; 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: references:dkim-signature; bh=NqN2bLiUSb1ymI8eG/eIv8zLvJCLcEgdnVFKpDVDLGk=; b=z2wySrf5FlGb1ZtjsPS2japwULIVWUl/if4tEbUVqbGAdU395aRtiX613YjdyQBFgiT0mj kyoIpPEv9a8wgfdC43kdQw2QXCCfv+/iUYpWbuE8kP1xErAcsmYamIcO23lkszw/hxd8VO l/BC3l/DVnWzHDW4al/ZdXPddD5gIuI= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=RbwMwJ+b; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf09.hostedemail.com: domain of 33rzRYwYKCMM130nwkpxxpun.lxvurw36-vvt4jlt.x0p@flex--surenb.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=33rzRYwYKCMM130nwkpxxpun.lxvurw36-vvt4jlt.x0p@flex--surenb.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674689759; a=rsa-sha256; cv=none; b=YbgO2bTVlbhyu+BnXKMF6zVzHmwToaAiJ5voNh7k+uVpowZEg08kAmDRr+v5MHla6o7rzs 2kbIXa6f1GO6NY63mzsuXL+t97fBA3flHcdsYplWXC4yZsMv1hnI+qU4OAf7XeEFtb6Soo fyAHaaRbze/tzMbtJfHRTl0C4fgFINY= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-5062f3a2977so1143407b3.21 for ; Wed, 25 Jan 2023 15:35:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=NqN2bLiUSb1ymI8eG/eIv8zLvJCLcEgdnVFKpDVDLGk=; b=RbwMwJ+b6j9fhzlZ1IAdL1jD5NRV7iTt+IzqMMe8iCvTCJENwmR1n5f3o0lS+JSKjF H+TdrgNfgkr4VyeT0CiHFabaALTt3S2XmQjvtFbLKKzdOcv7M7yseF2d3tWOm7B6ZbJ5 p4aPQ09ns3CsutdoRWjtP35i04oTdfx3JHmTXY0hWy2imo2zUCcqoxPrY4HmJ+hqg/YD ftqr2vSnM2vUTaLhKYvREj1fy12BxiQ8T3bOIf2uQrw4BYKgJeYdlpTjoH2RRaxvxRUA RFl7sU7RUY4huRX6Jrtti40j9HesmqDeM4VaSBub+FpMHilEvWIAMTs2Ebm4fUipggdd 5jHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=NqN2bLiUSb1ymI8eG/eIv8zLvJCLcEgdnVFKpDVDLGk=; b=RQJAl6m8E3AMhytJu2xoFfS6BtD/VzN63Mt8cpoeLAXydwkvDsd1QrsvYsqg1rY5mg 8RPSO1qQcw2I7mI9B4TOHRJHHUqBEAyDVwBkwQMCN3Eqi0Iw6XLdeE4c+daf+g8Hi6Ee NsHuHITGHGVrpJbq+4qVksuPBfyTdyRkiLHqzveXmm4Hzz9dHrofYsQf6alyiSNgF+0o PVfMiLu8zF4/BKS1RVdLv07Rd5tuA3NzHWD/B1zIYzZpR63l9Qa9bgNMYNK+zMH/orAY 3J4a8Dvwp+B9TK/0hgrybC2Y20IJ8jVQ0U6mi3pOoxtorIK7EJBqOWoNEF4Il3bsqqbe 2gdA== X-Gm-Message-State: AO0yUKUDa1rw/lZhLImIpazEbj0Z9KxvivVClvtvDZgOQ6aBptzCiezQ 1cOFEXLQCoHpZq5RGxCdDRHwAePAses= X-Google-Smtp-Source: AK7set+63CutG2et9ZbZuyKw0FszIXTAu/Eg7+GQi/bYSVlch14wD2gXCpmM/82+X+UTHdXJ/P4yCFg0YzQ= X-Received: from surenb-desktop.mtv.corp.google.com ([2620:15c:211:200:f7b0:20e8:ce66:f98]) (user=surenb job=sendgmr) by 2002:a81:6946:0:b0:506:527a:5146 with SMTP id e67-20020a816946000000b00506527a5146mr698746ywc.178.1674689758527; Wed, 25 Jan 2023 15:35:58 -0800 (PST) Date: Wed, 25 Jan 2023 15:35:47 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Message-ID: <20230125233554.153109-1-surenb@google.com> Subject: [PATCH v3 0/7] introduce vm_flags modifier functions From: Suren Baghdasaryan To: akpm@linux-foundation.org Cc: michel@lespinasse.org, jglisse@google.com, mhocko@suse.com, vbabka@suse.cz, hannes@cmpxchg.org, mgorman@techsingularity.net, dave@stgolabs.net, willy@infradead.org, liam.howlett@oracle.com, peterz@infradead.org, ldufour@linux.ibm.com, paulmck@kernel.org, mingo@redhat.com, will@kernel.org, luto@kernel.org, songliubraving@fb.com, peterx@redhat.com, david@redhat.com, dhowells@redhat.com, hughd@google.com, bigeasy@linutronix.de, kent.overstreet@linux.dev, punit.agrawal@bytedance.com, lstoakes@gmail.com, peterjung1337@gmail.com, rientjes@google.com, axelrasmussen@google.com, joelaf@google.com, minchan@google.com, jannh@google.com, shakeelb@google.com, tatashin@google.com, edumazet@google.com, gthelen@google.com, gurua@google.com, arjunroy@google.com, soheil@google.com, hughlynch@google.com, leewalsh@google.com, posk@google.com, linux-mm@kvack.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, x86@kernel.org, linux-kernel@vger.kernel.org, kernel-team@android.com, surenb@google.com X-Rspamd-Queue-Id: 71AB2140016 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: kcm7e3m8fmyephf9wnqsaafz9biejdxp X-HE-Tag: 1674689759-223462 X-HE-Meta: U2FsdGVkX19SYGcfBbO6FAz8tRUvOUE2HRHFj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0w6LhRmqo8ClAzaJUWQQPhwogE+Ulxbi+Z4ii891iwMzR1zjEJsGxdSp/0kiHaqzfWy4SlGweLQBvPwMAueUxzsHvA+oHtMa5SXJLhSscTe2/2KclQUBfrDpidVRh4WynKN9hvQMuoyEE3M/wLOII2sXHmUIn7okpYM7Rl5WnWu/n8c7kv6mVaUTlYjmYZI+knVOsK6elGj3CUzNlDor6Zd3DCTSZDc02E2/OfgJ/ghuzAM029tXRjdb2X/tcrr7F7fl9q4NiS/7ETT53kwiVUmOB3voqigRpQjHj5505fLDxKiuO86og7bZgd08l4c6eNL+usETBy72UKexUZyFqAxiRHIzLPwrSOMqrw7IYHsOCxcrowzMPMaTFXQwMbiX1AwYrH3LuJbFKiT4WpwOFcNGuK+xTCigQARYDNb3SqcLvMLZJFVGJ4mZZL///nPtlltECPSnOXM9xFASzWTRLpGWeT5REwhPHmxy7lU73uS71Od05LtqVEKo701ZnGOF1XR7JzfcvOSBnOWHGSthEKdCHcGPz354yu624QT0Ii6uUNRyvypGe5KLNM4PhHQJAIjR98FowSI/z3qNIjcewPfkjkBAz3COHX+LFO1xK16fGWhQmOzyFN4= 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: This patchset was originally published as a part of per-VMA locking [1] and was split after suggestion that it's viable on its own and to facilitate the review process. It is now a preprequisite for the next version of per-VMA lock patchset, which reuses vm_flags modifier functions to lock the VMA when vm_flags are being updated. VMA vm_flags modifications are usually done under exclusive mmap_lock protection because this attrubute affects other decisions like VMA merging or splitting and races should be prevented. Introduce vm_flags modifier functions to enforce correct locking. The patchset applies cleanly over mm-unstable branch of mm tree. My apologies for an extremely large distribution list. The patch touches lots of files and many are in arch/ and drivers/. Changes since v2 [2] - Add an additional patch to convert vma assignment to a memcpy. - Change vm_flags to a union of __private and const fields, per Peter Zijlstra and Matthew Wilcox. - Changed vm_flags type to vm_flags_t, per Matthew Wilcox. - Removed unnecessary BUG_ON's from ksm_madvise and hugepage_madvise, per Michal Hocko. - Documented mod_vm_flags_nolock usage, per Michal Hocko. [1] https://lore.kernel.org/all/20230109205336.3665937-1-surenb@google.com/ [2] https://lore.kernel.org/lkml/20230125083851.27759-1-surenb@google.com/ Suren Baghdasaryan (7): kernel/fork: convert vma assignment to a memcpy mm: introduce vma->vm_flags wrapper functions mm: replace VM_LOCKED_CLEAR_MASK with VM_LOCKED_MASK mm: replace vma->vm_flags direct modifications with modifier calls mm: replace vma->vm_flags indirect modification in ksm_madvise mm: introduce mod_vm_flags_nolock and use it in untrack_pfn mm: export dump_mm() arch/arm/kernel/process.c | 2 +- arch/ia64/mm/init.c | 8 +-- arch/loongarch/include/asm/tlb.h | 2 +- arch/powerpc/kvm/book3s_hv_uvmem.c | 5 +- arch/powerpc/kvm/book3s_xive_native.c | 2 +- arch/powerpc/mm/book3s64/subpage_prot.c | 2 +- arch/powerpc/platforms/book3s/vas-api.c | 2 +- arch/powerpc/platforms/cell/spufs/file.c | 14 ++--- arch/s390/mm/gmap.c | 8 ++- arch/x86/entry/vsyscall/vsyscall_64.c | 2 +- arch/x86/kernel/cpu/sgx/driver.c | 2 +- arch/x86/kernel/cpu/sgx/virt.c | 2 +- arch/x86/mm/pat/memtype.c | 14 +++-- arch/x86/um/mem_32.c | 2 +- drivers/acpi/pfr_telemetry.c | 2 +- drivers/android/binder.c | 3 +- drivers/char/mspec.c | 2 +- drivers/crypto/hisilicon/qm.c | 2 +- drivers/dax/device.c | 2 +- drivers/dma/idxd/cdev.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 4 +- drivers/gpu/drm/amd/amdkfd/kfd_doorbell.c | 4 +- drivers/gpu/drm/amd/amdkfd/kfd_events.c | 4 +- drivers/gpu/drm/amd/amdkfd/kfd_process.c | 4 +- drivers/gpu/drm/drm_gem.c | 2 +- drivers/gpu/drm/drm_gem_dma_helper.c | 3 +- drivers/gpu/drm/drm_gem_shmem_helper.c | 2 +- drivers/gpu/drm/drm_vm.c | 8 +-- drivers/gpu/drm/etnaviv/etnaviv_gem.c | 2 +- drivers/gpu/drm/exynos/exynos_drm_gem.c | 4 +- drivers/gpu/drm/gma500/framebuffer.c | 2 +- drivers/gpu/drm/i810/i810_dma.c | 2 +- drivers/gpu/drm/i915/gem/i915_gem_mman.c | 4 +- drivers/gpu/drm/mediatek/mtk_drm_gem.c | 2 +- drivers/gpu/drm/msm/msm_gem.c | 2 +- drivers/gpu/drm/omapdrm/omap_gem.c | 3 +- drivers/gpu/drm/rockchip/rockchip_drm_gem.c | 3 +- drivers/gpu/drm/tegra/gem.c | 5 +- drivers/gpu/drm/ttm/ttm_bo_vm.c | 3 +- drivers/gpu/drm/virtio/virtgpu_vram.c | 2 +- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 2 +- drivers/gpu/drm/xen/xen_drm_front_gem.c | 3 +- drivers/hsi/clients/cmt_speech.c | 2 +- drivers/hwtracing/intel_th/msu.c | 2 +- drivers/hwtracing/stm/core.c | 2 +- drivers/infiniband/hw/hfi1/file_ops.c | 4 +- drivers/infiniband/hw/mlx5/main.c | 4 +- drivers/infiniband/hw/qib/qib_file_ops.c | 13 ++--- drivers/infiniband/hw/usnic/usnic_ib_verbs.c | 2 +- .../infiniband/hw/vmw_pvrdma/pvrdma_verbs.c | 2 +- .../common/videobuf2/videobuf2-dma-contig.c | 2 +- .../common/videobuf2/videobuf2-vmalloc.c | 2 +- drivers/media/v4l2-core/videobuf-dma-contig.c | 2 +- drivers/media/v4l2-core/videobuf-dma-sg.c | 4 +- drivers/media/v4l2-core/videobuf-vmalloc.c | 2 +- drivers/misc/cxl/context.c | 2 +- drivers/misc/habanalabs/common/memory.c | 2 +- drivers/misc/habanalabs/gaudi/gaudi.c | 4 +- drivers/misc/habanalabs/gaudi2/gaudi2.c | 8 +-- drivers/misc/habanalabs/goya/goya.c | 4 +- drivers/misc/ocxl/context.c | 4 +- drivers/misc/ocxl/sysfs.c | 2 +- drivers/misc/open-dice.c | 4 +- drivers/misc/sgi-gru/grufile.c | 4 +- drivers/misc/uacce/uacce.c | 2 +- drivers/sbus/char/oradax.c | 2 +- drivers/scsi/cxlflash/ocxl_hw.c | 2 +- drivers/scsi/sg.c | 2 +- .../staging/media/atomisp/pci/hmm/hmm_bo.c | 2 +- drivers/staging/media/deprecated/meye/meye.c | 4 +- .../media/deprecated/stkwebcam/stk-webcam.c | 2 +- drivers/target/target_core_user.c | 2 +- drivers/uio/uio.c | 2 +- drivers/usb/core/devio.c | 3 +- drivers/usb/mon/mon_bin.c | 3 +- drivers/vdpa/vdpa_user/iova_domain.c | 2 +- drivers/vfio/pci/vfio_pci_core.c | 2 +- drivers/vhost/vdpa.c | 2 +- drivers/video/fbdev/68328fb.c | 2 +- drivers/video/fbdev/core/fb_defio.c | 4 +- drivers/xen/gntalloc.c | 2 +- drivers/xen/gntdev.c | 4 +- drivers/xen/privcmd-buf.c | 2 +- drivers/xen/privcmd.c | 4 +- fs/aio.c | 2 +- fs/cramfs/inode.c | 2 +- fs/erofs/data.c | 2 +- fs/exec.c | 4 +- fs/ext4/file.c | 2 +- fs/fuse/dax.c | 2 +- fs/hugetlbfs/inode.c | 4 +- fs/orangefs/file.c | 3 +- fs/proc/task_mmu.c | 2 +- fs/proc/vmcore.c | 3 +- fs/userfaultfd.c | 2 +- fs/xfs/xfs_file.c | 2 +- include/linux/mm.h | 55 +++++++++++++++++-- include/linux/mm_types.h | 10 +++- include/linux/pgtable.h | 5 +- kernel/bpf/ringbuf.c | 4 +- kernel/bpf/syscall.c | 4 +- kernel/events/core.c | 2 +- kernel/fork.c | 4 +- kernel/kcov.c | 2 +- kernel/relay.c | 2 +- mm/debug.c | 1 + mm/hugetlb.c | 4 +- mm/madvise.c | 2 +- mm/memory.c | 19 ++++--- mm/memremap.c | 4 +- mm/mlock.c | 12 ++-- mm/mmap.c | 32 ++++++----- mm/mprotect.c | 2 +- mm/mremap.c | 8 +-- mm/nommu.c | 11 ++-- mm/secretmem.c | 2 +- mm/shmem.c | 2 +- mm/vmalloc.c | 2 +- net/ipv4/tcp.c | 4 +- security/selinux/selinuxfs.c | 6 +- sound/core/oss/pcm_oss.c | 2 +- sound/core/pcm_native.c | 9 +-- sound/soc/pxa/mmp-sspa.c | 2 +- sound/usb/usx2y/us122l.c | 4 +- sound/usb/usx2y/usX2Yhwdep.c | 2 +- sound/usb/usx2y/usx2yhwdeppcm.c | 2 +- 127 files changed, 295 insertions(+), 234 deletions(-)