From patchwork Thu Jan 27 16:20:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandru Elisei X-Patchwork-Id: 12727041 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 4823AC433EF for ; Thu, 27 Jan 2022 16:23:38 +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: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=1zfFGv159CQR3jZgttOYnxzKKLblYKSHBtXxZOcROYM=; b=sOacxCUZK1X2yn /QZpXHJt97/EL7+BDh2/x+Fm3hPh28XsDyh0dif518botUM2zoesgAAaB19dmi8Pvi4KdEN8LMx2k wy3jcJg97FNubCyXVYlSCUQYKAmhaMEw1mG3fWUCTqkkOxkP7sh/juyog+csxcgsjMFW6596zVbqB wZ+03bPtZ2+JRaeSiVdJc8zNnQ6pIzvA/ywATzd8fNEz1iV6kZX+BDnOTJJGXsyKErAckFSh+WmEw s4UbN9wc51WjSuvC9Kp+R7W17ytCh5W3rf0hvSA6Fk7K7+kpM+8FZRCNpqLFiM4rB1fEz9HukM4Xw 6yfTgqQ+KjOSEFrrcPhQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nD7XL-00GSUC-Pl; Thu, 27 Jan 2022 16:22:15 +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 1nD7Vi-00GRp5-PO for linux-arm-kernel@lists.infradead.org; Thu, 27 Jan 2022 16:20:36 +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 3519E1063; Thu, 27 Jan 2022 08:20:34 -0800 (PST) Received: from monolith.localdoman (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 22BAB3F766; Thu, 27 Jan 2022 08:20:31 -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, andre.przywara@arm.com Subject: [PATCH v2 kvmtool 04/10] arm: Get rid of the ARM_VCPU_FEATURE_FLAGS() macro Date: Thu, 27 Jan 2022 16:20:27 +0000 Message-Id: <20220127162033.54290-5-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127162033.54290-1-alexandru.elisei@arm.com> References: <20220127162033.54290-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-20220127_082034_936924_67F8704F X-CRM114-Status: GOOD ( 13.65 ) 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 The ARM_VCPU_FEATURE_FLAGS() macro sets a feature bit in a rather convoluted way: if cpu_id is 0, then bit KVM_ARM_VCPU_POWER_OFF is 0, otherwise is set to 1. There's really no need for this indirection, especially considering that the macro has been changed to return the same value for both the arm and arm64 architectures. Replace it with a simple conditional statement in kvm_cpu__arch_init(), which makes it clearer to understand. Signed-off-by: Alexandru Elisei --- arm/aarch32/include/kvm/kvm-cpu-arch.h | 4 ---- arm/aarch64/include/kvm/kvm-cpu-arch.h | 4 ---- arm/kvm-cpu.c | 6 +++++- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/arm/aarch32/include/kvm/kvm-cpu-arch.h b/arm/aarch32/include/kvm/kvm-cpu-arch.h index 780e0e2f0934..fc9aef9f6320 100644 --- a/arm/aarch32/include/kvm/kvm-cpu-arch.h +++ b/arm/aarch32/include/kvm/kvm-cpu-arch.h @@ -5,10 +5,6 @@ #include "arm-common/kvm-cpu-arch.h" -#define ARM_VCPU_FEATURE_FLAGS(kvm, cpuid) { \ - [0] = (!!(cpuid) << KVM_ARM_VCPU_POWER_OFF), \ -} - #define ARM_MPIDR_HWID_BITMASK 0xFFFFFF #define ARM_CPU_ID 0, 0, 0 #define ARM_CPU_ID_MPIDR 5 diff --git a/arm/aarch64/include/kvm/kvm-cpu-arch.h b/arm/aarch64/include/kvm/kvm-cpu-arch.h index 016cf5b2b9ea..17b80493e2c0 100644 --- a/arm/aarch64/include/kvm/kvm-cpu-arch.h +++ b/arm/aarch64/include/kvm/kvm-cpu-arch.h @@ -5,10 +5,6 @@ #include "arm-common/kvm-cpu-arch.h" -#define ARM_VCPU_FEATURE_FLAGS(kvm, cpuid) { \ - [0] = (!!(cpuid) << KVM_ARM_VCPU_POWER_OFF), \ -} - #define ARM_MPIDR_HWID_BITMASK 0xFF00FFFFFFUL #define ARM_CPU_ID 3, 0, 0, 0 #define ARM_CPU_ID_MPIDR 5 diff --git a/arm/kvm-cpu.c b/arm/kvm-cpu.c index 554414f81b7a..62177ea73f82 100644 --- a/arm/kvm-cpu.c +++ b/arm/kvm-cpu.c @@ -43,7 +43,7 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) unsigned int i; struct kvm_vcpu_init preferred_init; struct kvm_vcpu_init vcpu_init = { - .features = ARM_VCPU_FEATURE_FLAGS(kvm, cpu_id) + .features = {}, }; vcpu = calloc(1, sizeof(struct kvm_cpu)); @@ -63,6 +63,10 @@ struct kvm_cpu *kvm_cpu__arch_init(struct kvm *kvm, unsigned long cpu_id) if (vcpu->kvm_run == MAP_FAILED) die("unable to mmap vcpu fd"); + /* VCPU 0 is the boot CPU, the others start in a poweroff state. */ + if (cpu_id > 0) + vcpu_init.features[0] |= (1UL << KVM_ARM_VCPU_POWER_OFF); + /* Set KVM_ARM_VCPU_PSCI_0_2 if available */ if (kvm__supports_extension(kvm, KVM_CAP_ARM_PSCI_0_2)) { vcpu_init.features[0] |= (1UL << KVM_ARM_VCPU_PSCI_0_2);