From: Evgeniy Polyakov Subject: Re: [PATCH] signals: Generate warning when flush_signals() is called from non-kthread context Date: Sat, 02 May 2015 14:56:43 +0300 Message-ID: <8198211430567803@web26m.yandex.ru> References: <1430502057.4472.255.camel@redhat.com> <20150501193813.GA2812@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Transfer-Encoding: QUOTED-PRINTABLE Cc: Alex Williamson , Oleg Nesterov , linux-kernel , kvm To: Ingo Molnar , Linus Torvalds , Neil Brown , Stephen Smalley Return-path: In-Reply-To: <20150501193813.GA2812@gmail.com> Sender: linux-kernel-owner@vger.kernel.org List-Id: kvm.vger.kernel.org Hi Ingo 01.05.2015, 22:38, "Ingo Molnar" : > * Linus Torvalds wrote: >> =9AOn Fri, May 1, 2015 at 10:40 AM, Alex Williamson >> =9A wrote: >>> =9A- Flush signals on interrupted wait to retain polling interval (= Alex Williamson) >> =9AThis cannot *possibly* be right. If I read this patch right, you'= re >> =9Arandomly just getting rid of signals. No way in hell is that corr= ect. >> >> =9A"flush_signals()" is only for kernel threads, where it's a hacky >> =9Aalternative to actually handling them (since kernel threads never >> =9Arreturn to user space and cannot really "handle" a signal). But y= ou're >> =9Adoing it in the ->remove handler for the device, which can be cal= led >> =9Aby arbitrary system processes. This is not a kernel thread thing,= as >> =9Afar as I can see. >> >> =9AIf you cannot handle signals, you damn well shouldn't be using >> =9A"wait_event_interruptible_timeout()" to begin with. Get rid of th= e >> =9A"interruptible", since it apparently *isn't* interruptible. >> >> =9ASo I'm not pulling this. >> >> =9ANow I'm worried that other drivers do insane things like this. I >> =9Awonder if we should add some sanity test to flush_signals() to ma= ke >> =9Asure that it can only ever get called from a kernel thread. > Looks unsafe: called from various module exit handlers in: > > =9A=9Adrivers/w1/slaves/w1_bq27000.c > =9A=9Adrivers/w1/slaves/w1_ds2406.c > =9A=9Adrivers/w1/slaves/w1_ds2408.c > =9A=9Adrivers/w1/slaves/w1_ds2413.c > =9A=9Adrivers/w1/slaves/w1_ds2423.c > =9A=9Adrivers/w1/slaves/w1_ds2431.c > =9A=9Adrivers/w1/slaves/w1_ds2433.c > =9A=9Adrivers/w1/slaves/w1_ds2760.c > =9A=9Adrivers/w1/slaves/w1_ds2780.c > =9A=9Adrivers/w1/slaves/w1_ds2781.c > =9A=9Adrivers/w1/slaves/w1_ds28e04.c > =9A=9Adrivers/w1/slaves/w1_smem.c > =9A=9Adrivers/w1/slaves/w1_therm.c > > which would be executed in rmmod context, losing signals. > Cc:-ed Evgeniy. w1 uses a little bit strange refcnt logic, basically every w1 module wa= its for all its users to release their w1 resources and doesn't exit until = its safe. To wait for resources to be freed at module exit time it checks its ref= cnt to drop to zero periodically and sleeps between the checks for a second. w1 flushes signals between = these checks for no particular reason, it can be safely removed from w1_unreg= ister_family() and interruptible sleep replaced with the normal one.