linux-next: manual merge of the mm-nonmm-unstable tree with the mm tree

Mark Brown posted 1 patch 1 week, 2 days ago
There is a newer version of this series
linux-next: manual merge of the mm-nonmm-unstable tree with the mm tree
Posted by Mark Brown 1 week, 2 days ago
Hi all,

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

  mm/damon/vaddr.c

between commits:

  6acc47b87e9f0 ("mm/damon/vaddr: avoid hw-driven pte updates during damon_hugetlb_mkold()")
  24f6b1a0ab44a ("mm/damon/vaddr: respect folio end for DAMOS_STAT")
  f256012bb6a1c ("mm/damon/vaddr: respect folio end for DAMOS_MIGRATE_{HOT,COLD}")
  fa5b61fcf5c9d ("mm/damon/vaddr: remove a debug message")
  ed6700504e3f5 ("mm/damon: move damon_hugetlb_mkold() from vaddr to ops-common")
  88ac1f509a7e6 ("mm/damon/vaddr: support prep_probes")
  68ce5caa141c4 ("mm/damon/vaddr: support apply_probe")
  45e6bd6ac2868 ("mm/damon/vaddr: extend apply_probes() for hugetlb")
  4144f08e72a48 ("mm/damon/vaddr: support pgidle_unset probe filter type")
  6a00e5447c45e ("mm/damon/vaddr: support DAMON_FILTER_TYPE_PGIDLE_SET")
  3dabc621c0cfd ("mm/damon/core: extend probe_hits_wsum() for moving sum based calculation")

from the mm tree and commit:

  566380a1497eb ("mm/damon/vaddr: avoid hw-driven pte updates during damon_hugetlb_mkold()")

from the mm-nonmm-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 mm/damon/vaddr.c
index d5dde97b3cd0d,04ee2a2c6a4d6..0000000000000
--- a/mm/damon/vaddr.c
+++ b/mm/damon/vaddr.c
@@@ -189,12 -189,22 +189,12 @@@ static int damon_va_three_regions(struc
   *   <BIG UNMAPPED REGION 2>
   *   <stack>
   */
 -static void __damon_va_init_regions(struct damon_ctx *ctx,
 -				     struct damon_target *t)
 +static void __damon_va_init_regions(struct damon_target *t)
  {
 -	struct damon_target *ti;
  	struct damon_addr_range regions[3];
 -	int tidx = 0;
  
 -	if (damon_va_three_regions(t, regions)) {
 -		damon_for_each_target(ti, ctx) {
 -			if (ti == t)
 -				break;
 -			tidx++;
 -		}
 -		pr_debug("Failed to get three regions of %dth target\n", tidx);
 +	if (damon_va_three_regions(t, regions))
  		return;
 -	}
  
  	damon_set_regions(t, regions, 3, DAMON_MIN_REGION_SZ);
  }
@@@ -207,7 -217,7 +207,7 @@@ static void damon_va_init(struct damon_
  	damon_for_each_target(t, ctx) {
  		/* the user may set the target regions as they want */
  		if (!damon_nr_regions(t))
 -			__damon_va_init_regions(ctx, t);
 +			__damon_va_init_regions(t);
  	}
  }
  
@@@ -283,6 -293,40 +283,6 @@@ out
  }
  
  #ifdef CONFIG_HUGETLB_PAGE
 -static bool damon_hugetlb_ptep_mkold(pte_t *pte, struct mm_struct *mm,
 -		struct vm_area_struct *vma, unsigned long addr, pte_t *entry)
 -{
 -	unsigned long psize = huge_page_size(hstate_vma(vma));
 -
 -	if (!pte_young(*entry))
 -		return false;
 -	*entry = huge_ptep_get_and_clear(mm, addr, pte, psize);
 -	*entry = pte_mkold(*entry);
 -	set_huge_pte_at(mm, addr, pte, *entry, psize);
 -	return true;
 -}
 -
 -static void damon_hugetlb_mkold(pte_t *pte, struct mm_struct *mm,
 -				struct vm_area_struct *vma, unsigned long addr)
 -{
 -	bool referenced = false;
 -	pte_t entry = huge_ptep_get(mm, addr, pte);
 -	struct folio *folio = pfn_folio(pte_pfn(entry));
 -
 -	folio_get(folio);
 -
 -	referenced = damon_hugetlb_ptep_mkold(pte, mm, vma, addr, &entry);
 -	if (mmu_notifier_clear_young(mm, addr,
 -				     addr + huge_page_size(hstate_vma(vma))))
 -		referenced = true;
 -
 -	if (referenced)
 -		folio_set_young(folio);
 -
 -	folio_set_idle(folio);
 -	folio_put(folio);
 -}
 -
  static int damon_mkold_hugetlb_entry(pte_t *pte, unsigned long hmask,
  				     unsigned long addr, unsigned long end,
  				     struct mm_walk *walk)
