From patchwork Mon Aug 9 15:24:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12426803 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 73127C4338F for ; Mon, 9 Aug 2021 15:28:17 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 3439B60EDF for ; Mon, 9 Aug 2021 15:28:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 3439B60EDF Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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=F/lS3ON9nGUp7CS+8zWR2P6T7nAA534ScvqzB/sSuBI=; b=KqFakroiEQJ+ElAsGCoKsUAhzw rksJUpNSvDz62M5ODjt1/f9bbqe4kDrp0LJ/Qx5CAN5HMX5MPg5Xf9GTml6rm45bfQ6d+glgB9dfd FSpJDD+3fHXn0U92sxomX9xO1of9URNgnchr8k/7AH7XQGYYmBp1i4k0lbW34PUVp2vkFuE4lzeuX e1gdoPlZ/T5eVNPX/KU9XHjYBhRwdLOQIS6k+xbF1k4bBRdEDbTrlB3H11J4/ib5VSCvCRqnyrIvh zJH+8B0PK74vwJMqoK5grrOZGRHEHe1agVUTk+/zCNL7mz71JY1TGuf3IQTLtdFXzQvZQ8C+XKitW aXCUzf5g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mD79W-0017yB-RY; Mon, 09 Aug 2021 15:25:23 +0000 Received: from mail-qv1-xf49.google.com ([2607:f8b0:4864:20::f49]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mD797-0017qQ-Pf for linux-arm-kernel@lists.infradead.org; Mon, 09 Aug 2021 15:24:59 +0000 Received: by mail-qv1-xf49.google.com with SMTP id z25-20020a0ca9590000b029033ba243ffa1so12619350qva.0 for ; Mon, 09 Aug 2021 08:24:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=BeIaolisaUZtGeC9k2EMLoK7VySoIN8YqNGAmtfkvk0=; b=iotHDKdGhx5vD9VI+nB2hXHLhXQLu/dD/nLQap0ZXipIAdjHfTrBtWxzjBLF27fJvX V8y2aGlVI3WevnGv3a/oygvB8DWA83QPRUnoFEaP2mA/jZ5OzBE3dKjBkI9lUapxC4nI kvU0G+t3hmhMJm5nfdoXxXB7+P0mv3iMd/wNs0oYDeM9lA/FwvqtmAfoJDexoKDFfwCM /KfNeDHdg0hyO5xlCEKkrzl90VhfWtHnfpPf+mjOAQJeoMnDgQiNXR4arITrxhV1tsQO oADMUZZt36O4VZv5wDHUL3HnQX+JwOi7hViCI1DDa2kxcUEA214zGyr/oVnSEsHC2Sef V3cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=BeIaolisaUZtGeC9k2EMLoK7VySoIN8YqNGAmtfkvk0=; b=f60pW23M0rysuGOtXZOUlh+tYmc/R+lMjOrY6fAfrhIL2lst7oc7Sy/jOHy4xjqgGO G7U3ftphLnYtNZO060RGWrwps0gKYUrMcWHNcYcMyJ8eZDOgxfmUBeH9sFmukhBHr9cx fmSGVqdtTlxVHycy6ew9EVC33SIE6RD4mgqPRg9cFliFmDJnW/rODLwJ7JQXH9nfY/JC WsOapy4dsgATdczQgi/3U5Zx+CaPEb83NUFfplLodWaybvcLeOSllF8pZaImWrI8VD59 X5JU6xFCgFn54sqsD3c36JjhEk46xbmXox+LczlhYgIYmQWdy1KWMB7wENqX+GeEqS8r Tr5w== X-Gm-Message-State: AOAM531/jIjwTkc5QyMWGs4I1TVKxnGZsy2vhN1YPVlDKwLHBYP/XabO J8nZZFQP+RQp420QXjWFZFc0Tl16iSmB X-Google-Smtp-Source: ABdhPJwwkJx0vgQujLnN6O80r1QMwphuw2OhWcj7Ct18NZVCBAh2Ykl3Y1mymMGph4BEdeJQyMlOnYmLV0m0 X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:b0e8:d460:758b:a0ae]) (user=qperret job=sendgmr) by 2002:ad4:59c5:: with SMTP id el5mr10407143qvb.43.1628522695300; Mon, 09 Aug 2021 08:24:55 -0700 (PDT) Date: Mon, 9 Aug 2021 16:24:29 +0100 In-Reply-To: <20210809152448.1810400-1-qperret@google.com> Message-Id: <20210809152448.1810400-3-qperret@google.com> Mime-Version: 1.0 References: <20210809152448.1810400-1-qperret@google.com> X-Mailer: git-send-email 2.32.0.605.g8dce9f2422-goog Subject: [PATCH v4 02/21] KVM: arm64: Introduce hyp_assert_lock_held() From: Quentin Perret To: maz@kernel.org, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org Cc: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, ardb@kernel.org, qwandor@google.com, tabba@google.com, dbrazdil@google.com, kernel-team@android.com, qperret@google.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210809_082457_887909_80FC3D50 X-CRM114-Status: GOOD ( 13.86 ) 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 Introduce a poor man's lockdep implementation at EL2 which allows to BUG() whenever a hyp spinlock is not held when it should. Hide this feature behind a new Kconfig option that targets the EL2 object specifically, instead of piggy backing on the existing CONFIG_LOCKDEP. EL2 cannot WARN() cleanly to report locking issues, hence BUG() is the only option and it is not clear whether we want this widely enabled. This is most likely going to be useful for local testing until the EL2 WARN() situation has improved. Signed-off-by: Quentin Perret --- arch/arm64/kvm/Kconfig | 9 +++++++++ arch/arm64/kvm/hyp/include/nvhe/spinlock.h | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig index a4eba0908bfa..9b9721895e5c 100644 --- a/arch/arm64/kvm/Kconfig +++ b/arch/arm64/kvm/Kconfig @@ -46,6 +46,15 @@ if KVM source "virt/kvm/Kconfig" +config NVHE_EL2_DEBUG + bool "Debug mode for non-VHE EL2 object" + help + Say Y here to enable the debug mode for the non-VHE KVM EL2 object. + Failure reports will BUG() in the hypervisor. This is intended for + local EL2 hypervisor development. + + If unsure, say N. + endif # KVM endif # VIRTUALIZATION diff --git a/arch/arm64/kvm/hyp/include/nvhe/spinlock.h b/arch/arm64/kvm/hyp/include/nvhe/spinlock.h index 04f65b655fcf..4652fd04bdbe 100644 --- a/arch/arm64/kvm/hyp/include/nvhe/spinlock.h +++ b/arch/arm64/kvm/hyp/include/nvhe/spinlock.h @@ -97,4 +97,21 @@ static inline bool hyp_spin_is_locked(hyp_spinlock_t *lock) return lockval.owner != lockval.next; } +#ifdef CONFIG_NVHE_EL2_DEBUG +static inline void hyp_assert_lock_held(hyp_spinlock_t *lock) +{ + /* + * The __pkvm_init() path accesses protected data-structures without + * holding locks as the other CPUs are guaranteed to not enter EL2 + * concurrently at this point in time. The point by which EL2 is + * initialized on all CPUs is reflected in the pkvm static key, so + * wait until it is set before checking the lock state. + */ + if (static_branch_likely(&kvm_protected_mode_initialized)) + BUG_ON(!hyp_spin_is_locked(lock)); +} +#else +static inline void hyp_assert_lock_held(hyp_spinlock_t *lock) { } +#endif + #endif /* __ARM64_KVM_NVHE_SPINLOCK_H__ */