Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp149991pxb; Tue, 23 Feb 2021 21:17:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJzyaf5UZkoxyrsRoNdQNjC34W/wvsyHJp/IdgNuzbJMZU9KESDzaWyFUbig1bR+86gr6dGv X-Received: by 2002:aa7:cdd2:: with SMTP id h18mr29145879edw.38.1614143832994; Tue, 23 Feb 2021 21:17:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614143832; cv=none; d=google.com; s=arc-20160816; b=f47RWtZ1PDmufX8cJnVCvg0NDqM9mZyT4akReonu6UaYUN+IRK0ZIBcHQYbM+qhuLI Qj2PGGF2/eso0hrsZZI6KiWz6I4Vb/QLNCDFgnN8wfd0GD7hFsgmtsTBzWTQXAPmDbv7 2bmiQuZPlpU3DsntOQADP0feyT345xnDEQfqHQwFvl0lqG9Tk2dJONFRTIyXf1fqAuyK CKZ4c04mFJiUqpXnvUX+w69he5l9plv6RedXRTcrFh45xikJvnP0ah5weUKNWmLbSWmp wdLUOh4hMSkbQvOE3Wh/tGKzAt7wAoFOQMFHb5Rq0MveYoz/4rRbSo1tCt23biLBs3iw MGrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=tGbQaORsJJc7Bd83VijxONNNr5UhfRoLV+MS2tAhN98=; b=0h4fCnHa5r3XpDH34Cuo0HcRsLwax0+q8Kqw1u1ew8XxWJGzRK1ToEi7gLvZeRADSB YH4X5UE1rJ1dr5WT4YpyB4m13l8Mz3npcpHUCj51DWd+bdjp0xMEujh9zczEO3nT4lvK aDBtslqEXHuRwlbx1bMmUILl9bWDrUZOH7sOHTDRm5Sm/z2YL+KvCV6aBXTlCtkQpw77 wqi+xvo6DECvfNFJqeveXPr9MgKL3bK+AmYx7V4tVQol7SPYMAfsEEXJmlj8ReOqejMq 5DQkhAQUQgSH+VV33j6qx8YatPXh6kqx0JioJKz9eo7w9yUpdTlmMrDkBLGChBzWnZTr pHwQ== 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 a12si644960ejv.528.2021.02.23.21.16.46; Tue, 23 Feb 2021 21:17:12 -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 S232454AbhBWWsE (ORCPT + 99 others); Tue, 23 Feb 2021 17:48:04 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:12642 "EHLO szxga04-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232453AbhBWWc7 (ORCPT ); Tue, 23 Feb 2021 17:32:59 -0500 Received: from DGGEMS404-HUB.china.huawei.com (unknown [172.30.72.59]) by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4DlYf45Jcqz16BrH; Wed, 24 Feb 2021 06:30:20 +0800 (CST) Received: from SWX921481.china.huawei.com (10.126.200.133) by DGGEMS404-HUB.china.huawei.com (10.3.19.204) with Microsoft SMTP Server id 14.3.498.0; Wed, 24 Feb 2021 06:31:49 +0800 From: Barry Song To: , , , CC: , , , Barry Song Subject: [PATCH v2 2/2] scripts/gdb: add lx_current support for arm64 Date: Wed, 24 Feb 2021 11:25:40 +1300 Message-ID: <20210223222540.9120-3-song.bao.hua@hisilicon.com> X-Mailer: git-send-email 2.21.0.windows.1 In-Reply-To: <20210223222540.9120-1-song.bao.hua@hisilicon.com> References: <20210223222540.9120-1-song.bao.hua@hisilicon.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.126.200.133] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org arm64 uses SP_EL0 to save the current task_struct address. While running in EL0, SP_EL0 is clobbered by userspace. So if the upper bit is not 1 (not TTBR1), the current address is invalid. This patch checks the upper bit of SP_EL0, if the upper bit is 1, lx_current() of arm64 will return the derefrence of current task. Otherwise, lx_current() will tell users they are running in userspace(EL0). While arm64 is running in EL0, it is actually pointless to print current task as the memory of kernel space is not accessible in EL0. Signed-off-by: Barry Song --- Documentation/dev-tools/gdb-kernel-debugging.rst | 2 +- scripts/gdb/linux/cpus.py | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Documentation/dev-tools/gdb-kernel-debugging.rst b/Documentation/dev-tools/gdb-kernel-debugging.rst index 1586901b683c..8e0f1fe8d17a 100644 --- a/Documentation/dev-tools/gdb-kernel-debugging.rst +++ b/Documentation/dev-tools/gdb-kernel-debugging.rst @@ -114,7 +114,7 @@ Examples of using the Linux-provided gdb helpers [ 0.000000] BIOS-e820: [mem 0x000000000009fc00-0x000000000009ffff] reserved .... -- Examine fields of the current task struct(supported by x86 only):: +- Examine fields of the current task struct(supported by x86 and arm64 only):: (gdb) p $lx_current().pid $1 = 4998 diff --git a/scripts/gdb/linux/cpus.py b/scripts/gdb/linux/cpus.py index f382762509d3..15fc4626d236 100644 --- a/scripts/gdb/linux/cpus.py +++ b/scripts/gdb/linux/cpus.py @@ -16,6 +16,9 @@ import gdb from linux import tasks, utils +task_type = utils.CachedType("struct task_struct") + + MAX_CPUS = 4096 @@ -157,9 +160,19 @@ Note that VAR has to be quoted as string.""" PerCpu() def get_current_task(cpu): + task_ptr_type = task_type.get_type().pointer() + if utils.is_target_arch("x86"): var_ptr = gdb.parse_and_eval("¤t_task") return per_cpu(var_ptr, cpu).dereference() + elif utils.is_target_arch("aarch64"): + current_task_addr = gdb.parse_and_eval("$SP_EL0") + if((current_task_addr >> 63) != 0): + current_task = current_task_addr.cast(task_ptr_type) + return current_task.dereference() + else: + raise gdb.GdbError("Sorry, obtaining the current task is not allowed " + "while running in userspace(EL0)") else: raise gdb.GdbError("Sorry, obtaining the current task is not yet " "supported with this arch") -- 2.25.1