Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp892418ybb; Wed, 8 Apr 2020 11:56:43 -0700 (PDT) X-Google-Smtp-Source: APiQypJ4cmiGpDiWJ/z9Bs+ajwnkBj8xHVo5iNNFhye7b8TaOwZnOQ3ESlb/6CULb7yq2HX4ZRy0 X-Received: by 2002:a9d:3f2:: with SMTP id f105mr7178135otf.187.1586372203183; Wed, 08 Apr 2020 11:56:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1586372203; cv=none; d=google.com; s=arc-20160816; b=M/X1gBM/qEOguaXbvTGt3M9X13yr9kR5HA5n2GOSiVgVoXa8OKZtZ2fWEBJpyQd0h2 tPQz2Mdro+dpLHowtf596uqUJmQ+gve+cEQh9Oha+dznlS514C/yczvKVksn5ZUPePRC HO4BuGRUdegdistW7k/lnGBFi0OPkYPshsSdNI4gANfgQ+CFItEKm4V9tI4ANvkSdPgO JGSE0zML0wlYkYcE99+3pcJEQTS4JBdOKAuuYhxMjNp+ORw9EieqqJgI/t059jfxQ6K+ YuIRE5N8ebifG6/r1NQbUg/gLb3ucvd2ltblqXGa5O8/XDb4SEVqpx0NGP2dexj/BJLh QWAQ== 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=suh6+9x2SWoNOKBwtEAB3+9V2UZtf1WztxESTUhqu6o=; b=HBesGjSkRIn3QZbC3b2cHtYtG5JMVFDD9GdWauFkLBmP1WV5lSNGFDlNTxKfn6QZsn 4PNYsFc1JcAcAjXhvFOuiWHMylWcgYVaGquvzQCu9q58m5Xe8okLThRP7s+3rsmL9yNa 2W+cIsAXCMGKZlXlS7vmmPOJGbTAlXnEpqUFFNM6a1maeIqgm+pDu7l3N+tyn+Jmv2l0 9h6O/+cQLgHIBFy0pmEvSzXBHXmby4K/w/gx+yLR43WAYn49adEW65o/GqWTEkH79USu UkIX3IZQ8ZBX16Fribdam2azsRmgh5mWG54R56Yf080ggNUsOj4f1b4dbxak8TpGt6OQ C6dw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2020-01-29 header.b=wrsywjVM; 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 g188si2371268oia.203.2020.04.08.11.56.30; Wed, 08 Apr 2020 11:56:43 -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=wrsywjVM; 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 S1730065AbgDHP73 (ORCPT + 99 others); Wed, 8 Apr 2020 11:59:29 -0400 Received: from userp2130.oracle.com ([156.151.31.86]:53892 "EHLO userp2130.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729889AbgDHP73 (ORCPT ); Wed, 8 Apr 2020 11:59:29 -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 038FeCWe088049; Wed, 8 Apr 2020 15:59:14 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=suh6+9x2SWoNOKBwtEAB3+9V2UZtf1WztxESTUhqu6o=; b=wrsywjVMFNZaYrCXazXnVXP8D+CoQwH9XkRTuyTZkudYdsaAgEuZG4CyffxoIJIWRV62 nfZvYRgQ7HRr2ZbP+nJeEVPjL15x2A9DKg5DKQ+fAm54yJRJsyiLL6uloVENDDMV4b64 WLF3xr4RpcEQ3Zv8pptjHOgqx1MWOLR14ndOk/HUNJEflIWGtyF8hC0Zkg496VNejuCB eJhI3WwyG30MI+Lqrnb61V0Q4lNuaAO5vvzQXlr1lRWH8HE3SvBFHVkjsArlDN39s1IS lxSUdhnfwz6C/B/nX8n8HoJ/E4HIvHFYRtCLs0Zc66pf2iF7Kt2gOvF5/5swP30PT9aw Zw== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by userp2130.oracle.com with ESMTP id 3091m3cfc2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 08 Apr 2020 15:59:14 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 038FbeuQ062359; Wed, 8 Apr 2020 15:59:13 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserp3020.oracle.com with ESMTP id 3091m4afq7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 08 Apr 2020 15:59:13 +0000 Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id 038FxAbK000743; Wed, 8 Apr 2020 15:59:10 GMT Received: from linux-1.home (/92.157.90.160) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 08 Apr 2020 08:59:10 -0700 Subject: Re: [PATCH V2 5/9] objtool: Add support for intra-function calls To: Julien Thierry , Peter Zijlstra Cc: x86@kernel.org, linux-kernel@vger.kernel.org, jpoimboe@redhat.com, tglx@linutronix.de References: <20200407073142.20659-1-alexandre.chartre@oracle.com> <20200407073142.20659-6-alexandre.chartre@oracle.com> <20200407130729.GZ20730@hirez.programming.kicks-ass.net> <40b19a8e-ae5e-623e-fb3f-261f9fec2ea5@oracle.com> <7ba6d4c9-c1dc-fa83-2ade-b7d3fba9e7fb@oracle.com> From: Alexandre Chartre Message-ID: Date: Wed, 8 Apr 2020 18:03:35 +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: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9584 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 phishscore=0 bulkscore=0 mlxscore=0 malwarescore=0 spamscore=0 adultscore=0 suspectscore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004080124 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9584 signatures=668685 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 adultscore=0 impostorscore=0 malwarescore=0 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 clxscore=1015 bulkscore=0 phishscore=0 mlxscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004080124 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/8/20 4:19 PM, Julien Thierry wrote: > > > On 4/8/20 3:06 PM, Alexandre Chartre wrote: >> >> >> On 4/7/20 3:28 PM, Alexandre Chartre wrote: >>> >>> On 4/7/20 3:07 PM, Peter Zijlstra wrote: >>>> On Tue, Apr 07, 2020 at 09:31:38AM +0200, Alexandre Chartre wrote: >>>> >>>>> index a62e032863a8..7ee1561bf7ad 100644 >>>>> --- a/tools/objtool/arch/x86/decode.c >>>>> +++ b/tools/objtool/arch/x86/decode.c >>>>> @@ -497,3 +497,15 @@ void arch_initial_func_cfi_state(struct cfi_state *state) >>>>>       state->regs[16].base = CFI_CFA; >>>>>       state->regs[16].offset = -8; >>>>>   } >>>>> + >>>>> + >>>>> +void arch_configure_intra_function_call(struct stack_op *op) >>>>> +{ >>>>> +    /* >>>>> +     * For the impact on the stack, make an intra-function >>>>> +     * call behaves like a push of an immediate value (the >>>>> +     * return address). >>>>> +     */ >>>>> +    op->src.type = OP_SRC_CONST; >>>>> +    op->dest.type = OP_DEST_PUSH; >>>>> +} >>>> >>>> An alternative is to always set up stack ops for CALL/RET on decode, but >>>> conditionally run update_insn_state() for them. >>>> >>>> Not sure that makes more logical sense, but the patch would be simpler I >>>> think. >>> >>> Right, this would avoid adding a new arch dependent function and the patch >>> will be simpler. This probably makes sense as the stack impact is the same >>> for all calls (but objtool will use it only for intra-function calls). >>> >> >> Actually the processing of the ret instruction is more complicated than I >> anticipated with intra-function calls, and so my implementation is not >> complete at the moment. >> >> The issue is to correctly handle how the ret is going to behave depending how >> the stack (or register on arm) is modified before the ret. Adjusting the stack >> offset makes the stack state correct, but objtool still needs to correctly >> figure out where the ret is going to return and where the code flow continues. >> > > A hint indicating the target "jump" address could be useful. It could > be used to add the information on some call/jump dynamic that aren't > associated with jump tables. Currently when objtool finds a jump > dynamic, if no branches were added to it, it will just return. > > Having such a hint could help make additional links (at least on > arm64). I don't know what Peter and Josh would think of that (if that > helps in your case of course). > Yes, I am thinking about tracking intra-function call return address, and having hints to specify a return address changes. For example, on x86, when we push the branch address on the stack we overwrite the last return address (the return address of the last intra-function call). Then the return instruction can figure out where to branch. alex.