Subject: Preemption in do_cpu (Re: [PATCH]Preemption patch for 2.6)

From: Pavel Kiryukhin <[email-masked]>
Date: Mon, 18 Apr 2005 13:32:46 +0400

Hi,
the preempt_disable/preempt_enable sequence in do_cpu() [traps.c]
exists quite long (patch submitted in Oct. 2004), so it should be nothing
wrong there.

Can somebody please comment why use of preempt_disable/enable in do_cpu
will not result in "scheduling while atomic" for fpu-less cpu (with enabled
preemption).

The sequence looks like

do_cpu()
| preempt_disable()
| fpu_emulator_cop1Handler()
| | cond_reshed()
| | | schedule()  <------ scheduling while atomic

The proposed patch was tested for Sibyte, but it has fpu (AFAIK) and has no
fpu_emulator_cop1Handler called.

--
Thank you,
Pavel Kiryukhin                   mailto:[email-masked]

Friday, October 22, 2004, 10:06:43 PM, you wrote:

ML> Hello !

ML> The attached patch incorporates preemption enable/disable in some parts
ML> of the kernel. I have tested this on the Broadcom Sibyte. Please review
ML> ...

ML> Thanks
ML> Manish Lachwani

<skip>

ML> Index: linux-2.6.8.1/arch/mips/kernel/traps.c
ML> ===================================================================
ML> --- linux-2.6.8.1.orig/arch/mips/kernel/traps.c
ML> +++ linux-2.6.8.1/arch/mips/kernel/traps.c

<skip>

ML>  case 1:
ML> +preempt_disable();
ML> +
ML>  own_fpu();
ML>  if (current->used_math) {	/* Using the FPU again.  */
ML>  restore_fp(current);
ML> @@ -674,6 +690,8 @@
ML>  force_sig(sig, current);
ML>  }
 
ML> +preempt_enable();
ML> +
ML>  return;
 
ML>  case 2:

<skip>

---

From: Jun Sun <[email-masked]>
Date: Mon, 18 Apr 2005 14:20:21 -0700

> fpu_emulator_cop1Handler called.

fpu_emulator maintains global variables and in general is dangerous
to be preempted in the middle of processing.

The quick fix for this problem is probably to move preemption disabling/
enabling inside fpu_emulator_cop1Handler().

Better fix is probably to modify fpu emulator so that it is preemption
safe overall.

Jun

---

From: Manish Lachwani <[email-masked]>
Date: Mon, 18 Apr 2005 14:35:16 -0700

>Better fix is probably to modify fpu emulator so that it is preemption
Missed this one ! I had a patch that enables preemption before the 
cond_resched and disables right after it. I forgot to send it to 
linux-mips though. But, I needed it to work on fpu-less CPU. My bad.

Thanks
Manish Lachwani

---

From: Atsushi Nemoto <[email-masked]>
Date: Tue, 19 Apr 2005 10:24:37 +0900 (JST)

>>>>> On Mon, 18 Apr 2005 14:20:21 -0700, Jun Sun <[email-masked]> said:
jsun> fpu_emulator maintains global variables and in general is
jsun> dangerous to be preempted in the middle of processing.

jsun> The quick fix for this problem is probably to move preemption
jsun> disabling/ enabling inside fpu_emulator_cop1Handler().

Also, get_user/put_user should not be used with preempt disabled.

Here is Quick and dirty workaround (including some other preemption fixes):

http://www.linux-mips.org/cgi-bin/mesg.cgi?a=linux-mips&i=20041025.003619.92586674.anemo%40mba.ocn.ne.jp

jsun> Better fix is probably to modify fpu emulator so that it is
jsun> preemption safe overall.

Sure.  It will make fpu emulator SMP safe also.

---
Atsushi Nemoto