Page MenuHomeFreeBSD

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

Authored by dumbbell on Sun, Apr 13, 11:31 AM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Apr 17, 11:38 PM
Unknown Object (File)
Thu, Apr 17, 7:16 PM
Unknown Object (File)
Thu, Apr 17, 9:48 AM
Unknown Object (File)
Thu, Apr 17, 2:45 AM
Unknown Object (File)
Thu, Apr 17, 2:10 AM
Unknown Object (File)
Wed, Apr 16, 8:18 PM
Unknown Object (File)
Wed, Apr 16, 8:03 AM
Unknown Object (File)
Mon, Apr 14, 9:01 AM
Subscribers

Details

Reviewers
markj
Group Reviewers
linuxkpi
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

Lint
Lint Skipped
Unit
Tests Skipped

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.Tue, Apr 15, 1:39 PM

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