@@@ -483,243 -527,6 +483,243 @@@ static unsigned int damon_va_check_acce
  	return max_nr_accesses;
  }
  
 +static void damon_va_prep_probe_region(struct damon_ctx *ctx,
 +		struct mm_struct *mm, struct damon_region *r,
 +		struct damon_probe *probe)
 +{
 +	struct damon_prep *p;
 +
 +	damon_for_each_prep(p, probe) {
 +		switch (p->action) {
 +		case DAMON_PREP_SET_PGIDLE:
 +			damon_va_mkold(mm, r->sampling_addr);
 +			break;
 +		default:
 +			break;
 +		}
 +	}
 +}
 +
 +static void damon_va_prep_probes(struct damon_ctx *ctx, bool set_samples)
 +{
 +	struct damon_target *t;
 +	struct mm_struct *mm;
 +	struct damon_region *r;
 +	struct damon_probe *p;
 +
 +	damon_for_each_target(t, ctx) {
 +		mm = damon_get_mm(t);
 +		if (!mm)
 +			continue;
 +		damon_for_each_region(r, t) {
 +			if (set_samples)
 +				r->sampling_addr = damon_rand(ctx, r->ar.start,
 +						r->ar.end);
 +			damon_for_each_probe(p, ctx)
 +				damon_va_prep_probe_region(ctx, mm, r, p);
 +		}
 +		mmput(mm);
 +	}
 +}
 +
 +static bool damon_va_young_addr(struct folio *folio, pte_t *pte, pmd_t *pmd,
 +		struct mm_struct *mm, unsigned long addr)
 +{
 +	bool young = false;
 +
 +	if (pte)
 +		young = pte_young(*pte);
 +	else if (pmd)
 +		young = pmd_young(*pmd);
 +	young = young || !folio_test_idle(folio) ||
 +		mmu_notifier_test_young(mm, addr);
 +	return young;
 +}
 +
 +static bool damon_va_filter_match(struct damon_filter *filter,
 +		struct folio *folio, pte_t *pte, pmd_t *pmd,
 +		struct mm_struct *mm, unsigned long addr)
 +{
 +	bool matched = false;
 +
 +	switch (filter->type) {
 +	case DAMON_FILTER_TYPE_PGIDLE_UNSET:
 +		if (!folio)
 +			matched = false;
 +		else
 +			matched = damon_va_young_addr(folio, pte, pmd, mm,
 +					addr);
 +		break;
 +	case DAMON_FILTER_TYPE_PGIDLE_SET:
 +		if (!folio)
 +			matched = false;
 +		else
 +			matched = !damon_va_young_addr(folio, pte, pmd, mm,
 +					addr);
 +		break;
 +	default:
 +		return damon_ops_filter_match(filter, folio);
 +	}
 +	return matched == filter->matching;
 +}
 +
 +static bool damon_va_filter_pass(struct folio *folio, struct damon_probe *p,
 +		pte_t *pte, pmd_t *pmd, struct mm_struct *mm,
 +		unsigned long addr)
 +{
 +	struct damon_filter *f;
 +	bool pass = true;
 +
 +	damon_for_each_filter(f, p) {
 +		if (damon_va_filter_match(f, folio, pte, pmd, mm, addr)) {
 +			pass = f->allow;
 +			break;
 +		}
 +		pass = !f->allow;
 +	}
 +	return pass;
 +}
 +
 +struct damon_va_probe_walk_private {
 +	struct damon_ctx *ctx;
 +	struct damon_region *r;
 +};
 +
 +static void damon_va_probe_folio(struct damon_ctx *ctx,
 +		struct damon_region *r, struct folio *folio,
 +		pte_t *pte, pmd_t *pmd, struct mm_struct *mm)
 +{
 +	struct damon_probe *probe;
 +	int i = 0;
 +
 +	damon_for_each_probe(probe, ctx) {
 +		if (damon_va_filter_pass(folio, probe, pte, pmd, mm,
 +					r->sampling_addr))
 +			r->probe_hits[i]++;
 +		i++;
 +	}
 +}
 +
 +static int damon_va_probe_pmd_entry(pmd_t *pmd, unsigned long addr,
 +		unsigned long next, struct mm_walk *walk)
 +{
 +	pte_t *pte;
 +	pte_t ptent;
 +	spinlock_t *ptl;
 +	struct folio *folio;
 +	struct damon_va_probe_walk_private *priv = walk->private;
 +
 +#ifdef CONFIG_TRANSPARENT_HUGEPAGE
 +	ptl = pmd_trans_huge_lock(pmd, walk->vma);
 +	if (ptl) {
 +		pmd_t pmde = pmdp_get(pmd);
 +
 +		if (!pmd_present(pmde))
 +			goto huge_out;
 +		folio = vm_normal_folio_pmd(walk->vma, addr, pmde);
 +		if (!folio)
 +			goto huge_out;
 +		damon_va_probe_folio(priv->ctx, priv->r, folio, NULL, &pmde,
 +				walk->vma->vm_mm);
 +
 +huge_out:
 +		spin_unlock(ptl);
 +		return 0;
 +	}
 +#endif	/* CONFIG_TRANSPARENT_HUGEPAGE */
 +
 +	pte = pte_offset_map_lock(walk->mm, pmd, addr, &ptl);
 +	if (!pte)
 +		return 0;
 +	ptent = ptep_get(pte);
 +	if (!pte_present(ptent))
 +		goto out;
 +	folio = vm_normal_folio(walk->vma, addr, ptent);
 +	if (!folio)
 +		goto out;
 +	damon_va_probe_folio(priv->ctx, priv->r, folio, &ptent, NULL,
 +			walk->vma->vm_mm);
 +
 +out:
 +	pte_unmap_unlock(pte, ptl);
 +	return 0;
 +}
 +
 +#ifdef CONFIG_HUGETLB_PAGE
 +static int damon_va_probe_hugetlb_entry(pte_t *pte, unsigned long hmask,
 +		unsigned long addr, unsigned long end, struct mm_walk *walk)
 +{
 +	struct damon_va_probe_walk_private *priv = walk->private;
 +	struct hstate *h = hstate_vma(walk->vma);
 +	struct folio *folio;
 +	spinlock_t *ptl;
 +	pte_t entry;
 +
 +	ptl = huge_pte_lock(h, walk->mm, pte);
 +	entry = huge_ptep_get(walk->mm, addr, pte);
 +	if (!pte_present(entry))
 +		goto out;
 +
 +	folio = pfn_folio(pte_pfn(entry));
 +	folio_get(folio);
 +	damon_va_probe_folio(priv->ctx, priv->r, folio, &entry, NULL,
 +			walk->vma->vm_mm);
 +	folio_put(folio);
 +
 +out:
 +	spin_unlock(ptl);
 +	return 0;
 +}
 +#else
 +#define damon_va_probe_hugetlb_entry NULL
 +#endif /* CONFIG_HUGETLB_PAGE */
 +
 +static void __damon_va_apply_probes(struct damon_ctx *ctx,
 +		struct mm_struct *mm,  struct damon_region *r)
 +{
 +	struct damon_va_probe_walk_private arg = {
 +		.ctx = ctx,
 +		.r = r,
 +	};
 +	struct mm_walk_ops damon_probe_walk_ops = {
 +		.pmd_entry = damon_va_probe_pmd_entry,
 +		.hugetlb_entry = damon_va_probe_hugetlb_entry,
 +	};
 +	unsigned long addr = r->sampling_addr;
 +
 +	if (!mm)
 +		return;
 +
 +	damon_va_walk_page_range(mm, addr, addr + 1, &damon_probe_walk_ops,
 +			&arg);
 +}
 +
 +static unsigned int damon_va_apply_probes(struct damon_ctx *ctx,
 +		bool set_samples, bool return_max_wsum)
 +{
 +	struct damon_target *t;
 +	struct mm_struct *mm;
 +	struct damon_region *r;
 +	unsigned int max_wsum = 0;
 +
 +	damon_for_each_target(t, ctx) {
 +		mm = damon_get_mm(t);
 +		damon_for_each_region(r, t) {
 +			if (set_samples)
 +				r->sampling_addr = damon_rand(ctx, r->ar.start,
 +						r->ar.end);
 +			__damon_va_apply_probes(ctx, mm, r);
 +			if (return_max_wsum)
 +				max_wsum = max(damon_probe_hits_wsum(r, false,
 +							false, ctx), max_wsum);
 +		}
 +		if (mm)
 +			mmput(mm);
 +	}
 +
 +	return max_wsum;
 +}
 +
  static bool damos_va_filter_young_match(struct damos_filter *filter,
  		struct folio *folio, struct vm_area_struct *vma,
  		unsigned long addr, pte_t *ptep, pmd_t *pmdp)
