Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for nvidia_modeset #709

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 46 additions & 5 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,23 +92,64 @@ int module_load(char *module_name, char *driver) {
* @return 1 if the driver is succesfully unloaded, 0 otherwise
*/
int module_unload(char *driver) {
if (module_is_loaded(driver) == 1) {

if (module_is_loaded("nvidia_uvm") == 1) {
int retries = 30;
bb_log(LOG_INFO, "Unloading nvidia_uvm driver\n");
char *mod_argv[] = {
"modprobe",
"-r",
"nvidia_uvm",
"nvidia_modeset",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just came across this line of code. You need to add driver as well, otherwise you will unload only modeset module, but not nvidia. Alternatively, you can change the logic removing else if statements and unload modules one by one.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my case, the driver line was unnecessary, since modprobe -r nvidia_modeset also unloaded nvidia. This may be specific to my system (Lenovo ThinkPad W540 running Arch Linux).

I agree with @invidian below that the whole thing needs a rewrite, not only because it's an inefficient fix, but a superior function would be modular, i.e. if nVidia starts throwing in nvidia_x with a new driver, we could simply add nvidia_x alongside nvidia, nvidia_modeset, and nvidia_uvm. Auto-detection would be ideal by parsing the output of lsmod | grep nvidia and automagically generating a list of modules to feed to module_unload based on that particular system.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arafey I have Arch Linux also, but I use nvidia-dkms package, so it might be somehow introduce a different behaviour, though, I haven't seen a case where one module would unload another unless you write so in modprobe.conf.

NULL
};
bb_run_fork_wait(mod_argv, 10);
while (retries-- > 0 && module_is_loaded("nvidia_uvm") == 1) {
usleep(100000);
}
if (module_is_loaded(driver) == 1) {
bb_log(LOG_ERR, "Unloading %s driver timed out.\n", driver);
return 0;
}
}

else if (module_is_loaded("nvidia_modeset") == 1) {
int retries = 30;
bb_log(LOG_INFO, "Unloading %s driver\n", driver);
bb_log(LOG_INFO, "Unloading nvidia_modeset driver\n");
char *mod_argv[] = {
"rmmod",
driver,
"modprobe",
"-r",
"nvidia_modeset",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above.

NULL
};
bb_run_fork_wait(mod_argv, 10);
while (retries-- > 0 && module_is_loaded(driver) == 1) {
while (retries-- > 0 && module_is_loaded("nvidia_modeset") == 1) {
usleep(100000);
}
if (module_is_loaded(driver) == 1) {
bb_log(LOG_ERR, "Unloading %s driver timed out.\n", driver);
return 0;
}
}

else if (module_is_loaded(driver) == 1) {
int retries = 30;
bb_log(LOG_INFO, "Unloading %s driver\n", driver);
char *mod_argv[] = {
"modprobe",
"-r",
driver,
NULL
};
bb_run_fork_wait(mod_argv, 10);
while (retries-- > 0 && module_is_loaded(driver) == 1) {
usleep(100000);
}
if (module_is_loaded(driver) == 1) {
bb_log(LOG_ERR, "Unloading %s driver timed out.\n", driver);
return 0;
}
}
return 1;
}

Expand Down