Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp51359rwe; Wed, 31 Aug 2022 16:13:51 -0700 (PDT) X-Google-Smtp-Source: AA6agR67Akl8Ohnx+6vw4KOl5J2Z0yw8wJPB4/XbMBXdo2xrJYnHkOwZtHfY0qw/yHxVkRZ2skDz X-Received: by 2002:a17:903:230f:b0:174:fa8c:bf78 with SMTP id d15-20020a170903230f00b00174fa8cbf78mr12482097plh.63.1661987631242; Wed, 31 Aug 2022 16:13:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661987631; cv=none; d=google.com; s=arc-20160816; b=AJlv3Y19lEbiXR4b0MP/aAWZtfDpTIBLkvi1I8+jWO/U1zb2ao4O5Fw6Y1dtk5ij/i 91MqnsJ510MdUgVe1+wNJokJuNGkfOCA9cQv7teNfRimhJCnHN6dcUnIkwwJUFW7utkE pBpo2q0jOb3tPuZHT7+c9Bbi7tn+NTw/4/IOAP+NYGztlF9Z2sF98P/Um0nYjW3vzkuY 0b5nJLZpTCfQBkbiDd+BfJf2h8cJ+fsycgyvXPW0JiDyY/a5UCk+Etw2Tm8wvnpwO9g6 m1s4lmQ7mRKdsLU3JFl6MQ1mioMWnM4mgXXThzjiZaJPAwFQ8QbmMm7jxAIQ0Q2QX0OS qNPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=EYUgCogkYfP7S3lxNn90QLEnhWTNL13lz3+GY3EDwMk=; b=dZ9SAsl134z3Rke4nCQCIkAIZ8HcB9amwjVK1Q1BEnD2DdmWUctCV8oSCm4h69ES1N Kk7ZLOEgovTVaoYCwWS1kSAPwhlcVQ892jKoxzC5KYZc0dZKn99cMc3jfQ+UYbtS9f3L 7Qb4JsW2Zw67yVh9l91yOXbPQPE9wO3kgEy6XSCSSE+/4NhO/Z4TJvWE9z+ULrL5IPXn UtLJJiZiknv4kFq7XHUK8bkRMU08OUzkvyLP+9XvqLrA0lW3iCEB0ivBXA29K75iKQxO YQ0zWPPNceb9SfxjXIMsJhQHSq5t0KQm7k4mmzVFt6Y/HZgfePyzHBjHJc1hoWkJbRAk gvKQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w28-20020a63161c000000b0042a49af1347si6184970pgl.563.2022.08.31.16.13.40; Wed, 31 Aug 2022 16:13:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232734AbiHaWtj (ORCPT + 99 others); Wed, 31 Aug 2022 18:49:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232711AbiHaWti (ORCPT ); Wed, 31 Aug 2022 18:49:38 -0400 Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id E1362DF4D4 for ; Wed, 31 Aug 2022 15:49:34 -0700 (PDT) Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 27VMjNZ8018075; Wed, 31 Aug 2022 17:45:23 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 27VMjMD4018074; Wed, 31 Aug 2022 17:45:22 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Wed, 31 Aug 2022 17:45:22 -0500 From: Segher Boessenkool To: Christophe Leroy Cc: Nicholas Piggin , Michael Ellerman , "linux-kernel@vger.kernel.org" , "linuxppc-dev@lists.ozlabs.org" , Zhouyi Zhou Subject: Re: [PATCH v2] powerpc: Fix irq_soft_mask_set() and irq_soft_mask_return() with sanitizer Message-ID: <20220831224522.GX25951@gate.crashing.org> References: <7c11b659-5b8e-256c-508e-39395041fccb@csgroup.eu> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7c11b659-5b8e-256c-508e-39395041fccb@csgroup.eu> User-Agent: Mutt/1.4.2.3i X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi! On Tue, Aug 30, 2022 at 09:10:02AM +0000, Christophe Leroy wrote: > Le 30/08/2022 ? 11:01, Nicholas Piggin a ?crit?: > > On Tue Aug 30, 2022 at 3:24 PM AEST, Christophe Leroy wrote: > >>> This is still slightly concerning to me. Is there any guarantee that the > >>> compiler would not use a different sequence for the address here? > >>> > >>> Maybe explicit r13 is required. > >>> > >> > >> local_paca is defined as: > >> > >> register struct paca_struct *local_paca asm("r13"); And this is in global scope, making it a global register variable. > >> Why would the compiler use another register ? > > > > Hopefully it doesn't. Is it guaranteed that it won't? Yes, this is guaranteed. For a local register variable this is guaranteed only for operands to an extended inline asm; any other access to the variable does not have to put it in the specified register. But this is a global register variable. The only thing that would make this crash and burn is if *any* translation unit did not see this declaration: it could then use r13 (if that was allowed by the ABI in effect, heh). > > I'm sure Segher will be delighted with the creative asm in __do_IRQ > > and call_do_irq :) *Grabs popcorn* All that %% is blinding, yes. Inline tabs are bad taste. Operand names instead of numbers are great for obfuscation, and nothing else -- unless you have more than four or five operands, in which case you have bigger problems already. Oh, this function is a good example of proper use of local register asm, btw. Comments like "// Inputs" are just harmful. As is the "creative" indentation here. Both harm readability and do not help understanding in any other way either. The thing about inline asm is the smallest details change meaning of the whole, it is a very harsh environment, you are programming both in C and directly assembler code as well, and things have to be valid for both, although on the other hand there is almost no error checking. Keeping it small, simple, readable is paramount. The rules for using inline asm: 0) Do no use inline asm. 1) Use extended asm, unless you know all differences with basic asm, and you know you want that. And if you answer "yes I do" to the latter, you answered wrong to the former. 2) Do not use toplevel asm. 3) Do no use inline asm. 4) Do no use inline asm. 5) Do no use inline asm. Inline asm is a very powerful escape hatch. Like all emergency exits, you should not use them if you do not need them! :-) But, you are talking about the function calling and the frame change I bet :-) Both of these are only okay because everything is back as it was when this (single!) asm is done, and the state created is perfectly fine (this is very dependent on exact ABI used, etc.) I would have used real assembler code here (in a .s file). But there probably are reasons to do things this way, performance probably? Segher