@@@ -869,8 -676,6 +869,8 @@@ huge_out
  		return 0;
  
  	for (; addr < next; pte += nr, addr += nr * PAGE_SIZE) {
 +		unsigned long page_idx;
 +
  		nr = 1;
  		ptent = ptep_get(pte);
  
@@@ -883,8 -688,7 +883,8 @@@
  			continue;
  		damos_va_migrate_dests_add(folio, walk->vma, addr, dests,
  				migration_lists);
 -		nr = folio_nr_pages(folio);
 +		page_idx = folio_page_idx(folio, pte_page(ptent));
 +		nr = folio_nr_pages(folio) - page_idx;
  	}
  	pte_unmap_unlock(start_pte, ptl);
  	return 0;
@@@ -1034,8 -838,6 +1034,8 @@@ huge_unlock
  		return 0;
  
  	for (; addr < next; pte += nr, addr += nr * PAGE_SIZE) {
 +		unsigned long page_idx;
 +
  		nr = 1;
  		ptent = ptep_get(pte);
  
@@@ -1049,8 -851,7 +1049,8 @@@
  
  		if (!damos_va_filter_out(s, folio, vma, addr, pte, NULL))
  			*sz_filter_passed += folio_size(folio);
 -		nr = folio_nr_pages(folio);
 +		page_idx = folio_page_idx(folio, pte_page(ptent));
 +		nr = folio_nr_pages(folio) - page_idx;
  		s->last_applied = folio;
  	}
  	pte_unmap_unlock(start_pte, ptl);
