]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
lib: test_hmm: use device devt for coherent device range selection
authorStanislav Kinsburskii <skinsburskii@gmail.com>
Mon, 29 Jun 2026 23:30:14 +0000 (16:30 -0700)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 21 Jul 2026 00:41:26 +0000 (17:41 -0700)
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().

Link: https://lore.kernel.org/178277581197.172200.16265155329935822153.stgit@skinsburskii
Fixes: af69016dab96 ("lib: test_hmm: implement a device release method")
Signed-off-by: Stanislav Kinsburskii <skinsburskii@gmail.com>
Reviewed-by: Alistair Popple <apopple@nvidia.com>
Cc: Balbir Singh <balbirs@nvidia.com>
Cc: Zenghui Yu (Huawei) <zenghui.yu@linux.dev>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/test_hmm.c

index 9c59d1ceb5b57d6257f5fe43a3b60586333ad4e3..c4adbf98fac7901a44ea843a7611fc1721da52bd 100644 (file)
@@ -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 +