All of lore.kernel.org
 help / color / mirror / Atom feed
* + mm-fix-huge-page-table-not-free-after-memory-unplug.patch added to mm-hotfixes-unstable branch
@ 2025-12-23  1:15 Andrew Morton
  2025-12-23  8:27 ` David Hildenbrand (Red Hat)
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Morton @ 2025-12-23  1:15 UTC (permalink / raw)
  To: mm-commits, rppt, jgg, david, baolu.lu, yuan1.liu, akpm


The patch titled
     Subject: mm: fix huge page table not free after memory unplug
has been added to the -mm mm-hotfixes-unstable branch.  Its filename is
     mm-fix-huge-page-table-not-free-after-memory-unplug.patch

This patch will shortly appear at
     https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-fix-huge-page-table-not-free-after-memory-unplug.patch

This patch will later appear in the mm-hotfixes-unstable branch at
    git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm

Before you just go and hit "reply", please:
   a) Consider who else should be cc'ed
   b) Prefer to cc a suitable mailing list as well
   c) Ideally: find the original patch on the mailing list and do a
      reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/process/submit-checklist.rst when testing your code ***

The -mm tree is included into linux-next via various
branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
and is updated there most days

------------------------------------------------------
From: Yuan Liu <yuan1.liu@intel.com>
Subject: mm: fix huge page table not free after memory unplug
Date: Sun, 21 Dec 2025 23:11:17 -0500

Newly plugged memory is marked as prot_sethuge via phys_pmd_init without
setting PG_head.  During memory unplug, free_hugepage_table frees the page
table as 2M, but pagetable_free handles it as 4K.

The following test case of memory unplug for a VM [1], tested in the
environment [2], show that results.

+-----------------------+------+------+
|Check System Memory    |Plug  |Unplug|
|via free -h            |256GB |256GB |
+-----------------------+------+------+
| Free 4K page table    |257GB |5.6GB |
+-----------------------+------+------+
| Free 2M page table    |257GB |1.7GB |
+-----------------------+------+------+

[1] Qemu commands to unhotplug 256G memory for a VM:
    object_add memory-backend-ram,id=hotmem0,size=256G,share=on
    device_add virtio-mem-pci,id=vmem1,memdev=hotmem0,bus=port1
    qom-set vmem1 requested-size 256G (Plug Memory)
    qom-set vmem1 requested-size 0G (Unplug Memory)

[2] Hardware     : Intel Icelake server
    Guest Kernel : v6.19-rc1
    Qemu         : v9.0.0

Launch VM:
    qemu-system-x86_64 -accel kvm -cpu host \
    -drive file=./Centos10_cloud.qcow2,format=qcow2,if=virtio \
    -drive file=./seed.img,format=raw,if=virtio \
    -smp 3,cores=3,threads=1,sockets=1,maxcpus=3 \
    -m 2G,slots=10,maxmem=2052472M \
    -device pcie-root-port,id=port1,bus=pcie.0,slot=1,multifunction=on \
    -device pcie-root-port,id=port2,bus=pcie.0,slot=2 \
    -nographic -machine q35 \
    -nic user,hostfwd=tcp::3000-:22

   Guest kernel auto-onlines newly added memory blocks:
   echo online > /sys/devices/system/memory/auto_online_blocks

Link: https://lkml.kernel.org/r/20251222041117.44865-1-yuan1.liu@intel.com
Fixes: bf9e4e30f353 ("x86/mm: use pagetable_free()")
Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
Cc: Jason Gunthorpe <jgg@nvidia.com>
Cc: Baolu Lu <baolu.lu@linux.intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: Mike Rapoport <rppt@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---

 arch/x86/mm/init_64.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- a/arch/x86/mm/init_64.c~mm-fix-huge-page-table-not-free-after-memory-unplug
+++ a/arch/x86/mm/init_64.c
@@ -1028,7 +1028,7 @@ static void __meminit free_pagetable(str
 		free_reserved_pages(page, nr_pages);
 #endif
 	} else {
-		pagetable_free(page_ptdesc(page));
+		__free_pages(page, order);
 	}
 }
 
_

Patches currently in -mm which might be from yuan1.liu@intel.com are

mm-fix-huge-page-table-not-free-after-memory-unplug.patch


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: + mm-fix-huge-page-table-not-free-after-memory-unplug.patch added to mm-hotfixes-unstable branch
  2025-12-23  1:15 + mm-fix-huge-page-table-not-free-after-memory-unplug.patch added to mm-hotfixes-unstable branch Andrew Morton
@ 2025-12-23  8:27 ` David Hildenbrand (Red Hat)
  2025-12-23 20:05   ` Mike Rapoport
  0 siblings, 1 reply; 3+ messages in thread
From: David Hildenbrand (Red Hat) @ 2025-12-23  8:27 UTC (permalink / raw)
  To: Andrew Morton, mm-commits, rppt, jgg, baolu.lu, yuan1.liu,
	Dave Hansen

On 12/23/25 02:15, Andrew Morton wrote:
> The patch titled
>       Subject: mm: fix huge page table not free after memory unplug
> has been added to the -mm mm-hotfixes-unstable branch.  Its filename is
>       mm-fix-huge-page-table-not-free-after-memory-unplug.patch
> 
> This patch will shortly appear at
>       https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/mm-fix-huge-page-table-not-free-after-memory-unplug.patch
> 
> This patch will later appear in the mm-hotfixes-unstable branch at
>      git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
> 
> Before you just go and hit "reply", please:
>     a) Consider who else should be cc'ed
>     b) Prefer to cc a suitable mailing list as well
>     c) Ideally: find the original patch on the mailing list and do a
>        reply-to-all to that, adding suitable additional cc's
> 
> *** Remember to use Documentation/process/submit-checklist.rst when testing your code ***
> 
> The -mm tree is included into linux-next via various
> branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
> and is updated there most days
> 
> ------------------------------------------------------
> From: Yuan Liu <yuan1.liu@intel.com>
> Subject: mm: fix huge page table not free after memory unplug
> Date: Sun, 21 Dec 2025 23:11:17 -0500
> 
> Newly plugged memory is marked as prot_sethuge via phys_pmd_init without
> setting PG_head.  During memory unplug, free_hugepage_table frees the page
> table as 2M, but pagetable_free handles it as 4K.
> 
> The following test case of memory unplug for a VM [1], tested in the
> environment [2], show that results.
> 
> +-----------------------+------+------+
> |Check System Memory    |Plug  |Unplug|
> |via free -h            |256GB |256GB |
> +-----------------------+------+------+
> | Free 4K page table    |257GB |5.6GB |
> +-----------------------+------+------+
> | Free 2M page table    |257GB |1.7GB |
> +-----------------------+------+------+
> 
> [1] Qemu commands to unhotplug 256G memory for a VM:
>      object_add memory-backend-ram,id=hotmem0,size=256G,share=on
>      device_add virtio-mem-pci,id=vmem1,memdev=hotmem0,bus=port1
>      qom-set vmem1 requested-size 256G (Plug Memory)
>      qom-set vmem1 requested-size 0G (Unplug Memory)
> 
> [2] Hardware     : Intel Icelake server
>      Guest Kernel : v6.19-rc1
>      Qemu         : v9.0.0
> 
> Launch VM:
>      qemu-system-x86_64 -accel kvm -cpu host \
>      -drive file=./Centos10_cloud.qcow2,format=qcow2,if=virtio \
>      -drive file=./seed.img,format=raw,if=virtio \
>      -smp 3,cores=3,threads=1,sockets=1,maxcpus=3 \
>      -m 2G,slots=10,maxmem=2052472M \
>      -device pcie-root-port,id=port1,bus=pcie.0,slot=1,multifunction=on \
>      -device pcie-root-port,id=port2,bus=pcie.0,slot=2 \
>      -nographic -machine q35 \
>      -nic user,hostfwd=tcp::3000-:22
> 
>     Guest kernel auto-onlines newly added memory blocks:
>     echo online > /sys/devices/system/memory/auto_online_blocks
> 
> Link: https://lkml.kernel.org/r/20251222041117.44865-1-yuan1.liu@intel.com
> Fixes: bf9e4e30f353 ("x86/mm: use pagetable_free()")
> Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
> Cc: Jason Gunthorpe <jgg@nvidia.com>
> Cc: Baolu Lu <baolu.lu@linux.intel.com>
> Cc: David Hildenbrand <david@redhat.com>
> Cc: Mike Rapoport <rppt@kernel.org>
> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> ---
> 
>   arch/x86/mm/init_64.c |    2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> --- a/arch/x86/mm/init_64.c~mm-fix-huge-page-table-not-free-after-memory-unplug
> +++ a/arch/x86/mm/init_64.c
> @@ -1028,7 +1028,7 @@ static void __meminit free_pagetable(str
>   		free_reserved_pages(page, nr_pages);
>   #endif
>   	} else {
> -		pagetable_free(page_ptdesc(page));
> +		__free_pages(page, order);

Hm, but this way we are skipping deconstructors, no?

In particular, clearing the kernel flag (ptdesc_clear_kernel()) and not 
handling ASYNC_KERNEL_PGTABLE_FREE correctly.

-- 
Cheers

David

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: + mm-fix-huge-page-table-not-free-after-memory-unplug.patch added to mm-hotfixes-unstable branch
  2025-12-23  8:27 ` David Hildenbrand (Red Hat)
