diff mbox series

[v3,11/14] device-dax: ensure dev_dax->pgmap is valid for dynamic devices

Message ID 20210714193542.21857-12-joao.m.martins@oracle.com (mailing list archive)
State New, archived
Headers show
Series mm, sparse-vmemmap: Introduce compound pagemaps | expand

Commit Message

Joao Martins July 14, 2021, 7:35 p.m. UTC
Right now, only static dax regions have a valid @pgmap pointer in its
struct dev_dax. Dynamic dax case however, do not.

In preparation for device-dax compound pagemap support, make sure that
dev_dax pgmap field is set after it has been allocated and initialized.

Suggested-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
---
 drivers/dax/device.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Dan Williams July 28, 2021, 7:30 a.m. UTC | #1
On Wed, Jul 14, 2021 at 12:36 PM Joao Martins <joao.m.martins@oracle.com> wrote:
>
> Right now, only static dax regions have a valid @pgmap pointer in its
> struct dev_dax. Dynamic dax case however, do not.
>
> In preparation for device-dax compound pagemap support, make sure that
> dev_dax pgmap field is set after it has been allocated and initialized.

I think this is ok to fold into the patch that needs it.

>
> Suggested-by: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
> ---
>  drivers/dax/device.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/dax/device.c b/drivers/dax/device.c
> index 0b82159b3564..6e348b5f9d45 100644
> --- a/drivers/dax/device.c
> +++ b/drivers/dax/device.c
> @@ -426,6 +426,8 @@ int dev_dax_probe(struct dev_dax *dev_dax)
>         }
>
>         pgmap->type = MEMORY_DEVICE_GENERIC;
> +       dev_dax->pgmap = pgmap;
> +
>         addr = devm_memremap_pages(dev, pgmap);
>         if (IS_ERR(addr))
>                 return PTR_ERR(addr);
> --
> 2.17.1
>
Joao Martins July 28, 2021, 3:56 p.m. UTC | #2
On 7/28/21 8:30 AM, Dan Williams wrote:
> On Wed, Jul 14, 2021 at 12:36 PM Joao Martins <joao.m.martins@oracle.com> wrote:
>>
>> Right now, only static dax regions have a valid @pgmap pointer in its
>> struct dev_dax. Dynamic dax case however, do not.
>>
>> In preparation for device-dax compound pagemap support, make sure that
>> dev_dax pgmap field is set after it has been allocated and initialized.
> 
> I think this is ok to fold into the patch that needs it.

OK, I've squashed that in.
Joao Martins Aug. 6, 2021, 12:28 p.m. UTC | #3
On 7/28/21 4:56 PM, Joao Martins wrote:
> On 7/28/21 8:30 AM, Dan Williams wrote:
>> On Wed, Jul 14, 2021 at 12:36 PM Joao Martins <joao.m.martins@oracle.com> wrote:
>>>
>>> Right now, only static dax regions have a valid @pgmap pointer in its
>>> struct dev_dax. Dynamic dax case however, do not.
>>>
>>> In preparation for device-dax compound pagemap support, make sure that
>>> dev_dax pgmap field is set after it has been allocated and initialized.
>>
>> I think this is ok to fold into the patch that needs it.
> 
> OK, I've squashed that in.
> 
I am wondering now whether I should un-squash this into a separate patch.

It regresses one of the test suites from ndctl for dynamic dax regions. memremap_pages()
calls (from a dynamic region) starts hitting rather random splats (below) on the 'root'
device (not the dax device children aiui). This fixes it but I am yet 100% if should be
this way:

diff --git a/drivers/dax/bus.c b/drivers/dax/bus.c
index 6cc4da4c713d..2a3a70e62d89 100644
--- a/drivers/dax/bus.c
+++ b/drivers/dax/bus.c
@@ -363,6 +363,9 @@ void kill_dev_dax(struct dev_dax *dev_dax)

        kill_dax(dax_dev);
        unmap_mapping_range(inode->i_mapping, 0, 0, 1);
+
+       if (!is_static(dev_dax->region))
+               dev_dax->pgmap = NULL;
 }
 EXPORT_SYMBOL_GPL(kill_dev_dax);

stacktraces:

