The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* linux-next: manual merge of the mm-unstable tree with the drm-misc-fixes tree
@ 2025-08-13  1:11 Stephen Rothwell
  2025-08-13  3:59 ` Andrew Morton
  2025-08-13  8:50 ` Danilo Krummrich
  0 siblings, 2 replies; 12+ messages in thread
From: Stephen Rothwell @ 2025-08-13  1:11 UTC (permalink / raw)
  To: Andrew Morton, Simona Vetter
  Cc: Danilo Krummrich, Vitaly Wool, Intel Graphics, DRI,
	Linux Kernel Mailing List, Linux Next Mailing List

[-- Attachment #1: Type: text/plain, Size: 4149 bytes --]

Hi all,

Today's linux-next merge of the mm-unstable tree got a conflict in:

  rust/kernel/alloc/allocator.rs

between commit:

  fde578c86281 ("rust: alloc: replace aligned_size() with Kmalloc::aligned_layout()")

from the drm-misc-fixes tree and commit:

  cda097b07bce ("rust: support large alignments in allocations")

from the mm-unstable tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc rust/kernel/alloc/allocator.rs
index 2692cf90c948,63f271624428..000000000000
--- a/rust/kernel/alloc/allocator.rs
+++ b/rust/kernel/alloc/allocator.rs
@@@ -43,11 -42,28 +42,17 @@@ pub struct Vmalloc
  /// For more details see [self].
  pub struct KVmalloc;
  
 -/// Returns a proper size to alloc a new object aligned to `new_layout`'s alignment.
 -fn aligned_size(new_layout: Layout) -> usize {
 -    // Customized layouts from `Layout::from_size_align()` can have size < align, so pad first.
 -    let layout = new_layout.pad_to_align();
 -
 -    // Note that `layout.size()` (after padding) is guaranteed to be a multiple of `layout.align()`
 -    // which together with the slab guarantees means the `krealloc` will return a properly aligned
 -    // object (see comments in `kmalloc()` for more information).
 -    layout.size()
 -}
 -
  /// # Invariants
  ///
- /// One of the following: `krealloc`, `vrealloc`, `kvrealloc`.
+ /// One of the following: `krealloc_node_align`, `vrealloc_node_align`, `kvrealloc_node_align`.
  struct ReallocFunc(
-     unsafe extern "C" fn(*const crate::ffi::c_void, usize, u32) -> *mut crate::ffi::c_void,
+     unsafe extern "C" fn(
+         *const crate::ffi::c_void,
+         usize,
+         crate::ffi::c_ulong,
+         u32,
+         crate::ffi::c_int,
+     ) -> *mut crate::ffi::c_void,
  );
  
  impl ReallocFunc {
@@@ -76,8 -92,9 +81,9 @@@
          layout: Layout,
          old_layout: Layout,
          flags: Flags,
+         nid: NumaNode,
      ) -> Result<NonNull<[u8]>, AllocError> {
 -        let size = aligned_size(layout);
 +        let size = layout.size();
          let ptr = match ptr {
              Some(ptr) => {
                  if old_layout.size() == 0 {
@@@ -134,11 -140,10 +140,12 @@@ unsafe impl Allocator for Kmalloc 
          layout: Layout,
          old_layout: Layout,
          flags: Flags,
+         nid: NumaNode,
      ) -> Result<NonNull<[u8]>, AllocError> {
 +        let layout = Kmalloc::aligned_layout(layout);
 +
          // SAFETY: `ReallocFunc::call` has the same safety requirements as `Allocator::realloc`.
-         unsafe { ReallocFunc::KREALLOC.call(ptr, layout, old_layout, flags) }
+         unsafe { ReallocFunc::KREALLOC.call(ptr, layout, old_layout, flags, nid) }
      }
  }
  
@@@ -177,19 -177,10 +179,14 @@@ unsafe impl Allocator for KVmalloc 
          layout: Layout,
          old_layout: Layout,
          flags: Flags,
+         nid: NumaNode,
      ) -> Result<NonNull<[u8]>, AllocError> {
 +        // `KVmalloc` may use the `Kmalloc` backend, hence we have to enforce a `Kmalloc`
 +        // compatible layout.
 +        let layout = Kmalloc::aligned_layout(layout);
 +
-         // TODO: Support alignments larger than PAGE_SIZE.
-         if layout.align() > bindings::PAGE_SIZE {
-             pr_warn!("KVmalloc does not support alignments larger than PAGE_SIZE yet.\n");
-             return Err(AllocError);
-         }
- 
          // SAFETY: If not `None`, `ptr` is guaranteed to point to valid memory, which was previously
          // allocated with this `Allocator`.
-         unsafe { ReallocFunc::KVREALLOC.call(ptr, layout, old_layout, flags) }
+         unsafe { ReallocFunc::KVREALLOC.call(ptr, layout, old_layout, flags, nid) }
      }
  }

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: linux-next: manual merge of the mm-unstable tree with the drm-misc-fixes tree
  2025-08-13  1:11 Stephen Rothwell
@ 2025-08-13  3:59 ` Andrew Morton
  2025-08-13  9:07   ` Danilo Krummrich
  2025-08-13  8:50 ` Danilo Krummrich
  1 sibling, 1 reply; 12+ messages in thread
From: Andrew Morton @ 2025-08-13  3:59 UTC (permalink / raw)
  To: Stephen Rothwell
  Cc: Simona Vetter, Danilo Krummrich, Vitaly Wool, Intel Graphics, DRI,
	Linux Kernel Mailing List, Linux Next Mailing List

On Wed, 13 Aug 2025 11:11:51 +1000 Stephen Rothwell <sfr@canb.auug.org.au> wrote:

> Hi all,
> 
> Today's linux-next merge of the mm-unstable tree got a conflict in:
> 
>   rust/kernel/alloc/allocator.rs
> 
> between commit:
> 
>   fde578c86281 ("rust: alloc: replace aligned_size() with Kmalloc::aligned_layout()")
> 
> from the drm-misc-fixes tree and commit:
> 
>   cda097b07bce ("rust: support large alignments in allocations")
> 
> from the mm-unstable tree.
> 
> I fixed it up (see below) and can carry the fix as necessary. This
> is now fixed as far as linux-next is concerned, but any non trivial
> conflicts should be mentioned to your upstream maintainer when your tree
> is submitted for merging.  You may also want to consider cooperating
> with the maintainer of the conflicting tree to minimise any particularly
> complex conflicts.
> 

Thanks.

Well that's messy.

Is it intended that the containing series ("Alloc and drm::Device
fixes") be merged into 6.17-rcX?



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

* Re: linux-next: manual merge of the mm-unstable tree with the drm-misc-fixes tree
  2025-08-13  1:11 Stephen Rothwell
  2025-08-13  3:59 ` Andrew Morton
@ 2025-08-13  8:50 ` Danilo Krummrich
  1 sibling, 0 replies; 12+ messages in thread
From: Danilo Krummrich @ 2025-08-13  8:50 UTC (permalink / raw)
  To: Stephen Rothwell
  Cc: Andrew Morton, Simona Vetter, Vitaly Wool, Intel Graphics, DRI,
	Linux Kernel Mailing List, Linux Next Mailing List

On Wed Aug 13, 2025 at 3:11 AM CEST, Stephen Rothwell wrote:
> Hi all,
>
> Today's linux-next merge of the mm-unstable tree got a conflict in:
>
>   rust/kernel/alloc/allocator.rs
>
> between commit:
>
>   fde578c86281 ("rust: alloc: replace aligned_size() with Kmalloc::aligned_layout()")
>
> from the drm-misc-fixes tree and commit:
>
>   cda097b07bce ("rust: support large alignments in allocations")
>
> from the mm-unstable tree.
>
> I fixed it up (see below) and can carry the fix as necessary. This
> is now fixed as far as linux-next is concerned, but any non trivial
> conflicts should be mentioned to your upstream maintainer when your tree
> is submitted for merging.  You may also want to consider cooperating
> with the maintainer of the conflicting tree to minimise any particularly
> complex conflicts.

Thanks, the resolution looks good!

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

* Re: linux-next: manual merge of the mm-unstable tree with the drm-misc-fixes tree
  2025-08-13  3:59 ` Andrew Morton
@ 2025-08-13  9:07   ` Danilo Krummrich
  0 siblings, 0 replies; 12+ messages in thread
From: Danilo Krummrich @ 2025-08-13  9:07 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Stephen Rothwell, Simona Vetter, Vitaly Wool, Intel Graphics, DRI,
	Linux Kernel Mailing List, Linux Next Mailing List

On Wed Aug 13, 2025 at 5:59 AM CEST, Andrew Morton wrote:
> Thanks.
>
> Well that's messy.

I think it's not too bad, the changes are just too close to each other -- no
semantic conflict.

As a general heads-up, Rust code is a bit more prone to conflicts.

On one hand this is due to the more powerful type system and components of
different subsystems being a bit closer connected to each other to provide
additional safety guarantees.

On the other hand, there's simply a lot of foundational work going on in
parallel.

For the Rust parts that are maintained under your mm tree, I think it should
generally stay well within limits though.

> Is it intended that the containing series ("Alloc and drm::Device
> fixes") be merged into 6.17-rcX?

Yes, not sure if it will be in -rc2 already, but should be in -rc3. So, the
conflict in -next should vanish in case you backmerge the corresponding -rc.

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

* linux-next: manual merge of the mm-unstable tree with the drm-misc-fixes tree
@ 2026-07-20 13:31 Mark Brown
  2026-07-20 14:41 ` Christoph Hellwig
  0 siblings, 1 reply; 12+ messages in thread
From: Mark Brown @ 2026-07-20 13:31 UTC (permalink / raw)
  To: Andrew Morton
  Cc: Christoph Hellwig, Linux Kernel Mailing List,
	Linux Next Mailing List, Matthew Brost

[-- Attachment #1: Type: text/plain, Size: 6876 bytes --]

Hi all,

Today's linux-next merge of the mm-unstable tree got a conflict in:

  drivers/gpu/drm/ttm/ttm_backup.c

between commit:

  a3fdf74ffa596 ("drm/ttm/pool: back up at native page order")

from the drm-misc-fixes tree and commit:

  c6bfdcf16f131 ("shmem: provide a shmem_write_folio wrapper")

from the mm-unstable tree.

I fixed it up (see below) and can carry the fix as necessary. This
is now fixed as far as linux-next is concerned, but any non trivial
conflicts should be mentioned to your upstream maintainer when your tree
is submitted for merging.  You may also want to consider cooperating
with the maintainer of the conflicting tree to minimise any particularly
complex conflicts.

diff --combined drivers/gpu/drm/ttm/ttm_backup.c
index 3c067aadc52de,c5b813a563e7f..0000000000000
--- a/drivers/gpu/drm/ttm/ttm_backup.c
+++ b/drivers/gpu/drm/ttm/ttm_backup.c
@@@ -6,10 -6,9 +6,10 @@@
  #include <drm/ttm/ttm_backup.h>
  
  #include <linux/export.h>
 -#include <linux/page-flags.h>
  #include <linux/swap.h>
  
 +#include "ttm_pool_internal.h"
 +
  /*
   * Need to map shmem indices to handle since a handle value
   * of 0 means error, following the swp_entry_t convention.
@@@ -69,23 -68,17 +69,23 @@@ int ttm_backup_copy_page(struct file *b
  }
  
  /**
 - * ttm_backup_backup_page() - Backup a page
 + * ttm_backup_backup_folio() - Backup a folio
   * @backup: The struct backup pointer to use.
 - * @page: The page to back up.
 - * @writeback: Whether to perform immediate writeback of the page.
 + * @folio: The folio to back up.
 + * @order: The allocation order of @folio.  Since TTM allocates higher-order
 + *         pages without __GFP_COMP, folio_nr_pages(@folio) would always
 + *         return 1; the caller must pass the true order explicitly.
 + * @writeback: Whether to perform immediate writeback of the folio's pages.
   * This may have performance implications.
 - * @idx: A unique integer for each page and each struct backup.
 + * @idx: A unique integer for the first page of the folio and each struct backup.
   * This allows the backup implementation to avoid managing
   * its address space separately.
 - * @page_gfp: The gfp value used when the page was allocated.
 - * This is used for accounting purposes.
 + * @folio_gfp: The gfp value used when the folio was allocated.
 + * Currently unused.
   * @alloc_gfp: The gfp to be used when allocating memory.
 + * @nr_pages_backed: Output. On a successful return, set to the number of
 + * pages actually backed up, which may be less than (1 << @order)
 + * if an -ENOMEM was encountered mid-folio.
   *
   * Context: If called from reclaim context, the caller needs to
   * assert that the shrinker gfp has __GFP_FS set, to avoid
@@@ -94,87 -87,53 +94,87 @@@
   * that the shrinker gfp has __GFP_IO set, since without it,
   * we're not allowed to start backup IO.
   *
 - * Return: A handle on success. Negative error code on failure.
 - *
 - * Note: This function could be extended to back up a folio and
 - * implementations would then split the folio internally if needed.
 - * Drawback is that the caller would then have to keep track of
 - * the folio size- and usage.
 + * Return: A handle for the first backed-up page on success (handles for
 + * subsequent pages follow sequentially). -ENOMEM if no pages could be backed
 + * up. Any other negative error code if a non-ENOMEM failure occurred; in that
 + * case any pages backed up so far are truncated before returning.
   */
  s64
 -ttm_backup_backup_page(struct file *backup, struct page *page,
 -		       bool writeback, pgoff_t idx, gfp_t page_gfp,
 -		       gfp_t alloc_gfp)
 +ttm_backup_backup_folio(struct file *backup, struct folio *folio,
 +			unsigned int order, bool writeback, pgoff_t idx,
 +			gfp_t folio_gfp, gfp_t alloc_gfp,
 +			pgoff_t *nr_pages_backed)
  {
  	struct address_space *mapping = backup->f_mapping;
 -	unsigned long handle = 0;
 +	int nr_pages = 1 << order;
  	struct folio *to_folio;
 -	int ret;
 +	int ret, i;
  
 -	to_folio = shmem_read_folio_gfp(mapping, idx, alloc_gfp);
 -	if (IS_ERR(to_folio))
 -		return PTR_ERR(to_folio);
 +	*nr_pages_backed = 0;
  
 -	folio_mark_accessed(to_folio);
 -	folio_lock(to_folio);
 -	folio_mark_dirty(to_folio);
 -	copy_highpage(folio_file_page(to_folio, idx), page);
 -	handle = ttm_backup_shmem_idx_to_handle(idx);
 +	for (i = 0; i < nr_pages; ) {
 +		int to_nr, j;
  
 -	if (writeback && !folio_mapped(to_folio) &&
 -	    folio_clear_dirty_for_io(to_folio)) {
 -		folio_set_reclaim(to_folio);
 -		ret = shmem_write_folio(to_folio);
 -		if (!folio_test_writeback(to_folio))
 -			folio_clear_reclaim(to_folio);
  		/*
 -		 * If writeout succeeds, it unlocks the folio.	errors
 -		 * are otherwise dropped, since writeout is only best
 -		 * effort here.
 +		 * Only inject past the first subpage so *nr_pages_backed is
 +		 * always > 0 here, matching a genuine mid-compound -ENOMEM
 +		 * and driving the caller's reactive split fallback instead
 +		 * of an early, no-progress failure.
  		 */
 -		if (ret)
 +		if (IS_ENABLED(CONFIG_FAULT_INJECTION) && i &&
 +		    ttm_backup_fault_inject_folio())
 +			to_folio = ERR_PTR(-ENOMEM);
 +		else
 +			to_folio = shmem_read_folio_gfp(mapping, idx + i, alloc_gfp);
 +		if (IS_ERR(to_folio)) {
 +			int err = PTR_ERR(to_folio);
 +
 +			if (err == -ENOMEM && *nr_pages_backed)
 +				return ttm_backup_shmem_idx_to_handle(idx);
 +
 +			if (*nr_pages_backed) {
 +				shmem_truncate_range(file_inode(backup),
 +						     (loff_t)idx << PAGE_SHIFT,
 +						     ((loff_t)(idx + i) << PAGE_SHIFT) - 1);
 +				/*
 +				 * The pages just truncated are no longer
 +				 * backed up; don't let the caller mistake
 +				 * them for valid handles.
 +				 */
 +				*nr_pages_backed = 0;
 +			}
 +			return err;
 +		}
 +
 +		to_nr = min_t(int, nr_pages - i,
 +			      folio_next_index(to_folio) - (idx + i));
 +
 +		folio_mark_accessed(to_folio);
 +		folio_lock(to_folio);
 +		folio_mark_dirty(to_folio);
 +
 +		for (j = 0; j < to_nr; j++)
 +			copy_highpage(folio_file_page(to_folio, idx + i + j),
 +				      folio_page(folio, i + j));
 +
 +		if (writeback && !folio_mapped(to_folio) &&
 +		    folio_clear_dirty_for_io(to_folio)) {
 +			folio_set_reclaim(to_folio);
++			ret = shmem_write_folio(to_folio);
 +			if (!folio_test_writeback(to_folio))
 +				folio_clear_reclaim(to_folio);
 +			if (ret == AOP_WRITEPAGE_ACTIVATE)
 +				folio_unlock(to_folio);
 +		} else {
  			folio_unlock(to_folio);
 -	} else {
 -		folio_unlock(to_folio);
 +		}
 +
 +		folio_put(to_folio);
 +		i += to_nr;
 +		*nr_pages_backed = i;
  	}
  
 -	folio_put(to_folio);
 -
 -	return handle;
 +	return ttm_backup_shmem_idx_to_handle(idx);
  }
  
  /**

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: linux-next: manual merge of the mm-unstable tree with the drm-misc-fixes tree
  2026-07-20 13:31 linux-next: manual merge of the mm-unstable tree with the drm-misc-fixes tree Mark Brown
@ 2026-07-20 14:41 ` Christoph Hellwig
  2026-07-20 14:46   ` Matthew Wilcox
  2026-07-20 21:58   ` Matthew Brost
  0 siblings, 2 replies; 12+ messages in thread
From: Christoph Hellwig @ 2026-07-20 14:41 UTC (permalink / raw)
  To: Mark Brown
  Cc: Andrew Morton, Christoph Hellwig, Linux Kernel Mailing List,
	Linux Next Mailing List, Matthew Brost, Hugh Dickins, Baolin Wang,
	linux-mm

On Mon, Jul 20, 2026 at 02:31:04PM +0100, Mark Brown wrote:
> Hi all,
> 
> Today's linux-next merge of the mm-unstable tree got a conflict in:
> 
>   drivers/gpu/drm/ttm/ttm_backup.c
> 
> between commit:
> 
>   a3fdf74ffa596 ("drm/ttm/pool: back up at native page order")
> 
> from the drm-misc-fixes tree and commit:
> 
>   c6bfdcf16f131 ("shmem: provide a shmem_write_folio wrapper")
> 
> from the mm-unstable tree.
> 
> I fixed it up (see below) and can carry the fix as necessary. This
> is now fixed as far as linux-next is concerned, but any non trivial
> conflicts should be mentioned to your upstream maintainer when your tree
> is submitted for merging.  You may also want to consider cooperating
> with the maintainer of the conflicting tree to minimise any particularly
> complex conflicts.

Much of the code here really should sit in shmem.c instead of having
random drivers/subsystems poke into the internals of shmem mappings
and folios.  But I feel like a broken record for saying that again
and again without any action :(

> 
> diff --combined drivers/gpu/drm/ttm/ttm_backup.c
> index 3c067aadc52de,c5b813a563e7f..0000000000000
> --- a/drivers/gpu/drm/ttm/ttm_backup.c
> +++ b/drivers/gpu/drm/ttm/ttm_backup.c
> @@@ -6,10 -6,9 +6,10 @@@
>   #include <drm/ttm/ttm_backup.h>
>   
>   #include <linux/export.h>
>  -#include <linux/page-flags.h>
>   #include <linux/swap.h>
>   
>  +#include "ttm_pool_internal.h"
>  +
>   /*
>    * Need to map shmem indices to handle since a handle value
>    * of 0 means error, following the swp_entry_t convention.
> @@@ -69,23 -68,17 +69,23 @@@ int ttm_backup_copy_page(struct file *b
>   }
>   
>   /**
>  - * ttm_backup_backup_page() - Backup a page
>  + * ttm_backup_backup_folio() - Backup a folio
>    * @backup: The struct backup pointer to use.
>  - * @page: The page to back up.
>  - * @writeback: Whether to perform immediate writeback of the page.
>  + * @folio: The folio to back up.
>  + * @order: The allocation order of @folio.  Since TTM allocates higher-order
>  + *         pages without __GFP_COMP, folio_nr_pages(@folio) would always
>  + *         return 1; the caller must pass the true order explicitly.
>  + * @writeback: Whether to perform immediate writeback of the folio's pages.
>    * This may have performance implications.
>  - * @idx: A unique integer for each page and each struct backup.
>  + * @idx: A unique integer for the first page of the folio and each struct backup.
>    * This allows the backup implementation to avoid managing
>    * its address space separately.
>  - * @page_gfp: The gfp value used when the page was allocated.
>  - * This is used for accounting purposes.
>  + * @folio_gfp: The gfp value used when the folio was allocated.
>  + * Currently unused.
>    * @alloc_gfp: The gfp to be used when allocating memory.
>  + * @nr_pages_backed: Output. On a successful return, set to the number of
>  + * pages actually backed up, which may be less than (1 << @order)
>  + * if an -ENOMEM was encountered mid-folio.
>    *
>    * Context: If called from reclaim context, the caller needs to
>    * assert that the shrinker gfp has __GFP_FS set, to avoid
> @@@ -94,87 -87,53 +94,87 @@@
>    * that the shrinker gfp has __GFP_IO set, since without it,
>    * we're not allowed to start backup IO.
>    *
>  - * Return: A handle on success. Negative error code on failure.
>  - *
>  - * Note: This function could be extended to back up a folio and
>  - * implementations would then split the folio internally if needed.
>  - * Drawback is that the caller would then have to keep track of
>  - * the folio size- and usage.
>  + * Return: A handle for the first backed-up page on success (handles for
>  + * subsequent pages follow sequentially). -ENOMEM if no pages could be backed
>  + * up. Any other negative error code if a non-ENOMEM failure occurred; in that
>  + * case any pages backed up so far are truncated before returning.
>    */
>   s64
>  -ttm_backup_backup_page(struct file *backup, struct page *page,
>  -		       bool writeback, pgoff_t idx, gfp_t page_gfp,
>  -		       gfp_t alloc_gfp)
>  +ttm_backup_backup_folio(struct file *backup, struct folio *folio,
>  +			unsigned int order, bool writeback, pgoff_t idx,
>  +			gfp_t folio_gfp, gfp_t alloc_gfp,
>  +			pgoff_t *nr_pages_backed)
>   {
>   	struct address_space *mapping = backup->f_mapping;
>  -	unsigned long handle = 0;
>  +	int nr_pages = 1 << order;
>   	struct folio *to_folio;
>  -	int ret;
>  +	int ret, i;
>   
>  -	to_folio = shmem_read_folio_gfp(mapping, idx, alloc_gfp);
>  -	if (IS_ERR(to_folio))
>  -		return PTR_ERR(to_folio);
>  +	*nr_pages_backed = 0;
>   
>  -	folio_mark_accessed(to_folio);
>  -	folio_lock(to_folio);
>  -	folio_mark_dirty(to_folio);
>  -	copy_highpage(folio_file_page(to_folio, idx), page);
>  -	handle = ttm_backup_shmem_idx_to_handle(idx);
>  +	for (i = 0; i < nr_pages; ) {
>  +		int to_nr, j;
>   
>  -	if (writeback && !folio_mapped(to_folio) &&
>  -	    folio_clear_dirty_for_io(to_folio)) {
>  -		folio_set_reclaim(to_folio);
>  -		ret = shmem_write_folio(to_folio);
>  -		if (!folio_test_writeback(to_folio))
>  -			folio_clear_reclaim(to_folio);
>   		/*
>  -		 * If writeout succeeds, it unlocks the folio.	errors
>  -		 * are otherwise dropped, since writeout is only best
>  -		 * effort here.
>  +		 * Only inject past the first subpage so *nr_pages_backed is
>  +		 * always > 0 here, matching a genuine mid-compound -ENOMEM
>  +		 * and driving the caller's reactive split fallback instead
>  +		 * of an early, no-progress failure.
>   		 */
>  -		if (ret)
>  +		if (IS_ENABLED(CONFIG_FAULT_INJECTION) && i &&
>  +		    ttm_backup_fault_inject_folio())
>  +			to_folio = ERR_PTR(-ENOMEM);
>  +		else
>  +			to_folio = shmem_read_folio_gfp(mapping, idx + i, alloc_gfp);
>  +		if (IS_ERR(to_folio)) {
>  +			int err = PTR_ERR(to_folio);
>  +
>  +			if (err == -ENOMEM && *nr_pages_backed)
>  +				return ttm_backup_shmem_idx_to_handle(idx);
>  +
>  +			if (*nr_pages_backed) {
>  +				shmem_truncate_range(file_inode(backup),
>  +						     (loff_t)idx << PAGE_SHIFT,
>  +						     ((loff_t)(idx + i) << PAGE_SHIFT) - 1);
>  +				/*
>  +				 * The pages just truncated are no longer
>  +				 * backed up; don't let the caller mistake
>  +				 * them for valid handles.
>  +				 */
>  +				*nr_pages_backed = 0;
>  +			}
>  +			return err;
>  +		}
>  +
>  +		to_nr = min_t(int, nr_pages - i,
>  +			      folio_next_index(to_folio) - (idx + i));
>  +
>  +		folio_mark_accessed(to_folio);
>  +		folio_lock(to_folio);
>  +		folio_mark_dirty(to_folio);
>  +
>  +		for (j = 0; j < to_nr; j++)
>  +			copy_highpage(folio_file_page(to_folio, idx + i + j),
>  +				      folio_page(folio, i + j));
>  +
>  +		if (writeback && !folio_mapped(to_folio) &&
>  +		    folio_clear_dirty_for_io(to_folio)) {
>  +			folio_set_reclaim(to_folio);
> ++			ret = shmem_write_folio(to_folio);
>  +			if (!folio_test_writeback(to_folio))
>  +				folio_clear_reclaim(to_folio);
>  +			if (ret == AOP_WRITEPAGE_ACTIVATE)
>  +				folio_unlock(to_folio);
>  +		} else {
>   			folio_unlock(to_folio);
>  -	} else {
>  -		folio_unlock(to_folio);
>  +		}
>  +
>  +		folio_put(to_folio);
>  +		i += to_nr;
>  +		*nr_pages_backed = i;
>   	}
>   
>  -	folio_put(to_folio);
>  -
>  -	return handle;
>  +	return ttm_backup_shmem_idx_to_handle(idx);
>   }
>   
>   /**


---end quoted text---

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

* Re: linux-next: manual merge of the mm-unstable tree with the drm-misc-fixes tree
  2026-07-20 14:41 ` Christoph Hellwig
@ 2026-07-20 14:46   ` Matthew Wilcox
  2026-07-20 22:08     ` Matthew Brost
  2026-07-20 21:58   ` Matthew Brost
  1 sibling, 1 reply; 12+ messages in thread
From: Matthew Wilcox @ 2026-07-20 14:46 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Mark Brown, Andrew Morton, Linux Kernel Mailing List,
	Linux Next Mailing List, Matthew Brost, Hugh Dickins, Baolin Wang,
	linux-mm, Christian Koenig, Huang Rui, dri-devel

On Mon, Jul 20, 2026 at 04:41:41PM +0200, Christoph Hellwig wrote:
> >   /**
> >  - * ttm_backup_backup_page() - Backup a page
> >  + * ttm_backup_backup_folio() - Backup a folio
> >    * @backup: The struct backup pointer to use.
> >  - * @page: The page to back up.
> >  - * @writeback: Whether to perform immediate writeback of the page.
> >  + * @folio: The folio to back up.
> >  + * @order: The allocation order of @folio.  Since TTM allocates higher-order
> >  + *         pages without __GFP_COMP, folio_nr_pages(@folio) would always
> >  + *         return 1; the caller must pass the true order explicitly.

Wait, what?  This is just broken.  TTM should change to allocate using
GFP_COMP.  Why can't graphics people ask questions before writing stupid
patches?


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

* Re: linux-next: manual merge of the mm-unstable tree with the drm-misc-fixes tree
  2026-07-20 14:41 ` Christoph Hellwig
  2026-07-20 14:46   ` Matthew Wilcox
@ 2026-07-20 21:58   ` Matthew Brost
  2026-07-21  4:54     ` Christoph Hellwig
  1 sibling, 1 reply; 12+ messages in thread
From: Matthew Brost @ 2026-07-20 21:58 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Mark Brown, Andrew Morton, Linux Kernel Mailing List,
	Linux Next Mailing List, Hugh Dickins, Baolin Wang, linux-mm

On Mon, Jul 20, 2026 at 04:41:41PM +0200, Christoph Hellwig wrote:
> On Mon, Jul 20, 2026 at 02:31:04PM +0100, Mark Brown wrote:
> > Hi all,
> > 
> > Today's linux-next merge of the mm-unstable tree got a conflict in:
> > 
> >   drivers/gpu/drm/ttm/ttm_backup.c
> > 
> > between commit:
> > 
> >   a3fdf74ffa596 ("drm/ttm/pool: back up at native page order")
> > 
> > from the drm-misc-fixes tree and commit:
> > 
> >   c6bfdcf16f131 ("shmem: provide a shmem_write_folio wrapper")
> > 
> > from the mm-unstable tree.
> > 
> > I fixed it up (see below) and can carry the fix as necessary. This
> > is now fixed as far as linux-next is concerned, but any non trivial
> > conflicts should be mentioned to your upstream maintainer when your tree
> > is submitted for merging.  You may also want to consider cooperating
> > with the maintainer of the conflicting tree to minimise any particularly
> > complex conflicts.
> 
> Much of the code here really should sit in shmem.c instead of having
> random drivers/subsystems poke into the internals of shmem mappings
> and folios.  But I feel like a broken record for saying that again
> and again without any action :(
> 

Do you have a suggestion of what parts to move over to shmem.c?

Pretty much all of this? I can take a look at this in a follow up?

Matt

> > 
> > diff --combined drivers/gpu/drm/ttm/ttm_backup.c
> > index 3c067aadc52de,c5b813a563e7f..0000000000000
> > --- a/drivers/gpu/drm/ttm/ttm_backup.c
> > +++ b/drivers/gpu/drm/ttm/ttm_backup.c
> > @@@ -6,10 -6,9 +6,10 @@@
> >   #include <drm/ttm/ttm_backup.h>
> >   
> >   #include <linux/export.h>
> >  -#include <linux/page-flags.h>
> >   #include <linux/swap.h>
> >   
> >  +#include "ttm_pool_internal.h"
> >  +
> >   /*
> >    * Need to map shmem indices to handle since a handle value
> >    * of 0 means error, following the swp_entry_t convention.
> > @@@ -69,23 -68,17 +69,23 @@@ int ttm_backup_copy_page(struct file *b
> >   }
> >   
> >   /**
> >  - * ttm_backup_backup_page() - Backup a page
> >  + * ttm_backup_backup_folio() - Backup a folio
> >    * @backup: The struct backup pointer to use.
> >  - * @page: The page to back up.
> >  - * @writeback: Whether to perform immediate writeback of the page.
> >  + * @folio: The folio to back up.
> >  + * @order: The allocation order of @folio.  Since TTM allocates higher-order
> >  + *         pages without __GFP_COMP, folio_nr_pages(@folio) would always
> >  + *         return 1; the caller must pass the true order explicitly.
> >  + * @writeback: Whether to perform immediate writeback of the folio's pages.
> >    * This may have performance implications.
> >  - * @idx: A unique integer for each page and each struct backup.
> >  + * @idx: A unique integer for the first page of the folio and each struct backup.
> >    * This allows the backup implementation to avoid managing
> >    * its address space separately.
> >  - * @page_gfp: The gfp value used when the page was allocated.
> >  - * This is used for accounting purposes.
> >  + * @folio_gfp: The gfp value used when the folio was allocated.
> >  + * Currently unused.
> >    * @alloc_gfp: The gfp to be used when allocating memory.
> >  + * @nr_pages_backed: Output. On a successful return, set to the number of
> >  + * pages actually backed up, which may be less than (1 << @order)
> >  + * if an -ENOMEM was encountered mid-folio.
> >    *
> >    * Context: If called from reclaim context, the caller needs to
> >    * assert that the shrinker gfp has __GFP_FS set, to avoid
> > @@@ -94,87 -87,53 +94,87 @@@
> >    * that the shrinker gfp has __GFP_IO set, since without it,
> >    * we're not allowed to start backup IO.
> >    *
> >  - * Return: A handle on success. Negative error code on failure.
> >  - *
> >  - * Note: This function could be extended to back up a folio and
> >  - * implementations would then split the folio internally if needed.
> >  - * Drawback is that the caller would then have to keep track of
> >  - * the folio size- and usage.
> >  + * Return: A handle for the first backed-up page on success (handles for
> >  + * subsequent pages follow sequentially). -ENOMEM if no pages could be backed
> >  + * up. Any other negative error code if a non-ENOMEM failure occurred; in that
> >  + * case any pages backed up so far are truncated before returning.
> >    */
> >   s64
> >  -ttm_backup_backup_page(struct file *backup, struct page *page,
> >  -		       bool writeback, pgoff_t idx, gfp_t page_gfp,
> >  -		       gfp_t alloc_gfp)
> >  +ttm_backup_backup_folio(struct file *backup, struct folio *folio,
> >  +			unsigned int order, bool writeback, pgoff_t idx,
> >  +			gfp_t folio_gfp, gfp_t alloc_gfp,
> >  +			pgoff_t *nr_pages_backed)
> >   {
> >   	struct address_space *mapping = backup->f_mapping;
> >  -	unsigned long handle = 0;
> >  +	int nr_pages = 1 << order;
> >   	struct folio *to_folio;
> >  -	int ret;
> >  +	int ret, i;
> >   
> >  -	to_folio = shmem_read_folio_gfp(mapping, idx, alloc_gfp);
> >  -	if (IS_ERR(to_folio))
> >  -		return PTR_ERR(to_folio);
> >  +	*nr_pages_backed = 0;
> >   
> >  -	folio_mark_accessed(to_folio);
> >  -	folio_lock(to_folio);
> >  -	folio_mark_dirty(to_folio);
> >  -	copy_highpage(folio_file_page(to_folio, idx), page);
> >  -	handle = ttm_backup_shmem_idx_to_handle(idx);
> >  +	for (i = 0; i < nr_pages; ) {
> >  +		int to_nr, j;
> >   
> >  -	if (writeback && !folio_mapped(to_folio) &&
> >  -	    folio_clear_dirty_for_io(to_folio)) {
> >  -		folio_set_reclaim(to_folio);
> >  -		ret = shmem_write_folio(to_folio);
> >  -		if (!folio_test_writeback(to_folio))
> >  -			folio_clear_reclaim(to_folio);
> >   		/*
> >  -		 * If writeout succeeds, it unlocks the folio.	errors
> >  -		 * are otherwise dropped, since writeout is only best
> >  -		 * effort here.
> >  +		 * Only inject past the first subpage so *nr_pages_backed is
> >  +		 * always > 0 here, matching a genuine mid-compound -ENOMEM
> >  +		 * and driving the caller's reactive split fallback instead
> >  +		 * of an early, no-progress failure.
> >   		 */
> >  -		if (ret)
> >  +		if (IS_ENABLED(CONFIG_FAULT_INJECTION) && i &&
> >  +		    ttm_backup_fault_inject_folio())
> >  +			to_folio = ERR_PTR(-ENOMEM);
> >  +		else
> >  +			to_folio = shmem_read_folio_gfp(mapping, idx + i, alloc_gfp);
> >  +		if (IS_ERR(to_folio)) {
> >  +			int err = PTR_ERR(to_folio);
> >  +
> >  +			if (err == -ENOMEM && *nr_pages_backed)
> >  +				return ttm_backup_shmem_idx_to_handle(idx);
> >  +
> >  +			if (*nr_pages_backed) {
> >  +				shmem_truncate_range(file_inode(backup),
> >  +						     (loff_t)idx << PAGE_SHIFT,
> >  +						     ((loff_t)(idx + i) << PAGE_SHIFT) - 1);
> >  +				/*
> >  +				 * The pages just truncated are no longer
> >  +				 * backed up; don't let the caller mistake
> >  +				 * them for valid handles.
> >  +				 */
> >  +				*nr_pages_backed = 0;
> >  +			}
> >  +			return err;
> >  +		}
> >  +
> >  +		to_nr = min_t(int, nr_pages - i,
> >  +			      folio_next_index(to_folio) - (idx + i));
> >  +
> >  +		folio_mark_accessed(to_folio);
> >  +		folio_lock(to_folio);
> >  +		folio_mark_dirty(to_folio);
> >  +
> >  +		for (j = 0; j < to_nr; j++)
> >  +			copy_highpage(folio_file_page(to_folio, idx + i + j),
> >  +				      folio_page(folio, i + j));
> >  +
> >  +		if (writeback && !folio_mapped(to_folio) &&
> >  +		    folio_clear_dirty_for_io(to_folio)) {
> >  +			folio_set_reclaim(to_folio);
> > ++			ret = shmem_write_folio(to_folio);
> >  +			if (!folio_test_writeback(to_folio))
> >  +				folio_clear_reclaim(to_folio);
> >  +			if (ret == AOP_WRITEPAGE_ACTIVATE)
> >  +				folio_unlock(to_folio);
> >  +		} else {
> >   			folio_unlock(to_folio);
> >  -	} else {
> >  -		folio_unlock(to_folio);
> >  +		}
> >  +
> >  +		folio_put(to_folio);
> >  +		i += to_nr;
> >  +		*nr_pages_backed = i;
> >   	}
> >   
> >  -	folio_put(to_folio);
> >  -
> >  -	return handle;
> >  +	return ttm_backup_shmem_idx_to_handle(idx);
> >   }
> >   
> >   /**
> 
> 
> ---end quoted text---

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

* Re: linux-next: manual merge of the mm-unstable tree with the drm-misc-fixes tree
  2026-07-20 14:46   ` Matthew Wilcox
@ 2026-07-20 22:08     ` Matthew Brost
  2026-07-21 16:55       ` Matthew Brost
  0 siblings, 1 reply; 12+ messages in thread
From: Matthew Brost @ 2026-07-20 22:08 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Christoph Hellwig, Mark Brown, Andrew Morton,
	Linux Kernel Mailing List, Linux Next Mailing List, Hugh Dickins,
	Baolin Wang, linux-mm, Christian Koenig, Huang Rui, dri-devel

On Mon, Jul 20, 2026 at 03:46:00PM +0100, Matthew Wilcox wrote:
> On Mon, Jul 20, 2026 at 04:41:41PM +0200, Christoph Hellwig wrote:
> > >   /**
> > >  - * ttm_backup_backup_page() - Backup a page
> > >  + * ttm_backup_backup_folio() - Backup a folio
> > >    * @backup: The struct backup pointer to use.
> > >  - * @page: The page to back up.
> > >  - * @writeback: Whether to perform immediate writeback of the page.
> > >  + * @folio: The folio to back up.
> > >  + * @order: The allocation order of @folio.  Since TTM allocates higher-order
> > >  + *         pages without __GFP_COMP, folio_nr_pages(@folio) would always
> > >  + *         return 1; the caller must pass the true order explicitly.
> 
> Wait, what?  This is just broken.  TTM should change to allocate using
> GFP_COMP.  Why can't graphics people ask questions before writing stupid
> patches?
> 

To be honest, I have no idea why TTM doesn't set GFP_COMP. This
predates my work in graphics by nearly a decade.

I found the following comment in TTM, which was added in this patch:
`git format-patch -1 bf9eee249ac20`

As far as I can tell, setting GFP_COMP would make things a lot easier in
a number of places.

Christian, who maintains TTM, is out for a couple of weeks, but this is
something we should probably take a closer look at.

Sorry for sending a stupid patch.

Matt

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

* Re: linux-next: manual merge of the mm-unstable tree with the drm-misc-fixes tree
  2026-07-20 21:58   ` Matthew Brost
@ 2026-07-21  4:54     ` Christoph Hellwig
  2026-07-21  6:06       ` Matthew Brost
  0 siblings, 1 reply; 12+ messages in thread
From: Christoph Hellwig @ 2026-07-21  4:54 UTC (permalink / raw)
  To: Matthew Brost
  Cc: Christoph Hellwig, Mark Brown, Andrew Morton,
	Linux Kernel Mailing List, Linux Next Mailing List, Hugh Dickins,
	Baolin Wang, linux-mm

On Mon, Jul 20, 2026 at 02:58:34PM -0700, Matthew Brost wrote:
> Do you have a suggestion of what parts to move over to shmem.c?
> 
> Pretty much all of this?

That's my first guess.  Basically when using a shmem folio to store
data we should have the code dealing with it contained in the shmem
code except for well-defined APIs.

> I can take a look at this in a follow up?

That would be great.

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

* Re: linux-next: manual merge of the mm-unstable tree with the drm-misc-fixes tree
  2026-07-21  4:54     ` Christoph Hellwig
@ 2026-07-21  6:06       ` Matthew Brost
  0 siblings, 0 replies; 12+ messages in thread
From: Matthew Brost @ 2026-07-21  6:06 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Mark Brown, Andrew Morton, Linux Kernel Mailing List,
	Linux Next Mailing List, Hugh Dickins, Baolin Wang, linux-mm

On Tue, Jul 21, 2026 at 06:54:16AM +0200, Christoph Hellwig wrote:
> On Mon, Jul 20, 2026 at 02:58:34PM -0700, Matthew Brost wrote:
> > Do you have a suggestion of what parts to move over to shmem.c?
> > 
> > Pretty much all of this?
> 
> That's my first guess.  Basically when using a shmem folio to store
> data we should have the code dealing with it contained in the shmem
> code except for well-defined APIs.
>

After quickly typing something - I'm landing on basically everything in
shmem.c.

> > I can take a look at this in a follow up?
> 
> That would be great.

Will share something shortly.

Matt

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

* Re: linux-next: manual merge of the mm-unstable tree with the drm-misc-fixes tree
  2026-07-20 22:08     ` Matthew Brost
@ 2026-07-21 16:55       ` Matthew Brost
  0 siblings, 0 replies; 12+ messages in thread
From: Matthew Brost @ 2026-07-21 16:55 UTC (permalink / raw)
  To: Matthew Wilcox
  Cc: Christoph Hellwig, Mark Brown, Andrew Morton,
	Linux Kernel Mailing List, Linux Next Mailing List, Hugh Dickins,
	Baolin Wang, linux-mm, Christian Koenig, Huang Rui, dri-devel

On Mon, Jul 20, 2026 at 03:08:22PM -0700, Matthew Brost wrote:
> On Mon, Jul 20, 2026 at 03:46:00PM +0100, Matthew Wilcox wrote:
> > On Mon, Jul 20, 2026 at 04:41:41PM +0200, Christoph Hellwig wrote:
> > > >   /**
> > > >  - * ttm_backup_backup_page() - Backup a page
> > > >  + * ttm_backup_backup_folio() - Backup a folio
> > > >    * @backup: The struct backup pointer to use.
> > > >  - * @page: The page to back up.
> > > >  - * @writeback: Whether to perform immediate writeback of the page.
> > > >  + * @folio: The folio to back up.
> > > >  + * @order: The allocation order of @folio.  Since TTM allocates higher-order
> > > >  + *         pages without __GFP_COMP, folio_nr_pages(@folio) would always
> > > >  + *         return 1; the caller must pass the true order explicitly.
> > 
> > Wait, what?  This is just broken.  TTM should change to allocate using
> > GFP_COMP.  Why can't graphics people ask questions before writing stupid
> > patches?
> > 
> 
> To be honest, I have no idea why TTM doesn't set GFP_COMP. This
> predates my work in graphics by nearly a decade.
> 
> I found the following comment in TTM, which was added in this patch:
> `git format-patch -1 bf9eee249ac20`
> 
> As far as I can tell, setting GFP_COMP would make things a lot easier in
> a number of places.
> 
> Christian, who maintains TTM, is out for a couple of weeks, but this is
> something we should probably take a closer look at.
> 

I have looked into this a bit, changing TTM over to allocations with
GFP_COMP seems pretty straight forward. I have local patches that are
working with my driver (Xe), will post something shortly.

Matt

> Sorry for sending a stupid patch.
> 
> Matt

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

end of thread, other threads:[~2026-07-21 16:55 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-20 13:31 linux-next: manual merge of the mm-unstable tree with the drm-misc-fixes tree Mark Brown
2026-07-20 14:41 ` Christoph Hellwig
2026-07-20 14:46   ` Matthew Wilcox
2026-07-20 22:08     ` Matthew Brost
2026-07-21 16:55       ` Matthew Brost
2026-07-20 21:58   ` Matthew Brost
2026-07-21  4:54     ` Christoph Hellwig
2026-07-21  6:06       ` Matthew Brost
  -- strict thread matches above, loose matches on Subject: below --
2025-08-13  1:11 Stephen Rothwell
2025-08-13  3:59 ` Andrew Morton
2025-08-13  9:07   ` Danilo Krummrich
2025-08-13  8:50 ` Danilo Krummrich

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox