From patchwork Thu Feb 10 22:41:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 12742494 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 70CD9C433EF for ; Thu, 10 Feb 2022 22:44:38 +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:From:Subject:Mime-Version:Message-Id :Date:Reply-To:To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=JrwnIz9ySNucHwgVbrqLSpK6pnaMarrnSC/aGOEBkqg=; b=Otd+Pp8eSfcaZI wCt03xCrMwiCVoEUFKcfcAktlxhQEt7DrJXCUQWElnK6P6ow6PA1hZS0H0LDq7hn6rN/iywTwpK2/ m4Z+2szUjIR3YJyrQx3yC0xtnQrwyobUZc1c771SmcYxE9E8fVnJYZsyVK7O1Urux1kA1jnmJtCas l2ATwXRyvEWaEPg7XZgffkBKACH2lh5mrx0QY92kWgDjufCyZDQxfhv9ApVa28sDG2Kwgxb+pwDfH r9gQgiP2R+NqcS3TD+1oI9KX2KH3G9UMCZR6gs+jKQ90dRkSbVVd5FOfpkOr6ZHzYOp7cRrnvSzo/ kOkFm0jn9RZMQld8dWmw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nII9O-0053Ba-Gi; Thu, 10 Feb 2022 22:42:54 +0000 Received: from mail-yb1-xb49.google.com ([2607:f8b0:4864:20::b49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nII9F-00539b-Ug for linux-arm-kernel@lists.infradead.org; Thu, 10 Feb 2022 22:42:52 +0000 Received: by mail-yb1-xb49.google.com with SMTP id f32-20020a25b0a0000000b0061dad37dcd6so14926480ybj.16 for ; Thu, 10 Feb 2022 14:42:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:cc; bh=KKogoV3I1Ztwi08cWi/kskl7f13dMqHnW1NYHFKZhQY=; b=MSpmQCaLUVfuj+jaf2QClix5p6yRH8yzpyXKVnUK70zmSq5C6/qdwILNdwUhcYMF8c u2hO+qWimnqb+XJXum2CyHU9kaCpP4gkRh47JMce1cQUyDNmevlnXSk/v4J+ibagMpdi 6SyBC+677sSNAQTgfwfnsoK9hG38S7tJZegaoLmq/yU+PY5VBbjSvEWD5BQFkjDn541W 0JSNQrorMDSfKK5rlmgt+EWI1MHti2dN4PrYJBbrILg+UvVfff878dBp5MtI/4qmAOqW Nc7XlL61zC/1JLJf8Tf3E1Keb7HV2kSiSgcuaOFlOR7BDfv+pCD6q+wH9wLq+bDThuMT cAVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:cc; bh=KKogoV3I1Ztwi08cWi/kskl7f13dMqHnW1NYHFKZhQY=; b=IMuNf/OvRcDU5xlQpJj+ohpjU6Cq5OTTVZ0AjEIrNHNU34oDPCOYOvIOOepT1Te76I E8ZwCO7GUfyzhhIXggROxA6lX5mmqBNtYhPR+BHsQc5E3cDiyZdcKF2gV4mSWTLOtNIR oeYIppb6VBoHs0AeTuxA7Q3rvCYFVnk3OfeT7wifCfUkbPVdxGb4E10YULD81SlB1/IX /86BMQxzJk7RlsbEizC7Hd9wZ/ebLdZTMWQ31yPm7QdFKOL83RmQjNR81R8Z3gaNyD6H FYio1MnldzyiZMKyeOxLWHuv7bUukEyvQgzi+oTRFgCFFuYXql5s7++al0oe+fXi/IAe su0A== X-Gm-Message-State: AOAM530+mEMgZOVrJXmDSUGjUQqErkGivmKxNu/1pj4q546BaP02rBV1 eztXWMrAgBVS0iI/9JO5f9JIdezdptivatjDAg== X-Google-Smtp-Source: ABdhPJyp/KdgRlhbqVTv9Y4bfoAHsHmpgIk8uWR57nT9DX2u71VlcwaE1ajfiRh3Ozy8DknZf9zAjVroiBACXQvDfw== X-Received: from kaleshsingh.mtv.corp.google.com ([2620:15c:211:200:8f02:232:ad86:2ab2]) (user=kaleshsingh job=sendgmr) by 2002:a25:5802:: with SMTP id m2mr9400424ybb.681.1644532964348; Thu, 10 Feb 2022 14:42:44 -0800 (PST) Date: Thu, 10 Feb 2022 14:41:41 -0800 Message-Id: <20220210224220.4076151-1-kaleshsingh@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.265.g69c8d7142f-goog Subject: [PATCH 0/7] KVM: arm64: Hypervisor stack enhancements From: Kalesh Singh Cc: will@kernel.org, maz@kernel.org, qperret@google.com, tabba@google.com, surenb@google.com, kernel-team@android.com, Kalesh Singh , Catalin Marinas , James Morse , Alexandru Elisei , Suzuki K Poulose , Ard Biesheuvel , Mark Rutland , Pasha Tatashin , Joey Gouly , Peter Collingbourne , Andrew Walbran , Andrew Scull , Paolo Bonzini , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.cs.columbia.edu X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220210_144246_013536_747B6DAA X-CRM114-Status: GOOD ( 13.27 ) 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 This series is based on v5.17-rc3 and adds the following stack features to the KVM nVHE hypervisor: == Hyp Stack Guard Pages == Based on the technique used by arm64 VMAP_STACK to detect overflow. i.e. the stack is aligned to twice its size which ensure that the 'stack shift' bit of any valid SP is 0. The 'stack shift' bit can be tested in the exception entry to detect overflow without corrupting GPRs. == Hyp Stack Unwinder == Based on the arm64 kernel stack unwinder (See: arch/arm64/kernel/stacktrace.c) The unwinding and dumping of the hyp stack is not enabled by default and depends on CONFIG_NVHE_EL2_DEBUG to avoid potential information leaks. When CONFIG_NVHE_EL2_DEBUG is enabled the host stage 2 protection is disabled, allowing the host to read the hypervisor stack pages and unwind the stack from EL1. This allows us to print the hypervisor stacktrace before panicking the host; as shown below: kvm [408]: nVHE hyp panic at: \ [] __kvm_nvhe_overflow_stack+0x10/0x34! kvm [408]: nVHE HYP call trace: kvm [408]: [] __kvm_nvhe_hyp_panic_bad_stack+0xc/0x10 kvm [408]: [] __kvm_nvhe___kvm_hyp_host_vector+0x248/0x794 kvm [408]: [] __kvm_nvhe_overflow_stack+0x20/0x34 . . . kvm [408]: [] __kvm_nvhe_overflow_stack+0x20/0x34 kvm [408]: [] __kvm_nvhe___kvm_vcpu_run+0x2c/0x40c kvm [408]: [] __kvm_nvhe_handle___kvm_vcpu_run+0x1c8/0x36c kvm [408]: [] __kvm_nvhe_handle_trap+0xa4/0x124 kvm [408]: [] __kvm_nvhe___host_exit+0x60/0x64 kvm [408]: ---- end of nVHE HYP call trace ---- Kalesh Singh (3): KVM: arm64: Add Hyp overflow stack KVM: arm64: Unwind and dump nVHE HYP stacktrace KVM: arm64: Symbolize the nVHE HYP backtrace Quentin Perret (4): KVM: arm64: Map the stack pages in the 'private' range KVM: arm64: Factor out private range VA allocation arm64: asm: Introduce test_sp_overflow macro KVM: arm64: Allocate guard pages near hyp stacks arch/arm64/include/asm/assembler.h | 11 + arch/arm64/include/asm/kvm_asm.h | 17 ++ arch/arm64/kernel/entry.S | 9 +- arch/arm64/kvm/Makefile | 1 + arch/arm64/kvm/arm.c | 2 +- arch/arm64/kvm/handle_exit.c | 14 +- arch/arm64/kvm/hyp/include/nvhe/mm.h | 1 + arch/arm64/kvm/hyp/nvhe/host.S | 21 ++ arch/arm64/kvm/hyp/nvhe/mm.c | 28 ++- arch/arm64/kvm/hyp/nvhe/setup.c | 63 +++++- arch/arm64/kvm/hyp/nvhe/switch.c | 22 ++ arch/arm64/kvm/stacktrace.c | 290 +++++++++++++++++++++++++++ arch/arm64/kvm/stacktrace.h | 17 ++ scripts/kallsyms.c | 2 +- 14 files changed, 468 insertions(+), 30 deletions(-) create mode 100644 arch/arm64/kvm/stacktrace.c create mode 100644 arch/arm64/kvm/stacktrace.h base-commit: dfd42facf1e4ada021b939b4e19c935dcdd55566