From patchwork Thu Jul 29 13:27:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Quentin Perret X-Patchwork-Id: 12408713 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 602B4C4338F for ; Thu, 29 Jul 2021 13:30:26 +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 363E760184 for ; Thu, 29 Jul 2021 13:30:26 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 363E760184 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=u6Sfk/gx2W9ITh6urT1JzmnIUdKBa1v0Ceca+3lQtcg=; b=yY039IOwgEw+zDeYxeqL+XcZCC xkBfdDkxIWJUIVc3DAU8BUs7pG7s25pEHDswml6jFJQGOW3bMp6u0RCwuwIHb+fjcCaKd8Z8ap65O EtKqiWawVJM1THNha9uoEhvXSjjyG9ZpeQNlz2a+XCwNfyCsPmBNFoaPeuRytwK87M/b/tSVU5zgj Ko4stRgeE5mtAzzOvHFd/AAJAiKVNSDKo6nWm0//R1EVXwWSp2Fr2qrC9jMFygjNXgM15/f3mtWRu 087GH7ESjNef4lH9/VW+vX4tkYIAFf6U+JVBoM5S/6mXgI4AKEHAXaAFqC6U4NHbDv1/mfDxYpcpc dWYZsCLw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m965k-004Egs-LX; Thu, 29 Jul 2021 13:28:53 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m965N-004Ea6-JX for linux-arm-kernel@lists.infradead.org; Thu, 29 Jul 2021 13:28:31 +0000 Received: by mail-wm1-x34a.google.com with SMTP id r125-20020a1c2b830000b0290197a4be97b7so1992773wmr.9 for ; Thu, 29 Jul 2021 06:28:28 -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=t7+5ofN1mhSPCYy31zt7RU0I2nBRXXWPYqlSGOk7ubE=; b=EOWUMMsZPsB2L4bsN4GxoGi3y0igtMQJVuIWpJTOwkroahO2vrvgGKDlL7RtzJMlsM 0oE50dz19H3398h3CH7lGvES9i7AZ+VyzBn3LLKoJN/6N09gfxN4nZrgog/WIOpdxF48 B/jbMHiG9QnFkf2f639cMBjVse7pVDqHc+1Ylei1mCqOmtyDH269kxdDb+J0Kuh6hwTv 9+n8fZ5n5Q8wA6fg82FoPSbY9mbZRd1dd4E3hdMvxHuv/9ztJK9IqX7gYuN2lWpjx5+s +HFOzx5RoBxyC3x0/qNim7tnNdldKJhuLJ7GxVdP5C7TH7ZDgtXRup/AoaGjp/YnLSie c8VA== 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=t7+5ofN1mhSPCYy31zt7RU0I2nBRXXWPYqlSGOk7ubE=; b=drNpJ6gFelHxemzzjSJB9qqwLNgFsX6tYT35jiLdyuB0wLvZ7lIatQaLauD0TQQtp/ Q+jpycXr2bsnRrUm9QqdQLyhVj1puKkznoiT9pEzBXjhKWCW2TVsvNT3ppNYGhKX43Y2 RaKbFt0ruI+vXZZHehAi7Qy+uVKvrz8+tjBdDUV/UtXO+imROivxzbSl65QslnBrn0eE Ru0Lxv6JLwL5pytz1gllgXDAp6zT3jaQo9jZuwTPOyRkL2N+B5iayujAaKD2QOmqW1nX 4DtszlafqG9dEiFi+v55FJFOck5b2AA0F14CUF4uuxoDE+vNUqs1h/uB58FMdMFB+rjG PUHg== X-Gm-Message-State: AOAM533TaNnow/Dap2KM0jA7VNIh41qGO7AKXZqX8Cf/+CB/prWXXJ9d t97clVhzjGva7BfwW9qhAB3XdAP9QGrF X-Google-Smtp-Source: ABdhPJyA9LhjEf8A/taAM06dydN+uO7RN2g31fVg3fvbmNEB2A5ceVlvMQQeLCoX2VjPrd82TvrUI4VZN1Ys X-Received: from luke.lon.corp.google.com ([2a00:79e0:d:210:293a:bc89:7514:5218]) (user=qperret job=sendgmr) by 2002:a1c:4b0a:: with SMTP id y10mr4499wma.1.1627565306816; Thu, 29 Jul 2021 06:28:26 -0700 (PDT) Date: Thu, 29 Jul 2021 14:27:59 +0100 In-Reply-To: <20210729132818.4091769-1-qperret@google.com> Message-Id: <20210729132818.4091769-3-qperret@google.com> Mime-Version: 1.0 References: <20210729132818.4091769-1-qperret@google.com> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog Subject: [PATCH v3 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, Quentin Perret X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210729_062829_696636_616C91B2 X-CRM114-Status: GOOD ( 13.21 ) 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__ */