Re: [PATCH] lib: test_hmm: use device devt for coherent device range selection

From: Andrew Morton

Date: Mon Jun 29 2026 - 20:07:05 EST


On Mon, 29 Jun 2026 16:30:14 -0700 Stanislav Kinsburskii <skinsburskii@xxxxxxxxx> wrote:

> Commit af69016dab96 ("lib: test_hmm: implement a device release method")
> moved the initial dmirror_allocate_chunk() call before cdev_device_add().
> That means the struct cdev has not been added yet, so cdev_add() has not
> initialized mdevice->cdevice.dev.
>
> The coherent-device range selection uses the device minor to choose between
> spm_addr_dev0 and spm_addr_dev1. Reading MINOR(mdevice->cdevice.dev) before
> cdev_add() therefore always sees an uninitialized dev_t. As a result, both
> coherent devices select the same physical range, and adding the second
> device fails due to the overlapping dev_pagemap range.
>
> Use mdevice->device.devt instead. It is initialized in
> dmirror_device_init() before dmirror_allocate_chunk() is called and is the
> same dev_t later passed to cdev_device_add().

Thanks.

> Fixes: af69016dab96 ("lib: test_hmm: implement a device release method")

We should cc the people involved with that commit. Added.

> --- a/lib/test_hmm.c
> +++ b/lib/test_hmm.c
> @@ -581,7 +581,7 @@ static int dmirror_allocate_chunk(struct dmirror_device *mdevice,
> devmem->pagemap.type = MEMORY_DEVICE_PRIVATE;
> break;
> case HMM_DMIRROR_MEMORY_DEVICE_COHERENT:
> - devmem->pagemap.range.start = (MINOR(mdevice->cdevice.dev) - 2) ?
> + devmem->pagemap.range.start = (MINOR(mdevice->device.devt) - 2) ?
> spm_addr_dev0 :
> spm_addr_dev1;
> devmem->pagemap.range.end = devmem->pagemap.range.start +
>

af69016dab96 had cc:stable, so I'll add cc:stable to this patch, to
help ensure that it lands in the appropriate places.