Skip to contentSkip to conversation

Sending signals to a kernel thread, broken in 2.6.22

DISCUSSION Oleg Nesterov 2 participants 3 messages May 30, 2007 USB

lore
Share & tools
lore
#0 lore raw
Quoted 6 lines · Alan Stern

The g_file_storage driver uses a kernel thread and communicates with that thread in part by means of signals. It also relies on the thread receiving signals from userspace as an indication that the thread should terminate.

Quoted 6 lines

This was all working in 2.6.21, but as of 2.6.22-rc3 the signal delivery mechanism (entirely within the kernel!) is no longer functional.

What's the story? Do I need to do something new and different to get signals working again? Should I avoid using signals entirely?

I guess you mean drivers/usb/gadget/file_storage.c

	fsg_main_thread:
		
		siginitsetinv(&fsg->thread_signal_mask, SIGTERM | ...);
		sigprocmask(SIG_SETMASK, &fsg->thread_signal_mask, NULL);

Yes?

Please look at

	change kernel threads to ignore signals instead of blocking them
	commit: 10ab825bdef8df510f99c703a5a2d9b13a4e31a5

I think you can convert the code above to use allow_signal().

Please note that it is not good to just unblock the signal, SIG_DFL means that __group_complete_signal() starts doing SIGNAL_GROUP_EXIT things. In particular, SIGTERM implies sigaddset(SIGKILL).

Oleg.

#1 lore raw
Quoted 19 lines · Oleg Nesterov
Quoted 9 lines · Alan Stern

The g_file_storage driver uses a kernel thread and communicates with that thread in part by means of signals. It also relies on the thread receiving signals from userspace as an indication that the thread should terminate.

This was all working in 2.6.21, but as of 2.6.22-rc3 the signal delivery mechanism (entirely within the kernel!) is no longer functional.

I guess you mean drivers/usb/gadget/file_storage.c

	fsg_main_thread:
		
		siginitsetinv(&fsg->thread_signal_mask, SIGTERM | ...);
		sigprocmask(SIG_SETMASK, &fsg->thread_signal_mask, NULL);
Quoted 8 lines

Yes?

Please look at

	change kernel threads to ignore signals instead of blocking them
	commit: 10ab825bdef8df510f99c703a5a2d9b13a4e31a5

I think you can convert the code above to use allow_signal().

something like untested/uncompiled patch below, what do you think?

Oleg.

drivers/usb/gadget/file_storage.c renamed from drivers/usb/gadget/file_storage.c~ +5 -7
@@ -686,7 +686,6 @@ struct fsg_dev {
 	int			thread_wakeup_needed;
 	struct completion	thread_notifier;
 	struct task_struct	*thread_task;
-	sigset_t		thread_signal_mask;
 
 	int			cmnd_size;
 	u8			cmnd[MAX_COMMAND_SIZE];
@@ -3277,8 +3276,7 @@ static void handle_exception(struct fsg_
 	/* Clear the existing signals.  Anything but SIGUSR1 is converted
 	 * into a high-priority EXIT exception. */
 	for (;;) {
-		sig = dequeue_signal_lock(current, &fsg->thread_signal_mask,
-				&info);
+		sig = dequeue_signal_lock(current, &current->blocked, &info);
 		if (!sig)
 			break;
 		if (sig != SIGUSR1) {
@@ -3431,10 +3429,10 @@ static int fsg_main_thread(void *fsg_)
 
 	/* Allow the thread to be killed by a signal, but set the signal mask
 	 * to block everything but INT, TERM, KILL, and USR1. */
-	siginitsetinv(&fsg->thread_signal_mask, sigmask(SIGINT) |
-			sigmask(SIGTERM) | sigmask(SIGKILL) |
-			sigmask(SIGUSR1));
-	sigprocmask(SIG_SETMASK, &fsg->thread_signal_mask, NULL);
+	allow_signal(SIGINT);
+	allow_signal(SIGTERM);
+	allow_signal(SIGKILL);
+	allow_signal(SIGUSR1);
 
 	/* Arrange for userspace references to be interpreted as kernel
 	 * pointers.  That way we can pass a kernel pointer to a routine
#2 lore raw
Quoted 8 lines · Oleg Nesterov
Quoted 6 lines

Please look at

	change kernel threads to ignore signals instead of blocking them
	commit: 10ab825bdef8df510f99c703a5a2d9b13a4e31a5

I think you can convert the code above to use allow_signal().

something like untested/uncompiled patch below, what do you think?

I tried it out, and it worked perfectly. Thank you very much.

Alan Stern