From patchwork Tue Jun 7 16:50:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 12872143 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E21D6C43334 for ; Tue, 7 Jun 2022 16:52:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=zEZoXhejLqbVdF2z9Q4qkhdYvQ3RkcgsvSDdLqhfVqE=; b=zO8plKqstSriKcMTStcsRytCwN EbrKrFvOZr9PHzovE8SHO3u99iZIlRlqAF9JcNl1vdj5V474DQ0UvH0HVgaHMsA4fprLnkUlXkluV auhBgdJ6DllXkEMkPlcWTo4L+5SlbeQahWey7JdgC8IIPyYemXUyAhNFrJqm4A0RzzDzn8+NINV/D zAvRKoYUro7wR4lhQXOvl7APmGWbAv5C11XpnZs5I3jI50yJZudj28EMn7OJ/5Jr8cPU6WnfCQPFh D4vLf4O5TwNqEPHxu++BcNq9Ea84IsDvnyxAHxhS0jqZeh8CVWc3VWFoYxVn9bMgd9fbcui1gfsUa 4SbKHNig==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nycQo-008TqM-L0; Tue, 07 Jun 2022 16:51:50 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nycQf-008Tlv-Jw for linux-arm-kernel@lists.infradead.org; Tue, 07 Jun 2022 16:51:44 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-2fb7cb07885so152986937b3.23 for ; Tue, 07 Jun 2022 09:51:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=utThYmevKONU/9m2pQGdDHA12doEH9idunElwn0Wp+Y=; b=gUIQMQl0JQzhYd3S4fyRf5XmWfJe5lmGtNGJawPlt9xGCh6iVfChXa73AoojCUrlbl IVXeOtMoTYUHDpAFH3A8brBwPVcti7T1TXiYbRGm9WL+wI2w1S/KEwaSu9WutVR9tygx 84Kvg+VfGwL6M1f0ziUNEjgMhLSuSnn44AbVKJ9wncUs/50JTgmnIHf+wQmtrOV7M8Mt K4uO5mPCKZewDVjZ3Ihsg/rY8/0Ud5jqcoTKOFhCTALO+vhAlMfVTPQqBzexRVTQ5AE6 AWpm7eIByU/UruiBwIFFfpmgXXAyJwhbholwIR4cxXKH/anXN/52PMZ9cQYrHOq/XYDw pDWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=utThYmevKONU/9m2pQGdDHA12doEH9idunElwn0Wp+Y=; b=AYrFL9mEDS2i7ePq+/n9KxNo0O30K3ksjhsLypEHA4urIpSeiHCnrioZfCMrz/GQvO XwKExRKCSHl3csVd0WsSqsk5S2M5IpuL/LvOv5WAJfD5tR/0lzAy4EM3TVT/5PdbusEY wCdehCwJTj4KA5osrjlq3L+Fn/4NOzKKWd4qDjqsYVN9i+dUjLv9t/B0iOL1B2Yne1Yf GGObtUNR5aCEXIJO8glGY2J0WG/9Xj2DXxDJtl9WGY0v+nZifFdz5GaVt66zewaYrs7A BU/PWFEahsQUrl4UFWR1a87gnSqTINJyPzIxcN9MN979byKAooOffRiRIy/Q5ZLv5GlQ DyVQ== X-Gm-Message-State: AOAM530MTQuSb+x2DSam7+fjsn5LNibsYiCMOEwIAtsTa3zQaDisAdg8 NXl9GnsV7hf1hXAx/Bp5EbOIf7+QoLqKyNMDZQ== X-Google-Smtp-Source: ABdhPJzuHcHlzERjFFs10J5b1VKR548pg9LJge0vp7jHTNhan1WTvDRj/6ZH8ppj3YV0piRTv9xwQbWhp9qkOIWgBQ== X-Received: from kaleshsingh.mtv.corp.google.com ([2620:15c:211:200:7091:8518:ec1e:93dc]) (user=kaleshsingh job=sendgmr) by 2002:a81:57d6:0:b0:30c:a234:140d with SMTP id l205-20020a8157d6000000b0030ca234140dmr33093505ywb.269.1654620698862; Tue, 07 Jun 2022 09:51:38 -0700 (PDT) Date: Tue, 7 Jun 2022 09:50:43 -0700 In-Reply-To: <20220607165105.639716-1-kaleshsingh@google.com> Message-Id: <20220607165105.639716-2-kaleshsingh@google.com> Mime-Version: 1.0 References: <20220607165105.639716-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.36.1.255.ge46751e96f-goog Subject: [PATCH v3 1/5] KVM: arm64: Factor out common stack unwinding logic From: Kalesh Singh To: mark.rutland@arm.com, broonie@kernel.org, maz@kernel.org Cc: will@kernel.org, qperret@google.com, tabba@google.com, surenb@google.com, tjmercier@google.com, kernel-team@android.com, Kalesh Singh , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Masami Hiramatsu , Alexei Starovoitov , "Madhavan T. Venkataraman" , Peter Zijlstra , Andrew Jones , Marco Elver , Kefeng Wang , Zenghui Yu , Keir Fraser , Ard Biesheuvel , Oliver Upton , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220607_095141_742556_576AA8A4 X-CRM114-Status: GOOD ( 17.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Factor out the stack unwinding logic common to both the host kernel and the nVHE hypersivor into __unwind_next(). This allows for reuse in the nVHE hypervisor stack unwinding (later in this series). Signed-off-by: Kalesh Singh Reviewed-by: Mark Brown --- Changes in v3: - Add Mark's Reviewed-by tag arch/arm64/kernel/stacktrace.c | 36 +++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 0467cb79f080..ee60c279511c 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -81,23 +81,19 @@ NOKPROBE_SYMBOL(unwind_init); * records (e.g. a cycle), determined based on the location and fp value of A * and the location (but not the fp value) of B. */ -static int notrace unwind_next(struct task_struct *tsk, - struct unwind_state *state) +static int notrace __unwind_next(struct task_struct *tsk, + struct unwind_state *state, + struct stack_info *info) { unsigned long fp = state->fp; - struct stack_info info; - - /* Final frame; nothing to unwind */ - if (fp == (unsigned long)task_pt_regs(tsk)->stackframe) - return -ENOENT; if (fp & 0x7) return -EINVAL; - if (!on_accessible_stack(tsk, fp, 16, &info)) + if (!on_accessible_stack(tsk, fp, 16, info)) return -EINVAL; - if (test_bit(info.type, state->stacks_done)) + if (test_bit(info->type, state->stacks_done)) return -EINVAL; /* @@ -113,7 +109,7 @@ static int notrace unwind_next(struct task_struct *tsk, * stack to another, it's never valid to unwind back to that first * stack. */ - if (info.type == state->prev_type) { + if (info->type == state->prev_type) { if (fp <= state->prev_fp) return -EINVAL; } else { @@ -127,7 +123,25 @@ static int notrace unwind_next(struct task_struct *tsk, state->fp = READ_ONCE_NOCHECK(*(unsigned long *)(fp)); state->pc = READ_ONCE_NOCHECK(*(unsigned long *)(fp + 8)); state->prev_fp = fp; - state->prev_type = info.type; + state->prev_type = info->type; + + return 0; +} +NOKPROBE_SYMBOL(__unwind_next); + +static int notrace unwind_next(struct task_struct *tsk, + struct unwind_state *state) +{ + struct stack_info info; + int err; + + /* Final frame; nothing to unwind */ + if (state->fp == (unsigned long)task_pt_regs(tsk)->stackframe) + return -ENOENT; + + err = __unwind_next(tsk, state, &info); + if (err) + return err; state->pc = ptrauth_strip_insn_pac(state->pc);