[  834.884765] ------------[ cut here ]------------
[  834.885887] nr_range must be specified
[  834.886461] WARNING: CPU: 3 PID: 3148 at mm/memremap.c:347 memremap_pages+0x54f/0x610
[  834.887578] Modules linked in:
[  834.887993] CPU: 3 PID: 3148 Comm: lt-daxctl Not tainted 5.14.0-rc3-next-20210729+ #201
[  834.889131] RIP: 0010:memremap_pages+0x54f/0x610
[  834.889886] Code: e1 97 00 0f 0b e9 14 fc ff ff 80 3d 11 99 79 01 00 0f 85 3e fc ff ff
48 c7 c7 e8 78 5e 82 c6 05 fd 98 79 01 01 e8 f8 e0 97 00 <0f> 0b 48 c7 c0 ea ff ff ff e9
2f fb ff ff 48 c7 c7 b0 a7 d1 82 e8
[  834.892491] RSP: 0018:ffffc90008fb3b40 EFLAGS: 00010286
[  834.893249] RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000027
[  834.894250] RDX: 0000000000000000 RSI: ffff88900fcd7610 RDI: ffff88900fcd7618
[  834.895283] RBP: ffffc90008fb3b98 R08: 0000000000000000 R09: c0000000ffffefff
[  834.896286] R10: ffffc90008fb3930 R11: ffffc90008fb3928 R12: 8000000000000063
[  834.897279] R13: ffff889042856430 R14: 0000000000000001 R15: ffff889042856400
[  834.898279] FS:  00007f83ddfd8780(0000) GS:ffff88900fcc0000(0000) knlGS:0000000000000000
[  834.899423] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  834.900194] CR2: 00007ffdb895c148 CR3: 0000000106bfc006 CR4: 0000000000170ee0
[  834.901195] Call Trace:
[  834.901651]  devm_memremap_pages+0x22/0x70
[  834.902244]  dev_dax_probe+0x175/0x2b0
[  834.902797]  dax_bus_probe+0x73/0xa0
[  834.903285]  really_probe+0xcf/0x3a0
[  834.903801]  __driver_probe_device+0xb3/0x130
[  834.904363]  driver_probe_device+0x24/0x90
[  834.904967]  __driver_attach+0xa1/0x170
[  834.905525]  ? __device_attach_driver+0xe0/0xe0
[  834.906164]  ? __device_attach_driver+0xe0/0xe0
[  834.906818]  bus_for_each_dev+0x74/0xb0
[  834.907321]  driver_attach+0x1e/0x20
[  834.907875]  do_id_store+0x1db/0x210
[  834.908352]  new_id_store+0x13/0x20
[  834.908865]  drv_attr_store+0x27/0x40
[  834.909398]  sysfs_kf_write+0x3b/0x50
[  834.909968]  kernfs_fop_write_iter+0x128/0x1b0
[  834.910635]  new_sync_write+0x117/0x1b0
[  834.911139]  vfs_write+0x181/0x250
[  834.911644]  ? do_sys_openat2+0x1d7/0x300
[  834.912216]  ksys_write+0x61/0xe0
[  834.912698]  __x64_sys_write+0x1a/0x20
[  834.913242]  do_syscall_64+0x3a/0x80
[  834.913772]  entry_SYSCALL_64_after_hwframe+0x44/0xae
[  834.914491] RIP: 0033:0x7f83dd4cda00
[  834.915010] Code: 73 01 c3 48 8b 0d 70 74 2d 00 f7 d8 64 89 01 48 83 c8 ff c3 66 0f 1f
44 00 00 83 3d bd d5 2d 00 00 75 10 b8 01 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 31 c3 48
83 ec 08 e8 7e cc 01 00 48 89 04 24
[  834.917543] RSP: 002b:00007ffdb895f308 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
[  834.918627] RAX: ffffffffffffffda RBX: 0000000000000004 RCX: 00007f83dd4cda00
[  834.919650] RDX: 0000000000000007 RSI: 00000000020c639d RDI: 0000000000000004
[  834.920658] RBP: 00000000020c639d R08: 0000000000000000 R09: 00000000020c45c0
[  834.921649] R10: 2f7861645f656369 R11: 0000000000000246 R12: 0000000000000007
[  834.922670] R13: 0000000000000001 R14: 00000000020c71b0 R15: 00000000020cc2e0
[  834.923650] ---[ end trace 61ea8560dbeb3a89 ]---

