public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
From: Mark Rutland <mark.rutland@arm.com>
To: linux-arm-kernel@lists.infradead.org
Cc: broonie@kernel.org, catalin.marinas@arm.com, james.morse@arm.com,
	kaleshsingh@google.com, madvenka@linux.microsoft.com,
	mark.rutland@arm.com, maz@kernel.org, tabba@google.com,
	will@kernel.org
Subject: [PATCH v2 6/8] arm64: stacktrace: remove stack type from fp translator
Date: Fri,  5 Aug 2022 13:45:20 +0100	[thread overview]
Message-ID: <20220805124522.706457-7-mark.rutland@arm.com> (raw)
In-Reply-To: <20220805124522.706457-1-mark.rutland@arm.com>

In subsequent patches we'll remove the stack_type enum, and move the FP
translation logic out of the raw FP unwind code.

In preparation for doing so, this patch removes the type parameter from
the FP translation callback, and modifies kvm_nvhe_stack_kern_va() to
determine the relevant stack directly.

So that kvm_nvhe_stack_kern_va() can use the stackinfo_*() helpers,
these are moved earlier in the file, but are not modified in any way.

Signed-off-by: Mark Rutland <mark.rutland@arm.com>
Reviewed-by: Kalesh Singh <kaleshsingh@google.com>
Cc: Fuad Tabba <tabba@google.com>
Cc: Madhavan T. Venkataraman <madvenka@linux.microsoft.com>
Cc: Marc Zyngier <maz@kernel.org>
Cc: Mark Brown <broonie@kernel.org>
---
 arch/arm64/include/asm/stacktrace/common.h |  6 +-
 arch/arm64/kvm/stacktrace.c                | 78 ++++++++++++----------
 2 files changed, 43 insertions(+), 41 deletions(-)