@@@ -1148,8 -949,6 +1148,8 @@@ static int __init damon_va_initcall(voi
  		.update = damon_va_update,
  		.prepare_access_checks = damon_va_prepare_access_checks,
  		.check_accesses = damon_va_check_accesses,
 +		.prep_probes = damon_va_prep_probes,
 +		.apply_probes = damon_va_apply_probes,
  		.target_valid = damon_va_target_valid,
  		.cleanup_target = damon_va_cleanup_target,
  		.apply_scheme = damon_va_apply_scheme,
Re: linux-next: manual merge of the mm-nonmm-unstable tree with the mm tree
Posted by Andrew Morton 1 week, 2 days ago
On Tue, 15 Sep 2026 14:32:22 +0100 Mark Brown <broonie@kernel.org> wrote:

> Hi all,
> 
> Today's linux-next merge of the mm-nonmm-unstable tree got a conflict in:
> 
>   mm/damon/vaddr.c
> 
> between commits:
> 
>   6acc47b87e9f0 ("mm/damon/vaddr: avoid hw-driven pte updates during damon_hugetlb_mkold()")
>   24f6b1a0ab44a ("mm/damon/vaddr: respect folio end for DAMOS_STAT")
>   f256012bb6a1c ("mm/damon/vaddr: respect folio end for DAMOS_MIGRATE_{HOT,COLD}")
>   fa5b61fcf5c9d ("mm/damon/vaddr: remove a debug message")
>   ed6700504e3f5 ("mm/damon: move damon_hugetlb_mkold() from vaddr to ops-common")
>   88ac1f509a7e6 ("mm/damon/vaddr: support prep_probes")
>   68ce5caa141c4 ("mm/damon/vaddr: support apply_probe")
>   45e6bd6ac2868 ("mm/damon/vaddr: extend apply_probes() for hugetlb")
>   4144f08e72a48 ("mm/damon/vaddr: support pgidle_unset probe filter type")
>   6a00e5447c45e ("mm/damon/vaddr: support DAMON_FILTER_TYPE_PGIDLE_SET")
>   3dabc621c0cfd ("mm/damon/core: extend probe_hits_wsum() for moving sum based calculation")
> 
> from the mm tree and commit:

hm, "mm tree" isn't a branch name.  I assume "mm-unstable" was meant.

> 
>   566380a1497eb ("mm/damon/vaddr: avoid hw-driven pte updates during damon_hugetlb_mkold()")
> 
> from the mm-nonmm-unstable tree.
> 

Something went wrong here.  "mm/damon/vaddr: avoid hw-driven pte
updates during damon_hugetlb_mkold()" is in mm-hotfixes-unstable. 
mm-hotfixes-unstable is merged into mm-unstable and mm-nonmm-unstable.
Re: linux-next: manual merge of the mm-nonmm-unstable tree with the mm tree
Posted by Mark Brown 1 week, 2 days ago
On Tue, Sep 15, 2026 at 10:54:13AM -0700, Andrew Morton wrote:
> On Tue, 15 Sep 2026 14:32:22 +0100 Mark Brown <broonie@kernel.org> wrote:

> > from the mm tree and commit:

> hm, "mm tree" isn't a branch name.  I assume "mm-unstable" was meant.

No, this is David's tree at:

   https://git.kernel.org/pub/scm/linux/kernel/git/mm/linux.git for-next

As requested your nonmm branches are the only ones left from your tree,
they were replaced by the above and the fixes branch at:

   https://git.kernel.org/pub/scm/linux/kernel/git/mm/linux.git for-next-fixes

Something got messed up with the CCs there, there were two other similar
conflicts today.  I'll double check what the scripts are doing next time
this comes up.
Re: linux-next: manual merge of the mm-nonmm-unstable tree with the mm tree
Posted by David Hildenbrand (Arm) 1 week, 2 days ago
On 9/15/26 19:59, Mark Brown wrote:
> On Tue, Sep 15, 2026 at 10:54:13AM -0700, Andrew Morton wrote:
>> On Tue, 15 Sep 2026 14:32:22 +0100 Mark Brown <broonie@kernel.org> wrote:
> 
>>> from the mm tree and commit:
> 
>> hm, "mm tree" isn't a branch name.  I assume "mm-unstable" was meant.
> 
> No, this is David's tree at:
> 
>    https://git.kernel.org/pub/scm/linux/kernel/git/mm/linux.git for-next
> 
> As requested your nonmm branches are the only ones left from your tree,
> they were replaced by the above and the fixes branch at:
> 
>    https://git.kernel.org/pub/scm/linux/kernel/git/mm/linux.git for-next-fixes
> 

Yes, only the MM portion go through the MM tree.

I think the problem is that

akpm/mm-nonmm-unstable

is based on

akpm/mm-hotfixes-unstable (and akpm/mm-hotfixes-stable)

Which only go into the MM-next tree.

So if a commit in akpm/mm-hotfixes-unstable changes (and a stale one is in
mm/for-next-fixes), it comes it through two trees in different forms.

Likely we'd need a separate akpm branch for NON-MM hotfixes ... or I'll take
care of all MM hotfixes through the mm/core tree.

-- 
Cheers,

David
Re: linux-next: manual merge of the mm-nonmm-unstable tree with the mm tree
Posted by Mark Brown 1 week, 2 days ago
On Tue, Sep 15, 2026 at 08:23:27PM +0200, David Hildenbrand (Arm) wrote:

> I think the problem is that

> akpm/mm-nonmm-unstable

> is based on

> akpm/mm-hotfixes-unstable (and akpm/mm-hotfixes-stable)

> Which only go into the MM-next tree.

> So if a commit in akpm/mm-hotfixes-unstable changes (and a stale one is in
> mm/for-next-fixes), it comes it through two trees in different forms.

Yes, rebasing a branch that's being merged elsewhere is going to cause
issues like this.

> Likely we'd need a separate akpm branch for NON-MM hotfixes ... or I'll take
> care of all MM hotfixes through the mm/core tree.

Either of those should work well, I can easily add an extra nonmm
hotfixes branch - let me know if that's what you decide to do.