From patchwork Tue Oct 27 17:26:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 11861155 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=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,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 173B0C55178 for ; Tue, 27 Oct 2020 17:27:36 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 852152076B for ; Tue, 27 Oct 2020 17:27:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="KUsfoN9i" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 852152076B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=d525hHOYbzyLp+8/FP7hgaQQ86O61lMFgmBpPB+UaK4=; b=KUsfoN9iuyPQB/FYIcXm5eB8E 9plFUP29bAAJdA34QpN9GUVVWH7fI7EXxQia7vDvkNRLAwmF82WS6IGWYOHRi+M/dIiK56+/y7yP0 4Kx+vpD4kFzL9Pbzv/w/2nEfVCanywYvM1K58RT4ODMKFi3u1eRjxi316vPumTMlX/CKF1cScRqws mhSpXuI8N8QdoibdiZ592yQGiSqAlhw8D8G5dHAlnUd6FLxwhBfwJKcu4WjaiQwM/QPYNna8GFRnC F0OGaIzKiffd9vi7eqHHKLQ/J8KYSe8eHL1hObyLF21G8fPG0U6oBxuDBJzHf3Cnth8fVjfpX1Hv+ B09MH/ivg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXSkK-0004yn-JC; Tue, 27 Oct 2020 17:26:56 +0000 Received: from foss.arm.com ([217.140.110.172]) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kXSjn-0004nw-1Y for linux-arm-kernel@lists.infradead.org; Tue, 27 Oct 2020 17:26:24 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 6C7EF15AD; Tue, 27 Oct 2020 10:26:22 -0700 (PDT) Received: from monolith.localdoman (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 593F33F719; Tue, 27 Oct 2020 10:26:21 -0700 (PDT) From: Alexandru Elisei To: linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Subject: [RFC PATCH v3 06/16] KVM: arm64: Introduce SPE primitives Date: Tue, 27 Oct 2020 17:26:55 +0000 Message-Id: <20201027172705.15181-7-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.29.1 In-Reply-To: <20201027172705.15181-1-alexandru.elisei@arm.com> References: <20201027172705.15181-1-alexandru.elisei@arm.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201027_132623_234683_D7A36415 X-CRM114-Status: GOOD ( 21.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: maz@kernel.org, will@kernel.org, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org KVM SPE emulation depends on the configuration option KVM_ARM_SPE and on on having hardware SPE support on all CPUs. The host driver must be compiled-in because we need the SPE interrupt to be enabled; it will be used to kick us out of the guest when the profiling buffer management interrupt is asserted by the GIC (for example, when the buffer is full). Add a VCPU flag to inform KVM that the guest has SPE enabled. It's worth noting that even though the KVM_ARM_SPE config option is gated by the SPE host driver being compiled-in, we don't actually check that the driver was loaded successfully when we advertise SPE support for guests. That's because we can live with the SPE interrupt being disabled. There is a delay between when the SPE hardware asserts the interrupt and when the GIC samples the interrupt line and asserts it to the CPU. If the SPE interrupt is disabled at the GIC level, this delay will be larger, at most a host timer tick. Signed-off-by: Alexandru Elisei --- arch/arm64/include/asm/kvm_host.h | 9 +++++++++ arch/arm64/kvm/Kconfig | 8 ++++++++ include/kvm/arm_spe.h | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 include/kvm/arm_spe.h diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 25d326aecded..43eee197764f 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -406,6 +406,7 @@ struct kvm_vcpu_arch { #define KVM_ARM64_GUEST_HAS_SVE (1 << 5) /* SVE exposed to guest */ #define KVM_ARM64_VCPU_SVE_FINALIZED (1 << 6) /* SVE config completed */ #define KVM_ARM64_GUEST_HAS_PTRAUTH (1 << 7) /* PTRAUTH exposed to guest */ +#define KVM_ARM64_GUEST_HAS_SPE (1 << 8) /* SPE exposed to guest */ #define vcpu_has_sve(vcpu) (system_supports_sve() && \ ((vcpu)->arch.flags & KVM_ARM64_GUEST_HAS_SVE)) @@ -419,6 +420,14 @@ struct kvm_vcpu_arch { #define vcpu_has_ptrauth(vcpu) false #endif +#ifdef CONFIG_KVM_ARM_SPE +#define vcpu_has_spe(vcpu) \ + (cpus_have_final_cap(ARM64_SPE) && \ + ((vcpu)->arch.flags & KVM_ARM64_GUEST_HAS_SPE)) +#else +#define vcpu_has_spe(vcpu) false +#endif + #define vcpu_gp_regs(v) (&(v)->arch.ctxt.regs) /* diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig index 043756db8f6e..8b35c0b806a7 100644 --- a/arch/arm64/kvm/Kconfig +++ b/arch/arm64/kvm/Kconfig @@ -57,6 +57,14 @@ config KVM_ARM_PMU Adds support for a virtual Performance Monitoring Unit (PMU) in virtual machines. +config KVM_ARM_SPE + bool "Virtual Statistical Profiling Extension (SPE) support" + depends on ARM_SPE_PMU + default y + help + Adds support for a virtual Statistical Profiling Extension (SPE) in + virtual machines. + endif # KVM endif # VIRTUALIZATION diff --git a/include/kvm/arm_spe.h b/include/kvm/arm_spe.h new file mode 100644 index 000000000000..db51ef15bf45 --- /dev/null +++ b/include/kvm/arm_spe.h @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2019 ARM Ltd. + */ + +#ifndef __ASM_ARM_KVM_SPE_H +#define __ASM_ARM_KVM_SPE_H + +#ifdef CONFIG_KVM_ARM_SPE +static inline bool kvm_arm_supports_spe(void) +{ + return cpus_have_final_cap(ARM64_SPE); +} + +#else +#define kvm_arm_supports_spe() false + +#endif /* CONFIG_KVM_ARM_SPE */ +#endif /* __ASM_ARM_KVM_SPE_H */