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=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS 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 D8010C433E0 for ; Tue, 9 Feb 2021 14:34:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8EB4964E4F for ; Tue, 9 Feb 2021 14:34:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232163AbhBIOei convert rfc822-to-8bit (ORCPT ); Tue, 9 Feb 2021 09:34:38 -0500 Received: from eu-smtp-delivery-151.mimecast.com ([207.82.80.151]:40625 "EHLO eu-smtp-delivery-151.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232077AbhBIOc6 (ORCPT ); Tue, 9 Feb 2021 09:32:58 -0500 Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-288-A_ICKLg_PmetPQrYbE_D-A-1; Tue, 09 Feb 2021 14:31:16 +0000 X-MC-Unique: A_ICKLg_PmetPQrYbE_D-A-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 9 Feb 2021 14:31:16 +0000 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Tue, 9 Feb 2021 14:31:16 +0000 From: David Laight To: 'Segher Boessenkool' , Nicholas Piggin CC: "linux-kernel@vger.kernel.org" , "Paul Mackerras" , "msuchanek@suse.de" , "linuxppc-dev@lists.ozlabs.org" Subject: RE: [PATCH v5 20/22] powerpc/syscall: Avoid storing 'current' in another pointer Thread-Topic: [PATCH v5 20/22] powerpc/syscall: Avoid storing 'current' in another pointer Thread-Index: AQHW/uu6M1m95GjSlEGhmhkEL2m4wKpP4cNQ Date: Tue, 9 Feb 2021 14:31:16 +0000 Message-ID: References: <24804747098369ebcdac38970b8f7a1260bdd248.1612796617.git.christophe.leroy@csgroup.eu> <1612838134.rvncv9kzls.astroid@bobo.none> <20210209135053.GD27854@gate.crashing.org> In-Reply-To: <20210209135053.GD27854@gate.crashing.org> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8BIT Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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? David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales) 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=-2.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,PDS_BAD_THREAD_QP_64, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 E3A1EC433E0 for ; Tue, 9 Feb 2021 14:39:44 +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 3392F64E4F for ; Tue, 9 Feb 2021 14:39:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3392F64E4F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=ACULAB.COM 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 4DZlsT5rQ5zDsqJ for ; Wed, 10 Feb 2021 01:39:41 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=aculab.com (client-ip=207.82.80.151; helo=eu-smtp-delivery-151.mimecast.com; envelope-from=david.laight@aculab.com; receiver=) Received: from eu-smtp-delivery-151.mimecast.com (eu-smtp-delivery-151.mimecast.com [207.82.80.151]) (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 4DZlh0061RzDsn3 for ; Wed, 10 Feb 2021 01:31:24 +1100 (AEDT) Received: from AcuMS.aculab.com (156.67.243.126 [156.67.243.126]) (Using TLS) by relay.mimecast.com with ESMTP id uk-mta-288-A_ICKLg_PmetPQrYbE_D-A-1; Tue, 09 Feb 2021 14:31:16 +0000 X-MC-Unique: A_ICKLg_PmetPQrYbE_D-A-1 Received: from AcuMS.Aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) by AcuMS.aculab.com (fd9f:af1c:a25b:0:43c:695e:880f:8750) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Tue, 9 Feb 2021 14:31:16 +0000 Received: from AcuMS.Aculab.com ([fe80::43c:695e:880f:8750]) by AcuMS.aculab.com ([fe80::43c:695e:880f:8750%12]) with mapi id 15.00.1347.000; Tue, 9 Feb 2021 14:31:16 +0000 From: David Laight To: 'Segher Boessenkool' , Nicholas Piggin Subject: RE: [PATCH v5 20/22] powerpc/syscall: Avoid storing 'current' in another pointer Thread-Topic: [PATCH v5 20/22] powerpc/syscall: Avoid storing 'current' in another pointer Thread-Index: AQHW/uu6M1m95GjSlEGhmhkEL2m4wKpP4cNQ Date: Tue, 9 Feb 2021 14:31:16 +0000 Message-ID: References: <24804747098369ebcdac38970b8f7a1260bdd248.1612796617.git.christophe.leroy@csgroup.eu> <1612838134.rvncv9kzls.astroid@bobo.none> <20210209135053.GD27854@gate.crashing.org> In-Reply-To: <20210209135053.GD27854@gate.crashing.org> Accept-Language: en-GB, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-transport-fromentityheader: Hosted x-originating-ip: [10.202.205.107] MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=C51A453 smtp.mailfrom=david.laight@aculab.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: aculab.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: "linuxppc-dev@lists.ozlabs.org" , "msuchanek@suse.de" , Paul Mackerras , "linux-kernel@vger.kernel.org" Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" From: Segher Boessenkool > Sent: 09 February 2021 13:51 >=20 > On Tue, Feb 09, 2021 at 12:36:20PM +1000, Nicholas Piggin wrote: > > What if you did this? >=20 > > +static inline struct task_struct *get_current(void) > > +{ > > +=09register struct task_struct *task asm ("r2"); > > + > > +=09return task; > > +} >=20 > 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.) >=20 > You can do something like >=20 > static inline struct task_struct *get_current(void) > { > =09register struct task_struct *task asm ("r2"); >=20 > =09asm("" : "+r"(task)); >=20 > =09return task; > } >=20 > 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? =09David - Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1= PT, UK Registration No: 1397386 (Wales)