From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45657C433E2 for ; Thu, 3 Sep 2020 08:43:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22B74206E7 for ; Thu, 3 Sep 2020 08:43:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726493AbgICIn4 (ORCPT ); Thu, 3 Sep 2020 04:43:56 -0400 Received: from elvis.franken.de ([193.175.24.41]:50566 "EHLO elvis.franken.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726448AbgICInz (ORCPT ); Thu, 3 Sep 2020 04:43:55 -0400 Received: from uucp (helo=alpha) by elvis.franken.de with local-bsmtp (Exim 3.36 #1) id 1kDkqX-0000U1-00; Thu, 03 Sep 2020 10:43:53 +0200 Received: by alpha.franken.de (Postfix, from userid 1000) id ECE03C0E86; Thu, 3 Sep 2020 10:43:31 +0200 (CEST) Date: Thu, 3 Sep 2020 10:43:31 +0200 From: Thomas Bogendoerfer To: Huacai Chen Cc: Jiaxun Yang , "open list:MIPS" , Fuxin Zhang , Zhangjin Wu Subject: Re: [PATCH V3 1/2] MIPS: Loongson-3: Enable COP2 usage in kernel Message-ID: <20200903084331.GA7223@alpha.franken.de> References: <20200807131357.GA11979@alpha.franken.de> <410cf75c-4cf5-94d8-fbc9-821d38f8a299@flygoat.com> <96dbe0be-7af6-b182-bbe0-534883539812@flygoat.com> <20200810141219.GA2844@alpha.franken.de> <106e65f5-d456-deaa-b47b-45b2a461b048@flygoat.com> <20200811120645.GA6199@alpha.franken.de> <20200826124646.GA9809@alpha.franken.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-mips-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org On Wed, Sep 02, 2020 at 02:54:10PM +0800, Huacai Chen wrote: > Hi, Thomas, > > On Wed, Aug 26, 2020 at 8:48 PM Thomas Bogendoerfer > 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 > > > 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; > I tried this way but it doesn't work, the reason is that the resume > routine in r4k_switch.S save the current hardware status into > THREAD_STATUS, but CU2 in hardware is cleared in its caller (i.e., > switch_to). so let's fix it there: diff --git a/arch/mips/include/asm/switch_to.h b/arch/mips/include/asm/switch_to.h index 0b0a93bf83cd..a4374b4cb88f 100644 --- a/arch/mips/include/asm/switch_to.h +++ b/arch/mips/include/asm/switch_to.h @@ -117,6 +117,8 @@ do { \ __restore_dsp(next); \ } \ if (cop2_present) { \ + u32 status = read_c0_status(); \ + \ set_c0_status(ST0_CU2); \ if ((KSTK_STATUS(prev) & ST0_CU2)) { \ if (cop2_lazy_restore) \ @@ -127,7 +129,7 @@ do { \ !cop2_lazy_restore) { \ cop2_restore(next); \ } \ - clear_c0_status(ST0_CU2); \ + write_c0_status(status); \ } \ __clear_r5_hw_ll_bit(); \ __clear_software_ll_bit(); \ BTW. if we come up to a final solution, this change should be a seperate patch. And the change in process.c probably, too. Thomas. -- Crap can work. Given enough thrust pigs will fly, but it's not necessarily a good idea. [ RFC1925, 2.3 ]