Merge tag 'for-linus-hmm' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma
authorLinus Torvalds <torvalds@linux-foundation.org>
Mon, 15 Jul 2019 02:42:11 +0000 (19:42 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Mon, 15 Jul 2019 02:42:11 +0000 (19:42 -0700)
Pull HMM updates from Jason Gunthorpe:
 "Improvements and bug fixes for the hmm interface in the kernel:

   - Improve clarity, locking and APIs related to the 'hmm mirror'
     feature merged last cycle. In linux-next we now see AMDGPU and
     nouveau to be using this API.

   - Remove old or transitional hmm APIs. These are hold overs from the
     past with no users, or APIs that existed only to manage cross tree
     conflicts. There are still a few more of these cleanups that didn't
     make the merge window cut off.

   - Improve some core mm APIs:
       - export alloc_pages_vma() for driver use
       - refactor into devm_request_free_mem_region() to manage
         DEVICE_PRIVATE resource reservations
       - refactor duplicative driver code into the core dev_pagemap
         struct

   - Remove hmm wrappers of improved core mm APIs, instead have drivers
     use the simplified API directly

   - Remove DEVICE_PUBLIC

   - Simplify the kconfig flow for the hmm users and core code"

* tag 'for-linus-hmm' of git://git.kernel.org/pub/scm/linux/kernel/git/rdma/rdma: (42 commits)
  mm: don't select MIGRATE_VMA_HELPER from HMM_MIRROR
  mm: remove the HMM config option
  mm: sort out the DEVICE_PRIVATE Kconfig mess
  mm: simplify ZONE_DEVICE page private data
  mm: remove hmm_devmem_add
  mm: remove hmm_vma_alloc_locked_page
  nouveau: use devm_memremap_pages directly
  nouveau: use alloc_page_vma directly
  PCI/P2PDMA: use the dev_pagemap internal refcount
  device-dax: use the dev_pagemap internal refcount
  memremap: provide an optional internal refcount in struct dev_pagemap
  memremap: replace the altmap_valid field with a PGMAP_ALTMAP_VALID flag
  memremap: remove the data field in struct dev_pagemap
  memremap: add a migrate_to_ram method to struct dev_pagemap_ops
  memremap: lift the devmap_enable manipulation into devm_memremap_pages
  memremap: pass a struct dev_pagemap to ->kill and ->cleanup
  memremap: move dev_pagemap callbacks into a separate structure
  memremap: validate the pagemap type passed to devm_memremap_pages
  mm: factor out a devm_request_free_mem_region helper
  mm: export alloc_pages_vma
  ...

15 files changed:
1  2 
arch/powerpc/mm/mem.c
fs/proc/task_mmu.c
include/linux/ioport.h
include/linux/mm.h
include/linux/mm_types.h
kernel/fork.c
mm/Kconfig
mm/Makefile
mm/gup.c
mm/hmm.c
mm/memcontrol.c
mm/memory-failure.c
mm/memory.c
mm/migrate.c
mm/page_alloc.c

Simple merge
Simple merge
index 5db386cfc2d48d34e34352e8b6a202a33b05840c,a02b290ca08a29676c9c1e5ca7e0c2feb062ffce..5b6a7121c9f09376bb3c780051cda4891c6c98c8
@@@ -133,16 -132,6 +133,15 @@@ enum 
        IORES_DESC_PERSISTENT_MEMORY            = 4,
        IORES_DESC_PERSISTENT_MEMORY_LEGACY     = 5,
        IORES_DESC_DEVICE_PRIVATE_MEMORY        = 6,
-       IORES_DESC_DEVICE_PUBLIC_MEMORY         = 7,
-       IORES_DESC_RESERVED                     = 8,
++      IORES_DESC_RESERVED                     = 7,
 +};
 +
 +/*
 + * Flags controlling ioremap() behavior.
 + */
 +enum {
 +      IORES_MAP_SYSTEM_RAM            = BIT(0),
 +      IORES_MAP_ENCRYPTED             = BIT(1),
  };
  
  /* helpers to define resources */
Simple merge
Simple merge
diff --cc kernel/fork.c
Simple merge
diff --cc mm/Kconfig
Simple merge
diff --cc mm/Makefile
Simple merge
diff --cc mm/gup.c
Simple merge
diff --cc mm/hmm.c
index f702a3895d05d828dba9e59198c0914f8b5f5a72,d48b9283725a907e8054a9906e79c16560b0ab9b..e1eedef129cf5c3425cb5d709b42910cb5409e43
+++ b/mm/hmm.c
@@@ -54,11 -42,16 +42,16 @@@ static const struct mmu_notifier_ops hm
   */
  static struct hmm *hmm_get_or_create(struct mm_struct *mm)
  {
-       struct hmm *hmm = mm_get_hmm(mm);
-       bool cleanup = false;
+       struct hmm *hmm;
  
-       if (hmm)
-               return hmm;
 -      lockdep_assert_held_exclusive(&mm->mmap_sem);
++      lockdep_assert_held_write(&mm->mmap_sem);
+       /* Abuse the page_table_lock to also protect mm->hmm. */
+       spin_lock(&mm->page_table_lock);
+       hmm = mm->hmm;
+       if (mm->hmm && kref_get_unless_zero(&mm->hmm->kref))
+               goto out_unlock;
+       spin_unlock(&mm->page_table_lock);
  
        hmm = kmalloc(sizeof(*hmm), GFP_KERNEL);
        if (!hmm)
@@@ -277,8 -245,8 +245,8 @@@ static const struct mmu_notifier_ops hm
   */
  int hmm_mirror_register(struct hmm_mirror *mirror, struct mm_struct *mm)
  {
 -      lockdep_assert_held_exclusive(&mm->mmap_sem);
++      lockdep_assert_held_write(&mm->mmap_sem);
        /* Sanity check */
        if (!mm || !mirror || !mirror->ops)
                return -EINVAL;
diff --cc mm/memcontrol.c
Simple merge
Simple merge
diff --cc mm/memory.c
Simple merge
diff --cc mm/migrate.c
Simple merge
diff --cc mm/page_alloc.c
Simple merge