From patchwork Thu Jul 21 05:57:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 12924753 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 99CAEC433EF for ; Thu, 21 Jul 2022 06:06: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:To:From:Subject:References: Mime-Version:Message-Id:In-Reply-To:Date:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=msp2FJKxDw/Y1gdNi9HoUjuxF8yn6VzuanhMNkY5n9w=; b=c65MTb9GHRcVySrZhJK/us+nwd rs9bVbcwglxvj8toiYFs2Am9GTKkr0lFqaZ76xcj/l/eKQvxi1FQx+EvAIz8gfv/SBrL11XvRo1cl eBeTM/RDN28ICMoDtgS45+DtGoDQdwCaJ1a7+o3WzmNUupVCGOQRsooKpttzIkkpFa4SrJ6v1V3V4 SzWFiqJwJYr924C+6aLrlBxLMeUzt4SJIF5y4PdhL6q9y9HyORNGGXfanNmg5dTWn2c2Hqgvs0FyU 5zcSHrmCTsmal8dUGvXtubABToMt0HESwEz3tvB+NbSfAZyDpVFAOcRq0jxItDKa+ylSMkBCGtSFl AjlnN/+A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oEPJe-000gbu-00; Thu, 21 Jul 2022 06:05:42 +0000 Received: from mail-yw1-x1149.google.com ([2607:f8b0:4864:20::1149]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oEPCO-000WwY-Ab for linux-arm-kernel@lists.infradead.org; Thu, 21 Jul 2022 05:58:14 +0000 Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-31e5cc477dcso7022987b3.0 for ; Wed, 20 Jul 2022 22:58:11 -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:to :cc; bh=gR1/Z2EPI44f0egwGbpih9U0FfR3lyB8C+b1oQ7a3ho=; b=afa5tl3ErYehtuGRVn6Z2F3olzHm5mqok9Hqwl9tU/bS/EZvKNoimqQLe5oCqF/DMc TdBQTNmlNrru0i9aIep5zRlPuoHEjwccgz4Qgy87jnj5xkgYHR+W30Pr8KipWYI6LJe/ JwvfS1kvj4dSVhZKIaHgofIjVXextnUms7EF/I0hZJtqp6bRCSsgSNsZvrl+NykLzrW1 NCvGslXIrCznfDzAKgWB2mVXua6LAoU7aPHY2Kx2Our4OmdaDygrvEfqL0tqMqLYbbmK y5QbtzMDtm2Xy58L9Yy8pWaiIH22zGx35r4CZp5SCFxcx+InneYPmkR0G8Fd6lS+Z+wW lU/A== 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:to:cc; bh=gR1/Z2EPI44f0egwGbpih9U0FfR3lyB8C+b1oQ7a3ho=; b=hb3NmF04o9+iiiJks8gFTJQe9W6k9MBFJUQN2eQ6w00xy9398+3UusNyFpOJRW2cT0 fvencJQM0AhDyvBWVCWDaYh5kdEDklnrvDReqy+RQ/SdYf5knPV0E/f1OEeZfUteBCwU b8jezyk8BVm21Po8FFyjKOUoz8kiQIHPvloFLAugfncxVfGQrKGDe1gECnkwdiJQ0/PQ up6fa5QdkSL/3W8WJ21L0bKYqyRhHfVpt8mrQD+syorToR8XZkyMdSXVX7VKnwZs2BD1 qNXtJHn2WlLvgbZl9ISJnUqHnA+c2OY7iXaJX0jLWZQROPqHdeICiiF8kN66U9imYnSX K1EQ== X-Gm-Message-State: AJIora/ldm3W9AFoddX/bv7lImMydrRJu9aEAIWPdpD7EK1bw4ag6W7k s3RwsS21EcT1PeMj/jIxJRXqaQqr+P4R1pe5ig== X-Google-Smtp-Source: AGRyM1sVq2WV+efPOaHv/EvfJltNWnGlGgRuoca8wHJKHuJymzfLurD1omQOCDXP5YKLf76jV42DjWRXPQaey+SEtQ== X-Received: from kaleshsingh.mtv.corp.google.com ([2620:15c:211:200:5a87:b61e:76b5:d1e0]) (user=kaleshsingh job=sendgmr) by 2002:a81:98d2:0:b0:31e:5d41:7a3e with SMTP id p201-20020a8198d2000000b0031e5d417a3emr11327128ywg.520.1658383090977; Wed, 20 Jul 2022 22:58:10 -0700 (PDT) Date: Wed, 20 Jul 2022 22:57:26 -0700 In-Reply-To: <20220721055728.718573-1-kaleshsingh@google.com> Message-Id: <20220721055728.718573-16-kaleshsingh@google.com> Mime-Version: 1.0 References: <20220721055728.718573-1-kaleshsingh@google.com> X-Mailer: git-send-email 2.37.0.170.g444d1eabd0-goog Subject: [PATCH v5 15/17] KVM: arm64: Implement non-protected nVHE hyp stack unwinder From: Kalesh Singh To: maz@kernel.org, mark.rutland@arm.com, broonie@kernel.org, madvenka@linux.microsoft.com, tabba@google.com Cc: will@kernel.org, qperret@google.com, kaleshsingh@google.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, andreyknvl@gmail.com, vincenzo.frascino@arm.com, mhiramat@kernel.org, ast@kernel.org, drjones@redhat.com, wangkefeng.wang@huawei.com, elver@google.com, keirf@google.com, yuzenghui@huawei.com, ardb@kernel.org, oupton@google.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, android-mm@google.com, kernel-team@android.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220720_225812_413338_CDD77DDD X-CRM114-Status: GOOD ( 14.24 ) 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 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 Reviewed-by: Fuad Tabba --- 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);