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 <[email protected]>
Signed-off-by: Kalesh Singh <[email protected]>
Reviewed-by: Mark Brown <[email protected]>
---
Changes in v3:
- Add Mark's Reviewed-by tag
Changes in v2:
- Split out refactoring of common unwinding logic into a separate patch,
per Mark Brown
arch/arm64/include/asm/stacktrace.h | 18 +++++++++-----
arch/arm64/kernel/stacktrace.c | 37 ++++++++++++++++-------------
arch/arm64/kvm/hyp/nvhe/Makefile | 3 ++-
3 files changed, 35 insertions(+), 23 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 ee60c279511c..a84e38d41d38 100644
--- a/arch/arm64/kernel/stacktrace.c
+++ b/arch/arm64/kernel/stacktrace.c
@@ -129,6 +129,26 @@ static int notrace __unwind_next(struct task_struct *tsk,
}
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)
{
@@ -171,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;
@@ -238,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.1.255.ge46751e96f-goog
On Tue, 07 Jun 2022 17:50:44 +0100,
Kalesh Singh <[email protected]> wrote:
>
> 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 <[email protected]>
> Signed-off-by: Kalesh Singh <[email protected]>
> Reviewed-by: Mark Brown <[email protected]>
> ---
>
> Changes in v3:
> - Add Mark's Reviewed-by tag
>
> Changes in v2:
> - Split out refactoring of common unwinding logic into a separate patch,
> per Mark Brown
>
> arch/arm64/include/asm/stacktrace.h | 18 +++++++++-----
> arch/arm64/kernel/stacktrace.c | 37 ++++++++++++++++-------------
> arch/arm64/kvm/hyp/nvhe/Makefile | 3 ++-
> 3 files changed, 35 insertions(+), 23 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,
What is the reason for this reordering? I have the sinking feeling
that this could play badly with the logic that assumes that it is
legal to switch from a lesser stack type to a higher one, and could
allow switching to a duff stack.
I would at least like to see a justification of why this isn't less
safe than the current code.
[...]
> 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
This, I positively hate. It is only a marginally better than the
cross-arch references we used to have with arch/arm/kvm. I'd be much
more happy with an include file containing the shared code. It would
also allow the removal of some of the #ifdeferry. Note that this is
the approach that we ended up adopting for the VHE/nVHE split.
Thanks,
M.
--
Without deviation from the norm, progress is not possible.
On Wed, Jun 8, 2022 at 12:33 AM Marc Zyngier <[email protected]> wrote:
>
> On Tue, 07 Jun 2022 17:50:44 +0100,
> Kalesh Singh <[email protected]> wrote:
> >
> > 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 <[email protected]>
> > Signed-off-by: Kalesh Singh <[email protected]>
> > Reviewed-by: Mark Brown <[email protected]>
> > ---
> >
> > Changes in v3:
> > - Add Mark's Reviewed-by tag
> >
> > Changes in v2:
> > - Split out refactoring of common unwinding logic into a separate patch,
> > per Mark Brown
> >
> > arch/arm64/include/asm/stacktrace.h | 18 +++++++++-----
> > arch/arm64/kernel/stacktrace.c | 37 ++++++++++++++++-------------
> > arch/arm64/kvm/hyp/nvhe/Makefile | 3 ++-
> > 3 files changed, 35 insertions(+), 23 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,
>
> What is the reason for this reordering? I have the sinking feeling
> that this could play badly with the logic that assumes that it is
> legal to switch from a lesser stack type to a higher one, and could
> allow switching to a duff stack.
HI Marc. Thanks for reviewing.
I only reordered the enum to group the common types. But I don't have
a strong opinion on it. The unwinding doesn't depend on the ordering
in this enum. When we transition form stack 'A'-->'B', we set the
stack_done bit for stack A so that we never transition back to 'A', as
it's not valid to transition back to a previous stack. But the order
of the sequence itself is not something enforced.
>
> I would at least like to see a justification of why this isn't less
> safe than the current code.
>
> [...]
>
> > 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
>
> This, I positively hate. It is only a marginally better than the
> cross-arch references we used to have with arch/arm/kvm. I'd be much
> more happy with an include file containing the shared code. It would
> also allow the removal of some of the #ifdeferry. Note that this is
> the approach that we ended up adopting for the VHE/nVHE split.
>
Also thought about moving stuff to some header file, but I thought
this might be less intrusive. Let me prototype to see how they
compare.
Thanks,
Kalesh
> Thanks,
>
> M.
>
> --
> Without deviation from the norm, progress is not possible.
>
> --
> To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
>