diff --git a/arch/arm64/include/asm/stacktrace/common.h b/arch/arm64/include/asm/stacktrace/common.h
index 0071f2459c703..0bd9d7ad295e0 100644
--- a/arch/arm64/include/asm/stacktrace/common.h
+++ b/arch/arm64/include/asm/stacktrace/common.h
@@ -114,13 +114,11 @@ static inline void unwind_init_common(struct unwind_state *state,
  * a kernel address.
  *
  * @fp:   the frame pointer to be updated to its kernel address.
- * @type: the stack type associated with frame pointer @fp
  *
  * Returns true and success and @fp is updated to the corresponding
  * kernel virtual address; otherwise returns false.
  */
-typedef bool (*stack_trace_translate_fp_fn)(unsigned long *fp,
-					    enum stack_type type);
+typedef bool (*stack_trace_translate_fp_fn)(unsigned long *fp);
 
 /*
  * on_accessible_stack_fn() - Check whether a stack range is on any
@@ -165,7 +163,7 @@ unwind_next_frame_record(struct unwind_state *state,
 	 * If fp is not from the current address space perform the necessary
 	 * translation before dereferencing it to get the next fp.
 	 */
-	if (translate_fp && !translate_fp(&kern_fp, info.type))
+	if (translate_fp && !translate_fp(&kern_fp))
 		return -EINVAL;
 
 	/*
diff --git a/arch/arm64/kvm/stacktrace.c b/arch/arm64/kvm/stacktrace.c
index 26927344a2632..abdc231ae70fd 100644
--- a/arch/arm64/kvm/stacktrace.c
+++ b/arch/arm64/kvm/stacktrace.c
@@ -21,6 +21,34 @@
 
 #include <asm/stacktrace/nvhe.h>
 
+static struct stack_info stackinfo_get_overflow(void)
+{
+	struct kvm_nvhe_stacktrace_info *stacktrace_info
+				= this_cpu_ptr_nvhe_sym(kvm_stacktrace_info);
+	unsigned long low = (unsigned long)stacktrace_info->overflow_stack_base;
+	unsigned long high = low + OVERFLOW_STACK_SIZE;
+
+	return (struct stack_info) {
+		.low = low,
+		.high = high,
+		.type = STACK_TYPE_OVERFLOW,
+	};
+}
+
+static struct stack_info stackinfo_get_hyp(void)
+{
+	struct kvm_nvhe_stacktrace_info *stacktrace_info
+				= this_cpu_ptr_nvhe_sym(kvm_stacktrace_info);
+	unsigned long low = (unsigned long)stacktrace_info->stack_base;
+	unsigned long high = low + PAGE_SIZE;
+
+	return (struct stack_info) {
+		.low = low,
+		.high = high,
+		.type = STACK_TYPE_HYP,
+	};
+}
+
 /*
  * kvm_nvhe_stack_kern_va - Convert KVM nVHE HYP stack addresses to a kernel VAs
  *
@@ -34,27 +62,31 @@
  * Returns true on success and updates @addr to its corresponding kernel VA;
  * otherwise returns false.
  */
-static bool kvm_nvhe_stack_kern_va(unsigned long *addr,
-				   enum stack_type type)
+static bool kvm_nvhe_stack_kern_va(unsigned long *addr)
 {
 	struct kvm_nvhe_stacktrace_info *stacktrace_info;
 	unsigned long hyp_base, kern_base, hyp_offset;
+	struct stack_info stack;
 
 	stacktrace_info = this_cpu_ptr_nvhe_sym(kvm_stacktrace_info);
 
-	switch (type) {
-	case STACK_TYPE_HYP:
+	stack = stackinfo_get_hyp();
+	if (stackinfo_on_stack(&stack, *addr, 1)) {
 		kern_base = (unsigned long)*this_cpu_ptr(&kvm_arm_hyp_stack_page);
 		hyp_base = (unsigned long)stacktrace_info->stack_base;
-		break;
-	case STACK_TYPE_OVERFLOW:
+		goto found;
+	}
+
+	stack = stackinfo_get_overflow();
+	if (stackinfo_on_stack(&stack, *addr, 1)) {
 		kern_base = (unsigned long)this_cpu_ptr_nvhe_sym(overflow_stack);
 		hyp_base = (unsigned long)stacktrace_info->overflow_stack_base;
-		break;
-	default:
-		return false;
+		goto found;
 	}
 
+	return false;
+
+found:
 	hyp_offset = *addr - hyp_base;
 
 	*addr = kern_base + hyp_offset;
@@ -62,34 +94,6 @@ static bool kvm_nvhe_stack_kern_va(unsigned long *addr,
 	return true;
 }
 
-static struct stack_info stackinfo_get_overflow(void)
-{
-	struct kvm_nvhe_stacktrace_info *stacktrace_info
-				= this_cpu_ptr_nvhe_sym(kvm_stacktrace_info);
-	unsigned long low = (unsigned long)stacktrace_info->overflow_stack_base;
-	unsigned long high = low + OVERFLOW_STACK_SIZE;
-
-	return (struct stack_info) {
-		.low = low,
-		.high = high,
-		.type = STACK_TYPE_OVERFLOW,
-	};
-}
-
-static struct stack_info stackinfo_get_hyp(void)
-{
-	struct kvm_nvhe_stacktrace_info *stacktrace_info
-				= this_cpu_ptr_nvhe_sym(kvm_stacktrace_info);
-	unsigned long low = (unsigned long)stacktrace_info->stack_base;
-	unsigned long high = low + PAGE_SIZE;
-
-	return (struct stack_info) {
-		.low = low,
-		.high = high,
-		.type = STACK_TYPE_HYP,
-	};
-}
-
 static bool on_accessible_stack(const struct task_struct *tsk,
 				unsigned long sp, unsigned long size,
 				struct stack_info *info)
-- 
2.30.2


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2022-08-05 12:48 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-05 12:45 [PATCH v2 0/8] arm64: stacktrace: cleanups and improvements Mark Rutland
2022-08-05 12:45 ` [PATCH v2 1/8] arm64: stacktrace: simplify unwind_next_common() Mark Rutland
2022-08-05 12:45 ` [PATCH v2 2/8] arm64: stacktrace: rename unwind_next_common() -> unwind_next_frame_record() Mark Rutland
2022-08-08 11:38   ` Will Deacon
2022-08-08 11:46     ` Mark Rutland
2022-08-05 12:45 ` [PATCH v2 3/8] arm64: stacktrace: move SDEI stack helpers to stacktrace code Mark Rutland
2022-08-05 12:45 ` [PATCH v2 4/8] arm64: stacktrace: add stackinfo_on_stack() helper Mark Rutland
2022-08-05 12:45 ` [PATCH v2 5/8] arm64: stacktrace: rework stack boundary discovery Mark Rutland
2022-08-05 12:45 ` Mark Rutland [this message]
2022-08-08 11:55   ` [PATCH v2 6/8] arm64: stacktrace: remove stack type from fp translator Will Deacon
2022-08-08 12:08     ` Mark Rutland
2022-08-08 12:30       ` Mark Rutland
2022-08-08 11:56   ` Mark Brown
2022-08-05 12:45 ` [PATCH v2 7/8] arm64: stacktrace: track all stack boundaries explicitly Mark Rutland
2022-08-08 12:04   ` Mark Brown
2022-08-05 12:45 ` [PATCH v2 8/8] arm64: stacktrace: track hyp stacks in unwinder's address space Mark Rutland
2022-08-08 12:09   ` Mark Brown
2022-08-06  1:11 ` [PATCH v2 0/8] arm64: stacktrace: cleanups and improvements Madhavan T. Venkataraman
2022-08-08 11:59 ` Will Deacon
2022-08-08 12:11   ` Mark Rutland
2022-08-08 12:28     ` Will Deacon
2022-08-08 12:33       ` Mark Rutland
2022-08-08 12:38     ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220805124522.706457-7-mark.rutland@arm.com \
    --to=mark.rutland@arm.com \
    --cc=broonie@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=james.morse@arm.com \
    --cc=kaleshsingh@google.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=madvenka@linux.microsoft.com \
    --cc=maz@kernel.org \
    --cc=tabba@google.com \
    --cc=will@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox