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=-5.5 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no 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 33194C43333 for ; Wed, 10 Feb 2021 08:49:34 +0000 (UTC) Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5BFD264E4B for ; Wed, 10 Feb 2021 08:49:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5BFD264E4B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=csgroup.eu Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 4DbD2z12ttzDqwh for ; Wed, 10 Feb 2021 19:49:31 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=csgroup.eu (client-ip=93.17.236.30; helo=pegase1.c-s.fr; envelope-from=christophe.leroy@csgroup.eu; receiver=) Received: from pegase1.c-s.fr (pegase1.c-s.fr [93.17.236.30]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4DbCz02PVzzDqLW for ; Wed, 10 Feb 2021 19:46:04 +1100 (AEDT) Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4DbCyv4br2z9v1NF; Wed, 10 Feb 2021 09:45:59 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at c-s.fr Received: from pegase1.c-s.fr ([192.168.12.234]) by localhost (pegase1.c-s.fr [192.168.12.234]) (amavisd-new, port 10024) with ESMTP id QECMkfz-wJQJ; Wed, 10 Feb 2021 09:45:59 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase1.c-s.fr (Postfix) with ESMTP id 4DbCyv3m5Fz9v1NC; Wed, 10 Feb 2021 09:45:59 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6019F8B7FA; Wed, 10 Feb 2021 09:46:00 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id BRme29R15nhT; Wed, 10 Feb 2021 09:46:00 +0100 (CET) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id B52868B75F; Wed, 10 Feb 2021 09:45:59 +0100 (CET) Subject: Re: [PATCH v5 20/22] powerpc/syscall: Avoid storing 'current' in another pointer To: Nicholas Piggin , David Laight , 'Segher Boessenkool' References: <24804747098369ebcdac38970b8f7a1260bdd248.1612796617.git.christophe.leroy@csgroup.eu> <1612838134.rvncv9kzls.astroid@bobo.none> <20210209135053.GD27854@gate.crashing.org> <1612922312.mnpowzgd0r.astroid@bobo.none> From: Christophe Leroy Message-ID: Date: Wed, 10 Feb 2021 09:45:56 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: <1612922312.mnpowzgd0r.astroid@bobo.none> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: fr Content-Transfer-Encoding: 8bit X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Paul Mackerras , "msuchanek@suse.de" , "linuxppc-dev@lists.ozlabs.org" , "linux-kernel@vger.kernel.org" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" Le 10/02/2021 à 03:00, Nicholas Piggin a écrit : > Excerpts from Christophe Leroy's message of February 10, 2021 3:03 am: >> >> >> Le 09/02/2021 à 15:31, David Laight a écrit : >>> From: Segher Boessenkool >>>> Sent: 09 February 2021 13:51 >>>> >>>> On Tue, Feb 09, 2021 at 12:36:20PM +1000, Nicholas Piggin wrote: >>>>> What if you did this? >>>> >>>>> +static inline struct task_struct *get_current(void) >>>>> +{ >>>>> + register struct task_struct *task asm ("r2"); >>>>> + >>>>> + return task; >>>>> +} >>>> >>>> Local register asm variables are *only* guaranteed to live in that >>>> register as operands to an asm. See >>>> https://gcc.gnu.org/onlinedocs/gcc/Local-Register-Variables.html#Local-Register-Variables >>>> ("The only supported use" etc.) >>>> >>>> You can do something like >>>> >>>> static inline struct task_struct *get_current(void) >>>> { >>>> register struct task_struct *task asm ("r2"); >>>> >>>> asm("" : "+r"(task)); >>>> >>>> return task; >>>> } >>>> >>>> which makes sure that "task" actually is in r2 at the point of that asm. >>> >>> If "r2" always contains current (and is never assigned by the compiler) >>> why not use a global register variable for it? >>> >> >> >> The change proposed by Nick doesn't solve the issue. > > It seemed to change code generation in a simple test case, oh well. > >> >> The problem is that at the begining of the function we have: >> >> unsigned long *ti_flagsp = ¤t_thread_info()->flags; >> >> When the function uses ti_flagsp for the first time, it does use 112(r2) >> >> Then the function calls some other functions. >> >> Most likely because the function could update 'current', GCC copies r2 into r30, so that if r2 get >> changed by the called function, ti_flagsp is still based on the previous value of current. >> >> Allthough we know r2 wont change, GCC doesn't know it. And in order to save r2 into r30, it needs to >> save r30 in the stack. >> >> >> By using ¤t_thread_info()->flags directly instead of this intermediaite ti_flagsp pointer, GCC >> uses r2 instead instead of doing a copy. >> >> >> Nick, I don't understand the reason why you need that 'ti_flagsp' local var. > > Just to save typing, I don't mind your patch I was just wondering if > current could be improved in general. > Thanks, I'll post v6 of it as a follow-up of yesterday's two remaining follow-up patches. Christophe