lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CA+EHjTy4ozkDCs0FECRnJFfN-_G0ye4uJ3OVhMRvzUQux-QL=A@mail.gmail.com>
Date:   Thu, 21 Jul 2022 10:58:50 +0100
From:   Fuad Tabba <tabba@...gle.com>
To:     Kalesh Singh <kaleshsingh@...gle.com>
Cc:     maz@...nel.org, mark.rutland@....com, broonie@...nel.org,
        madvenka@...ux.microsoft.com, will@...nel.org, qperret@...gle.com,
        james.morse@....com, alexandru.elisei@....com,
        suzuki.poulose@....com, catalin.marinas@....com,
        andreyknvl@...il.com, vincenzo.frascino@....com,
        mhiramat@...nel.org, ast@...nel.org, wangkefeng.wang@...wei.com,
        elver@...gle.com, keirf@...gle.com, yuzenghui@...wei.com,
        ardb@...nel.org, oupton@...gle.com,
        linux-arm-kernel@...ts.infradead.org, kvmarm@...ts.cs.columbia.edu,
        linux-kernel@...r.kernel.org, kernel-team@...roid.com
Subject: Re: [PATCH v5 15/17] KVM: arm64: Implement non-protected nVHE hyp
 stack unwinder

Hi Kalesh,

On Thu, Jul 21, 2022 at 6:58 AM Kalesh Singh <kaleshsingh@...gle.com> wrote:
>
> Implements the common framework necessary for unwind() to work
> for non-protected nVHE mode:
>     - on_accessible_stack()
>     - on_overflow_stack()
>     - unwind_next()
>
> Non-protected nVHE unwind() is used to unwind and dump the hypervisor
> stacktrace by the host in EL1
>
> Signed-off-by: Kalesh Singh <kaleshsingh@...gle.com>
> ---

Reviewed-by: Fuad Tabba <tabba@...gle.com>

Cheers,
/fuad


>
> Changes in v5:
>   - Use regular comments instead of doc comments, per Fuad
>
>  arch/arm64/include/asm/stacktrace/nvhe.h | 67 +++++++++++++++++++++++-
>  arch/arm64/kvm/arm.c                     |  2 +-
>  2 files changed, 66 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/include/asm/stacktrace/nvhe.h b/arch/arm64/include/asm/stacktrace/nvhe.h
> index c3688e717136..7a6e761aa443 100644
> --- a/arch/arm64/include/asm/stacktrace/nvhe.h
> +++ b/arch/arm64/include/asm/stacktrace/nvhe.h
> @@ -120,15 +120,78 @@ NOKPROBE_SYMBOL(unwind_next);
>   * (by the host in EL1).
>   */
>
> +DECLARE_KVM_NVHE_PER_CPU(unsigned long [PAGE_SIZE/sizeof(long)], overflow_stack);
> +DECLARE_KVM_NVHE_PER_CPU(struct kvm_nvhe_stacktrace_info, kvm_stacktrace_info);
> +DECLARE_PER_CPU(unsigned long, kvm_arm_hyp_stack_page);
> +
> +/*
> + * kvm_nvhe_stack_kern_va - Convert KVM nVHE HYP stack addresses to a kernel VAs
> + *
> + * The nVHE hypervisor stack is mapped in the flexible 'private' VA range, to
> + * allow for guard pages below the stack. Consequently, the fixed offset address
> + * translation macros won't work here.
> + *
> + * The kernel VA is calculated as an offset from the kernel VA of the hypervisor
> + * stack base.
> + *
> + * Returns true on success and updates @addr to its corresponding kernel VA;
> + * otherwise returns false.
> + */
> +static inline bool kvm_nvhe_stack_kern_va(unsigned long *addr,
> +                                         enum stack_type type)
> +{
> +       struct kvm_nvhe_stacktrace_info *stacktrace_info;
> +       unsigned long hyp_base, kern_base, hyp_offset;
> +
> +       stacktrace_info = this_cpu_ptr_nvhe_sym(kvm_stacktrace_info);
> +
> +       switch (type) {
> +       case STACK_TYPE_HYP:
> +               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:
> +               kern_base = (unsigned long)this_cpu_ptr_nvhe_sym(overflow_stack);
> +               hyp_base = (unsigned long)stacktrace_info->overflow_stack_base;
> +               break;
> +       default:
> +               return false;
> +       }
> +
> +       hyp_offset = *addr - hyp_base;
> +
> +       *addr = kern_base + hyp_offset;
> +
> +       return true;
> +}
> +
>  static inline bool on_overflow_stack(unsigned long sp, unsigned long size,
>                                      struct stack_info *info)
>  {
> -       return false;
> +       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 on_stack(sp, size, low, high, STACK_TYPE_OVERFLOW, info);
> +}
> +
> +static inline bool on_hyp_stack(unsigned long sp, unsigned long size,
> +                               struct stack_info *info)
> +{
> +       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 on_stack(sp, size, low, high, STACK_TYPE_HYP, info);
>  }
>
>  static inline int notrace unwind_next(struct unwind_state *state)
>  {
> -       return 0;
> +       struct stack_info info;
> +
> +       return unwind_next_common(state, &info, kvm_nvhe_stack_kern_va);
>  }
>  NOKPROBE_SYMBOL(unwind_next);
>
> diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c
> index a0188144a122..6a64293108c5 100644
> --- a/arch/arm64/kvm/arm.c
> +++ b/arch/arm64/kvm/arm.c
> @@ -49,7 +49,7 @@ DEFINE_STATIC_KEY_FALSE(kvm_protected_mode_initialized);
>
>  DECLARE_KVM_HYP_PER_CPU(unsigned long, kvm_hyp_vector);
>
> -static DEFINE_PER_CPU(unsigned long, kvm_arm_hyp_stack_page);
> +DEFINE_PER_CPU(unsigned long, kvm_arm_hyp_stack_page);
>  unsigned long kvm_arm_hyp_percpu_base[NR_CPUS];
>  DECLARE_KVM_NVHE_PER_CPU(struct kvm_nvhe_init_params, kvm_init_params);
>
> --
> 2.37.0.170.g444d1eabd0-goog
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