From patchwork Mon Nov 15 16:56:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 12692637 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD821C433F5 for ; Mon, 15 Nov 2021 16:57:21 +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 9582061357 for ; Mon, 15 Nov 2021 16:57:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9582061357 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YkBJgJ45d2cfm6BD/BnXRChjfjRymuNtH+dhst3GCPI=; b=OBEx9iOmNstTf9 JhVHXHLYKz37DwhOM7d3wfft71UUtwdVb8okS8JcgLfZYUy7Vq0jaNEbFL5K0x5XfT69jxlQQdIga AfnbmUIvNx1RppDBz+cb5u+d9I2j5J4s5tsu7wD1KCbg/Vs3MonuWJcAWueAw80RiS8f5AjTW396K 1KUrkyGv+JXQI2tDlHLhdgJyApQfUrxFWcFHhoVJ2vQkE3isGc6yh1ELgm8j5dLJTix4c2w2r/Unj l4rwy8VAIhDMkKnsHm6rVgu0CBXrcqzX+1FQxCgsvrwDK12zBw6sgge59DyXZCC27dkVa9shuU8fL EKndOncmWhahfZkIyDAA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mmfH8-00GQnx-Th; Mon, 15 Nov 2021 16:56:11 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mmfGT-00GQZf-Pe for linux-arm-kernel@lists.infradead.org; Mon, 15 Nov 2021 16:55:31 +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 155261FB; Mon, 15 Nov 2021 08:55:29 -0800 (PST) Received: from monolith.localdoman (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 9A4163F7F5; Mon, 15 Nov 2021 08:55:27 -0800 (PST) From: Alexandru Elisei To: will@kernel.org, julien.thierry.kdev@gmail.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, maz@kernel.org, james.morse@arm.com, suzuki.poulose@arm.com, mark.rutland@arm.com Subject: [PATCH kvmtool 2/9] arm: Move arch specific VCPU features to the arch specific function Date: Mon, 15 Nov 2021 16:56:58 +0000 Message-Id: <20211115165705.195736-3-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211115165705.195736-1-alexandru.elisei@arm.com> References: <20211115165705.195736-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-20211115_085529_925555_CD67B28A X-CRM114-Status: GOOD ( 15.74 ) 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 KVM_CAP_ARM_EL1_32BIT and KVM_CAP_ARM_PMU_V3 are arm64 specific features. They are set based on arm64 specific command line options and they target arm64 hardware features. It makes little sense for kvmtool to set the features in the code that is shared between arm and arm64. Move the logic to set the feature bits to the arch specific function kvm_cpu__select_features(), which is already used by arm64 to set other arm64 specific features. Signed-off-by: Alexandru Elisei --- arm/aarch64/include/kvm/kvm-cpu-arch.h | 4 +--- arm/aarch64/kvm-cpu.c | 12 ++++++++++++ arm/kvm-cpu.c | 8 -------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/arm/aarch64/include/kvm/kvm-cpu-arch.h b/arm/aarch64/include/kvm/kvm-cpu-arch.h index 8dfb82ecbc37..016cf5b2b9ea 100644 --- a/arm/aarch64/include/kvm/kvm-cpu-arch.h +++ b/arm/aarch64/include/kvm/kvm-cpu-arch.h @@ -6,9 +6,7 @@ #include "arm-common/kvm-cpu-arch.h" #define ARM_VCPU_FEATURE_FLAGS(kvm, cpuid) { \ - [0] = ((!!(cpuid) << KVM_ARM_VCPU_POWER_OFF) | \ - (!!(kvm)->cfg.arch.aarch32_guest << KVM_ARM_VCPU_EL1_32BIT) | \ - (!!(kvm)->cfg.arch.has_pmuv3 << KVM_ARM_VCPU_PMU_V3)) \ + [0] = (!!(cpuid) << KVM_ARM_VCPU_POWER_OFF), \ } #define ARM_MPIDR_HWID_BITMASK 0xFF00FFFFFFUL diff --git a/arm/aarch64/kvm-cpu.c b/arm/aarch64/kvm-cpu.c index 9f3e8586880c..3b6224a599c8 100644 --- a/arm/aarch64/kvm-cpu.c +++ b/arm/aarch64/kvm-cpu.c @@ -130,6 +130,18 @@ static void reset_vcpu_aarch64(struct kvm_cpu *vcpu) void kvm_cpu__select_features(struct kvm *kvm, struct kvm_vcpu_init *init) { + if (kvm->cfg.arch.aarch32_guest) { + if (!kvm__supports_extension(kvm, KVM_CAP_ARM_EL1_32BIT)) + die("32bit guests are not supported\n"); + init->features[0] |= 1UL << KVM_ARM_VCPU_EL1_32BIT; + } + + if (kvm->cfg.arch.has_pmuv3) { + if (!kvm__supports_extension(kvm, KVM_CAP_ARM_PMU_V3)) + die("PMUv3 is not supported"); + init->features[0] |= 1UL << KVM_ARM_VCPU_PMU_V3; + } + /* Enable pointer authentication if available */ if (kvm__supports_extension(kvm, KVM_CAP_ARM_PTRAUTH_ADDRESS) && kvm__supports_extension(kvm, KVM_CAP_ARM_PTRAUTH_GENERIC)) { diff --git a/arm/kvm-cpu.c b/arm/kvm-cpu.c index 6a2408c632df..554414f81b7a 100644 --- a/arm/kvm-cpu.c +++ b/arm/kvm-cpu.c @@ -46,14 +46,6 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) .features = ARM_VCPU_FEATURE_FLAGS(kvm, cpu_id) }; - if (kvm->cfg.arch.aarch32_guest && - !kvm__supports_extension(kvm, KVM_CAP_ARM_EL1_32BIT)) - die("32bit guests are not supported\n"); - - if (kvm->cfg.arch.has_pmuv3 && - !kvm__supports_extension(kvm, KVM_CAP_ARM_PMU_V3)) - die("PMUv3 is not supported"); - vcpu = calloc(1, sizeof(struct kvm_cpu)); if (!vcpu) return NULL;