Hi, Thomas, On Fri, Aug 28, 2020 at 5:34 PM Thomas Bogendoerfer <tsbogend@xxxxxxxxxxxxxxxx> wrote: > > On Fri, Aug 28, 2020 at 05:21:19PM +0800, Huacai Chen wrote: > > Hi, Thomas, > > > > On Fri, Aug 28, 2020 at 4:43 PM Thomas Bogendoerfer > > <tsbogend@xxxxxxxxxxxxxxxx> wrote: > > > > > > On Thu, Aug 27, 2020 at 11:48:29AM +0800, Huacai Chen wrote: > > > > Hi, Thomas, > > > > > > > > On Wed, Aug 26, 2020 at 8:48 PM Thomas Bogendoerfer > > > > <tsbogend@xxxxxxxxxxxxxxxx> wrote: > > > > > > > > > > On Fri, Aug 14, 2020 at 05:44:18PM +0800, Huacai Chen wrote: > > > > > > On Tue, Aug 11, 2020 at 8:08 PM Thomas Bogendoerfer > > > > > > <tsbogend@xxxxxxxxxxxxxxxx> wrote: > > > > > > > this comes with it's own memcpy/memset and stuff, I don't see a reason why > > > > > > > COP2 needs to be enabled there, > > > > > > gslq/gssq can also be generated by toolchains. > > > > > > > > > > I don't want to introduce every single CPU optimization bits into such > > > > > a closed first stage loader. So please use $(filter-out) in > > > > > arch/mips/boot/compressed/Makefile to disable creation of 16byte load/stores. > > > > > > > > > > > > which is correct for all user space process, otherwise the whole > > > > > > > cop2 exception thing wouldn't work. And if cop2 exception handling > > > > > > > has been run it's set in THREAD_STATUS. > > > > > > > > > > > > > THREAD_STATUS means thread_struct.cp0_status, which is the cp0_status > > > > > > when a process runs in kernel-space. KSTK_STATUS (what you have seen > > > > > > in copy_thread_tls() below) means cp0_status in a process's kernel > > > > > > stack, which saves the cp0_status when a process runs in user-space. > > > > > > Whether COP2 exception can work depends on that KSTK_STATUS (but not > > > > > > THREAD_STATUS) should not contain CU2 at the first time. So, whether > > > > > > or not THREAD_STATUS contains CU2, it won't break COP2 handling. > > > > > > > > > > so why don't we fix the the in-kernel cp0_status instead ? > > > > > > > > > > How about this ? > > > > > > > > > > diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c > > > > > index 90b869297893..26fb77a8d406 100644 > > > > > --- a/arch/mips/kernel/process.c > > > > > +++ b/arch/mips/kernel/process.c > > > > > @@ -133,6 +133,7 @@ int copy_thread_tls(unsigned long clone_flags, unsigned long usp, > > > > > /* Put the stack after the struct pt_regs. */ > > > > > childksp = (unsigned long) childregs; > > > > > p->thread.cp0_status = read_c0_status() & ~(ST0_CU2|ST0_CU1); > > > > > + p->thread.cp0_status |= ST0_KERNEL_CUMASK; > > > > > if (unlikely(p->flags & PF_KTHREAD)) { > > > > > /* kernel thread */ > > > > > unsigned long status = p->thread.cp0_status; > > > > This seems a good idea, I will send a new version. > > > > > > IMHO it migt be even better to just use > > > > > > p->thread.cp0_status = read_c0_status(); > > > > > > without masking. We are in kernel, so we took care of whatever CU1/CU2 > > > handling had to be done at kernel entry. So keeping the current cp0 status > > > for the new thread looks more sane to me. > > I think this may cause FPU be enabled in kernel by mistake. > > if it is enabled at that point, it was already enabled in kernel. In kernel FPU may be enabled temporarily, and it seems a preemptible kernel may enable FPU for a new process (maybe I'm wrong, this is a bit complex). Huacai > > Thomas. > > -- > Crap can work. Given enough thrust pigs will fly, but it's not necessarily a > good idea. [ RFC1925, 2.3 ]