From patchwork Wed Jul 14 09:55: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: 12376509 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.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, 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 44247C07E9A for ; Wed, 14 Jul 2021 09:57:55 +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 0C91061040 for ; Wed, 14 Jul 2021 09:57:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C91061040 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=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:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=oASAGbpREwdteYkpSg40ZyxijviS9YlMzGtO9AG5YhU=; b=Cqnb0b6TGu46r3 ZhGnxWsb0eX2y5h1myG7xRQ8s5lVy83m/ko27EWiLGAcD0uw5m2dp/xbGW6Yn0JaV948TryZarMNv qyP7eNl7KCYJg48IKz0JBTe85HuSU/c88gzz3eQH+G/fMv4bJZzTUTAol2NiY8rkM2mQGdJD94VDQ EUxBrQbKM49TQOS1L4lUlhsywwRfBCDfNTxVBfZIspbQPyl47+VQIMDKiMLHj9MzhJxGtnbfG/+kz tnOsRv+prRjLx+bEDamth+JXcdILiGaTvdr/cSG5oYC1lTFekf0PiCSR1fGByaE6zn8eosoblHCXA UnyAqPiXQ3zS98xKFf1w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3bcP-00Cy7s-PF; Wed, 14 Jul 2021 09:55:53 +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 1m3bbn-00Cxu1-4h for linux-arm-kernel@lists.infradead.org; Wed, 14 Jul 2021 09:55:18 +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 B83921042; Wed, 14 Jul 2021 02:55:09 -0700 (PDT) Received: from monolith.cable.virginm.net (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 57C8D3F774; Wed, 14 Jul 2021 02:55:08 -0700 (PDT) From: Alexandru Elisei To: maz@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu Cc: james.morse@arm.com, suzuki.poulose@arm.com Subject: [PATCH 2/5] KVM: arm64: Use vcpu_has_feature() to check the feature bits Date: Wed, 14 Jul 2021 10:55:58 +0100 Message-Id: <20210714095601.184854-3-alexandru.elisei@arm.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210714095601.184854-1-alexandru.elisei@arm.com> References: <20210714095601.184854-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-20210714_025515_354411_BA8A3629 X-CRM114-Status: GOOD ( 16.55 ) 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 Commit 66e94d5cafd4 ("KVM: arm64: Prevent mixed-width VM creation") added the vcpu_has_feature() function for checking if a feature bit is set. Replace uses of test_bit() with the vcpu_has_feature() abstraction. Signed-off-by: Alexandru Elisei --- There's one place place where I opted not to replace test_bit() with vcpu_has_feature(), in arm.c::kvm_vcpu_set_target(). The function already manipulates the feature bits directly, so I preferred to keep it consistent. arch/arm64/include/asm/kvm_emulate.h | 2 +- arch/arm64/include/asm/kvm_host.h | 4 ++-- arch/arm64/kvm/arm.c | 2 +- arch/arm64/kvm/psci.c | 2 +- arch/arm64/kvm/reset.c | 12 ++++++------ include/kvm/arm_psci.h | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h index 6bf776c2399c..738fb51920d2 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -70,7 +70,7 @@ static inline void vcpu_reset_hcr(struct kvm_vcpu *vcpu) vcpu->arch.hcr_el2 |= HCR_TVM; } - if (test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features)) + if (vcpu_has_feature(vcpu, KVM_ARM_VCPU_EL1_32BIT)) vcpu->arch.hcr_el2 &= ~HCR_RW; /* diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 0b087bcfcfeb..e6bdf1feb922 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -781,8 +781,8 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu); ((vcpu)->arch.flags & KVM_ARM64_VCPU_SVE_FINALIZED) #define kvm_has_mte(kvm) (system_supports_mte() && (kvm)->arch.mte_enabled) -#define kvm_vcpu_has_pmu(vcpu) \ - (test_bit(KVM_ARM_VCPU_PMU_V3, (vcpu)->arch.features)) + +#define kvm_vcpu_has_pmu(vcpu) (vcpu_has_feature(vcpu, KVM_ARM_VCPU_PMU_V3)) int kvm_trng_call(struct kvm_vcpu *vcpu); #ifdef CONFIG_KVM diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index e9a2b8f27792..646c7b003a59 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -1108,7 +1108,7 @@ static int kvm_arch_vcpu_ioctl_vcpu_init(struct kvm_vcpu *vcpu, /* * Handle the "start in power-off" case. */ - if (test_bit(KVM_ARM_VCPU_POWER_OFF, vcpu->arch.features)) + if (vcpu_has_feature(vcpu, KVM_ARM_VCPU_POWER_OFF)) vcpu_power_off(vcpu); else vcpu->arch.power_off = false; diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c index db4056ecccfd..536f637f1e41 100644 --- a/arch/arm64/kvm/psci.c +++ b/arch/arm64/kvm/psci.c @@ -492,7 +492,7 @@ int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) { bool wants_02; - wants_02 = test_bit(KVM_ARM_VCPU_PSCI_0_2, vcpu->arch.features); + wants_02 = vcpu_has_feature(vcpu, KVM_ARM_VCPU_PSCI_0_2); switch (val) { case KVM_ARM_PSCI_0_1: diff --git a/arch/arm64/kvm/reset.c b/arch/arm64/kvm/reset.c index cba7872d69a8..80b16984cf3a 100644 --- a/arch/arm64/kvm/reset.c +++ b/arch/arm64/kvm/reset.c @@ -157,8 +157,8 @@ static int kvm_vcpu_enable_ptrauth(struct kvm_vcpu *vcpu) * features are requested by the userspace together and the system * supports these capabilities. */ - if (!test_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, vcpu->arch.features) || - !test_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, vcpu->arch.features) || + if (!vcpu_has_feature(vcpu, KVM_ARM_VCPU_PTRAUTH_ADDRESS) || + !vcpu_has_feature(vcpu, KVM_ARM_VCPU_PTRAUTH_GENERIC) || !system_has_full_ptr_auth()) return -EINVAL; @@ -223,7 +223,7 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu) kvm_arch_vcpu_put(vcpu); if (!kvm_arm_vcpu_sve_finalized(vcpu)) { - if (test_bit(KVM_ARM_VCPU_SVE, vcpu->arch.features)) { + if (vcpu_has_feature(vcpu, KVM_ARM_VCPU_SVE)) { ret = kvm_vcpu_enable_sve(vcpu); if (ret) goto out; @@ -232,8 +232,8 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu) kvm_vcpu_reset_sve(vcpu); } - if (test_bit(KVM_ARM_VCPU_PTRAUTH_ADDRESS, vcpu->arch.features) || - test_bit(KVM_ARM_VCPU_PTRAUTH_GENERIC, vcpu->arch.features)) { + if (vcpu_has_feature(vcpu, KVM_ARM_VCPU_PTRAUTH_ADDRESS) || + vcpu_has_feature(vcpu, KVM_ARM_VCPU_PTRAUTH_GENERIC)) { if (kvm_vcpu_enable_ptrauth(vcpu)) { ret = -EINVAL; goto out; @@ -247,7 +247,7 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu) switch (vcpu->arch.target) { default: - if (test_bit(KVM_ARM_VCPU_EL1_32BIT, vcpu->arch.features)) { + if (vcpu_has_feature(vcpu, KVM_ARM_VCPU_EL1_32BIT)) { pstate = VCPU_RESET_PSTATE_SVC; } else { pstate = VCPU_RESET_PSTATE_EL1; diff --git a/include/kvm/arm_psci.h b/include/kvm/arm_psci.h index 5b58bd2fe088..8b7891d7a368 100644 --- a/include/kvm/arm_psci.h +++ b/include/kvm/arm_psci.h @@ -29,7 +29,7 @@ static inline int kvm_psci_version(struct kvm_vcpu *vcpu, struct kvm *kvm) * revisions. It is thus safe to return the latest, unless * userspace has instructed us otherwise. */ - if (test_bit(KVM_ARM_VCPU_PSCI_0_2, vcpu->arch.features)) { + if (vcpu_has_feature(vcpu, KVM_ARM_VCPU_PSCI_0_2)) { if (vcpu->kvm->arch.psci_version) return vcpu->kvm->arch.psci_version;