@ 2025-12-23 20:05   ` Mike Rapoport
  0 siblings, 0 replies; 3+ messages in thread
From: Mike Rapoport @ 2025-12-23 20:05 UTC (permalink / raw)
  To: David Hildenbrand (Red Hat)
  Cc: Andrew Morton, mm-commits, jgg, baolu.lu, yuan1.liu, Dave Hansen

On Tue, Dec 23, 2025 at 09:27:52AM +0100, David Hildenbrand (Red Hat) wrote:
> On 12/23/25 02:15, Andrew Morton wrote:
>
> > From: Yuan Liu <yuan1.liu@intel.com>
> > Subject: mm: fix huge page table not free after memory unplug
> > Date: Sun, 21 Dec 2025 23:11:17 -0500
> > 
> > Newly plugged memory is marked as prot_sethuge via phys_pmd_init without
> > setting PG_head.  During memory unplug, free_hugepage_table frees the page
> > table as 2M, but pagetable_free handles it as 4K.
> > 
> > Link: https://lkml.kernel.org/r/20251222041117.44865-1-yuan1.liu@intel.com
> > Fixes: bf9e4e30f353 ("x86/mm: use pagetable_free()")
> > Signed-off-by: Yuan Liu <yuan1.liu@intel.com>
> > Cc: Jason Gunthorpe <jgg@nvidia.com>
> > Cc: Baolu Lu <baolu.lu@linux.intel.com>
> > Cc: David Hildenbrand <david@redhat.com>
> > Cc: Mike Rapoport <rppt@kernel.org>
> > Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
> > ---
> > 
> >   arch/x86/mm/init_64.c |    2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > --- a/arch/x86/mm/init_64.c~mm-fix-huge-page-table-not-free-after-memory-unplug
> > +++ a/arch/x86/mm/init_64.c
> > @@ -1028,7 +1028,7 @@ static void __meminit free_pagetable(str
> >   		free_reserved_pages(page, nr_pages);
> >   #endif
> >   	} else {
> > -		pagetable_free(page_ptdesc(page));
> > +		__free_pages(page, order);
> 
> Hm, but this way we are skipping deconstructors, no?
> 
> In particular, clearing the kernel flag (ptdesc_clear_kernel()) and not
> handling ASYNC_KERNEL_PGTABLE_FREE correctly.

And it seems to be x86 material at any rate.

-- 
Sincerely yours,
Mike.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-12-23 20:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-23  1:15 + mm-fix-huge-page-table-not-free-after-memory-unplug.patch added to mm-hotfixes-unstable branch Andrew Morton
2025-12-23  8:27 ` David Hildenbrand (Red Hat)
2025-12-23 20:05   ` Mike Rapoport

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.