From: Kalesh Singh <kaleshsingh@google.com>
To: unlisted-recipients:; (no To-header on input)
Cc: mark.rutland@arm.com, will@kernel.org, maz@kernel.org,
qperret@google.com, tabba@google.com, surenb@google.com,
kernel-team@android.com, Kalesh Singh <kaleshsingh@google.com>,
James Morse <james.morse@arm.com>,
Alexandru Elisei <alexandru.elisei@arm.com>,
Suzuki K Poulose <suzuki.poulose@arm.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Masami Hiramatsu <mhiramat@kernel.org>,
Mark Brown <broonie@kernel.org>,
Peter Collingbourne <pcc@google.com>,
Alexei Starovoitov <ast@kernel.org>,
"Madhavan T. Venkataraman" <madvenka@linux.microsoft.com>,
Andrew Jones <drjones@redhat.com>,
Zenghui Yu <yuzenghui@huawei.com>, Keir Fraser <keirf@google.com>,
Kefeng Wang <wangkefeng.wang@huawei.com>,
linux-arm-kernel@lists.infradead.org,
kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org
Subject: [PATCH 1/4] KVM: arm64: Compile stacktrace.nvhe.o
Date: Wed, 27 Apr 2022 11:46:56 -0700 [thread overview]
Message-ID: <20220427184716.1949239-2-kaleshsingh@google.com> (raw)
In-Reply-To: <20220427184716.1949239-1-kaleshsingh@google.com>
Recompile stack unwinding code for use with the nVHE hypervisor. This is
a preparatory patch that will allow reusing most of the kernel unwinding
logic in the nVHE hypervisor.
Suggested-by: Mark Rutland <mark.rutland@arm.com>
Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
---
arch/arm64/include/asm/stacktrace.h | 18 ++++---
arch/arm64/kernel/stacktrace.c | 73 ++++++++++++++++++-----------
arch/arm64/kvm/hyp/nvhe/Makefile | 3 +-
3 files changed, 60 insertions(+), 34 deletions(-)
diff --git a/arch/arm64/include/asm/stacktrace.h b/arch/arm64/include/asm/stacktrace.h
index aec9315bf156..f5af9a94c5a6 100644
--- a/arch/arm64/include/asm/stacktrace.h
+++ b/arch/arm64/include/asm/stacktrace.h
@@ -16,12 +16,14 @@
#include <asm/sdei.h>
enum stack_type {
- STACK_TYPE_UNKNOWN,
+#ifndef __KVM_NVHE_HYPERVISOR__
STACK_TYPE_TASK,
STACK_TYPE_IRQ,
STACK_TYPE_OVERFLOW,
STACK_TYPE_SDEI_NORMAL,
STACK_TYPE_SDEI_CRITICAL,
+#endif /* !__KVM_NVHE_HYPERVISOR__ */
+ STACK_TYPE_UNKNOWN,
__NR_STACK_TYPES
};
@@ -31,11 +33,6 @@ struct stack_info {
enum stack_type type;
};
-extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk,
- const char *loglvl);
-
-DECLARE_PER_CPU(unsigned long *, irq_stack_ptr);
-
static inline bool on_stack(unsigned long sp, unsigned long size,
unsigned long low, unsigned long high,
enum stack_type type, struct stack_info *info)
@@ -54,6 +51,12 @@ static inline bool on_stack(unsigned long sp, unsigned long size,
return true;
}
+#ifndef __KVM_NVHE_HYPERVISOR__
+extern void dump_backtrace(struct pt_regs *regs, struct task_struct *tsk,
+ const char *loglvl);
+
+DECLARE_PER_CPU(unsigned long *, irq_stack_ptr);
+
static inline bool on_irq_stack(unsigned long sp, unsigned long size,
struct stack_info *info)
{
@@ -88,6 +91,7 @@ static inline bool on_overflow_stack(unsigned long sp, unsigned long size,
static inline bool on_overflow_stack(unsigned long sp, unsigned long size,
struct stack_info *info) { return false; }
#endif
+#endif /* !__KVM_NVHE_HYPERVISOR__ */
/*
@@ -101,6 +105,7 @@ static inline bool on_accessible_stack(const struct task_struct *tsk,
if (info)
info->type = STACK_TYPE_UNKNOWN;
+#ifndef __KVM_NVHE_HYPERVISOR__
if (on_task_stack(tsk, sp, size, info))
return true;
if (tsk != current || preemptible())
@@ -111,6 +116,7 @@ static inline bool on_accessible_stack(const struct task_struct *tsk,
return true;
if (on_sdei_stack(sp, size, info))
return true;
+#endif /* !__KVM_NVHE_HYPERVISOR__ */
return false;
}
diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c
index 0467cb79f080..a84e38d41d38 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,45 @@ 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);
+
+static void notrace unwind(struct task_struct *tsk,
+ struct unwind_state *state,
+ stack_trace_consume_fn consume_entry, void *cookie)
+{
+ while (1) {
+ int ret;
+
+ if (!consume_entry(cookie, state->pc))
+ break;
+ ret = unwind_next(tsk, state);
+ if (ret < 0)
+ break;
+ }
+}
+NOKPROBE_SYMBOL(unwind);
+
+#ifndef __KVM_NVHE_HYPERVISOR__
+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);
@@ -157,22 +191,6 @@ static int notrace unwind_next(struct task_struct *tsk,
}
NOKPROBE_SYMBOL(unwind_next);
-static void notrace unwind(struct task_struct *tsk,
- struct unwind_state *state,
- stack_trace_consume_fn consume_entry, void *cookie)
-{
- while (1) {
- int ret;
-
- if (!consume_entry(cookie, state->pc))
- break;
- ret = unwind_next(tsk, state);
- if (ret < 0)
- break;
- }
-}
-NOKPROBE_SYMBOL(unwind);
-
static bool dump_backtrace_entry(void *arg, unsigned long where)
{
char *loglvl = arg;
@@ -224,3 +242,4 @@ noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry,
unwind(task, &state, consume_entry, cookie);
}
+#endif /* !__KVM_NVHE_HYPERVISOR__ */
diff --git a/arch/arm64/kvm/hyp/nvhe/Makefile b/arch/arm64/kvm/hyp/nvhe/Makefile
index f9fe4dc21b1f..c0ff0d6fc403 100644
--- a/arch/arm64/kvm/hyp/nvhe/Makefile
+++ b/arch/arm64/kvm/hyp/nvhe/Makefile
@@ -14,7 +14,8 @@ lib-objs := $(addprefix ../../../lib/, $(lib-objs))
obj-y := timer-sr.o sysreg-sr.o debug-sr.o switch.o tlb.o hyp-init.o host.o \
hyp-main.o hyp-smp.o psci-relay.o early_alloc.o page_alloc.o \
- cache.o setup.o mm.o mem_protect.o sys_regs.o pkvm.o
+ cache.o setup.o mm.o mem_protect.o sys_regs.o pkvm.o \
+ ../../../kernel/stacktrace.o
obj-y += ../vgic-v3-sr.o ../aarch32.o ../vgic-v2-cpuif-proxy.o ../entry.o \
../fpsimd.o ../hyp-entry.o ../exception.o ../pgtable.o
obj-$(CONFIG_DEBUG_LIST) += list_debug.o
--
2.36.0.rc2.479.g8af0fa9b8e-goog
next prev parent reply other threads:[~2022-04-27 18:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-27 18:46 [PATCH 0/4] KVM nVHE Hypervisor stack unwinder Kalesh Singh
2022-04-27 18:46 ` Kalesh Singh [this message]
2022-04-29 12:47 ` [PATCH 1/4] KVM: arm64: Compile stacktrace.nvhe.o Mark Brown
2022-04-29 16:25 ` Kalesh Singh
2022-04-27 18:46 ` [PATCH 2/4] KVM: arm64: Add hypervisor overflow stack Kalesh Singh
2022-04-27 18:46 ` [PATCH 3/4] KVM: arm64: Allocate shared stacktrace pages Kalesh Singh
2022-04-27 18:46 ` [PATCH 4/4] KVM: arm64: Unwind and dump nVHE hypervisor stacktrace Kalesh Singh
2022-04-29 13:24 ` 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=20220427184716.1949239-2-kaleshsingh@google.com \
--to=kaleshsingh@google.com \
--cc=alexandru.elisei@arm.com \
--cc=ast@kernel.org \
--cc=broonie@kernel.org \
--cc=catalin.marinas@arm.com \
--cc=drjones@redhat.com \
--cc=james.morse@arm.com \
--cc=keirf@google.com \
--cc=kernel-team@android.com \
--cc=kvmarm@lists.cs.columbia.edu \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=madvenka@linux.microsoft.com \
--cc=mark.rutland@arm.com \
--cc=maz@kernel.org \
--cc=mhiramat@kernel.org \
--cc=pcc@google.com \
--cc=qperret@google.com \
--cc=surenb@google.com \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=wangkefeng.wang@huawei.com \
--cc=will@kernel.org \
--cc=yuzenghui@huawei.com \
/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
all inboxes | Powered by JetHome®