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 */
 
   */
  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)
   */
  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;