Page MenuHomeFreeBSD

linuxkpi: Make "free page" code paths closer to Linux
ClosedPublic

Authored by dumbbell on Apr 13 2025, 11:31 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Oct 11, 8:29 AM
Unknown Object (File)
Wed, Sep 24, 1:27 AM
Unknown Object (File)
Tue, Sep 23, 9:40 PM
Unknown Object (File)
Sun, Sep 21, 6:53 AM
Unknown Object (File)
Sep 15 2025, 4:24 AM
Unknown Object (File)
Sep 13 2025, 3:57 PM
Unknown Object (File)
Sep 8 2025, 10:54 AM
Unknown Object (File)
Sep 2 2025, 5:13 AM
Subscribers

Details

Summary

There is basically one code path to free pages on Linux. In particular, free_pages() is used for other pages than those returned by alloc_pages().

Also on Linux, release_pages() takes either struct page or struct folio. struct folio support will be added in a followup commit. Regardless, because pages come from several sources, linux_free_pages() need to accept managed and unmanaged pages.

This is part of the update of DRM drivers to Linux 6.7. This is a follow-up to D48755.

Sponsored by: The FreeBSD Foundation

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

other pages than those returned by alloc_pages().

It would be really nice to have some comment explaining where those pages might be allocated, as it's not clear from looking through the linuxkpi. It's not possible to judge whether this change is correct without more information -- it may well be fine, but I don't know. For instance, if the page belongs to a VM object, is free_page() supposed to remove the page from the object?

Here is the code path that gets the pages that later cause the panic described in D48743:

  1. A scatter/gather list of pages is allocated in i915’s shmem_get_pages(): https://github.com/dumbbell/drm-kmod/blob/update-to-linux-6.8/drivers/gpu/drm/i915/gem/i915_gem_shmem.c#L255
  2. The list is allocated by shmem_sg_alloc_table(), defined in the same source file. It calls shmem_read_folio_gfp(): https://github.com/dumbbell/drm-kmod/blob/update-to-linux-6.8/drivers/gpu/drm/i915/gem/i915_gem_shmem.c#L132
  3. shmem_read_folio_gfp() is synonymous to shmem_read_mapping_page_gfp() in linuxkpi. It calls vm_page_grab_valid(): https://github.com/dumbbell/freebsd-src/blob/drm-related-linuxkpi-changes/sys/compat/linuxkpi/common/src/linux_shmemfs.c#L54-L55

put_page() is then called on each page and that’s when the panic occurs: https://github.com/dumbbell/drm-kmod/blob/update-to-linux-6.8/drivers/gpu/drm/i915/gem/i915_gem_shmem.c#L269

My point is that as I understand Linux code, the put_page()/release_pages() functions are used on pages and folios, regardless of how the page was allocated (it doesn’t need to come from alloc_page()).

I will reproduce the panic and provide the information you requested in the other review now.

This revision is now accepted and ready to land.Apr 15 2025, 1:39 PM

I will add a comment to the code in the final patch to explain that pages come from several sources.