From mboxrd@z Thu Jan 1 00:00:00 1970 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 95980C369DC for ; Mon, 28 Apr 2025 20:01:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 36C9E6B002E; Mon, 28 Apr 2025 16:01:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2F1E46B0083; Mon, 28 Apr 2025 16:01:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 16B826B0085; Mon, 28 Apr 2025 16:01:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E34226B002E for ; Mon, 28 Apr 2025 16:01:10 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 79090813CA for ; Mon, 28 Apr 2025 20:01:12 +0000 (UTC) X-FDA: 83384521584.20.196ED0D Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) by imf29.hostedemail.com (Postfix) with ESMTP id 9B6BB120008 for ; Mon, 28 Apr 2025 20:01:10 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=YVCjJnyC; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of surenb@google.com designates 209.85.160.181 as permitted sender) smtp.mailfrom=surenb@google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1745870470; a=rsa-sha256; cv=none; b=F2ps6sEMxW8pvavIcPe72hEhpnczBNyook+mAqlSN1NpueIVu4mLaslVDrN+Hj07eivZJ7 uC26KjHboU8uxRPekhCKcWvRG29vPYJ+56teBhfKljmmfNymso+p3KoY46TXsUnM4yLsez A/6CWjPVc1rkKnaQwK3bBPsyL9hruMc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1745870470; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=VJybhQX+mtsA+JCLNM6FgFt4VcVPgczSDExJzTxfhFQ=; b=imWjDw2R7rJm+bjrB1Knz7rBFJ0Upl7jSvEKD1lCLpB6imMuAQwDeb+sW/HN3kFST661WQ O9uMNEQNM6GlBFpDy9ck2yiwP5Y1zsPSIlup7VOXIkYLl0trMEt9AVqggGNjx6ydUG+tr2 ncuHuZFhkXrP1iIZUXIAOXlc25u18z4= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=YVCjJnyC; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf29.hostedemail.com: domain of surenb@google.com designates 209.85.160.181 as permitted sender) smtp.mailfrom=surenb@google.com Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-4774611d40bso63191cf.0 for ; Mon, 28 Apr 2025 13:01:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1745870470; x=1746475270; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=VJybhQX+mtsA+JCLNM6FgFt4VcVPgczSDExJzTxfhFQ=; b=YVCjJnyCMwODIYOCuHzhkJheEY/sKbcv11dIs5NpriP8I9Ji19/79giAUKyygxCr7K jLkik7Fig8ltwN460M6BO11AwvzECqDvy6hqs9Z2HSNWuYP1A7TUkU3/siOgq3MFW4MC ScVN7DCzwgVj2a+RuvQSFKEtpV+ksOHOIMXGChcdKqdhb0I+e+xVbwD9gVl2tZmRwweg Tad6OvAf1eIq2GcoGe1VWzq0g62L1crnYqtR7u+iCdJoWy3HS9d+y5YluiRpMvZHpoMk zZcQ+NctyvBQLvzJu3LPKKI2WrwcDzQ+Uy+lWaZlvr6WIKXrKhnrgzQxaM/9vYbZ4GQw 0ToA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1745870470; x=1746475270; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VJybhQX+mtsA+JCLNM6FgFt4VcVPgczSDExJzTxfhFQ=; b=CZNcGHO0cqLxa+qObNbGGjvEr2cBenqD+heB9HGxCa+ARoHfQpL6JDXRbjCHopHtFu FKo28nsrjAn5ZsA3fvy8roTz02wwE+szbAsk3mjUo8NiW0S9p5UfhubO/1aUxnBZ5IZk MvRwX32kuqaree4S7f6Wamgn6SsAJE0uWTHqV8tFL1/mqEC+5TnQCzP/bdEi5zZowjxe qkYlBPoNfNusMJFX40QX1PSU4EDa2TdIs9KwLi/VPow6tEAjdzq5VHFKJ5RLZS2Jo+N6 AAfHYhbcabE2wo5erSttKdoysDFLarW2Em91lqd8jajEj+yHYXj9Q3ZpclB6f/loPCTx EaUA== X-Forwarded-Encrypted: i=1; AJvYcCXDNnZknSz5LL+U/2Q8PFPhUbufTAMJKsRSbg7pGRtgkkgBADkaXfTtxn0woCK1xPE1bTI63xtrfw==@kvack.org X-Gm-Message-State: AOJu0YxnEJ2kZMPSu88EllBa+EMu7BxS2xY/0p2/mNRMefA6iELvS9vI lUnfSazCVHM2TCgt/UXfOndwYAryiViyHDe1GRNHas3r5rcd7tpOw8910VfGFk3AhNf/v364tRH b7AErUGFWYtZaudWqvRGVAMPSMIKlmnYaNoiT X-Gm-Gg: ASbGncsIS7KgEkJsp/nRQxk67tV/fNH9wnFio7gdzV/7azDzecwc4A58z9W+3k3lAB6 53zXi839R/2TSDlZPnF0tAOednuYW+klr4YrE55grPNvj6k1fj9cZ7HqavZbAjt0gNcTz4+yLZv LN79jwstvIS8NPBc2oY+J+ X-Google-Smtp-Source: AGHT+IGGX805tNN1FfFiEFOchaakv5NY8Ys+vkzyi3lPHWYF87xZoteOkyrR931CQ/lcrijlBEjyDE79ZFOslGdLmbQ= X-Received: by 2002:a05:622a:54e:b0:47b:840:7f5b with SMTP id d75a77b69052e-48866bc4b7cmr724121cf.29.1745870469322; Mon, 28 Apr 2025 13:01:09 -0700 (PDT) MIME-Version: 1.0 References: <20250425081715.1341199-1-david@redhat.com> <20250425081715.1341199-6-david@redhat.com> <8131940c-8b22-4856-947b-62ca64e2f417@lucifer.local> In-Reply-To: <8131940c-8b22-4856-947b-62ca64e2f417@lucifer.local> From: Suren Baghdasaryan Date: Mon, 28 Apr 2025 13:00:58 -0700 X-Gm-Features: ATxdqUHOhJ-hIQqSTjS_MDyVVtLFB6JwqHLrl6lHfgnOs5bz7Sa9PO5BAiYKY_U Message-ID: Subject: Re: [PATCH v1 05/11] mm: convert VM_PFNMAP tracking to pfnmap_track() + pfnmap_untrack() To: Lorenzo Stoakes Cc: David Hildenbrand , linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-trace-kernel@vger.kernel.org, Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Tvrtko Ursulin , David Airlie , Simona Vetter , Andrew Morton , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , "Liam R. Howlett" , Vlastimil Babka , Jann Horn , Pedro Falcato , Peter Xu Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9B6BB120008 X-Stat-Signature: emj7t6564f149wsem87moqr7fpjz5dec X-Rspam-User: X-HE-Tag: 1745870470-204779 X-HE-Meta: U2FsdGVkX1+Pxjfmmu8hxgsAB2YzBTk/f1shwcsg4FKsbpXPJZsYEwX3JUV+q/vneaKMgf/4uWtxx95dWKBub4Fn0cVPq6pL9JLzYxabXmELE20DhVNGpi1KbaWTDHnic4wQkjl/WXBT7LPXUFsnLM0yFHw/uPeWq6OF1X6FNTPFNl6IiW6AwwwoOLy6gNQL/TXfkvmsnC5E6kOZ/tgLdo2qD/vNknWyiVgYlgO6bY4ilx44WpoOYKt8zeDpGJh0iADrbDJkju0srrGBEUK4ZIqu063m0Qmz1Ah/YxkXbALI0HKpdGaiBDb/jHHWik6l2O+vVqR3ZoQsX0AYjfCiYTd8Xlvsbszqt1P79I6IuTbAkKgCV1CNXpf3uZlttWTjHAiXt5OjMNJAA+KQorPodC77lYp1rQinr6pIllSD7588djgkbHOtNAffx2LmQh9uIApHE7IoTgerCMham47qPtTaxjGLwt3u/2ruBR4ddnIgIbkitdjKNzQY5cD6rbBC0aFJx5aVnboA5zNKzjji5fZu20y30g4E+YjmK/0B7OVAh4s23UbnujkU+GnKlvDV5CRi/icgmvqeIxt26/3RR4Ph/1SRNpA856ERGG1fFTtmwPMVdNww7+3OWLnR67yutD89prdZRbUzH+3n6UvHDKSrLk3YXAc1zmRRyTdVgxrBvTfK6MyxO/8fL9AK3XCo+/gmmpUavwViepd/L0yZjHWilm/WKzkxwxoHnG1mkgHiJ9Axj0uhZHxoD5GEkn1hlGf7+aKFAXAlzRTrbKn0DTEZYAS5v0jS4+Heb4wEOS4L0mq3ZbwFXQKXUEjcMDs3hPoyle5HYus0HZNyz1oWtB68IfWa0KoK9e8bW5tV78Y0XbW3i/irEzR56/ioa1HHvS+Emoda+QCzy1uOHz56Jb9ObfDhvnTn38/HBdX50Z5CuS/sCItx/8e+V9UgOxvskZss5vXQFTuopQ/pyxr Gz35Z8rA ku9+lUwKnTqbMASFMZ+pPqrKGyIeyI40dsBaxQ7vMQIvxSITM4p9WPlbY9CIyBUlioALgIn3j/jmOVkbZnMzWMOHrQzRkyEabyoniCvbixfX1QP3e/rSHE6JBEKRxYdsfw7zEkaP41+v/N1PGpTWhMItd8BxWIndlZikV93rZgvkVf6l973DaEgWfst/+BgUk+6j9Jr/pI5BJzb7n8iSKK1p+lHGddmYtT2nQ6MPqvB04uv3vsWOU8mA7Qfx0TXI+KRJW5hvrZlNWvbwb5u0e9E6UjCGC9gE1Qi4s 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: List-Subscribe: List-Unsubscribe: On Mon, Apr 28, 2025 at 12:47=E2=80=AFPM Lorenzo Stoakes wrote: > > +cc Suren, who has worked HEAVILY on VMA field manipulation and such :) > > Suren - David is proposing adding a new field. AFAICT this does not add a > new cache line so I think we're all good. > > But FYI! Thanks! Yes, there should be some space in the last cacheline after my last field reshuffling. > > On Fri, Apr 25, 2025 at 10:17:09AM +0200, David Hildenbrand wrote: > > Let's use our new interface. In remap_pfn_range(), we'll now decide > > whether we have to track (full VMA covered) or only sanitize the pgprot > > (partial VMA covered). > > > > Remember what we have to untrack by linking it from the VMA. When > > duplicating VMAs (e.g., splitting, mremap, fork), we'll handle it simil= ar > > to anon VMA names, and use a kref to share the tracking. > > > > Once the last VMA un-refs our tracking data, we'll do the untracking, > > which simplifies things a lot and should sort our various issues we saw > > recently, for example, when partially unmapping/zapping a tracked VMA. > > > > This change implies that we'll keep tracking the original PFN range eve= n > > after splitting + partially unmapping it: not too bad, because it was > > not working reliably before. The only thing that kind-of worked before > > was shrinking such a mapping using mremap(): we managed to adjust the > > reservation in a hacky way, now we won't adjust the reservation but > > leave it around until all involved VMAs are gone. > > > > Signed-off-by: David Hildenbrand > > --- > > include/linux/mm_inline.h | 2 + > > include/linux/mm_types.h | 11 ++++++ > > kernel/fork.c | 54 ++++++++++++++++++++++++-- > > mm/memory.c | 81 +++++++++++++++++++++++++++++++-------- > > mm/mremap.c | 4 -- > > 5 files changed, 128 insertions(+), 24 deletions(-) > > > > diff --git a/include/linux/mm_inline.h b/include/linux/mm_inline.h > > index f9157a0c42a5c..89b518ff097e6 100644 > > --- a/include/linux/mm_inline.h > > +++ b/include/linux/mm_inline.h > > @@ -447,6 +447,8 @@ static inline bool anon_vma_name_eq(struct anon_vma= _name *anon_name1, > > > > #endif /* CONFIG_ANON_VMA_NAME */ > > > > +void pfnmap_track_ctx_release(struct kref *ref); > > + > > static inline void init_tlb_flush_pending(struct mm_struct *mm) > > { > > atomic_set(&mm->tlb_flush_pending, 0); > > diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h > > index 56d07edd01f91..91124761cfda8 100644 > > --- a/include/linux/mm_types.h > > +++ b/include/linux/mm_types.h > > @@ -764,6 +764,14 @@ struct vma_numab_state { > > int prev_scan_seq; > > }; > > > > +#ifdef __HAVE_PFNMAP_TRACKING > > +struct pfnmap_track_ctx { > > + struct kref kref; > > + unsigned long pfn; > > + unsigned long size; > > +}; > > +#endif > > + > > /* > > * This struct describes a virtual memory area. There is one of these > > * per VM-area/task. A VM area is any part of the process virtual memo= ry > > @@ -877,6 +885,9 @@ struct vm_area_struct { > > struct anon_vma_name *anon_name; > > #endif > > struct vm_userfaultfd_ctx vm_userfaultfd_ctx; > > +#ifdef __HAVE_PFNMAP_TRACKING > > + struct pfnmap_track_ctx *pfnmap_track_ctx; > > +#endif > > } __randomize_layout; > > > > #ifdef CONFIG_NUMA > > diff --git a/kernel/fork.c b/kernel/fork.c > > index 168681fc4b25a..ae518b8fe752c 100644 > > --- a/kernel/fork.c > > +++ b/kernel/fork.c > > @@ -481,7 +481,51 @@ static void vm_area_init_from(const struct vm_area= _struct *src, > > #ifdef CONFIG_NUMA > > dest->vm_policy =3D src->vm_policy; > > #endif > > +#ifdef __HAVE_PFNMAP_TRACKING > > + dest->pfnmap_track_ctx =3D NULL; > > +#endif > > +} > > + > > +#ifdef __HAVE_PFNMAP_TRACKING > > +static inline int vma_pfnmap_track_ctx_dup(struct vm_area_struct *orig= , > > + struct vm_area_struct *new) > > +{ > > + struct pfnmap_track_ctx *ctx =3D orig->pfnmap_track_ctx; > > + > > + if (likely(!ctx)) > > + return 0; > > + > > + /* > > + * We don't expect to ever hit this. If ever required, we would h= ave > > + * to duplicate the tracking. > > + */ > > + if (unlikely(kref_read(&ctx->kref) >=3D REFCOUNT_MAX)) > > + return -ENOMEM; > > + kref_get(&ctx->kref); > > + new->pfnmap_track_ctx =3D ctx; > > + return 0; > > +} > > + > > +static inline void vma_pfnmap_track_ctx_release(struct vm_area_struct = *vma) > > +{ > > + struct pfnmap_track_ctx *ctx =3D vma->pfnmap_track_ctx; > > + > > + if (likely(!ctx)) > > + return; > > + > > + kref_put(&ctx->kref, pfnmap_track_ctx_release); > > + vma->pfnmap_track_ctx =3D NULL; > > +} > > +#else > > +static inline int vma_pfnmap_track_ctx_dup(struct vm_area_struct *orig= , > > + struct vm_area_struct *new) > > +{ > > + return 0; > > } > > +static inline void vma_pfnmap_track_ctx_release(struct vm_area_struct = *vma) > > +{ > > +} > > +#endif > > > > struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) > > { > > @@ -493,6 +537,11 @@ struct vm_area_struct *vm_area_dup(struct vm_area_= struct *orig) > > ASSERT_EXCLUSIVE_WRITER(orig->vm_flags); > > ASSERT_EXCLUSIVE_WRITER(orig->vm_file); > > vm_area_init_from(orig, new); > > + > > + if (vma_pfnmap_track_ctx_dup(orig, new)) { > > + kmem_cache_free(vm_area_cachep, new); > > + return NULL; > > + } > > vma_lock_init(new, true); > > INIT_LIST_HEAD(&new->anon_vma_chain); > > vma_numab_state_init(new); > > @@ -507,6 +556,7 @@ void vm_area_free(struct vm_area_struct *vma) > > vma_assert_detached(vma); > > vma_numab_state_free(vma); > > free_anon_vma_name(vma); > > + vma_pfnmap_track_ctx_release(vma); > > kmem_cache_free(vm_area_cachep, vma); > > } > > > > @@ -669,10 +719,6 @@ static __latent_entropy int dup_mmap(struct mm_str= uct *mm, > > if (!tmp) > > goto fail_nomem; > > > > - /* track_pfn_copy() will later take care of copying inter= nal state. */ > > - if (unlikely(tmp->vm_flags & VM_PFNMAP)) > > - untrack_pfn_clear(tmp); > > - > > retval =3D vma_dup_policy(mpnt, tmp); > > if (retval) > > goto fail_nomem_policy; > > diff --git a/mm/memory.c b/mm/memory.c > > index c737a8625866a..eb2b3f10a97ec 100644 > > --- a/mm/memory.c > > +++ b/mm/memory.c > > @@ -1370,7 +1370,7 @@ copy_page_range(struct vm_area_struct *dst_vma, s= truct vm_area_struct *src_vma) > > struct mm_struct *dst_mm =3D dst_vma->vm_mm; > > struct mm_struct *src_mm =3D src_vma->vm_mm; > > struct mmu_notifier_range range; > > - unsigned long next, pfn =3D 0; > > + unsigned long next; > > bool is_cow; > > int ret; > > > > @@ -1380,12 +1380,6 @@ copy_page_range(struct vm_area_struct *dst_vma, = struct vm_area_struct *src_vma) > > if (is_vm_hugetlb_page(src_vma)) > > return copy_hugetlb_page_range(dst_mm, src_mm, dst_vma, s= rc_vma); > > > > - if (unlikely(src_vma->vm_flags & VM_PFNMAP)) { > > - ret =3D track_pfn_copy(dst_vma, src_vma, &pfn); > > - if (ret) > > - return ret; > > - } > > - > > /* > > * We need to invalidate the secondary MMU mappings only when > > * there could be a permission downgrade on the ptes of the > > @@ -1427,8 +1421,6 @@ copy_page_range(struct vm_area_struct *dst_vma, s= truct vm_area_struct *src_vma) > > raw_write_seqcount_end(&src_mm->write_protect_seq); > > mmu_notifier_invalidate_range_end(&range); > > } > > - if (ret && unlikely(src_vma->vm_flags & VM_PFNMAP)) > > - untrack_pfn_copy(dst_vma, pfn); > > return ret; > > } > > > > @@ -1923,9 +1915,6 @@ static void unmap_single_vma(struct mmu_gather *t= lb, > > if (vma->vm_file) > > uprobe_munmap(vma, start, end); > > > > - if (unlikely(vma->vm_flags & VM_PFNMAP)) > > - untrack_pfn(vma, 0, 0, mm_wr_locked); > > - > > if (start !=3D end) { > > if (unlikely(is_vm_hugetlb_page(vma))) { > > /* > > @@ -2871,6 +2860,36 @@ int remap_pfn_range_notrack(struct vm_area_struc= t *vma, unsigned long addr, > > return error; > > } > > > > +#ifdef __HAVE_PFNMAP_TRACKING > > +static inline struct pfnmap_track_ctx *pfnmap_track_ctx_alloc(unsigned= long pfn, > > + unsigned long size, pgprot_t *prot) > > +{ > > + struct pfnmap_track_ctx *ctx; > > + > > + if (pfnmap_track(pfn, size, prot)) > > + return ERR_PTR(-EINVAL); > > + > > + ctx =3D kmalloc(sizeof(*ctx), GFP_KERNEL); > > + if (unlikely(!ctx)) { > > + pfnmap_untrack(pfn, size); > > + return ERR_PTR(-ENOMEM); > > + } > > + > > + ctx->pfn =3D pfn; > > + ctx->size =3D size; > > + kref_init(&ctx->kref); > > + return ctx; > > +} > > + > > +void pfnmap_track_ctx_release(struct kref *ref) > > +{ > > + struct pfnmap_track_ctx *ctx =3D container_of(ref, struct pfnmap_= track_ctx, kref); > > + > > + pfnmap_untrack(ctx->pfn, ctx->size); > > + kfree(ctx); > > +} > > +#endif /* __HAVE_PFNMAP_TRACKING */ > > + > > /** > > * remap_pfn_range - remap kernel memory to userspace > > * @vma: user vma to map to > > @@ -2883,20 +2902,50 @@ int remap_pfn_range_notrack(struct vm_area_stru= ct *vma, unsigned long addr, > > * > > * Return: %0 on success, negative error code otherwise. > > */ > > +#ifdef __HAVE_PFNMAP_TRACKING > > int remap_pfn_range(struct vm_area_struct *vma, unsigned long addr, > > unsigned long pfn, unsigned long size, pgprot_t prot) > > { > > + struct pfnmap_track_ctx *ctx =3D NULL; > > int err; > > > > - err =3D track_pfn_remap(vma, &prot, pfn, addr, PAGE_ALIGN(size)); > > - if (err) > > + size =3D PAGE_ALIGN(size); > > + > > + /* > > + * If we cover the full VMA, we'll perform actual tracking, and > > + * remember to untrack when the last reference to our tracking > > + * context from a VMA goes away. > > + * > > + * If we only cover parts of the VMA, we'll only sanitize the > > + * pgprot. > > + */ > > + if (addr =3D=3D vma->vm_start && addr + size =3D=3D vma->vm_end) = { > > + if (vma->pfnmap_track_ctx) > > + return -EINVAL; > > + ctx =3D pfnmap_track_ctx_alloc(pfn, size, &prot); > > + if (IS_ERR(ctx)) > > + return PTR_ERR(ctx); > > + } else if (pfnmap_sanitize_pgprot(pfn, size, &prot)) { > > return -EINVAL; > > + } > > > > err =3D remap_pfn_range_notrack(vma, addr, pfn, size, prot); > > - if (err) > > - untrack_pfn(vma, pfn, PAGE_ALIGN(size), true); > > + if (ctx) { > > + if (err) > > + kref_put(&ctx->kref, pfnmap_track_ctx_release); > > + else > > + vma->pfnmap_track_ctx =3D ctx; > > + } > > return err; > > } > > + > > +#else > > +int remap_pfn_range(struct vm_area_struct *vma, unsigned long addr, > > + unsigned long pfn, unsigned long size, pgprot_t prot) > > +{ > > + return remap_pfn_range_notrack(vma, addr, pfn, size, prot); > > +} > > +#endif > > EXPORT_SYMBOL(remap_pfn_range); > > > > /** > > diff --git a/mm/mremap.c b/mm/mremap.c > > index 7db9da609c84f..6e78e02f74bd3 100644 > > --- a/mm/mremap.c > > +++ b/mm/mremap.c > > @@ -1191,10 +1191,6 @@ static int copy_vma_and_data(struct vma_remap_st= ruct *vrm, > > if (is_vm_hugetlb_page(vma)) > > clear_vma_resv_huge_pages(vma); > > > > - /* Tell pfnmap has moved from this vma */ > > - if (unlikely(vma->vm_flags & VM_PFNMAP)) > > - untrack_pfn_clear(vma); > > - > > *new_vma_ptr =3D new_vma; > > return err; > > } > > -- > > 2.49.0 > >