Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1146026pxb; Wed, 10 Feb 2021 00:51:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJwyONeaG2oJblwWrGQ7b1XHLhVcLYzOh3x0sKOzsTIoqv8J5ggbCKFV4/ElmTp9zfUD+iI+ X-Received: by 2002:a17:907:b16:: with SMTP id h22mr1833807ejl.393.1612947092431; Wed, 10 Feb 2021 00:51:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612947092; cv=none; d=google.com; s=arc-20160816; b=Of5GbyHrtJ7J0bHdqFQoMsYGfGRChBS/DBpR2ZVazQuIzDR3waItkDlAu6Ln5hGGja RV6tJiso+Hsep6TgfWkOvheWzM/oFcERtowfBd6thE3qF1+nSLTIJy1adBA+nLsyMeV9 gCaNksmpa3eti4XH9rW3RENB8oA6sx1SpXcEe65OEdbk+Ga/Gnc+Pk8mtnj7KAS3yAa0 3SWlViRGjNXn+FLtM1QZi9et2PHcQYxWLgIwQwO/RzxRIb8MJyFYqNbERPy4DHMCAr1Y UbCwrBdTZZRAYn6w7czzGe1MXHZ7qtvUtVR7yyCBKqMJ1uNLfsvJrDtn/qep9QxAVBBJ K86A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=aLvq7OXka1iUH1ak0qvS51R+A54lEXAp007GuKx+uV0=; b=awwTGjj8YtvxFIOPU3mdNwLO9cnOisIVIbjs/7omSqdNashKNjUhsZbPGrrwof3Y4a GfGIUgFAmwxbyKeW6276z1b9yrUU5/vY0YbM+uh42exsSqEgObrj/uni1bVaj3nofeir S8oPisahdVXPiB/M+u5TAbJ2Hn76K7Hm5hQ+7flkHQW95vEbtHyzWWkVP9xwRgDhEoKf ysaIbkYTe1/l4jfmJM1A3rinXNTARx1ulEDCHWoWKl3FPJOWNNlssOkfAM+6WaUzyZ8v 6HTikUQOfoWSRaymuHepUxy0fOlzwa0hVn8tEG8PwlR503R+P/nTqCsA1J4LOSP0NJZG feMQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c4si931808edr.553.2021.02.10.00.51.07; Wed, 10 Feb 2021 00:51:32 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231204AbhBJIsP (ORCPT + 99 others); Wed, 10 Feb 2021 03:48:15 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:47769 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230445AbhBJIq6 (ORCPT ); Wed, 10 Feb 2021 03:46:58 -0500 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' Cc: "linux-kernel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , "msuchanek@suse.de" , Paul Mackerras 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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