free_pages() is supposed to be called when we only have a virtual address.
__free_pages() is supposed to be called when we have a page.
There are a number of callers that use page_address() to get a page's
virtual address then call free_pages() on it when they should just call
__free_pages() directly.
Add kernel-docs for free_pages() to help callers better understand which
function they should be calling, and replace the obvious cases of
misuse.
-----------------
Based on mm-new, I intend to have all of these taken through the mm tree.
I've split the patches into separate subsystems to make it easier to
resolve conflicts, but there aren't any functional changes.
v3:
- Collect some Reviewed-by Tags
- Replace remaining free_page() calls in patch 7 (all other patches
are unchanged from v2)
- Add all appropriate mailing lists that were missing from v2
v2:
- Reference __get_free_pages() instead of alloc_pages() in the
free_pages() kernel-doc
- Get some Reviewed-by tags
- cc the subsystem maintainers related to specific patches
Vishal Moola (Oracle) (7):
mm/page_alloc: Add kernel-docs for free_pages()
aoe: Stop calling page_address() in free_page()
x86: Stop calling page_address() in free_pages()
riscv: Stop calling page_address() in free_pages()
powerpc: Stop calling page_address() in free_pages()
arm64: Stop calling page_address() in free_pages()
virtio_balloon: Stop calling page_address() in free_pages()
arch/arm64/mm/mmu.c | 2 +-
arch/powerpc/mm/book3s64/radix_pgtable.c | 2 +-
arch/riscv/mm/init.c | 4 ++--
arch/x86/mm/init_64.c | 2 +-
arch/x86/platform/efi/memmap.c | 2 +-
drivers/block/aoe/aoecmd.c | 2 +-
drivers/virtio/virtio_balloon.c | 8 +++-----
mm/page_alloc.c | 9 +++++++++
8 files changed, 19 insertions(+), 12 deletions(-)
--
2.51.0
Add kernel-docs to free_pages(). This will help callers understand when
to use it instead of __free_pages().
Signed-off-by: Vishal Moola (Oracle) <redacted>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Acked-by: SeongJae Park <sj@kernel.org>
---
mm/page_alloc.c | 9 +++++++++
1 file changed, 9 insertions(+)
free_page() should be used when we only have a virtual address. We
should call __free_page() directly on our page instead.
Signed-off-by: Vishal Moola (Oracle) <redacted>
Reviewed-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
drivers/block/aoe/aoecmd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
free_pages() should be used when we only have a virtual address. We
should call __free_pages() directly on our page instead.
Signed-off-by: Vishal Moola (Oracle) <redacted>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
---
arch/x86/mm/init_64.c | 2 +-
arch/x86/platform/efi/memmap.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
free_pages() should be used when we only have a virtual address. We
should call __free_pages() directly on our page instead.
Signed-off-by: Vishal Moola (Oracle) <redacted>
---
arch/riscv/mm/init.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
free_pages() should be used when we only have a virtual address. We
should call __free_pages() directly on our page instead.
Signed-off-by: Vishal Moola (Oracle) <redacted>
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
---
arch/powerpc/mm/book3s64/radix_pgtable.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
free_pages() should be used when we only have a virtual address. We
should call __free_pages() directly on our page instead.
Signed-off-by: Vishal Moola (Oracle) <redacted>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
---
arch/arm64/mm/mmu.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
free_pages() should be used when we only have a virtual address. We
should call __free_pages() directly on our page instead.
Signed-off-by: Vishal Moola (Oracle) <redacted>
---
drivers/virtio/virtio_balloon.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
From: David Hildenbrand <hidden> Date: 2025-09-03 19:13:23
On 03.09.25 20:59, Vishal Moola (Oracle) wrote:
free_pages() should be used when we only have a virtual address. We
should call __free_pages() directly on our page instead.
Signed-off-by: Vishal Moola (Oracle) <redacted>
---
Acked-by: David Hildenbrand <redacted>
--
Cheers
David / dhildenb
Le 03/09/2025 à 20:59, Vishal Moola (Oracle) a écrit :
free_pages() should be used when we only have a virtual address. We
should call __free_pages() directly on our page instead.
Signed-off-by: Vishal Moola (Oracle) <redacted>
Reviewed-by: Ritesh Harjani (IBM) <ritesh.list@gmail.com>
From: Mike Rapoport <rppt@kernel.org> Date: 2025-09-04 11:51:14
On Wed, Sep 03, 2025 at 11:59:17AM -0700, Vishal Moola (Oracle) wrote:
quoted hunk
free_pages() should be used when we only have a virtual address. We
should call __free_pages() directly on our page instead.
Signed-off-by: Vishal Moola (Oracle) <redacted>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
---
arch/x86/mm/init_64.c | 2 +-
arch/x86/platform/efi/memmap.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
From: Mike Rapoport <rppt@kernel.org> Date: 2025-09-04 11:54:32
On Thu, Sep 04, 2025 at 02:51:14PM +0300, Mike Rapoport wrote:
On Wed, Sep 03, 2025 at 11:59:17AM -0700, Vishal Moola (Oracle) wrote:
quoted
free_pages() should be used when we only have a virtual address. We
should call __free_pages() directly on our page instead.
Signed-off-by: Vishal Moola (Oracle) <redacted>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
---
arch/x86/mm/init_64.c | 2 +-
arch/x86/platform/efi/memmap.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
From: Mike Rapoport <rppt@kernel.org> Date: 2025-09-04 11:55:32
On Wed, Sep 03, 2025 at 11:59:14AM -0700, Vishal Moola (Oracle) wrote:
free_pages() is supposed to be called when we only have a virtual address.
__free_pages() is supposed to be called when we have a page.
There are a number of callers that use page_address() to get a page's
virtual address then call free_pages() on it when they should just call
__free_pages() directly.
Add kernel-docs for free_pages() to help callers better understand which
function they should be calling, and replace the obvious cases of
misuse.
Vishal Moola (Oracle) (7):
mm/page_alloc: Add kernel-docs for free_pages()
aoe: Stop calling page_address() in free_page()
x86: Stop calling page_address() in free_pages()
riscv: Stop calling page_address() in free_pages()
powerpc: Stop calling page_address() in free_pages()
arm64: Stop calling page_address() in free_pages()
virtio_balloon: Stop calling page_address() in free_pages()
Acked-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Hi Vishal,
On 9/3/25 20:59, Vishal Moola (Oracle) wrote:
quoted hunk
free_pages() should be used when we only have a virtual address. We
should call __free_pages() directly on our page instead.
Signed-off-by: Vishal Moola (Oracle) <redacted>
---
arch/riscv/mm/init.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
From: "Michael S. Tsirkin" <mst@redhat.com> Date: 2025-09-04 21:38:36
On Wed, Sep 03, 2025 at 11:59:21AM -0700, Vishal Moola (Oracle) wrote:
free_pages() should be used when we only have a virtual address. We
should call __free_pages() directly on our page instead.
Signed-off-by: Vishal Moola (Oracle) <redacted>
On Thu, Sep 04, 2025 at 02:54:24PM +0300, Mike Rapoport wrote:
On Thu, Sep 04, 2025 at 02:51:14PM +0300, Mike Rapoport wrote:
quoted
On Wed, Sep 03, 2025 at 11:59:17AM -0700, Vishal Moola (Oracle) wrote:
quoted
free_pages() should be used when we only have a virtual address. We
should call __free_pages() directly on our page instead.
Signed-off-by: Vishal Moola (Oracle) <redacted>
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
---
arch/x86/mm/init_64.c | 2 +-
arch/x86/platform/efi/memmap.c | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
@@ -42,7 +42,7 @@ void __init __efi_memmap_free(u64 phys, unsigned long size, unsigned long flags)structpage*p=pfn_to_page(PHYS_PFN(phys));unsignedintorder=get_order(size);-free_pages((unsignedlong)page_address(p),order);
Could be just free_pages((unsigned long)phys_to_virt(phys), order), then
the page is not needed at all.
Or even __free_pages(phys_to_page(phys), order);
Right. It actually looks like we could inline this whole block if we
really wanted to...
__free_pages(phys_to_page(phys), get_order(size));
Should I send a fixup (or v4) with this change?