[  835.941573] Hotplug memory [0x0-0x0] exceeds maximum addressable range [0x0-0x3fffffffffff]
[  835.944269] ------------[ cut here ]------------
[  835.945412] kernel BUG at mm/memory_hotplug.c:316!
[  835.946574] invalid opcode: 0000 [#1] SMP PTI
[  835.947622] CPU: 6 PID: 3593 Comm: lt-daxctl Tainted: G        W
5.14.0-rc3-next-20210729+ #201
[  835.949845] RIP: 0010:__add_pages+0x100/0x150
[  835.950899] Code: ba 89 55 d4 e8 4d 32 00 00 8b 55 d4 48 83 c4 08 89 d0 5b 41 5c 41 5d
41 5e 41 5f 5d c3 31 d2 eb e0 0f 0b ba ea ff ff ff eb e2 <0f> 0b 80 3d e6 43 dc 00 00 ba
ea ff ff ff 75 d2 48 c7 c7 b8 35 5e
[  835.953662] RSP: 0018:ffffc900094bbab0 EFLAGS: 00010246
[  835.954336] RAX: 0000000000000000 RBX: 0000000000000000 RCX: 0000000000000000
[  835.955276] RDX: 0000000000000000 RSI: ffff88900fd97610 RDI: ffff88900fd97610
[  835.956251] RBP: ffffc900094bbae0 R08: 0000000000000000 R09: c0000000ffffefff
[  835.957214] R10: ffffc900094bb888 R11: ffffc900094bb880 R12: 0000000000000000
[  835.958154] R13: 0000000000000000 R14: ffffc900094bbb50 R15: 0000000000000000
[  835.959097] FS:  00007fd63c55e780(0000) GS:ffff88900fd80000(0000) knlGS:0000000000000000
[  835.960163] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
[  835.960960] CR2: 00007fffc4d7abd8 CR3: 00000001126f2001 CR4: 0000000000170ee0
[  835.961903] Call Trace:
[  835.962220]  add_pages+0x17/0x70
[  835.962696]  arch_add_memory+0x45/0x50
[  835.963175]  memremap_pages+0x2a8/0x610
[  835.963726]  devm_memremap_pages+0x22/0x70
[  835.964223]  dev_dax_probe+0x175/0x2b0
[  835.964778]  dax_bus_probe+0x73/0xa0
[  835.965215]  really_probe+0xcf/0x3a0
[  835.965717]  __driver_probe_device+0xb3/0x130
[  835.966248]  driver_probe_device+0x24/0x90
[  835.966835]  __driver_attach+0xa1/0x170
[  835.967340]  ? __device_attach_driver+0xe0/0xe0
[  835.967956]  ? __device_attach_driver+0xe0/0xe0
[  835.968589]  bus_for_each_dev+0x74/0xb0
[  835.969090]  driver_attach+0x1e/0x20
[  835.969605]  do_id_store+0x1db/0x210
[  835.970057]  new_id_store+0x13/0x20
[  835.970536]  drv_attr_store+0x27/0x40
[  835.971023]  sysfs_kf_write+0x3b/0x50
[  835.971529]  kernfs_fop_write_iter+0x128/0x1b0
[  835.972141]  new_sync_write+0x117/0x1b0
[  835.972697]  vfs_write+0x181/0x250
[  835.973130]  ? do_sys_openat2+0x1d7/0x300
[  835.973698]  ksys_write+0x61/0xe0
[  835.974117]  __x64_sys_write+0x1a/0x20
[  835.974654]  do_syscall_64+0x3a/0x80
[  835.975105]  entry_SYSCALL_64_after_hwframe+0x44/0xae
[  835.975802] RIP: 0033:0x7fd63ba53a00
[  835.976257] Code: 73 01 c3 48 8b 0d 70 74 2d 00 f7 d8 64 89 01 48 83 c8 ff c3 66 0f 1f
44 00 00 83 3d bd d5 2d 00 00 75 10 b8 01 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 31 c3 48
83 ec 08 e8 7e cc 01 00 48 89 04 24
[  835.978754] RSP: 002b:00007fffc4d7dd98 EFLAGS: 00000246 ORIG_RAX: 0000000000000001
[  835.979765] RAX: ffffffffffffffda RBX: 0000000000000004 RCX: 00007fd63ba53a00
[  835.980761] RDX: 0000000000000007 RSI: 000000000081939d RDI: 0000000000000004
[  835.981714] RBP: 000000000081939d R08: 0000000000000000 R09: 00000000008175c0
[  835.982671] R10: 2f7861645f656369 R11: 0000000000000246 R12: 0000000000000007
[  835.983647] R13: 0000000000000001 R14: 000000000081a1b0 R15: 000000000081f2e0
[  835.984593] Modules linked in:
[  835.985041] ---[ end trace 61ea8560dbeb3a8a ]---
[  835.985789] RIP: 0010:__add_pages+0x100/0x150
diff mbox series

Patch

diff --git a/drivers/dax/device.c b/drivers/dax/device.c
index 0b82159b3564..6e348b5f9d45 100644
--- a/drivers/dax/device.c
+++ b/drivers/dax/device.c
@@ -426,6 +426,8 @@  int dev_dax_probe(struct dev_dax *dev_dax)
 	}
 
 	pgmap->type = MEMORY_DEVICE_GENERIC;
+	dev_dax->pgmap = pgmap;
+
 	addr = devm_memremap_pages(dev, pgmap);
 	if (IS_ERR(addr))
 		return PTR_ERR(addr);