Received: by 2002:a05:6a10:2785:0:0:0:0 with SMTP id ia5csp3044322pxb; Tue, 12 Jan 2021 05:07:59 -0800 (PST) X-Google-Smtp-Source: ABdhPJwNa+xqSt7BRJFAk64HI8DfGygC4cPDtW76bh8H0IIiQSGYKgiFoRc97xoBVVmamhe3r2Ce X-Received: by 2002:a17:906:85cd:: with SMTP id i13mr3193801ejy.553.1610456879123; Tue, 12 Jan 2021 05:07:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1610456879; cv=none; d=google.com; s=arc-20160816; b=IoQPhquHRyJWuV9y7nvS5oxC4zuhDHyqxDCEDYL2o3EDpJ6/Cb9GfKfICKOk3Al917 mObbijhjlcioqVUCLMwAfAY7RuzryFrUIevcwnkP4R6pYNxQbRm8YUg+Ugtj8m8iXoj5 aZPLfbiXoJcexSngzj2S9AWiRvRPrPe8YNxArCBLlxL/+Ywc73XAJ6g5uXq3QqwRxiyu lqBODFrFdF0Op253zUsqDXbKYnPQ3kiRkZep3yMvyUJazdYdD/9jW+fxNrOoB0w05Vgc YDHJCF3vFXZjbF775WVVHkMbsxhX3skhJhDN32qakTnHJ2u2Oh84zcXUe3B2MFP03SU+ FGFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=u0GfCGW6B7T581FmuKl5ssLjsSlQGgD59GIf4g49YRg=; b=bKGr2YVmqeiFJo+K4xmdOE+00fFrSCAga2r3qcU+u/ZgALgPX7xpjkJUWxU3Pu8M7e UiVFfzpUvo1FHaF/YKAEJkGI8eYb0twWctjoyZkNWSBWYo7+6ffhRTYmqzVfpuMRIeRP 4XoSKhF9UtKqrxpOlDUNIm+xbDPlpejEsO0lO9dedIxKTC0bGQMgTF3LIdqkAdTcsgn9 9za6GiUk+huaq18zbEEdPzRnVbJuASQtXeZ0tza0dq3ThhxWUv6wfZy8Ap/P1Hqwk5rL 5jGa0GtvDe33ZNSkVU1dnA8gMha73YDTbd+aKExbsBdILAsc+SK30+PO9IRUJyO0f1+f WUPw== 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 c11si22768edy.88.2021.01.12.05.07.33; Tue, 12 Jan 2021 05:07:59 -0800 (PST) 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 S2388002AbhALMaa (ORCPT + 99 others); Tue, 12 Jan 2021 07:30:30 -0500 Received: from mail.loongson.cn ([114.242.206.163]:34332 "EHLO loongson.cn" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2387535AbhALMaH (ORCPT ); Tue, 12 Jan 2021 07:30:07 -0500 Received: from loongson.localdomain (unknown [113.200.148.30]) by mail.loongson.cn (Coremail) with SMTP id AQAAf9Dx6L0dlv1fsycDAA--.5569S6; Tue, 12 Jan 2021 20:29:19 +0800 (CST) From: Jinyang He To: Thomas Bogendoerfer Cc: linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Burton , Jun-Ru Chang Subject: [PATCH 4/4] MIPS: Add is_jr_ra_ins() to end the loop early Date: Tue, 12 Jan 2021 20:29:17 +0800 Message-Id: <1610454557-25867-5-git-send-email-hejinyang@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1610454557-25867-1-git-send-email-hejinyang@loongson.cn> References: <1610454557-25867-1-git-send-email-hejinyang@loongson.cn> X-CM-TRANSID: AQAAf9Dx6L0dlv1fsycDAA--.5569S6 X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2KfnxnUUI43ZEXa7IUYe6wtUUUUU== X-CM-SenderInfo: pkhmx0p1dqwqxorr0wxvrqhubq/ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For those leaf functions, they are likely to have no stack operations. Add is_jr_ra_ins() to determine whether jr ra has been touched before the frame_size is found. Without this patch, the get frame_size operation may be out of range and get the frame_size from the next nested function. Signed-off-by: Jinyang He --- arch/mips/kernel/process.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c index bef8f8d..9e6f194 100644 --- a/arch/mips/kernel/process.c +++ b/arch/mips/kernel/process.c @@ -205,6 +205,36 @@ struct mips_frame_info { #define J_TARGET(pc,target) \ (((unsigned long)(pc) & 0xf0000000) | ((target) << 2)) +static inline int is_jr_ra_ins(union mips_instruction *ip) +{ +#ifdef CONFIG_CPU_MICROMIPS + /* + * jr16 ra + * jr ra + */ + if (mm_insn_16bit(ip->word >> 16)) { + if (ip->mm16_r5_format.opcode == mm_pool16c_op && + ip->mm16_r5_format.rt == mm_jr16_op && + ip->mm16_r5_format.imm == 31) + return 1; + return 0; + } + + if (ip->r_format.opcode == mm_pool32a_op && + ip->r_format.func == mm_pool32axf_op && + ((ip->u_format.uimmediate >> 6) & GENMASK(9,0)) == mm_jalr_op && + ip->r_format.rs == 31) + return 1; + return 0; +#else + if (ip->r_format.opcode == spec_op && + ip->r_format.func == jr_op && + ip->r_format.rs == 31) + return 1; + return 0; +#endif +} + static inline int is_ra_save_ins(union mips_instruction *ip, int *poff) { #ifdef CONFIG_CPU_MICROMIPS @@ -417,7 +447,9 @@ static int get_frame_info(struct mips_frame_info *info) last_insn_size = 4; } - if (!info->frame_size) { + if (is_jr_ra_ins(ip)) { + break; + } else if (!info->frame_size) { is_sp_move_ins(&insn, &info->frame_size); continue; } else if (!saw_jump && is_jump_ins(ip)) { -- 2.1.0