Fix crash after reloading a driver using ttm
Subsystems (12)
cover Fix crash after reloading a driver using ttm
Kobjects are supposed to be dynamically allocated, but with recent changes this rule was violated. Reverting those commits fixes crashes when a drm driver using TTM gets loaded again.
The object in question is "ttm_mem_glob" declared inside "include/drm/ttm/ttm_memory.h" and instatiated inside "drivers/gpu/drm/ttm/ttm_memory.c".
from "Documentation/kobject.txt":
"Because kobjects are dynamic, they must not be declared statically or on the stack, but instead, always allocated dynamically. Future versions of the kernel will contain a run-time check for kobjects that are created statically and will warn the developer of this improper usage."
Unloading ttm before reloading the driver workarounds that crash, because the memory backing the kobject member "kobj" is cleaned up. The kobject_del and kobject_put function never free or clean up the kobject object leaving it in an undefined state.
I reverted a few more commits to make it less painful for me to rever this rather big change.
dmesg output:
[54758.418036] kobject (00000000687a067d): tried to init an initialized object, something is seriously wrong. [54758.418040] CPU: 6 PID: 26746 Comm: insmod Tainted: G U OE 5.0.6-200.fc29.x86_64 #1 [54758.418041] Hardware name: Dell Inc. XPS 15 9560/05FFDN, BIOS 1.12.1 10/02/2018 [54758.418041] Call Trace: [54758.418049] dump_stack+0x5c/0x80 [54758.418054] kobject_init.cold.9+0x31/0x3f [54758.418057] kobject_init_and_add+0x35/0xa0 [54758.418063] ttm_mem_global_init+0x8f/0x2b0 [ttm] [54758.418067] ? __debugfs_create_file+0xe1/0x110 [54758.418071] ttm_bo_device_init+0x198/0x2a0 [ttm] [54758.418144] nouveau_ttm_init+0xbf/0x340 [nouveau] [54758.418206] nouveau_drm_device_init+0x125/0x7d0 [nouveau] [54758.418210] ? pci_bus_read_config_word+0x49/0x70 [54758.418266] nouveau_drm_probe+0x26f/0x2c0 [nouveau] [54758.418270] local_pci_probe+0x41/0x90 [54758.418272] pci_device_probe+0x118/0x1a0 [54758.418275] really_probe+0xf8/0x3b0 [54758.418277] driver_probe_device+0xb3/0xf0 [54758.418278] __driver_attach+0xdd/0x110 [54758.418280] ? driver_probe_device+0xf0/0xf0 [54758.418282] bus_for_each_dev+0x77/0xc0 [54758.418285] ? klist_add_tail+0x3b/0x60 [54758.418287] bus_add_driver+0x152/0x230 [54758.418288] ? 0xffffffffc1027000 [54758.418290] driver_register+0x6b/0xb0 [54758.418291] ? 0xffffffffc1027000 [54758.418294] do_one_initcall+0x46/0x1c3 [54758.418296] ? _cond_resched+0x15/0x30 [54758.418299] ? kmem_cache_alloc_trace+0x154/0x1d0 [54758.418302] do_init_module+0x5a/0x210 [54758.418304] load_module+0x2096/0x22d0 [54758.418308] ? ima_post_read_file+0xf4/0x100 [54758.418310] ? __do_sys_finit_module+0xa8/0x110 [54758.418312] __do_sys_finit_module+0xa8/0x110 [54758.418315] do_syscall_64+0x5b/0x160 [54758.418317] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [54758.418319] RIP: 0033:0x7fc0b38b6edd [54758.418321] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 7b 7f 0c 00 f7 d8 64 89 01 48 [54758.418322] RSP: 002b:00007ffc7f1620d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 [54758.418323] RAX: ffffffffffffffda RBX: 00005629a3996ac0 RCX: 00007fc0b38b6edd [54758.418324] RDX: 0000000000000000 RSI: 00005629a3996260 RDI: 0000000000000003 [54758.418325] RBP: 00005629a3996260 R08: 0000000000000000 R09: 0000000000000000 [54758.418326] R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000000000 [54758.418326] R13: 00005629a3996a80 R14: 0000000000000000 R15: 00005629a3996260 [54758.418346] BUG: unable to handle kernel paging request at 00000004ee194700 [54758.418348] #PF error: [WRITE] [54758.418349] PGD 0 P4D 0 [54758.418352] Oops: 0002 [#1] SMP PTI [54758.418354] CPU: 6 PID: 26746 Comm: insmod Tainted: G U OE 5.0.6-200.fc29.x86_64 #1 [54758.418355] Hardware name: Dell Inc. XPS 15 9560/05FFDN, BIOS 1.12.1 10/02/2018 [54758.418360] RIP: 0010:ttm_mem_global_init+0x1fe/0x2b0 [ttm] [54758.418361] Code: 00 00 00 48 89 5d 40 48 89 ab a0 00 00 00 e8 79 ba 95 f8 85 c0 0f 85 a2 00 00 00 8b 83 90 00 00 00 8d 50 01 89 93 90 00 00 00 <48> 89 ac c3 80 00 00 00 85 d2 0f 85 c6 99 00 00 48 8b 83 98 00 00 [54758.418363] RSP: 0018:ffffc24e53c1f988 EFLAGS: 00010246 [54758.418364] RAX: 00000000a5a2f300 RBX: ffffffffc101ae80 RCX: 0000000000000000 [54758.418366] RDX: 00000000a5a2f301 RSI: 0000000000000000 RDI: ffff9ebe78b67330 [54758.418367] RBP: ffff9ebe42c79d00 R08: 0000000000000044 R09: 0000000000000228 [54758.418368] R10: 0000000000000000 R11: ffff9ebb62720bb8 R12: 0000000000000000 [54758.418370] R13: ffff9ebe27d71640 R14: ffff9eba9f258600 R15: ffffffffc1453880 [54758.418371] FS: 00007fc0b379c280(0000) GS:ffff9ebeae380000(0000) knlGS:0000000000000000 [54758.418373] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [54758.418374] CR2: 00000004ee194700 CR3: 000000045069e005 CR4: 00000000003606e0 [54758.418375] Call Trace: [54758.418381] ttm_bo_device_init+0x198/0x2a0 [ttm] [54758.418439] nouveau_ttm_init+0xbf/0x340 [nouveau] [54758.418495] nouveau_drm_device_init+0x125/0x7d0 [nouveau] [54758.418499] ? pci_bus_read_config_word+0x49/0x70 [54758.418552] nouveau_drm_probe+0x26f/0x2c0 [nouveau] [54758.418556] local_pci_probe+0x41/0x90 [54758.418558] pci_device_probe+0x118/0x1a0 [54758.418561] really_probe+0xf8/0x3b0 [54758.418563] driver_probe_device+0xb3/0xf0 [54758.418565] __driver_attach+0xdd/0x110 [54758.418567] ? driver_probe_device+0xf0/0xf0 [54758.418570] bus_for_each_dev+0x77/0xc0 [54758.418573] ? klist_add_tail+0x3b/0x60 [54758.418574] bus_add_driver+0x152/0x230 [54758.418576] ? 0xffffffffc1027000 [54758.418578] driver_register+0x6b/0xb0 [54758.418580] ? 0xffffffffc1027000 [54758.418583] do_one_initcall+0x46/0x1c3 [54758.418585] ? _cond_resched+0x15/0x30 [54758.418587] ? kmem_cache_alloc_trace+0x154/0x1d0 [54758.418591] do_init_module+0x5a/0x210 [54758.418593] load_module+0x2096/0x22d0 [54758.418596] ? ima_post_read_file+0xf4/0x100 [54758.418599] ? __do_sys_finit_module+0xa8/0x110 [54758.418601] __do_sys_finit_module+0xa8/0x110 [54758.418604] do_syscall_64+0x5b/0x160 [54758.418607] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [54758.418609] RIP: 0033:0x7fc0b38b6edd [54758.418610] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 7b 7f 0c 00 f7 d8 64 89 01 48 [54758.418612] RSP: 002b:00007ffc7f1620d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 [54758.418614] RAX: ffffffffffffffda RBX: 00005629a3996ac0 RCX: 00007fc0b38b6edd [54758.418615] RDX: 0000000000000000 RSI: 00005629a3996260 RDI: 0000000000000003 [54758.418616] RBP: 00005629a3996260 R08: 0000000000000000 R09: 0000000000000000 [54758.418618] R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000000000 [54758.418619] R13: 00005629a3996a80 R14: 0000000000000000 R15: 00005629a3996260 [54758.418620] Modules linked in: nouveau(OE+) acpi_call(OE) ttm rfcomm ccm xt_CHECKSUM ipt_MASQUERADE tun bridge stp llc devlink ip6t_rpfilter ip6t_REJECT nf_reject_ipv6 xt_conntrack ebtable_nat ip6table_nat nf_nat_ipv6 ip6table_mangle ip6table_raw ip6table_security iptable_nat nf_nat_ipv4 nf_nat iptable_mangle iptable_raw iptable_security nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 libcrc32c ip_set nfnetlink ebtable_filter ebtables ip6table_filter ip6_tables cmac bnep sunrpc vfat fat btusb btrtl btbcm btintel uvcvideo videobuf2_vmalloc bluetooth videobuf2_memops videobuf2_v4l2 videobuf2_common videodev media ecdh_generic arc4 snd_hda_codec_hdmi ath10k_pci ath10k_core snd_hda_codec_realtek iTCO_wdt mei_wdt iTCO_vendor_support snd_hda_codec_generic mac80211 intel_rapl snd_hda_intel x86_pkg_temp_thermal intel_powerclamp coretemp snd_hda_codec dell_laptop ledtrig_audio dell_smm_hwmon snd_hda_core kvm_intel snd_hwdep ath snd_seq snd_seq_device intel_cstate cfg80211 snd_pcm dell_wmi intel_uncore [54758.418653] dell_smbios dcdbas intel_rapl_perf snd_timer joydev dell_wmi_descriptor intel_wmi_thunderbolt wmi_bmof snd idma64 soundcore i2c_i801 rfkill rtsx_pci_ms memstick mei_me mei processor_thermal_device intel_lpss_pci intel_soc_dts_iosf intel_pch_thermal intel_lpss int3400_thermal acpi_pad acpi_thermal_rel int3403_thermal intel_hid pcc_cpufreq int340x_thermal_zone sparse_keymap binfmt_misc zram dm_crypt hid_multitouch i915 kvmgt mdev vfio kvm irqbypass i2c_algo_bit crct10dif_pclmul drm_kms_helper rtsx_pci_sdmmc crc32_pclmul mmc_core crc32c_intel mxm_wmi drm nvme ghash_clmulni_intel nvme_core serio_raw rtsx_pci i2c_hid video wmi i2c_dev lz4 lz4_compress [last unloaded: nouveau] [54758.418679] CR2: 00000004ee194700 [54758.418681] ---[ end trace c5175234e6efc034 ]--- [54758.418686] RIP: 0010:ttm_mem_global_init+0x1fe/0x2b0 [ttm] [54758.418688] Code: 00 00 00 48 89 5d 40 48 89 ab a0 00 00 00 e8 79 ba 95 f8 85 c0 0f 85 a2 00 00 00 8b 83 90 00 00 00 8d 50 01 89 93 90 00 00 00 <48> 89 ac c3 80 00 00 00 85 d2 0f 85 c6 99 00 00 48 8b 83 98 00 00 [54758.418689] RSP: 0018:ffffc24e53c1f988 EFLAGS: 00010246 [54758.418690] RAX: 00000000a5a2f300 RBX: ffffffffc101ae80 RCX: 0000000000000000 [54758.418691] RDX: 00000000a5a2f301 RSI: 0000000000000000 RDI: ffff9ebe78b67330 [54758.418692] RBP: ffff9ebe42c79d00 R08: 0000000000000044 R09: 0000000000000228 [54758.418694] R10: 0000000000000000 R11: ffff9ebb62720bb8 R12: 0000000000000000 [54758.418695] R13: ffff9ebe27d71640 R14: ffff9eba9f258600 R15: ffffffffc1453880 [54758.418696] FS: 00007fc0b379c280(0000) GS:ffff9ebeae380000(0000) knlGS:0000000000000000 [54758.418698] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [54758.418699] CR2: 00000004ee194700 CR3: 000000045069e005 CR4: 00000000003606e0
Karol Herbst (6):
Revert "drm: Remove drm_global.{c,h} v2"
Revert "drm/ttm: initialize globals during device init (v2)" Revert "drm/ttm: Fix bo_global and mem_global kfree error" Revert "drm/ttm: use a static ttm_bo_global instance" Revert "drm/ttm: make the device list mutex static" Revert "drm/ttm: use a static ttm_mem_global instance"
drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 103 ++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 2 + drivers/gpu/drm/ast/ast_drv.h | 2 + drivers/gpu/drm/ast/ast_ttm.c | 64 ++++++++ drivers/gpu/drm/bochs/bochs.h | 2 + drivers/gpu/drm/bochs/bochs_mm.c | 61 ++++++++ drivers/gpu/drm/cirrus/cirrus_drv.h | 2 + drivers/gpu/drm/cirrus/cirrus_ttm.c | 64 ++++++++ drivers/gpu/drm/drm_drv.c | 2 + drivers/gpu/drm/drm_global.c | 137 ++++++++++++++++++ .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 + drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 57 ++++++++ drivers/gpu/drm/mgag200/mgag200_drv.h | 2 + drivers/gpu/drm/mgag200/mgag200_ttm.c | 64 ++++++++ drivers/gpu/drm/nouveau/nouveau_drv.h | 2 + drivers/gpu/drm/nouveau/nouveau_ttm.c | 67 +++++++++ drivers/gpu/drm/qxl/qxl_drv.h | 3 + drivers/gpu/drm/qxl/qxl_ttm.c | 61 ++++++++ drivers/gpu/drm/radeon/radeon.h | 3 + drivers/gpu/drm/radeon/radeon_ttm.c | 65 +++++++++ drivers/gpu/drm/ttm/ttm_bo.c | 67 +++------ drivers/gpu/drm/ttm/ttm_memory.c | 14 +- drivers/gpu/drm/virtio/virtgpu_drv.h | 3 + drivers/gpu/drm/virtio/virtgpu_ttm.c | 62 ++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 15 +- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 6 +- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 54 +++++++ drivers/staging/vboxvideo/vbox_drv.h | 2 + drivers/staging/vboxvideo/vbox_ttm.c | 65 ++++++++- include/drm/drmP.h | 1 + include/drm/drm_global.h | 53 +++++++ include/drm/ttm/ttm_bo_driver.h | 54 ++++++- include/drm/ttm/ttm_memory.h | 4 +- 34 files changed, 1102 insertions(+), 65 deletions(-) create mode 100644 drivers/gpu/drm/drm_global.c create mode 100644 include/drm/drm_global.h
Signature · 6 lines
2.20.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/6 Revert "drm: Remove drm_global.{c,h} v2"
This reverts commit 2bb42410b1bd324912389c6ac748df1c1befd69f.
--- drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/drm_drv.c | 2 + drivers/gpu/drm/drm_global.c | 137 ++++++++++++++++++++++++++++++++ include/drm/drmP.h | 1 + include/drm/drm_global.h | 53 ++++++++++++ include/drm/ttm/ttm_bo_driver.h | 1 + 6 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/drm_global.c create mode 100644 include/drm/drm_global.h
drivers/gpu/drm/Makefile +1 -1
@@ -11,7 +11,7 @@ drm-y := drm_auth.o drm_bufs.o drm_cache.o \ drm_sysfs.o drm_hashtab.o drm_mm.o \ drm_crtc.o drm_fourcc.o drm_modes.o drm_edid.o \ drm_encoder_slave.o \ - drm_trace_points.o drm_prime.o \ + drm_trace_points.o drm_global.o drm_prime.o \ drm_rect.o drm_vma_manager.o drm_flip_work.o \ drm_modeset_lock.o drm_atomic.o drm_bridge.o \ drm_framebuffer.o drm_connector.o drm_blend.o \
drivers/gpu/drm/drm_drv.c +2 -0
@@ -960,12 +960,14 @@ static void drm_core_exit(void)drm_sysfs_destroy ();idr_destroy (&drm_minors_idr);drm_connector_ida_destroy (); +drm_global_release (); }static int __init drm_core_init (void ) {int ret; +drm_global_init ();drm_connector_ida_init ();idr_init (&drm_minors_idr);
drivers/gpu/drm/drm_global.c new file +137 -0
137 lines not on this page · raw message
include/drm/drmP.h +1 -0
@@ -68,6 +68,7 @@#include <drm/drm_agpsupport.h> #include <drm/drm_crtc.h> #include <drm/drm_fourcc.h> +#include <drm/drm_global.h> #include <drm/drm_hashtab.h> #include <drm/drm_mm.h> #include <drm/drm_os_linux.h>
include/drm/drm_global.h new file +53 -0
53 lines not on this page · raw message
include/drm/ttm/ttm_bo_driver.h +1 -0
@@ -31,6 +31,7 @@#define _TTM_BO_DRIVER_H_#include <drm/drm_mm.h> +#include <drm/drm_global.h> #include <drm/drm_vma_manager.h> #include <linux/workqueue.h> #include <linux/fs.h>
Signature · 6 lines
2.20.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/6 Revert "drm/ttm: initialize globals during device init (v2)"
In reply to Karol HerbstThis reverts commit a64f784bb14a56bfdfad2dc397dd67e4564e3a29.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 59 ++++++++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 1 + drivers/gpu/drm/ast/ast_drv.h | 1 + drivers/gpu/drm/ast/ast_ttm.c | 36 +++++++++++ drivers/gpu/drm/bochs/bochs.h | 1 + drivers/gpu/drm/bochs/bochs_mm.c | 35 +++++++++++ drivers/gpu/drm/cirrus/cirrus_drv.h | 1 + drivers/gpu/drm/cirrus/cirrus_ttm.c | 36 +++++++++++ .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 1 + drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 34 +++++++++++ drivers/gpu/drm/mgag200/mgag200_drv.h | 1 + drivers/gpu/drm/mgag200/mgag200_ttm.c | 36 +++++++++++ drivers/gpu/drm/nouveau/nouveau_drv.h | 1 + drivers/gpu/drm/nouveau/nouveau_ttm.c | 39 ++++++++++++ drivers/gpu/drm/qxl/qxl_drv.h | 2 + drivers/gpu/drm/qxl/qxl_ttm.c | 33 +++++++++++ drivers/gpu/drm/radeon/radeon.h | 2 + drivers/gpu/drm/radeon/radeon_ttm.c | 39 ++++++++++++ drivers/gpu/drm/ttm/ttm_bo.c | 19 +++--- drivers/gpu/drm/virtio/virtgpu_drv.h | 2 + drivers/gpu/drm/virtio/virtgpu_ttm.c | 35 +++++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 11 +++- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 3 + drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 27 +++++++++ drivers/staging/vboxvideo/vbox_drv.h | 1 + drivers/staging/vboxvideo/vbox_ttm.c | 41 ++++++++++++- include/drm/ttm/ttm_bo_driver.h | 41 ++++++++++++- 27 files changed, 521 insertions(+), 17 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +57 -2
@@ -61,6 +61,56 @@ static int amdgpu_map_buffer(struct ttm_buffer_object *bo,static int amdgpu_ttm_debugfs_init (struct amdgpu_device *adev);static void amdgpu_ttm_debugfs_fini (struct amdgpu_device *adev); +/* +* Global memory. +*/ + +/** +* amdgpu_ttm_global_init - Initialize global TTM memory reference structures. +* +* @adev: AMDGPU device for which the global structures need to be registered. +* +* This is called as part of the AMDGPU ttm init from amdgpu_ttm_init() +* during bring up. +*/ +static int amdgpu_ttm_global_init (struct amdgpu_device *adev) +{ +struct drm_global_reference *global_ref; +int r; + +/* ensure reference is false in case init fails */ + adev->mman.mem_global_referenced = false; + + global_ref = &adev->mman.bo_global_ref.ref; + global_ref->global_type =DRM_GLOBAL_TTM_BO ; + global_ref->size =sizeof (struct ttm_bo_global ); + global_ref->init = &ttm_bo_global_ref_init; + global_ref->release = &ttm_bo_global_ref_release; + r =drm_global_item_ref (global_ref); +if (r) { +DRM_ERROR ("Failed setting up TTM BO subsystem.\n" ); + goto error_bo; + } + +mutex_init (&adev->mman.gtt_window_lock); + + adev->mman.mem_global_referenced = true; + +return 0 ; + +error_bo: +return r; +} + +static void amdgpu_ttm_global_fini (struct amdgpu_device *adev) +{ +if (adev->mman.mem_global_referenced) { +mutex_destroy (&adev->mman.gtt_window_lock); +drm_global_item_unref (&adev->mman.bo_global_ref.ref); + adev->mman.mem_global_referenced = false; + } +} +static int amdgpu_invalidate_caches (struct ttm_bo_device *bdev,uint32_t flags) {return 0 ;
@@ -1664,10 +1714,14 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)int r;u64 vis_vram_limit; -mutex_init (&adev->mman.gtt_window_lock); - +/* initialize global references for vram/gtt */ + r =amdgpu_ttm_global_init (adev); +if (r) { +return r; + }/* No others user of address space so set it to 0 */ r = ttm_bo_device_init(&adev->mman.bdev, + adev->mman.bo_global_ref.ref.object, &amdgpu_bo_driver, adev->ddev->anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET,
@@ -1824,6 +1878,7 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)ttm_bo_clean_mm (&adev->mman.bdev,AMDGPU_PL_GWS );ttm_bo_clean_mm (&adev->mman.bdev,AMDGPU_PL_OA );ttm_bo_device_release (&adev->mman.bdev); +amdgpu_ttm_global_fini (adev); adev->mman.initialized = false;DRM_INFO ("amdgpu: ttm finalized\n" ); }
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +1 -0
@@ -39,6 +39,7 @@#define AMDGPU_GTT_NUM_TRANSFER_WINDOWS 2struct amdgpu_mman { +struct ttm_bo_global_ref bo_global_ref;struct ttm_bo_device bdev;bool mem_global_referenced;bool initialized;
drivers/gpu/drm/ast/ast_drv.h +1 -0
@@ -104,6 +104,7 @@ struct ast_private {int fb_mtrr;struct { +struct ttm_bo_global_ref bo_global_ref;struct ttm_bo_device bdev; } ttm;
drivers/gpu/drm/ast/ast_ttm.c +36 -0
@@ -36,6 +36,35 @@ ast_bdev(struct ttm_bo_device *bd) return container_of(bd, struct ast_private, ttm.bdev); } +static int ast_ttm_global_init (struct ast_private *ast) +{ +struct drm_global_reference *global_ref; +int r; + + global_ref = &ast->ttm.bo_global_ref.ref; + global_ref->global_type =DRM_GLOBAL_TTM_BO ; + global_ref->size =sizeof (struct ttm_bo_global ); + global_ref->init = &ttm_bo_global_ref_init; + global_ref->release = &ttm_bo_global_ref_release; + r =drm_global_item_ref (global_ref); +if (r !=0 ) { +DRM_ERROR ("Failed setting up TTM BO subsystem.\n" ); +return r; + } +return 0 ; +} + +static void +ast_ttm_global_release (struct ast_private *ast) +{ +if (ast->ttm.bo_global_ref.ref.release ==NULL ) +return ; + +drm_global_item_unref (&ast->ttm.bo_global_ref.ref); + ast->ttm.bo_global_ref.ref.release =NULL ; +} + +static void ast_bo_ttm_destroy (struct ttm_buffer_object *tbo) {struct ast_bo *bo;
@@ -175,7 +204,12 @@ int ast_mm_init(struct ast_private *ast)struct drm_device *dev = ast->dev;struct ttm_bo_device *bdev = &ast->ttm.bdev; + ret =ast_ttm_global_init (ast); +if (ret) +return ret; + ret = ttm_bo_device_init(&ast->ttm.bdev, + ast->ttm.bo_global_ref.ref.object, &ast_bo_driver, dev->anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET,
@@ -206,6 +240,8 @@ void ast_mm_fini(struct ast_private *ast)ttm_bo_device_release (&ast->ttm.bdev); +ast_ttm_global_release (ast); +arch_phys_wc_del (ast->fb_mtrr);arch_io_free_memtype_wc (pci_resource_start (dev->pdev,0 ),pci_resource_len (dev->pdev,0 ));
drivers/gpu/drm/bochs/bochs.h +1 -0
@@ -77,6 +77,7 @@ struct bochs_device {/* ttm */ struct { +struct ttm_bo_global_ref bo_global_ref;struct ttm_bo_device bdev;bool initialized; } ttm;
drivers/gpu/drm/bochs/bochs_mm.c +35 -0
@@ -16,6 +16,35 @@ static inline struct bochs_device *bochs_bdev(struct ttm_bo_device *bd) return container_of(bd, struct bochs_device, ttm.bdev); } +static int bochs_ttm_global_init (struct bochs_device *bochs) +{ +struct drm_global_reference *global_ref; +int r; + + global_ref = &bochs->ttm.bo_global_ref.ref; + global_ref->global_type =DRM_GLOBAL_TTM_BO ; + global_ref->size =sizeof (struct ttm_bo_global ); + global_ref->init = &ttm_bo_global_ref_init; + global_ref->release = &ttm_bo_global_ref_release; + r =drm_global_item_ref (global_ref); +if (r !=0 ) { +DRM_ERROR ("Failed setting up TTM BO subsystem.\n" ); +return r; + } + +return 0 ; +} + +static void bochs_ttm_global_release (struct bochs_device *bochs) +{ +if (bochs->ttm.bo_global_ref.ref.release ==NULL ) +return ; + +drm_global_item_unref (&bochs->ttm.bo_global_ref.ref); + bochs->ttm.bo_global_ref.ref.release =NULL ; +} + +static void bochs_bo_ttm_destroy (struct ttm_buffer_object *tbo) {struct bochs_bo *bo;
@@ -153,7 +182,12 @@ int bochs_mm_init(struct bochs_device *bochs)struct ttm_bo_device *bdev = &bochs->ttm.bdev;int ret; + ret =bochs_ttm_global_init (bochs); +if (ret) +return ret; + ret = ttm_bo_device_init(&bochs->ttm.bdev, + bochs->ttm.bo_global_ref.ref.object, &bochs_bo_driver, bochs->dev->anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET,
@@ -180,6 +214,7 @@ void bochs_mm_fini(struct bochs_device *bochs)return ;ttm_bo_device_release (&bochs->ttm.bdev); +bochs_ttm_global_release (bochs); bochs->ttm.initialized = false; }
drivers/gpu/drm/cirrus/cirrus_drv.h +1 -0
@@ -136,6 +136,7 @@ struct cirrus_device {int fb_mtrr;struct { +struct ttm_bo_global_ref bo_global_ref;struct ttm_bo_device bdev; } ttm;bool mm_inited;
drivers/gpu/drm/cirrus/cirrus_ttm.c +36 -0
@@ -36,6 +36,35 @@ cirrus_bdev(struct ttm_bo_device *bd) return container_of(bd, struct cirrus_device, ttm.bdev); } +static int cirrus_ttm_global_init (struct cirrus_device *cirrus) +{ +struct drm_global_reference *global_ref; +int r; + + global_ref = &cirrus->ttm.bo_global_ref.ref; + global_ref->global_type =DRM_GLOBAL_TTM_BO ; + global_ref->size =sizeof (struct ttm_bo_global ); + global_ref->init = &ttm_bo_global_ref_init; + global_ref->release = &ttm_bo_global_ref_release; + r =drm_global_item_ref (global_ref); +if (r !=0 ) { +DRM_ERROR ("Failed setting up TTM BO subsystem.\n" ); +return r; + } +return 0 ; +} + +static void +cirrus_ttm_global_release (struct cirrus_device *cirrus) +{ +if (cirrus->ttm.bo_global_ref.ref.release ==NULL ) +return ; + +drm_global_item_unref (&cirrus->ttm.bo_global_ref.ref); + cirrus->ttm.bo_global_ref.ref.release =NULL ; +} + +static void cirrus_bo_ttm_destroy (struct ttm_buffer_object *tbo) {struct cirrus_bo *bo;
@@ -175,7 +204,12 @@ int cirrus_mm_init(struct cirrus_device *cirrus)struct drm_device *dev = cirrus->dev;struct ttm_bo_device *bdev = &cirrus->ttm.bdev; + ret =cirrus_ttm_global_init (cirrus); +if (ret) +return ret; + ret = ttm_bo_device_init(&cirrus->ttm.bdev, + cirrus->ttm.bo_global_ref.ref.object, &cirrus_bo_driver, dev->anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET,
@@ -211,6 +245,8 @@ void cirrus_mm_fini(struct cirrus_device *cirrus)ttm_bo_device_release (&cirrus->ttm.bdev); +cirrus_ttm_global_release (cirrus); +arch_phys_wc_del (cirrus->fb_mtrr); cirrus->fb_mtrr =0 ; arch_io_free_memtype_wc(pci_resource_start(dev->pdev, 0),
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h +1 -0
@@ -49,6 +49,7 @@ struct hibmc_drm_private {bool mode_config_initialized;/* ttm */ +struct ttm_bo_global_ref bo_global_ref;struct ttm_bo_device bdev;bool initialized;
drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c +34 -0
@@ -29,6 +29,32 @@ hibmc_bdev(struct ttm_bo_device *bd) return container_of(bd, struct hibmc_drm_private, bdev); } +static int hibmc_ttm_global_init (struct hibmc_drm_private *hibmc) +{ +int ret; + + hibmc->bo_global_ref.ref.global_type =DRM_GLOBAL_TTM_BO ; + hibmc->bo_global_ref.ref.size =sizeof (struct ttm_bo_global ); + hibmc->bo_global_ref.ref.init = &ttm_bo_global_ref_init; + hibmc->bo_global_ref.ref.release = &ttm_bo_global_ref_release; + ret =drm_global_item_ref (&hibmc->bo_global_ref.ref); +if (ret) { +DRM_ERROR ("failed setting up TTM BO subsystem: %d\n" , ret); +return ret; + } +return 0 ; +} + +static void +hibmc_ttm_global_release (struct hibmc_drm_private *hibmc) +{ +if (hibmc->bo_global_ref.ref.release ==NULL ) +return ; + +drm_global_item_unref (&hibmc->bo_global_ref.ref); + hibmc->bo_global_ref.ref.release =NULL ; +} +static void hibmc_bo_ttm_destroy (struct ttm_buffer_object *tbo) { struct hibmc_bo *bo = container_of(tbo, struct hibmc_bo, bo);
@@ -188,12 +214,18 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc)struct drm_device *dev = hibmc->dev;struct ttm_bo_device *bdev = &hibmc->bdev; + ret =hibmc_ttm_global_init (hibmc); +if (ret) +return ret; + ret =ttm_bo_device_init (&hibmc->bdev, + hibmc->bo_global_ref.ref.object, &hibmc_bo_driver, dev->anon_inode->i_mapping,DRM_FILE_PAGE_OFFSET , true);if (ret) { +hibmc_ttm_global_release (hibmc);DRM_ERROR ("error initializing bo driver: %d\n" , ret);return ret; }
@@ -201,6 +233,7 @@ int hibmc_mm_init(struct hibmc_drm_private *hibmc) ret =ttm_bo_init_mm (bdev,TTM_PL_VRAM , hibmc->fb_size >>PAGE_SHIFT );if (ret) { +hibmc_ttm_global_release (hibmc);DRM_ERROR ("failed ttm VRAM init: %d\n" , ret);return ret; }
@@ -215,6 +248,7 @@ void hibmc_mm_fini(struct hibmc_drm_private *hibmc)return ;ttm_bo_device_release (&hibmc->bdev); +hibmc_ttm_global_release (hibmc); hibmc->mm_inited = false; }
drivers/gpu/drm/mgag200/mgag200_drv.h +1 -0
@@ -212,6 +212,7 @@ struct mga_device {int fb_mtrr;struct { +struct ttm_bo_global_ref bo_global_ref;struct ttm_bo_device bdev; } ttm;
drivers/gpu/drm/mgag200/mgag200_ttm.c +36 -0
@@ -36,6 +36,35 @@ mgag200_bdev(struct ttm_bo_device *bd) return container_of(bd, struct mga_device, ttm.bdev); } +static int mgag200_ttm_global_init (struct mga_device *ast) +{ +struct drm_global_reference *global_ref; +int r; + + global_ref = &ast->ttm.bo_global_ref.ref; + global_ref->global_type =DRM_GLOBAL_TTM_BO ; + global_ref->size =sizeof (struct ttm_bo_global ); + global_ref->init = &ttm_bo_global_ref_init; + global_ref->release = &ttm_bo_global_ref_release; + r =drm_global_item_ref (global_ref); +if (r !=0 ) { +DRM_ERROR ("Failed setting up TTM BO subsystem.\n" ); +return r; + } +return 0 ; +} + +static void +mgag200_ttm_global_release (struct mga_device *ast) +{ +if (ast->ttm.bo_global_ref.ref.release ==NULL ) +return ; + +drm_global_item_unref (&ast->ttm.bo_global_ref.ref); + ast->ttm.bo_global_ref.ref.release =NULL ; +} + +static void mgag200_bo_ttm_destroy (struct ttm_buffer_object *tbo) {struct mgag200_bo *bo;
@@ -175,7 +204,12 @@ int mgag200_mm_init(struct mga_device *mdev)struct drm_device *dev = mdev->dev;struct ttm_bo_device *bdev = &mdev->ttm.bdev; + ret =mgag200_ttm_global_init (mdev); +if (ret) +return ret; + ret = ttm_bo_device_init(&mdev->ttm.bdev, + mdev->ttm.bo_global_ref.ref.object, &mgag200_bo_driver, dev->anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET,
@@ -206,6 +240,8 @@ void mgag200_mm_fini(struct mga_device *mdev)ttm_bo_device_release (&mdev->ttm.bdev); +mgag200_ttm_global_release (mdev); +arch_io_free_memtype_wc (pci_resource_start (dev->pdev,0 ),pci_resource_len (dev->pdev,0 ));arch_phys_wc_del (mdev->fb_mtrr);
drivers/gpu/drm/nouveau/nouveau_drv.h +1 -0
@@ -146,6 +146,7 @@ struct nouveau_drm {/* TTM interface support */ struct { +struct ttm_bo_global_ref bo_global_ref;struct ttm_bo_device bdev;atomic_t validate_sequence; int (*move)(struct nouveau_channel *,
drivers/gpu/drm/nouveau/nouveau_ttm.c +39 -0
@@ -174,6 +174,38 @@ nouveau_ttm_mmap(struct file *filp, struct vm_area_struct *vma)return ttm_bo_mmap (filp, vma, &drm->ttm.bdev); } +int +nouveau_ttm_global_init (struct nouveau_drm *drm) +{ +struct drm_global_reference *global_ref; +int ret; + + global_ref = &drm->ttm.bo_global_ref.ref; + global_ref->global_type =DRM_GLOBAL_TTM_BO ; + global_ref->size =sizeof (struct ttm_bo_global ); + global_ref->init = &ttm_bo_global_ref_init; + global_ref->release = &ttm_bo_global_ref_release; + + ret =drm_global_item_ref (global_ref); +if (unlikely (ret !=0 )) { +DRM_ERROR ("Failed setting up TTM BO subsystem\n" ); + drm->ttm.bo_global_ref.ref.release =NULL ; +return ret; + } + +return 0 ; +} + +void +nouveau_ttm_global_release (struct nouveau_drm *drm) +{ +if (drm->ttm.bo_global_ref.ref.release ==NULL ) +return ; + +drm_global_item_unref (&drm->ttm.bo_global_ref.ref); + drm->ttm.bo_global_ref.ref.release =NULL ; +} +static int nouveau_ttm_init_host (struct nouveau_drm *drm,u8 kind) {
@@ -236,7 +268,12 @@ nouveau_ttm_init(struct nouveau_drm *drm) drm->agp.cma = pci->agp.cma; } + ret =nouveau_ttm_global_init (drm); +if (ret) +return ret; + ret = ttm_bo_device_init(&drm->ttm.bdev, + drm->ttm.bo_global_ref.ref.object, &nouveau_bo_driver, dev->anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET,
@@ -291,6 +328,8 @@ nouveau_ttm_fini(struct nouveau_drm *drm)ttm_bo_device_release (&drm->ttm.bdev); +nouveau_ttm_global_release (drm); +arch_phys_wc_del (drm->ttm.mtrr); drm->ttm.mtrr =0 ; arch_io_free_memtype_wc(device->func->resource_addr(device, 1),
drivers/gpu/drm/qxl/qxl_drv.h +2 -0
@@ -126,6 +126,8 @@ struct qxl_output {#define drm_encoder_to_qxl_output (x) container_of(x, struct qxl_output, enc)struct qxl_mman { +struct ttm_bo_global_ref bo_global_ref; +bool mem_global_referenced;struct ttm_bo_device bdev; };
drivers/gpu/drm/qxl/qxl_ttm.c +33 -0
@@ -46,6 +46,34 @@ static struct qxl_device *qxl_get_qdev(struct ttm_bo_device *bdev)return qdev; } +static int qxl_ttm_global_init (struct qxl_device *qdev) +{ +struct drm_global_reference *global_ref; +int r; + + global_ref = &qdev->mman.bo_global_ref.ref; + global_ref->global_type =DRM_GLOBAL_TTM_BO ; + global_ref->size =sizeof (struct ttm_bo_global ); + global_ref->init = &ttm_bo_global_ref_init; + global_ref->release = &ttm_bo_global_ref_release; + r =drm_global_item_ref (global_ref); +if (r !=0 ) { +DRM_ERROR ("Failed setting up TTM BO subsystem.\n" ); +return r; + } + + qdev->mman.mem_global_referenced = true; +return 0 ; +} + +static void qxl_ttm_global_fini (struct qxl_device *qdev) +{ +if (qdev->mman.mem_global_referenced) { +drm_global_item_unref (&qdev->mman.bo_global_ref.ref); + qdev->mman.mem_global_referenced = false; + } +} +static struct vm_operations_struct qxl_ttm_vm_ops;static const struct vm_operations_struct *ttm_vm_ops;
@@ -316,8 +344,12 @@ int qxl_ttm_init(struct qxl_device *qdev)int r;int num_io_pages;/* != rom->num_io_pages, we include surface0 */ + r =qxl_ttm_global_init (qdev); +if (r) +return r;/* No others user of address space so set it to 0 */ r =ttm_bo_device_init (&qdev->mman.bdev, + qdev->mman.bo_global_ref.ref.object, &qxl_bo_driver, qdev->ddev.anon_inode->i_mapping,DRM_FILE_PAGE_OFFSET ,0 );
@@ -353,6 +385,7 @@ void qxl_ttm_fini(struct qxl_device *qdev)ttm_bo_clean_mm (&qdev->mman.bdev,TTM_PL_VRAM );ttm_bo_clean_mm (&qdev->mman.bdev,TTM_PL_PRIV );ttm_bo_device_release (&qdev->mman.bdev); +qxl_ttm_global_fini (qdev);DRM_INFO ("qxl: ttm finalized\n" ); }
drivers/gpu/drm/radeon/radeon.h +2 -0
@@ -448,7 +448,9 @@ struct radeon_surface_reg {* TTM. */ struct radeon_mman { +struct ttm_bo_global_ref bo_global_ref;struct ttm_bo_device bdev; +bool mem_global_referenced;bool initialized;#if defined(CONFIG_DEBUG_FS )
drivers/gpu/drm/radeon/radeon_ttm.c +39 -0
@@ -60,6 +60,39 @@ static struct radeon_device *radeon_get_rdev(struct ttm_bo_device *bdev)return rdev; } + +/* +* Global memory. +*/ +static int radeon_ttm_global_init (struct radeon_device *rdev) +{ +struct drm_global_reference *global_ref; +int r; + + rdev->mman.mem_global_referenced = false; + global_ref = &rdev->mman.bo_global_ref.ref; + global_ref->global_type =DRM_GLOBAL_TTM_BO ; + global_ref->size =sizeof (struct ttm_bo_global ); + global_ref->init = &ttm_bo_global_ref_init; + global_ref->release = &ttm_bo_global_ref_release; + r =drm_global_item_ref (global_ref); +if (r !=0 ) { +DRM_ERROR ("Failed setting up TTM BO subsystem.\n" ); +return r; + } + + rdev->mman.mem_global_referenced = true; +return 0 ; +} + +static void radeon_ttm_global_fini (struct radeon_device *rdev) +{ +if (rdev->mman.mem_global_referenced) { +drm_global_item_unref (&rdev->mman.bo_global_ref.ref); + rdev->mman.mem_global_referenced = false; + } +} +static int radeon_invalidate_caches (struct ttm_bo_device *bdev,uint32_t flags) {return 0 ;
@@ -788,8 +821,13 @@ int radeon_ttm_init(struct radeon_device *rdev) {int r; + r =radeon_ttm_global_init (rdev); +if (r) { +return r; + }/* No others user of address space so set it to 0 */ r = ttm_bo_device_init(&rdev->mman.bdev, + rdev->mman.bo_global_ref.ref.object, &radeon_bo_driver, rdev->ddev->anon_inode->i_mapping, DRM_FILE_PAGE_OFFSET,
@@ -861,6 +899,7 @@ void radeon_ttm_fini(struct radeon_device *rdev)ttm_bo_clean_mm (&rdev->mman.bdev,TTM_PL_TT );ttm_bo_device_release (&rdev->mman.bdev);radeon_gart_fini (rdev); +radeon_ttm_global_fini (rdev); rdev->mman.initialized = false;DRM_INFO ("radeon: ttm finalized\n" ); }
drivers/gpu/drm/ttm/ttm_bo.c +7 -12
@@ -1530,7 +1530,7 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj)__free_page (glob->dummy_read_page); } -static void ttm_bo_global_release (void ) +void ttm_bo_global_release (void ) {struct ttm_bo_global *glob = &ttm_bo_glob;
@@ -1544,8 +1544,9 @@ static void ttm_bo_global_release(void) out:mutex_unlock (&ttm_global_mutex); } +EXPORT_SYMBOL (ttm_bo_global_release); -static int ttm_bo_global_init (void ) +int ttm_bo_global_init (void ) {struct ttm_bo_global *glob = &ttm_bo_glob;int ret =0 ;
@@ -1582,6 +1583,8 @@ static int ttm_bo_global_init(void)mutex_unlock (&ttm_global_mutex);return ret; } +EXPORT_SYMBOL (ttm_bo_global_init); +int ttm_bo_device_release (struct ttm_bo_device *bdev) {
@@ -1620,25 +1623,18 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)drm_vma_offset_manager_destroy (&bdev->vma_manager); -if (!ret) -ttm_bo_global_release (); -return ret; }EXPORT_SYMBOL (ttm_bo_device_release);int ttm_bo_device_init (struct ttm_bo_device *bdev, +struct ttm_bo_global *glob,struct ttm_bo_driver *driver,struct address_space *mapping,uint64_t file_page_offset,bool need_dma32) { -struct ttm_bo_global *glob = &ttm_bo_glob; -int ret; - - ret =ttm_bo_global_init (); -if (ret) -return ret; +int ret = -EINVAL ; bdev->driver = driver;
@@ -1665,7 +1661,6 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,return 0 ; out_no_sys: -ttm_bo_global_release ();return ret; }EXPORT_SYMBOL (ttm_bo_device_init);
drivers/gpu/drm/virtio/virtgpu_drv.h +2 -0
@@ -145,6 +145,8 @@ struct virtio_gpu_fbdev { };struct virtio_gpu_mman { +struct ttm_bo_global_ref bo_global_ref; +bool mem_global_referenced;struct ttm_bo_device bdev; };
drivers/gpu/drm/virtio/virtgpu_ttm.c +35 -0
@@ -50,6 +50,35 @@ virtio_gpu_device *virtio_gpu_get_vgdev(struct ttm_bo_device *bdev)return vgdev; } +static int virtio_gpu_ttm_global_init (struct virtio_gpu_device *vgdev) +{ +struct drm_global_reference *global_ref; +int r; + + vgdev->mman.mem_global_referenced = false; + global_ref = &vgdev->mman.bo_global_ref.ref; + global_ref->global_type =DRM_GLOBAL_TTM_BO ; + global_ref->size =sizeof (struct ttm_bo_global ); + global_ref->init = &ttm_bo_global_ref_init; + global_ref->release = &ttm_bo_global_ref_release; + r =drm_global_item_ref (global_ref); +if (r !=0 ) { +DRM_ERROR ("Failed setting up TTM BO subsystem.\n" ); +return r; + } + + vgdev->mman.mem_global_referenced = true; +return 0 ; +} + +static void virtio_gpu_ttm_global_fini (struct virtio_gpu_device *vgdev) +{ +if (vgdev->mman.mem_global_referenced) { +drm_global_item_unref (&vgdev->mman.bo_global_ref.ref); + vgdev->mman.mem_global_referenced = false; + } +} +int virtio_gpu_mmap (struct file *filp,struct vm_area_struct *vma) {struct drm_file *file_priv;
@@ -326,8 +355,12 @@ int virtio_gpu_ttm_init(struct virtio_gpu_device *vgdev) {int r; + r =virtio_gpu_ttm_global_init (vgdev); +if (r) +return r;/* No others user of address space so set it to 0 */ r =ttm_bo_device_init (&vgdev->mman.bdev, + vgdev->mman.bo_global_ref.ref.object, &virtio_gpu_bo_driver, vgdev->ddev->anon_inode->i_mapping,DRM_FILE_PAGE_OFFSET ,0 );
@@ -346,11 +379,13 @@ int virtio_gpu_ttm_init(struct virtio_gpu_device *vgdev) err_mm_init:ttm_bo_device_release (&vgdev->mman.bdev); err_dev_init: +virtio_gpu_ttm_global_fini (vgdev);return r; }void virtio_gpu_ttm_fini (struct virtio_gpu_device *vgdev) {ttm_bo_device_release (&vgdev->mman.bdev); +virtio_gpu_ttm_global_fini (vgdev);DRM_INFO ("virtio_gpu: ttm finalized\n" ); }
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +10 -1
@@ -785,6 +785,11 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)DRM_INFO ("MMIO at 0x%08x size is %u kiB\n" , dev_priv->mmio_start, dev_priv->mmio_size /1024 ); + ret =vmw_ttm_global_init (dev_priv); +if (unlikely (ret !=0 )) + goto out_err0; + +vmw_master_init (&dev_priv->fbdev_master);ttm_lock_set_kill (&dev_priv->fbdev_master.lock, false,SIGTERM ); dev_priv->active_master = &dev_priv->fbdev_master;
@@ -795,7 +800,7 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)if (unlikely (dev_priv->mmio_virt ==NULL )) { ret = -ENOMEM ;DRM_ERROR ("Failed mapping MMIO.\n" ); - goto out_err0; + goto out_err3; }/* Need mmio memory to check for fifo pitchlock cap. */
@@ -849,6 +854,7 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset) } ret = ttm_bo_device_init(&dev_priv->bdev, + dev_priv->bo_global_ref.ref.object, &vmw_bo_driver, dev->anon_inode->i_mapping, VMWGFX_FILE_PAGE_OFFSET,
@@ -970,6 +976,8 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)ttm_object_device_release (&dev_priv->tdev); out_err4:memunmap (dev_priv->mmio_virt); +out_err3: +vmw_ttm_global_release (dev_priv); out_err0:for (i = vmw_res_context; i < vmw_res_max; ++i)idr_destroy (&dev_priv->res_idr[i]);
@@ -1021,6 +1029,7 @@ static void vmw_driver_unload(struct drm_device *dev)memunmap (dev_priv->mmio_virt);if (dev_priv->ctx.staged_bindings)vmw_binding_state_free (dev_priv->ctx.staged_bindings); +vmw_ttm_global_release (dev_priv);for (i = vmw_res_context; i < vmw_res_max; ++i)idr_destroy (&dev_priv->res_idr[i]);
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +3 -0
@@ -417,6 +417,7 @@ enum {struct vmw_private {struct ttm_bo_device bdev; +struct ttm_bo_global_ref bo_global_ref;struct vmw_fifo_state fifo;
@@ -832,6 +833,8 @@ extern int vmw_fifo_flush(struct vmw_private *dev_priv,* TTM glue - vmwgfx_ttm_glue.c */ +extern int vmw_ttm_global_init (struct vmw_private *dev_priv); +extern void vmw_ttm_global_release (struct vmw_private *dev_priv);extern int vmw_mmap (struct file *filp,struct vm_area_struct *vma); extern void vmw_validation_mem_init_ttm(struct vmw_private *dev_priv,
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +27 -0
@@ -78,3 +78,30 @@ void vmw_validation_mem_init_ttm(struct vmw_private *dev_priv, size_t gran) vvm->unreserve_mem = vmw_vmt_unreserve; vvm->gran = gran; } + +int vmw_ttm_global_init (struct vmw_private *dev_priv) +{ +struct drm_global_reference *global_ref; +int ret; + + global_ref = &dev_priv->bo_global_ref.ref; + global_ref->global_type =DRM_GLOBAL_TTM_BO ; + global_ref->size =sizeof (struct ttm_bo_global ); + global_ref->init = &ttm_bo_global_ref_init; + global_ref->release = &ttm_bo_global_ref_release; + ret =drm_global_item_ref (global_ref); + +if (unlikely (ret !=0 )) { +DRM_ERROR ("Failed setting up TTM buffer objects.\n" ); + goto out_no_bo; + } + +return 0 ; +out_no_bo: +return ret; +} + +void vmw_ttm_global_release (struct vmw_private *dev_priv) +{ +drm_global_item_unref (&dev_priv->bo_global_ref.ref); +}
drivers/staging/vboxvideo/vbox_drv.h +1 -0
@@ -79,6 +79,7 @@ struct vbox_private {int fb_mtrr;struct { +struct ttm_bo_global_ref bo_global_ref;struct ttm_bo_device bdev; } ttm;
drivers/staging/vboxvideo/vbox_ttm.c +40 -1
71 lines not on this page · raw message
include/drm/ttm/ttm_bo_driver.h +40 -1
57 lines not on this page · raw message
Signature · 6 lines
2.20.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 3/6 Revert "drm/ttm: Fix bo_global and mem_global kfree error"
In reply to Karol HerbstThis reverts commit 30f33126feca0fe16df9e9302ffc28a953e2eb37.
--- drivers/gpu/drm/ttm/ttm_bo.c | 1 + drivers/gpu/drm/ttm/ttm_memory.c | 9 +++++++++ 2 files changed, 10 insertions(+)
drivers/gpu/drm/ttm/ttm_bo.c +1 -0
@@ -1528,6 +1528,7 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj) container_of(kobj, struct ttm_bo_global, kobj);__free_page (glob->dummy_read_page); +kfree (glob); }void ttm_bo_global_release (void )
drivers/gpu/drm/ttm/ttm_memory.c +9 -0
@@ -219,6 +219,14 @@ static ssize_t ttm_mem_global_store(struct kobject *kobj,return size; } +static void ttm_mem_global_kobj_release (struct kobject *kobj) +{ +struct ttm_mem_global *glob = + container_of(kobj, struct ttm_mem_global, kobj); + +kfree (glob); +} +static struct attribute *ttm_mem_global_attrs[] = { &ttm_mem_global_lower_mem_limit,NULL
@@ -230,6 +238,7 @@ static const struct sysfs_ops ttm_mem_global_ops = { };static struct kobj_type ttm_mem_glob_kobj_type = { + .release = &ttm_mem_global_kobj_release, .sysfs_ops = &ttm_mem_global_ops, .default_attrs = ttm_mem_global_attrs, };
Signature · 6 lines
2.20.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 4/6 Revert "drm/ttm: use a static ttm_bo_global instance"
In reply to Karol HerbstThis reverts commit 62b53b37e4b1500d4eb4624a44ad861cf8d3cd18.
--- drivers/gpu/drm/ttm/ttm_bo.c | 31 ++++++++----------------------- include/drm/ttm/ttm_bo_driver.h | 15 +++++++-------- 2 files changed, 15 insertions(+), 31 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +8 -23
@@ -49,9 +49,6 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj);* ttm_global_mutex - protecting the global BO state */ DEFINE_MUTEX (ttm_global_mutex); -struct ttm_bo_global ttm_bo_glob = { - .use_count =0 -};static struct attribute ttm_bo_count = { .name ="bo_count" ,
@@ -1531,35 +1528,22 @@ static void ttm_bo_global_kobj_release(struct kobject *kobj)kfree (glob); } -void ttm_bo_global_release (void ) +void ttm_bo_global_release (struct ttm_bo_global *glob) { -struct ttm_bo_global *glob = &ttm_bo_glob; - -mutex_lock (&ttm_global_mutex); -if (--glob->use_count >0 ) - goto out; -kobject_del (&glob->kobj);kobject_put (&glob->kobj);ttm_mem_global_release (&ttm_mem_glob); -out: -mutex_unlock (&ttm_global_mutex); }EXPORT_SYMBOL (ttm_bo_global_release); -int ttm_bo_global_init (void ) +int ttm_bo_global_init (struct ttm_bo_global *glob) { -struct ttm_bo_global *glob = &ttm_bo_glob; -int ret =0 ; +int ret;unsigned i; -mutex_lock (&ttm_global_mutex); -if (++glob->use_count >1 ) - goto out; - ret =ttm_mem_global_init (&ttm_mem_glob);if (ret) - goto out; +return ret;spin_lock_init (&glob->lru_lock); glob->mem_glob = &ttm_mem_glob;
@@ -1568,7 +1552,7 @@ int ttm_bo_global_init(void)if (unlikely (glob->dummy_read_page ==NULL )) { ret = -ENOMEM ; - goto out; + goto out_no_drp; }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i)
@@ -1580,8 +1564,9 @@ int ttm_bo_global_init(void) &glob->kobj, &ttm_bo_glob_kobj_type, ttm_get_kobj(), "buffer_objects");if (unlikely (ret !=0 ))kobject_put (&glob->kobj); -out: -mutex_unlock (&ttm_global_mutex); +return ret; +out_no_drp: +kfree (glob);return ret; }EXPORT_SYMBOL (ttm_bo_global_init);
include/drm/ttm/ttm_bo_driver.h +7 -8
@@ -398,7 +398,7 @@ struct ttm_bo_driver {* @swap_lru: Lru list of buffer objects used for swapping. */ -extern struct ttm_bo_global { +struct ttm_bo_global {/** * Constant after init.
@@ -410,9 +410,8 @@ extern struct ttm_bo_global {spinlock_t lru_lock;/** -* Protected by ttm_global_mutex. +* Protected by device_list_mutex. */ -unsigned int use_count;struct list_head device_list;/**
@@ -424,7 +423,7 @@ extern struct ttm_bo_global {* Internal protection. */ atomic_t bo_count; -} ttm_bo_glob; +};#define TTM_NUM_MEM_TYPES 8
@@ -569,8 +568,8 @@ void ttm_bo_mem_put(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem);void ttm_bo_mem_put_locked (struct ttm_buffer_object *bo,struct ttm_mem_reg *mem); -void ttm_bo_global_release (void ); -int ttm_bo_global_init (void ); +void ttm_bo_global_release (struct ttm_bo_global *glob); +int ttm_bo_global_init (struct ttm_bo_global *glob);int ttm_bo_device_release (struct ttm_bo_device *bdev);
@@ -907,7 +906,7 @@ struct ttm_bo_global_ref {*/ static inline int ttm_bo_global_ref_init (struct drm_global_reference *ref) { -return ttm_bo_global_init (); +return ttm_bo_global_init (ref->object); }/**
@@ -921,7 +920,7 @@ static inline int ttm_bo_global_ref_init(struct drm_global_reference *ref)*/ static inline void ttm_bo_global_ref_release (struct drm_global_reference *ref) { -ttm_bo_global_release (); +ttm_bo_global_release (ref->object); }#endif
Signature · 6 lines
2.20.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 5/6 Revert "drm/ttm: make the device list mutex static"
In reply to Karol HerbstThis reverts commit 56b3d20413587fab6a790cfc8bc075ca94bc8ed9.
--- drivers/gpu/drm/ttm/ttm_bo.c | 14 +++++--------- include/drm/ttm/ttm_bo_driver.h | 1 + 2 files changed, 6 insertions(+), 9 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +5 -9
@@ -45,11 +45,6 @@static void ttm_bo_global_kobj_release (struct kobject *kobj); -/** -* ttm_global_mutex - protecting the global BO state -*/ -DEFINE_MUTEX (ttm_global_mutex); -static struct attribute ttm_bo_count = { .name ="bo_count" , .mode =S_IRUGO
@@ -1545,6 +1540,7 @@ int ttm_bo_global_init(struct ttm_bo_global *glob)if (ret)return ret; +mutex_init (&glob->device_list_mutex);spin_lock_init (&glob->lru_lock); glob->mem_glob = &ttm_mem_glob; glob->mem_glob->bo_glob = glob;
@@ -1592,9 +1588,9 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev) } } -mutex_lock (&ttm_global_mutex); +mutex_lock (&glob->device_list_mutex);list_del (&bdev->device_list); -mutex_unlock (&ttm_global_mutex); +mutex_unlock (&glob->device_list_mutex);cancel_delayed_work_sync (&bdev->wq);
@@ -1641,9 +1637,9 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev, bdev->dev_mapping = mapping; bdev->glob = glob; bdev->need_dma32 = need_dma32; -mutex_lock (&ttm_global_mutex); +mutex_lock (&glob->device_list_mutex);list_add_tail (&bdev->device_list, &glob->device_list); -mutex_unlock (&ttm_global_mutex); +mutex_unlock (&glob->device_list_mutex);return 0 ; out_no_sys:
include/drm/ttm/ttm_bo_driver.h +1 -0
@@ -407,6 +407,7 @@ struct ttm_bo_global {struct kobject kobj;struct ttm_mem_global *mem_glob;struct page *dummy_read_page; +struct mutex device_list_mutex;spinlock_t lru_lock;/**
Signature · 6 lines
2.20.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 6/6 Revert "drm/ttm: use a static ttm_mem_global instance"
In reply to Karol HerbstThis reverts commit 27eb1fa9130a98edd2b321d4dbce5c8b244ee7af.
--- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 44 +++++++++++++++++++ drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 1 + drivers/gpu/drm/ast/ast_drv.h | 1 + drivers/gpu/drm/ast/ast_ttm.c | 32 +++++++++++++- drivers/gpu/drm/bochs/bochs.h | 1 + drivers/gpu/drm/bochs/bochs_mm.c | 30 ++++++++++++- drivers/gpu/drm/cirrus/cirrus_drv.h | 1 + drivers/gpu/drm/cirrus/cirrus_ttm.c | 32 +++++++++++++- .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 1 + drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 31 +++++++++++-- drivers/gpu/drm/mgag200/mgag200_drv.h | 1 + drivers/gpu/drm/mgag200/mgag200_ttm.c | 32 +++++++++++++- drivers/gpu/drm/nouveau/nouveau_drv.h | 1 + drivers/gpu/drm/nouveau/nouveau_ttm.c | 34 ++++++++++++-- drivers/gpu/drm/qxl/qxl_drv.h | 1 + drivers/gpu/drm/qxl/qxl_ttm.c | 28 ++++++++++++ drivers/gpu/drm/radeon/radeon.h | 1 + drivers/gpu/drm/radeon/radeon_ttm.c | 26 +++++++++++ drivers/gpu/drm/ttm/ttm_bo.c | 10 ++--- drivers/gpu/drm/ttm/ttm_memory.c | 5 +-- drivers/gpu/drm/virtio/virtgpu_drv.h | 1 + drivers/gpu/drm/virtio/virtgpu_ttm.c | 27 ++++++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 4 +- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 3 +- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 27 ++++++++++++ drivers/staging/vboxvideo/vbox_drv.h | 1 + drivers/staging/vboxvideo/vbox_ttm.c | 24 ++++++++++ include/drm/ttm/ttm_bo_driver.h | 8 +++- include/drm/ttm/ttm_memory.h | 4 +- 29 files changed, 380 insertions(+), 32 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +44 -0
@@ -65,6 +65,33 @@ static void amdgpu_ttm_debugfs_fini(struct amdgpu_device *adev);* Global memory. */ +/** +* amdgpu_ttm_mem_global_init - Initialize and acquire reference to +* memory object +* +* @ref: Object for initialization. +* +* This is called by drm_global_item_ref() when an object is being +* initialized. +*/ +static int amdgpu_ttm_mem_global_init (struct drm_global_reference *ref) +{ +return ttm_mem_global_init (ref->object); +} + +/** +* amdgpu_ttm_mem_global_release - Drop reference to a memory object +* +* @ref: Object being removed +* +* This is called by drm_global_item_unref() when an object is being +* released. +*/ +static void amdgpu_ttm_mem_global_release (struct drm_global_reference *ref) +{ +ttm_mem_global_release (ref->object); +} +/** * amdgpu_ttm_global_init - Initialize global TTM memory reference structures. *
@@ -81,6 +108,20 @@ static int amdgpu_ttm_global_init(struct amdgpu_device *adev)/* ensure reference is false in case init fails */ adev->mman.mem_global_referenced = false; + global_ref = &adev->mman.mem_global_ref; + global_ref->global_type =DRM_GLOBAL_TTM_MEM ; + global_ref->size =sizeof (struct ttm_mem_global ); + global_ref->init = &amdgpu_ttm_mem_global_init; + global_ref->release = &amdgpu_ttm_mem_global_release; + r =drm_global_item_ref (global_ref); +if (r) { +DRM_ERROR ("Failed setting up TTM memory accounting " +"subsystem.\n" ); + goto error_mem; + } + + adev->mman.bo_global_ref.mem_glob = + adev->mman.mem_global_ref.object; global_ref = &adev->mman.bo_global_ref.ref; global_ref->global_type =DRM_GLOBAL_TTM_BO ; global_ref->size =sizeof (struct ttm_bo_global );
@@ -99,6 +140,8 @@ static int amdgpu_ttm_global_init(struct amdgpu_device *adev)return 0 ; error_bo: +drm_global_item_unref (&adev->mman.mem_global_ref); +error_mem:return r; }
@@ -107,6 +150,7 @@ static void amdgpu_ttm_global_fini(struct amdgpu_device *adev)if (adev->mman.mem_global_referenced) {mutex_destroy (&adev->mman.gtt_window_lock);drm_global_item_unref (&adev->mman.bo_global_ref.ref); +drm_global_item_unref (&adev->mman.mem_global_ref); adev->mman.mem_global_referenced = false; } }
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h +1 -0
@@ -40,6 +40,7 @@struct amdgpu_mman {struct ttm_bo_global_ref bo_global_ref; +struct drm_global_reference mem_global_ref;struct ttm_bo_device bdev;bool mem_global_referenced;bool initialized;
drivers/gpu/drm/ast/ast_drv.h +1 -0
@@ -104,6 +104,7 @@ struct ast_private {int fb_mtrr;struct { +struct drm_global_reference mem_global_ref;struct ttm_bo_global_ref bo_global_ref;struct ttm_bo_device bdev; } ttm;
drivers/gpu/drm/ast/ast_ttm.c +30 -2
@@ -36,11 +36,37 @@ ast_bdev(struct ttm_bo_device *bd) return container_of(bd, struct ast_private, ttm.bdev); } +static int +ast_ttm_mem_global_init (struct drm_global_reference *ref) +{ +return ttm_mem_global_init (ref->object); +} + +static void +ast_ttm_mem_global_release (struct drm_global_reference *ref) +{ +ttm_mem_global_release (ref->object); +} +static int ast_ttm_global_init (struct ast_private *ast) {struct drm_global_reference *global_ref;int r; + global_ref = &ast->ttm.mem_global_ref; + global_ref->global_type =DRM_GLOBAL_TTM_MEM ; + global_ref->size =sizeof (struct ttm_mem_global ); + global_ref->init = &ast_ttm_mem_global_init; + global_ref->release = &ast_ttm_mem_global_release; + r =drm_global_item_ref (global_ref); +if (r !=0 ) { +DRM_ERROR ("Failed setting up TTM memory accounting " +"subsystem.\n" ); +return r; + } + + ast->ttm.bo_global_ref.mem_glob = + ast->ttm.mem_global_ref.object; global_ref = &ast->ttm.bo_global_ref.ref; global_ref->global_type =DRM_GLOBAL_TTM_BO ; global_ref->size =sizeof (struct ttm_bo_global );
@@ -49,6 +75,7 @@ static int ast_ttm_global_init(struct ast_private *ast) r =drm_global_item_ref (global_ref);if (r !=0 ) {DRM_ERROR ("Failed setting up TTM BO subsystem.\n" ); +drm_global_item_unref (&ast->ttm.mem_global_ref);return r; }return 0 ;
@@ -57,11 +84,12 @@ static int ast_ttm_global_init(struct ast_private *ast)static void ast_ttm_global_release (struct ast_private *ast) { -if (ast->ttm.bo_global_ref.ref.release ==NULL ) +if (ast->ttm.mem_global_ref.release ==NULL )return ;drm_global_item_unref (&ast->ttm.bo_global_ref.ref); - ast->ttm.bo_global_ref.ref.release =NULL ; +drm_global_item_unref (&ast->ttm.mem_global_ref); + ast->ttm.mem_global_ref.release =NULL ; }
drivers/gpu/drm/bochs/bochs.h +1 -0
@@ -77,6 +77,7 @@ struct bochs_device {/* ttm */ struct { +struct drm_global_reference mem_global_ref;struct ttm_bo_global_ref bo_global_ref;struct ttm_bo_device bdev;bool initialized;
drivers/gpu/drm/bochs/bochs_mm.c +28 -2
@@ -16,11 +16,35 @@ static inline struct bochs_device *bochs_bdev(struct ttm_bo_device *bd) return container_of(bd, struct bochs_device, ttm.bdev); } +static int bochs_ttm_mem_global_init (struct drm_global_reference *ref) +{ +return ttm_mem_global_init (ref->object); +} + +static void bochs_ttm_mem_global_release (struct drm_global_reference *ref) +{ +ttm_mem_global_release (ref->object); +} +static int bochs_ttm_global_init (struct bochs_device *bochs) {struct drm_global_reference *global_ref;int r; + global_ref = &bochs->ttm.mem_global_ref; + global_ref->global_type =DRM_GLOBAL_TTM_MEM ; + global_ref->size =sizeof (struct ttm_mem_global ); + global_ref->init = &bochs_ttm_mem_global_init; + global_ref->release = &bochs_ttm_mem_global_release; + r =drm_global_item_ref (global_ref); +if (r !=0 ) { +DRM_ERROR ("Failed setting up TTM memory accounting " +"subsystem.\n" ); +return r; + } + + bochs->ttm.bo_global_ref.mem_glob = + bochs->ttm.mem_global_ref.object; global_ref = &bochs->ttm.bo_global_ref.ref; global_ref->global_type =DRM_GLOBAL_TTM_BO ; global_ref->size =sizeof (struct ttm_bo_global );
@@ -29,6 +53,7 @@ static int bochs_ttm_global_init(struct bochs_device *bochs) r =drm_global_item_ref (global_ref);if (r !=0 ) {DRM_ERROR ("Failed setting up TTM BO subsystem.\n" ); +drm_global_item_unref (&bochs->ttm.mem_global_ref);return r; }
@@ -37,11 +62,12 @@ static int bochs_ttm_global_init(struct bochs_device *bochs)static void bochs_ttm_global_release (struct bochs_device *bochs) { -if (bochs->ttm.bo_global_ref.ref.release ==NULL ) +if (bochs->ttm.mem_global_ref.release ==NULL )return ;drm_global_item_unref (&bochs->ttm.bo_global_ref.ref); - bochs->ttm.bo_global_ref.ref.release =NULL ; +drm_global_item_unref (&bochs->ttm.mem_global_ref); + bochs->ttm.mem_global_ref.release =NULL ; }
drivers/gpu/drm/cirrus/cirrus_drv.h +1 -0
@@ -136,6 +136,7 @@ struct cirrus_device {int fb_mtrr;struct { +struct drm_global_reference mem_global_ref;struct ttm_bo_global_ref bo_global_ref;struct ttm_bo_device bdev; } ttm;
drivers/gpu/drm/cirrus/cirrus_ttm.c +30 -2
@@ -36,11 +36,37 @@ cirrus_bdev(struct ttm_bo_device *bd) return container_of(bd, struct cirrus_device, ttm.bdev); } +static int +cirrus_ttm_mem_global_init (struct drm_global_reference *ref) +{ +return ttm_mem_global_init (ref->object); +} + +static void +cirrus_ttm_mem_global_release (struct drm_global_reference *ref) +{ +ttm_mem_global_release (ref->object); +} +static int cirrus_ttm_global_init (struct cirrus_device *cirrus) {struct drm_global_reference *global_ref;int r; + global_ref = &cirrus->ttm.mem_global_ref; + global_ref->global_type =DRM_GLOBAL_TTM_MEM ; + global_ref->size =sizeof (struct ttm_mem_global ); + global_ref->init = &cirrus_ttm_mem_global_init; + global_ref->release = &cirrus_ttm_mem_global_release; + r =drm_global_item_ref (global_ref); +if (r !=0 ) { +DRM_ERROR ("Failed setting up TTM memory accounting " +"subsystem.\n" ); +return r; + } + + cirrus->ttm.bo_global_ref.mem_glob = + cirrus->ttm.mem_global_ref.object; global_ref = &cirrus->ttm.bo_global_ref.ref; global_ref->global_type =DRM_GLOBAL_TTM_BO ; global_ref->size =sizeof (struct ttm_bo_global );
@@ -49,6 +75,7 @@ static int cirrus_ttm_global_init(struct cirrus_device *cirrus) r =drm_global_item_ref (global_ref);if (r !=0 ) {DRM_ERROR ("Failed setting up TTM BO subsystem.\n" ); +drm_global_item_unref (&cirrus->ttm.mem_global_ref);return r; }return 0 ;
@@ -57,11 +84,12 @@ static int cirrus_ttm_global_init(struct cirrus_device *cirrus)static void cirrus_ttm_global_release (struct cirrus_device *cirrus) { -if (cirrus->ttm.bo_global_ref.ref.release ==NULL ) +if (cirrus->ttm.mem_global_ref.release ==NULL )return ;drm_global_item_unref (&cirrus->ttm.bo_global_ref.ref); - cirrus->ttm.bo_global_ref.ref.release =NULL ; +drm_global_item_unref (&cirrus->ttm.mem_global_ref); + cirrus->ttm.mem_global_ref.release =NULL ; }
drivers/gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h +1 -0
@@ -49,6 +49,7 @@ struct hibmc_drm_private {bool mode_config_initialized;/* ttm */ +struct drm_global_reference mem_global_ref;struct ttm_bo_global_ref bo_global_ref;struct ttm_bo_device bdev;bool initialized;
drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c +27 -4
@@ -29,10 +29,34 @@ hibmc_bdev(struct ttm_bo_device *bd) return container_of(bd, struct hibmc_drm_private, bdev); } +static int +hibmc_ttm_mem_global_init (struct drm_global_reference *ref) +{ +return ttm_mem_global_init (ref->object); +} + +static void +hibmc_ttm_mem_global_release (struct drm_global_reference *ref) +{ +ttm_mem_global_release (ref->object); +} +static int hibmc_ttm_global_init (struct hibmc_drm_private *hibmc) {int ret; + hibmc->mem_global_ref.global_type =DRM_GLOBAL_TTM_MEM ; + hibmc->mem_global_ref.size =sizeof (struct ttm_mem_global ); + hibmc->mem_global_ref.init = &hibmc_ttm_mem_global_init; + hibmc->mem_global_ref.release = &hibmc_ttm_mem_global_release; + ret =drm_global_item_ref (&hibmc->mem_global_ref); +if (ret) { +DRM_ERROR ("could not get ref on ttm global: %d\n" , ret); +return ret; + } + + hibmc->bo_global_ref.mem_glob = + hibmc->mem_global_ref.object; hibmc->bo_global_ref.ref.global_type =DRM_GLOBAL_TTM_BO ; hibmc->bo_global_ref.ref.size =sizeof (struct ttm_bo_global ); hibmc->bo_global_ref.ref.init = &ttm_bo_global_ref_init;
@@ -40,6 +64,7 @@ static int hibmc_ttm_global_init(struct hibmc_drm_private *hibmc) ret =drm_global_item_ref (&hibmc->bo_global_ref.ref);if (ret) {DRM_ERROR ("failed setting up TTM BO subsystem: %d\n" , ret); +drm_global_item_unref (&hibmc->mem_global_ref);return ret; }return 0 ;
@@ -48,11 +73,9 @@ static int hibmc_ttm_global_init(struct hibmc_drm_private *hibmc)static void hibmc_ttm_global_release (struct hibmc_drm_private *hibmc) { -if (hibmc->bo_global_ref.ref.release ==NULL ) -return ; -drm_global_item_unref (&hibmc->bo_global_ref.ref); - hibmc->bo_global_ref.ref.release =NULL ; +drm_global_item_unref (&hibmc->mem_global_ref); + hibmc->mem_global_ref.release =NULL ; }static void hibmc_bo_ttm_destroy (struct ttm_buffer_object *tbo)
drivers/gpu/drm/mgag200/mgag200_drv.h +1 -0
@@ -212,6 +212,7 @@ struct mga_device {int fb_mtrr;struct { +struct drm_global_reference mem_global_ref;struct ttm_bo_global_ref bo_global_ref;struct ttm_bo_device bdev; } ttm;
drivers/gpu/drm/mgag200/mgag200_ttm.c +30 -2
@@ -36,11 +36,37 @@ mgag200_bdev(struct ttm_bo_device *bd) return container_of(bd, struct mga_device, ttm.bdev); } +static int +mgag200_ttm_mem_global_init (struct drm_global_reference *ref) +{ +return ttm_mem_global_init (ref->object); +} + +static void +mgag200_ttm_mem_global_release (struct drm_global_reference *ref) +{ +ttm_mem_global_release (ref->object); +} +static int mgag200_ttm_global_init (struct mga_device *ast) {struct drm_global_reference *global_ref;int r; + global_ref = &ast->ttm.mem_global_ref; + global_ref->global_type =DRM_GLOBAL_TTM_MEM ; + global_ref->size =sizeof (struct ttm_mem_global ); + global_ref->init = &mgag200_ttm_mem_global_init; + global_ref->release = &mgag200_ttm_mem_global_release; + r =drm_global_item_ref (global_ref); +if (r !=0 ) { +DRM_ERROR ("Failed setting up TTM memory accounting " +"subsystem.\n" ); +return r; + } + + ast->ttm.bo_global_ref.mem_glob = + ast->ttm.mem_global_ref.object; global_ref = &ast->ttm.bo_global_ref.ref; global_ref->global_type =DRM_GLOBAL_TTM_BO ; global_ref->size =sizeof (struct ttm_bo_global );
@@ -49,6 +75,7 @@ static int mgag200_ttm_global_init(struct mga_device *ast) r =drm_global_item_ref (global_ref);if (r !=0 ) {DRM_ERROR ("Failed setting up TTM BO subsystem.\n" ); +drm_global_item_unref (&ast->ttm.mem_global_ref);return r; }return 0 ;
@@ -57,11 +84,12 @@ static int mgag200_ttm_global_init(struct mga_device *ast)static void mgag200_ttm_global_release (struct mga_device *ast) { -if (ast->ttm.bo_global_ref.ref.release ==NULL ) +if (ast->ttm.mem_global_ref.release ==NULL )return ;drm_global_item_unref (&ast->ttm.bo_global_ref.ref); - ast->ttm.bo_global_ref.ref.release =NULL ; +drm_global_item_unref (&ast->ttm.mem_global_ref); + ast->ttm.mem_global_ref.release =NULL ; }
drivers/gpu/drm/nouveau/nouveau_drv.h +1 -0
@@ -146,6 +146,7 @@ struct nouveau_drm {/* TTM interface support */ struct { +struct drm_global_reference mem_global_ref;struct ttm_bo_global_ref bo_global_ref;struct ttm_bo_device bdev;atomic_t validate_sequence;
drivers/gpu/drm/nouveau/nouveau_ttm.c +31 -3
@@ -174,12 +174,38 @@ nouveau_ttm_mmap(struct file *filp, struct vm_area_struct *vma)return ttm_bo_mmap (filp, vma, &drm->ttm.bdev); } +static int +nouveau_ttm_mem_global_init (struct drm_global_reference *ref) +{ +return ttm_mem_global_init (ref->object); +} + +static void +nouveau_ttm_mem_global_release (struct drm_global_reference *ref) +{ +ttm_mem_global_release (ref->object); +} +int nouveau_ttm_global_init (struct nouveau_drm *drm) {struct drm_global_reference *global_ref;int ret; + global_ref = &drm->ttm.mem_global_ref; + global_ref->global_type =DRM_GLOBAL_TTM_MEM ; + global_ref->size =sizeof (struct ttm_mem_global ); + global_ref->init = &nouveau_ttm_mem_global_init; + global_ref->release = &nouveau_ttm_mem_global_release; + + ret =drm_global_item_ref (global_ref); +if (unlikely (ret !=0 )) { +DRM_ERROR ("Failed setting up TTM memory accounting\n" ); + drm->ttm.mem_global_ref.release =NULL ; +return ret; + } + + drm->ttm.bo_global_ref.mem_glob = global_ref->object; global_ref = &drm->ttm.bo_global_ref.ref; global_ref->global_type =DRM_GLOBAL_TTM_BO ; global_ref->size =sizeof (struct ttm_bo_global );
@@ -189,7 +215,8 @@ nouveau_ttm_global_init(struct nouveau_drm *drm) ret =drm_global_item_ref (global_ref);if (unlikely (ret !=0 )) {DRM_ERROR ("Failed setting up TTM BO subsystem\n" ); - drm->ttm.bo_global_ref.ref.release =NULL ; +drm_global_item_unref (&drm->ttm.mem_global_ref); + drm->ttm.mem_global_ref.release =NULL ;return ret; }
@@ -199,11 +226,12 @@ nouveau_ttm_global_init(struct nouveau_drm *drm)void nouveau_ttm_global_release (struct nouveau_drm *drm) { -if (drm->ttm.bo_global_ref.ref.release ==NULL ) +if (drm->ttm.mem_global_ref.release ==NULL )return ;drm_global_item_unref (&drm->ttm.bo_global_ref.ref); - drm->ttm.bo_global_ref.ref.release =NULL ; +drm_global_item_unref (&drm->ttm.mem_global_ref); + drm->ttm.mem_global_ref.release =NULL ; } static int
drivers/gpu/drm/qxl/qxl_drv.h +1 -0
@@ -127,6 +127,7 @@ struct qxl_output {struct qxl_mman {struct ttm_bo_global_ref bo_global_ref; +struct drm_global_reference mem_global_ref;bool mem_global_referenced;struct ttm_bo_device bdev; };
drivers/gpu/drm/qxl/qxl_ttm.c +28 -0
@@ -46,11 +46,37 @@ static struct qxl_device *qxl_get_qdev(struct ttm_bo_device *bdev)return qdev; } +static int qxl_ttm_mem_global_init (struct drm_global_reference *ref) +{ +return ttm_mem_global_init (ref->object); +} + +static void qxl_ttm_mem_global_release (struct drm_global_reference *ref) +{ +ttm_mem_global_release (ref->object); +} +static int qxl_ttm_global_init (struct qxl_device *qdev) {struct drm_global_reference *global_ref;int r; + qdev->mman.mem_global_referenced = false; + global_ref = &qdev->mman.mem_global_ref; + global_ref->global_type =DRM_GLOBAL_TTM_MEM ; + global_ref->size =sizeof (struct ttm_mem_global ); + global_ref->init = &qxl_ttm_mem_global_init; + global_ref->release = &qxl_ttm_mem_global_release; + + r =drm_global_item_ref (global_ref); +if (r !=0 ) { +DRM_ERROR ("Failed setting up TTM memory accounting " +"subsystem.\n" ); +return r; + } + + qdev->mman.bo_global_ref.mem_glob = + qdev->mman.mem_global_ref.object; global_ref = &qdev->mman.bo_global_ref.ref; global_ref->global_type =DRM_GLOBAL_TTM_BO ; global_ref->size =sizeof (struct ttm_bo_global );
@@ -59,6 +85,7 @@ static int qxl_ttm_global_init(struct qxl_device *qdev) r =drm_global_item_ref (global_ref);if (r !=0 ) {DRM_ERROR ("Failed setting up TTM BO subsystem.\n" ); +drm_global_item_unref (&qdev->mman.mem_global_ref);return r; }
@@ -70,6 +97,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev) {if (qdev->mman.mem_global_referenced) {drm_global_item_unref (&qdev->mman.bo_global_ref.ref); +drm_global_item_unref (&qdev->mman.mem_global_ref); qdev->mman.mem_global_referenced = false; } }
drivers/gpu/drm/radeon/radeon.h +1 -0
@@ -449,6 +449,7 @@ struct radeon_surface_reg {*/ struct radeon_mman {struct ttm_bo_global_ref bo_global_ref; +struct drm_global_reference mem_global_ref;struct ttm_bo_device bdev;bool mem_global_referenced;bool initialized;
drivers/gpu/drm/radeon/radeon_ttm.c +26 -0
@@ -64,12 +64,36 @@ static struct radeon_device *radeon_get_rdev(struct ttm_bo_device *bdev)/* * Global memory. */ +static int radeon_ttm_mem_global_init (struct drm_global_reference *ref) +{ +return ttm_mem_global_init (ref->object); +} + +static void radeon_ttm_mem_global_release (struct drm_global_reference *ref) +{ +ttm_mem_global_release (ref->object); +} +static int radeon_ttm_global_init (struct radeon_device *rdev) {struct drm_global_reference *global_ref;int r; rdev->mman.mem_global_referenced = false; + global_ref = &rdev->mman.mem_global_ref; + global_ref->global_type =DRM_GLOBAL_TTM_MEM ; + global_ref->size =sizeof (struct ttm_mem_global ); + global_ref->init = &radeon_ttm_mem_global_init; + global_ref->release = &radeon_ttm_mem_global_release; + r =drm_global_item_ref (global_ref); +if (r !=0 ) { +DRM_ERROR ("Failed setting up TTM memory accounting " +"subsystem.\n" ); +return r; + } + + rdev->mman.bo_global_ref.mem_glob = + rdev->mman.mem_global_ref.object; global_ref = &rdev->mman.bo_global_ref.ref; global_ref->global_type =DRM_GLOBAL_TTM_BO ; global_ref->size =sizeof (struct ttm_bo_global );
@@ -78,6 +102,7 @@ static int radeon_ttm_global_init(struct radeon_device *rdev) r =drm_global_item_ref (global_ref);if (r !=0 ) {DRM_ERROR ("Failed setting up TTM BO subsystem.\n" ); +drm_global_item_unref (&rdev->mman.mem_global_ref);return r; }
@@ -89,6 +114,7 @@ static void radeon_ttm_global_fini(struct radeon_device *rdev) {if (rdev->mman.mem_global_referenced) {drm_global_item_unref (&rdev->mman.bo_global_ref.ref); +drm_global_item_unref (&rdev->mman.mem_global_ref); rdev->mman.mem_global_referenced = false; } }
drivers/gpu/drm/ttm/ttm_bo.c +3 -7
@@ -1527,22 +1527,18 @@ void ttm_bo_global_release(struct ttm_bo_global *glob) {kobject_del (&glob->kobj);kobject_put (&glob->kobj); -ttm_mem_global_release (&ttm_mem_glob); }EXPORT_SYMBOL (ttm_bo_global_release); -int ttm_bo_global_init (struct ttm_bo_global *glob) +int ttm_bo_global_init (struct ttm_bo_global *glob, +struct ttm_mem_global *mem_glob) {int ret;unsigned i; - ret =ttm_mem_global_init (&ttm_mem_glob); -if (ret) -return ret; -mutex_init (&glob->device_list_mutex);spin_lock_init (&glob->lru_lock); - glob->mem_glob = &ttm_mem_glob; + glob->mem_glob = mem_glob; glob->mem_glob->bo_glob = glob; glob->dummy_read_page =alloc_page (__GFP_ZERO |GFP_DMA32 );
drivers/gpu/drm/ttm/ttm_memory.c +2 -3
@@ -41,9 +41,6 @@#define TTM_MEMORY_ALLOC_RETRIES 4 -struct ttm_mem_global ttm_mem_glob; -EXPORT_SYMBOL (ttm_mem_glob); -struct ttm_mem_zone {struct kobject kobj;struct ttm_mem_global *glob;
@@ -467,6 +464,7 @@ int ttm_mem_global_init(struct ttm_mem_global *glob)ttm_mem_global_release (glob);return ret; } +EXPORT_SYMBOL (ttm_mem_global_init);void ttm_mem_global_release (struct ttm_mem_global *glob) {
@@ -488,6 +486,7 @@ void ttm_mem_global_release(struct ttm_mem_global *glob)kobject_del (&glob->kobj);kobject_put (&glob->kobj); } +EXPORT_SYMBOL (ttm_mem_global_release);static void ttm_check_swapping (struct ttm_mem_global *glob) {
drivers/gpu/drm/virtio/virtgpu_drv.h +1 -0
@@ -146,6 +146,7 @@ struct virtio_gpu_fbdev {struct virtio_gpu_mman {struct ttm_bo_global_ref bo_global_ref; +struct drm_global_reference mem_global_ref;bool mem_global_referenced;struct ttm_bo_device bdev; };
drivers/gpu/drm/virtio/virtgpu_ttm.c +27 -0
@@ -50,12 +50,37 @@ virtio_gpu_device *virtio_gpu_get_vgdev(struct ttm_bo_device *bdev)return vgdev; } +static int virtio_gpu_ttm_mem_global_init (struct drm_global_reference *ref) +{ +return ttm_mem_global_init (ref->object); +} + +static void virtio_gpu_ttm_mem_global_release (struct drm_global_reference *ref) +{ +ttm_mem_global_release (ref->object); +} +static int virtio_gpu_ttm_global_init (struct virtio_gpu_device *vgdev) {struct drm_global_reference *global_ref;int r; vgdev->mman.mem_global_referenced = false; + global_ref = &vgdev->mman.mem_global_ref; + global_ref->global_type =DRM_GLOBAL_TTM_MEM ; + global_ref->size =sizeof (struct ttm_mem_global ); + global_ref->init = &virtio_gpu_ttm_mem_global_init; + global_ref->release = &virtio_gpu_ttm_mem_global_release; + + r =drm_global_item_ref (global_ref); +if (r !=0 ) { +DRM_ERROR ("Failed setting up TTM memory accounting " +"subsystem.\n" ); +return r; + } + + vgdev->mman.bo_global_ref.mem_glob = + vgdev->mman.mem_global_ref.object; global_ref = &vgdev->mman.bo_global_ref.ref; global_ref->global_type =DRM_GLOBAL_TTM_BO ; global_ref->size =sizeof (struct ttm_bo_global );
@@ -64,6 +89,7 @@ static int virtio_gpu_ttm_global_init(struct virtio_gpu_device *vgdev) r =drm_global_item_ref (global_ref);if (r !=0 ) {DRM_ERROR ("Failed setting up TTM BO subsystem.\n" ); +drm_global_item_unref (&vgdev->mman.mem_global_ref);return r; }
@@ -75,6 +101,7 @@ static void virtio_gpu_ttm_global_fini(struct virtio_gpu_device *vgdev) {if (vgdev->mman.mem_global_referenced) {drm_global_item_unref (&vgdev->mman.bo_global_ref.ref); +drm_global_item_unref (&vgdev->mman.mem_global_ref); vgdev->mman.mem_global_referenced = false; } }
drivers/gpu/drm/vmwgfx/vmwgfx_drv.c +2 -2
@@ -812,8 +812,8 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset) goto out_err4; } - dev_priv->tdev =ttm_object_device_init (&ttm_mem_glob,12 , - &vmw_prime_dmabuf_ops); + dev_priv->tdev =ttm_object_device_init + (dev_priv->mem_global_ref.object,12 , &vmw_prime_dmabuf_ops);if (unlikely (dev_priv->tdev ==NULL )) {DRM_ERROR ("Unable to initialize TTM object management.\n" );
drivers/gpu/drm/vmwgfx/vmwgfx_drv.h +2 -1
@@ -418,6 +418,7 @@ enum {struct vmw_private {struct ttm_bo_device bdev;struct ttm_bo_global_ref bo_global_ref; +struct drm_global_reference mem_global_ref;struct vmw_fifo_state fifo;
@@ -1356,7 +1357,7 @@ vmw_bo_reference(struct vmw_buffer_object *buf)static inline struct ttm_mem_global *vmw_mem_glob (struct vmw_private *dev_priv) { -return &ttm_mem_glob; +return (struct ttm_mem_global *) dev_priv->mem_global_ref.object; }static inline void vmw_fifo_resource_inc (struct vmw_private *dev_priv)
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c +27 -0
@@ -79,11 +79,36 @@ void vmw_validation_mem_init_ttm(struct vmw_private *dev_priv, size_t gran) vvm->gran = gran; } +static int vmw_ttm_mem_global_init (struct drm_global_reference *ref) +{ +DRM_INFO ("global init.\n" ); +return ttm_mem_global_init (ref->object); +} + +static void vmw_ttm_mem_global_release (struct drm_global_reference *ref) +{ +ttm_mem_global_release (ref->object); +} +int vmw_ttm_global_init (struct vmw_private *dev_priv) {struct drm_global_reference *global_ref;int ret; + global_ref = &dev_priv->mem_global_ref; + global_ref->global_type =DRM_GLOBAL_TTM_MEM ; + global_ref->size =sizeof (struct ttm_mem_global ); + global_ref->init = &vmw_ttm_mem_global_init; + global_ref->release = &vmw_ttm_mem_global_release; + + ret =drm_global_item_ref (global_ref); +if (unlikely (ret !=0 )) { +DRM_ERROR ("Failed setting up TTM memory accounting.\n" ); +return ret; + } + + dev_priv->bo_global_ref.mem_glob = + dev_priv->mem_global_ref.object; global_ref = &dev_priv->bo_global_ref.ref; global_ref->global_type =DRM_GLOBAL_TTM_BO ; global_ref->size =sizeof (struct ttm_bo_global );
@@ -98,10 +123,12 @@ int vmw_ttm_global_init(struct vmw_private *dev_priv)return 0 ; out_no_bo: +drm_global_item_unref (&dev_priv->mem_global_ref);return ret; }void vmw_ttm_global_release (struct vmw_private *dev_priv) {drm_global_item_unref (&dev_priv->bo_global_ref.ref); +drm_global_item_unref (&dev_priv->mem_global_ref); }
drivers/staging/vboxvideo/vbox_drv.h +1 -0
@@ -79,6 +79,7 @@ struct vbox_private {int fb_mtrr;struct { +struct drm_global_reference mem_global_ref;struct ttm_bo_global_ref bo_global_ref;struct ttm_bo_device bdev; } ttm;
drivers/staging/vboxvideo/vbox_ttm.c +24 -0
@@ -16,6 +16,16 @@ static inline struct vbox_private *vbox_bdev(struct ttm_bo_device *bd) return container_of(bd, struct vbox_private, ttm.bdev); } +static int vbox_ttm_mem_global_init (struct drm_global_reference *ref) +{ +return ttm_mem_global_init (ref->object); +} + +static void vbox_ttm_mem_global_release (struct drm_global_reference *ref) +{ +ttm_mem_global_release (ref->object); +} +/** * Adds the vbox memory manager object/structures to the global memory manager. */
@@ -24,6 +34,18 @@ static int vbox_ttm_global_init(struct vbox_private *vbox)struct drm_global_reference *global_ref;int ret; + global_ref = &vbox->ttm.mem_global_ref; + global_ref->global_type =DRM_GLOBAL_TTM_MEM ; + global_ref->size =sizeof (struct ttm_mem_global ); + global_ref->init = &vbox_ttm_mem_global_init; + global_ref->release = &vbox_ttm_mem_global_release; + ret =drm_global_item_ref (global_ref); +if (ret) { +DRM_ERROR ("Failed setting up TTM memory subsystem.\n" ); +return ret; + } + + vbox->ttm.bo_global_ref.mem_glob = vbox->ttm.mem_global_ref.object; global_ref = &vbox->ttm.bo_global_ref.ref; global_ref->global_type =DRM_GLOBAL_TTM_BO ; global_ref->size =sizeof (struct ttm_bo_global );
@@ -33,6 +55,7 @@ static int vbox_ttm_global_init(struct vbox_private *vbox) ret =drm_global_item_ref (global_ref);if (ret) {DRM_ERROR ("Failed setting up TTM BO subsystem.\n" ); +drm_global_item_unref (&vbox->ttm.mem_global_ref);return ret; }
@@ -45,6 +68,7 @@ static int vbox_ttm_global_init(struct vbox_private *vbox)static void vbox_ttm_global_release (struct vbox_private *vbox) {drm_global_item_unref (&vbox->ttm.bo_global_ref.ref); +drm_global_item_unref (&vbox->ttm.mem_global_ref); }static void vbox_bo_ttm_destroy (struct ttm_buffer_object *tbo)
include/drm/ttm/ttm_bo_driver.h +6 -2
@@ -570,7 +570,8 @@ void ttm_bo_mem_put_locked(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem);void ttm_bo_global_release (struct ttm_bo_global *glob); -int ttm_bo_global_init (struct ttm_bo_global *glob); +int ttm_bo_global_init (struct ttm_bo_global *glob, +struct ttm_mem_global *mem_glob);int ttm_bo_device_release (struct ttm_bo_device *bdev);
@@ -894,6 +895,7 @@ extern const struct ttm_mem_type_manager_func ttm_bo_manager_func;struct ttm_bo_global_ref {struct drm_global_reference ref; +struct ttm_mem_global *mem_glob; };/**
@@ -907,7 +909,9 @@ struct ttm_bo_global_ref {*/ static inline int ttm_bo_global_ref_init (struct drm_global_reference *ref) { -return ttm_bo_global_init (ref->object); +struct ttm_bo_global_ref *bo_ref = + container_of(ref, struct ttm_bo_global_ref, ref); +return ttm_bo_global_init (ref->object, bo_ref->mem_glob); }/**
include/drm/ttm/ttm_memory.h +2 -2
@@ -63,7 +63,7 @@#define TTM_MEM_MAX_ZONES 2struct ttm_mem_zone ; -extern struct ttm_mem_global { +struct ttm_mem_global {struct kobject kobj;struct ttm_bo_global *bo_glob;struct workqueue_struct *swap_queue;
@@ -78,7 +78,7 @@ extern struct ttm_mem_global {#else struct ttm_mem_zone *zone_dma32;#endif -} ttm_mem_glob; +};extern int ttm_mem_global_init (struct ttm_mem_global *glob);extern void ttm_mem_global_release (struct ttm_mem_global *glob);
Signature · 6 lines
2.20.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 16.04.19 um 02:35 schrieb Karol Herbst:
Quoted 14 lines
Kobjects are supposed to be dynamically allocated, but with recent changes this rule was violated. Reverting those commits fixes crashes when a drm driver using TTM gets loaded again.
The object in question is "
ttm_mem_glob" declared inside "include/drm/ttm/ttm_memory.h" and instatiated inside "drivers/gpu/drm/ttm/ttm_memory.c".from "
Documentation/kobject.txt":
"Because kobjects are dynamic, they must not be declared statically or on the stack, but instead, always allocated dynamically. Future versions of the kernel will contain a run-time check for kobjects that are created statically and will warn the developer of this improper usage."
Quoted 7 lines
Unloading ttm before reloading the driver workarounds that crash, because the memory backing the kobject member "kobj" is cleaned up. The
kobject_delandkobject_putfunction never free or clean up the kobject object leaving it in an undefined state.I reverted a few more commits to make it less painful for me to rever this rather big change.
Well, NAK. By reverting those change you also re-introduced the problems we originally fixed with those patches.
Please work on a proper fix instead,
Christian.
Quoted 158 lines
dmesg output:
[54758.418036] kobject (00000000687a067d): tried to init an initialized object, something is seriously wrong. [54758.418040] CPU: 6 PID: 26746 Comm: insmod Tainted: G U OE 5.0.6-200.fc29.x86_64 #1 [54758.418041] Hardware name: Dell Inc. XPS 15 9560/05FFDN, BIOS 1.12.1 10/02/2018 [54758.418041] Call Trace: [54758.418049] dump_stack+0x5c/0x80 [54758.418054] kobject_init.cold.9+0x31/0x3f [54758.418057] kobject_init_and_add+0x35/0xa0 [54758.418063] ttm_mem_global_init+0x8f/0x2b0 [ttm] [54758.418067] ? __debugfs_create_file+0xe1/0x110 [54758.418071] ttm_bo_device_init+0x198/0x2a0 [ttm] [54758.418144] nouveau_ttm_init+0xbf/0x340 [nouveau] [54758.418206] nouveau_drm_device_init+0x125/0x7d0 [nouveau] [54758.418210] ? pci_bus_read_config_word+0x49/0x70 [54758.418266] nouveau_drm_probe+0x26f/0x2c0 [nouveau] [54758.418270] local_pci_probe+0x41/0x90 [54758.418272] pci_device_probe+0x118/0x1a0 [54758.418275] really_probe+0xf8/0x3b0 [54758.418277] driver_probe_device+0xb3/0xf0 [54758.418278] __driver_attach+0xdd/0x110 [54758.418280] ? driver_probe_device+0xf0/0xf0 [54758.418282] bus_for_each_dev+0x77/0xc0 [54758.418285] ? klist_add_tail+0x3b/0x60 [54758.418287] bus_add_driver+0x152/0x230 [54758.418288] ? 0xffffffffc1027000 [54758.418290] driver_register+0x6b/0xb0 [54758.418291] ? 0xffffffffc1027000 [54758.418294] do_one_initcall+0x46/0x1c3 [54758.418296] ? _cond_resched+0x15/0x30 [54758.418299] ? kmem_cache_alloc_trace+0x154/0x1d0 [54758.418302] do_init_module+0x5a/0x210 [54758.418304] load_module+0x2096/0x22d0 [54758.418308] ? ima_post_read_file+0xf4/0x100 [54758.418310] ? __do_sys_finit_module+0xa8/0x110 [54758.418312] __do_sys_finit_module+0xa8/0x110 [54758.418315] do_syscall_64+0x5b/0x160 [54758.418317] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [54758.418319] RIP: 0033:0x7fc0b38b6edd [54758.418321] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 7b 7f 0c 00 f7 d8 64 89 01 48 [54758.418322] RSP: 002b:00007ffc7f1620d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 [54758.418323] RAX: ffffffffffffffda RBX: 00005629a3996ac0 RCX: 00007fc0b38b6edd [54758.418324] RDX: 0000000000000000 RSI: 00005629a3996260 RDI: 0000000000000003 [54758.418325] RBP: 00005629a3996260 R08: 0000000000000000 R09: 0000000000000000 [54758.418326] R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000000000 [54758.418326] R13: 00005629a3996a80 R14: 0000000000000000 R15: 00005629a3996260 [54758.418346] BUG: unable to handle kernel paging request at 00000004ee194700 [54758.418348] #PF error: [WRITE] [54758.418349] PGD 0 P4D 0 [54758.418352] Oops: 0002 [#1] SMP PTI [54758.418354] CPU: 6 PID: 26746 Comm: insmod Tainted: G U OE 5.0.6-200.fc29.x86_64 #1 [54758.418355] Hardware name: Dell Inc. XPS 15 9560/05FFDN, BIOS 1.12.1 10/02/2018 [54758.418360] RIP: 0010:ttm_mem_global_init+0x1fe/0x2b0 [ttm] [54758.418361] Code: 00 00 00 48 89 5d 40 48 89 ab a0 00 00 00 e8 79 ba 95 f8 85 c0 0f 85 a2 00 00 00 8b 83 90 00 00 00 8d 50 01 89 93 90 00 00 00 <48> 89 ac c3 80 00 00 00 85 d2 0f 85 c6 99 00 00 48 8b 83 98 00 00 [54758.418363] RSP: 0018:ffffc24e53c1f988 EFLAGS: 00010246 [54758.418364] RAX: 00000000a5a2f300 RBX: ffffffffc101ae80 RCX: 0000000000000000 [54758.418366] RDX: 00000000a5a2f301 RSI: 0000000000000000 RDI: ffff9ebe78b67330 [54758.418367] RBP: ffff9ebe42c79d00 R08: 0000000000000044 R09: 0000000000000228 [54758.418368] R10: 0000000000000000 R11: ffff9ebb62720bb8 R12: 0000000000000000 [54758.418370] R13: ffff9ebe27d71640 R14: ffff9eba9f258600 R15: ffffffffc1453880 [54758.418371] FS: 00007fc0b379c280(0000) GS:ffff9ebeae380000(0000) knlGS:0000000000000000 [54758.418373] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [54758.418374] CR2: 00000004ee194700 CR3: 000000045069e005 CR4: 00000000003606e0 [54758.418375] Call Trace: [54758.418381] ttm_bo_device_init+0x198/0x2a0 [ttm] [54758.418439] nouveau_ttm_init+0xbf/0x340 [nouveau] [54758.418495] nouveau_drm_device_init+0x125/0x7d0 [nouveau] [54758.418499] ? pci_bus_read_config_word+0x49/0x70 [54758.418552] nouveau_drm_probe+0x26f/0x2c0 [nouveau] [54758.418556] local_pci_probe+0x41/0x90 [54758.418558] pci_device_probe+0x118/0x1a0 [54758.418561] really_probe+0xf8/0x3b0 [54758.418563] driver_probe_device+0xb3/0xf0 [54758.418565] __driver_attach+0xdd/0x110 [54758.418567] ? driver_probe_device+0xf0/0xf0 [54758.418570] bus_for_each_dev+0x77/0xc0 [54758.418573] ? klist_add_tail+0x3b/0x60 [54758.418574] bus_add_driver+0x152/0x230 [54758.418576] ? 0xffffffffc1027000 [54758.418578] driver_register+0x6b/0xb0 [54758.418580] ? 0xffffffffc1027000 [54758.418583] do_one_initcall+0x46/0x1c3 [54758.418585] ? _cond_resched+0x15/0x30 [54758.418587] ? kmem_cache_alloc_trace+0x154/0x1d0 [54758.418591] do_init_module+0x5a/0x210 [54758.418593] load_module+0x2096/0x22d0 [54758.418596] ? ima_post_read_file+0xf4/0x100 [54758.418599] ? __do_sys_finit_module+0xa8/0x110 [54758.418601] __do_sys_finit_module+0xa8/0x110 [54758.418604] do_syscall_64+0x5b/0x160 [54758.418607] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [54758.418609] RIP: 0033:0x7fc0b38b6edd [54758.418610] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 7b 7f 0c 00 f7 d8 64 89 01 48 [54758.418612] RSP: 002b:00007ffc7f1620d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 [54758.418614] RAX: ffffffffffffffda RBX: 00005629a3996ac0 RCX: 00007fc0b38b6edd [54758.418615] RDX: 0000000000000000 RSI: 00005629a3996260 RDI: 0000000000000003 [54758.418616] RBP: 00005629a3996260 R08: 0000000000000000 R09: 0000000000000000 [54758.418618] R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000000000 [54758.418619] R13: 00005629a3996a80 R14: 0000000000000000 R15: 00005629a3996260 [54758.418620] Modules linked in: nouveau(OE+) acpi_call(OE) ttm rfcomm ccm xt_CHECKSUM ipt_MASQUERADE tun bridge stp llc devlink ip6t_rpfilter ip6t_REJECT nf_reject_ipv6 xt_conntrack ebtable_nat ip6table_nat nf_nat_ipv6 ip6table_mangle ip6table_raw ip6table_security iptable_nat nf_nat_ipv4 nf_nat iptable_mangle iptable_raw iptable_security nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 libcrc32c ip_set nfnetlink ebtable_filter ebtables ip6table_filter ip6_tables cmac bnep sunrpc vfat fat btusb btrtl btbcm btintel uvcvideo videobuf2_vmalloc bluetooth videobuf2_memops videobuf2_v4l2 videobuf2_common videodev media ecdh_generic arc4 snd_hda_codec_hdmi ath10k_pci ath10k_core snd_hda_codec_realtek iTCO_wdt mei_wdt iTCO_vendor_support snd_hda_codec_generic mac80211 intel_rapl snd_hda_intel x86_pkg_temp_thermal intel_powerclamp coretemp snd_hda_codec dell_laptop ledtrig_audio dell_smm_hwmon snd_hda_core kvm_intel snd_hwdep ath snd_seq snd_seq_device intel_cstate cfg80211 snd_pcm dell_wmi intel_uncore [54758.418653] dell_smbios dcdbas intel_rapl_perf snd_timer joydev dell_wmi_descriptor intel_wmi_thunderbolt wmi_bmof snd idma64 soundcore i2c_i801 rfkill rtsx_pci_ms memstick mei_me mei processor_thermal_device intel_lpss_pci intel_soc_dts_iosf intel_pch_thermal intel_lpss int3400_thermal acpi_pad acpi_thermal_rel int3403_thermal intel_hid pcc_cpufreq int340x_thermal_zone sparse_keymap binfmt_misc zram dm_crypt hid_multitouch i915 kvmgt mdev vfio kvm irqbypass i2c_algo_bit crct10dif_pclmul drm_kms_helper rtsx_pci_sdmmc crc32_pclmul mmc_core crc32c_intel mxm_wmi drm nvme ghash_clmulni_intel nvme_core serio_raw rtsx_pci i2c_hid video wmi i2c_dev lz4 lz4_compress [last unloaded: nouveau] [54758.418679] CR2: 00000004ee194700 [54758.418681] ---[ end trace c5175234e6efc034 ]--- [54758.418686] RIP: 0010:ttm_mem_global_init+0x1fe/0x2b0 [ttm] [54758.418688] Code: 00 00 00 48 89 5d 40 48 89 ab a0 00 00 00 e8 79 ba 95 f8 85 c0 0f 85 a2 00 00 00 8b 83 90 00 00 00 8d 50 01 89 93 90 00 00 00 <48> 89 ac c3 80 00 00 00 85 d2 0f 85 c6 99 00 00 48 8b 83 98 00 00 [54758.418689] RSP: 0018:ffffc24e53c1f988 EFLAGS: 00010246 [54758.418690] RAX: 00000000a5a2f300 RBX: ffffffffc101ae80 RCX: 0000000000000000 [54758.418691] RDX: 00000000a5a2f301 RSI: 0000000000000000 RDI: ffff9ebe78b67330 [54758.418692] RBP: ffff9ebe42c79d00 R08: 0000000000000044 R09: 0000000000000228 [54758.418694] R10: 0000000000000000 R11: ffff9ebb62720bb8 R12: 0000000000000000 [54758.418695] R13: ffff9ebe27d71640 R14: ffff9eba9f258600 R15: ffffffffc1453880 [54758.418696] FS: 00007fc0b379c280(0000) GS:ffff9ebeae380000(0000) knlGS:0000000000000000 [54758.418698] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [54758.418699] CR2: 00000004ee194700 CR3: 000000045069e005 CR4: 00000000003606e0Karol Herbst (6):
Revert "drm: Remove drm_global.{c,h} v2"
Revert "drm/ttm: initialize globals during device init (v2)" Revert "drm/ttm: Fixbo_globalandmem_globalkfree error" Revert "drm/ttm: use a staticttm_bo_globalinstance" Revert "drm/ttm: make the device list mutex static" Revert "drm/ttm: use a staticttm_mem_globalinstance"drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 103 ++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 2 + drivers/gpu/drm/ast/ast_drv.h | 2 + drivers/gpu/drm/ast/ast_ttm.c | 64 ++++++++ drivers/gpu/drm/bochs/bochs.h | 2 + drivers/gpu/drm/bochs/bochs_mm.c | 61 ++++++++ drivers/gpu/drm/cirrus/cirrus_drv.h | 2 + drivers/gpu/drm/cirrus/cirrus_ttm.c | 64 ++++++++ drivers/gpu/drm/drm_drv.c | 2 + drivers/gpu/drm/drm_global.c | 137 ++++++++++++++++++ .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 + drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 57 ++++++++ drivers/gpu/drm/mgag200/mgag200_drv.h | 2 + drivers/gpu/drm/mgag200/mgag200_ttm.c | 64 ++++++++ drivers/gpu/drm/nouveau/nouveau_drv.h | 2 + drivers/gpu/drm/nouveau/nouveau_ttm.c | 67 +++++++++ drivers/gpu/drm/qxl/qxl_drv.h | 3 + drivers/gpu/drm/qxl/qxl_ttm.c | 61 ++++++++ drivers/gpu/drm/radeon/radeon.h | 3 + drivers/gpu/drm/radeon/radeon_ttm.c | 65 +++++++++ drivers/gpu/drm/ttm/ttm_bo.c | 67 +++------ drivers/gpu/drm/ttm/ttm_memory.c | 14 +- drivers/gpu/drm/virtio/virtgpu_drv.h | 3 + drivers/gpu/drm/virtio/virtgpu_ttm.c | 62 ++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 15 +- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 6 +- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 54 +++++++ drivers/staging/vboxvideo/vbox_drv.h | 2 + drivers/staging/vboxvideo/vbox_ttm.c | 65 ++++++++- include/drm/drmP.h | 1 + include/drm/drm_global.h | 53 +++++++ include/drm/ttm/ttm_bo_driver.h | 54 ++++++- include/drm/ttm/ttm_memory.h | 4 +- 34 files changed, 1102 insertions(+), 65 deletions(-)
Quoted 3 lines
create mode 100644
drivers/gpu/drm/drm_global.c
create mode 100644include/drm/drm_global.h
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 21 lines · Christian König
Am 16.04.19 um 02:35 schrieb Karol Herbst:
Quoted 19 lines
Kobjects are supposed to be dynamically allocated, but with recent changes this rule was violated. Reverting those commits fixes crashes when a drm driver using TTM gets loaded again.
The object in question is "
ttm_mem_glob" declared inside "include/drm/ttm/ttm_memory.h" and instatiated inside "drivers/gpu/drm/ttm/ttm_memory.c".from "
Documentation/kobject.txt":
"Because kobjects are dynamic, they must not be declared statically or on the stack, but instead, always allocated dynamically. Future versions of the kernel will contain a run-time check for kobjects that are created statically and will warn the developer of this improper usage."Unloading ttm before reloading the driver workarounds that crash, because the memory backing the kobject member "kobj" is cleaned up. The
kobject_delandkobject_putfunction never free or clean up the kobject object leaving it in an undefined state.
Quoted 8 lines
Quoted 2 lines
I reverted a few more commits to make it less painful for me to rever this rather big change.
Well, NAK. By reverting those change you also re-introduced the problems we originally fixed with those patches.
Please work on a proper fix instead,
Christian.
And which problem was that besides duplicated code (or maybe even a bit of memory consumption if multiple ttm driver were used)? If I had to choose between duplicated code and a crash, I choose the former.
Maybe I missed the real reason why those changes are made, but the commit messages don't really seem to tell me.
Quoted 154 lines
Quoted 154 lines
dmesg output:
[54758.418036] kobject (00000000687a067d): tried to init an initialized object, something is seriously wrong. [54758.418040] CPU: 6 PID: 26746 Comm: insmod Tainted: G U OE 5.0.6-200.fc29.x86_64 #1 [54758.418041] Hardware name: Dell Inc. XPS 15 9560/05FFDN, BIOS 1.12.1 10/02/2018 [54758.418041] Call Trace: [54758.418049] dump_stack+0x5c/0x80 [54758.418054] kobject_init.cold.9+0x31/0x3f [54758.418057] kobject_init_and_add+0x35/0xa0 [54758.418063] ttm_mem_global_init+0x8f/0x2b0 [ttm] [54758.418067] ? __debugfs_create_file+0xe1/0x110 [54758.418071] ttm_bo_device_init+0x198/0x2a0 [ttm] [54758.418144] nouveau_ttm_init+0xbf/0x340 [nouveau] [54758.418206] nouveau_drm_device_init+0x125/0x7d0 [nouveau] [54758.418210] ? pci_bus_read_config_word+0x49/0x70 [54758.418266] nouveau_drm_probe+0x26f/0x2c0 [nouveau] [54758.418270] local_pci_probe+0x41/0x90 [54758.418272] pci_device_probe+0x118/0x1a0 [54758.418275] really_probe+0xf8/0x3b0 [54758.418277] driver_probe_device+0xb3/0xf0 [54758.418278] __driver_attach+0xdd/0x110 [54758.418280] ? driver_probe_device+0xf0/0xf0 [54758.418282] bus_for_each_dev+0x77/0xc0 [54758.418285] ? klist_add_tail+0x3b/0x60 [54758.418287] bus_add_driver+0x152/0x230 [54758.418288] ? 0xffffffffc1027000 [54758.418290] driver_register+0x6b/0xb0 [54758.418291] ? 0xffffffffc1027000 [54758.418294] do_one_initcall+0x46/0x1c3 [54758.418296] ? _cond_resched+0x15/0x30 [54758.418299] ? kmem_cache_alloc_trace+0x154/0x1d0 [54758.418302] do_init_module+0x5a/0x210 [54758.418304] load_module+0x2096/0x22d0 [54758.418308] ? ima_post_read_file+0xf4/0x100 [54758.418310] ? __do_sys_finit_module+0xa8/0x110 [54758.418312] __do_sys_finit_module+0xa8/0x110 [54758.418315] do_syscall_64+0x5b/0x160 [54758.418317] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [54758.418319] RIP: 0033:0x7fc0b38b6edd [54758.418321] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 7b 7f 0c 00 f7 d8 64 89 01 48 [54758.418322] RSP: 002b:00007ffc7f1620d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 [54758.418323] RAX: ffffffffffffffda RBX: 00005629a3996ac0 RCX: 00007fc0b38b6edd [54758.418324] RDX: 0000000000000000 RSI: 00005629a3996260 RDI: 0000000000000003 [54758.418325] RBP: 00005629a3996260 R08: 0000000000000000 R09: 0000000000000000 [54758.418326] R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000000000 [54758.418326] R13: 00005629a3996a80 R14: 0000000000000000 R15: 00005629a3996260 [54758.418346] BUG: unable to handle kernel paging request at 00000004ee194700 [54758.418348] #PF error: [WRITE] [54758.418349] PGD 0 P4D 0 [54758.418352] Oops: 0002 [#1] SMP PTI [54758.418354] CPU: 6 PID: 26746 Comm: insmod Tainted: G U OE 5.0.6-200.fc29.x86_64 #1 [54758.418355] Hardware name: Dell Inc. XPS 15 9560/05FFDN, BIOS 1.12.1 10/02/2018 [54758.418360] RIP: 0010:ttm_mem_global_init+0x1fe/0x2b0 [ttm] [54758.418361] Code: 00 00 00 48 89 5d 40 48 89 ab a0 00 00 00 e8 79 ba 95 f8 85 c0 0f 85 a2 00 00 00 8b 83 90 00 00 00 8d 50 01 89 93 90 00 00 00 <48> 89 ac c3 80 00 00 00 85 d2 0f 85 c6 99 00 00 48 8b 83 98 00 00 [54758.418363] RSP: 0018:ffffc24e53c1f988 EFLAGS: 00010246 [54758.418364] RAX: 00000000a5a2f300 RBX: ffffffffc101ae80 RCX: 0000000000000000 [54758.418366] RDX: 00000000a5a2f301 RSI: 0000000000000000 RDI: ffff9ebe78b67330 [54758.418367] RBP: ffff9ebe42c79d00 R08: 0000000000000044 R09: 0000000000000228 [54758.418368] R10: 0000000000000000 R11: ffff9ebb62720bb8 R12: 0000000000000000 [54758.418370] R13: ffff9ebe27d71640 R14: ffff9eba9f258600 R15: ffffffffc1453880 [54758.418371] FS: 00007fc0b379c280(0000) GS:ffff9ebeae380000(0000) knlGS:0000000000000000 [54758.418373] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [54758.418374] CR2: 00000004ee194700 CR3: 000000045069e005 CR4: 00000000003606e0 [54758.418375] Call Trace: [54758.418381] ttm_bo_device_init+0x198/0x2a0 [ttm] [54758.418439] nouveau_ttm_init+0xbf/0x340 [nouveau] [54758.418495] nouveau_drm_device_init+0x125/0x7d0 [nouveau] [54758.418499] ? pci_bus_read_config_word+0x49/0x70 [54758.418552] nouveau_drm_probe+0x26f/0x2c0 [nouveau] [54758.418556] local_pci_probe+0x41/0x90 [54758.418558] pci_device_probe+0x118/0x1a0 [54758.418561] really_probe+0xf8/0x3b0 [54758.418563] driver_probe_device+0xb3/0xf0 [54758.418565] __driver_attach+0xdd/0x110 [54758.418567] ? driver_probe_device+0xf0/0xf0 [54758.418570] bus_for_each_dev+0x77/0xc0 [54758.418573] ? klist_add_tail+0x3b/0x60 [54758.418574] bus_add_driver+0x152/0x230 [54758.418576] ? 0xffffffffc1027000 [54758.418578] driver_register+0x6b/0xb0 [54758.418580] ? 0xffffffffc1027000 [54758.418583] do_one_initcall+0x46/0x1c3 [54758.418585] ? _cond_resched+0x15/0x30 [54758.418587] ? kmem_cache_alloc_trace+0x154/0x1d0 [54758.418591] do_init_module+0x5a/0x210 [54758.418593] load_module+0x2096/0x22d0 [54758.418596] ? ima_post_read_file+0xf4/0x100 [54758.418599] ? __do_sys_finit_module+0xa8/0x110 [54758.418601] __do_sys_finit_module+0xa8/0x110 [54758.418604] do_syscall_64+0x5b/0x160 [54758.418607] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [54758.418609] RIP: 0033:0x7fc0b38b6edd [54758.418610] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 7b 7f 0c 00 f7 d8 64 89 01 48 [54758.418612] RSP: 002b:00007ffc7f1620d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 [54758.418614] RAX: ffffffffffffffda RBX: 00005629a3996ac0 RCX: 00007fc0b38b6edd [54758.418615] RDX: 0000000000000000 RSI: 00005629a3996260 RDI: 0000000000000003 [54758.418616] RBP: 00005629a3996260 R08: 0000000000000000 R09: 0000000000000000 [54758.418618] R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000000000 [54758.418619] R13: 00005629a3996a80 R14: 0000000000000000 R15: 00005629a3996260 [54758.418620] Modules linked in: nouveau(OE+) acpi_call(OE) ttm rfcomm ccm xt_CHECKSUM ipt_MASQUERADE tun bridge stp llc devlink ip6t_rpfilter ip6t_REJECT nf_reject_ipv6 xt_conntrack ebtable_nat ip6table_nat nf_nat_ipv6 ip6table_mangle ip6table_raw ip6table_security iptable_nat nf_nat_ipv4 nf_nat iptable_mangle iptable_raw iptable_security nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 libcrc32c ip_set nfnetlink ebtable_filter ebtables ip6table_filter ip6_tables cmac bnep sunrpc vfat fat btusb btrtl btbcm btintel uvcvideo videobuf2_vmalloc bluetooth videobuf2_memops videobuf2_v4l2 videobuf2_common videodev media ecdh_generic arc4 snd_hda_codec_hdmi ath10k_pci ath10k_core snd_hda_codec_realtek iTCO_wdt mei_wdt iTCO_vendor_support snd_hda_codec_generic mac80211 intel_rapl snd_hda_intel x86_pkg_temp_thermal intel_powerclamp coretemp snd_hda_codec dell_laptop ledtrig_audio dell_smm_hwmon snd_hda_core kvm_intel snd_hwdep ath snd_seq snd_seq_device intel_cstate cfg80211 snd_pcm dell_wmi intel_uncore [54758.418653] dell_smbios dcdbas intel_rapl_perf snd_timer joydev dell_wmi_descriptor intel_wmi_thunderbolt wmi_bmof snd idma64 soundcore i2c_i801 rfkill rtsx_pci_ms memstick mei_me mei processor_thermal_device intel_lpss_pci intel_soc_dts_iosf intel_pch_thermal intel_lpss int3400_thermal acpi_pad acpi_thermal_rel int3403_thermal intel_hid pcc_cpufreq int340x_thermal_zone sparse_keymap binfmt_misc zram dm_crypt hid_multitouch i915 kvmgt mdev vfio kvm irqbypass i2c_algo_bit crct10dif_pclmul drm_kms_helper rtsx_pci_sdmmc crc32_pclmul mmc_core crc32c_intel mxm_wmi drm nvme ghash_clmulni_intel nvme_core serio_raw rtsx_pci i2c_hid video wmi i2c_dev lz4 lz4_compress [last unloaded: nouveau] [54758.418679] CR2: 00000004ee194700 [54758.418681] ---[ end trace c5175234e6efc034 ]--- [54758.418686] RIP: 0010:ttm_mem_global_init+0x1fe/0x2b0 [ttm] [54758.418688] Code: 00 00 00 48 89 5d 40 48 89 ab a0 00 00 00 e8 79 ba 95 f8 85 c0 0f 85 a2 00 00 00 8b 83 90 00 00 00 8d 50 01 89 93 90 00 00 00 <48> 89 ac c3 80 00 00 00 85 d2 0f 85 c6 99 00 00 48 8b 83 98 00 00 [54758.418689] RSP: 0018:ffffc24e53c1f988 EFLAGS: 00010246 [54758.418690] RAX: 00000000a5a2f300 RBX: ffffffffc101ae80 RCX: 0000000000000000 [54758.418691] RDX: 00000000a5a2f301 RSI: 0000000000000000 RDI: ffff9ebe78b67330 [54758.418692] RBP: ffff9ebe42c79d00 R08: 0000000000000044 R09: 0000000000000228 [54758.418694] R10: 0000000000000000 R11: ffff9ebb62720bb8 R12: 0000000000000000 [54758.418695] R13: ffff9ebe27d71640 R14: ffff9eba9f258600 R15: ffffffffc1453880 [54758.418696] FS: 00007fc0b379c280(0000) GS:ffff9ebeae380000(0000) knlGS:0000000000000000 [54758.418698] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [54758.418699] CR2: 00000004ee194700 CR3: 000000045069e005 CR4: 00000000003606e0Karol Herbst (6):
Revert "drm: Remove drm_global.{c,h} v2"
Revert "drm/ttm: initialize globals during device init (v2)" Revert "drm/ttm: Fixbo_globalandmem_globalkfree error" Revert "drm/ttm: use a staticttm_bo_globalinstance" Revert "drm/ttm: make the device list mutex static" Revert "drm/ttm: use a staticttm_mem_globalinstance"drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 103 ++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 2 + drivers/gpu/drm/ast/ast_drv.h | 2 + drivers/gpu/drm/ast/ast_ttm.c | 64 ++++++++ drivers/gpu/drm/bochs/bochs.h | 2 + drivers/gpu/drm/bochs/bochs_mm.c | 61 ++++++++ drivers/gpu/drm/cirrus/cirrus_drv.h | 2 + drivers/gpu/drm/cirrus/cirrus_ttm.c | 64 ++++++++ drivers/gpu/drm/drm_drv.c | 2 + drivers/gpu/drm/drm_global.c | 137 ++++++++++++++++++ .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 + drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 57 ++++++++ drivers/gpu/drm/mgag200/mgag200_drv.h | 2 + drivers/gpu/drm/mgag200/mgag200_ttm.c | 64 ++++++++ drivers/gpu/drm/nouveau/nouveau_drv.h | 2 + drivers/gpu/drm/nouveau/nouveau_ttm.c | 67 +++++++++ drivers/gpu/drm/qxl/qxl_drv.h | 3 + drivers/gpu/drm/qxl/qxl_ttm.c | 61 ++++++++ drivers/gpu/drm/radeon/radeon.h | 3 + drivers/gpu/drm/radeon/radeon_ttm.c | 65 +++++++++ drivers/gpu/drm/ttm/ttm_bo.c | 67 +++------ drivers/gpu/drm/ttm/ttm_memory.c | 14 +- drivers/gpu/drm/virtio/virtgpu_drv.h | 3 + drivers/gpu/drm/virtio/virtgpu_ttm.c | 62 ++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 15 +- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 6 +- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 54 +++++++ drivers/staging/vboxvideo/vbox_drv.h | 2 + drivers/staging/vboxvideo/vbox_ttm.c | 65 ++++++++-
Quoted 10 lines
Quoted 8 lines
include/drm/drmP.h | 1 + include/drm/drm_global.h | 53 +++++++ include/drm/ttm/ttm_bo_driver.h | 54 ++++++- include/drm/ttm/ttm_memory.h | 4 +- 34 files changed, 1102 insertions(+), 65 deletions(-)create mode 100644
drivers/gpu/drm/drm_global.c
create mode 100644include/drm/drm_global.h
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Koenig, Christian
maintainerAm 16.04.19 um 11:10 schrieb Karol Herbst:
Quoted 27 lines
Quoted 25 lines · Christian König
Am 16.04.19 um 02:35 schrieb Karol Herbst:
Quoted 14 lines
Kobjects are supposed to be dynamically allocated, but with recent changes this rule was violated. Reverting those commits fixes crashes when a drm driver using TTM gets loaded again.
The object in question is "
ttm_mem_glob" declared inside "include/drm/ttm/ttm_memory.h" and instatiated inside "drivers/gpu/drm/ttm/ttm_memory.c".from "
Documentation/kobject.txt":
"Because kobjects are dynamic, they must not be declared statically or on the stack, but instead, always allocated dynamically. Future versions of the kernel will contain a run-time check for kobjects that are created statically and will warn the developer of this improper usage."Quoted 7 lines
Unloading ttm before reloading the driver workarounds that crash, because the memory backing the kobject member "kobj" is cleaned up. The
kobject_delandkobject_putfunction never free or clean up the kobject object leaving it in an undefined state.I reverted a few more commits to make it less painful for me to rever this rather big change.
Well, NAK. By reverting those change you also re-introduced the problems we originally fixed with those patches.
Quoted 8 lines
Quoted 2 lines
Please work on a proper fix instead,
Christian.And which problem was that besides duplicated code (or maybe even a bit of memory consumption if multiple ttm driver were used)? If I had to choose between duplicated code and a crash, I choose the former.
Maybe I missed the real reason why those changes are made, but the commit messages don't really seem to tell me.
The old implementation crashed because different drivers tried to allocate the same kobj.
Crashing in one way is not better than crashing in another way.
Christian.
Quoted 154 lines
Quoted 154 lines
Quoted 154 lines
dmesg output:
[54758.418036] kobject (00000000687a067d): tried to init an initialized object, something is seriously wrong. [54758.418040] CPU: 6 PID: 26746 Comm: insmod Tainted: G U OE 5.0.6-200.fc29.x86_64 #1 [54758.418041] Hardware name: Dell Inc. XPS 15 9560/05FFDN, BIOS 1.12.1 10/02/2018 [54758.418041] Call Trace: [54758.418049] dump_stack+0x5c/0x80 [54758.418054] kobject_init.cold.9+0x31/0x3f [54758.418057] kobject_init_and_add+0x35/0xa0 [54758.418063] ttm_mem_global_init+0x8f/0x2b0 [ttm] [54758.418067] ? __debugfs_create_file+0xe1/0x110 [54758.418071] ttm_bo_device_init+0x198/0x2a0 [ttm] [54758.418144] nouveau_ttm_init+0xbf/0x340 [nouveau] [54758.418206] nouveau_drm_device_init+0x125/0x7d0 [nouveau] [54758.418210] ? pci_bus_read_config_word+0x49/0x70 [54758.418266] nouveau_drm_probe+0x26f/0x2c0 [nouveau] [54758.418270] local_pci_probe+0x41/0x90 [54758.418272] pci_device_probe+0x118/0x1a0 [54758.418275] really_probe+0xf8/0x3b0 [54758.418277] driver_probe_device+0xb3/0xf0 [54758.418278] __driver_attach+0xdd/0x110 [54758.418280] ? driver_probe_device+0xf0/0xf0 [54758.418282] bus_for_each_dev+0x77/0xc0 [54758.418285] ? klist_add_tail+0x3b/0x60 [54758.418287] bus_add_driver+0x152/0x230 [54758.418288] ? 0xffffffffc1027000 [54758.418290] driver_register+0x6b/0xb0 [54758.418291] ? 0xffffffffc1027000 [54758.418294] do_one_initcall+0x46/0x1c3 [54758.418296] ? _cond_resched+0x15/0x30 [54758.418299] ? kmem_cache_alloc_trace+0x154/0x1d0 [54758.418302] do_init_module+0x5a/0x210 [54758.418304] load_module+0x2096/0x22d0 [54758.418308] ? ima_post_read_file+0xf4/0x100 [54758.418310] ? __do_sys_finit_module+0xa8/0x110 [54758.418312] __do_sys_finit_module+0xa8/0x110 [54758.418315] do_syscall_64+0x5b/0x160 [54758.418317] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [54758.418319] RIP: 0033:0x7fc0b38b6edd [54758.418321] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 7b 7f 0c 00 f7 d8 64 89 01 48 [54758.418322] RSP: 002b:00007ffc7f1620d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 [54758.418323] RAX: ffffffffffffffda RBX: 00005629a3996ac0 RCX: 00007fc0b38b6edd [54758.418324] RDX: 0000000000000000 RSI: 00005629a3996260 RDI: 0000000000000003 [54758.418325] RBP: 00005629a3996260 R08: 0000000000000000 R09: 0000000000000000 [54758.418326] R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000000000 [54758.418326] R13: 00005629a3996a80 R14: 0000000000000000 R15: 00005629a3996260 [54758.418346] BUG: unable to handle kernel paging request at 00000004ee194700 [54758.418348] #PF error: [WRITE] [54758.418349] PGD 0 P4D 0 [54758.418352] Oops: 0002 [#1] SMP PTI [54758.418354] CPU: 6 PID: 26746 Comm: insmod Tainted: G U OE 5.0.6-200.fc29.x86_64 #1 [54758.418355] Hardware name: Dell Inc. XPS 15 9560/05FFDN, BIOS 1.12.1 10/02/2018 [54758.418360] RIP: 0010:ttm_mem_global_init+0x1fe/0x2b0 [ttm] [54758.418361] Code: 00 00 00 48 89 5d 40 48 89 ab a0 00 00 00 e8 79 ba 95 f8 85 c0 0f 85 a2 00 00 00 8b 83 90 00 00 00 8d 50 01 89 93 90 00 00 00 <48> 89 ac c3 80 00 00 00 85 d2 0f 85 c6 99 00 00 48 8b 83 98 00 00 [54758.418363] RSP: 0018:ffffc24e53c1f988 EFLAGS: 00010246 [54758.418364] RAX: 00000000a5a2f300 RBX: ffffffffc101ae80 RCX: 0000000000000000 [54758.418366] RDX: 00000000a5a2f301 RSI: 0000000000000000 RDI: ffff9ebe78b67330 [54758.418367] RBP: ffff9ebe42c79d00 R08: 0000000000000044 R09: 0000000000000228 [54758.418368] R10: 0000000000000000 R11: ffff9ebb62720bb8 R12: 0000000000000000 [54758.418370] R13: ffff9ebe27d71640 R14: ffff9eba9f258600 R15: ffffffffc1453880 [54758.418371] FS: 00007fc0b379c280(0000) GS:ffff9ebeae380000(0000) knlGS:0000000000000000 [54758.418373] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [54758.418374] CR2: 00000004ee194700 CR3: 000000045069e005 CR4: 00000000003606e0 [54758.418375] Call Trace: [54758.418381] ttm_bo_device_init+0x198/0x2a0 [ttm] [54758.418439] nouveau_ttm_init+0xbf/0x340 [nouveau] [54758.418495] nouveau_drm_device_init+0x125/0x7d0 [nouveau] [54758.418499] ? pci_bus_read_config_word+0x49/0x70 [54758.418552] nouveau_drm_probe+0x26f/0x2c0 [nouveau] [54758.418556] local_pci_probe+0x41/0x90 [54758.418558] pci_device_probe+0x118/0x1a0 [54758.418561] really_probe+0xf8/0x3b0 [54758.418563] driver_probe_device+0xb3/0xf0 [54758.418565] __driver_attach+0xdd/0x110 [54758.418567] ? driver_probe_device+0xf0/0xf0 [54758.418570] bus_for_each_dev+0x77/0xc0 [54758.418573] ? klist_add_tail+0x3b/0x60 [54758.418574] bus_add_driver+0x152/0x230 [54758.418576] ? 0xffffffffc1027000 [54758.418578] driver_register+0x6b/0xb0 [54758.418580] ? 0xffffffffc1027000 [54758.418583] do_one_initcall+0x46/0x1c3 [54758.418585] ? _cond_resched+0x15/0x30 [54758.418587] ? kmem_cache_alloc_trace+0x154/0x1d0 [54758.418591] do_init_module+0x5a/0x210 [54758.418593] load_module+0x2096/0x22d0 [54758.418596] ? ima_post_read_file+0xf4/0x100 [54758.418599] ? __do_sys_finit_module+0xa8/0x110 [54758.418601] __do_sys_finit_module+0xa8/0x110 [54758.418604] do_syscall_64+0x5b/0x160 [54758.418607] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [54758.418609] RIP: 0033:0x7fc0b38b6edd [54758.418610] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 7b 7f 0c 00 f7 d8 64 89 01 48 [54758.418612] RSP: 002b:00007ffc7f1620d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 [54758.418614] RAX: ffffffffffffffda RBX: 00005629a3996ac0 RCX: 00007fc0b38b6edd [54758.418615] RDX: 0000000000000000 RSI: 00005629a3996260 RDI: 0000000000000003 [54758.418616] RBP: 00005629a3996260 R08: 0000000000000000 R09: 0000000000000000 [54758.418618] R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000000000 [54758.418619] R13: 00005629a3996a80 R14: 0000000000000000 R15: 00005629a3996260 [54758.418620] Modules linked in: nouveau(OE+) acpi_call(OE) ttm rfcomm ccm xt_CHECKSUM ipt_MASQUERADE tun bridge stp llc devlink ip6t_rpfilter ip6t_REJECT nf_reject_ipv6 xt_conntrack ebtable_nat ip6table_nat nf_nat_ipv6 ip6table_mangle ip6table_raw ip6table_security iptable_nat nf_nat_ipv4 nf_nat iptable_mangle iptable_raw iptable_security nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 libcrc32c ip_set nfnetlink ebtable_filter ebtables ip6table_filter ip6_tables cmac bnep sunrpc vfat fat btusb btrtl btbcm btintel uvcvideo videobuf2_vmalloc bluetooth videobuf2_memops videobuf2_v4l2 videobuf2_common videodev media ecdh_generic arc4 snd_hda_codec_hdmi ath10k_pci ath10k_core snd_hda_codec_realtek iTCO_wdt mei_wdt iTCO_vendor_support snd_hda_codec_generic mac80211 intel_rapl snd_hda_intel x86_pkg_temp_thermal intel_powerclamp coretemp snd_hda_codec dell_laptop ledtrig_audio dell_smm_hwmon snd_hda_core kvm_intel snd_hwdep ath snd_seq snd_seq_device intel_cstate cfg80211 snd_pcm dell_wmi intel_uncore [54758.418653] dell_smbios dcdbas intel_rapl_perf snd_timer joydev dell_wmi_descriptor intel_wmi_thunderbolt wmi_bmof snd idma64 soundcore i2c_i801 rfkill rtsx_pci_ms memstick mei_me mei processor_thermal_device intel_lpss_pci intel_soc_dts_iosf intel_pch_thermal intel_lpss int3400_thermal acpi_pad acpi_thermal_rel int3403_thermal intel_hid pcc_cpufreq int340x_thermal_zone sparse_keymap binfmt_misc zram dm_crypt hid_multitouch i915 kvmgt mdev vfio kvm irqbypass i2c_algo_bit crct10dif_pclmul drm_kms_helper rtsx_pci_sdmmc crc32_pclmul mmc_core crc32c_intel mxm_wmi drm nvme ghash_clmulni_intel nvme_core serio_raw rtsx_pci i2c_hid video wmi i2c_dev lz4 lz4_compress [last unloaded: nouveau] [54758.418679] CR2: 00000004ee194700 [54758.418681] ---[ end trace c5175234e6efc034 ]--- [54758.418686] RIP: 0010:ttm_mem_global_init+0x1fe/0x2b0 [ttm] [54758.418688] Code: 00 00 00 48 89 5d 40 48 89 ab a0 00 00 00 e8 79 ba 95 f8 85 c0 0f 85 a2 00 00 00 8b 83 90 00 00 00 8d 50 01 89 93 90 00 00 00 <48> 89 ac c3 80 00 00 00 85 d2 0f 85 c6 99 00 00 48 8b 83 98 00 00 [54758.418689] RSP: 0018:ffffc24e53c1f988 EFLAGS: 00010246 [54758.418690] RAX: 00000000a5a2f300 RBX: ffffffffc101ae80 RCX: 0000000000000000 [54758.418691] RDX: 00000000a5a2f301 RSI: 0000000000000000 RDI: ffff9ebe78b67330 [54758.418692] RBP: ffff9ebe42c79d00 R08: 0000000000000044 R09: 0000000000000228 [54758.418694] R10: 0000000000000000 R11: ffff9ebb62720bb8 R12: 0000000000000000 [54758.418695] R13: ffff9ebe27d71640 R14: ffff9eba9f258600 R15: ffffffffc1453880 [54758.418696] FS: 00007fc0b379c280(0000) GS:ffff9ebeae380000(0000) knlGS:0000000000000000 [54758.418698] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [54758.418699] CR2: 00000004ee194700 CR3: 000000045069e005 CR4: 00000000003606e0Karol Herbst (6):
Revert "drm: Remove drm_global.{c,h} v2"
Revert "drm/ttm: initialize globals during device init (v2)" Revert "drm/ttm: Fixbo_globalandmem_globalkfree error" Revert "drm/ttm: use a staticttm_bo_globalinstance" Revert "drm/ttm: make the device list mutex static" Revert "drm/ttm: use a staticttm_mem_globalinstance"drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 103 ++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 2 + drivers/gpu/drm/ast/ast_drv.h | 2 + drivers/gpu/drm/ast/ast_ttm.c | 64 ++++++++ drivers/gpu/drm/bochs/bochs.h | 2 + drivers/gpu/drm/bochs/bochs_mm.c | 61 ++++++++ drivers/gpu/drm/cirrus/cirrus_drv.h | 2 + drivers/gpu/drm/cirrus/cirrus_ttm.c | 64 ++++++++ drivers/gpu/drm/drm_drv.c | 2 + drivers/gpu/drm/drm_global.c | 137 ++++++++++++++++++ .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 + drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 57 ++++++++ drivers/gpu/drm/mgag200/mgag200_drv.h | 2 + drivers/gpu/drm/mgag200/mgag200_ttm.c | 64 ++++++++ drivers/gpu/drm/nouveau/nouveau_drv.h | 2 + drivers/gpu/drm/nouveau/nouveau_ttm.c | 67 +++++++++ drivers/gpu/drm/qxl/qxl_drv.h | 3 + drivers/gpu/drm/qxl/qxl_ttm.c | 61 ++++++++ drivers/gpu/drm/radeon/radeon.h | 3 + drivers/gpu/drm/radeon/radeon_ttm.c | 65 +++++++++ drivers/gpu/drm/ttm/ttm_bo.c | 67 +++------ drivers/gpu/drm/ttm/ttm_memory.c | 14 +- drivers/gpu/drm/virtio/virtgpu_drv.h | 3 + drivers/gpu/drm/virtio/virtgpu_ttm.c | 62 ++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 15 +- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 6 +- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 54 +++++++ drivers/staging/vboxvideo/vbox_drv.h | 2 + drivers/staging/vboxvideo/vbox_ttm.c | 65 ++++++++- include/drm/drmP.h | 1 +
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
include/drm/drm_global.h | 53 +++++++ include/drm/ttm/ttm_bo_driver.h | 54 ++++++- include/drm/ttm/ttm_memory.h | 4 +- 34 files changed, 1102 insertions(+), 65 deletions(-)create mode 100644
drivers/gpu/drm/drm_global.ccreate mode 100644include/drm/drm_global.h
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 38 lines · Christian
Am 16.04.19 um 11:10 schrieb Karol Herbst:
Quoted 27 lines
Quoted 25 lines · Christian König
Am 16.04.19 um 02:35 schrieb Karol Herbst:
Quoted 14 lines
Kobjects are supposed to be dynamically allocated, but with recent changes this rule was violated. Reverting those commits fixes crashes when a drm driver using TTM gets loaded again.
The object in question is "
ttm_mem_glob" declared inside "include/drm/ttm/ttm_memory.h" and instatiated inside "drivers/gpu/drm/ttm/ttm_memory.c".from "
Documentation/kobject.txt":
"Because kobjects are dynamic, they must not be declared statically or on the stack, but instead, always allocated dynamically. Future versions of the kernel will contain a run-time check for kobjects that are created statically and will warn the developer of this improper usage."Quoted 7 lines
Unloading ttm before reloading the driver workarounds that crash, because the memory backing the kobject member "kobj" is cleaned up. The
kobject_delandkobject_putfunction never free or clean up the kobject object leaving it in an undefined state.I reverted a few more commits to make it less painful for me to rever this rather big change.
Well, NAK. By reverting those change you also re-introduced the problems we originally fixed with those patches.
Quoted 8 lines
Quoted 2 lines
Please work on a proper fix instead,
Christian.And which problem was that besides duplicated code (or maybe even a bit of memory consumption if multiple ttm driver were used)? If I had to choose between duplicated code and a crash, I choose the former.
Maybe I missed the real reason why those changes are made, but the commit messages don't really seem to tell me.
Quoted 7 lines
The old implementation crashed because different drivers tried to allocate the same kobj.
Crashing in one way is not better than crashing in another way.
Christian.
how can that old crash be triggered? By loading two ttm based drivers at the same time or by other means?
Quoted 154 lines
Quoted 154 lines
Quoted 154 lines
Quoted 154 lines
dmesg output:
[54758.418036] kobject (00000000687a067d): tried to init an initialized object, something is seriously wrong. [54758.418040] CPU: 6 PID: 26746 Comm: insmod Tainted: G U OE 5.0.6-200.fc29.x86_64 #1 [54758.418041] Hardware name: Dell Inc. XPS 15 9560/05FFDN, BIOS 1.12.1 10/02/2018 [54758.418041] Call Trace: [54758.418049] dump_stack+0x5c/0x80 [54758.418054] kobject_init.cold.9+0x31/0x3f [54758.418057] kobject_init_and_add+0x35/0xa0 [54758.418063] ttm_mem_global_init+0x8f/0x2b0 [ttm] [54758.418067] ? __debugfs_create_file+0xe1/0x110 [54758.418071] ttm_bo_device_init+0x198/0x2a0 [ttm] [54758.418144] nouveau_ttm_init+0xbf/0x340 [nouveau] [54758.418206] nouveau_drm_device_init+0x125/0x7d0 [nouveau] [54758.418210] ? pci_bus_read_config_word+0x49/0x70 [54758.418266] nouveau_drm_probe+0x26f/0x2c0 [nouveau] [54758.418270] local_pci_probe+0x41/0x90 [54758.418272] pci_device_probe+0x118/0x1a0 [54758.418275] really_probe+0xf8/0x3b0 [54758.418277] driver_probe_device+0xb3/0xf0 [54758.418278] __driver_attach+0xdd/0x110 [54758.418280] ? driver_probe_device+0xf0/0xf0 [54758.418282] bus_for_each_dev+0x77/0xc0 [54758.418285] ? klist_add_tail+0x3b/0x60 [54758.418287] bus_add_driver+0x152/0x230 [54758.418288] ? 0xffffffffc1027000 [54758.418290] driver_register+0x6b/0xb0 [54758.418291] ? 0xffffffffc1027000 [54758.418294] do_one_initcall+0x46/0x1c3 [54758.418296] ? _cond_resched+0x15/0x30 [54758.418299] ? kmem_cache_alloc_trace+0x154/0x1d0 [54758.418302] do_init_module+0x5a/0x210 [54758.418304] load_module+0x2096/0x22d0 [54758.418308] ? ima_post_read_file+0xf4/0x100 [54758.418310] ? __do_sys_finit_module+0xa8/0x110 [54758.418312] __do_sys_finit_module+0xa8/0x110 [54758.418315] do_syscall_64+0x5b/0x160 [54758.418317] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [54758.418319] RIP: 0033:0x7fc0b38b6edd [54758.418321] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 7b 7f 0c 00 f7 d8 64 89 01 48 [54758.418322] RSP: 002b:00007ffc7f1620d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 [54758.418323] RAX: ffffffffffffffda RBX: 00005629a3996ac0 RCX: 00007fc0b38b6edd [54758.418324] RDX: 0000000000000000 RSI: 00005629a3996260 RDI: 0000000000000003 [54758.418325] RBP: 00005629a3996260 R08: 0000000000000000 R09: 0000000000000000 [54758.418326] R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000000000 [54758.418326] R13: 00005629a3996a80 R14: 0000000000000000 R15: 00005629a3996260 [54758.418346] BUG: unable to handle kernel paging request at 00000004ee194700 [54758.418348] #PF error: [WRITE] [54758.418349] PGD 0 P4D 0 [54758.418352] Oops: 0002 [#1] SMP PTI [54758.418354] CPU: 6 PID: 26746 Comm: insmod Tainted: G U OE 5.0.6-200.fc29.x86_64 #1 [54758.418355] Hardware name: Dell Inc. XPS 15 9560/05FFDN, BIOS 1.12.1 10/02/2018 [54758.418360] RIP: 0010:ttm_mem_global_init+0x1fe/0x2b0 [ttm] [54758.418361] Code: 00 00 00 48 89 5d 40 48 89 ab a0 00 00 00 e8 79 ba 95 f8 85 c0 0f 85 a2 00 00 00 8b 83 90 00 00 00 8d 50 01 89 93 90 00 00 00 <48> 89 ac c3 80 00 00 00 85 d2 0f 85 c6 99 00 00 48 8b 83 98 00 00 [54758.418363] RSP: 0018:ffffc24e53c1f988 EFLAGS: 00010246 [54758.418364] RAX: 00000000a5a2f300 RBX: ffffffffc101ae80 RCX: 0000000000000000 [54758.418366] RDX: 00000000a5a2f301 RSI: 0000000000000000 RDI: ffff9ebe78b67330 [54758.418367] RBP: ffff9ebe42c79d00 R08: 0000000000000044 R09: 0000000000000228 [54758.418368] R10: 0000000000000000 R11: ffff9ebb62720bb8 R12: 0000000000000000 [54758.418370] R13: ffff9ebe27d71640 R14: ffff9eba9f258600 R15: ffffffffc1453880 [54758.418371] FS: 00007fc0b379c280(0000) GS:ffff9ebeae380000(0000) knlGS:0000000000000000 [54758.418373] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [54758.418374] CR2: 00000004ee194700 CR3: 000000045069e005 CR4: 00000000003606e0 [54758.418375] Call Trace: [54758.418381] ttm_bo_device_init+0x198/0x2a0 [ttm] [54758.418439] nouveau_ttm_init+0xbf/0x340 [nouveau] [54758.418495] nouveau_drm_device_init+0x125/0x7d0 [nouveau] [54758.418499] ? pci_bus_read_config_word+0x49/0x70 [54758.418552] nouveau_drm_probe+0x26f/0x2c0 [nouveau] [54758.418556] local_pci_probe+0x41/0x90 [54758.418558] pci_device_probe+0x118/0x1a0 [54758.418561] really_probe+0xf8/0x3b0 [54758.418563] driver_probe_device+0xb3/0xf0 [54758.418565] __driver_attach+0xdd/0x110 [54758.418567] ? driver_probe_device+0xf0/0xf0 [54758.418570] bus_for_each_dev+0x77/0xc0 [54758.418573] ? klist_add_tail+0x3b/0x60 [54758.418574] bus_add_driver+0x152/0x230 [54758.418576] ? 0xffffffffc1027000 [54758.418578] driver_register+0x6b/0xb0 [54758.418580] ? 0xffffffffc1027000 [54758.418583] do_one_initcall+0x46/0x1c3 [54758.418585] ? _cond_resched+0x15/0x30 [54758.418587] ? kmem_cache_alloc_trace+0x154/0x1d0 [54758.418591] do_init_module+0x5a/0x210 [54758.418593] load_module+0x2096/0x22d0 [54758.418596] ? ima_post_read_file+0xf4/0x100 [54758.418599] ? __do_sys_finit_module+0xa8/0x110 [54758.418601] __do_sys_finit_module+0xa8/0x110 [54758.418604] do_syscall_64+0x5b/0x160 [54758.418607] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [54758.418609] RIP: 0033:0x7fc0b38b6edd [54758.418610] Code: 00 c3 66 2e 0f 1f 84 00 00 00 00 00 90 f3 0f 1e fa 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 7b 7f 0c 00 f7 d8 64 89 01 48 [54758.418612] RSP: 002b:00007ffc7f1620d8 EFLAGS: 00000246 ORIG_RAX: 0000000000000139 [54758.418614] RAX: ffffffffffffffda RBX: 00005629a3996ac0 RCX: 00007fc0b38b6edd [54758.418615] RDX: 0000000000000000 RSI: 00005629a3996260 RDI: 0000000000000003 [54758.418616] RBP: 00005629a3996260 R08: 0000000000000000 R09: 0000000000000000 [54758.418618] R10: 0000000000000003 R11: 0000000000000246 R12: 0000000000000000 [54758.418619] R13: 00005629a3996a80 R14: 0000000000000000 R15: 00005629a3996260 [54758.418620] Modules linked in: nouveau(OE+) acpi_call(OE) ttm rfcomm ccm xt_CHECKSUM ipt_MASQUERADE tun bridge stp llc devlink ip6t_rpfilter ip6t_REJECT nf_reject_ipv6 xt_conntrack ebtable_nat ip6table_nat nf_nat_ipv6 ip6table_mangle ip6table_raw ip6table_security iptable_nat nf_nat_ipv4 nf_nat iptable_mangle iptable_raw iptable_security nf_conntrack nf_defrag_ipv6 nf_defrag_ipv4 libcrc32c ip_set nfnetlink ebtable_filter ebtables ip6table_filter ip6_tables cmac bnep sunrpc vfat fat btusb btrtl btbcm btintel uvcvideo videobuf2_vmalloc bluetooth videobuf2_memops videobuf2_v4l2 videobuf2_common videodev media ecdh_generic arc4 snd_hda_codec_hdmi ath10k_pci ath10k_core snd_hda_codec_realtek iTCO_wdt mei_wdt iTCO_vendor_support snd_hda_codec_generic mac80211 intel_rapl snd_hda_intel x86_pkg_temp_thermal intel_powerclamp coretemp snd_hda_codec dell_laptop ledtrig_audio dell_smm_hwmon snd_hda_core kvm_intel snd_hwdep ath snd_seq snd_seq_device intel_cstate cfg80211 snd_pcm dell_wmi intel_uncore [54758.418653] dell_smbios dcdbas intel_rapl_perf snd_timer joydev dell_wmi_descriptor intel_wmi_thunderbolt wmi_bmof snd idma64 soundcore i2c_i801 rfkill rtsx_pci_ms memstick mei_me mei processor_thermal_device intel_lpss_pci intel_soc_dts_iosf intel_pch_thermal intel_lpss int3400_thermal acpi_pad acpi_thermal_rel int3403_thermal intel_hid pcc_cpufreq int340x_thermal_zone sparse_keymap binfmt_misc zram dm_crypt hid_multitouch i915 kvmgt mdev vfio kvm irqbypass i2c_algo_bit crct10dif_pclmul drm_kms_helper rtsx_pci_sdmmc crc32_pclmul mmc_core crc32c_intel mxm_wmi drm nvme ghash_clmulni_intel nvme_core serio_raw rtsx_pci i2c_hid video wmi i2c_dev lz4 lz4_compress [last unloaded: nouveau] [54758.418679] CR2: 00000004ee194700 [54758.418681] ---[ end trace c5175234e6efc034 ]--- [54758.418686] RIP: 0010:ttm_mem_global_init+0x1fe/0x2b0 [ttm] [54758.418688] Code: 00 00 00 48 89 5d 40 48 89 ab a0 00 00 00 e8 79 ba 95 f8 85 c0 0f 85 a2 00 00 00 8b 83 90 00 00 00 8d 50 01 89 93 90 00 00 00 <48> 89 ac c3 80 00 00 00 85 d2 0f 85 c6 99 00 00 48 8b 83 98 00 00 [54758.418689] RSP: 0018:ffffc24e53c1f988 EFLAGS: 00010246 [54758.418690] RAX: 00000000a5a2f300 RBX: ffffffffc101ae80 RCX: 0000000000000000 [54758.418691] RDX: 00000000a5a2f301 RSI: 0000000000000000 RDI: ffff9ebe78b67330 [54758.418692] RBP: ffff9ebe42c79d00 R08: 0000000000000044 R09: 0000000000000228 [54758.418694] R10: 0000000000000000 R11: ffff9ebb62720bb8 R12: 0000000000000000 [54758.418695] R13: ffff9ebe27d71640 R14: ffff9eba9f258600 R15: ffffffffc1453880 [54758.418696] FS: 00007fc0b379c280(0000) GS:ffff9ebeae380000(0000) knlGS:0000000000000000 [54758.418698] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [54758.418699] CR2: 00000004ee194700 CR3: 000000045069e005 CR4: 00000000003606e0Karol Herbst (6):
Revert "drm: Remove drm_global.{c,h} v2"
Revert "drm/ttm: initialize globals during device init (v2)" Revert "drm/ttm: Fixbo_globalandmem_globalkfree error" Revert "drm/ttm: use a staticttm_bo_globalinstance" Revert "drm/ttm: make the device list mutex static" Revert "drm/ttm: use a staticttm_mem_globalinstance"drivers/gpu/drm/Makefile | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 103 ++++++++++++- drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 2 + drivers/gpu/drm/ast/ast_drv.h | 2 + drivers/gpu/drm/ast/ast_ttm.c | 64 ++++++++ drivers/gpu/drm/bochs/bochs.h | 2 + drivers/gpu/drm/bochs/bochs_mm.c | 61 ++++++++ drivers/gpu/drm/cirrus/cirrus_drv.h | 2 + drivers/gpu/drm/cirrus/cirrus_ttm.c | 64 ++++++++ drivers/gpu/drm/drm_drv.c | 2 + drivers/gpu/drm/drm_global.c | 137 ++++++++++++++++++ .../gpu/drm/hisilicon/hibmc/hibmc_drm_drv.h | 2 + drivers/gpu/drm/hisilicon/hibmc/hibmc_ttm.c | 57 ++++++++ drivers/gpu/drm/mgag200/mgag200_drv.h | 2 + drivers/gpu/drm/mgag200/mgag200_ttm.c | 64 ++++++++ drivers/gpu/drm/nouveau/nouveau_drv.h | 2 + drivers/gpu/drm/nouveau/nouveau_ttm.c | 67 +++++++++ drivers/gpu/drm/qxl/qxl_drv.h | 3 + drivers/gpu/drm/qxl/qxl_ttm.c | 61 ++++++++ drivers/gpu/drm/radeon/radeon.h | 3 + drivers/gpu/drm/radeon/radeon_ttm.c | 65 +++++++++ drivers/gpu/drm/ttm/ttm_bo.c | 67 +++------ drivers/gpu/drm/ttm/ttm_memory.c | 14 +- drivers/gpu/drm/virtio/virtgpu_drv.h | 3 + drivers/gpu/drm/virtio/virtgpu_ttm.c | 62 ++++++++ drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 15 +- drivers/gpu/drm/vmwgfx/vmwgfx_drv.h | 6 +- drivers/gpu/drm/vmwgfx/vmwgfx_ttm_glue.c | 54 +++++++ drivers/staging/vboxvideo/vbox_drv.h | 2 + drivers/staging/vboxvideo/vbox_ttm.c | 65 ++++++++- include/drm/drmP.h | 1 +
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
include/drm/drm_global.h | 53 +++++++ include/drm/ttm/ttm_bo_driver.h | 54 ++++++- include/drm/ttm/ttm_memory.h | 4 +- 34 files changed, 1102 insertions(+), 65 deletions(-)create mode 100644
drivers/gpu/drm/drm_global.ccreate mode 100644include/drm/drm_global.h
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Koenig, Christian
maintainerAm 16.04.19 um 12:54 schrieb Karol Herbst:
Quoted 41 lines
Quoted 39 lines · Christian
Am 16.04.19 um 11:10 schrieb Karol Herbst:
Quoted 27 lines
Quoted 25 lines · Christian König
Am 16.04.19 um 02:35 schrieb Karol Herbst:
Quoted 14 lines
Kobjects are supposed to be dynamically allocated, but with recent changes this rule was violated. Reverting those commits fixes crashes when a drm driver using TTM gets loaded again.
The object in question is "
ttm_mem_glob" declared inside "include/drm/ttm/ttm_memory.h" and instatiated inside "drivers/gpu/drm/ttm/ttm_memory.c".from "
Documentation/kobject.txt":
"Because kobjects are dynamic, they must not be declared statically or on the stack, but instead, always allocated dynamically. Future versions of the kernel will contain a run-time check for kobjects that are created statically and will warn the developer of this improper usage."Quoted 7 lines
Unloading ttm before reloading the driver workarounds that crash, because the memory backing the kobject member "kobj" is cleaned up. The
kobject_delandkobject_putfunction never free or clean up the kobject object leaving it in an undefined state.I reverted a few more commits to make it less painful for me to rever this rather big change.
Well, NAK. By reverting those change you also re-introduced the problems we originally fixed with those patches.
Quoted 8 lines
Quoted 2 lines
Please work on a proper fix instead,
Christian.And which problem was that besides duplicated code (or maybe even a bit of memory consumption if multiple ttm driver were used)? If I had to choose between duplicated code and a crash, I choose the former.
Maybe I missed the real reason why those changes are made, but the commit messages don't really seem to tell me.
The old implementation crashed because different drivers tried to allocate the same kobj.
Quoted 6 lines
Quoted 4 lines
Crashing in one way is not better than crashing in another way.
Christian.
how can that old crash be triggered? By loading two ttm based drivers at the same time or by other means?
Yes, exactly. Even worse it could be triggered by one driver instantiating multiple times at the same time, e.g two AMD GPUs in the same system.
On the other hand I completely agree that using kobj static is completely nuts. The problem is that using a kobj was the wrong approach in the first place.
In other words when you have something which controls a global behavior of a module, what do you use? Right, a module parameter.
Point is that we can't get away from those kobj without breaking the uapi, so that is something which can't be done easily.
Regards,
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 58 lines · Christian
Am 16.04.19 um 12:54 schrieb Karol Herbst:
Quoted 41 lines
Quoted 39 lines · Christian
Am 16.04.19 um 11:10 schrieb Karol Herbst:
Quoted 27 lines
Quoted 25 lines · Christian König
Am 16.04.19 um 02:35 schrieb Karol Herbst:
Quoted 14 lines
Kobjects are supposed to be dynamically allocated, but with recent changes this rule was violated. Reverting those commits fixes crashes when a drm driver using TTM gets loaded again.
The object in question is "
ttm_mem_glob" declared inside "include/drm/ttm/ttm_memory.h" and instatiated inside "drivers/gpu/drm/ttm/ttm_memory.c".from "
Documentation/kobject.txt":
"Because kobjects are dynamic, they must not be declared statically or on the stack, but instead, always allocated dynamically. Future versions of the kernel will contain a run-time check for kobjects that are created statically and will warn the developer of this improper usage."Quoted 7 lines
Unloading ttm before reloading the driver workarounds that crash, because the memory backing the kobject member "kobj" is cleaned up. The
kobject_delandkobject_putfunction never free or clean up the kobject object leaving it in an undefined state.I reverted a few more commits to make it less painful for me to rever this rather big change.
Well, NAK. By reverting those change you also re-introduced the problems we originally fixed with those patches.
Quoted 8 lines
Quoted 2 lines
Please work on a proper fix instead,
Christian.And which problem was that besides duplicated code (or maybe even a bit of memory consumption if multiple ttm driver were used)? If I had to choose between duplicated code and a crash, I choose the former.
Maybe I missed the real reason why those changes are made, but the commit messages don't really seem to tell me.
The old implementation crashed because different drivers tried to allocate the same kobj.
Quoted 6 lines
Quoted 4 lines
Crashing in one way is not better than crashing in another way.
Christian.
how can that old crash be triggered? By loading two ttm based drivers at the same time or by other means?
Yes, exactly. Even worse it could be triggered by one driver instantiating multiple times at the same time, e.g two AMD GPUs in the same system.
On the other hand I completely agree that using kobj static is completely nuts. The problem is that using a kobj was the wrong approach in the first place.
Quoted 8 lines
In other words when you have something which controls a global behavior of a module, what do you use? Right, a module parameter.
Point is that we can't get away from those kobj without breaking the uapi, so that is something which can't be done easily.
Regards,
Christian.
okay, thanks for the explanation!
Currently I will be testing your first patch you sent out on top of 5.0.7, so that we could propose that for stable. The second didn't apply, but it didn't look relevant for the actual fix. Will reply to the patch with my results then.
Thanks
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 16.04.19 um 13:20 schrieb Karol Herbst:
Quoted 64 lines
Quoted 62 lines · Christian
Am 16.04.19 um 12:54 schrieb Karol Herbst:
Quoted 41 lines
Quoted 39 lines · Christian
Am 16.04.19 um 11:10 schrieb Karol Herbst:
Quoted 27 lines
Quoted 25 lines · Christian König
Am 16.04.19 um 02:35 schrieb Karol Herbst:
Quoted 14 lines
Kobjects are supposed to be dynamically allocated, but with recent changes this rule was violated. Reverting those commits fixes crashes when a drm driver using TTM gets loaded again.
The object in question is "
ttm_mem_glob" declared inside "include/drm/ttm/ttm_memory.h" and instatiated inside "drivers/gpu/drm/ttm/ttm_memory.c".from "
Documentation/kobject.txt":
"Because kobjects are dynamic, they must not be declared statically or on the stack, but instead, always allocated dynamically. Future versions of the kernel will contain a run-time check for kobjects that are created statically and will warn the developer of this improper usage."Quoted 7 lines
Unloading ttm before reloading the driver workarounds that crash, because the memory backing the kobject member "kobj" is cleaned up. The
kobject_delandkobject_putfunction never free or clean up the kobject object leaving it in an undefined state.I reverted a few more commits to make it less painful for me to rever this rather big change.
Well, NAK. By reverting those change you also re-introduced the problems we originally fixed with those patches.
Quoted 8 lines
Quoted 2 lines
Please work on a proper fix instead,
Christian.And which problem was that besides duplicated code (or maybe even a bit of memory consumption if multiple ttm driver were used)? If I had to choose between duplicated code and a crash, I choose the former.
Maybe I missed the real reason why those changes are made, but the commit messages don't really seem to tell me.
The old implementation crashed because different drivers tried to allocate the same kobj.
Quoted 6 lines
Quoted 4 lines
Crashing in one way is not better than crashing in another way.
Christian.
how can that old crash be triggered? By loading two ttm based drivers at the same time or by other means?
Yes, exactly. Even worse it could be triggered by one driver instantiating multiple times at the same time, e.g two AMD GPUs in the same system.
On the other hand I completely agree that using kobj static is completely nuts. The problem is that using a kobj was the wrong approach in the first place.
In other words when you have something which controls a global behavior of a module, what do you use? Right, a module parameter.
Point is that we can't get away from those kobj without breaking the uapi, so that is something which can't be done easily.
Quoted 8 lines
Quoted 2 lines
Regards,
Christian.okay, thanks for the explanation!
Currently I will be testing your first patch you sent out on top of 5.0.7, so that we could propose that for stable. The second didn't apply, but it didn't look relevant for the actual fix. Will reply to the patch with my results then.
The second is just a further clean, please ignore that one for backporting.
Let me know if the first one works on 5.0.7, if yes I'm going to add a CC stable tag before pushing.
Thanks,
Christian.
Quoted 6 lines
Thanks
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 57 lines · Christian
Am 16.04.19 um 12:54 schrieb Karol Herbst:
Quoted 41 lines
Quoted 39 lines · Christian
Am 16.04.19 um 11:10 schrieb Karol Herbst:
Quoted 27 lines
Quoted 25 lines · Christian König
Am 16.04.19 um 02:35 schrieb Karol Herbst:
Quoted 14 lines
Kobjects are supposed to be dynamically allocated, but with recent changes this rule was violated. Reverting those commits fixes crashes when a drm driver using TTM gets loaded again.
The object in question is "
ttm_mem_glob" declared inside "include/drm/ttm/ttm_memory.h" and instatiated inside "drivers/gpu/drm/ttm/ttm_memory.c".from "
Documentation/kobject.txt":
"Because kobjects are dynamic, they must not be declared statically or on the stack, but instead, always allocated dynamically. Future versions of the kernel will contain a run-time check for kobjects that are created statically and will warn the developer of this improper usage."Quoted 7 lines
Unloading ttm before reloading the driver workarounds that crash, because the memory backing the kobject member "kobj" is cleaned up. The
kobject_delandkobject_putfunction never free or clean up the kobject object leaving it in an undefined state.I reverted a few more commits to make it less painful for me to rever this rather big change.
Well, NAK. By reverting those change you also re-introduced the problems we originally fixed with those patches.
Quoted 8 lines
Quoted 2 lines
Please work on a proper fix instead,
Christian.And which problem was that besides duplicated code (or maybe even a bit of memory consumption if multiple ttm driver were used)? If I had to choose between duplicated code and a crash, I choose the former.
Maybe I missed the real reason why those changes are made, but the commit messages don't really seem to tell me.
The old implementation crashed because different drivers tried to allocate the same kobj.
Quoted 6 lines
Quoted 4 lines
Crashing in one way is not better than crashing in another way.
Christian.
how can that old crash be triggered? By loading two ttm based drivers at the same time or by other means?
Yes, exactly. Even worse it could be triggered by one driver instantiating multiple times at the same time, e.g two AMD GPUs in the same system.
On the other hand I completely agree that using kobj static is completely nuts. The problem is that using a kobj was the wrong approach in the first place.
Quoted 5 lines
In other words when you have something which controls a global behavior of a module, what do you use? Right, a module parameter.
Point is that we can't get away from those kobj without breaking the uapi, so that is something which can't be done easily.
Randome idea: Push the kobj setup into drm.ko (and shrugg it off as another lesson in how maybe uapi shouldn't have been designed, but hey not our worst mistake by far). I think that'd be totally ok. -Daniel
Signature · 7 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Koenig, Christian
maintainerAm 16.04.19 um 14:18 schrieb Daniel Vetter:
Quoted 57 lines · Christian
Quoted 56 lines
Am 16.04.19 um 12:54 schrieb Karol Herbst:
Quoted 41 lines
Quoted 39 lines · Christian
Am 16.04.19 um 11:10 schrieb Karol Herbst:
Quoted 27 lines
Quoted 25 lines · Christian König
Am 16.04.19 um 02:35 schrieb Karol Herbst:
Quoted 14 lines
Kobjects are supposed to be dynamically allocated, but with recent changes this rule was violated. Reverting those commits fixes crashes when a drm driver using TTM gets loaded again.
The object in question is "
ttm_mem_glob" declared inside "include/drm/ttm/ttm_memory.h" and instatiated inside "drivers/gpu/drm/ttm/ttm_memory.c".from "
Documentation/kobject.txt":
"Because kobjects are dynamic, they must not be declared statically or on the stack, but instead, always allocated dynamically. Future versions of the kernel will contain a run-time check for kobjects that are created statically and will warn the developer of this improper usage."Quoted 7 lines
Unloading ttm before reloading the driver workarounds that crash, because the memory backing the kobject member "kobj" is cleaned up. The
kobject_delandkobject_putfunction never free or clean up the kobject object leaving it in an undefined state.I reverted a few more commits to make it less painful for me to rever this rather big change.
Well, NAK. By reverting those change you also re-introduced the problems we originally fixed with those patches.
Quoted 8 lines
Quoted 2 lines
Please work on a proper fix instead,
Christian.And which problem was that besides duplicated code (or maybe even a bit of memory consumption if multiple ttm driver were used)? If I had to choose between duplicated code and a crash, I choose the former.
Maybe I missed the real reason why those changes are made, but the commit messages don't really seem to tell me.
The old implementation crashed because different drivers tried to allocate the same kobj.
Quoted 6 lines
Quoted 4 lines
Crashing in one way is not better than crashing in another way.
Christian.
how can that old crash be triggered? By loading two ttm based drivers at the same time or by other means?
Yes, exactly. Even worse it could be triggered by one driver instantiating multiple times at the same time, e.g two AMD GPUs in the same system.
On the other hand I completely agree that using kobj static is completely nuts. The problem is that using a kobj was the wrong approach in the first place.
Quoted 8 lines
Quoted 5 lines
In other words when you have something which controls a global behavior of a module, what do you use? Right, a module parameter.
Point is that we can't get away from those kobj without breaking the uapi, so that is something which can't be done easily.
Randome idea: Push the kobj setup into drm.ko (and shrugg it off as another lesson in how maybe uapi shouldn't have been designed, but hey not our worst mistake by far). I think that'd be totally ok.
Yeah, thought about that as well.
But I would rather re-design this from the scratch instead of just moving it over.
And yes I agree with a bit of luck that UAPI is actually not used at all, so we could remove it sooner or later.
Regards,
Christian.
Quoted 1 line
-Daniel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 20 lines · Christian König
Am 16.04.19 um 02:35 schrieb Karol Herbst:
Quoted 19 lines
Kobjects are supposed to be dynamically allocated, but with recent changes this rule was violated. Reverting those commits fixes crashes when a drm driver using TTM gets loaded again.
The object in question is "
ttm_mem_glob" declared inside "include/drm/ttm/ttm_memory.h" and instatiated inside "drivers/gpu/drm/ttm/ttm_memory.c".from "
Documentation/kobject.txt":
"Because kobjects are dynamic, they must not be declared statically or on the stack, but instead, always allocated dynamically. Future versions of the kernel will contain a run-time check for kobjects that are created statically and will warn the developer of this improper usage."Unloading ttm before reloading the driver workarounds that crash, because the memory backing the kobject member "kobj" is cleaned up. The
kobject_delandkobject_putfunction never free or clean up the kobject object leaving it in an undefined state.
Quoted 7 lines
Quoted 2 lines
I reverted a few more commits to make it less painful for me to rever this rather big change.
Well, NAK. By reverting those change you also re-introduced the problems we originally fixed with those patches.
Please work on a proper fix instead,
That's not Karol's responsibility, that's yours as the author. I would like to remind about Linux's regressions policy, quoting from Documentation/process/4.Coding.rst:
"One final hazard worth mentioning is this: it can be tempting to make a change (which may bring big improvements) which causes something to break for existing users. This kind of change is called a "regression," and regressions have become most unwelcome in the mainline kernel. With few exceptions, changes which cause regressions will be backed out if the regression cannot be fixed in a timely manner. Far better to avoid the regression in the first place.
It is often argued that a regression can be justified if it causes things to work for more people than it creates problems for. Why not make a change if it brings new functionality to ten systems for each one it breaks? The best answer to this question was expressed by Linus in July, 2007:
::
So we don't fix bugs by introducing new problems. That way lies madness, and nobody ever knows if you actually make any real progress at all. Is it two steps forwards, one step back, or one step forward and two steps back?"
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 49 lines · Eric Anholt
Quoted 20 lines · Christian König
Am 16.04.19 um 02:35 schrieb Karol Herbst:
Quoted 19 lines
Kobjects are supposed to be dynamically allocated, but with recent changes this rule was violated. Reverting those commits fixes crashes when a drm driver using TTM gets loaded again.
The object in question is "
ttm_mem_glob" declared inside "include/drm/ttm/ttm_memory.h" and instatiated inside "drivers/gpu/drm/ttm/ttm_memory.c".from "
Documentation/kobject.txt":
"Because kobjects are dynamic, they must not be declared statically or on the stack, but instead, always allocated dynamically. Future versions of the kernel will contain a run-time check for kobjects that are created statically and will warn the developer of this improper usage."Unloading ttm before reloading the driver workarounds that crash, because the memory backing the kobject member "kobj" is cleaned up. The
kobject_delandkobject_putfunction never free or clean up the kobject object leaving it in an undefined state.Quoted 7 lines
Quoted 2 lines
I reverted a few more commits to make it less painful for me to rever this rather big change.
Well, NAK. By reverting those change you also re-introduced the problems we originally fixed with those patches.
Please work on a proper fix instead,
That's not Karol's responsibility, that's yours as the author. I would like to remind about Linux's regressions policy, quoting from
Documentation/process/4.Coding.rst:"One final hazard worth mentioning is this: it can be tempting to make a change (which may bring big improvements) which causes something to break for existing users. This kind of change is called a "regression," and regressions have become most unwelcome in the mainline kernel. With few exceptions, changes which cause regressions will be backed out if the regression cannot be fixed in a timely manner. Far better to avoid the regression in the first place.
It is often argued that a regression can be justified if it causes things to work for more people than it creates problems for. Why not make a change if it brings new functionality to ten systems for each one it breaks? The best answer to this question was expressed by Linus in July, 2007:
Quoted 6 lines
::
So we don't fix bugs by introducing new problems. That way lies madness, and nobody ever knows if you actually make any real progress at all. Is it two steps forwards, one step back, or one step forward and two steps back?"
he already wrote a fix. Search for "[PATCH 1/2] drm/ttm: fix re-init of global structures"
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel