Skip to content

Commit

Permalink
WIP: x11/nvidia-driver/470: Backport fix for nvidia-modeset panic
Browse files Browse the repository at this point in the history
This backports a fix where a non-sleepable lock is held while sleeping
occurs. This is fixed in more recent versions but is still causing issues
in 470.

PR: 274519
  • Loading branch information
amshafer committed Mar 11, 2024
1 parent 864b23c commit 635c3df
Showing 1 changed file with 93 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
--- src/nvidia-modeset/nvidia-modeset-freebsd.c.orig 2018-08-21 23:09:28 UTC
--- src/nvidia-modeset/nvidia-modeset-freebsd.c.orig 2024-03-11 15:49:45 UTC
+++ src/nvidia-modeset/nvidia-modeset-freebsd.c
@@ -25,6 +25,7 @@
@@ -27,6 +27,7 @@
#include <sys/file.h>
#include <sys/proc.h>
#include <sys/stack.h>
+#include <sys/sysproto.h>

#include "nvkms-ioctl.h"
#include "nvidia-modeset-os-interface.h"
@@ -48,6 +49,7 @@
@@ -52,6 +53,7 @@
#include "machine/../linux32/linux32_proto.h"
#endif
#include <compat/linux/linux_ioctl.h>
+ #include <compat/linux/linux_util.h>
#endif


@@ -252,7 +254,12 @@ struct nvkms_ref_ptr {
@@ -280,7 +282,12 @@ struct nvkms_ref_ptr* nvkms_alloc_ref_ptr(void *ptr)

struct nvkms_ref_ptr* NVKMS_API_CALL nvkms_alloc_ref_ptr(void *ptr)
struct nvkms_ref_ptr* nvkms_alloc_ref_ptr(void *ptr)
{
- struct nvkms_ref_ptr *ref_ptr = nvkms_alloc(sizeof(*ref_ptr), NV_FALSE);
+ /*
Expand All @@ -30,7 +30,46 @@
if (ref_ptr) {
mtx_init(&ref_ptr->lock, "nvkms-ref-ptr-lock", NULL, MTX_SPIN);
// The ref_ptr owner counts as a reference on the ref_ptr itself.
@@ -867,29 +869,31 @@ static int nvkms_poll(
@@ -371,7 +378,7 @@ static struct {
* Global list with pending timers, any change requires acquiring lock
*/
static struct {
- struct sx lock;
+ struct mtx lock;
LIST_HEAD(nvkms_timers_head, nvkms_timer_t) list;
} nvkms_timers;

@@ -384,9 +391,9 @@ static void nvkms_taskqueue_callback(void *arg, int pe
* We can delete this timer from pending timers list - it's being
* processed now.
*/
- sx_xlock(&nvkms_timers.lock);
+ mtx_lock_spin(&nvkms_timers.lock);
LIST_REMOVE(timer, timers_list);
- sx_xunlock(&nvkms_timers.lock);
+ mtx_unlock_spin(&nvkms_timers.lock);

/*
* After taskqueue_callback we want to be sure that callout_callback
@@ -454,7 +461,7 @@ nvkms_init_timer(struct nvkms_timer_t *timer, nvkms_ti
* run in parallel with this, it could race against nvkms_init_timer()
* and free the timer before its initialization is complete.
*/
- sx_xlock(&nvkms_timers.lock);
+ mtx_lock_spin(&nvkms_timers.lock);
LIST_INSERT_HEAD(&nvkms_timers.list, timer, timers_list);

if (usec == 0) {
@@ -468,7 +475,7 @@ nvkms_init_timer(struct nvkms_timer_t *timer, nvkms_ti
NVKMS_USECS_TO_TICKS(usec),
nvkms_callout_callback, (void *) timer);
}
- sx_xunlock(&nvkms_timers.lock);
+ mtx_unlock_spin(&nvkms_timers.lock);
}

nvkms_timer_handle_t*
@@ -916,29 +923,31 @@ static int nvkms_poll(
*************************************************************************/

#if defined(NVKMS_SUPPORT_LINUX_COMPAT)
Expand Down Expand Up @@ -77,23 +116,68 @@
}

#define NVKMS_LINUX_IOCTL_MIN _IOC(0, NVKMS_IOCTL_MAGIC, NVKMS_IOCTL_CMD, 0)
@@ -909,6 +909,7 @@ static struct linux_ioctl_handler nvkms_linux_ioctl_ha
@@ -954,6 +963,7 @@ static void nvkms_linux_compat_load(void)
static void nvkms_linux_compat_load(void)
{
#if defined(NVKMS_SUPPORT_LINUX_COMPAT)
+ linux_device_register_handler(&nvkms_linux_device_handler);
linux_ioctl_register_handler(&nvkms_linux_ioctl_handler);
#endif
}
@@ -917,6 +918,7 @@ static void nvkms_linux_compat_unload(void)
@@ -962,6 +972,7 @@ static void nvkms_linux_compat_unload(void)
{
#if defined(NVKMS_SUPPORT_LINUX_COMPAT)
linux_ioctl_unregister_handler(&nvkms_linux_ioctl_handler);
+ linux_device_unregister_handler(&nvkms_linux_device_handler);
#endif
}

@@ -1100,4 +1102,9 @@ MODULE_DEPEND(nvidia_modeset, /* module
@@ -1011,7 +1022,7 @@ nvidia_modeset_loader(struct module *m, int what, void
nvkms_module.is_unloading = NV_FALSE;

LIST_INIT(&nvkms_timers.list);
- sx_init(&nvkms_timers.lock, "nvidia-modeset timer lock");
+ mtx_init(&nvkms_timers.lock, "nvidia-modeset timer lock", NULL, MTX_SPIN);

nvkms_dev = make_dev(&nvkms_cdevsw,
NVKMS_CDEV_MINOR,
@@ -1020,7 +1031,7 @@ nvidia_modeset_loader(struct module *m, int what, void

if (nvkms_dev == NULL) {
sx_destroy(&nvkms_module.lock);
- sx_destroy(&nvkms_timers.lock);
+ mtx_destroy(&nvkms_timers.lock);
sx_destroy(&nvkms_lock);

nvkms_free_rm();
@@ -1089,7 +1100,7 @@ nvidia_modeset_loader(struct module *m, int what, void
* nvkms_taskqueue_callback() doesn't get called after the
* module is unloaded.
*/
- sx_xlock(&nvkms_timers.lock);
+ mtx_lock_spin(&nvkms_timers.lock);

LIST_FOREACH_SAFE(timer, &nvkms_timers.list, timers_list, tmp) {
if (timer->callout_created) {
@@ -1111,7 +1122,7 @@ nvidia_modeset_loader(struct module *m, int what, void
}
}

- sx_xunlock(&nvkms_timers.lock);
+ mtx_unlock_spin(&nvkms_timers.lock);

taskqueue_run(taskqueue_nvkms);

@@ -1119,7 +1130,7 @@ nvidia_modeset_loader(struct module *m, int what, void
nvkms_dev = NULL;

sx_destroy(&nvkms_module.lock);
- sx_destroy(&nvkms_timers.lock);
+ mtx_destroy(&nvkms_timers.lock);
sx_destroy(&nvkms_lock);

nvkms_free_rm();
@@ -1151,4 +1162,9 @@ MODULE_DEPEND(nvidia_modeset, /* module
MODULE_DEPEND(nvidia_modeset, /* module name */
linux, /* prerequisite module */
1, 1, 1); /* vmin, vpref, vmax */
Expand Down

0 comments on commit 635c3df

Please sign in to comment.