GPF on 0xdead000000000100 in nvme_map_data - Linux 5.9.9
Subsystems (5)
Hello,
I can reliably hit kernel panic in nvme_map_data() which looks like the one below. It happens on Linux 5.9.9, while 5.4.75 works fine. I haven't tried other version on this hardware. Linux is running as Xen PV dom0, on top of nvme there is LUKS and then LVM with thin provisioning. The crash happens reliably when starting a Xen domU (which uses one of thin provisioned LVM volumes as its disk). But booting dom0 works fine (even though it is using the same disk setup for its root filesystem).
I did a bit of debugging and found it's about this part:
drivers/nvme/host/pci.c:
800 static blk_status_t nvme_map_data(struct nvme_dev *dev, struct request *req,
801 struct nvme_command *cmnd)
802 {
803 struct nvme_iod *iod = blk_mq_rq_to_pdu(req); 804 blk_status_t ret = BLK_STS_RESOURCE; 805 int nr_mapped;
806
807 if (blk_rq_nr_phys_segments(req) == 1) {
808 struct bio_vec bv = req_bvec(req);
809
810 if (!is_pci_p2pdma_page(bv.bv_page)) {
Here, bv.bv_page->pgmap is LIST_POISON1, while page_zonenum(bv.bv_page) says ZONE_DEVICE. So, is_pci_p2pdma_page() crashes on accessing bv.bv_page->pgmap->type.
The panic message:
general protection fault, probably for non-canonical address 0xdead000000000100: 0000 [#1] SMP NOPTI CPU: 1 PID: 134 Comm: kworker/u12:2 Not tainted 5.9.9-1.qubes.x86_64 #1 Hardware name: LENOVO 20M9CTO1WW/20M9CTO1WW, BIOS N2CET50W (1.33 ) 01/15/2020 Workqueue: dm-thin do_worker [dm_thin_pool] RIP: e030:nvme_map_data+0x300/0x3a0 [nvme] Code: b8 fe ff ff e9 a8 fe ff ff 4c 8b 56 68 8b 5e 70 8b 76 74 49 8b 02 48 c1 e8 33 83 e0 07 83 f8 04 0f 85 f2 fe ff ff 49 8b 42 08 <83> b8 d0 00 00 00 04 0f 85 e1 fe ff ff e9 38 fd ff ff 8b 55 70 be RSP: e02b:ffffc900010e7ad8 EFLAGS: 00010246 RAX: dead000000000100 RBX: 0000000000001000 RCX: ffff8881a58f5000 RDX: 0000000000001000 RSI: 0000000000000000 RDI: ffff8881a679e000 RBP: ffff8881a5ef4c80 R08: ffff8881a5ef4c80 R09: 0000000000000002 R10: ffffea0003dfff40 R11: 0000000000000008 R12: ffff8881a679e000 R13: ffffc900010e7b20 R14: ffff8881a70b5980 R15: ffff8881a679e000 FS: 0000000000000000(0000) GS:ffff8881b5440000(0000) knlGS:0000000000000000 CS: e030 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000001d64408 CR3: 00000001aa2c0000 CR4: 0000000000050660 Call Trace: nvme_queue_rq+0xa7/0x1a0 [nvme] __blk_mq_try_issue_directly+0x11d/0x1e0 ? add_wait_queue_exclusive+0x70/0x70 blk_mq_try_issue_directly+0x35/0xc0l[ blk_mq_submit_bio+0x58f/0x660 __submit_bio_noacct+0x300/0x330 process_shared_bio+0x126/0x1b0 [dm_thin_pool] process_cell+0x226/0x280 [dm_thin_pool] process_thin_deferred_cells+0x185/0x320 [dm_thin_pool] process_deferred_bios+0xa4/0x2a0 [dm_thin_pool]UX do_worker+0xcc/0x130 [dm_thin_pool] process_one_work+0x1b4/0x370 worker_thread+0x4c/0x310 ? process_one_work+0x370/0x370 kthread+0x11b/0x140 ? __kthread_bind_mask+0x60/0x60< ret_from_fork+0x22/0x30 Modules linked in: loop snd_seq_dummy snd_hrtimer nf_tables nfnetlink vfat fat snd_sof_pci snd_sof_intel_byt snd_sof_intel_ipc snd_sof_intel_hda_common snd_soc_hdac_hda snd_sof_xtensa_dsp snd_sof_intel_hda snd_sof snd_soc_skl snd_soc_sst_
ipc snd_soc_sst_dsp snd_hda_ext_core snd_soc_acpi_intel_match snd_soc_acpi snd_soc_core snd_compress ac97_bus snd_pcm_dmaengine elan_i2c snd_hda_codec_hdmi mei_hdcp iTCO_wdt intel_powerclamp intel_pmc_bxt ee1004 intel_rapl_msr iTCO_vendor _support joydev pcspkr intel_wmi_thunderbolt wmi_bmof thunderbolt ucsi_acpi idma64 typec_ucsi snd_hda_codec_realtek typec snd_hda_codec_generic snd_hda_intel snd_intel_dspcfg snd_hda_codec thinkpad_acpi snd_hda_core ledtrig_audio int3403_ thermal snd_hwdep snd_seq snd_seq_device snd_pcm iwlwifi snd_timer processor_thermal_device mei_me cfg80211 intel_rapl_common snd e1000e mei int3400_thermal int340x_thermal_zone i2c_i801 acpi_thermal_rel soundcore intel_soc_dts_iosf i2c_s mbus rfkill intel_pch_thermal xenfs
ip_tables dm_thin_pool dm_persistent_data dm_bio_prison dm_crypt nouveau rtsx_pci_sdmmc mmc_core mxm_wmi crct10dif_pclmul ttm crc32_pclmul crc32c_intel i915 ghash_clmulni_intel i2c_algo_bit serio_raw nvme drm_kms_helper cec xhci_pci nvme_core rtsx_pci xhci_pci_renesas drm xhci_hcd wmi video pinctrl_cannonlake pinctrl_intel xen_privcmd xen_pciback xen_blkback xen_gntalloc xen_gntdev xen_evtchn uinput
---[ end trace f8d47e4aa6724df4 ]--- RIP: e030:nvme_map_data+0x300/0x3a0 [nvme] Code: b8 fe ff ff e9 a8 fe ff ff 4c 8b 56 68 8b 5e 70 8b 76 74 49 8b 02 48 c1 e8 33 83 e0 07 83 f8 04 0f 85 f2 fe ff ff 49 8b 42 08 <83> b8 d0 00 00 00 04 0f 85 e1 fe ff ff e9 38 fd ff ff 8b 55 70 be RSP: e02b:ffffc900010e7ad8 EFLAGS: 00010246 RAX: dead000000000100 RBX: 0000000000001000 RCX: ffff8881a58f5000 RDX: 0000000000001000 RSI: 0000000000000000 RDI: ffff8881a679e000 RBP: ffff8881a5ef4c80 R08: ffff8881a5ef4c80 R09: 0000000000000002 R10: ffffea0003dfff40 R11: 0000000000000008 R12: ffff8881a679e000 R13: ffffc900010e7b20 R14: ffff8881a70b5980 R15: ffff8881a679e000 FS: 0000000000000000(0000) GS:ffff8881b5440000(0000) knlGS:0000000000000000 CS: e030 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000001d64408 CR3: 00000001aa2c0000 CR4: 0000000000050660 Kernel panic - not syncing: Fatal exception
Kernel Offset: disabled
Any ideas?
If not, I can try to run bisect on it, but it will be rather time consuming.
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Keith Busch
maintainerQuoted 24 lines · Marek Marczykowski-Górecki
I can reliably hit kernel panic in
nvme_map_data()which looks like the one below. It happens on Linux 5.9.9, while 5.4.75 works fine. I haven't tried other version on this hardware. Linux is running as Xen PV dom0, on top of nvme there is LUKS and then LVM with thin provisioning. The crash happens reliably when starting a Xen domU (which uses one of thin provisioned LVM volumes as its disk). But booting dom0 works fine (even though it is using the same disk setup for its root filesystem).I did a bit of debugging and found it's about this part:
drivers/nvme/host/pci.c:
800 staticblk_status_tnvme_map_data(structnvme_dev*dev, struct request *req,
801 structnvme_command*cmnd)
802 {803 struct nvme_iod *iod = blk_mq_rq_to_pdu(req); 804 blk_status_t ret = BLK_STS_RESOURCE; 805 int nr_mapped;806
807 if (blk_rq_nr_phys_segments(req)== 1) {
808 structbio_vecbv =req_bvec(req);
809
810 if (!is_pci_p2pdma_page(bv.bv_page)) {
Quoted 3 lines
Here,
bv.bv_page->pgmapisLIST_POISON1, whilepage_zonenum(bv.bv_page)saysZONE_DEVICE. So,is_pci_p2pdma_page()crashes on accessingbv.bv_page->pgmap->type.
Something sounds off. I thought all ZONE_DEVICE pages require a pgmap because that's what holds a references to the device's live-ness. What are you allocating this memory from that makes ZONE_DEVICE true without a pgmap?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 25 lines · Keith Busch
Quoted 24 lines · Marek Marczykowski-Górecki
I can reliably hit kernel panic in
nvme_map_data()which looks like the one below. It happens on Linux 5.9.9, while 5.4.75 works fine. I haven't tried other version on this hardware. Linux is running as Xen PV dom0, on top of nvme there is LUKS and then LVM with thin provisioning. The crash happens reliably when starting a Xen domU (which uses one of thin provisioned LVM volumes as its disk). But booting dom0 works fine (even though it is using the same disk setup for its root filesystem).I did a bit of debugging and found it's about this part:
drivers/nvme/host/pci.c:
800 staticblk_status_tnvme_map_data(structnvme_dev*dev, struct request *req,
801 structnvme_command*cmnd)
802 {803 struct nvme_iod *iod = blk_mq_rq_to_pdu(req); 804 blk_status_t ret = BLK_STS_RESOURCE; 805 int nr_mapped;806
807 if (blk_rq_nr_phys_segments(req)== 1) {
808 structbio_vecbv =req_bvec(req);
809
810 if (!is_pci_p2pdma_page(bv.bv_page)) {
Quoted 8 lines
Quoted 3 lines
Here,
bv.bv_page->pgmapisLIST_POISON1, whilepage_zonenum(bv.bv_page)saysZONE_DEVICE. So,is_pci_p2pdma_page()crashes on accessingbv.bv_page->pgmap->type.Something sounds off. I thought all
ZONE_DEVICEpages require a pgmap because that's what holds a references to the device's live-ness. What are you allocating this memory from that makesZONE_DEVICEtrue without a pgmap?
Well, I allocate anything myself. I just try to start the system with unmodified Linux 5.9.9 and NVME drive...
I didn't managed to find where this page is allocated, nor where it gets broken. I _suspect_ it gets allocated as ZONE_DEVICE page and then gets released as ZONE_NORMAL which sets another part of the union to LIST_POISON1. But I have absolutely no data to confirm/deny this theory.
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 35 lines · Marek Marczykowski-Górecki
Quoted 25 lines · Keith Busch
Quoted 24 lines · Marek Marczykowski-Górecki
I can reliably hit kernel panic in
nvme_map_data()which looks like the one below. It happens on Linux 5.9.9, while 5.4.75 works fine. I haven't tried other version on this hardware. Linux is running as Xen PV dom0, on top of nvme there is LUKS and then LVM with thin provisioning. The crash happens reliably when starting a Xen domU (which uses one of thin provisioned LVM volumes as its disk). But booting dom0 works fine (even though it is using the same disk setup for its root filesystem).I did a bit of debugging and found it's about this part:
drivers/nvme/host/pci.c:
800 staticblk_status_tnvme_map_data(structnvme_dev*dev, struct request *req,
801 structnvme_command*cmnd)
802 {803 struct nvme_iod *iod = blk_mq_rq_to_pdu(req); 804 blk_status_t ret = BLK_STS_RESOURCE; 805 int nr_mapped;806
807 if (blk_rq_nr_phys_segments(req)== 1) {
808 structbio_vecbv =req_bvec(req);
809
810 if (!is_pci_p2pdma_page(bv.bv_page)) {Quoted 8 lines
Quoted 3 lines
Here,
bv.bv_page->pgmapisLIST_POISON1, whilepage_zonenum(bv.bv_page)saysZONE_DEVICE. So,is_pci_p2pdma_page()crashes on accessingbv.bv_page->pgmap->type.Something sounds off. I thought all
ZONE_DEVICEpages require a pgmap because that's what holds a references to the device's live-ness. What are you allocating this memory from that makesZONE_DEVICEtrue without a pgmap?
Quoted 6 lines
Well, I allocate anything myself. I just try to start the system with unmodified Linux 5.9.9 and NVME drive...
I didn't managed to find where this page is allocated, nor where it gets broken. I _suspect_ it gets allocated asZONE_DEVICEpage and then gets released asZONE_NORMALwhich sets another part of the union toLIST_POISON1. But I have absolutely no data to confirm/deny this theory.
I've bisected this (thanks to a bit of scripting, PXE and git bisect run, it was long, but fairly painless) and identified this commit as the culprit:
commit 9e2369c06c8a181478039258a4598c1ddd2cadfa
Author: Roger Pau Monne <[email protected]> Date: Tue Sep 1 10:33:26 2020 +0200
xen: add helpers to allocate unpopulated memory
I'm adding relevant people and xen-devel to the thread. For completeness, here is the original crash message:
general protection fault, probably for non-canonical address 0xdead000000000100: 0000 [#1] SMP NOPTI CPU: 1 PID: 134 Comm: kworker/u12:2 Not tainted 5.9.9-1.qubes.x86_64 #1 Hardware name: LENOVO 20M9CTO1WW/20M9CTO1WW, BIOS N2CET50W (1.33 ) 01/15/2020 Workqueue: dm-thin do_worker [dm_thin_pool] RIP: e030:nvme_map_data+0x300/0x3a0 [nvme] Code: b8 fe ff ff e9 a8 fe ff ff 4c 8b 56 68 8b 5e 70 8b 76 74 49 8b 02 48 c1 e8 33 83 e0 07 83 f8 04 0f 85 f2 fe ff ff 49 8b 42 08 <83> b8 d0 00 00 00 04 0f 85 e1 fe ff ff e9 38 fd ff ff 8b 55 70 be RSP: e02b:ffffc900010e7ad8 EFLAGS: 00010246 RAX: dead000000000100 RBX: 0000000000001000 RCX: ffff8881a58f5000 RDX: 0000000000001000 RSI: 0000000000000000 RDI: ffff8881a679e000 RBP: ffff8881a5ef4c80 R08: ffff8881a5ef4c80 R09: 0000000000000002 R10: ffffea0003dfff40 R11: 0000000000000008 R12: ffff8881a679e000 R13: ffffc900010e7b20 R14: ffff8881a70b5980 R15: ffff8881a679e000 FS: 0000000000000000(0000) GS:ffff8881b5440000(0000) knlGS:0000000000000000 CS: e030 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000001d64408 CR3: 00000001aa2c0000 CR4: 0000000000050660 Call Trace: nvme_queue_rq+0xa7/0x1a0 [nvme] __blk_mq_try_issue_directly+0x11d/0x1e0 ? add_wait_queue_exclusive+0x70/0x70 blk_mq_try_issue_directly+0x35/0xc0l[ blk_mq_submit_bio+0x58f/0x660 __submit_bio_noacct+0x300/0x330 process_shared_bio+0x126/0x1b0 [dm_thin_pool] process_cell+0x226/0x280 [dm_thin_pool] process_thin_deferred_cells+0x185/0x320 [dm_thin_pool] process_deferred_bios+0xa4/0x2a0 [dm_thin_pool]UX do_worker+0xcc/0x130 [dm_thin_pool] process_one_work+0x1b4/0x370 worker_thread+0x4c/0x310 ? process_one_work+0x370/0x370 kthread+0x11b/0x140 ? __kthread_bind_mask+0x60/0x60< ret_from_fork+0x22/0x30 Modules linked in: loop snd_seq_dummy snd_hrtimer nf_tables nfnetlink vfat fat snd_sof_pci snd_sof_intel_byt snd_sof_intel_ipc snd_sof_intel_hda_common snd_soc_hdac_hda snd_sof_xtensa_dsp snd_sof_intel_hda snd_sof snd_soc_skl
snd_soc_sst_
ipc snd_soc_sst_dsp snd_hda_ext_core snd_soc_acpi_intel_match snd_soc_acpi snd_soc_core snd_compress ac97_bus snd_pcm_dmaengine elan_i2c snd_hda_codec_hdmi mei_hdcp iTCO_wdt intel_powerclamp intel_pmc_bxt ee1004 intel_rapl_msr iTCO_vendor_support joydev pcspkr intel_wmi_thunderbolt wmi_bmof thunderbolt ucsi_acpi idma64 typec_ucsi snd_hda_codec_realtek typec snd_hda_codec_generic snd_hda_intel snd_intel_dspcfg snd_hda_codec thinkpad_acpi snd_hda_core ledtrig_audio int3403_
thermal snd_hwdep snd_seq snd_seq_device snd_pcm iwlwifi snd_timer processor_thermal_device mei_me cfg80211 intel_rapl_common snd e1000e mei int3400_thermal int340x_thermal_zone i2c_i801 acpi_thermal_rel soundcore intel_soc_dts_iosf i2c_s
mbus rfkill intel_pch_thermal xenfs
ip_tables dm_thin_pool dm_persistent_data dm_bio_prison dm_crypt nouveau rtsx_pci_sdmmc mmc_core mxm_wmi crct10dif_pclmul ttm crc32_pclmul crc32c_intel i915 ghash_clmulni_intel i2c_algo_bit serio_raw nvme drm_kms_helper cec xhci_pci
nvme_core rtsx_pci xhci_pci_renesas drm xhci_hcd wmi video pinctrl_cannonlake pinctrl_intel xen_privcmd xen_pciback xen_blkback xen_gntalloc xen_gntdev xen_evtchn uinput
---[ end trace f8d47e4aa6724df4 ]--- RIP: e030:nvme_map_data+0x300/0x3a0 [nvme] Code: b8 fe ff ff e9 a8 fe ff ff 4c 8b 56 68 8b 5e 70 8b 76 74 49 8b 02 48 c1 e8 33 83 e0 07 83 f8 04 0f 85 f2 fe ff ff 49 8b 42 08 <83> b8 d0 00 00 00 04 0f 85 e1 fe ff ff e9 38 fd ff ff 8b 55 70 be RSP: e02b:ffffc900010e7ad8 EFLAGS: 00010246 RAX: dead000000000100 RBX: 0000000000001000 RCX: ffff8881a58f5000 RDX: 0000000000001000 RSI: 0000000000000000 RDI: ffff8881a679e000 RBP: ffff8881a5ef4c80 R08: ffff8881a5ef4c80 R09: 0000000000000002 R10: ffffea0003dfff40 R11: 0000000000000008 R12: ffff8881a679e000 R13: ffffc900010e7b20 R14: ffff8881a70b5980 R15: ffff8881a679e000 FS: 0000000000000000(0000) GS:ffff8881b5440000(0000) knlGS:0000000000000000 CS: e030 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000001d64408 CR3: 00000001aa2c0000 CR4: 0000000000050660 Kernel panic - not syncing: Fatal exception
Kernel Offset: disabled
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Christoph Hellwig
maintainerQuoted 10 lines · Marek Marczykowski-Górecki
culprit:
commit
9e2369c06c8a181478039258a4598c1ddd2cadfaAuthor: Roger Pau Monne <[email protected]> Date: Tue Sep 1 10:33:26 2020 +0200xen: add helpers to allocate unpopulated memory
I'm adding relevant people and xen-devel to the thread. For completeness, here is the original crash message:
That commit definitively adds a new ZONE_DEVICE user, so it does look related. But you are not running on Xen, are you?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Marek Marczykowski-Górecki
culprit:
commit
9e2369c06c8a181478039258a4598c1ddd2cadfaAuthor: Roger Pau Monne <[email protected]> Date: Tue Sep 1 10:33:26 2020 +0200
Quoted 7 lines
Quoted 4 lines
xen: add helpers to allocate unpopulated memory
I'm adding relevant people and xen-devel to the thread. For completeness, here is the original crash message:
That commit definitively adds a new
ZONE_DEVICEuser, so it does look related. But you are not running on Xen, are you?
I am. It is Xen dom0.
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 10 lines · Marek Marczykowski-Górecki
Quoted 9 lines · Christoph Hellwig
Quoted 8 lines · Marek Marczykowski-Górecki
culprit:
commit
9e2369c06c8a181478039258a4598c1ddd2cadfaAuthor: Roger Pau Monne <[email protected]> Date: Tue Sep 1 10:33:26 2020 +0200xen: add helpers to allocate unpopulated memory
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
I'm adding relevant people and xen-devel to the thread. For completeness, here is the original crash message:
That commit definitively adds a new
ZONE_DEVICEuser, so it does look related. But you are not running on Xen, are you?I am. It is Xen dom0.
I'm afraid I'm on leave and won't be able to look into this until the beginning of January. I would guess it's some kind of bad interaction between blkback and NVMe drivers both using ZONE_DEVICE?
Maybe the best is to revert this change and I will look into it when I get back, unless someone is willing to debug this further.
Thanks, Roger.
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 18 lines · Roger Pau Monné
Quoted 16 lines · Marek Marczykowski-Górecki
Quoted 14 lines · Christoph Hellwig
Quoted 10 lines · Marek Marczykowski-Górecki
culprit:
commit
9e2369c06c8a181478039258a4598c1ddd2cadfaAuthor: Roger Pau Monne <[email protected]> Date: Tue Sep 1 10:33:26 2020 +0200xen: add helpers to allocate unpopulated memory
I'm adding relevant people and xen-devel to the thread. For completeness, here is the original crash message:
That commit definitively adds a new
ZONE_DEVICEuser, so it does look related. But you are not running on Xen, are you?
Quoted 8 lines
Quoted 1 line
I am. It is Xen dom0.
I'm afraid I'm on leave and won't be able to look into this until the beginning of January. I would guess it's some kind of bad interaction between blkback and NVMe drivers both using
ZONE_DEVICE?Maybe the best is to revert this change and I will look into it when I get back, unless someone is willing to debug this further.
Looking at commit 9e2369c06c8a and xen-blkback put_free_pages() , they both use page->lru which is part of the anonymous union shared with *pgmap. That matches Marek's suspicion that the ZONE_DEVICE memory is being used as ZONE_NORMAL.
memmap_init_zone_device() says:
* ZONE_DEVICE pages union ->lru with a ->pgmap back pointer
* and zone_device_data. It is a bug if a ZONE_DEVICE page is
* ever freed or placed on a driver-private list.
Regards,
Jason
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Jürgen Groß
maintainerMarek,
Quoted 33 lines · Jason Andryuk
Quoted 18 lines · Roger Pau Monné
Quoted 16 lines · Marek Marczykowski-Górecki
Quoted 14 lines · Christoph Hellwig
Quoted 10 lines · Marek Marczykowski-Górecki
culprit:
commit
9e2369c06c8a181478039258a4598c1ddd2cadfaAuthor: Roger Pau Monne <[email protected]> Date: Tue Sep 1 10:33:26 2020 +0200xen: add helpers to allocate unpopulated memory
I'm adding relevant people and xen-devel to the thread. For completeness, here is the original crash message:
That commit definitively adds a new
ZONE_DEVICEuser, so it does look related. But you are not running on Xen, are you?Quoted 8 lines
Quoted 1 line
I am. It is Xen dom0.
I'm afraid I'm on leave and won't be able to look into this until the beginning of January. I would guess it's some kind of bad interaction between blkback and NVMe drivers both using
ZONE_DEVICE?Maybe the best is to revert this change and I will look into it when I get back, unless someone is willing to debug this further.
Looking at commit
9e2369c06c8aand xen-blkbackput_free_pages(), they both usepage->lruwhich is part of the anonymous union shared with *pgmap. That matches Marek's suspicion that theZONE_DEVICEmemory is being used asZONE_NORMAL.
Quoted 4 lines
memmap_init_zone_device()says:
*ZONE_DEVICEpages union ->lru with a ->pgmap back pointer
* andzone_device_data. It is a bug if aZONE_DEVICEpage is
* ever freed or placed on a driver-private list.
Could you test whether the two attached patches are helping?
Only compile tested.
Juergen
From 4f6ad98ce5fd457fd12e6617b0bc2a8f82fbce4d Mon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Mon, 7 Dec 2020 08:31:22 +0100
Subject: [PATCH 1/2] xen: add helpers for caching grant mapping pages
Instead of having similar helpers in multiple backend drivers use common helpers for caching pages allocated via gnttab_alloc_pages().
Make use of those helpers in blkback and scsiback.
--- drivers/block/xen-blkback/blkback.c | 89 ++++++----------------------- drivers/block/xen-blkback/common.h | 4 +- drivers/block/xen-blkback/xenbus.c | 6 +- drivers/xen/grant-table.c | 72 +++++++++++++++++++++++ drivers/xen/xen-scsiback.c | 60 ++++--------------- include/xen/grant_table.h | 13 +++++ 6 files changed, 116 insertions(+), 128 deletions(-)
drivers/block/xen-blkback/blkback.c +17 -72
@@ -132,73 +132,12 @@ module_param(log_stats, int, 0644);#define BLKBACK_INVALID_HANDLE (~0) -/* Number of free pages to remove on each call to gnttab_free_pages */ -#define NUM_BATCH_FREE_PAGES 10 -static inline bool persistent_gnt_timeout (struct persistent_gnt *persistent_gnt) {return pgrant_timeout && (jiffies - persistent_gnt->last_used >=HZ * pgrant_timeout); } -static inline int get_free_page (struct xen_blkif_ring *ring,struct page **page) -{ -unsigned long flags; - -spin_lock_irqsave (&ring->free_pages_lock, flags); -if (list_empty (&ring->free_pages)) { -BUG_ON (ring->free_pages_num !=0 ); -spin_unlock_irqrestore (&ring->free_pages_lock, flags); -return gnttab_alloc_pages (1 , page); - } -BUG_ON (ring->free_pages_num ==0 ); - page[0] = list_first_entry(&ring->free_pages, struct page, lru); -list_del (&page[0 ]->lru); - ring->free_pages_num--; -spin_unlock_irqrestore (&ring->free_pages_lock, flags); - -return 0 ; -} - -static inline void put_free_pages (struct xen_blkif_ring *ring,struct page **page, -int num) -{ -unsigned long flags; -int i; - -spin_lock_irqsave (&ring->free_pages_lock, flags); -for (i =0 ; i < num; i++) -list_add (&page[i]->lru, &ring->free_pages); - ring->free_pages_num += num; -spin_unlock_irqrestore (&ring->free_pages_lock, flags); -} - -static inline void shrink_free_pagepool (struct xen_blkif_ring *ring,int num) -{ -/* Remove requested pages in batches of NUM_BATCH_FREE_PAGES */ -struct page *page[NUM_BATCH_FREE_PAGES ]; -unsigned int num_pages =0 ; -unsigned long flags; - -spin_lock_irqsave (&ring->free_pages_lock, flags); -while (ring->free_pages_num > num) { -BUG_ON (list_empty (&ring->free_pages)); - page[num_pages] =list_first_entry (&ring->free_pages, - struct page, lru); -list_del (&page[num_pages]->lru); - ring->free_pages_num--; -if (++num_pages ==NUM_BATCH_FREE_PAGES ) { -spin_unlock_irqrestore (&ring->free_pages_lock, flags); -gnttab_free_pages (num_pages, page); -spin_lock_irqsave (&ring->free_pages_lock, flags); - num_pages =0 ; - } - } -spin_unlock_irqrestore (&ring->free_pages_lock, flags); -if (num_pages !=0 ) -gnttab_free_pages (num_pages, page); -} -#define vaddr (page) ((unsigned long)pfn_to_kaddr(page_to_pfn(page)))static int do_block_io_op (struct xen_blkif_ring *ring,unsigned int *eoi_flags);
@@ -331,7 +270,8 @@ static void free_persistent_gnts(struct xen_blkif_ring *ring, struct rb_root *ro unmap_data.count = segs_to_unmap;BUG_ON (gnttab_unmap_refs_sync (&unmap_data)); -put_free_pages (ring, pages, segs_to_unmap); +gnttab_page_cache_put (&ring->free_pages, pages, + segs_to_unmap); segs_to_unmap =0 ; }
@@ -371,7 +311,8 @@ void xen_blkbk_unmap_purged_grants(struct work_struct *work)if (++segs_to_unmap ==BLKIF_MAX_SEGMENTS_PER_REQUEST ) { unmap_data.count = segs_to_unmap;BUG_ON (gnttab_unmap_refs_sync (&unmap_data)); -put_free_pages (ring, pages, segs_to_unmap); +gnttab_page_cache_put (&ring->free_pages, pages, + segs_to_unmap); segs_to_unmap =0 ; }kfree (persistent_gnt);
@@ -379,7 +320,7 @@ void xen_blkbk_unmap_purged_grants(struct work_struct *work)if (segs_to_unmap >0 ) { unmap_data.count = segs_to_unmap;BUG_ON (gnttab_unmap_refs_sync (&unmap_data)); -put_free_pages (ring, pages, segs_to_unmap); +gnttab_page_cache_put (&ring->free_pages, pages, segs_to_unmap); } }
@@ -664,9 +605,10 @@ int xen_blkif_schedule(void *arg)/* Shrink the free pages pool if it is too large. */ if (time_before (jiffies, blkif->buffer_squeeze_end)) -shrink_free_pagepool (ring,0 ); +gnttab_page_cache_shrink (&ring->free_pages,0 );else -shrink_free_pagepool (ring, max_buffer_pages); +gnttab_page_cache_shrink (&ring->free_pages, + max_buffer_pages);if (log_stats &&time_after (jiffies, ring->st_print))print_stats (ring);
@@ -697,7 +639,7 @@ void xen_blkbk_free_caches(struct xen_blkif_ring *ring) ring->persistent_gnt_c =0 ;/* Since we are shutting down remove all pages from the buffer */ -shrink_free_pagepool (ring,0 /* All */ ); +gnttab_page_cache_shrink (&ring->free_pages,0 /* All */ ); } static unsigned int xen_blkbk_unmap_prepare(
@@ -736,7 +678,7 @@ static void xen_blkbk_unmap_and_respond_callback(int result, struct gntab_unmap_but is this the best way to deal with this? */ BUG_ON (result); -put_free_pages (ring, data->pages, data->count); +gnttab_page_cache_put (&ring->free_pages, data->pages, data->count);make_response (ring, pending_req->id, pending_req->operation, pending_req->status);free_req (ring, pending_req);
@@ -803,7 +745,8 @@ static void xen_blkbk_unmap(struct xen_blkif_ring *ring,if (invcount) { ret =gnttab_unmap_refs (unmap,NULL , unmap_pages, invcount);BUG_ON (ret); -put_free_pages (ring, unmap_pages, invcount); +gnttab_page_cache_put (&ring->free_pages, unmap_pages, + invcount); } pages += batch; num -= batch;
@@ -850,7 +793,8 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring, pages[i]->page = persistent_gnt->page; pages[i]->persistent_gnt = persistent_gnt; }else { -if (get_free_page (ring, &pages[i]->page)) +if (gnttab_page_cache_get (&ring->free_pages, + &pages[i]->page)) goto out_of_memory; addr =vaddr (pages[i]->page); pages_to_gnt[segs_to_map] = pages[i]->page;
@@ -883,7 +827,8 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring,BUG_ON (new_map_idx >= segs_to_map);if (unlikely (map[new_map_idx].status !=0 )) {pr_debug ("invalid buffer -- could not remap it\n" ); -put_free_pages (ring, &pages[seg_idx]->page,1 ); +gnttab_page_cache_put (&ring->free_pages, + &pages[seg_idx]->page,1 ); pages[seg_idx]->handle =BLKBACK_INVALID_HANDLE ; ret |=1 ; goto next;
@@ -944,7 +889,7 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring, out_of_memory:pr_alert ("%s: out of memory\n" , __func__); -put_free_pages (ring, pages_to_gnt, segs_to_map); +gnttab_page_cache_put (&ring->free_pages, pages_to_gnt, segs_to_map);for (i = last_map; i < num; i++) pages[i]->handle =BLKBACK_INVALID_HANDLE ;return -ENOMEM ;
drivers/block/xen-blkback/common.h +1 -3
@@ -288,9 +288,7 @@ struct xen_blkif_ring {struct work_struct persistent_purge_work;/* Buffer of free pages to map grant refs. */ -spinlock_t free_pages_lock; -int free_pages_num; -struct list_head free_pages; +struct gnttab_page_cache free_pages;struct work_struct free_work;/* Thread shutdown wait queue. */
drivers/block/xen-blkback/xenbus.c +2 -4
@@ -144,8 +144,7 @@ static int xen_blkif_alloc_rings(struct xen_blkif *blkif)INIT_LIST_HEAD (&ring->pending_free);INIT_LIST_HEAD (&ring->persistent_purge_list);INIT_WORK (&ring->persistent_purge_work, xen_blkbk_unmap_purged_grants); -spin_lock_init (&ring->free_pages_lock); -INIT_LIST_HEAD (&ring->free_pages); +gnttab_page_cache_init (&ring->free_pages);spin_lock_init (&ring->pending_free_lock);init_waitqueue_head (&ring->pending_free_wq);
@@ -317,8 +316,7 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)BUG_ON (atomic_read (&ring->persistent_gnt_in_use) !=0 );BUG_ON (!list_empty (&ring->persistent_purge_list));BUG_ON (!RB_EMPTY_ROOT (&ring->persistent_gnts)); -BUG_ON (!list_empty (&ring->free_pages)); -BUG_ON (ring->free_pages_num !=0 ); +BUG_ON (ring->free_pages.num_pages !=0 );BUG_ON (ring->persistent_gnt_c !=0 );WARN_ON (i != (XEN_BLKIF_REQS_PER_PAGE * blkif->nr_ring_pages)); ring->active = false;
drivers/xen/grant-table.c +72 -0
78 lines not on this page · raw message
drivers/xen/xen-scsiback.c +11 -49
114 lines not on this page · raw message
include/xen/grant_table.h +13 -0
@@ -198,6 +198,19 @@ void gnttab_free_auto_xlat_frames(void);int gnttab_alloc_pages (int nr_pages,struct page **pages);void gnttab_free_pages (int nr_pages,struct page **pages); +struct gnttab_page_cache { +spinlock_t lock; +struct list_head pages; +unsigned int num_pages; +}; + +void gnttab_page_cache_init (struct gnttab_page_cache *cache); +int gnttab_page_cache_get (struct gnttab_page_cache *cache,struct page **page); +void gnttab_page_cache_put (struct gnttab_page_cache *cache,struct page **page, +unsigned int num); +void gnttab_page_cache_shrink (struct gnttab_page_cache *cache, +unsigned int num); +#ifdef CONFIG_XEN_GRANT_DMA_ALLOC struct gnttab_dma_alloc_args {/* Device for which DMA memory will be/was allocated. */
Signature · 1 line
2.26.2
From 061fee2e0b4cb7dc7deb07980fca8afa6349358b Mon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Mon, 7 Dec 2020 09:36:14 +0100
Subject: [PATCH 2/2] xen: don't use page->lru for ZONE_DEVICE memory
Commit 9e2369c06c8a18 ("xen: add helpers to allocate unpopulated memory") introduced usage of ZONE_DEVICE memory for foreign memory mappings.
Unfortunately this collides with using page->lru for Xen backend private page caches.
Fix that by using page->zone_device_data instead.
--- drivers/xen/grant-table.c | 65 ++++++++++++++++++++++++++++++++++----- include/xen/grant_table.h | 4 +++ 2 files changed, 62 insertions(+), 7 deletions(-)
drivers/xen/grant-table.c +58 -7
96 lines not on this page · raw message
include/xen/grant_table.h +4 -0
@@ -200,7 +200,11 @@ void gnttab_free_pages(int nr_pages, struct page **pages);struct gnttab_page_cache {spinlock_t lock; +#ifdef CONFIG_XEN_UNPOPULATED_ALLOC +struct page *pages; +#else struct list_head pages; +#endif unsigned int num_pages; };
Signature · 1 line
2.26.2
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Jürgen Groß
maintainerQuoted 36 lines · Jürgen Groß
Marek,
Quoted 33 lines · Jason Andryuk
Quoted 18 lines · Roger Pau Monné
Quoted 16 lines · Marek Marczykowski-Górecki
Quoted 14 lines · Christoph Hellwig
Quoted 10 lines · Marek Marczykowski-Górecki
culprit:
commit
9e2369c06c8a181478039258a4598c1ddd2cadfa
Author: Roger Pau Monne <[email protected]>
Date: Tue Sep 1 10:33:26 2020 +0200xen: add helpers to allocate unpopulated memory
I'm adding relevant people and xen-devel to the thread. For completeness, here is the original crash message:
That commit definitively adds a new
ZONE_DEVICEuser, so it does look related. But you are not running on Xen, are you?Quoted 8 lines
Quoted 1 line
I am. It is Xen dom0.
I'm afraid I'm on leave and won't be able to look into this until the beginning of January. I would guess it's some kind of bad interaction between blkback and NVMe drivers both using
ZONE_DEVICE?Maybe the best is to revert this change and I will look into it when I get back, unless someone is willing to debug this further.
Looking at commit
9e2369c06c8aand xen-blkbackput_free_pages(), they both usepage->lruwhich is part of the anonymous union shared with *pgmap. That matches Marek's suspicion that theZONE_DEVICEmemory is being used asZONE_NORMAL.
Quoted 8 lines
Quoted 4 lines
memmap_init_zone_device()says:
*ZONE_DEVICEpages union ->lru with a ->pgmap back pointer
* and zone_device_data. It is a bug if aZONE_DEVICEpage is
* ever freed or placed on a driver-private list.Could you test whether the two attached patches are helping?
Only compile tested.
Oh, sorry, one patch missing.
I need to modify drivers/xen/unpopulated-alloc.c, too.
Juergen
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Jürgen Groß
maintainerMarek,
Quoted 33 lines · Jason Andryuk
Quoted 18 lines · Roger Pau Monné
Quoted 16 lines · Marek Marczykowski-Górecki
Quoted 14 lines · Christoph Hellwig
Quoted 10 lines · Marek Marczykowski-Górecki
culprit:
commit
9e2369c06c8a181478039258a4598c1ddd2cadfaAuthor: Roger Pau Monne <[email protected]> Date: Tue Sep 1 10:33:26 2020 +0200xen: add helpers to allocate unpopulated memory
I'm adding relevant people and xen-devel to the thread. For completeness, here is the original crash message:
That commit definitively adds a new
ZONE_DEVICEuser, so it does look related. But you are not running on Xen, are you?Quoted 8 lines
Quoted 1 line
I am. It is Xen dom0.
I'm afraid I'm on leave and won't be able to look into this until the beginning of January. I would guess it's some kind of bad interaction between blkback and NVMe drivers both using
ZONE_DEVICE?Maybe the best is to revert this change and I will look into it when I get back, unless someone is willing to debug this further.
Looking at commit
9e2369c06c8aand xen-blkbackput_free_pages(), they both usepage->lruwhich is part of the anonymous union shared with *pgmap. That matches Marek's suspicion that theZONE_DEVICEmemory is being used asZONE_NORMAL.
Quoted 4 lines
memmap_init_zone_device()says:
*ZONE_DEVICEpages union ->lru with a ->pgmap back pointer
* andzone_device_data. It is a bug if aZONE_DEVICEpage is
* ever freed or placed on a driver-private list.
Second try, now even tested to work on a test system (without NVMe).
Juergen
From 4f6ad98ce5fd457fd12e6617b0bc2a8f82fbce4d Mon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Mon, 7 Dec 2020 08:31:22 +0100
Subject: [PATCH 1/2] xen: add helpers for caching grant mapping pages
Instead of having similar helpers in multiple backend drivers use common helpers for caching pages allocated via gnttab_alloc_pages().
Make use of those helpers in blkback and scsiback.
--- drivers/block/xen-blkback/blkback.c | 89 ++++++----------------------- drivers/block/xen-blkback/common.h | 4 +- drivers/block/xen-blkback/xenbus.c | 6 +- drivers/xen/grant-table.c | 72 +++++++++++++++++++++++ drivers/xen/xen-scsiback.c | 60 ++++--------------- include/xen/grant_table.h | 13 +++++ 6 files changed, 116 insertions(+), 128 deletions(-)
drivers/block/xen-blkback/blkback.c +17 -72
@@ -132,73 +132,12 @@ module_param(log_stats, int, 0644);#define BLKBACK_INVALID_HANDLE (~0) -/* Number of free pages to remove on each call to gnttab_free_pages */ -#define NUM_BATCH_FREE_PAGES 10 -static inline bool persistent_gnt_timeout (struct persistent_gnt *persistent_gnt) {return pgrant_timeout && (jiffies - persistent_gnt->last_used >=HZ * pgrant_timeout); } -static inline int get_free_page (struct xen_blkif_ring *ring,struct page **page) -{ -unsigned long flags; - -spin_lock_irqsave (&ring->free_pages_lock, flags); -if (list_empty (&ring->free_pages)) { -BUG_ON (ring->free_pages_num !=0 ); -spin_unlock_irqrestore (&ring->free_pages_lock, flags); -return gnttab_alloc_pages (1 , page); - } -BUG_ON (ring->free_pages_num ==0 ); - page[0] = list_first_entry(&ring->free_pages, struct page, lru); -list_del (&page[0 ]->lru); - ring->free_pages_num--; -spin_unlock_irqrestore (&ring->free_pages_lock, flags); - -return 0 ; -} - -static inline void put_free_pages (struct xen_blkif_ring *ring,struct page **page, -int num) -{ -unsigned long flags; -int i; - -spin_lock_irqsave (&ring->free_pages_lock, flags); -for (i =0 ; i < num; i++) -list_add (&page[i]->lru, &ring->free_pages); - ring->free_pages_num += num; -spin_unlock_irqrestore (&ring->free_pages_lock, flags); -} - -static inline void shrink_free_pagepool (struct xen_blkif_ring *ring,int num) -{ -/* Remove requested pages in batches of NUM_BATCH_FREE_PAGES */ -struct page *page[NUM_BATCH_FREE_PAGES ]; -unsigned int num_pages =0 ; -unsigned long flags; - -spin_lock_irqsave (&ring->free_pages_lock, flags); -while (ring->free_pages_num > num) { -BUG_ON (list_empty (&ring->free_pages)); - page[num_pages] =list_first_entry (&ring->free_pages, - struct page, lru); -list_del (&page[num_pages]->lru); - ring->free_pages_num--; -if (++num_pages ==NUM_BATCH_FREE_PAGES ) { -spin_unlock_irqrestore (&ring->free_pages_lock, flags); -gnttab_free_pages (num_pages, page); -spin_lock_irqsave (&ring->free_pages_lock, flags); - num_pages =0 ; - } - } -spin_unlock_irqrestore (&ring->free_pages_lock, flags); -if (num_pages !=0 ) -gnttab_free_pages (num_pages, page); -} -#define vaddr (page) ((unsigned long)pfn_to_kaddr(page_to_pfn(page)))static int do_block_io_op (struct xen_blkif_ring *ring,unsigned int *eoi_flags);
@@ -331,7 +270,8 @@ static void free_persistent_gnts(struct xen_blkif_ring *ring, struct rb_root *ro unmap_data.count = segs_to_unmap;BUG_ON (gnttab_unmap_refs_sync (&unmap_data)); -put_free_pages (ring, pages, segs_to_unmap); +gnttab_page_cache_put (&ring->free_pages, pages, + segs_to_unmap); segs_to_unmap =0 ; }
@@ -371,7 +311,8 @@ void xen_blkbk_unmap_purged_grants(struct work_struct *work)if (++segs_to_unmap ==BLKIF_MAX_SEGMENTS_PER_REQUEST ) { unmap_data.count = segs_to_unmap;BUG_ON (gnttab_unmap_refs_sync (&unmap_data)); -put_free_pages (ring, pages, segs_to_unmap); +gnttab_page_cache_put (&ring->free_pages, pages, + segs_to_unmap); segs_to_unmap =0 ; }kfree (persistent_gnt);
@@ -379,7 +320,7 @@ void xen_blkbk_unmap_purged_grants(struct work_struct *work)if (segs_to_unmap >0 ) { unmap_data.count = segs_to_unmap;BUG_ON (gnttab_unmap_refs_sync (&unmap_data)); -put_free_pages (ring, pages, segs_to_unmap); +gnttab_page_cache_put (&ring->free_pages, pages, segs_to_unmap); } }
@@ -664,9 +605,10 @@ int xen_blkif_schedule(void *arg)/* Shrink the free pages pool if it is too large. */ if (time_before (jiffies, blkif->buffer_squeeze_end)) -shrink_free_pagepool (ring,0 ); +gnttab_page_cache_shrink (&ring->free_pages,0 );else -shrink_free_pagepool (ring, max_buffer_pages); +gnttab_page_cache_shrink (&ring->free_pages, + max_buffer_pages);if (log_stats &&time_after (jiffies, ring->st_print))print_stats (ring);
@@ -697,7 +639,7 @@ void xen_blkbk_free_caches(struct xen_blkif_ring *ring) ring->persistent_gnt_c =0 ;/* Since we are shutting down remove all pages from the buffer */ -shrink_free_pagepool (ring,0 /* All */ ); +gnttab_page_cache_shrink (&ring->free_pages,0 /* All */ ); } static unsigned int xen_blkbk_unmap_prepare(
@@ -736,7 +678,7 @@ static void xen_blkbk_unmap_and_respond_callback(int result, struct gntab_unmap_but is this the best way to deal with this? */ BUG_ON (result); -put_free_pages (ring, data->pages, data->count); +gnttab_page_cache_put (&ring->free_pages, data->pages, data->count);make_response (ring, pending_req->id, pending_req->operation, pending_req->status);free_req (ring, pending_req);
@@ -803,7 +745,8 @@ static void xen_blkbk_unmap(struct xen_blkif_ring *ring,if (invcount) { ret =gnttab_unmap_refs (unmap,NULL , unmap_pages, invcount);BUG_ON (ret); -put_free_pages (ring, unmap_pages, invcount); +gnttab_page_cache_put (&ring->free_pages, unmap_pages, + invcount); } pages += batch; num -= batch;
@@ -850,7 +793,8 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring, pages[i]->page = persistent_gnt->page; pages[i]->persistent_gnt = persistent_gnt; }else { -if (get_free_page (ring, &pages[i]->page)) +if (gnttab_page_cache_get (&ring->free_pages, + &pages[i]->page)) goto out_of_memory; addr =vaddr (pages[i]->page); pages_to_gnt[segs_to_map] = pages[i]->page;
@@ -883,7 +827,8 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring,BUG_ON (new_map_idx >= segs_to_map);if (unlikely (map[new_map_idx].status !=0 )) {pr_debug ("invalid buffer -- could not remap it\n" ); -put_free_pages (ring, &pages[seg_idx]->page,1 ); +gnttab_page_cache_put (&ring->free_pages, + &pages[seg_idx]->page,1 ); pages[seg_idx]->handle =BLKBACK_INVALID_HANDLE ; ret |=1 ; goto next;
@@ -944,7 +889,7 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring, out_of_memory:pr_alert ("%s: out of memory\n" , __func__); -put_free_pages (ring, pages_to_gnt, segs_to_map); +gnttab_page_cache_put (&ring->free_pages, pages_to_gnt, segs_to_map);for (i = last_map; i < num; i++) pages[i]->handle =BLKBACK_INVALID_HANDLE ;return -ENOMEM ;
drivers/block/xen-blkback/common.h +1 -3
@@ -288,9 +288,7 @@ struct xen_blkif_ring {struct work_struct persistent_purge_work;/* Buffer of free pages to map grant refs. */ -spinlock_t free_pages_lock; -int free_pages_num; -struct list_head free_pages; +struct gnttab_page_cache free_pages;struct work_struct free_work;/* Thread shutdown wait queue. */
drivers/block/xen-blkback/xenbus.c +2 -4
@@ -144,8 +144,7 @@ static int xen_blkif_alloc_rings(struct xen_blkif *blkif)INIT_LIST_HEAD (&ring->pending_free);INIT_LIST_HEAD (&ring->persistent_purge_list);INIT_WORK (&ring->persistent_purge_work, xen_blkbk_unmap_purged_grants); -spin_lock_init (&ring->free_pages_lock); -INIT_LIST_HEAD (&ring->free_pages); +gnttab_page_cache_init (&ring->free_pages);spin_lock_init (&ring->pending_free_lock);init_waitqueue_head (&ring->pending_free_wq);
@@ -317,8 +316,7 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)BUG_ON (atomic_read (&ring->persistent_gnt_in_use) !=0 );BUG_ON (!list_empty (&ring->persistent_purge_list));BUG_ON (!RB_EMPTY_ROOT (&ring->persistent_gnts)); -BUG_ON (!list_empty (&ring->free_pages)); -BUG_ON (ring->free_pages_num !=0 ); +BUG_ON (ring->free_pages.num_pages !=0 );BUG_ON (ring->persistent_gnt_c !=0 );WARN_ON (i != (XEN_BLKIF_REQS_PER_PAGE * blkif->nr_ring_pages)); ring->active = false;
drivers/xen/grant-table.c +72 -0
78 lines not on this page · raw message
drivers/xen/xen-scsiback.c +11 -49
114 lines not on this page · raw message
include/xen/grant_table.h +13 -0
@@ -198,6 +198,19 @@ void gnttab_free_auto_xlat_frames(void);int gnttab_alloc_pages (int nr_pages,struct page **pages);void gnttab_free_pages (int nr_pages,struct page **pages); +struct gnttab_page_cache { +spinlock_t lock; +struct list_head pages; +unsigned int num_pages; +}; + +void gnttab_page_cache_init (struct gnttab_page_cache *cache); +int gnttab_page_cache_get (struct gnttab_page_cache *cache,struct page **page); +void gnttab_page_cache_put (struct gnttab_page_cache *cache,struct page **page, +unsigned int num); +void gnttab_page_cache_shrink (struct gnttab_page_cache *cache, +unsigned int num); +#ifdef CONFIG_XEN_GRANT_DMA_ALLOC struct gnttab_dma_alloc_args {/* Device for which DMA memory will be/was allocated. */
Signature · 1 line
2.26.2
From 5ecf68877ed7ff4c7a96464b82eb84cc34d6d3f3 Mon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Mon, 7 Dec 2020 09:36:14 +0100
Subject: [PATCH 2/2] xen: don't use page->lru for ZONE_DEVICE memory
Commit 9e2369c06c8a18 ("xen: add helpers to allocate unpopulated memory") introduced usage of ZONE_DEVICE memory for foreign memory mappings.
Unfortunately this collides with using page->lru for Xen backend private page caches.
Fix that by using page->zone_device_data instead.
--- drivers/xen/grant-table.c | 65 +++++++++++++++++++++++++++++---- drivers/xen/unpopulated-alloc.c | 20 +++++----- include/xen/grant_table.h | 4 ++ 3 files changed, 73 insertions(+), 16 deletions(-)
drivers/xen/grant-table.c +58 -7
96 lines not on this page · raw message
drivers/xen/unpopulated-alloc.c +11 -9
@@ -12,7 +12,7 @@#include <xen/xen.h> static DEFINE_MUTEX (list_lock); -static LIST_HEAD (page_list); +static struct page *page_list;static unsigned int list_count;static int fill_list (unsigned int nr_pages)
@@ -84,7 +84,8 @@ static int fill_list(unsigned int nr_pages)struct page *pg =virt_to_page (vaddr +PAGE_SIZE * i);BUG_ON (!virt_addr_valid (vaddr +PAGE_SIZE * i)); -list_add (&pg->lru, &page_list); + pg->zone_device_data = page_list; + page_list = pg; list_count++; }
@@ -118,12 +119,10 @@ int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages) }for (i =0 ; i < nr_pages; i++) { -struct page *pg =list_first_entry_or_null (&page_list, - struct page, - lru); +struct page *pg = page_list;BUG_ON (!pg); -list_del (&pg->lru); + page_list = pg->zone_device_data; list_count--; pages[i] = pg;
@@ -134,7 +133,8 @@ int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages)unsigned int j;for (j =0 ; j <= i; j++) { -list_add (&pages[j]->lru, &page_list); + pages[j]->zone_device_data = page_list; + page_list = pages[j]; list_count++; } goto out;
@@ -160,7 +160,8 @@ void xen_free_unpopulated_pages(unsigned int nr_pages, struct page **pages)mutex_lock (&list_lock);for (i =0 ; i < nr_pages; i++) { -list_add (&pages[i]->lru, &page_list); + pages[i]->zone_device_data = page_list; + page_list = pages[i]; list_count++; }mutex_unlock (&list_lock);
@@ -189,7 +190,8 @@ static int __init init(void)struct page *pg =pfn_to_page (xen_extra_mem[i].start_pfn + j); -list_add (&pg->lru, &page_list); + pg->zone_device_data = page_list; + page_list = pg; list_count++; } }
include/xen/grant_table.h +4 -0
@@ -200,7 +200,11 @@ void gnttab_free_pages(int nr_pages, struct page **pages);struct gnttab_page_cache {spinlock_t lock; +#ifdef CONFIG_XEN_UNPOPULATED_ALLOC +struct page *pages; +#else struct list_head pages; +#endif unsigned int num_pages; };
Signature · 1 line
2.26.2
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 36 lines · Jürgen Groß
Marek,
Quoted 33 lines · Jason Andryuk
Quoted 18 lines · Roger Pau Monné
Quoted 16 lines · Marek Marczykowski-Górecki
Quoted 14 lines · Christoph Hellwig
Quoted 10 lines · Marek Marczykowski-Górecki
culprit:
commit
9e2369c06c8a181478039258a4598c1ddd2cadfaAuthor: Roger Pau Monne <[email protected]> Date: Tue Sep 1 10:33:26 2020 +0200xen: add helpers to allocate unpopulated memory
I'm adding relevant people and xen-devel to the thread. For completeness, here is the original crash message:
That commit definitively adds a new
ZONE_DEVICEuser, so it does look related. But you are not running on Xen, are you?Quoted 8 lines
Quoted 1 line
I am. It is Xen dom0.
I'm afraid I'm on leave and won't be able to look into this until the beginning of January. I would guess it's some kind of bad interaction between blkback and NVMe drivers both using
ZONE_DEVICE?Maybe the best is to revert this change and I will look into it when I get back, unless someone is willing to debug this further.
Looking at commit
9e2369c06c8aand xen-blkbackput_free_pages(), they both usepage->lruwhich is part of the anonymous union shared with *pgmap. That matches Marek's suspicion that theZONE_DEVICEmemory is being used asZONE_NORMAL.
Quoted 6 lines
Quoted 4 lines
memmap_init_zone_device()says:
*ZONE_DEVICEpages union ->lru with a ->pgmap back pointer
* andzone_device_data. It is a bug if aZONE_DEVICEpage is
* ever freed or placed on a driver-private list.Second try, now even tested to work on a test system (without NVMe).
It doesn't work for me:
[ 526.023340] xen-blkback: backend/vbd/1/51712: using 2 queues, protocol 1 (x86_64-abi) persistent grants [ 526.030550] xen-blkback: backend/vbd/1/51728: using 2 queues, protocol 1 (x86_64-abi) persistent grants [ 526.034810] BUG: kernel NULL pointer dereference, address: 0000000000000010 [ 526.034841] #PF: supervisor read access in kernel mode [ 526.034857] #PF: error_code(0x0000) - not-present page [ 526.034875] PGD 105428067 P4D 105428067 PUD 105b92067 PMD 0 [ 526.034896] Oops: 0000 [#1] SMP NOPTI [ 526.034909] CPU: 3 PID: 4007 Comm: 1.xvda-0 Tainted: G W 5.10.0-rc6-1.qubes.x86_64+ #108 [ 526.034933] Hardware name: LENOVO 20M9CTO1WW/20M9CTO1WW, BIOS N2CET50W (1.33 ) 01/15/2020 [ 526.034974] RIP: e030:gnttab_page_cache_get+0x32/0x60 [ 526.034990] Code: 89 f4 55 48 89 fd e8 4d e3 80 00 48 83 7d 08 00 48 89 c6 74 15 48 89 ef e8 5b e0 80 00 4c 89 e6 5d bf 01 00 00 00 41 5c eb 8e <48> 8b 04 25 10 00 00 00 48 89 ef 48 89 45 08 49 c7 04 24 00 00 00 [ 526.035035] RSP: e02b:ffffc90003e27a40 EFLAGS: 00010046 [ 526.035052] RAX: 0000000000000200 RBX: 0000000000000001 RCX: 0000000000000000 [ 526.035072] RDX: 0000000000000001 RSI: 0000000000000200 RDI: ffff888104275518 [ 526.035092] RBP: ffff888104275518 R08: 0000000000000000 R09: 0000000000000000 [ 526.035113] R10: ffff888104275400 R11: 0000000000000000 R12: ffff888109b5d3a0 [ 526.035133] R13: 0000000000000000 R14: 0000000000000000 R15: ffff888104275400 [ 526.035159] FS: 0000000000000000(0000) GS:ffff8881b54c0000(0000) knlGS:0000000000000000 [ 526.035194] CS: 10000e030 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 526.035214] CR2: 0000000000000010 CR3: 0000000103b5a000 CR4: 0000000000050660 [ 526.035239] Call Trace: [ 526.035253] xen_blkbk_map+0x131/0x5a0 [ 526.035268] dispatch_rw_block_io+0x42a/0x9c0 [ 526.035284] ? xen_mc_flush+0xcb/0x190 [ 526.035298] __do_block_io_op+0x314/0x630 [ 526.035312] xen_blkif_schedule+0x182/0x790 [ 526.035327] ? finish_wait+0x80/0x80 [ 526.035340] ? xen_blkif_be_int+0x30/0x30 [ 526.035355] kthread+0xfe/0x140 [ 526.035371] ? kthread_park+0x90/0x90 [ 526.035385] ret_from_fork+0x22/0x30 [ 526.035398] Modules linked in: [ 526.035410] CR2: 0000000000000010 [ 526.035440] ---[ end trace 431ea72658d96c9d ]--- [ 526.176390] RIP: e030:gnttab_page_cache_get+0x32/0x60 [ 526.176460] Code: 89 f4 55 48 89 fd e8 4d e3 80 00 48 83 7d 08 00 48 89 c6 74 15 48 89 ef e8 5b e0 80 00 4c 89 e6 5d bf 01 00 00 00 41 5c eb 8e <48> 8b 04 25 10 00 00 00 48 89 ef 48 89 45 08 49 c7 04 24 00 00 00 [ 526.250734] RSP: e02b:ffffc90003e27a40 EFLAGS: 00010046 [ 526.250751] RAX: 0000000000000200 RBX: 0000000000000001 RCX: 0000000000000000 [ 526.250771] RDX: 0000000000000001 RSI: 0000000000000200 RDI: ffff888104275518 [ 526.250790] RBP: ffff888104275518 R08: 0000000000000000 R09: 0000000000000000 [ 526.250808] R10: ffff888104275400 R11: 0000000000000000 R12: ffff888109b5d3a0 [ 526.250827] R13: 0000000000000000 R14: 0000000000000000 R15: ffff888104275400 [ 526.250863] FS: 0000000000000000(0000) GS:ffff8881b54c0000(0000) knlGS:0000000000000000 [ 526.250884] CS: 10000e030 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 526.250901] CR2: 0000000000000010 CR3: 0000000103b5a000 CR4: 0000000000050660 [ 526.250924] Kernel panic - not syncing: Fatal exception [ 526.250972] Kernel Offset: disabled
This is 7059c2c00a2196865c2139083cbef47cd18109b6 with your patches on top.
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
Jürgen Groß
maintainerQuoted 42 lines · Marek Marczykowski-Górecki
Quoted 41 lines · Jürgen Groß
Marek,
Quoted 37 lines · Jason Andryuk
Quoted 18 lines · Roger Pau Monné
Quoted 16 lines · Marek Marczykowski-Górecki
Quoted 14 lines · Christoph Hellwig
Quoted 10 lines · Marek Marczykowski-Górecki
culprit:
commit
9e2369c06c8a181478039258a4598c1ddd2cadfaAuthor: Roger Pau Monne <[email protected]> Date: Tue Sep 1 10:33:26 2020 +0200xen: add helpers to allocate unpopulated memory
I'm adding relevant people and xen-devel to the thread. For completeness, here is the original crash message:
That commit definitively adds a new
ZONE_DEVICEuser, so it does look related. But you are not running on Xen, are you?Quoted 8 lines
Quoted 1 line
I am. It is Xen dom0.
I'm afraid I'm on leave and won't be able to look into this until the beginning of January. I would guess it's some kind of bad interaction between blkback and NVMe drivers both using
ZONE_DEVICE?Maybe the best is to revert this change and I will look into it when I get back, unless someone is willing to debug this further.
Looking at commit
9e2369c06c8aand xen-blkbackput_free_pages(), they both usepage->lruwhich is part of the anonymous union shared with *pgmap. That matches Marek's suspicion that theZONE_DEVICEmemory is being used asZONE_NORMAL.
memmap_init_zone_device()says:
*ZONE_DEVICEpages union ->lru with a ->pgmap back pointer
* andzone_device_data. It is a bug if aZONE_DEVICEpage is
* ever freed or placed on a driver-private list.
Quoted 7 lines
Quoted 1 line
Second try, now even tested to work on a test system (without NVMe).
It doesn't work for me:
[ 526.023340] xen-blkback: backend/vbd/1/51712: using 2 queues, protocol 1 (x86_64-abi) persistent grants [ 526.030550] xen-blkback: backend/vbd/1/51728: using 2 queues, protocol 1 (x86_64-abi) persistent grants [ 526.034810] BUG: kernel NULL pointer dereference, address: 0000000000000010
Oh, indeed. Silly bug. My test was with qdisk as backend :-(
3rd try...
Juergen
From 4f6ad98ce5fd457fd12e6617b0bc2a8f82fbce4d Mon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Mon, 7 Dec 2020 08:31:22 +0100
Subject: [PATCH 1/2] xen: add helpers for caching grant mapping pages
Instead of having similar helpers in multiple backend drivers use common helpers for caching pages allocated via gnttab_alloc_pages().
Make use of those helpers in blkback and scsiback.
--- drivers/block/xen-blkback/blkback.c | 89 ++++++----------------------- drivers/block/xen-blkback/common.h | 4 +- drivers/block/xen-blkback/xenbus.c | 6 +- drivers/xen/grant-table.c | 72 +++++++++++++++++++++++ drivers/xen/xen-scsiback.c | 60 ++++--------------- include/xen/grant_table.h | 13 +++++ 6 files changed, 116 insertions(+), 128 deletions(-)
drivers/block/xen-blkback/blkback.c +17 -72
@@ -132,73 +132,12 @@ module_param(log_stats, int, 0644);#define BLKBACK_INVALID_HANDLE (~0) -/* Number of free pages to remove on each call to gnttab_free_pages */ -#define NUM_BATCH_FREE_PAGES 10 -static inline bool persistent_gnt_timeout (struct persistent_gnt *persistent_gnt) {return pgrant_timeout && (jiffies - persistent_gnt->last_used >=HZ * pgrant_timeout); } -static inline int get_free_page (struct xen_blkif_ring *ring,struct page **page) -{ -unsigned long flags; - -spin_lock_irqsave (&ring->free_pages_lock, flags); -if (list_empty (&ring->free_pages)) { -BUG_ON (ring->free_pages_num !=0 ); -spin_unlock_irqrestore (&ring->free_pages_lock, flags); -return gnttab_alloc_pages (1 , page); - } -BUG_ON (ring->free_pages_num ==0 ); - page[0] = list_first_entry(&ring->free_pages, struct page, lru); -list_del (&page[0 ]->lru); - ring->free_pages_num--; -spin_unlock_irqrestore (&ring->free_pages_lock, flags); - -return 0 ; -} - -static inline void put_free_pages (struct xen_blkif_ring *ring,struct page **page, -int num) -{ -unsigned long flags; -int i; - -spin_lock_irqsave (&ring->free_pages_lock, flags); -for (i =0 ; i < num; i++) -list_add (&page[i]->lru, &ring->free_pages); - ring->free_pages_num += num; -spin_unlock_irqrestore (&ring->free_pages_lock, flags); -} - -static inline void shrink_free_pagepool (struct xen_blkif_ring *ring,int num) -{ -/* Remove requested pages in batches of NUM_BATCH_FREE_PAGES */ -struct page *page[NUM_BATCH_FREE_PAGES ]; -unsigned int num_pages =0 ; -unsigned long flags; - -spin_lock_irqsave (&ring->free_pages_lock, flags); -while (ring->free_pages_num > num) { -BUG_ON (list_empty (&ring->free_pages)); - page[num_pages] =list_first_entry (&ring->free_pages, - struct page, lru); -list_del (&page[num_pages]->lru); - ring->free_pages_num--; -if (++num_pages ==NUM_BATCH_FREE_PAGES ) { -spin_unlock_irqrestore (&ring->free_pages_lock, flags); -gnttab_free_pages (num_pages, page); -spin_lock_irqsave (&ring->free_pages_lock, flags); - num_pages =0 ; - } - } -spin_unlock_irqrestore (&ring->free_pages_lock, flags); -if (num_pages !=0 ) -gnttab_free_pages (num_pages, page); -} -#define vaddr (page) ((unsigned long)pfn_to_kaddr(page_to_pfn(page)))static int do_block_io_op (struct xen_blkif_ring *ring,unsigned int *eoi_flags);
@@ -331,7 +270,8 @@ static void free_persistent_gnts(struct xen_blkif_ring *ring, struct rb_root *ro unmap_data.count = segs_to_unmap;BUG_ON (gnttab_unmap_refs_sync (&unmap_data)); -put_free_pages (ring, pages, segs_to_unmap); +gnttab_page_cache_put (&ring->free_pages, pages, + segs_to_unmap); segs_to_unmap =0 ; }
@@ -371,7 +311,8 @@ void xen_blkbk_unmap_purged_grants(struct work_struct *work)if (++segs_to_unmap ==BLKIF_MAX_SEGMENTS_PER_REQUEST ) { unmap_data.count = segs_to_unmap;BUG_ON (gnttab_unmap_refs_sync (&unmap_data)); -put_free_pages (ring, pages, segs_to_unmap); +gnttab_page_cache_put (&ring->free_pages, pages, + segs_to_unmap); segs_to_unmap =0 ; }kfree (persistent_gnt);
@@ -379,7 +320,7 @@ void xen_blkbk_unmap_purged_grants(struct work_struct *work)if (segs_to_unmap >0 ) { unmap_data.count = segs_to_unmap;BUG_ON (gnttab_unmap_refs_sync (&unmap_data)); -put_free_pages (ring, pages, segs_to_unmap); +gnttab_page_cache_put (&ring->free_pages, pages, segs_to_unmap); } }
@@ -664,9 +605,10 @@ int xen_blkif_schedule(void *arg)/* Shrink the free pages pool if it is too large. */ if (time_before (jiffies, blkif->buffer_squeeze_end)) -shrink_free_pagepool (ring,0 ); +gnttab_page_cache_shrink (&ring->free_pages,0 );else -shrink_free_pagepool (ring, max_buffer_pages); +gnttab_page_cache_shrink (&ring->free_pages, + max_buffer_pages);if (log_stats &&time_after (jiffies, ring->st_print))print_stats (ring);
@@ -697,7 +639,7 @@ void xen_blkbk_free_caches(struct xen_blkif_ring *ring) ring->persistent_gnt_c =0 ;/* Since we are shutting down remove all pages from the buffer */ -shrink_free_pagepool (ring,0 /* All */ ); +gnttab_page_cache_shrink (&ring->free_pages,0 /* All */ ); } static unsigned int xen_blkbk_unmap_prepare(
@@ -736,7 +678,7 @@ static void xen_blkbk_unmap_and_respond_callback(int result, struct gntab_unmap_but is this the best way to deal with this? */ BUG_ON (result); -put_free_pages (ring, data->pages, data->count); +gnttab_page_cache_put (&ring->free_pages, data->pages, data->count);make_response (ring, pending_req->id, pending_req->operation, pending_req->status);free_req (ring, pending_req);
@@ -803,7 +745,8 @@ static void xen_blkbk_unmap(struct xen_blkif_ring *ring,if (invcount) { ret =gnttab_unmap_refs (unmap,NULL , unmap_pages, invcount);BUG_ON (ret); -put_free_pages (ring, unmap_pages, invcount); +gnttab_page_cache_put (&ring->free_pages, unmap_pages, + invcount); } pages += batch; num -= batch;
@@ -850,7 +793,8 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring, pages[i]->page = persistent_gnt->page; pages[i]->persistent_gnt = persistent_gnt; }else { -if (get_free_page (ring, &pages[i]->page)) +if (gnttab_page_cache_get (&ring->free_pages, + &pages[i]->page)) goto out_of_memory; addr =vaddr (pages[i]->page); pages_to_gnt[segs_to_map] = pages[i]->page;
@@ -883,7 +827,8 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring,BUG_ON (new_map_idx >= segs_to_map);if (unlikely (map[new_map_idx].status !=0 )) {pr_debug ("invalid buffer -- could not remap it\n" ); -put_free_pages (ring, &pages[seg_idx]->page,1 ); +gnttab_page_cache_put (&ring->free_pages, + &pages[seg_idx]->page,1 ); pages[seg_idx]->handle =BLKBACK_INVALID_HANDLE ; ret |=1 ; goto next;
@@ -944,7 +889,7 @@ static int xen_blkbk_map(struct xen_blkif_ring *ring, out_of_memory:pr_alert ("%s: out of memory\n" , __func__); -put_free_pages (ring, pages_to_gnt, segs_to_map); +gnttab_page_cache_put (&ring->free_pages, pages_to_gnt, segs_to_map);for (i = last_map; i < num; i++) pages[i]->handle =BLKBACK_INVALID_HANDLE ;return -ENOMEM ;
drivers/block/xen-blkback/common.h +1 -3
@@ -288,9 +288,7 @@ struct xen_blkif_ring {struct work_struct persistent_purge_work;/* Buffer of free pages to map grant refs. */ -spinlock_t free_pages_lock; -int free_pages_num; -struct list_head free_pages; +struct gnttab_page_cache free_pages;struct work_struct free_work;/* Thread shutdown wait queue. */
drivers/block/xen-blkback/xenbus.c +2 -4
@@ -144,8 +144,7 @@ static int xen_blkif_alloc_rings(struct xen_blkif *blkif)INIT_LIST_HEAD (&ring->pending_free);INIT_LIST_HEAD (&ring->persistent_purge_list);INIT_WORK (&ring->persistent_purge_work, xen_blkbk_unmap_purged_grants); -spin_lock_init (&ring->free_pages_lock); -INIT_LIST_HEAD (&ring->free_pages); +gnttab_page_cache_init (&ring->free_pages);spin_lock_init (&ring->pending_free_lock);init_waitqueue_head (&ring->pending_free_wq);
@@ -317,8 +316,7 @@ static int xen_blkif_disconnect(struct xen_blkif *blkif)BUG_ON (atomic_read (&ring->persistent_gnt_in_use) !=0 );BUG_ON (!list_empty (&ring->persistent_purge_list));BUG_ON (!RB_EMPTY_ROOT (&ring->persistent_gnts)); -BUG_ON (!list_empty (&ring->free_pages)); -BUG_ON (ring->free_pages_num !=0 ); +BUG_ON (ring->free_pages.num_pages !=0 );BUG_ON (ring->persistent_gnt_c !=0 );WARN_ON (i != (XEN_BLKIF_REQS_PER_PAGE * blkif->nr_ring_pages)); ring->active = false;
drivers/xen/grant-table.c +72 -0
78 lines not on this page · raw message
drivers/xen/xen-scsiback.c +11 -49
114 lines not on this page · raw message
include/xen/grant_table.h +13 -0
@@ -198,6 +198,19 @@ void gnttab_free_auto_xlat_frames(void);int gnttab_alloc_pages (int nr_pages,struct page **pages);void gnttab_free_pages (int nr_pages,struct page **pages); +struct gnttab_page_cache { +spinlock_t lock; +struct list_head pages; +unsigned int num_pages; +}; + +void gnttab_page_cache_init (struct gnttab_page_cache *cache); +int gnttab_page_cache_get (struct gnttab_page_cache *cache,struct page **page); +void gnttab_page_cache_put (struct gnttab_page_cache *cache,struct page **page, +unsigned int num); +void gnttab_page_cache_shrink (struct gnttab_page_cache *cache, +unsigned int num); +#ifdef CONFIG_XEN_GRANT_DMA_ALLOC struct gnttab_dma_alloc_args {/* Device for which DMA memory will be/was allocated. */
Signature · 1 line
2.26.2
From bf6d138b2be7e3195d952dd3269efecc097f1e61 Mon Sep 17 00:00:00 2001
From: Juergen Gross <[email protected]>
Date: Mon, 7 Dec 2020 09:36:14 +0100
Subject: [PATCH 2/2] xen: don't use page->lru for ZONE_DEVICE memory
Commit 9e2369c06c8a18 ("xen: add helpers to allocate unpopulated memory") introduced usage of ZONE_DEVICE memory for foreign memory mappings.
Unfortunately this collides with using page->lru for Xen backend private page caches.
Fix that by using page->zone_device_data instead.
--- drivers/xen/grant-table.c | 65 +++++++++++++++++++++++++++++---- drivers/xen/unpopulated-alloc.c | 20 +++++----- include/xen/grant_table.h | 4 ++ 3 files changed, 73 insertions(+), 16 deletions(-)
drivers/xen/grant-table.c +58 -7
96 lines not on this page · raw message
drivers/xen/unpopulated-alloc.c +11 -9
@@ -12,7 +12,7 @@#include <xen/xen.h> static DEFINE_MUTEX (list_lock); -static LIST_HEAD (page_list); +static struct page *page_list;static unsigned int list_count;static int fill_list (unsigned int nr_pages)
@@ -84,7 +84,8 @@ static int fill_list(unsigned int nr_pages)struct page *pg =virt_to_page (vaddr +PAGE_SIZE * i);BUG_ON (!virt_addr_valid (vaddr +PAGE_SIZE * i)); -list_add (&pg->lru, &page_list); + pg->zone_device_data = page_list; + page_list = pg; list_count++; }
@@ -118,12 +119,10 @@ int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages) }for (i =0 ; i < nr_pages; i++) { -struct page *pg =list_first_entry_or_null (&page_list, - struct page, - lru); +struct page *pg = page_list;BUG_ON (!pg); -list_del (&pg->lru); + page_list = pg->zone_device_data; list_count--; pages[i] = pg;
@@ -134,7 +133,8 @@ int xen_alloc_unpopulated_pages(unsigned int nr_pages, struct page **pages)unsigned int j;for (j =0 ; j <= i; j++) { -list_add (&pages[j]->lru, &page_list); + pages[j]->zone_device_data = page_list; + page_list = pages[j]; list_count++; } goto out;
@@ -160,7 +160,8 @@ void xen_free_unpopulated_pages(unsigned int nr_pages, struct page **pages)mutex_lock (&list_lock);for (i =0 ; i < nr_pages; i++) { -list_add (&pages[i]->lru, &page_list); + pages[i]->zone_device_data = page_list; + page_list = pages[i]; list_count++; }mutex_unlock (&list_lock);
@@ -189,7 +190,8 @@ static int __init init(void)struct page *pg =pfn_to_page (xen_extra_mem[i].start_pfn + j); -list_add (&pg->lru, &page_list); + pg->zone_device_data = page_list; + page_list = pg; list_count++; } }
include/xen/grant_table.h +4 -0
@@ -200,7 +200,11 @@ void gnttab_free_pages(int nr_pages, struct page **pages);struct gnttab_page_cache {spinlock_t lock; +#ifdef CONFIG_XEN_UNPOPULATED_ALLOC +struct page *pages; +#else struct list_head pages; +#endif unsigned int num_pages; };
Signature · 1 line
2.26.2
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme
Quoted 47 lines · Jürgen Groß
Quoted 46 lines · Marek Marczykowski-Górecki
Quoted 36 lines · Jürgen Groß
Marek,
Quoted 33 lines · Jason Andryuk
Quoted 18 lines · Roger Pau Monné
Quoted 16 lines · Marek Marczykowski-Górecki
Quoted 14 lines · Christoph Hellwig
Quoted 10 lines · Marek Marczykowski-Górecki
culprit:
commit
9e2369c06c8a181478039258a4598c1ddd2cadfaAuthor: Roger Pau Monne <[email protected]> Date: Tue Sep 1 10:33:26 2020 +0200xen: add helpers to allocate unpopulated memory
I'm adding relevant people and xen-devel to the thread. For completeness, here is the original crash message:
That commit definitively adds a new
ZONE_DEVICEuser, so it does look related. But you are not running on Xen, are you?Quoted 8 lines
Quoted 1 line
I am. It is Xen dom0.
I'm afraid I'm on leave and won't be able to look into this until the beginning of January. I would guess it's some kind of bad interaction between blkback and NVMe drivers both using
ZONE_DEVICE?Maybe the best is to revert this change and I will look into it when I get back, unless someone is willing to debug this further.
Looking at commit
9e2369c06c8aand xen-blkbackput_free_pages(), they both usepage->lruwhich is part of the anonymous union shared with *pgmap. That matches Marek's suspicion that theZONE_DEVICEmemory is being used asZONE_NORMAL.Quoted 6 lines
Quoted 4 lines
memmap_init_zone_device()says:
*ZONE_DEVICEpages union ->lru with a ->pgmap back pointer
* andzone_device_data. It is a bug if aZONE_DEVICEpage is
* ever freed or placed on a driver-private list.Second try, now even tested to work on a test system (without NVMe).
It doesn't work for me:
Quoted 7 lines
Quoted 3 lines
[ 526.023340] xen-blkback: backend/vbd/1/51712: using 2 queues, protocol 1 (x86_64-abi) persistent grants [ 526.030550] xen-blkback: backend/vbd/1/51728: using 2 queues, protocol 1 (x86_64-abi) persistent grants [ 526.034810] BUG: kernel NULL pointer dereference, address: 0000000000000010Oh, indeed. Silly bug. My test was with qdisk as backend :-(
3rd try...
Now it works :)
Signature · 5 lines
Best Regards, Marek Marczykowski-Górecki Invisible Things Lab A: Because it messes up the order in which people normally read text. Q: Why is top-posting such a bad thing?
_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme