From patchwork Mon May 2 19:12:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 12834638 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 005DFC433EF for ; Mon, 2 May 2022 19:13:58 +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:From:Subject:References:Mime-Version :Message-Id:In-Reply-To:Date:Reply-To:To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=bE3r/cfP1IAcZw8daz+3u0KCVIuiQ5qOlEnU7OzJwro=; b=kNq+4Xfdt0OOem Nk3Eiku7j+c9+vpLRFX3fuBoUZPAjb5JIw2uRxRoQWShOZCYRC33kYQN9Zbt/QlE1vcR+otLZ9A4e G30LpNakW5yvbzsXkPAnogz5qPPBhVkDAM3G5EZ5qMI/jduvlswm6VEkGEnI/xcngZi3vUfyuqnui AiyggnLqF+LZ5L1yKV2RuFOauD/6OZiUWBKl7q/T2TxJj6RHDePjQCb0qcKYzLp3sJwjajGoqwghQ 2byag9XlppiJTEwbiY5QwkQxW/UGt128mUksz5Z/3IGKC0EOMcLOPUr5oqC+UGehje0481GigEf2J HOibOQj/O1ApIoPAX0rA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nlbTc-002Jrc-0e; Mon, 02 May 2022 19:12:56 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nlbTZ-002Jr6-6S for linux-arm-kernel@lists.infradead.org; Mon, 02 May 2022 19:12:54 +0000 Received: by mail-yb1-xb49.google.com with SMTP id b6-20020a253406000000b006484c081280so13909088yba.5 for ; Mon, 02 May 2022 12:12:51 -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:cc; bh=SbkfFHwtj6LDfXcNEKyNCOiQxOwKu8gDiCPd3B2piLM=; b=EDJR3DTAX2eHb+n+nXs3NyHOQJ5iRpUPyz9W4sVPdLTKifwIuceSm9nqbUt+EAUjs8 Uy7YZCVBjsQZMuZZcYGoCTs3O2Q/0PWU1nemxTVCkyltR+Pfraxqcm/Mij0yMMW/vQpX 7o+MND69tDg8pttIB2MbNlqW61RbtG5ybH/CaNOoZlcGKOazY5whaBWWiNA+qS9nBW32 lGox+qsH97d8T7BvUlXqz4iiarm8kZeWQnrhNR/mPh4JMvWU2LVL4KaXwOnrglgIsYjJ 4umG8AwCaxD8GgaeNHACi79kPhW7xzf/d4gjHIFvgZyqSBDCJJIazbd++y+qCRLqv5Go POdw== 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:cc; bh=SbkfFHwtj6LDfXcNEKyNCOiQxOwKu8gDiCPd3B2piLM=; b=GynM6m4wtn7bM+Zor/6QT3fsZb69ziVevYhX91E3xJ07qc94twLKx+045d54Oenv9p WRWoOLXpqll3OnKUMHqHJXtiLfGRKiSpuIBe8CwVJpEGtblQTgYEeUJi///UdHHSIIVH D0iO4cghlvOL8FdOuSBV//yJFgaWEIJ4vnTcIRwSZTS5eZ5BHvIuAOS6saznQAIiw0hW qvlBqhXfYJjDAXBZYXxhfaNb/i2rMFTKM7Sh/a8S241gfm5noSWuZnFLO85PwkIECf5d bGyIr9ofnKiUwsPZDNqhxHodW5FxX/xhVIyAltkfEaQOo6Lwm7jg+jkeDj44vkpN7OTc p7eg== X-Gm-Message-State: AOAM531KRuRXNMou4XhXjuCtAWhnCdtjKzhNiMqvHFtQRVjlxfSKbP4u jDqcYcgKQZzKiXgb0b+qApu0h8CIJSy9Fv2nuw== X-Google-Smtp-Source: ABdhPJxP2xIlP7KifAzH0zbmoPkFGlaCnGx7XBRgqtsRS8QtrsuRrH/CX2j863LkhO0OA3feG1oXuqpQ/Sp0DoMkEA== X-Received: from kaleshsingh.mtv.corp.google.com ([2620:15c:211:200:55c:7548:7073:c14f]) (user=kaleshsingh job=sendgmr) by 2002:a0d:e8c7:0:b0:2f4:cd95:76d8 with SMTP id r190-20020a0de8c7000000b002f4cd9576d8mr12025072ywe.55.1651518771017; Mon, 02 May 2022 12:12:51 -0700 (PDT) Date: Mon, 2 May 2022 12:12:01 -0700 In-Reply-To: <20220502191222.4192768-1-kaleshsingh@google.com> Message-Id: <20220502191222.4192768-2-kaleshsingh@google.com> Mime-Version: 1.0 References: <20220502191222.4192768-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.36.0.464.gb9c8b46e94-goog Subject: [PATCH v2 1/5] KVM: arm64: Factor out common stack unwinding logic From: Kalesh Singh Cc: mark.rutland@arm.com, broonie@kernel.org, will@kernel.org, maz@kernel.org, qperret@google.com, tabba@google.com, surenb@google.com, kernel-team@android.com, Kalesh Singh , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Masami Hiramatsu , Peter Collingbourne , Alexei Starovoitov , "Madhavan T. Venkataraman" , Andrew Jones , Keir Fraser , Marco Elver , Kefeng Wang , Zenghui Yu , Ard Biesheuvel , 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-20220502_121253_276761_F62EDEEB X-CRM114-Status: GOOD ( 16.56 ) 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 --- 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);