Home | History | Annotate | Download | only in linux
History log of /src/sys/external/bsd/drm2/linux/linux_ww_mutex.c
RevisionDateAuthorComments
 1.16  29-Jul-2023  riastradh drm/linux_ww_mutex: Fix ww acquire context ordering.

XXX pullup-8
XXX pullup-9
XXX pullup-10
 1.15  29-Jul-2023  riastradh drm/linux_ww_mutex: Fix wait loops.

If cv_wait_sig returns because a signal is delivered, we may
nonetheless have been granted the lock. It is harmless for us to
ignore this fact in three of the four paths, but in
ww_mutex_state_wait_sig, we may now have ownership of the lock and
MUST NOT return failure because the caller MUST release the lock
before destroying the ww_acquire_ctx.

While here, restructure the other three loops for clarity, so they
match the structure of the fourth and so they have a little less
impenetrable negation.

PR kern/57537

XXX pullup-8
XXX pullup-9
XXX pullup-10
 1.14  18-Mar-2022  riastradh branches: 1.14.4;
drm: In ww_mutex_unlock, do lockdebug check first.

This way we get a full lockdebug dump when LOCKDEBUG is enabled,
instead of just the panic message (which includes the lock address
you could pass to `show lock' in ddb, but let's get the dump by
default even if you don't enter ddb).

Also in the KASSERT print the mutex.
 1.13  26-Dec-2021  riastradh drm: Allow ww_mutex_lock after ww_acquire_done if we already hold it.

In other words, if ww_mutex_lock would return -EALREADY, that's OK and
does not warrant an assertion.

PR kern/56557
 1.12  24-Dec-2021  riastradh Revert "drm: Fix missing newline in DRM_WARN."

Accidentally included more than I intended here.
 1.11  24-Dec-2021  riastradh drm: Fix missing newline in DRM_WARN.
 1.10  19-Dec-2021  riastradh drm: Spruce up ww_mutex comments. Audit return values.
 1.9  19-Dec-2021  riastradh linux/ww_mutex: Disable locking-against-self asserts in trylock.

This seems to be done intentionally in Linux.
 1.8  19-Dec-2021  riastradh Implement dma_resv_locking_ctx more carefully.
 1.7  09-May-2019  ozaki-r branches: 1.7.2;
Avoid prepending a timestamp to lock debug outputs on ddb

Lock printer functions (lockops_t#lo_dump) use printf_nolog to print, but
printf_nolog now prepends a timestamp which is unnecessary for ddb:

db{0}> show all locks/t
[Locks tracked through LWPs]
Locks held by an LWP (iperf):
Lock 0 (initialized at soinit)
lock address : 0xffffedeb84b06080 type : sleep/adaptive
initialized : 0xffffffff806d8c3f
shared holds : 0 exclusive: 1
shares wanted: 0 exclusive: 11
current cpu : 0 last held: 1
current lwp : 0xffffedeb849ff040 last held: 0xffffedeb7dfdb240
last locked* : 0xffffffff806d8335 unlocked : 0xffffffff806d8385
[ 79103.0868574] owner field : 0xffffedeb7dfdb240 wait/spin: 1/0

Fix it by passing a printer function to lo_dump functions, i.e., make the
functions use db_printf on ddb.
 1.6  16-Apr-2019  mrg fix various problems i've seen where cv_*wait*() return ERESTART,
which is -3 in netbsd, which we have mapped linux ERESTARTSYS to.

this has a problem because linux code often returns errors and
pointers in the same value, and pointer values between -4095 and
-1 are considered as error returns, but -3 ends up as 3 and thus
is not considered an error, and mayhem ensues.

with this in place my kabylake system seems actually stable, i
have not triggered any of my prior issues in almost 4 weeks now.


Taylor asked me to write up a description and then wrote most of
the text below for me :-)


In Linux code, we always work with ERESTARTSYS so the code meaning
start over is a positive NetBSD errno safe for PTR_ERR/ERR_PTR.
To achieve this:
1. adapt all cv_waits that return to Linux so they map ERESTART to
ERESTARTSYS, and
2. adapt all returns to userland so they convert ERESTARTSYS to
ERESTART.
Leave EINTR and all other error codes alone.
 1.5  27-Aug-2018  riastradh Use Linux atomic64 for ww mutex class.

This way we can take advantage of the hash-locked atomic64 on
platforms that lack native atomic_inc_64_nv.
 1.4  16-Sep-2017  christos branches: 1.4.2; 1.4.4; 1.4.6;
more const
 1.3  25-Aug-2017  riastradh Fix lockdebug_locked annotations.

When thread A grants ownership to thread B waiting with a context,
thread B needs to assert lockdebug_locked; otherwise, when it
releases, lockdebug_unlocked thinks it's releasing an unlocked
ww_mutex.

Fixes LOCKDEBUG failure with radeon noticed by martin@.
 1.2  21-May-2015  riastradh branches: 1.2.10;
Adapt ww_mutex to use LOCKDEBUG.

Should help track down PR 49862.
 1.1  08-Jan-2015  riastradh branches: 1.1.2; 1.1.4;
Move Linux ww_mutex code into a .c file where it belongs.
 1.1.4.4  28-Aug-2017  skrll Sync with HEAD
 1.1.4.3  06-Jun-2015  skrll Sync with HEAD
 1.1.4.2  06-Apr-2015  skrll Sync with HEAD
 1.1.4.1  08-Jan-2015  skrll file linux_ww_mutex.c was added on branch nick-nhusb on 2015-04-06 15:18:17 +0000
 1.1.2.3  30-Jul-2015  snj Pull up following revision(s) (requested by riastradh in ticket #907):
sys/external/bsd/drm2/linux/linux_ww_mutex.c: revision 1.2
sys/external/bsd/drm2/include/linux/ww_mutex.h: revision 1.11
Adapt ww_mutex to use LOCKDEBUG.
Should help track down PR 49862.
 1.1.2.2  06-Mar-2015  snj Pull up following revision(s) (requested by mrg in ticket #573):
sys/external/bsd/common/include/linux/kernel.h: 1.5, 1.6
sys/external/bsd/drm2/dist/drm/drm_ioctl.c: 1.4
sys/external/bsd/drm2/dist/drm/drm_irq.c: 1.6-1.8
sys/external/bsd/drm2/dist/drm/i915/i915_dma.c: 1.13-1.15
sys/external/bsd/drm2/dist/drm/i915/i915_gem.c: 1.23-1.27
sys/external/bsd/drm2/dist/drm/i915/i915_gem_execbuffer.c: 1.5
sys/external/bsd/drm2/dist/drm/i915/intel_display.c: 1.14, 1.15
sys/external/bsd/drm2/dist/drm/i915/intel_dp.c: 1.10
sys/external/bsd/drm2/dist/drm/i915/intel_drv.h: 1.8
sys/external/bsd/drm2/dist/drm/i915/intel_i2c.c: 1.8-1.13
sys/external/bsd/drm2/dist/drm/i915/intel_pm.c: 1.6
sys/external/bsd/drm2/dist/drm/i915/intel_ringbuffer.c: 1.5, 1.6
sys/external/bsd/drm2/dist/drm/nouveau/core/engine/device/nouveau_engine_device_base.c: 1.4
sys/external/bsd/drm2/dist/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nvc0.c: 1.3, 1.4
sys/external/bsd/drm2/dist/drm/nouveau/core/engine/fifo/nouveau_engine_fifo_nve0.c: 1.3, 1.4
sys/external/bsd/drm2/dist/drm/nouveau/core/include/core/device.h: 1.4
sys/external/bsd/drm2/dist/drm/nouveau/core/include/subdev/mc.h: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/core/include/subdev/pwr.h: 1.3, 1.4
sys/external/bsd/drm2/dist/drm/nouveau/core/os.h: 1.4, 1.5
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/bios/nouveau_subdev_bios_base.c: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/bios/nouveau_subdev_bios_pll.c: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/clock/nouveau_subdev_clock_base.c: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/clock/nouveau_subdev_clock_nv50.c: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/devinit/fbmem.h: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/devinit/nouveau_subdev_devinit_nv04.c: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/fb/nouveau_subdev_fb_nv50.c: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/fb/nouveau_subdev_fb_nvc0.c: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/fb/nv50.h: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/fb/nvc0.h: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/mc/nouveau_subdev_mc_base.c: 1.2, 1.3
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/mxm/nouveau_subdev_mxm_nv50.c: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/pwr/nouveau_subdev_pwr_base.c: 1.3, 1.4
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/therm/nouveau_subdev_therm_ic.c: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/timer/nouveau_subdev_timer_nv04.c: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/vm/nouveau_subdev_vm_base.c: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/vm/nouveau_subdev_vm_nv04.c: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/vm/nouveau_subdev_vm_nv44.c: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/core/subdev/vm/nv04.h: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/nouveau_bo.h: 1.3
sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c: 1.4, 1.5
sys/external/bsd/drm2/dist/drm/nouveau/nouveau_fbcon.c: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/nouveau_nv50_display.c: 1.3
sys/external/bsd/drm2/dist/drm/nouveau/nouveau_nv84_fence.c: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/nouveau_ttm.c: 1.3
sys/external/bsd/drm2/dist/drm/nouveau/nouveau_ttm.h: 1.2
sys/external/bsd/drm2/dist/drm/nouveau/nouveau_vga.h: 1.2
sys/external/bsd/drm2/dist/drm/radeon/radeon_fence.c: 1.6-1.8
sys/external/bsd/drm2/dist/drm/radeon/radeon_pm.c: 1.3
sys/external/bsd/drm2/dist/drm/radeon/rs400.c: 1.3
sys/external/bsd/drm2/dist/drm/via/via_dmablit.c: 1.3, 1.4
sys/external/bsd/drm2/dist/drm/via/via_drv.h: 1.3
sys/external/bsd/drm2/dist/drm/via/via_irq.c: 1.3, 1.4
sys/external/bsd/drm2/dist/drm/via/via_video.c: 1.3, 1.4
sys/external/bsd/drm2/dist/include/drm/drmP.h: 1.10
sys/external/bsd/drm2/dist/include/drm/drm_crtc.h: 1.4
sys/external/bsd/drm2/dist/include/drm/drm_modes.h: 1.3
sys/external/bsd/drm2/dist/uapi/drm/i915_drm.h: 1.2
sys/external/bsd/drm2/drm/drm_cache.c: 1.4-1.6
sys/external/bsd/drm2/drm/drm_drv.c: 1.14
sys/external/bsd/drm2/drm/drm_module.c: 1.10
sys/external/bsd/drm2/drm/drm_sysctl.c: 1.5
sys/external/bsd/drm2/drm/drm_vma_manager.c: 1.2
sys/external/bsd/drm2/drm/drmfb.c: 1.1
sys/external/bsd/drm2/drm/files.drmkms: 1.10, 1.11
sys/external/bsd/drm2/i2c/drm_encoder_slave.c: 1.1
sys/external/bsd/drm2/i915drm/files.i915drmkms: 1.7, 1.10
sys/external/bsd/drm2/i915drm/intelfb.c: 1.11, 1.12
sys/external/bsd/drm2/include/asm/io.h: 1.4
sys/external/bsd/drm2/include/asm/unaligned.h: 1.2, 1.3
sys/external/bsd/drm2/include/drm/drm_encoder_slave.h: 1.1
sys/external/bsd/drm2/include/drm/drm_wait_netbsd.h: 1.7-1.11
sys/external/bsd/drm2/include/drm/drmfb.h: 1.1
sys/external/bsd/drm2/include/drm/drmfb_pci.h: 1.1, 1.2
sys/external/bsd/drm2/include/linux/bitops.h: 1.9
sys/external/bsd/drm2/include/linux/i2c.h: 1.7, 1.8
sys/external/bsd/drm2/include/linux/io-mapping.h: 1.5
sys/external/bsd/drm2/include/linux/moduleparam.h: 1.5
sys/external/bsd/drm2/include/linux/pci.h: 1.12-1.15
sys/external/bsd/drm2/include/linux/pm.h: 1.4
sys/external/bsd/drm2/include/linux/reboot.h: 1.2
sys/external/bsd/drm2/include/linux/slab.h: 1.5
sys/external/bsd/drm2/include/linux/string.h: 1.4
sys/external/bsd/drm2/include/linux/vgaarb.h: 1.3
sys/external/bsd/drm2/include/linux/ww_mutex.h: 1.10
sys/external/bsd/drm2/linux/files.drmkms_linux: 1.8
sys/external/bsd/drm2/linux/linux_i2c.c: 1.3
sys/external/bsd/drm2/linux/linux_ww_mutex.c: 1.1
sys/external/bsd/drm2/nouveau/files.nouveau: 1.5-1.8
sys/external/bsd/drm2/nouveau/nouveau_pci.c: 1.1-1.3
sys/external/bsd/drm2/nouveau/nouveau_pci.h: 1.1
sys/external/bsd/drm2/nouveau/nouveau_sysfs.c: 1.1
sys/external/bsd/drm2/nouveau/nouveau_vga.c: 1.1
sys/external/bsd/drm2/nouveau/nouveaufb.c: 1.1
sys/external/bsd/drm2/nouveau/nouveaufb.h: 1.1
sys/external/bsd/drm2/pci/drm_pci.c: 1.10-1.12
sys/external/bsd/drm2/pci/drm_pci_module.c: 1.4
sys/external/bsd/drm2/pci/drmfb_pci.c: 1.1-1.3
sys/external/bsd/drm2/pci/files.drmkms_pci: 1.5
sys/external/bsd/drm2/radeon/radeon_pci.c: 1.5-1.7
sys/modules/drmkms/Makefile: 1.8, 1.9
sys/modules/drmkms_linux/Makefile: 1.6
sys/modules/drmkms_pci/Makefile: 1.5
sync drm2 with HEAD.
 1.1.2.1  08-Jan-2015  snj file linux_ww_mutex.c was added on branch netbsd-7 on 2015-03-06 21:39:10 +0000
 1.2.10.6  01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1876):

sys/external/bsd/drm2/linux/linux_ww_mutex.c: revision 1.15

drm/linux_ww_mutex: Fix wait loops.

If cv_wait_sig returns because a signal is delivered, we may
nonetheless have been granted the lock. It is harmless for us to
ignore this fact in three of the four paths, but in
ww_mutex_state_wait_sig, we may now have ownership of the lock and
MUST NOT return failure because the caller MUST release the lock
before destroying the ww_acquire_ctx.

While here, restructure the other three loops for clarity, so they
match the structure of the fourth and so they have a little less
impenetrable negation.

PR kern/57537
 1.2.10.5  01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1875):

sys/external/bsd/drm2/linux/linux_ww_mutex.c: revision 1.10

drm: Spruce up ww_mutex comments. Audit return values.
 1.2.10.4  01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1874):

sys/external/bsd/drm2/linux/linux_ww_mutex.c: revision 1.16

drm/linux_ww_mutex: Fix ww acquire context ordering.
 1.2.10.3  23-Apr-2019  martin Pull up following revision(s) via patch (requested by mrg in ticket #1242):

sys/external/bsd/common/include/linux/err.h: revision 1.3
sys/external/bsd/drm2/include/drm/drm_wait_netbsd.h: revision 1.15
sys/external/bsd/common/include/linux/errno.h: revision 1.4
sys/external/bsd/drm2/dist/drm/nouveau/nouveau_drm.c: revision 1.17
sys/external/bsd/drm2/linux/linux_ww_mutex.c: revision 1.6
sys/external/bsd/drm2/dist/drm/nouveau/nouveau_fence.c: revision 1.14

fix various problems i've seen where cv_*wait*() return ERESTART,
which is -3 in netbsd, which we have mapped linux ERESTARTSYS to.

this has a problem because linux code often returns errors and
pointers in the same value, and pointer values between -4095 and
- -1 are considered as error returns, but -3 ends up as 3 and thus
is not considered an error, and mayhem ensues.

with this in place my kabylake system seems actually stable, i
have not triggered any of my prior issues in almost 4 weeks now.

Taylor asked me to write up a description and then wrote most of
the text below for me :-)

In Linux code, we always work with ERESTARTSYS so the code meaning
start over is a positive NetBSD errno safe for PTR_ERR/ERR_PTR.

To achieve this:

1. adapt all cv_waits that return to Linux so they map ERESTART to
ERESTARTSYS, and

2. adapt all returns to userland so they convert ERESTARTSYS to
ERESTART.

Leave EINTR and all other error codes alone.
 1.2.10.2  27-Sep-2018  martin Apply patch, requested by mrg in ticket #1036:

sys/external/bsd/drm2/linux/linux_ww_mutex.c (apply patch)

Fix LOCKDEBUG build error. Change not needed in -current.
 1.2.10.1  01-Sep-2018  martin Pull up following revision(s) (requested by riastradh in ticket #1003):

sys/external/bsd/drm2/dist/drm/i915/intel_sdvo.c: revision 1.8
sys/external/bsd/drm2/dist/drm/ttm/ttm_tt.c: revision 1.10
sys/external/bsd/drm2/drm/drm_scatter.c: revision 1.4
sys/external/bsd/drm2/dist/drm/i915/i915_reg.h: revision 1.2
sys/external/bsd/drm2/linux/linux_ww_mutex.c: revision 1.3
sys/external/bsd/drm2/linux/linux_ww_mutex.c: revision 1.4
sys/external/bsd/drm2/linux/linux_idr.c: revision 1.6

Pull in upstream commit:
Author: Ville Syrj=E4l=E4 <ville.syrjala%linux.intel.com@localhost>
Date: Mon Jun 9 16:20:46 2014 +0300
drm/i915: Avoid div-by-zero when pixel_multiplier is zero
On certain platforms pixel_multiplier is read out in
.get_pipe_config(), but it also gets used to calculate the
pixel clock in intel_sdvo_get_config(). If the pipe is disabled
but some SDVO outputs are active, we may end up dividing by zero
in intel_sdvo_get_config().
Fixes https://bugs.freedesktop.org/show_bug.cgi?id=3D76520
Tweak slightly sketchy logic in linux_idr.
1. idr_preload can fail if you don't set __GFP_WAIT.
2. If idr_preload fails, it is wrong for idr_alloc to assert.
3. There is no way for idr_alloc to know what flags idr_preload got.
Probably won't *fix* any bugs, but if there is a bug with a missing
__GFP_WAIT, then we will learn about a trifle sooner.
Fix error branch in ttm_dma_tt_init to avoid double-free.
Should fix symptom of PR kern/52438, but who knows what underlying
problem causes us to reach the error branch in the first place.
Fix lockdebug_locked annotations.
When thread A grants ownership to thread B waiting with a context,
thread B needs to assert lockdebug_locked; otherwise, when it
releases, lockdebug_unlocked thinks it's releasing an unlocked
ww_mutex.

Fixes LOCKDEBUG failure with radeon noticed by martin@.

more const

XXX: add a NULL init to avoid a GCC 6 maybe uninit warning.

Remove UB from definition of symbols in i915_reg.h
Kernel Undefined Behavior Sanitizer enforces more warnings in build time.
This makes the build fatal in the drm/i915 code in:
- intel_ddi_put_crtc_pll(),
- intel_ddi_clock_get(),
- intel_ddi_pll_enable(),
- intel_ddi_setup_hw_pll_state().
The error message in all the cases says:
error: case label does not reduce to an integer constant
Set the type of the value left shifted to unsigned.
This change is required to build NetBSD/amd64 with KUBSan.
 1.4.6.1  10-Jun-2019  christos Sync with HEAD
 1.4.4.1  06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.4.2.2  03-Dec-2017  jdolecek update from HEAD
 1.4.2.1  16-Sep-2017  jdolecek file linux_ww_mutex.c was added on branch tls-maxphys on 2017-12-03 11:38:00 +0000
 1.7.2.3  01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1696):

sys/external/bsd/drm2/linux/linux_ww_mutex.c: revision 1.15

drm/linux_ww_mutex: Fix wait loops.

If cv_wait_sig returns because a signal is delivered, we may
nonetheless have been granted the lock. It is harmless for us to
ignore this fact in three of the four paths, but in
ww_mutex_state_wait_sig, we may now have ownership of the lock and
MUST NOT return failure because the caller MUST release the lock
before destroying the ww_acquire_ctx.

While here, restructure the other three loops for clarity, so they
match the structure of the fourth and so they have a little less
impenetrable negation.

PR kern/57537
 1.7.2.2  01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1695):
sys/external/bsd/drm2/linux/linux_ww_mutex.c: revision 1.10
drm: Spruce up ww_mutex comments. Audit return values.
 1.7.2.1  01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1694):

sys/external/bsd/drm2/linux/linux_ww_mutex.c: revision 1.16

drm/linux_ww_mutex: Fix ww acquire context ordering.
 1.14.4.2  01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #299):

sys/external/bsd/drm2/linux/linux_ww_mutex.c: revision 1.16

drm/linux_ww_mutex: Fix ww acquire context ordering.
 1.14.4.1  01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #298):

sys/external/bsd/drm2/linux/linux_ww_mutex.c: revision 1.15

drm/linux_ww_mutex: Fix wait loops.

If cv_wait_sig returns because a signal is delivered, we may
nonetheless have been granted the lock. It is harmless for us to
ignore this fact in three of the four paths, but in
ww_mutex_state_wait_sig, we may now have ownership of the lock and
MUST NOT return failure because the caller MUST release the lock
before destroying the ww_acquire_ctx.

While here, restructure the other three loops for clarity, so they
match the structure of the fourth and so they have a little less
impenetrable negation.

PR kern/57537

RSS XML Feed