Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3077992ybb; Mon, 6 Apr 2020 01:22:02 -0700 (PDT) X-Google-Smtp-Source: APiQypJGgHSlrs7DLQpWaDmvIQEGX8ZiBMMk+jXaXxYBrO4Jk3qncnvgL8/J4otV95h9JQmIyi56 X-Received: by 2002:aca:170c:: with SMTP id j12mr11529864oii.50.1586161322712; Mon, 06 Apr 2020 01:22:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586161322; cv=none; d=google.com; s=arc-20160816; b=C+R/WrT45Ldh1+gBlHf4sEW4UFiU8WNAEd87ogMbNWURpWQmjKCaSKE4MMYfveVBWq fmk/8/9efnKvYNcf1GNBFC9ZCKlpjT5+YBh/wz8zn2ADyV4Jn4p9/jjRiLp1DPPU1uFD T4PiBEtHVayNaVHHDzuWgu0bLGmi7rVvlTHFGFHwrxKnSIh6DsHkfWo88tQwpfUh+q+D X1X8Uv7oYQ+qq+WOLx2Np91NyUQVInRDjHxI2ERoFCB4Cj8YV7zBhJxzD1XO1eKDLWvE LP3yxi91s/t2cUiglXPOVJdi0HJH7sn+L3q5QOkT/AbTwTpVyD9Ckz5fGe64i61r7DsV aBBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dkim-signature; bh=4sx9ij7QMNxt5XRbdtt4DnqueS7Xi00J/FDyBrUqDRc=; b=e4KZCk8ccqA5Fq+B9Snwt3DItfwio8wHbUxvT2ccRYETWWuonJ3NrPs06lGWLrteu6 Xi9P7TlvowonZ6xjk7L7kwCb7s70t06P2RoJivyv/1yW1AtyL7ZAiTlYEcrRuSzNYQTX Eh9yitBTpm45mihg+pu7BEePUVcgZXK0XwCdkGK6V4dYzhHH1doOWDuqmS1ZwFcOLPSr YRg86k2KE02kgCAQzUMEKqCN2O/LsaE+2D2ReBk/LmYb4DlXXhEIsPJyW7f99edb+mNT U5JES1EU/xUlfY3dEtYqH4Fhzawe5F6QN/BOgMGQ7IiDtEwsTt3gFX6PmlDaiFPACXfo 8Phg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=BgcaXSUg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s24si7394059otp.251.2020.04.06.01.21.49; Mon, 06 Apr 2020 01:22:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=BgcaXSUg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726661AbgDFIT5 (ORCPT + 99 others); Mon, 6 Apr 2020 04:19:57 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:33814 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726514AbgDFIT5 (ORCPT ); Mon, 6 Apr 2020 04:19:57 -0400 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0368EAql138072; Mon, 6 Apr 2020 08:17:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : to : cc : references : from : message-id : date : mime-version : in-reply-to : content-type : content-transfer-encoding; s=corp-2020-01-29; bh=4sx9ij7QMNxt5XRbdtt4DnqueS7Xi00J/FDyBrUqDRc=; b=BgcaXSUgxpKMcJdY8/ezBNa7w1RINeCDKMRO5uQvlOEW4iDkmwV+IwhWY5QZWbSSeDfs ASgI2z1hR0Giyz64XxOOMe+YinrdZS8FEYPndv+h0r7FlJ98FIP7D5RRXJxa8eZ+e8mE scAuJmYESYEFAIrnPLwauC1+Py5oE2mydr+RPp1i3+M8fdU8Dvy2Ba0LToYdfIhoVha3 +lqQe6ceNgSTotfjrTRzk22hGS3qsLmhrgmCtTamxeASB93E50M3GiHGu4JvAifSrWIP tLxLL5stQyKWAn/lozWObxl6cYQRLD2a/eKIsnXZS4cSF2eru9y0J4nqfsY8g48qAcnx PQ== Received: from userp3020.oracle.com (userp3020.oracle.com [156.151.31.79]) by userp2130.oracle.com with ESMTP id 306hnqwbx3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Apr 2020 08:17:34 +0000 Received: from pps.filterd (userp3020.oracle.com [127.0.0.1]) by userp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0368COpk150977; Mon, 6 Apr 2020 08:15:34 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userp3020.oracle.com with ESMTP id 3073xvp07w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 06 Apr 2020 08:15:34 +0000 Received: from abhmp0009.oracle.com (abhmp0009.oracle.com [141.146.116.15]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0368FW2A016144; Mon, 6 Apr 2020 08:15:32 GMT Received: from linux-1.home (/92.157.90.160) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 06 Apr 2020 01:15:32 -0700 Subject: Re: [PATCH 4/7] objtool: Add support for return trampoline call To: Peter Zijlstra , Josh Poimboeuf Cc: Julien Thierry , x86@kernel.org, linux-kernel@vger.kernel.org, tglx@linutronix.de References: <20200402082220.808-5-alexandre.chartre@oracle.com> <20200402154022.GG20730@hirez.programming.kicks-ass.net> <20200403151757.lhhia7pzqptvlqz5@treble> <20200403154620.GS20730@hirez.programming.kicks-ass.net> <20200404133218.GL20760@hirez.programming.kicks-ass.net> <20200404142232.wpn7estahnabfy3z@treble> <20200404155126.GF20730@hirez.programming.kicks-ass.net> From: Alexandre Chartre Message-ID: <27f433a3-6109-9831-5292-3df4155e10fb@oracle.com> Date: Mon, 6 Apr 2020 10:19:56 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0 MIME-Version: 1.0 In-Reply-To: <20200404155126.GF20730@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9582 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 mlxlogscore=999 adultscore=0 spamscore=0 phishscore=0 malwarescore=0 mlxscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004060069 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9582 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 adultscore=0 priorityscore=1501 mlxscore=0 malwarescore=0 mlxlogscore=999 lowpriorityscore=0 spamscore=0 impostorscore=0 suspectscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004060069 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/4/20 5:51 PM, Peter Zijlstra wrote: > On Sat, Apr 04, 2020 at 09:22:32AM -0500, Josh Poimboeuf wrote: >> On Sat, Apr 04, 2020 at 03:32:18PM +0200, Peter Zijlstra wrote: >>> On Fri, Apr 03, 2020 at 05:46:20PM +0200, Peter Zijlstra wrote: >>>> On Fri, Apr 03, 2020 at 10:17:57AM -0500, Josh Poimboeuf wrote: >>>>> Peter, I think my previous idea for UNWIND_HINT_ADJUST stack_add=8 would >>>>> work here? >>>> >>>> Yes, it would. >>> >>> Sorry, I have reconsidered. While it will shut up objtool, it will not >>> 'work'. That is, the ORC data generated will not correctly unwind. >>> >>> I'll try and write a longer email tonight. >> >> Right, that's what I've been trying to say. The ORC data will be >> non-deterministic unless we unroll the loop. Or did you mean something >> else? > > The below should result in deterministic code. > > diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h > index 07e95dcb40ad..109ee65f4a11 100644 > --- a/arch/x86/include/asm/nospec-branch.h > +++ b/arch/x86/include/asm/nospec-branch.h > @@ -59,8 +59,8 @@ > jmp 775b; \ > 774: \ > dec reg; \ > - jnz 771b; \ > - add $(BITS_PER_LONG/8) * nr, sp; > + add $(BITS_PER_LONG/8) * $2, sp; \ > + jnz 771b; > > #ifdef __ASSEMBLY__ Nice. This works fine and allows to remove ANNOTATE_NOSPEC_ALTERNATIVE when using __FILL_RETURN_BUFFER. However this is probably less performant because we now have nr/2 add instructions instead of just 1. Here is a variant where I unroll half of the loop. This way we have 2 add+dec+jnz instruction instructions instead of nr/2 dec+jnz and 1 add instruction. #define __FILL_RETURN_BUFFER(reg, nr, sp) \ mov $1, reg; \ 771: \ .rept (nr/2); \ call 772f; \ 773: /* speculation trap */ \ pause; \ lfence; \ jmp 773b; \ 772: ; \ .endr; \ add $(BITS_PER_LONG/8) * (nr/2), sp; \ dec reg; \ jnz 771b; Note that we can't unroll the entire loop: it won't work with nr=32 because the code is then too large to fit into an alternative (the alternative size is encoded on only one byte so this allows a maximum size of 255, while with nr=32 the size is around 390). alex.