Received: by 2002:a25:23cc:0:0:0:0:0 with SMTP id j195csp570410ybj; Thu, 7 May 2020 02:30:20 -0700 (PDT) X-Google-Smtp-Source: APiQypJ2Kfshds+Rc8jcj2ISyUovqZD4WGMNtQxP8D+HcQ3ddsJCd1yYlNjDP+1+Qos21H+fdNq9 X-Received: by 2002:a17:906:6a02:: with SMTP id o2mr10830461ejr.223.1588843820056; Thu, 07 May 2020 02:30:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588843820; cv=none; d=google.com; s=arc-20160816; b=P0RmN7ZVMbqGoqV3sDy9Q6qpqs10BqnhNj9W1wVrwKOcxq/YMZIRB35S2UfZB23a3c Fp7G28Jfsl/xjlr8q5kh/26JgY3EG+dsg8Q6EhSoizTjEkR6h0rOXfqNZ3Egdv1kY4YF IeEAW/uiQJrPxbDcw9IDG3qh+F/f0h6hUwFRsRK+4oSkioci0FvLNVIua6JElvmMJ+7T jAcrM7HVzUDd2rwT7p4hkeRiksCOTQL/crbBnL5+00tic1Tjz1BWNDfbVb98mbX0aHyz 1fsY2MTNK5xEkUoMFGlp85JWKo5wvOGRPM2fDl8MH+2fYUtubweK8AyQV/XbuyqjIwTE bTpw== 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:mime-version:user-agent:date:message-id:subject :from:cc:to; bh=HYGikDkl+yZk+ZkA11tYld0dx6hqcV2lpq8X+bON8gA=; b=lbiqQUijAGWqh4hggo3zmVJL5Jz/X3p1925tWHrnavN/vmbjcFeBJY1+MY27+IqkH8 KaXFNPBnByLRTY9sIDJaiCdxVWtazRrk3lkyaKdXQ9xmRVNxXgrYt7tNgXzxBNGpuM6j wtZgyktCrNDM/HkXffauNJkQZ91yrwDV6L84NmDg9UUlZOrU5QuaxQilIdXsJS+jJhoH c9DZOTvF8CM+oRDlLadREztTF27pj/J9AHI9aHzmmYKNJFSlK91JWzEnmF2YwCaf4NPJ pqGg3S5gEqj/DH+nqH/uVcjcWRcKYqpEOW+Wwdn4BkoZ39nzo3joBnHOqJtXJh7Vyhkb Nt5g== 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 ce16si3061676ejc.526.2020.05.07.02.29.56; Thu, 07 May 2020 02:30:20 -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 S1726222AbgEGJ2c (ORCPT + 99 others); Thu, 7 May 2020 05:28:32 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:3840 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725857AbgEGJ2c (ORCPT ); Thu, 7 May 2020 05:28:32 -0400 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 4D9753340A18592668BD; Thu, 7 May 2020 17:28:30 +0800 (CST) Received: from [127.0.0.1] (10.166.215.237) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.487.0; Thu, 7 May 2020 17:28:20 +0800 To: , , , , , , <0x7f454c46@gmail.com>, , , , CC: , From: Yunfeng Ye Subject: [PATCH] arm64: stacktrace: Factor out some common code info on_stack() Message-ID: <10b188af-a03b-3acc-8a06-cf31a46f735a@huawei.com> Date: Thu, 7 May 2020 17:28:19 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.166.215.237] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There are some common codes for stack checking, so factors it out into the function on_stack() and on_valid_stack(). No functional change. Signed-off-by: Yunfeng Ye --- arch/arm64/include/asm/stacktrace.h | 53 +++++++++++++++++-------------------- arch/arm64/kernel/sdei.c | 28 ++------------------ 2 files changed, 26 insertions(+), 55 deletions(-) diff --git a/arch/arm64/include/asm/stacktrace.h b/arch/arm64/include/asm/stacktrace.h index fdb913cc0bcb..b92bef2fb6cd 100644 --- a/arch/arm64/include/asm/stacktrace.h +++ b/arch/arm64/include/asm/stacktrace.h @@ -69,27 +69,40 @@ extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk, DECLARE_PER_CPU(unsigned long *, irq_stack_ptr); -static inline bool on_irq_stack(unsigned long sp, +static inline bool on_stack(unsigned long sp, unsigned long low, + unsigned long high, enum stack_type type, struct stack_info *info) { - unsigned long low = (unsigned long)raw_cpu_read(irq_stack_ptr); - unsigned long high = low + IRQ_STACK_SIZE; - - if (!low) - return false; - if (sp < low || sp >= high) return false; if (info) { info->low = low; info->high = high; - info->type = STACK_TYPE_IRQ; + info->type = type; } - return true; } +static inline bool on_valid_stack(unsigned long sp, unsigned long low, + unsigned long high, enum stack_type type, + struct stack_info *info) +{ + if (!low) + return false; + + return on_stack(sp, low, high, type, info); +} + +static inline bool on_irq_stack(unsigned long sp, + struct stack_info *info) +{ + unsigned long low = (unsigned long)raw_cpu_read(irq_stack_ptr); + unsigned long high = low + IRQ_STACK_SIZE; + + return on_valid_stack(sp, low, high, STACK_TYPE_IRQ, info); +} + static inline bool on_task_stack(const struct task_struct *tsk, unsigned long sp, struct stack_info *info) @@ -97,16 +110,7 @@ static inline bool on_task_stack(const struct task_struct *tsk, unsigned long low = (unsigned long)task_stack_page(tsk); unsigned long high = low + THREAD_SIZE; - if (sp < low || sp >= high) - return false; - - if (info) { - info->low = low; - info->high = high; - info->type = STACK_TYPE_TASK; - } - - return true; + return on_stack(sp, low, high, STACK_TYPE_TASK, info); } #ifdef CONFIG_VMAP_STACK @@ -118,16 +122,7 @@ static inline bool on_overflow_stack(unsigned long sp, unsigned long low = (unsigned long)raw_cpu_ptr(overflow_stack); unsigned long high = low + OVERFLOW_STACK_SIZE; - if (sp < low || sp >= high) - return false; - - if (info) { - info->low = low; - info->high = high; - info->type = STACK_TYPE_OVERFLOW; - } - - return true; + return on_stack(sp, low, high, STACK_TYPE_OVERFLOW, info); } #else static inline bool on_overflow_stack(unsigned long sp, diff --git a/arch/arm64/kernel/sdei.c b/arch/arm64/kernel/sdei.c index d6259dac62b6..1758fcaa45dd 100644 --- a/arch/arm64/kernel/sdei.c +++ b/arch/arm64/kernel/sdei.c @@ -95,19 +95,7 @@ static bool on_sdei_normal_stack(unsigned long sp, struct stack_info *info) unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_normal_ptr); unsigned long high = low + SDEI_STACK_SIZE; - if (!low) - return false; - - if (sp < low || sp >= high) - return false; - - if (info) { - info->low = low; - info->high = high; - info->type = STACK_TYPE_SDEI_NORMAL; - } - - return true; + return on_valid_stack(sp, low, high, STACK_TYPE_SDEI_NORMAL, info); } static bool on_sdei_critical_stack(unsigned long sp, struct stack_info *info) @@ -115,19 +103,7 @@ static bool on_sdei_critical_stack(unsigned long sp, struct stack_info *info) unsigned long low = (unsigned long)raw_cpu_read(sdei_stack_critical_ptr); unsigned long high = low + SDEI_STACK_SIZE; - if (!low) - return false; - - if (sp < low || sp >= high) - return false; - - if (info) { - info->low = low; - info->high = high; - info->type = STACK_TYPE_SDEI_CRITICAL; - } - - return true; + return on_valid_stack(sp, low, high, STACK_TYPE_SDEI_CRITICAL, info); } bool _on_sdei_stack(unsigned long sp, struct stack_info *info) -- 1.8.3.1