Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp2912667pxb; Tue, 24 Aug 2021 10:26:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzHD4O1dQApKAuXEWo602OY+dkL3plDlglhxv+FjOt8qt7qO71R9VGLoirqlFxcXxbtM7vI X-Received: by 2002:a17:906:520b:: with SMTP id g11mr5341880ejm.502.1629826017198; Tue, 24 Aug 2021 10:26:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629826017; cv=none; d=google.com; s=arc-20160816; b=DhVfC7fHlpC0ankxEbynXz020RpStI5ELK6tvfV5mV50Dz/JU88hMJ6sbBFf/2KHdL GHYcVQ44bd6B6mB1HJdLmV+BOukDa+1vDZXe1VPBVkt+dkWnsTYagPdVXVqDjrNIdWB4 z1czXN3XrqWV9VlWB3abjpJ+HF+VvF0a0pfxCAL1hF9bn4olTRau9uoEHs0f3K/9ma7e RL7v9C06LbI4n+OdIJ36MlkQgJ6jv7qoN7qoYAMLKl7dFAKOqc9Vdsmtle2baioXikuP cYKFWRzbDyw/CMi8LEAtuy7kq40GTwC4r2njb5wsOrXeug9mNzeyRnlxm4zmWh7kG8lc Sngg== 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-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=QPnWg/LGGvxt5CM1BB+uyz3TappOCL8fKgNmmw9LuWs=; b=Ms/zeM9FFrP0JlIXtOrYb/m3Zj3nIF8OBhPdGC1l1OKClOTKWL3IAqpcMiI4h4owLZ vmJTOaj2BroDt6m+8aIuHwAPpRAwnI3p3Af52lOqZIBObYW0GhNdT2/26nr9LKp4zCuT 5Q+IUmBNO/z1pwcsAr0i6IMPnUwqzSu2mMq0CQ77+m86CzwW/FJhTXm0F5WP6se1mj9s WLnd2h2rqt2P0Z2tLgZAOVO2lsmpOxb0XrKpNp3yApP46YeEPGS3fRWF3L8TT5bA7lvY ax6kul8Vbcu4LGInoamQeYrz2+dH+tTKnjPLxUOuJf+oJ5MmS51srK265Z3DqHVmu3bG fBGQ== 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 fl2si16506379ejc.34.2021.08.24.10.26.30; Tue, 24 Aug 2021 10:26:57 -0700 (PDT) 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 S232549AbhHXRZt (ORCPT + 99 others); Tue, 24 Aug 2021 13:25:49 -0400 Received: from gate.crashing.org ([63.228.1.57]:51272 "EHLO gate.crashing.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240313AbhHXRWN (ORCPT ); Tue, 24 Aug 2021 13:22:13 -0400 Received: from gate.crashing.org (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 17OHFvAg028670; Tue, 24 Aug 2021 12:15:57 -0500 Received: (from segher@localhost) by gate.crashing.org (8.14.1/8.14.1/Submit) id 17OHFuD6028666; Tue, 24 Aug 2021 12:15:56 -0500 X-Authentication-Warning: gate.crashing.org: segher set sender to segher@kernel.crashing.org using -f Date: Tue, 24 Aug 2021 12:15:56 -0500 From: Segher Boessenkool To: Christophe Leroy Cc: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3] powerpc/booke: Avoid link stack corruption in several places Message-ID: <20210824171556.GJ1583@gate.crashing.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.3i Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi! On Tue, Aug 24, 2021 at 07:56:26AM +0000, Christophe Leroy wrote: > Use bcl 20,31,+4 instead of bl in order to preserve link stack. You use $+4 actually, which is clearer than .+4 or just +4 (and I am surprised that the latter even works btw, I never knew :-) -- either way it looks like a typo). > - bl invstr /* Find our address */ > + bcl 20,31,$+4 /* Find our address */ > invstr: mflr r6 /* Make it accessible */ You can remove the label now. This isn't true in all cases, but here you can (all times it is called "invstr"). > @@ -85,7 +85,7 @@ skpinv: addi r6,r6,1 /* Increment */ > addi r6,r6,10 > slw r6,r8,r6 /* convert to mask */ > > - bl 1f /* Find our address */ > + bcl 20,31,$+4 /* Find our address */ > 1: mflr r7 Here, too. > @@ -1045,7 +1045,7 @@ head_start_47x: > sync > > /* Find the entry we are running from */ > - bl 1f > + bcl 20,31,$+4 > 1: mflr r23 > tlbsx r23,0,r23 > tlbre r24,r23,0 And here. > @@ -1132,7 +1132,7 @@ _GLOBAL(switch_to_as1) > bne 1b > > /* Get the tlb entry used by the current running code */ > - bl 0f > + bcl 20,31,$+4 > 0: mflr r4 > tlbsx 0,r4 > @@ -1166,7 +1166,7 @@ _GLOBAL(switch_to_as1) > _GLOBAL(restore_to_as0) > mflr r0 > > - bl 0f > + bcl 20,31,$+4 > 0: mflr r9 > addi r9,r9,1f - 0b And these. > --- a/arch/powerpc/mm/nohash/tlb_low.S > +++ b/arch/powerpc/mm/nohash/tlb_low.S > @@ -199,7 +199,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_476_DD2) > * Touch enough instruction cache lines to ensure cache hits > */ > 1: mflr r9 > - bl 2f > + bcl 20,31,$+4 > 2: mflr r6 > li r7,32 > PPC_ICBT(0,R6,R7) /* touch next cache line */ > @@ -414,7 +414,7 @@ _GLOBAL(loadcam_multi) > * Set up temporary TLB entry that is the same as what we're > * running from, but in AS=1. > */ > - bl 1f > + bcl 20,31,$+4 > 1: mflr r6 > tlbsx 0,r8 > mfspr r6,SPRN_MAS1 And these too. There does not see to be a warning for usused local labels, it would be useful in this case :-) Segher