Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1111809pxb; Tue, 9 Feb 2021 23:43:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJxmG24+iJE9jBL9ZgLQfseO2Q9Pv88gqly2PHCpybZHr6lPvVMsiIG3azxrp3wDbS7B89pg X-Received: by 2002:a17:906:9a06:: with SMTP id ai6mr1671201ejc.463.1612942989124; Tue, 09 Feb 2021 23:43:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612942989; cv=none; d=google.com; s=arc-20160816; b=CWILAHBC/rR6kZHQy8bETB96mqv8yA4meZarbz4mXpEj/U8qW2x7tOG6AmwF2xZCEv LMW/0w/9Fceir7pHS7hFdK93Roa+fxTeqBg/yq0MVUp3AwxVHC8Uo+6Fm2GHJ42gbu+O 0NpR4lLy8RQxajMRhzJ779DQTrRlcqmhKwHqiF4TNmS/vuAoeEI6ZKmAwE1XtD9Y3Q05 mfK7isFqaCu/YbFfg/kD9uBVWh04N85O6XvxfVM6l5DhN0uyQfvGa037bNx/iz0fY8JC 8YW6XqwVdzryaJ3Zck3TZR+jQ0T42XnMwicH/YfkCxGeeOu40b3y1a/ZQd6cb3UqGbmt XUhA== 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=tWmapO+O9bA+301b/cEtLY5VIYJef1yQ4/Ew5NMuI7E=; b=pzzglRPXDK7q+UmOW8AWFR/Rs+r68C2ELpVbKt+U97Di/96JzW4w3i40xOlSfxhyRg GM+8Qg3B889Mv/E2RwdP63+G3kMTXcbf2MQE8YdORHi+KsIY1zSkMpDm25RZ78jp+Uqj VgbZyDhRR0NPhxo0Yy5uSfDxhOJzBmCUP7cHvf4dSdIeGIEjc3tkz5EBDtjsGuW+9jrZ IwhQk9BFSnktUD9c/FjZYhhgC3LLJ4rVkm0I6SFRJWWUgytNozgdk4cJ0TGUtI7FZFER YtDrLhAiZZOWa4mLNsQkXGV1cONbXaBgplh3qGJrMZVr6ZQS13ZPQp2OJXPe90J7+Iq9 /xQA== 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 j14si801334eje.590.2021.02.09.23.42.43; Tue, 09 Feb 2021 23:43:09 -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 S232860AbhBIREo (ORCPT + 99 others); Tue, 9 Feb 2021 12:04:44 -0500 Received: from pegase1.c-s.fr ([93.17.236.30]:23665 "EHLO pegase1.c-s.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232912AbhBIREX (ORCPT ); Tue, 9 Feb 2021 12:04:23 -0500 Received: from localhost (mailhub1-int [192.168.12.234]) by localhost (Postfix) with ESMTP id 4DZq3R6lxTz9v2fx; Tue, 9 Feb 2021 18:03:31 +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 Gcz4YRACtslA; Tue, 9 Feb 2021 18:03:31 +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 4DZq3R5Y7Qz9v2fv; Tue, 9 Feb 2021 18:03:31 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 5CE8E8B7EE; Tue, 9 Feb 2021 18:03:33 +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 d9oR9oP2EDOI; Tue, 9 Feb 2021 18:03:33 +0100 (CET) Received: from [192.168.4.90] (unknown [192.168.4.90]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9E0608B7EA; Tue, 9 Feb 2021 18:03:32 +0100 (CET) Subject: Re: [PATCH v5 20/22] powerpc/syscall: Avoid storing 'current' in another pointer To: David Laight , 'Segher Boessenkool' , Nicholas Piggin Cc: "linuxppc-dev@lists.ozlabs.org" , "msuchanek@suse.de" , Paul Mackerras , "linux-kernel@vger.kernel.org" References: <24804747098369ebcdac38970b8f7a1260bdd248.1612796617.git.christophe.leroy@csgroup.eu> <1612838134.rvncv9kzls.astroid@bobo.none> <20210209135053.GD27854@gate.crashing.org> From: Christophe Leroy Message-ID: Date: Tue, 9 Feb 2021 18:03:33 +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: 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 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. 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. Christophe