From patchwork Tue Feb 22 16:51:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kalesh Singh X-Patchwork-Id: 12755683 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 07F05C433F5 for ; Tue, 22 Feb 2022 16:58: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: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=i9tJ3OrYNqqQjXWLS7gOLXmjBAww7kL4susWqVQpedk=; b=IlruCB+yEXTzGX Op5rh5c81bBi5E3NjhygRQV2HH7l5G8uBnp8hXPORbWb/beJfCPvGEqt9uKj/0GKjX/fKZ6JGYJ+k 5dOdGk4dyceU21JlTBHtjYa+vGaF8zX5rIFPWsH57DJcXH057vT+pHqFTQ8J4jN7VV2pzyLPXIi0o UnY6AeTNdOn0PKoPdQ3bi/igIQaClziTVj3GymnRxrXqGk2gufj4XNolYzQtSN/UweDjIoIGyr6XH MNc0yBfY/XZ42Sr2B7TohY8V0Thm9fs/Szp2d3ShqnO1ItVUS/KmjFKomqDGl91xdAtDB60Awv4vH voTsofQpFtoPGP8RF6jA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nMYTK-00AniK-HA; Tue, 22 Feb 2022 16:57:08 +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 1nMYP7-00Am6w-8b for linux-arm-kernel@lists.infradead.org; Tue, 22 Feb 2022 16:52:47 +0000 Received: by mail-yb1-xb49.google.com with SMTP id d17-20020a253611000000b006244e94b7b4so12334731yba.4 for ; Tue, 22 Feb 2022 08:52:43 -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=FUZhxNiWpTBuv/yo6aC9br7WFC740z5ipvXijUNB1uM=; b=rl7DGr9SKCJXXULyQIrNMfWNqV8X0uSCbZhx5bKPP42G9Onx9lq+GQAIBvFAcYM0KR Yud0tbtBDX9beTd1+sjFvWoFwk5t88qg3J8PAorzHjj5DCnaTGLU11aui2kWTwEwa6xW 99/fFQPBB69uHXZRrLMnY8mskRUSa+VgfrimpGhCICIeOSjegQMfKYPl8tb+QwDyI4ED lb2YHKrWGQYam0vicFHUYcE7//ShpkJZAnf2Z1mqkqoEvEPITOq8clnVfeWptecNU6Za DrkwL6jDl0jULxJGn0RHx0MH8eTOkdkY0DSoUVak546uIUpSPco/QgZ6eFu6kAr1RrKr S/1g== 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=FUZhxNiWpTBuv/yo6aC9br7WFC740z5ipvXijUNB1uM=; b=Qs4xCLAiSHqXmbp3XrIP3bnyIF2VRsjEcHPmI5qJFeqWQr/ha1cegHAqHqs2Xc8zXi AQ3h1MPicGUGBGi3V/Xc+csNUFF6lrQCcMRAkkE3jKatn8tAVW+as6c13d3BcRSMHK8v dAWRu1OuyATSyL+T7hzkPmdDXjaoIHBGU0p58lXMC/i1gLTdUe9mfoWmmyPCjbNCPiK4 BArangijG3zwcpLbkfGqUIRVR+MOkNXfHMExppuhbLyRVirHprGCL3eQvPnyL5rDVMr1 Ge3+QkcsMx8BxhGPxNlT6s65Y7sQoVpTVPVq1kIcqg8tCu8cJtdIunJ8qBbJZOmS61pK FQXw== X-Gm-Message-State: AOAM532LqElxN4hytUONac/S2o4FkmuBZxQdQj69ReaLcaRZeKlDhO/r npXA3bRvP6bWrU/l9Ytnfhp88YnuFl2BWL8QWQ== X-Google-Smtp-Source: ABdhPJyDNYxSumcySMKx9aBNsuewfhPBBIWRyZkgKwWzEZsy+dn6LQiZfsn1zFM7NhoOIoZ+FkhSFT8MYUoWd1pNFw== X-Received: from kaleshsingh.mtv.corp.google.com ([2620:15c:211:200:5db7:1235:b3dd:cfcb]) (user=kaleshsingh job=sendgmr) by 2002:a81:4bcd:0:b0:2d0:a61f:6b5a with SMTP id y196-20020a814bcd000000b002d0a61f6b5amr23695338ywa.477.1645548763067; Tue, 22 Feb 2022 08:52:43 -0800 (PST) Date: Tue, 22 Feb 2022 08:51:01 -0800 Message-Id: <20220222165212.2005066-1-kaleshsingh@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.35.1.473.g83b2b277ed-goog Subject: [PATCH v2 0/9] 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 Scull , 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-20220222_085245_371151_A606F9B9 X-CRM114-Status: GOOD ( 17.30 ) 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 Hi all, This is v2 of the nVHE hypervisor stack enhancements. v1 can be found at: https://lore.kernel.org/r/20220210224220.4076151-1-kaleshsingh@google.com/ This version has been updated to work for 'classic' KVM in nVHE mode in addition to pKVM, per Marc; and rebased on 5.17-rc5. The cover letter has been copied below for convenience. Thanks, Kalesh ----- This series 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 (8): KVM: arm64: Introduce hyp_alloc_private_va_range() KVM: arm64: Introduce pkvm_alloc_private_va_range() KVM: arm64: Add guard pages for KVM nVHE hypervisor stack KVM: arm64: Add guard pages for pKVM (protected nVHE) hypervisor stack KVM: arm64: Detect and handle hypervisor stack overflows KVM: arm64: Add hypervisor overflow stack KVM: arm64: Unwind and dump nVHE HYP stacktrace KVM: arm64: Symbolize the nVHE HYP backtrace Quentin Perret (1): arm64: asm: Introduce test_sp_overflow macro arch/arm64/include/asm/assembler.h | 11 + arch/arm64/include/asm/kvm_asm.h | 18 ++ arch/arm64/include/asm/kvm_mmu.h | 4 + arch/arm64/kernel/entry.S | 7 +- arch/arm64/kvm/Kconfig | 5 +- arch/arm64/kvm/Makefile | 1 + arch/arm64/kvm/arm.c | 34 +++- arch/arm64/kvm/handle_exit.c | 16 +- arch/arm64/kvm/hyp/include/nvhe/mm.h | 3 +- arch/arm64/kvm/hyp/nvhe/host.S | 21 ++ arch/arm64/kvm/hyp/nvhe/hyp-main.c | 5 +- arch/arm64/kvm/hyp/nvhe/mm.c | 49 +++-- arch/arm64/kvm/hyp/nvhe/setup.c | 25 ++- arch/arm64/kvm/hyp/nvhe/switch.c | 29 +++ arch/arm64/kvm/mmu.c | 61 ++++-- arch/arm64/kvm/stacktrace.c | 290 +++++++++++++++++++++++++++ arch/arm64/kvm/stacktrace.h | 17 ++ scripts/kallsyms.c | 2 +- 18 files changed, 533 insertions(+), 65 deletions(-) create mode 100644 arch/arm64/kvm/stacktrace.c create mode 100644 arch/arm64/kvm/stacktrace.h base-commit: cfb92440ee71adcc2105b0890bb01ac3cddb8507