From patchwork Thu Feb 24 17:25:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12759055 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 F3442C433EF for ; Thu, 24 Feb 2022 17:27:52 +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: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=NK01XXQIHXUDJ5QLmOmtMcDnoiwzuwhWRPFG0LK6tVo=; b=qiGvDNp/W7OKQ+XoEn4KqUYUlE ifk9HiG+Dc6/DbAd82ZnoK8gG+8nuWjRLqHoA9QCrTUw9ihYelhoXKPKZ0s0T5G2zjvK4+IBnSrm2 Vxc4oZL17idNGO6SXAeGXcAMMN4fbRqsskfRCS0gBnBWD/F4s3kjxgqv5E5bKan/Y+SxK+kcJAmkh hqbtzKR4Mp8z+mu0GlfQK1/Viure6yhBVPPGmiOsyjR5jQqN12nDznxSC0eE27k/0y121wCNs2kni IYH5ACoXu7C8f+pgMy1NvcWUP9dZpYPbh60/xoV0umyesTzaWb9YDOhNKhay7dubf9HOjzwPy9xJO J0v28knA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHsr-001mFD-KI; Thu, 24 Feb 2022 17:26:29 +0000 Received: from mail-yw1-x114a.google.com ([2607:f8b0:4864:20::114a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHsY-001m7G-Lw for linux-arm-kernel@lists.infradead.org; Thu, 24 Feb 2022 17:26:12 +0000 Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-2d726bd83a2so4165377b3.20 for ; Thu, 24 Feb 2022 09:26:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=OHhLpLvB3qKnaPMcJXUCZPNXxBBzMdDsCYySjLei9Uc=; b=GrmGz3NFqhQz8C/BrDEZksYrGBoDx3ClpAKEtXxgXUijApRe7oeu30tFdFBHip9AWl Nm6e1k1lIxlvIAfX08PiYuv8PCbtfyDqxffFlH4RKyuTMB4riC/yYSkRj+FLEsN9tvC/ mhqysm/alXSR4TLGQM59yOML8RnlMBm9tGksFVxG8JnpeHsf8NiNarDAu5c8uCmEX978 RkCAbpWeiBfRFyv2/VQPgdVhcxb04YI01QrBv/d9KsshovlAl8RjOPNBIxEIuIB1gxFb 7W63DZ3+AO+oV6ebv1/i9aGIKwEjpuowb4zR39gQ0sdfPZv3Z0/cOyTDoSpFU7NghcXl d3vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=OHhLpLvB3qKnaPMcJXUCZPNXxBBzMdDsCYySjLei9Uc=; b=jR2cnktfPteYwjWHf5O4wHKWHjEmQF5yoe3MzXNPdAGg6KHDizy1umRm76vDPylmIj 75ZMc3cC2ruIYA+CadOJn2no5bbUbcZ9QxNRCZP+UTlNTPCfOdvl+c6UiNiaxC8MhWfn e1LWlVy66DMQ0GvIlMXHHVp9U0uMF+UVokw75J19G6mElSKsk1zx/IFf+mAtaVB3ul8a P17WNHy1EiyRB8qu0U1hpWx+gtgHFtr28Xwz0SWB4dIPQNibK9V2AY7uCRVcFBY4jL+u GXopPeI7Aoc7b/YTQUnEBF6IJun4jBgw67+iCAexNuVKj30dgLUkw3yLADc28j0RgEni DzOw== X-Gm-Message-State: AOAM530ccMkmhI9ZaLLYee6KjN+S/yJZqp+ZJU//tfyqcqUaShtYS0de Iw1Acj7hAkVyraYlZ6DkGw24l7UtoEh+ X-Google-Smtp-Source: ABdhPJwBPy85gowI0srCVbE8O6AG99yJGSXUDaBo2gPb6bw41u0maONws+UInNcfiuwA6dqmu/fn+HbxZMHI X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a05:6902:693:b0:613:7f4f:2e63 with SMTP id i19-20020a056902069300b006137f4f2e63mr3364017ybt.271.1645723568558; Thu, 24 Feb 2022 09:26:08 -0800 (PST) Date: Thu, 24 Feb 2022 17:25:47 +0000 In-Reply-To: <20220224172559.4170192-1-rananta@google.com> Message-Id: <20220224172559.4170192-2-rananta@google.com> Mime-Version: 1.0 References: <20220224172559.4170192-1-rananta@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v4 01/13] KVM: arm64: Factor out firmware register handling from psci.c From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220224_092610_751283_92C90555 X-CRM114-Status: GOOD ( 20.86 ) 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 Common hypercall firmware register handing is currently employed by psci.c. Since the upcoming patches add more of these registers, it's better to move the generic handling to hypercall.c for a cleaner presentation. While we are at it, collect all the firmware registers under fw_reg_ids[] to help implement kvm_arm_get_fw_num_regs() and kvm_arm_copy_fw_reg_indices() in a generic way. No functional change intended. Signed-off-by: Raghavendra Rao Ananta Reviewed-by: Oliver Upton --- arch/arm64/kvm/guest.c | 2 +- arch/arm64/kvm/hypercalls.c | 170 +++++++++++++++++++++++++++++++++++ arch/arm64/kvm/psci.c | 166 ---------------------------------- include/kvm/arm_hypercalls.h | 7 ++ include/kvm/arm_psci.h | 7 -- 5 files changed, 178 insertions(+), 174 deletions(-) diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index e116c7767730..8238e52d890d 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c index 30da78f72b3b..3c2fcf31ad3d 100644 --- a/arch/arm64/kvm/hypercalls.c +++ b/arch/arm64/kvm/hypercalls.c @@ -146,3 +146,173 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) smccc_set_retval(vcpu, val[0], val[1], val[2], val[3]); return 1; } + +static const u64 kvm_arm_fw_reg_ids[] = { + KVM_REG_ARM_PSCI_VERSION, + KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1, + KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2, +}; + +int kvm_arm_get_fw_num_regs(struct kvm_vcpu *vcpu) +{ + return ARRAY_SIZE(kvm_arm_fw_reg_ids); +} + +int kvm_arm_copy_fw_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(kvm_arm_fw_reg_ids); i++) { + if (put_user(kvm_arm_fw_reg_ids[i], uindices++)) + return -EFAULT; + } + + return 0; +} + +#define KVM_REG_FEATURE_LEVEL_WIDTH 4 +#define KVM_REG_FEATURE_LEVEL_MASK (BIT(KVM_REG_FEATURE_LEVEL_WIDTH) - 1) + +/* + * Convert the workaround level into an easy-to-compare number, where higher + * values mean better protection. + */ +static int get_kernel_wa_level(u64 regid) +{ + switch (regid) { + case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1: + switch (arm64_get_spectre_v2_state()) { + case SPECTRE_VULNERABLE: + return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_AVAIL; + case SPECTRE_MITIGATED: + return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_AVAIL; + case SPECTRE_UNAFFECTED: + return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_REQUIRED; + } + return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_AVAIL; + case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2: + switch (arm64_get_spectre_v4_state()) { + case SPECTRE_MITIGATED: + /* + * As for the hypercall discovery, we pretend we + * don't have any FW mitigation if SSBS is there at + * all times. + */ + if (cpus_have_final_cap(ARM64_SSBS)) + return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL; + fallthrough; + case SPECTRE_UNAFFECTED: + return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_REQUIRED; + case SPECTRE_VULNERABLE: + return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL; + } + } + + return -EINVAL; +} + +int kvm_arm_get_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) +{ + void __user *uaddr = (void __user *)(long)reg->addr; + u64 val; + + switch (reg->id) { + case KVM_REG_ARM_PSCI_VERSION: + val = kvm_psci_version(vcpu, vcpu->kvm); + break; + case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1: + case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2: + val = get_kernel_wa_level(reg->id) & KVM_REG_FEATURE_LEVEL_MASK; + break; + default: + return -ENOENT; + } + + if (copy_to_user(uaddr, &val, KVM_REG_SIZE(reg->id))) + return -EFAULT; + + return 0; +} + +int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) +{ + void __user *uaddr = (void __user *)(long)reg->addr; + u64 val; + int wa_level; + + if (copy_from_user(&val, uaddr, KVM_REG_SIZE(reg->id))) + return -EFAULT; + + switch (reg->id) { + case KVM_REG_ARM_PSCI_VERSION: + { + bool wants_02; + + wants_02 = test_bit(KVM_ARM_VCPU_PSCI_0_2, vcpu->arch.features); + + switch (val) { + case KVM_ARM_PSCI_0_1: + if (wants_02) + return -EINVAL; + vcpu->kvm->arch.psci_version = val; + return 0; + case KVM_ARM_PSCI_0_2: + case KVM_ARM_PSCI_1_0: + if (!wants_02) + return -EINVAL; + vcpu->kvm->arch.psci_version = val; + return 0; + } + break; + } + + case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1: + if (val & ~KVM_REG_FEATURE_LEVEL_MASK) + return -EINVAL; + + if (get_kernel_wa_level(reg->id) < val) + return -EINVAL; + + return 0; + + case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2: + if (val & ~(KVM_REG_FEATURE_LEVEL_MASK | + KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_ENABLED)) + return -EINVAL; + + /* The enabled bit must not be set unless the level is AVAIL. */ + if ((val & KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_ENABLED) && + (val & KVM_REG_FEATURE_LEVEL_MASK) != KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_AVAIL) + return -EINVAL; + + /* + * Map all the possible incoming states to the only two we + * really want to deal with. + */ + switch (val & KVM_REG_FEATURE_LEVEL_MASK) { + case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL: + case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_UNKNOWN: + wa_level = KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL; + break; + case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_AVAIL: + case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_REQUIRED: + wa_level = KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_REQUIRED; + break; + default: + return -EINVAL; + } + + /* + * We can deal with NOT_AVAIL on NOT_REQUIRED, but not the + * other way around. + */ + if (get_kernel_wa_level(reg->id) < wa_level) + return -EINVAL; + + return 0; + default: + return -ENOENT; + } + + return -EINVAL; +} diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c index 3eae32876897..d5bc663a8629 100644 --- a/arch/arm64/kvm/psci.c +++ b/arch/arm64/kvm/psci.c @@ -403,169 +403,3 @@ int kvm_psci_call(struct kvm_vcpu *vcpu) return -EINVAL; }; } - -int kvm_arm_get_fw_num_regs(struct kvm_vcpu *vcpu) -{ - return 3; /* PSCI version and two workaround registers */ -} - -int kvm_arm_copy_fw_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) -{ - if (put_user(KVM_REG_ARM_PSCI_VERSION, uindices++)) - return -EFAULT; - - if (put_user(KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1, uindices++)) - return -EFAULT; - - if (put_user(KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2, uindices++)) - return -EFAULT; - - return 0; -} - -#define KVM_REG_FEATURE_LEVEL_WIDTH 4 -#define KVM_REG_FEATURE_LEVEL_MASK (BIT(KVM_REG_FEATURE_LEVEL_WIDTH) - 1) - -/* - * Convert the workaround level into an easy-to-compare number, where higher - * values mean better protection. - */ -static int get_kernel_wa_level(u64 regid) -{ - switch (regid) { - case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1: - switch (arm64_get_spectre_v2_state()) { - case SPECTRE_VULNERABLE: - return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_AVAIL; - case SPECTRE_MITIGATED: - return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_AVAIL; - case SPECTRE_UNAFFECTED: - return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_REQUIRED; - } - return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1_NOT_AVAIL; - case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2: - switch (arm64_get_spectre_v4_state()) { - case SPECTRE_MITIGATED: - /* - * As for the hypercall discovery, we pretend we - * don't have any FW mitigation if SSBS is there at - * all times. - */ - if (cpus_have_final_cap(ARM64_SSBS)) - return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL; - fallthrough; - case SPECTRE_UNAFFECTED: - return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_REQUIRED; - case SPECTRE_VULNERABLE: - return KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL; - } - } - - return -EINVAL; -} - -int kvm_arm_get_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) -{ - void __user *uaddr = (void __user *)(long)reg->addr; - u64 val; - - switch (reg->id) { - case KVM_REG_ARM_PSCI_VERSION: - val = kvm_psci_version(vcpu, vcpu->kvm); - break; - case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1: - case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2: - val = get_kernel_wa_level(reg->id) & KVM_REG_FEATURE_LEVEL_MASK; - break; - default: - return -ENOENT; - } - - if (copy_to_user(uaddr, &val, KVM_REG_SIZE(reg->id))) - return -EFAULT; - - return 0; -} - -int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) -{ - void __user *uaddr = (void __user *)(long)reg->addr; - u64 val; - int wa_level; - - if (copy_from_user(&val, uaddr, KVM_REG_SIZE(reg->id))) - return -EFAULT; - - switch (reg->id) { - case KVM_REG_ARM_PSCI_VERSION: - { - bool wants_02; - - wants_02 = test_bit(KVM_ARM_VCPU_PSCI_0_2, vcpu->arch.features); - - switch (val) { - case KVM_ARM_PSCI_0_1: - if (wants_02) - return -EINVAL; - vcpu->kvm->arch.psci_version = val; - return 0; - case KVM_ARM_PSCI_0_2: - case KVM_ARM_PSCI_1_0: - if (!wants_02) - return -EINVAL; - vcpu->kvm->arch.psci_version = val; - return 0; - } - break; - } - - case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1: - if (val & ~KVM_REG_FEATURE_LEVEL_MASK) - return -EINVAL; - - if (get_kernel_wa_level(reg->id) < val) - return -EINVAL; - - return 0; - - case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2: - if (val & ~(KVM_REG_FEATURE_LEVEL_MASK | - KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_ENABLED)) - return -EINVAL; - - /* The enabled bit must not be set unless the level is AVAIL. */ - if ((val & KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_ENABLED) && - (val & KVM_REG_FEATURE_LEVEL_MASK) != KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_AVAIL) - return -EINVAL; - - /* - * Map all the possible incoming states to the only two we - * really want to deal with. - */ - switch (val & KVM_REG_FEATURE_LEVEL_MASK) { - case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL: - case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_UNKNOWN: - wa_level = KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_AVAIL; - break; - case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_AVAIL: - case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_REQUIRED: - wa_level = KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_REQUIRED; - break; - default: - return -EINVAL; - } - - /* - * We can deal with NOT_AVAIL on NOT_REQUIRED, but not the - * other way around. - */ - if (get_kernel_wa_level(reg->id) < wa_level) - return -EINVAL; - - return 0; - default: - return -ENOENT; - } - - return -EINVAL; -} diff --git a/include/kvm/arm_hypercalls.h b/include/kvm/arm_hypercalls.h index 0e2509d27910..5d38628a8d04 100644 --- a/include/kvm/arm_hypercalls.h +++ b/include/kvm/arm_hypercalls.h @@ -40,4 +40,11 @@ static inline void smccc_set_retval(struct kvm_vcpu *vcpu, vcpu_set_reg(vcpu, 3, a3); } +struct kvm_one_reg; + +int kvm_arm_get_fw_num_regs(struct kvm_vcpu *vcpu); +int kvm_arm_copy_fw_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices); +int kvm_arm_get_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg); +int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg); + #endif diff --git a/include/kvm/arm_psci.h b/include/kvm/arm_psci.h index 5b58bd2fe088..080c2d0bd6e7 100644 --- a/include/kvm/arm_psci.h +++ b/include/kvm/arm_psci.h @@ -42,11 +42,4 @@ static inline int kvm_psci_version(struct kvm_vcpu *vcpu, struct kvm *kvm) int kvm_psci_call(struct kvm_vcpu *vcpu); -struct kvm_one_reg; - -int kvm_arm_get_fw_num_regs(struct kvm_vcpu *vcpu); -int kvm_arm_copy_fw_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices); -int kvm_arm_get_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg); -int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg); - #endif /* __KVM_ARM_PSCI_H__ */ From patchwork Thu Feb 24 17:25:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12759056 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 38BB6C433F5 for ; Thu, 24 Feb 2022 17:28:11 +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: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=Z4pkJw3iBH+MKmD613d9KRDFk6KkxdrJRPFYUhgd9Sk=; b=1Rkws8nUYkP0aFS2UWqcP7HRg9 +maKFCZPcAZkKrJbZDBWZls/SkpLD2/GLotA/8P3wYBJOJN3ClNVLIB52Ny1WKXh1VlMvQGiihfST SOz2eOfVwMclH3inpzkU/LkQa8jHG68ogHgBJtdWO53LJEAQbfZuPWnsqdtZ27WxjEzc2aldb6SkS 3TwvcLrdTycTt3y+4/7z7Qm2odxjJbNvNgH4fwLp7gMyTiI657ExY4p6WerY3j8LVFF4KB3PguDK5 sTy/EPHudPi3ocxxKG+i2d8N0zTPsbB12CthUGnNMG0178BhmbORaBQWMjyZcHXdsAH8uv6lhMAjW owHHe2MQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHt6-001mNY-VA; Thu, 24 Feb 2022 17:26:45 +0000 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHsa-001m7v-Vz for linux-arm-kernel@lists.infradead.org; Thu, 24 Feb 2022 17:26:14 +0000 Received: by mail-pj1-x1049.google.com with SMTP id t12-20020a17090abc4c00b001bc770db571so1613727pjv.5 for ; Thu, 24 Feb 2022 09:26:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=zwE5cEiZetqja2vTCL0nln/ypguSZC8fkvH9hAsICEY=; b=LH+vDy+8ljzpicztnBAsbYWVN/aATE2Kmw8jVkRvb5AmwHm3Ky1fKJ4iIhhozC0xfN 00nBusB/t7F5cZwHxAuierFsQrUSZ3rCPuoDVxm8QuFjcgWpF32iwuXO6dGgAKY+D4Nk FvKJRHLNE5tNX0D89rzPT/YTI4nLxoktj+rfcCckFSljNttUEvkXz9xJ5EhnyKA518Pj Dj0Yr70wBcWcRbOGY6FVpu2plko5nX7djwY45eKlfm2KgjR2xayqTAlhashQB/NxPCEY oPZM50Y73mowM3F4rMjiF4pcYJIRtPl4PjMaZ52lAMHvyDQC7K2GQNNn/+3C38/C9HEm Cw0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=zwE5cEiZetqja2vTCL0nln/ypguSZC8fkvH9hAsICEY=; b=KmBmOet/YDs9V9xj8K5NeTI6xZEX8xnHEflAltrV+oXp/PEp9Im4BhLQnmFz76myzc s1NdMQn59QQ4FRuAxwgNWL7gjktHrdwilLpC5em6WLRa7bpxm0ax8e6wY1sxjJvhCJVs anH64f+KzugfNhJAac8Lk+Fy33pOWZ05xkfGxA+ImFpZxSwzMSgpa7j6S4GOH9ch/eOU 3+T7h+M2OPLRbA4QLHfL2BLDv7RMWUfz4uRHYIdHb+R6PNHeyxgVKA9jiFXkQVVnD7eR W1hcYwaFVyoUo5VSLAhJ7fEF3OMu5iSfLLpAE0g04gIne8265XjHuuSIC62hWez7Iurb uJJw== X-Gm-Message-State: AOAM532djlzCTykZN+5Df7dNZ8hjbeQJNim27TST8BmZakf5LdpHxEpU GuKi6jH03ao77pLnf73hUuYwFrnLBnWp X-Google-Smtp-Source: ABdhPJwfEvyME9PSudMtl/0BdcjrGMwthB+z29yBgicXmdecZAiSEcSau/lGG27t2U3spq2A4jebc9Q1/DXt X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a17:902:6902:b0:14d:6aa4:f3f5 with SMTP id j2-20020a170902690200b0014d6aa4f3f5mr3575116plk.20.1645723571006; Thu, 24 Feb 2022 09:26:11 -0800 (PST) Date: Thu, 24 Feb 2022 17:25:48 +0000 In-Reply-To: <20220224172559.4170192-1-rananta@google.com> Message-Id: <20220224172559.4170192-3-rananta@google.com> Mime-Version: 1.0 References: <20220224172559.4170192-1-rananta@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v4 02/13] KVM: arm64: Introduce KVM_CAP_ARM_REG_SCOPE From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220224_092613_109557_255919BA X-CRM114-Status: GOOD ( 18.96 ) 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_[GET|SET]_ONE_REG act on per-vCPU basis. Currently certain ARM64 registers, such as KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_[1|2], are accessed via this interface even though the effect that they have are really per-VM. As a result, userspace could just waste cycles to read/write the same information for every vCPU that it spawns, only to realize that there's absolutely no change in the VM's state. The problem gets worse in proportion to the number of vCPUs created. As a result, to avoid this redundancy, introduce the capability KVM_CAP_ARM_REG_SCOPE. If enabled, KVM_GET_REG_LIST will advertise the registers that are VM-scoped by dynamically modifying the register encoding. KVM_REG_ARM_SCOPE_* helper macros are introduced to decode the same. By learning this, userspace can access such registers only once. Signed-off-by: Raghavendra Rao Ananta --- Documentation/virt/kvm/api.rst | 16 ++++++++++++++++ arch/arm64/include/asm/kvm_host.h | 3 +++ arch/arm64/include/uapi/asm/kvm.h | 6 ++++++ arch/arm64/kvm/arm.c | 13 +++++++------ include/uapi/linux/kvm.h | 1 + 5 files changed, 33 insertions(+), 6 deletions(-) diff --git a/Documentation/virt/kvm/api.rst b/Documentation/virt/kvm/api.rst index a4267104db50..7e7b3439f540 100644 --- a/Documentation/virt/kvm/api.rst +++ b/Documentation/virt/kvm/api.rst @@ -7561,3 +7561,19 @@ The argument to KVM_ENABLE_CAP is also a bitmask, and must be a subset of the result of KVM_CHECK_EXTENSION. KVM will forward to userspace the hypercalls whose corresponding bit is in the argument, and return ENOSYS for the others. + +8.34 KVM_CAP_ARM_REG_SCOPE +-------------------------- + +:Architectures: arm64 + +The capability, if enabled, amends the existing register encoding +with additional information to the userspace if a particular register +is scoped per-vCPU or per-VM via KVM_GET_REG_LIST. KVM provides +KVM_REG_ARM_SCOPE_* helper macros to decode the same. Userspace can +use this information from the register encoding to access a VM-scopped +regiser only once, as opposed to accessing it for every vCPU for the +same effect. + +On the other hand, if the capability is disabled, all the registers +remain vCPU-scopped by default, retaining backward compatibility. diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 5bc01e62c08a..8132de6bd718 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -136,6 +136,9 @@ struct kvm_arch { /* Memory Tagging Extension enabled for the guest */ bool mte_enabled; + + /* Register scoping enabled for KVM registers */ + bool reg_scope_enabled; }; struct kvm_vcpu_fault_info { diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h index b3edde68bc3e..c35447cc0e0c 100644 --- a/arch/arm64/include/uapi/asm/kvm.h +++ b/arch/arm64/include/uapi/asm/kvm.h @@ -199,6 +199,12 @@ struct kvm_arm_copy_mte_tags { #define KVM_REG_ARM_COPROC_MASK 0x000000000FFF0000 #define KVM_REG_ARM_COPROC_SHIFT 16 +/* Defines if a KVM register is one per-vCPU or one per-VM */ +#define KVM_REG_ARM_SCOPE_MASK 0x0000000010000000 +#define KVM_REG_ARM_SCOPE_SHIFT 28 +#define KVM_REG_ARM_SCOPE_VCPU 0 +#define KVM_REG_ARM_SCOPE_VM 1 + /* Normal registers are mapped as coprocessor 16. */ #define KVM_REG_ARM_CORE (0x0010 << KVM_REG_ARM_COPROC_SHIFT) #define KVM_REG_ARM_CORE_REG(name) (offsetof(struct kvm_regs, name) / sizeof(__u32)) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index ecc5958e27fe..107977c82c6c 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -81,26 +81,26 @@ int kvm_arch_check_processor_compat(void *opaque) int kvm_vm_ioctl_enable_cap(struct kvm *kvm, struct kvm_enable_cap *cap) { - int r; + int r = 0; if (cap->flags) return -EINVAL; switch (cap->cap) { case KVM_CAP_ARM_NISV_TO_USER: - r = 0; kvm->arch.return_nisv_io_abort_to_user = true; break; case KVM_CAP_ARM_MTE: mutex_lock(&kvm->lock); - if (!system_supports_mte() || kvm->created_vcpus) { + if (!system_supports_mte() || kvm->created_vcpus) r = -EINVAL; - } else { - r = 0; + else kvm->arch.mte_enabled = true; - } mutex_unlock(&kvm->lock); break; + case KVM_CAP_ARM_REG_SCOPE: + WRITE_ONCE(kvm->arch.reg_scope_enabled, true); + break; default: r = -EINVAL; break; @@ -209,6 +209,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) case KVM_CAP_SET_GUEST_DEBUG: case KVM_CAP_VCPU_ATTRIBUTES: case KVM_CAP_PTP_KVM: + case KVM_CAP_ARM_REG_SCOPE: r = 1; break; case KVM_CAP_SET_GUEST_DEBUG2: diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h index 5191b57e1562..c4fe81ed9ee6 100644 --- a/include/uapi/linux/kvm.h +++ b/include/uapi/linux/kvm.h @@ -1134,6 +1134,7 @@ struct kvm_ppc_resize_hpt { #define KVM_CAP_VM_GPA_BITS 207 #define KVM_CAP_XSAVE2 208 #define KVM_CAP_SYS_ATTRIBUTES 209 +#define KVM_CAP_ARM_REG_SCOPE 210 #ifdef KVM_CAP_IRQ_ROUTING From patchwork Thu Feb 24 17:25:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12759057 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 99C10C433EF for ; Thu, 24 Feb 2022 17:28:30 +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: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=xeP3JbPkH0vjegLObRk7rsqX4cu3w1sraR2TsRwcMxU=; b=3BETtZoa8ewMgd6Ul5eh2VVQix Th0hzLY0UiedlH4VYC9ZayB+WzrocE0FZiRkVZqT/wb9t24V368vQFyZmZ+zG+w77RHJPEEXWnmst dMY/j6stWfUAdBbvHoN9WLUvmdIiDG7EOVnvmGQ0Jxzs1efkHSvYil5vNTsEdvs2RuSSaX+kac7W7 IlI8RXHoDNY1EwAq5Ek0uMze0YRpBOp4Ixo+ccpnyWinUA81vMA6caBfZ68RKocd9tJV9nvP3awYD h04cZxLIXG3N9kq4FudQfYxfN4zvP2d2Apknhldx2r3J5BPpZt+N6GYotrg5R9ZGBrTs/BqxLNeNw ufEZ8ONw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHtU-001mWc-Eo; Thu, 24 Feb 2022 17:27:09 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHsd-001m8n-36 for linux-arm-kernel@lists.infradead.org; Thu, 24 Feb 2022 17:26:17 +0000 Received: by mail-pj1-x104a.google.com with SMTP id mn16-20020a17090b189000b001bc2315d75cso1745480pjb.3 for ; Thu, 24 Feb 2022 09:26:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=KaCBuwIyBaYjU3K7NXFsCjZcUQNiR1GDNYO7qs8JETY=; b=fZLUwv+joWr/KbhO5KrM6woBx5STObKXzVBlyItFKgfFX2ppVopErWfQyAyqmXKCOx 7jRwCDUOzx9jtL9EJrqyC/h3OjKVMzzyFz22XYWAHaCiZM7gegqLJnyaBcr8T5zHpdMc WxFEKpGgcJlSYHmcbY8TWDHaP1af46W4E8eFFpT51tXxeM+DuvDCrZzLSr9DJPPkwsQS T5eMRo5XWoO6q/1IOYfMQqIBfbOTzUbuS539VeFrhKfo6c8/nzkGGzldC/mEabJedqZ9 yaiXtwieY8sApFSm6D1pDeaUqDdNWzspj3NWfIR4fKioNKKnUVMBh9ogvyH0g+Rk1pJ1 zbHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=KaCBuwIyBaYjU3K7NXFsCjZcUQNiR1GDNYO7qs8JETY=; b=IYFvsKZ7tcf8/nK26mariI6b8rKHXaBxLlpQOdyjka5DBc7DTlswhdXzlkxkvPwGuV M4ZIz2Px53msEJ6ps/UDycz6/MvdyMe/hM6jQKm6xHcKrS57UJJ4edLlvNhkG8dDHf62 +uf+yeOFPDskgPwGrgDSgPGiCBrmH63kwe5n4B84EztJZHSpgEi0MNribYa6r+AmM+Kf tgdm90T/iBhIdXTDyopAkta8PGqYEODPbxY2e/zAPcm1uxZw6MH5ONgIqeEhEjXV/n9q 0k0TxRTRrlUo3CMcWtkRj1d4SRehPfwOjhTJntqACnIEgsFFqa7UAqbkVcOS/xZPj9Gj KpUw== X-Gm-Message-State: AOAM530KlxNjj27HG28pV2x3h7vyyJUc6YqT8rAmKn2Nt1YU92LOiWUn R9aEO5hV6UVzGIwRfsU+Q2bdSuzoLuWf X-Google-Smtp-Source: ABdhPJxMtaJZ3smrZYeKjDmBPhXAaNSzbfO+lVKvJuxUWaHxzZNzmp4RLYQj5GycYVgIiIBYBxCU6HzY8eFt X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a62:5ac6:0:b0:4df:34dc:d6c5 with SMTP id o189-20020a625ac6000000b004df34dcd6c5mr3940421pfb.9.1645723573162; Thu, 24 Feb 2022 09:26:13 -0800 (PST) Date: Thu, 24 Feb 2022 17:25:49 +0000 In-Reply-To: <20220224172559.4170192-1-rananta@google.com> Message-Id: <20220224172559.4170192-4-rananta@google.com> Mime-Version: 1.0 References: <20220224172559.4170192-1-rananta@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v4 03/13] KVM: arm64: Encode the scope for firmware registers From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220224_092615_185345_3D82C948 X-CRM114-Status: GOOD ( 22.23 ) 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 psuedo-firmware registers, KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1 and KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2, can be scopped as per-VM registers. Hence, during the KVM_GET_REG_LIST call, encode KVM_REG_ARM_SCOPE_VM into the registers, but during KVM_[GET|SET]_ONE_REG calls, clear the scope information such that they can be processed like before. For future expansion, helper functions such as kvm_arm_reg_id_encode_scope() and kvm_arm_reg_id_clear_scope() are introduced. Signed-off-by: Raghavendra Rao Ananta --- arch/arm64/include/asm/kvm_host.h | 2 + arch/arm64/kvm/guest.c | 77 +++++++++++++++++++++++++++++++ arch/arm64/kvm/hypercalls.c | 31 +++++++++---- 3 files changed, 100 insertions(+), 10 deletions(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 8132de6bd718..657733554d98 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -794,6 +794,8 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu); (test_bit(KVM_ARM_VCPU_PMU_V3, (vcpu)->arch.features)) int kvm_trng_call(struct kvm_vcpu *vcpu); +int kvm_arm_reg_id_encode_scope(struct kvm_vcpu *vcpu, u64 *reg_id); +void kvm_arm_reg_id_clear_scope(struct kvm_vcpu *vcpu, u64 *reg_id); #ifdef CONFIG_KVM extern phys_addr_t hyp_mem_base; extern phys_addr_t hyp_mem_size; diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index 8238e52d890d..eb061e64a7a5 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -61,6 +61,83 @@ const struct kvm_stats_header kvm_vcpu_stats_header = { sizeof(kvm_vcpu_stats_desc), }; +/* Registers that are VM scopped */ +static const u64 kvm_arm_vm_scope_fw_regs[] = { + KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1, + KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2, +}; + +/** + * kvm_arm_reg_id_encode_scope - Encode the KVM_REG_ARM_SCOPE info into the + * register-id + * @vcpu: The vcpu pointer + * @reg_id: Pointer to the register + * + * The function adds the register's scoping information into its encoding. + * If it's explicitly marked as a per-VM register, it's encoded with + * KVM_REG_ARM_SCOPE_VM. Else, it's marked as KVM_REG_ARM_SCOPE_VCPU, which + * is also the default if KVM_CAP_ARM_REG_SCOPE is disabled. + * + * For any error cases, the function returns an error code, else it returns + * the integer value of the encoding. + */ +int kvm_arm_reg_id_encode_scope(struct kvm_vcpu *vcpu, u64 *reg_id) +{ + const u64 *vm_scope_reg_arr; + unsigned int arr_size, idx; + + if (!READ_ONCE(vcpu->kvm->arch.reg_scope_enabled)) + return KVM_REG_ARM_SCOPE_VCPU; + + if (!reg_id) + return -EINVAL; + + switch (*reg_id & KVM_REG_ARM_COPROC_MASK) { + case KVM_REG_ARM_FW: + vm_scope_reg_arr = kvm_arm_vm_scope_fw_regs; + arr_size = ARRAY_SIZE(kvm_arm_vm_scope_fw_regs); + break; + default: + /* All the other register classes are currently + * treated as per-vCPU registers. + */ + return KVM_REG_ARM_SCOPE_VCPU; + } + + /* By default, all the registers encodings are scoped as vCPU. + * Modify the scope only if a register is marked as per-VM. + */ + for (idx = 0; idx < arr_size; idx++) { + if (vm_scope_reg_arr[idx] == *reg_id) { + *reg_id |= + KVM_REG_ARM_SCOPE_VM << KVM_REG_ARM_SCOPE_SHIFT; + return KVM_REG_ARM_SCOPE_VM; + } + } + + return KVM_REG_ARM_SCOPE_VCPU; +} + +/** + * kvm_arm_reg_id_clear_scope - Clear the KVM_REG_ARM_SCOPE info from the + * register-id + * @vcpu: The vcpu pointer + * @reg_id: Pointer to the register + * + * The function clears the register's scoping information, which ultimately + * is the raw encoding of the register. Note that the result is same as that + * of re-encoding the register as KVM_REG_ARM_SCOPE_VCPU. + * The function can be helpful to the existing code that uses the original + * register encoding to operate on the register. + */ +void kvm_arm_reg_id_clear_scope(struct kvm_vcpu *vcpu, u64 *reg_id) +{ + if (!READ_ONCE(vcpu->kvm->arch.reg_scope_enabled) || !reg_id) + return; + + *reg_id &= ~(1 << KVM_REG_ARM_SCOPE_SHIFT); +} + static bool core_reg_offset_is_vreg(u64 off) { return off >= KVM_REG_ARM_CORE_REG(fp_regs.vregs) && diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c index 3c2fcf31ad3d..8624e6964940 100644 --- a/arch/arm64/kvm/hypercalls.c +++ b/arch/arm64/kvm/hypercalls.c @@ -160,10 +160,17 @@ int kvm_arm_get_fw_num_regs(struct kvm_vcpu *vcpu) int kvm_arm_copy_fw_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices) { - int i; + int i, ret; + u64 reg_id; for (i = 0; i < ARRAY_SIZE(kvm_arm_fw_reg_ids); i++) { - if (put_user(kvm_arm_fw_reg_ids[i], uindices++)) + reg_id = kvm_arm_fw_reg_ids[i]; + + ret = kvm_arm_reg_id_encode_scope(vcpu, ®_id); + if (ret < 0) + return ret; + + if (put_user(reg_id, uindices++)) return -EFAULT; } @@ -214,21 +221,23 @@ static int get_kernel_wa_level(u64 regid) int kvm_arm_get_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) { void __user *uaddr = (void __user *)(long)reg->addr; - u64 val; + u64 val, reg_id = reg->id; - switch (reg->id) { + kvm_arm_reg_id_clear_scope(vcpu, ®_id); + + switch (reg_id) { case KVM_REG_ARM_PSCI_VERSION: val = kvm_psci_version(vcpu, vcpu->kvm); break; case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1: case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2: - val = get_kernel_wa_level(reg->id) & KVM_REG_FEATURE_LEVEL_MASK; + val = get_kernel_wa_level(reg_id) & KVM_REG_FEATURE_LEVEL_MASK; break; default: return -ENOENT; } - if (copy_to_user(uaddr, &val, KVM_REG_SIZE(reg->id))) + if (copy_to_user(uaddr, &val, KVM_REG_SIZE(reg_id))) return -EFAULT; return 0; @@ -237,13 +246,15 @@ int kvm_arm_get_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) { void __user *uaddr = (void __user *)(long)reg->addr; - u64 val; + u64 val, reg_id = reg->id; int wa_level; if (copy_from_user(&val, uaddr, KVM_REG_SIZE(reg->id))) return -EFAULT; - switch (reg->id) { + kvm_arm_reg_id_clear_scope(vcpu, ®_id); + + switch (reg_id) { case KVM_REG_ARM_PSCI_VERSION: { bool wants_02; @@ -270,7 +281,7 @@ int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) if (val & ~KVM_REG_FEATURE_LEVEL_MASK) return -EINVAL; - if (get_kernel_wa_level(reg->id) < val) + if (get_kernel_wa_level(reg_id) < val) return -EINVAL; return 0; @@ -306,7 +317,7 @@ int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) * We can deal with NOT_AVAIL on NOT_REQUIRED, but not the * other way around. */ - if (get_kernel_wa_level(reg->id) < wa_level) + if (get_kernel_wa_level(reg_id) < wa_level) return -EINVAL; return 0; From patchwork Thu Feb 24 17:25:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12759072 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 80C92C433F5 for ; Thu, 24 Feb 2022 17:29:00 +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: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=+YHzzGK7Dd/I/wtVGweA+y0o3Gq38jsjkFgxQAjep6Y=; b=gtP1tcvzStTY3Sgl02M7TZlRHh sl9zJd86DBJM7BD6giPi9z3i74lN4lJ5+5XXbmMG8yk0Yw/6BjPmhiwB+pISCl/KATa5n+sz1Feie LSNzDH6f3SFj1VjiFvo4WEm7UZgxC5WHUTzS/FrgYNuOEv+aouih/7wzPSl1hR4Pv0RuYg2LCElei S45vMSrJbd9DygjFo1garEidth6cS0NnxT2RsDWAt1MngWlLaMguG8Xr0XuphnZ1e+IEsiukqrxv0 MmIxdcYwfwedEyJix0D9S6BVifE2WgvBVggWg/UcR1O2Mh97GL5Wsr/lTEGD0h3br/Sf+OHRXwjOk HeWl/i9Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHtx-001mj0-Rd; Thu, 24 Feb 2022 17:27:38 +0000 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHsf-001m9w-MW for linux-arm-kernel@lists.infradead.org; Thu, 24 Feb 2022 17:26:22 +0000 Received: by mail-pg1-x54a.google.com with SMTP id bj8-20020a056a02018800b0035ec8c16f0bso1415670pgb.11 for ; Thu, 24 Feb 2022 09:26:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=OsZB1WQ6lcTDQc8TII8Z2w2H891AEk6o7uXrnU60Sz4=; b=n/F4ja1wwLJBW/ijXvomC0vFaa1Gbh0XTIQ72X/rtTtlaWrnWJVjVDVQnw0Chugj0j s8eGLxLruJTXlJ3udhRPkErT9dlaCCvq+4Pc/4AyP6fslw5wApjjMzXxR5JolWEo3Uhn /xF8xB+oMyZoF8zM+m9Y3UAvlg9Q5fezULZ3Z37nGxzJzBcGlg2zHbru5rcSqCNNtg96 iSGxIhYOowJ4KOjg8isnidQLFfTqDemO76gaoctt3D7t2fR4oP7+MifAHi8KKPk6R9uU ke+J+3OxaxPspS1mFy6prNU6GZzF3ophbL5sU3A7T9zPgk19vFCo7IozP+KWOWWnuJ5v YFJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=OsZB1WQ6lcTDQc8TII8Z2w2H891AEk6o7uXrnU60Sz4=; b=THsHQEMNbPFkBFZtJOslSOiPzyFvARFf1eOiYqEBVk1D2BZ4vf9zqTVOJV5MIOaZSw WNUa9LUWvtiKIZv4phvmYitz1edy43li1sXikRFvRHvlsdia2m8TVaI340cj6rbhy9/6 +HqcM+9L7HX7Z4FtbKlzGBabueibMauNnbrkItefEHkOghNJnCtTKdKhOmwluPLRx/lw BBrSbBqVxavmI9aJ3HC7quIS8FmZnQyvuG1bjNgmzOwmmDt7NasDGB7GX3A7CrCg5lqv Ce0C8pN3en+svuYGzyIv8ILm9RTc9/wl9AxS3yq6LteAO/jONZ6hJTPgtvLp5pFnozvR DVYw== X-Gm-Message-State: AOAM531TyG5FypJCDbpsFSzcjkyfAQOTztflToX1uoesbJbxc/JznREL 6bQmMA/fSKCnWDwapliB4j7DsavKoICZ X-Google-Smtp-Source: ABdhPJwNVZA2Yo1/QQAgM2dA9o//8LsSbVv/DS6uJksGu0XtYEWfniXtgFLtkwUsjMzINEE1xgsyTvGjlEWP X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a17:90a:2c0c:b0:1b9:fa47:1caf with SMTP id m12-20020a17090a2c0c00b001b9fa471cafmr3880202pjd.34.1645723575490; Thu, 24 Feb 2022 09:26:15 -0800 (PST) Date: Thu, 24 Feb 2022 17:25:50 +0000 In-Reply-To: <20220224172559.4170192-1-rananta@google.com> Message-Id: <20220224172559.4170192-5-rananta@google.com> Mime-Version: 1.0 References: <20220224172559.4170192-1-rananta@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v4 04/13] KVM: arm64: Capture VM's first run From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220224_092617_775932_11C19EBB X-CRM114-Status: GOOD ( 11.75 ) 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 Capture the first run of the KVM VM, which is basically the first KVM_RUN issued for any vCPU. This state of the VM is helpful in the upcoming patches to prevent user-space from configuring certain VM features, such as the feature bitmap exposed by the psuedo-firmware registers, after the VM has started running. Signed-off-by: Raghavendra Rao Ananta --- arch/arm64/include/asm/kvm_host.h | 9 +++++++++ arch/arm64/kvm/arm.c | 2 ++ 2 files changed, 11 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 657733554d98..e823571e50cc 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -139,6 +139,9 @@ struct kvm_arch { /* Register scoping enabled for KVM registers */ bool reg_scope_enabled; + + /* Capture first run of the VM */ + bool has_run_once; }; struct kvm_vcpu_fault_info { @@ -796,6 +799,12 @@ bool kvm_arm_vcpu_is_finalized(struct kvm_vcpu *vcpu); int kvm_trng_call(struct kvm_vcpu *vcpu); int kvm_arm_reg_id_encode_scope(struct kvm_vcpu *vcpu, u64 *reg_id); void kvm_arm_reg_id_clear_scope(struct kvm_vcpu *vcpu, u64 *reg_id); + +static inline bool kvm_arm_vm_has_run_once(struct kvm_arch *kvm_arch) +{ + return kvm_arch->has_run_once; +} + #ifdef CONFIG_KVM extern phys_addr_t hyp_mem_base; extern phys_addr_t hyp_mem_size; diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index 107977c82c6c..f61cd8d57eae 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -635,6 +635,8 @@ int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu) if (kvm_vm_is_protected(kvm)) kvm_call_hyp_nvhe(__pkvm_vcpu_init_traps, vcpu); + kvm->arch.has_run_once = true; + return ret; } From patchwork Thu Feb 24 17:25:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12759073 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 E2AA9C433EF for ; Thu, 24 Feb 2022 17:29:31 +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: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=3aNCmqyiym2dXuN1sAOfvFvGfTjPkfSEpzf66EpdLUI=; b=smYZ592axLpE/yagbTTg+xvaDH F6KM5IJwSd/ZWthwjEXiFVjM/qCjYZygaMBsDICMQqTBu3gBZ5cgiZ8xlYhok8wXSYAhwuuRQqFcY Dis9vsimKv+P+smsdEgpssXVDkOsQDNmwqQDD3DdfIWKjh7na4K1mk5L61zy/MRl4vogIb7mKDFgg FuW+mvWzqvskLFoxRcSyZqFPuiz7Ep0rj8cVPGQqWTZFeoaJBkJCkduO3NzWIAdgoyoFV2gEqqmSJ kqEaEHneND68sXjMlWM82PrSw3PXjlhIrqU9ptodSBO0lICpmYk7JRoxJ6GfaXq5pop0x/bqTAvjW lTm+5DYQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHuR-001n0h-NP; Thu, 24 Feb 2022 17:28:08 +0000 Received: from mail-pl1-x64a.google.com ([2607:f8b0:4864:20::64a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHsh-001mB2-HC for linux-arm-kernel@lists.infradead.org; Thu, 24 Feb 2022 17:26:23 +0000 Received: by mail-pl1-x64a.google.com with SMTP id 17-20020a170902ee5100b0014fef809980so1416594plo.10 for ; Thu, 24 Feb 2022 09:26:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=BqUDVmORg3gJxeFJEfV8OScHbsxicE1Om/mYva4eJ3Y=; b=rAfqBnG3atJh2mL+uCW1tdA53b0IXTJ+VPS0KnWtbPZKPMPiwhoJtHfbmUC9cOP1CC Esdq4Vmtc0h627Wgs59KBX61NZ9rBrXkscv12jFkr/QWgGbVE19EuCdIpTWqs9Te9sKk hOH/GH7Z7xmkrIn3l2Bzpm8IXvAwf0ynzy56RDS0bBXG8cb+pIIT/A7h3qomxnXnFs2i rZgbME2ajd4E/OpooJHgKVtO704imaNfyZjNkSuUauyJL5/SE00lbar9bmXl6/SWh0+O tK4HXz3BM6sbDWY1fLQYGF5AUBRunJQHTIUQvGY0lZVxoqwBNTgTMw1sqENo16OnJQVo fuXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=BqUDVmORg3gJxeFJEfV8OScHbsxicE1Om/mYva4eJ3Y=; b=MlD21zndWrWmDWa1wCHJIQpJhOYYCq/cXjhtwN5QS+Zf5pv7Zivd+D5lZQJvuG7Xu4 Vj7EA+94Rdizb2b5/QWUB320g7yQXcz8J7udEN79v2qE2S9X6pBMljhD7HaseyRuA3JZ QSvo8/a/3xNuyPKac0TGCa9nrlmgke0Cs+e3Gg6Y8H1vwybOI4e0WaAVdKOvzXDCO7lx b34rrGVvLPDT8W/hgnNY10g9fuJsmdak1B+AZz+ydT6WU39wcDAfQ5eKs1oBr6euTqnY wN98GOY0SExAiBWKyCur4FDc2cp+mqzcYiO+0sCQ3SxomPeFLzJOpAMgpSpi3rkBUlWF Jqqw== X-Gm-Message-State: AOAM531+qvEu/0WFTsTMr3BSmdZ59hS9jmY3mUGFsUeYDiA7fyFHTOMD eFkxTP5FOHH4hL7RODZa3wxkIlxPlIr9 X-Google-Smtp-Source: ABdhPJw9sweD4GH/b1vbNTaysA645aiUNR6TCvzUOD00db8b0cDcuo3978PjhEE0J8cJAOIpo3t5U7+LD2pI X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:aa7:9017:0:b0:4df:e33f:f1b4 with SMTP id m23-20020aa79017000000b004dfe33ff1b4mr3967296pfo.80.1645723577709; Thu, 24 Feb 2022 09:26:17 -0800 (PST) Date: Thu, 24 Feb 2022 17:25:51 +0000 In-Reply-To: <20220224172559.4170192-1-rananta@google.com> Message-Id: <20220224172559.4170192-6-rananta@google.com> Mime-Version: 1.0 References: <20220224172559.4170192-1-rananta@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v4 05/13] KVM: arm64: Setup a framework for hypercall bitmap firmware registers From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220224_092619_623035_487B2B35 X-CRM114-Status: GOOD ( 24.62 ) 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 regularly introduces new hypercall services to the guests without any consent from the userspace. This means, the guests can observe hypercall services in and out as they migrate across various host kernel versions. This could be a major problem if the guest discovered a hypercall, started using it, and after getting migrated to an older kernel realizes that it's no longer available. Depending on how the guest handles the change, there's a potential chance that the guest would just panic. As a result, there's a need for the userspace to elect the services that it wishes the guest to discover. It can elect these services based on the kernels spread across its (migration) fleet. To remedy this, extend the existing firmware psuedo-registers, such as KVM_REG_ARM_PSCI_VERSION, for all the hypercall services available. These firmware registers are categorized based on the service call owners, and unlike the existing firmware psuedo-registers, they hold the features supported in the form of a bitmap. During the VM initialization, the registers holds an upper-limit of the features supported by the corresponding registers. It's expected that the VMMs discover the features provided by each register via GET_ONE_REG, and writeback the desired values using SET_ONE_REG. KVM allows this modification only until the VM has started. Older userspace code can simply ignore the capability and the hypercall services will be exposed unconditionally to the guests, thus ensuring backward compatibility. In this patch, the framework adds the register only for ARM's standard secure services (owner value 4). Currently, this includes support only for ARM True Random Number Generator (TRNG) service, with bit-0 of the register representing mandatory features of v1.0. The register is also added to the kvm_arm_vm_scope_fw_regs[] list as it maintains its state per-VM. Other services are momentarily added in the upcoming patches. Signed-off-by: Raghavendra Rao Ananta --- arch/arm64/include/asm/kvm_host.h | 12 +++++ arch/arm64/include/uapi/asm/kvm.h | 8 ++++ arch/arm64/kvm/arm.c | 8 ++++ arch/arm64/kvm/guest.c | 1 + arch/arm64/kvm/hypercalls.c | 78 +++++++++++++++++++++++++++++++ include/kvm/arm_hypercalls.h | 4 ++ 6 files changed, 111 insertions(+) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index e823571e50cc..1909ced3208f 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -101,6 +101,15 @@ struct kvm_s2_mmu { struct kvm_arch_memory_slot { }; +/** + * struct kvm_hvc_desc: KVM ARM64 hypercall descriptor + * + * @hvc_std_bmap: Bitmap of standard secure service calls + */ +struct kvm_hvc_desc { + u64 hvc_std_bmap; +}; + struct kvm_arch { struct kvm_s2_mmu mmu; @@ -142,6 +151,9 @@ struct kvm_arch { /* Capture first run of the VM */ bool has_run_once; + + /* Hypercall firmware register' descriptor */ + struct kvm_hvc_desc hvc_desc; }; struct kvm_vcpu_fault_info { diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h index c35447cc0e0c..2decc30d6b84 100644 --- a/arch/arm64/include/uapi/asm/kvm.h +++ b/arch/arm64/include/uapi/asm/kvm.h @@ -287,6 +287,14 @@ struct kvm_arm_copy_mte_tags { #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_REQUIRED 3 #define KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_ENABLED (1U << 4) +/* Bitmap firmware registers, extension to the existing psuedo-register space */ +#define KVM_REG_ARM_FW_BMAP KVM_REG_ARM_FW_REG(0xff00) +#define KVM_REG_ARM_FW_BMAP_REG(r) (KVM_REG_ARM_FW_BMAP | (r)) + +#define KVM_REG_ARM_STD_BMAP KVM_REG_ARM_FW_BMAP_REG(0) +#define KVM_REG_ARM_STD_BIT_TRNG_V1_0 BIT(0) +#define KVM_REG_ARM_STD_BMAP_BIT_MAX 0 /* Last valid bit */ + /* SVE registers */ #define KVM_REG_ARM64_SVE (0x15 << KVM_REG_ARM_COPROC_SHIFT) diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c index f61cd8d57eae..e9f9edb1cf55 100644 --- a/arch/arm64/kvm/arm.c +++ b/arch/arm64/kvm/arm.c @@ -156,6 +156,7 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) kvm->arch.max_vcpus = kvm_arm_default_max_vcpus(); set_default_spectre(kvm); + kvm_arm_init_hypercalls(kvm); return ret; out_free_stage2_pgd: @@ -635,7 +636,14 @@ int kvm_arch_vcpu_run_pid_change(struct kvm_vcpu *vcpu) if (kvm_vm_is_protected(kvm)) kvm_call_hyp_nvhe(__pkvm_vcpu_init_traps, vcpu); + /* + * Grab kvm->lock such that the reader of has_run_once can finish + * the necessary operation atomically, such as deciding whether to + * block the writes to the firmware registers if the VM has run once. + */ + mutex_lock(&kvm->lock); kvm->arch.has_run_once = true; + mutex_unlock(&kvm->lock); return ret; } diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index eb061e64a7a5..d66e6c742bbe 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -65,6 +65,7 @@ const struct kvm_stats_header kvm_vcpu_stats_header = { static const u64 kvm_arm_vm_scope_fw_regs[] = { KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1, KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2, + KVM_REG_ARM_STD_BMAP, }; /** diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c index 8624e6964940..48c126c3da72 100644 --- a/arch/arm64/kvm/hypercalls.c +++ b/arch/arm64/kvm/hypercalls.c @@ -58,6 +58,29 @@ static void kvm_ptp_get_time(struct kvm_vcpu *vcpu, u64 *val) val[3] = lower_32_bits(cycles); } +static bool kvm_arm_fw_reg_feat_enabled(u64 reg_bmap, u64 feat_bit) +{ + return reg_bmap & feat_bit; +} + +static bool kvm_hvc_call_supported(struct kvm_vcpu *vcpu, u32 func_id) +{ + struct kvm_hvc_desc *hvc_desc = &vcpu->kvm->arch.hvc_desc; + + switch (func_id) { + case ARM_SMCCC_TRNG_VERSION: + case ARM_SMCCC_TRNG_FEATURES: + case ARM_SMCCC_TRNG_GET_UUID: + case ARM_SMCCC_TRNG_RND32: + case ARM_SMCCC_TRNG_RND64: + return kvm_arm_fw_reg_feat_enabled(hvc_desc->hvc_std_bmap, + KVM_REG_ARM_STD_BIT_TRNG_V1_0); + default: + /* By default, allow the services that aren't listed here */ + return true; + } +} + int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) { u32 func_id = smccc_get_function(vcpu); @@ -65,6 +88,9 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) u32 feature; gpa_t gpa; + if (!kvm_hvc_call_supported(vcpu, func_id)) + goto out; + switch (func_id) { case ARM_SMCCC_VERSION_FUNC_ID: val[0] = ARM_SMCCC_VERSION_1_1; @@ -143,6 +169,7 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) return kvm_psci_call(vcpu); } +out: smccc_set_retval(vcpu, val[0], val[1], val[2], val[3]); return 1; } @@ -151,8 +178,16 @@ static const u64 kvm_arm_fw_reg_ids[] = { KVM_REG_ARM_PSCI_VERSION, KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1, KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2, + KVM_REG_ARM_STD_BMAP, }; +void kvm_arm_init_hypercalls(struct kvm *kvm) +{ + struct kvm_hvc_desc *hvc_desc = &kvm->arch.hvc_desc; + + hvc_desc->hvc_std_bmap = ARM_SMCCC_STD_FEATURES; +} + int kvm_arm_get_fw_num_regs(struct kvm_vcpu *vcpu) { return ARRAY_SIZE(kvm_arm_fw_reg_ids); @@ -220,6 +255,7 @@ static int get_kernel_wa_level(u64 regid) int kvm_arm_get_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) { + struct kvm_hvc_desc *hvc_desc = &vcpu->kvm->arch.hvc_desc; void __user *uaddr = (void __user *)(long)reg->addr; u64 val, reg_id = reg->id; @@ -233,6 +269,9 @@ int kvm_arm_get_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2: val = get_kernel_wa_level(reg_id) & KVM_REG_FEATURE_LEVEL_MASK; break; + case KVM_REG_ARM_STD_BMAP: + val = READ_ONCE(hvc_desc->hvc_std_bmap); + break; default: return -ENOENT; } @@ -243,6 +282,43 @@ int kvm_arm_get_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) return 0; } +static int kvm_arm_set_fw_reg_bmap(struct kvm_vcpu *vcpu, u64 reg_id, u64 val) +{ + int ret = 0; + struct kvm *kvm = vcpu->kvm; + struct kvm_hvc_desc *hvc_desc = &kvm->arch.hvc_desc; + u64 *fw_reg_bmap, fw_reg_features; + + switch (reg_id) { + case KVM_REG_ARM_STD_BMAP: + fw_reg_bmap = &hvc_desc->hvc_std_bmap; + fw_reg_features = ARM_SMCCC_STD_FEATURES; + break; + default: + return -ENOENT; + } + + /* Check for unsupported bit */ + if (val & ~fw_reg_features) + return -EINVAL; + + mutex_lock(&kvm->lock); + + /* + * If the VM (any vCPU) has already started running, return success + * if there's no change in the value. Else, return -EBUSY. + */ + if (kvm_arm_vm_has_run_once(&kvm->arch)) { + ret = *fw_reg_bmap != val ? -EBUSY : 0; + goto out; + } + + WRITE_ONCE(*fw_reg_bmap, val); +out: + mutex_unlock(&kvm->lock); + return ret; +} + int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) { void __user *uaddr = (void __user *)(long)reg->addr; @@ -321,6 +397,8 @@ int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) return -EINVAL; return 0; + case KVM_REG_ARM_STD_BMAP: + return kvm_arm_set_fw_reg_bmap(vcpu, reg_id, val); default: return -ENOENT; } diff --git a/include/kvm/arm_hypercalls.h b/include/kvm/arm_hypercalls.h index 5d38628a8d04..64d30b452809 100644 --- a/include/kvm/arm_hypercalls.h +++ b/include/kvm/arm_hypercalls.h @@ -6,6 +6,9 @@ #include +#define ARM_SMCCC_STD_FEATURES \ + GENMASK_ULL(KVM_REG_ARM_STD_BMAP_BIT_MAX, 0) + int kvm_hvc_call_handler(struct kvm_vcpu *vcpu); static inline u32 smccc_get_function(struct kvm_vcpu *vcpu) @@ -42,6 +45,7 @@ static inline void smccc_set_retval(struct kvm_vcpu *vcpu, struct kvm_one_reg; +void kvm_arm_init_hypercalls(struct kvm *kvm); int kvm_arm_get_fw_num_regs(struct kvm_vcpu *vcpu); int kvm_arm_copy_fw_reg_indices(struct kvm_vcpu *vcpu, u64 __user *uindices); int kvm_arm_get_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg); From patchwork Thu Feb 24 17:25:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12759074 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 A6FD5C433F5 for ; Thu, 24 Feb 2022 17:29:52 +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: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=ecUGdpOXXCWU0/gydgF4ION9BUZkUcVt81DdygGdgHQ=; b=bfazqc1kByXFq2dibv6c6H8tvg d0t6/m/JrEZlHxVorzz9GEsmchptcoMOootiLsX/4UtE3aOxnIjJ7Ry4SZbIxV1LcjXRoL8VXNolN o3Q6tQdn46Xfdi3D4kG3oM+moBdkcLhvZvu2nzKC30KYheIBk80D1Idqu7ZQ/YPPsQnzZKUl6SrQa nh+jWQ9OFaiuiovYujrhxkeUa4Dm9y6Jo78Z3QGph4BpKGFtAZL4IfQGxR8ag0a6Z1Mw2lxx4z0X4 i7e89aXF2rzwra4fb/KAKEYuxy+bSVHD4ZZLy+OezZP9RouxO2XlDz/uaU40ogzp8SEtnhAUCTZSq P6Enq1aA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHuq-001nDi-Bs; Thu, 24 Feb 2022 17:28:32 +0000 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHsj-001mBr-UA for linux-arm-kernel@lists.infradead.org; Thu, 24 Feb 2022 17:26:24 +0000 Received: by mail-pg1-x54a.google.com with SMTP id u74-20020a63794d000000b00373efe2ac5aso1406892pgc.14 for ; Thu, 24 Feb 2022 09:26:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=f7YVBmCb6IbcPz2I9pSRMYsNCE3tvWzh5vUe6Npy1Ak=; b=GIp3dFeze4hYb6KlcHmjeEgFI+VrVtEnbRgjGd32qlKA2YNcGaWP5tT+SNeDb5id8S OdR8AlBGI5a6PQqilkbfUfvxWLDDf+IXhx8WG/NOwhGsskYyy/CHYj+Zno+qpTUQEIZ2 KaW+a/lIWjQmpI6XnKUUswrx/dBC3jyJp2SbUuhnRxsWZYjCUrDzAr/OCUvz7RrfQQSp V847UnL1nDMpusfG3u00l5lwbJkA8sSm6L1nHUC1cnsF35YkXe/TyPAjoHlSTAEQPe8k 6QTrumKamOpp/qNO1f2Gc08fFiPg0Rz7NRXpzm4NEsT6QCisj6F+6SFEBlavPRBdSjqT A+iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=f7YVBmCb6IbcPz2I9pSRMYsNCE3tvWzh5vUe6Npy1Ak=; b=F+WHGTjxcdpYbHpXpTuC1Hn9xqTtDfwwOLVi7JpQXm/pPenkmXl3MNhpaeDCS/CPLW /9CiJ4a9Rh/guuvq3T8GYbqzvJOdJn/5BZ6QCHKwLKH2DI0Dld9AsnzRR2irwX8PnJVO GvNikLefZfIIUbU4beD41FT1huesdTVOALID8uZayP536Qb1lrj37Nytc4NICKBEdbvT Jf/Rt4M94VfdDi/9BIvPmnD49HdQt2NpTUE/4GA91r/AbHG/h89ZqluA8pbrRxxMP4yn kGjnbxDtoZKtcxLekVwIT7ZJp/fJnzkVWetbcxgzHNavYCHSoc+WDE4nv7nyC7vwx3C5 ECgw== X-Gm-Message-State: AOAM533vM/cHHPdKPPBjwJ8ZGSOl8u+sff5gzJFVW6fKGkFhrrVOvRY1 lIYeyeIe6qw6f45V00QWQzUPwpocmssF X-Google-Smtp-Source: ABdhPJxSCGu3k55BbAvghObP6sR447q+n09jYrxk+9b6zOi1NDp47823WoeG/9N4MDL4UVSEZtw++WwQmJLQ X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a05:6a00:1aca:b0:4e1:a2b6:5b9 with SMTP id f10-20020a056a001aca00b004e1a2b605b9mr3807079pfv.4.1645723580479; Thu, 24 Feb 2022 09:26:20 -0800 (PST) Date: Thu, 24 Feb 2022 17:25:52 +0000 In-Reply-To: <20220224172559.4170192-1-rananta@google.com> Message-Id: <20220224172559.4170192-7-rananta@google.com> Mime-Version: 1.0 References: <20220224172559.4170192-1-rananta@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v4 06/13] KVM: arm64: Add standard hypervisor firmware register From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220224_092622_021736_53A609D2 X-CRM114-Status: GOOD ( 16.95 ) 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 the firmware register to hold the standard hypervisor service calls (owner value 5) as a bitmap. The bitmap represents the features that'll be enabled for the guest, as configured by the user-space. Currently, this includes support only for Paravirtualized time, represented by bit-0. The register is also added to the kvm_arm_vm_scope_fw_regs[] list as it maintains its state per-VM. Signed-off-by: Raghavendra Rao Ananta --- arch/arm64/include/asm/kvm_host.h | 2 ++ arch/arm64/include/uapi/asm/kvm.h | 4 ++++ arch/arm64/kvm/guest.c | 1 + arch/arm64/kvm/hypercalls.c | 20 +++++++++++++++++++- include/kvm/arm_hypercalls.h | 3 +++ 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 1909ced3208f..318148b69279 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -105,9 +105,11 @@ struct kvm_arch_memory_slot { * struct kvm_hvc_desc: KVM ARM64 hypercall descriptor * * @hvc_std_bmap: Bitmap of standard secure service calls + * @hvc_std_hyp_bmap: Bitmap of standard hypervisor service calls */ struct kvm_hvc_desc { u64 hvc_std_bmap; + u64 hvc_std_hyp_bmap; }; struct kvm_arch { diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h index 2decc30d6b84..9a2caead7359 100644 --- a/arch/arm64/include/uapi/asm/kvm.h +++ b/arch/arm64/include/uapi/asm/kvm.h @@ -295,6 +295,10 @@ struct kvm_arm_copy_mte_tags { #define KVM_REG_ARM_STD_BIT_TRNG_V1_0 BIT(0) #define KVM_REG_ARM_STD_BMAP_BIT_MAX 0 /* Last valid bit */ +#define KVM_REG_ARM_STD_HYP_BMAP KVM_REG_ARM_FW_BMAP_REG(1) +#define KVM_REG_ARM_STD_HYP_BIT_PV_TIME BIT(0) +#define KVM_REG_ARM_STD_HYP_BMAP_BIT_MAX 0 /* Last valid bit */ + /* SVE registers */ #define KVM_REG_ARM64_SVE (0x15 << KVM_REG_ARM_COPROC_SHIFT) diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index d66e6c742bbe..c42426d6137e 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -66,6 +66,7 @@ static const u64 kvm_arm_vm_scope_fw_regs[] = { KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1, KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2, KVM_REG_ARM_STD_BMAP, + KVM_REG_ARM_STD_HYP_BMAP, }; /** diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c index 48c126c3da72..ebc0cc26cf2e 100644 --- a/arch/arm64/kvm/hypercalls.c +++ b/arch/arm64/kvm/hypercalls.c @@ -75,6 +75,10 @@ static bool kvm_hvc_call_supported(struct kvm_vcpu *vcpu, u32 func_id) case ARM_SMCCC_TRNG_RND64: return kvm_arm_fw_reg_feat_enabled(hvc_desc->hvc_std_bmap, KVM_REG_ARM_STD_BIT_TRNG_V1_0); + case ARM_SMCCC_HV_PV_TIME_FEATURES: + case ARM_SMCCC_HV_PV_TIME_ST: + return kvm_arm_fw_reg_feat_enabled(hvc_desc->hvc_std_hyp_bmap, + KVM_REG_ARM_STD_HYP_BIT_PV_TIME); default: /* By default, allow the services that aren't listed here */ return true; @@ -83,6 +87,7 @@ static bool kvm_hvc_call_supported(struct kvm_vcpu *vcpu, u32 func_id) int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) { + struct kvm_hvc_desc *hvc_desc = &vcpu->kvm->arch.hvc_desc; u32 func_id = smccc_get_function(vcpu); u64 val[4] = {SMCCC_RET_NOT_SUPPORTED}; u32 feature; @@ -134,7 +139,10 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) } break; case ARM_SMCCC_HV_PV_TIME_FEATURES: - val[0] = SMCCC_RET_SUCCESS; + if (kvm_arm_fw_reg_feat_enabled( + hvc_desc->hvc_std_hyp_bmap, + KVM_REG_ARM_STD_HYP_BIT_PV_TIME)) + val[0] = SMCCC_RET_SUCCESS; break; } break; @@ -179,6 +187,7 @@ static const u64 kvm_arm_fw_reg_ids[] = { KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1, KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2, KVM_REG_ARM_STD_BMAP, + KVM_REG_ARM_STD_HYP_BMAP, }; void kvm_arm_init_hypercalls(struct kvm *kvm) @@ -186,6 +195,7 @@ void kvm_arm_init_hypercalls(struct kvm *kvm) struct kvm_hvc_desc *hvc_desc = &kvm->arch.hvc_desc; hvc_desc->hvc_std_bmap = ARM_SMCCC_STD_FEATURES; + hvc_desc->hvc_std_hyp_bmap = ARM_SMCCC_STD_HYP_FEATURES; } int kvm_arm_get_fw_num_regs(struct kvm_vcpu *vcpu) @@ -272,6 +282,9 @@ int kvm_arm_get_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) case KVM_REG_ARM_STD_BMAP: val = READ_ONCE(hvc_desc->hvc_std_bmap); break; + case KVM_REG_ARM_STD_HYP_BMAP: + val = READ_ONCE(hvc_desc->hvc_std_hyp_bmap); + break; default: return -ENOENT; } @@ -294,6 +307,10 @@ static int kvm_arm_set_fw_reg_bmap(struct kvm_vcpu *vcpu, u64 reg_id, u64 val) fw_reg_bmap = &hvc_desc->hvc_std_bmap; fw_reg_features = ARM_SMCCC_STD_FEATURES; break; + case KVM_REG_ARM_STD_HYP_BMAP: + fw_reg_bmap = &hvc_desc->hvc_std_hyp_bmap; + fw_reg_features = ARM_SMCCC_STD_HYP_FEATURES; + break; default: return -ENOENT; } @@ -398,6 +415,7 @@ int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) return 0; case KVM_REG_ARM_STD_BMAP: + case KVM_REG_ARM_STD_HYP_BMAP: return kvm_arm_set_fw_reg_bmap(vcpu, reg_id, val); default: return -ENOENT; diff --git a/include/kvm/arm_hypercalls.h b/include/kvm/arm_hypercalls.h index 64d30b452809..a1cb6e839c74 100644 --- a/include/kvm/arm_hypercalls.h +++ b/include/kvm/arm_hypercalls.h @@ -9,6 +9,9 @@ #define ARM_SMCCC_STD_FEATURES \ GENMASK_ULL(KVM_REG_ARM_STD_BMAP_BIT_MAX, 0) +#define ARM_SMCCC_STD_HYP_FEATURES \ + GENMASK_ULL(KVM_REG_ARM_STD_HYP_BMAP_BIT_MAX, 0) + int kvm_hvc_call_handler(struct kvm_vcpu *vcpu); static inline u32 smccc_get_function(struct kvm_vcpu *vcpu) From patchwork Thu Feb 24 17:25:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12759075 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 30A2AC43217 for ; Thu, 24 Feb 2022 17:30:30 +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: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=oUJD9azBHIO6TnCZIQMcbYA2cMiIFHUpkNrEkvh5msg=; b=mDcisYXzuuOWKstrJGbJrCKZv9 cmtmJ62MzWzzB0kij9+UbQRC/ZNbl0+WYNAURHg1aE45Jwcl8UxzZ7amDZGU3kUC26xiV6uGBqmfM Coi37zi5tFQlY0iJ3TU+92Eh2IbocB/OOQOH97jHq84+OCphDqs43Yg4+gs+MMahRgXGe1+879J6t DavMFqVlsq9vc3ai8aKtRsa78EUWRTZP4zT2HoWAwYPMbC83pju0cyl9UyAClmgtEc7r5E9VnF8Ob 8uchZIr/4JlCWiDFuFSdWe9Lxik5fXzamCYWvZhDkyhnUfz6fA32tWevgImD3VRhCUXLq1QjHIvsu 8zPv5OEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHvJ-001nPm-Ig; Thu, 24 Feb 2022 17:29:01 +0000 Received: from mail-pg1-x54a.google.com ([2607:f8b0:4864:20::54a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHsn-001mD3-1z for linux-arm-kernel@lists.infradead.org; Thu, 24 Feb 2022 17:26:26 +0000 Received: by mail-pg1-x54a.google.com with SMTP id n188-20020a6340c5000000b003747606cb0dso1417470pga.6 for ; Thu, 24 Feb 2022 09:26:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=0wDRpcCunfnn6jCq2Avo69TvJ8i4x6eSnCJLc/mO0iE=; b=ciEhdzZf28FOJSjBalS1IXNdMFbY6mvXPtNTSgACZqBzz53Fw5WS+3q7RMKXXr0e6f Yze4Oiywc8kMCpD1QhLgqXFtFk6jSdqVP9eKRBsXSKO5b1OYcJ2rqZb6pS78RrqiV2rj SSswk2sH09OAW1GYjO44B1cM8+1dTNx7Rxheuih2CHf8M8ETwuK0boZnjK2Z0aExSuw0 Rp0qyU7BMMoMsl7YlYBpOFaR8OWovgakrwllhYAnPu/fwwP+JLAIQ8F+F8on+FcdPGzN Pew7kD00APKcrjSXCaLpU+b37D4YcYibmne+3dmu7tB3E7w0NqBBIytvwvkUs/1MuZ8+ jEwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=0wDRpcCunfnn6jCq2Avo69TvJ8i4x6eSnCJLc/mO0iE=; b=Vlt2w8Ke3WKGzWhWf4I9ot9cfrISzdBA6t9hdGXdFVEqpZlxgu6JWoDxmnGrOcKbfU gMxQXKl3wE/BlN/4lgTC0N9rX+RW8123LobJJPyzrNZZo985amWJNZ9UVwaD+6/MNprT mntIwGwHLrGkN1ZQ5Sp4AkENFF6y+Gh6DZjsSci0IwKVFduM6K6na/hUpSXdeQE8vKw7 pm5sT3wTKSoKM8tFixLq6fFMDQWCHPGOk3hMXGAZCSjunlbd2n3lT5HI43qWHlyrh/dF uXOVn4PYfYUEdGcUD1EdCs6d4mkdO/5ul9BcWmu6jrbD91MJDm0E1YpsBD/99984WDhW Hcrw== X-Gm-Message-State: AOAM532SKus/jBwD+JyNnVUHBt5jM9yBsT0xqWolxo7Mnyfkkv9c/eJq urNGpCCmdaVzrpVzOBEqy2DR0+dScybA X-Google-Smtp-Source: ABdhPJzqjbV4k4lcCU4qKhTeOaOfUQ1qbFWWZSE6Unijap+Xg11o0GsRTN8d58koVdyFFG9WdVpF4hMmJYWM X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a05:6a00:1f08:b0:4c6:eb85:be8c with SMTP id be8-20020a056a001f0800b004c6eb85be8cmr3806765pfb.62.1645723583919; Thu, 24 Feb 2022 09:26:23 -0800 (PST) Date: Thu, 24 Feb 2022 17:25:53 +0000 In-Reply-To: <20220224172559.4170192-1-rananta@google.com> Message-Id: <20220224172559.4170192-8-rananta@google.com> Mime-Version: 1.0 References: <20220224172559.4170192-1-rananta@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v4 07/13] KVM: arm64: Add vendor hypervisor firmware register From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220224_092625_166802_1CD0A5AA X-CRM114-Status: GOOD ( 16.71 ) 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 the firmware register to hold the vendor specific hypervisor service calls (owner value 6) as a bitmap. The bitmap represents the features that'll be enabled for the guest, as configured by the user-space. Currently, this includes support only for Precision Time Protocol (PTP), represented by bit-0. The register is also added to the kvm_arm_vm_scope_fw_regs[] list as it maintains its state per-VM. Signed-off-by: Raghavendra Rao Ananta --- arch/arm64/include/asm/kvm_host.h | 2 ++ arch/arm64/include/uapi/asm/kvm.h | 4 ++++ arch/arm64/kvm/guest.c | 1 + arch/arm64/kvm/hypercalls.c | 22 +++++++++++++++++++++- include/kvm/arm_hypercalls.h | 3 +++ 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h index 318148b69279..d999456c4604 100644 --- a/arch/arm64/include/asm/kvm_host.h +++ b/arch/arm64/include/asm/kvm_host.h @@ -106,10 +106,12 @@ struct kvm_arch_memory_slot { * * @hvc_std_bmap: Bitmap of standard secure service calls * @hvc_std_hyp_bmap: Bitmap of standard hypervisor service calls + * @hvc_vendor_hyp_bmap: Bitmap of vendor specific hypervisor service calls */ struct kvm_hvc_desc { u64 hvc_std_bmap; u64 hvc_std_hyp_bmap; + u64 hvc_vendor_hyp_bmap; }; struct kvm_arch { diff --git a/arch/arm64/include/uapi/asm/kvm.h b/arch/arm64/include/uapi/asm/kvm.h index 9a2caead7359..ed470bde13d8 100644 --- a/arch/arm64/include/uapi/asm/kvm.h +++ b/arch/arm64/include/uapi/asm/kvm.h @@ -299,6 +299,10 @@ struct kvm_arm_copy_mte_tags { #define KVM_REG_ARM_STD_HYP_BIT_PV_TIME BIT(0) #define KVM_REG_ARM_STD_HYP_BMAP_BIT_MAX 0 /* Last valid bit */ +#define KVM_REG_ARM_VENDOR_HYP_BMAP KVM_REG_ARM_FW_BMAP_REG(2) +#define KVM_REG_ARM_VENDOR_HYP_BIT_PTP BIT(0) +#define KVM_REG_ARM_VENDOR_HYP_BMAP_BIT_MAX 0 /* Last valid bit */ + /* SVE registers */ #define KVM_REG_ARM64_SVE (0x15 << KVM_REG_ARM_COPROC_SHIFT) diff --git a/arch/arm64/kvm/guest.c b/arch/arm64/kvm/guest.c index c42426d6137e..fc3656f91aed 100644 --- a/arch/arm64/kvm/guest.c +++ b/arch/arm64/kvm/guest.c @@ -67,6 +67,7 @@ static const u64 kvm_arm_vm_scope_fw_regs[] = { KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2, KVM_REG_ARM_STD_BMAP, KVM_REG_ARM_STD_HYP_BMAP, + KVM_REG_ARM_VENDOR_HYP_BMAP, }; /** diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c index ebc0cc26cf2e..5c5098c8f1f9 100644 --- a/arch/arm64/kvm/hypercalls.c +++ b/arch/arm64/kvm/hypercalls.c @@ -79,6 +79,9 @@ static bool kvm_hvc_call_supported(struct kvm_vcpu *vcpu, u32 func_id) case ARM_SMCCC_HV_PV_TIME_ST: return kvm_arm_fw_reg_feat_enabled(hvc_desc->hvc_std_hyp_bmap, KVM_REG_ARM_STD_HYP_BIT_PV_TIME); + case ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID: + return kvm_arm_fw_reg_feat_enabled(hvc_desc->hvc_vendor_hyp_bmap, + KVM_REG_ARM_VENDOR_HYP_BIT_PTP); default: /* By default, allow the services that aren't listed here */ return true; @@ -162,7 +165,14 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu) break; case ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID: val[0] = BIT(ARM_SMCCC_KVM_FUNC_FEATURES); - val[0] |= BIT(ARM_SMCCC_KVM_FUNC_PTP); + + /* + * The feature bits exposed to user-space doesn't include + * ARM_SMCCC_KVM_FUNC_FEATURES. However, we expose this to + * the guest as bit-0. Hence, left-shift the user-space + * exposed bitmap by 1 to accommodate this. + */ + val[0] |= hvc_desc->hvc_vendor_hyp_bmap << 1; break; case ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID: kvm_ptp_get_time(vcpu, val); @@ -188,6 +198,7 @@ static const u64 kvm_arm_fw_reg_ids[] = { KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2, KVM_REG_ARM_STD_BMAP, KVM_REG_ARM_STD_HYP_BMAP, + KVM_REG_ARM_VENDOR_HYP_BMAP, }; void kvm_arm_init_hypercalls(struct kvm *kvm) @@ -196,6 +207,7 @@ void kvm_arm_init_hypercalls(struct kvm *kvm) hvc_desc->hvc_std_bmap = ARM_SMCCC_STD_FEATURES; hvc_desc->hvc_std_hyp_bmap = ARM_SMCCC_STD_HYP_FEATURES; + hvc_desc->hvc_vendor_hyp_bmap = ARM_SMCCC_VENDOR_HYP_FEATURES; } int kvm_arm_get_fw_num_regs(struct kvm_vcpu *vcpu) @@ -285,6 +297,9 @@ int kvm_arm_get_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) case KVM_REG_ARM_STD_HYP_BMAP: val = READ_ONCE(hvc_desc->hvc_std_hyp_bmap); break; + case KVM_REG_ARM_VENDOR_HYP_BMAP: + val = READ_ONCE(hvc_desc->hvc_vendor_hyp_bmap); + break; default: return -ENOENT; } @@ -311,6 +326,10 @@ static int kvm_arm_set_fw_reg_bmap(struct kvm_vcpu *vcpu, u64 reg_id, u64 val) fw_reg_bmap = &hvc_desc->hvc_std_hyp_bmap; fw_reg_features = ARM_SMCCC_STD_HYP_FEATURES; break; + case KVM_REG_ARM_VENDOR_HYP_BMAP: + fw_reg_bmap = &hvc_desc->hvc_vendor_hyp_bmap; + fw_reg_features = ARM_SMCCC_VENDOR_HYP_FEATURES; + break; default: return -ENOENT; } @@ -416,6 +435,7 @@ int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg) return 0; case KVM_REG_ARM_STD_BMAP: case KVM_REG_ARM_STD_HYP_BMAP: + case KVM_REG_ARM_VENDOR_HYP_BMAP: return kvm_arm_set_fw_reg_bmap(vcpu, reg_id, val); default: return -ENOENT; diff --git a/include/kvm/arm_hypercalls.h b/include/kvm/arm_hypercalls.h index a1cb6e839c74..91be758ca58e 100644 --- a/include/kvm/arm_hypercalls.h +++ b/include/kvm/arm_hypercalls.h @@ -12,6 +12,9 @@ #define ARM_SMCCC_STD_HYP_FEATURES \ GENMASK_ULL(KVM_REG_ARM_STD_HYP_BMAP_BIT_MAX, 0) +#define ARM_SMCCC_VENDOR_HYP_FEATURES \ + GENMASK_ULL(KVM_REG_ARM_VENDOR_HYP_BMAP_BIT_MAX, 0) + int kvm_hvc_call_handler(struct kvm_vcpu *vcpu); static inline u32 smccc_get_function(struct kvm_vcpu *vcpu) From patchwork Thu Feb 24 17:25:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12759076 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 4E4DFC433EF for ; Thu, 24 Feb 2022 17:30:50 +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: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=XRKa6UP8eJUsvS6/3ZIGrP8WMChgTbZXjNvaWYHXI74=; b=WxE3/K1gIfjDxlTiwjeUy3XZfb ZwIo/pfdHFK13HdtlGrs6TOobn7urQT5ZQOH3RAGxClcozOXdjE7SXfrK+9zp78c4Sh1EPiTCuKaF rBwAFoRZ0MF/EPWqSI/fI69kz1S0oYnELCRuq4nAfp4GyFwBWBLjbA9veqO2ZwC2fPnBmeblAVs/p ECDRVApXKIHRfccqHicMpzuUpQDPPt/+I6wwxXHhLev4MdmKBf4p65j1BiIHdJbZ8uYF9vMYJan/c Vc2XCjcJZP37rky68L6K+uHjJP5WVZaeASxLeFVcuJ0mXfGpAuLpwQ6P/5BnszznCUodBsVwZTw6A aoqIdajw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHve-001naW-W2; Thu, 24 Feb 2022 17:29:23 +0000 Received: from mail-pf1-x44a.google.com ([2607:f8b0:4864:20::44a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHsq-001mE3-0P for linux-arm-kernel@lists.infradead.org; Thu, 24 Feb 2022 17:26:29 +0000 Received: by mail-pf1-x44a.google.com with SMTP id j204-20020a6280d5000000b004e107ad3488so1616550pfd.15 for ; Thu, 24 Feb 2022 09:26:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=b6uNiWvgAwogCk/jxX+wM4vHns+UEbCP4x0AKJLO+4Q=; b=h+4yAjVxpHpHUG9ZXzKDxIY+XLIBSv6S2i9Dizt7ZsHBT6ZQPOVwypGOZXKBNUg6DZ R6n9PG3mnByfdNrm8n/8ktstVfOHvp/Ref4D+MPm4vuwgKFo4gTWrv7W38u0oQKvhnxi Bc+teTfh7/CqaXBRR3MXfqLp30xNrKZPqHJhTjpFdSvBNQUJb6opdmPm7JNfTOliqfz7 +lNPqy0LF97Pb3uCq/4tTwWMkFYwLB+f6iUL/onr8Z86zLRqVweT0wANPb0ELlZb9XmW sKD0BqPMfSCeVVNxMxORAmwxagVX3bmp6ivji2USJVMpXim36w50UMdzJYYiaax+rIQe I7Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=b6uNiWvgAwogCk/jxX+wM4vHns+UEbCP4x0AKJLO+4Q=; b=VQjVSBIq9+8ggG1WGKVYgwSH52pysprJnikADTFuFl0kCrfh5lY+gKCvuwJ/N7Buca MiKoMR0A6VOsdoIci1PjRbiIrw+mxbMjnx+mDuBHoRXVfaZ6jE69PHeXZYxHQr8xb7qq Jmm8YMTyI6M2nCgHn+W+8dlATGz8jgaC8iehfhIoFw7S/dkHKV6CGao/kfFE5Xfur3tj JcTFA96gv5LJPf5f1Vnjl8GzSxsBykqjOpt2BPIEtbjRN2+zREwWs5wouh5HVtDqxMoM hN0HQoFxcIM/onqJtDAIHRM8X+IHB4zrmqtZotw+6ebSnNVGH6tuLANdSWpEM4p1bNq1 rlQQ== X-Gm-Message-State: AOAM532a5/4barJ+pmW44m5x4mZXeQnKIMrGW3Z4dCH64/5F8Q1aDTdF KVie1ZFaFMFtzlyM1WNGf81mcPrqhjOK X-Google-Smtp-Source: ABdhPJwk7AgkVcTxMVZ+wEFay2w+mClV6dcietIwRyKAlHhoCWyT1LJHKiM+ia3GXTfTot6zyZ3GOK98LzI0 X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a17:902:930b:b0:14d:b0c0:1f71 with SMTP id bc11-20020a170902930b00b0014db0c01f71mr3700280plb.113.1645723586271; Thu, 24 Feb 2022 09:26:26 -0800 (PST) Date: Thu, 24 Feb 2022 17:25:54 +0000 In-Reply-To: <20220224172559.4170192-1-rananta@google.com> Message-Id: <20220224172559.4170192-9-rananta@google.com> Mime-Version: 1.0 References: <20220224172559.4170192-1-rananta@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v4 08/13] Docs: KVM: Add doc for the bitmap firmware registers From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220224_092628_142338_D41FF837 X-CRM114-Status: GOOD ( 17.86 ) 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 Add the documentation for the bitmap firmware registers in psci.rst. This includes the details for KVM_REG_ARM_STD_BMAP, KVM_REG_ARM_STD_HYP_BMAP, and KVM_REG_ARM_VENDOR_HYP_BMAP registers. Since the document is growing to carry other hypercall related information, make necessary adjustments to present the document in a generic sense, rather than being PSCI focused. Signed-off-by: Raghavendra Rao Ananta --- Documentation/virt/kvm/arm/psci.rst | 83 ++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 18 deletions(-) diff --git a/Documentation/virt/kvm/arm/psci.rst b/Documentation/virt/kvm/arm/psci.rst index d52c2e83b5b8..bc5c2886ca23 100644 --- a/Documentation/virt/kvm/arm/psci.rst +++ b/Documentation/virt/kvm/arm/psci.rst @@ -1,32 +1,32 @@ .. SPDX-License-Identifier: GPL-2.0 -========================================= -Power State Coordination Interface (PSCI) -========================================= +======================= +ARM Hypercall Interface +======================= -KVM implements the PSCI (Power State Coordination Interface) -specification in order to provide services such as CPU on/off, reset -and power-off to the guest. +KVM handles the hypercall services as requested by the guests. New hypercall +services are regularly made available by the ARM specification or by KVM (as +vendor services) if they make sense from a virtualization point of view. -The PSCI specification is regularly updated to provide new features, -and KVM implements these updates if they make sense from a virtualization -point of view. - -This means that a guest booted on two different versions of KVM can -observe two different "firmware" revisions. This could cause issues if -a given guest is tied to a particular PSCI revision (unlikely), or if -a migration causes a different PSCI version to be exposed out of the -blue to an unsuspecting guest. +This means that a guest booted on two different versions of KVM can observe +two different "firmware" revisions. This could cause issues if a given guest +is tied to a particular version of a hypercall service, or if a migration +causes a different version to be exposed out of the blue to an unsuspecting +guest. In order to remedy this situation, KVM exposes a set of "firmware pseudo-registers" that can be manipulated using the GET/SET_ONE_REG interface. These registers can be saved/restored by userspace, and set -to a convenient value if required. +to a convenient value as required. -The following register is defined: +The following registers are defined: * KVM_REG_ARM_PSCI_VERSION: + KVM implements the PSCI (Power State Coordination Interface) + specification in order to provide services such as CPU on/off, reset + and power-off to the guest. + - Only valid if the vcpu has the KVM_ARM_VCPU_PSCI_0_2 feature set (and thus has already been initialized) - Returns the current PSCI version on GET_ONE_REG (defaulting to the @@ -74,4 +74,51 @@ The following register is defined: KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2_NOT_REQUIRED: The workaround is always active on this vCPU or it is not needed. -.. [1] https://developer.arm.com/-/media/developer/pdf/ARM_DEN_0070A_Firmware_interfaces_for_mitigating_CVE-2017-5715.pdf +Contrary to the above registers, the following registers exposes the hypercall +services in the form of a feature-bitmap. This bitmap is translated to the +services that are exposed to the guest. There is a register defined per service +call owner and can be accessed via GET/SET_ONE_REG interface. + +By default, these registers are set with the upper limit of the features that +are supported. User-space can discover this configuration via GET_ONE_REG. If +unsatisfied, the user-space can write back the desired bitmap back via +SET_ONE_REG. The features for the registers that are untouched, probably because +userspace isn't aware of them, will be exposed as is to the guest. + +The psuedo-firmware bitmap register are as follows: + +* KVM_REG_ARM_STD_BMAP: + Controls the bitmap of the ARM Standard Secure Service Calls. + + The following bits are accepted: + + KVM_REG_ARM_STD_BIT_TRNG_V1_0: + The bit represents the services offered under v1.0 of ARM True Random + Number Generator (TRNG) specification, ARM DEN0098. + +* KVM_REG_ARM_STD_HYP_BMAP: + Controls the bitmap of the ARM Standard Hypervisor Service Calls. + + The following bits are accepted: + + KVM_REG_ARM_STD_HYP_BIT_PV_TIME: + The bit represents the Paravirtualized Time service as represented by + ARM DEN0057A. + +* KVM_REG_ARM_VENDOR_HYP_BMAP: + Controls the bitmap of the Vendor specific Hypervisor Service Calls. + + The following bits are accepted: + + KVM_REG_ARM_VENDOR_HYP_BIT_PTP: + The bit represents the Precision Time Protocol KVM service. + +Errors: + + ======= ============================================================= + -ENOENT Unknown register accessed. + -EBUSY Attempt a 'write' to the register after the VM has started. + -EINVAL Invalid bitmap written to the register. + ======= ============================================================= + +.. [1] https://developer.arm.com/-/media/developer/pdf/ARM_DEN_0070A_Firmware_interfaces_for_mitigating_CVE-2017-5715.pdf \ No newline at end of file From patchwork Thu Feb 24 17:25:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12759077 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 D136AC433EF for ; Thu, 24 Feb 2022 17:31:24 +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: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=NDMbHavjA+DKESGJkVD/hds/KGd7+0D7AHM4V3DN9PM=; b=F7PvRC+GVrxGYeTo+CLcL20xal 9iI3bQg3Un2cLSjAMldbkeThwl3qWTM33ipwTpZCzV/maimY5+HeHv/aR43HCJqxpvHF9mtp/2Yeg BTCNKPLenD1WgxKZ0ySeosQRz1KQzWVhAHti7xiJGsv+v2gjbYdj6U1INmFd9hRSdRqCM7EfBCM6+ /647leONEyVpAQ3nZx/R3LlewTBAM/zGJFZVpQAm92ecBx78lpNYwhPJl44IpUtcZVxKKnDsItlM/ CP/jyYzDbGeN2MS/nr8VI4K7uzxT/bMbcazZEXStH9P2NEOLEinwX8jHo1cd25YoVgviLsy/lMy5E 5IHCZKcQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHwF-001nqC-0h; Thu, 24 Feb 2022 17:30:00 +0000 Received: from mail-pj1-x1049.google.com ([2607:f8b0:4864:20::1049]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHss-001mFI-0G for linux-arm-kernel@lists.infradead.org; Thu, 24 Feb 2022 17:26:31 +0000 Received: by mail-pj1-x1049.google.com with SMTP id w3-20020a17090ac98300b001b8b914e91aso1766155pjt.0 for ; Thu, 24 Feb 2022 09:26:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=/yI+1iHLFKapqIM71Fi477KtJQIbrAd1wE7m0DoVTrg=; b=BX44DBoUoT7DxSh0J1USD87fHZhHxbcIv+UIN+p9yTigBQ9rkC70b9lUdxzXby4YQD KMd52RGWYjaaW1mHhmPX5yT+JeYaFygpZY0qhfH1XvQg4NW+V/3WQmadTFO0LuyUmjqI Lf4X1oVugf+w+6UILacWvqCQD699Y1sZ4jHxPCht5kQp0Z7gmZzjkNCEjNdcP+9Z/PgR xKtXomjP+kvoY2+igh5Qgl1oXuX44weeSxLg17woXyG242n2H2rrMhMI9uPz0uyVFxom j9u76QtEXmUQj2ImKEWLR1zsNdb+nKTskysG+XXZFqOdlVy/AMw05nrczKv2DjXofDpL i+ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=/yI+1iHLFKapqIM71Fi477KtJQIbrAd1wE7m0DoVTrg=; b=Dle3JT/3BWghCWXElpGyTmjFfmbCgQDPKtfssbugm+pvLz192wNkkyRNfDGyH5P5vv 24WlXvciPkb2AYzBsRUVUkerowoWhuHdvn7jkrAOSz/7Vhs94vpEjJOR2Y/4Ri0WHAB0 FDCdt0PCxLwlNUAxswbReeBknO5gwQg4dY3Cop4G52vX8Hm/wDAgiM4QEWaUhhCptqhW 4IiK0INNR29sivNWxgKN2R69yjoETZX4PNJ+gcI8jwI0kDUWCStKTrBg6MKhuud9Twe9 RIZrdbz80GvnFJGZRhcxSdS5dkJnf/jzsXgqSF4SxtLanzTuzjR3PoCanoZ21IdzcGiJ eN4Q== X-Gm-Message-State: AOAM531X6J8zHSZi9MWy+s9/Jv0U+V4IKsK73vXpICMvgAkSnFx2Nz3l btHPEhXbbAsTIz/Gyql8Lw2JHoG04efK X-Google-Smtp-Source: ABdhPJyekDaVQfujrpGwc51nGDLUID+Ox5wvRHROwF3BH9GvfkusWzxxeNEpolKSk+8ZEG7ImKIZOKSGzN1P X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a17:902:700b:b0:148:ee33:70fe with SMTP id y11-20020a170902700b00b00148ee3370femr3741547plk.38.1645723588637; Thu, 24 Feb 2022 09:26:28 -0800 (PST) Date: Thu, 24 Feb 2022 17:25:55 +0000 In-Reply-To: <20220224172559.4170192-1-rananta@google.com> Message-Id: <20220224172559.4170192-10-rananta@google.com> Mime-Version: 1.0 References: <20220224172559.4170192-1-rananta@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v4 09/13] Docs: KVM: Rename psci.rst to hypercalls.rst From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220224_092630_113385_7167E8D5 X-CRM114-Status: UNSURE ( 7.07 ) X-CRM114-Notice: Please train this message. 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 Since the doc now covers more of general hypercalls' details, rather than just PSCI, rename the file to a more appropriate name- hypercalls.rst. Signed-off-by: Raghavendra Rao Ananta Reviewed-by: Oliver Upton --- Documentation/virt/kvm/arm/{psci.rst => hypercalls.rst} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Documentation/virt/kvm/arm/{psci.rst => hypercalls.rst} (100%) diff --git a/Documentation/virt/kvm/arm/psci.rst b/Documentation/virt/kvm/arm/hypercalls.rst similarity index 100% rename from Documentation/virt/kvm/arm/psci.rst rename to Documentation/virt/kvm/arm/hypercalls.rst From patchwork Thu Feb 24 17:25:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12759078 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 7D8C4C433F5 for ; Thu, 24 Feb 2022 17:32:04 +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: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=gwZJ4TSxvG/ssqu6hdjLvdF1eIDNXMhuXW0I/YJwwwc=; b=uvOi1bEkNg3gc0+K+JhBiIU4XU W7G4KtMrPdF4Vyl4jEj4NRYb1kfGlc3SZbaMuTnyjSfpBvSfxJsVzb2sSSMGkLc0tL5Er6L5crAPl NPrlPH6j5rHFrFEN1eh4ko7/vo4k+M71caGDQK2Uo9rSGMMT0krnlkOcum9ed4Im3GVA/yTzMYcBy n2vrW8uKToYZwXTetoe5RxDx+YP0UeN77MrMejKa8lhybEP4PMcHg3GY2pfygkGe85Z0/k5npMVNx vE/Om6pc519eZiDFykYAT5cUr8uS04CiKjZvsPmbeMPZWNW6ryDgRF7FOuuxkuW+9yrvRCtd4VfZd sGMIukEg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHwl-001o4k-Ht; Thu, 24 Feb 2022 17:30:32 +0000 Received: from mail-pg1-x549.google.com ([2607:f8b0:4864:20::549]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHsu-001mGV-IU for linux-arm-kernel@lists.infradead.org; Thu, 24 Feb 2022 17:26:34 +0000 Received: by mail-pg1-x549.google.com with SMTP id m15-20020a63580f000000b00370dc6cafe9so1424816pgb.5 for ; Thu, 24 Feb 2022 09:26:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=QgbZvK2OelZR+0slSn0oup5LSIqRFfP5HH0xakkbQ6w=; b=Lp9S001wVZKumLnKiYdg5/2/uqFBt8Q08r4iWj4R52Lln+D6Uv3QDcDGCzRCLJ/Zz5 4mRMpYYJ143XdWGhmIQq/sMsanQQxpkHbgcTEjzYz0LArNd2914JkTg9haSVbRQKOWvj SPfKcZ9cdqDDS9hkaAYmkoTPTi+R/bxI7+XO6T38ukpTXlvjMbX9Ht9gMR1NgxezI7nq luV7w7eiImB1E3qBilLWKb5GrWvl5x7HuQIXy3oLGwXQ/XR9vgRZteqEuqlHtJU9NNza rl8lhTtJgU241kVvdAMWAT2NrjO1iwjwjwnM+OnWMVi/vuNgc1+mcIwNQ3SvoNZcuJDy wHjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=QgbZvK2OelZR+0slSn0oup5LSIqRFfP5HH0xakkbQ6w=; b=sa9huKvfj/O07Vm3bkV5nyiNG/jlS7c1zS1+FRMqV3V2jG6B2m1kHwrHQegblL3OFE cNweNVsU9NuNJ/R8i2DkqN9W40QUfxr7NxB/4ldOwFbyTMskIQrMhWniHUmefoRe3GTW DGb98IbfxpzIwM/Yb5y/sBSk4bZ0l4sgYZmJYciV0ZC0BB1cJ8/BgZNt8s75jgU95G1K 6EDzHYP5o6kKiyeO8fle71vKkcpEn4L4zr7pKcaYH0o+nSsRUCZRiicO+zs/HCxpGZPU z2DsuS2uo0EjbF8E3MNvnHjQ5ImV3C/PTR7lQ1rf4KA7h2H7D0smEY35WS/7VLelYhdt TExA== X-Gm-Message-State: AOAM530UK16EDTT6w1iJJKPe0qlqYLXxENjgFPM+zsGuQCrbYPznL7Ro /JpfOM0AoaD2cHxX8yj0PbsG/TcOboXA X-Google-Smtp-Source: ABdhPJxW0ZC3y6jO1H/YjjkgEZ96qgNVN6qZHewqJNTPXXTh2+qkgZzrfvIUvtDka7Ycif5aizVS9DjWhAWE X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a17:902:ce05:b0:14f:8ba2:2339 with SMTP id k5-20020a170902ce0500b0014f8ba22339mr3560434plg.152.1645723590707; Thu, 24 Feb 2022 09:26:30 -0800 (PST) Date: Thu, 24 Feb 2022 17:25:56 +0000 In-Reply-To: <20220224172559.4170192-1-rananta@google.com> Message-Id: <20220224172559.4170192-11-rananta@google.com> Mime-Version: 1.0 References: <20220224172559.4170192-1-rananta@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v4 10/13] tools: Import ARM SMCCC definitions From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220224_092632_649278_E3E0BDEC X-CRM114-Status: GOOD ( 14.62 ) 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 Import the standard SMCCC definitions from include/linux/arm-smccc.h. Signed-off-by: Raghavendra Rao Ananta --- tools/include/linux/arm-smccc.h | 188 ++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100644 tools/include/linux/arm-smccc.h diff --git a/tools/include/linux/arm-smccc.h b/tools/include/linux/arm-smccc.h new file mode 100644 index 000000000000..a11c0bbabd5b --- /dev/null +++ b/tools/include/linux/arm-smccc.h @@ -0,0 +1,188 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2015, Linaro Limited + */ +#ifndef __LINUX_ARM_SMCCC_H +#define __LINUX_ARM_SMCCC_H + +#include + +/* + * This file provides common defines for ARM SMC Calling Convention as + * specified in + * https://developer.arm.com/docs/den0028/latest + * + * This code is up-to-date with version DEN 0028 C + */ + +#define ARM_SMCCC_STD_CALL _AC(0,U) +#define ARM_SMCCC_FAST_CALL _AC(1,U) +#define ARM_SMCCC_TYPE_SHIFT 31 + +#define ARM_SMCCC_SMC_32 0 +#define ARM_SMCCC_SMC_64 1 +#define ARM_SMCCC_CALL_CONV_SHIFT 30 + +#define ARM_SMCCC_OWNER_MASK 0x3F +#define ARM_SMCCC_OWNER_SHIFT 24 + +#define ARM_SMCCC_FUNC_MASK 0xFFFF + +#define ARM_SMCCC_IS_FAST_CALL(smc_val) \ + ((smc_val) & (ARM_SMCCC_FAST_CALL << ARM_SMCCC_TYPE_SHIFT)) +#define ARM_SMCCC_IS_64(smc_val) \ + ((smc_val) & (ARM_SMCCC_SMC_64 << ARM_SMCCC_CALL_CONV_SHIFT)) +#define ARM_SMCCC_FUNC_NUM(smc_val) ((smc_val) & ARM_SMCCC_FUNC_MASK) +#define ARM_SMCCC_OWNER_NUM(smc_val) \ + (((smc_val) >> ARM_SMCCC_OWNER_SHIFT) & ARM_SMCCC_OWNER_MASK) + +#define ARM_SMCCC_CALL_VAL(type, calling_convention, owner, func_num) \ + (((type) << ARM_SMCCC_TYPE_SHIFT) | \ + ((calling_convention) << ARM_SMCCC_CALL_CONV_SHIFT) | \ + (((owner) & ARM_SMCCC_OWNER_MASK) << ARM_SMCCC_OWNER_SHIFT) | \ + ((func_num) & ARM_SMCCC_FUNC_MASK)) + +#define ARM_SMCCC_OWNER_ARCH 0 +#define ARM_SMCCC_OWNER_CPU 1 +#define ARM_SMCCC_OWNER_SIP 2 +#define ARM_SMCCC_OWNER_OEM 3 +#define ARM_SMCCC_OWNER_STANDARD 4 +#define ARM_SMCCC_OWNER_STANDARD_HYP 5 +#define ARM_SMCCC_OWNER_VENDOR_HYP 6 +#define ARM_SMCCC_OWNER_TRUSTED_APP 48 +#define ARM_SMCCC_OWNER_TRUSTED_APP_END 49 +#define ARM_SMCCC_OWNER_TRUSTED_OS 50 +#define ARM_SMCCC_OWNER_TRUSTED_OS_END 63 + +#define ARM_SMCCC_FUNC_QUERY_CALL_UID 0xff01 + +#define ARM_SMCCC_QUIRK_NONE 0 +#define ARM_SMCCC_QUIRK_QCOM_A6 1 /* Save/restore register a6 */ + +#define ARM_SMCCC_VERSION_1_0 0x10000 +#define ARM_SMCCC_VERSION_1_1 0x10001 +#define ARM_SMCCC_VERSION_1_2 0x10002 +#define ARM_SMCCC_VERSION_1_3 0x10003 + +#define ARM_SMCCC_1_3_SVE_HINT 0x10000 + +#define ARM_SMCCC_VERSION_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, 0) + +#define ARM_SMCCC_ARCH_FEATURES_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, 1) + +#define ARM_SMCCC_ARCH_SOC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, 2) + +#define ARM_SMCCC_ARCH_WORKAROUND_1 \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, 0x8000) + +#define ARM_SMCCC_ARCH_WORKAROUND_2 \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + 0, 0x7fff) + +#define ARM_SMCCC_VENDOR_HYP_CALL_UID_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_VENDOR_HYP, \ + ARM_SMCCC_FUNC_QUERY_CALL_UID) + +/* KVM UID value: 28b46fb6-2ec5-11e9-a9ca-4b564d003a74 */ +#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_0 0xb66fb428U +#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_1 0xe911c52eU +#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_2 0x564bcaa9U +#define ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3 0x743a004dU + +/* KVM "vendor specific" services */ +#define ARM_SMCCC_KVM_FUNC_FEATURES 0 +#define ARM_SMCCC_KVM_FUNC_PTP 1 +#define ARM_SMCCC_KVM_FUNC_FEATURES_2 127 +#define ARM_SMCCC_KVM_NUM_FUNCS 128 + +#define ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_VENDOR_HYP, \ + ARM_SMCCC_KVM_FUNC_FEATURES) + +#define SMCCC_ARCH_WORKAROUND_RET_UNAFFECTED 1 + +/* + * ptp_kvm is a feature used for time sync between vm and host. + * ptp_kvm module in guest kernel will get service from host using + * this hypercall ID. + */ +#define ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_VENDOR_HYP, \ + ARM_SMCCC_KVM_FUNC_PTP) + +/* ptp_kvm counter type ID */ +#define KVM_PTP_VIRT_COUNTER 0 +#define KVM_PTP_PHYS_COUNTER 1 + +/* Paravirtualised time calls (defined by ARM DEN0057A) */ +#define ARM_SMCCC_HV_PV_TIME_FEATURES \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_64, \ + ARM_SMCCC_OWNER_STANDARD_HYP, \ + 0x20) + +#define ARM_SMCCC_HV_PV_TIME_ST \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_64, \ + ARM_SMCCC_OWNER_STANDARD_HYP, \ + 0x21) + +/* TRNG entropy source calls (defined by ARM DEN0098) */ +#define ARM_SMCCC_TRNG_VERSION \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_STANDARD, \ + 0x50) + +#define ARM_SMCCC_TRNG_FEATURES \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_STANDARD, \ + 0x51) + +#define ARM_SMCCC_TRNG_GET_UUID \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_STANDARD, \ + 0x52) + +#define ARM_SMCCC_TRNG_RND32 \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_32, \ + ARM_SMCCC_OWNER_STANDARD, \ + 0x53) + +#define ARM_SMCCC_TRNG_RND64 \ + ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, \ + ARM_SMCCC_SMC_64, \ + ARM_SMCCC_OWNER_STANDARD, \ + 0x53) + +/* + * Return codes defined in ARM DEN 0070A + * ARM DEN 0070A is now merged/consolidated into ARM DEN 0028 C + */ +#define SMCCC_RET_SUCCESS 0 +#define SMCCC_RET_NOT_SUPPORTED -1 +#define SMCCC_RET_NOT_REQUIRED -2 +#define SMCCC_RET_INVALID_PARAMETER -3 + +#endif /*__LINUX_ARM_SMCCC_H*/ From patchwork Thu Feb 24 17:25:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12759079 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 16D27C433FE for ; Thu, 24 Feb 2022 17:32:41 +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: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=JGu661ER31k6U5CV1yd6l0U+SRsRoJCoFyAB+PHzXbU=; b=lZMWl7zP8vccuOhLeyY6c15PlG MNAE5hrMj+jELQGC8yc3Cee+puFXJAOr6P95mrwyHBwKkhTLXKrUe1x0xe9xm8fSixfgG/88pwUAk hZeh68n31ntQ8lr64JHEevXSfte9VB2KF010RHLBNEc7YOygU/b0sWBYplGVjyc5K5YZ0/ES5fjQk 3ezpdX6Pmia1/JYty4Gd5TOVPYqcwf1vsog5TJegqbYkx40yB8DgW0DSwH6kPpa2YD0sBjrbuBqhj t4GD1Ro9vBhWSAS7N8A59vmXmQGknyPVLx88O44fG9cQ7X6FSn4//99GjUmGVrscxH797s4KiOue6 MeLfOipw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHxK-001oLv-Eo; Thu, 24 Feb 2022 17:31:07 +0000 Received: from mail-pl1-x649.google.com ([2607:f8b0:4864:20::649]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHsw-001mHh-91 for linux-arm-kernel@lists.infradead.org; Thu, 24 Feb 2022 17:26:37 +0000 Received: by mail-pl1-x649.google.com with SMTP id n12-20020a170902968c00b001500c6029b0so1420293plp.5 for ; Thu, 24 Feb 2022 09:26:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=KxLF7qzKbc8UFtk7tO6zSgT4pjqe2yY92U69kuJWElE=; b=Ibq2L/kDegT2ECNcaQXPAs7djEODMNl6Odaya6jgnPWZwo8ddlFwZQf5S2DV1lDKXh KvqDVlQRjlXs0r+9hv5s4YACXuw+mZH8LtJ9PjnUl+m/ZKgOJhNu5UTG/sW92wXtuJ53 uTA70vfKFeeqKKcz3kmCuUJDCYC2jsj1x3VKD3fMxhwpYqXFxkE6Ryi/kYomzSshDYFb zaCFurXQqXvGlWD9SuSkzApAxF7z4m7vGgt6OanmwFR3UcAlwoV4m/vf2Dl/KySQsaX/ ID6OoI+rC9i9ZACeBS2AWlYwc3JMYgiMB0VLfj+e4bNJ3K/2wDtWal25WRCbJUUBRdW1 09hA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=KxLF7qzKbc8UFtk7tO6zSgT4pjqe2yY92U69kuJWElE=; b=3D90wUWv2BrLvbw9b4+Epe+vKGGPQz+jX1lI1LaTmfaq675SVn8H2LjpOpNguM5mMI MIFIo/Vvi0lb3LO4iw/ymKu+Ylkx32pnASzhqvOBztcC4bOxYuQqcBTeLMuT3Iz+I5jC XUNS6nc1wprRirwrGZ9hOO86vSEsReeE+IFGM5tLO601LyJ72lbnjala82T61SGLnBXH ZKbIUoedo/QUPbbizyRfzXcKb/TiEI2mChuptt1zfwxKGsLXZeWV7UEZ3Xjoj6vr0X2h j49dtnjdlnVuakT0XbvBNlQPJvncnb/4LK1zkSXpl+mj0sj54G1XjdqLpohcXItuq/63 FIKQ== X-Gm-Message-State: AOAM530zUSlmyklwJbfCOTZh/Lo2uAsXlO5XcLVEEbM1GcjKzrUVqOA6 WjIa8uLj8wNIswOJPUYA1nmj68nUrHOA X-Google-Smtp-Source: ABdhPJyrVMqrzObbtdrqsKfy7PVH706+lroyD/W5B1nltv6iTYOALVQlwfiPpkDn123mnsFrgGkxxJ5C3gkx X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a17:902:d345:b0:14f:ee29:5ee6 with SMTP id l5-20020a170902d34500b0014fee295ee6mr3440637plk.102.1645723593017; Thu, 24 Feb 2022 09:26:33 -0800 (PST) Date: Thu, 24 Feb 2022 17:25:57 +0000 In-Reply-To: <20220224172559.4170192-1-rananta@google.com> Message-Id: <20220224172559.4170192-12-rananta@google.com> Mime-Version: 1.0 References: <20220224172559.4170192-1-rananta@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v4 11/13] selftests: KVM: aarch64: Introduce hypercall ABI test From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220224_092634_373099_1C0461D6 X-CRM114-Status: GOOD ( 23.05 ) 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 KVM selftest to check the hypercall interface for arm64 platforms. The test validates the user-space's IOCTL interface to read/write the psuedo-firmware registers as well as its effects on the guest upon certain configurations. Signed-off-by: Raghavendra Rao Ananta --- tools/testing/selftests/kvm/.gitignore | 1 + tools/testing/selftests/kvm/Makefile | 1 + .../selftests/kvm/aarch64/hypercalls.c | 376 ++++++++++++++++++ 3 files changed, 378 insertions(+) create mode 100644 tools/testing/selftests/kvm/aarch64/hypercalls.c diff --git a/tools/testing/selftests/kvm/.gitignore b/tools/testing/selftests/kvm/.gitignore index ac69108d9ffd..f13c33fcd733 100644 --- a/tools/testing/selftests/kvm/.gitignore +++ b/tools/testing/selftests/kvm/.gitignore @@ -2,6 +2,7 @@ /aarch64/arch_timer /aarch64/debug-exceptions /aarch64/get-reg-list +/aarch64/hypercalls /aarch64/psci_test /aarch64/vgic_init /aarch64/vgic_irq diff --git a/tools/testing/selftests/kvm/Makefile b/tools/testing/selftests/kvm/Makefile index 2a27c09b22ae..2181bdd5b09c 100644 --- a/tools/testing/selftests/kvm/Makefile +++ b/tools/testing/selftests/kvm/Makefile @@ -102,6 +102,7 @@ TEST_GEN_PROGS_x86_64 += system_counter_offset_test TEST_GEN_PROGS_aarch64 += aarch64/arch_timer TEST_GEN_PROGS_aarch64 += aarch64/debug-exceptions TEST_GEN_PROGS_aarch64 += aarch64/get-reg-list +TEST_GEN_PROGS_aarch64 += aarch64/hypercalls TEST_GEN_PROGS_aarch64 += aarch64/psci_test TEST_GEN_PROGS_aarch64 += aarch64/vgic_init TEST_GEN_PROGS_aarch64 += aarch64/vgic_irq diff --git a/tools/testing/selftests/kvm/aarch64/hypercalls.c b/tools/testing/selftests/kvm/aarch64/hypercalls.c new file mode 100644 index 000000000000..e4e3a286ff3e --- /dev/null +++ b/tools/testing/selftests/kvm/aarch64/hypercalls.c @@ -0,0 +1,376 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* hypercalls: Check the ARM64's psuedo-firmware bitmap register interface. + * + * The test validates the basic hypercall functionalities that are exposed + * via the psuedo-firmware bitmap register. This includes the registers' + * read/write behavior before and after the VM has started, and if the + * hypercalls are properly masked or unmasked to the guest when disabled or + * enabled from the KVM userspace, respectively. + */ + +#include +#include +#include +#include + +#include "processor.h" + +#define FW_REG_ULIMIT_VAL(max_feat_bit) (GENMASK_ULL(max_feat_bit, 0)) + +struct kvm_fw_reg_info { + uint64_t reg; /* Register definition */ + uint64_t max_feat_bit; /* Bit that represents the upper limit of the feature-map */ +}; + +#define FW_REG_INFO(r, bit_max) \ + { \ + .reg = r, \ + .max_feat_bit = bit_max, \ + } + +static const struct kvm_fw_reg_info fw_reg_info[] = { + FW_REG_INFO(KVM_REG_ARM_STD_BMAP, KVM_REG_ARM_STD_BMAP_BIT_MAX), + FW_REG_INFO(KVM_REG_ARM_STD_HYP_BMAP, KVM_REG_ARM_STD_HYP_BMAP_BIT_MAX), + FW_REG_INFO(KVM_REG_ARM_VENDOR_HYP_BMAP, KVM_REG_ARM_VENDOR_HYP_BMAP_BIT_MAX), +}; + +enum test_stage { + TEST_STAGE_REG_IFACE, + TEST_STAGE_HVC_IFACE_FEAT_DISABLED, + TEST_STAGE_HVC_IFACE_FEAT_ENABLED, + TEST_STAGE_HVC_IFACE_FALSE_INFO, + TEST_STAGE_END, +}; + +static int stage; + +struct test_hvc_info { + uint32_t func_id; + int64_t arg0; + + void (*test_hvc_disabled)(const struct test_hvc_info *hc_info, + struct arm_smccc_res *res); + void (*test_hvc_enabled)(const struct test_hvc_info *hc_info, + struct arm_smccc_res *res); +}; + +#define TEST_HVC_INFO(f, a0, test_disabled, test_enabled) \ + { \ + .func_id = f, \ + .arg0 = a0, \ + .test_hvc_disabled = test_disabled, \ + .test_hvc_enabled = test_enabled, \ + } + +static void +test_ptp_feat_hvc_disabled(const struct test_hvc_info *hc_info, struct arm_smccc_res *res) +{ + GUEST_ASSERT_3((res->a0 & BIT(ARM_SMCCC_KVM_FUNC_PTP)) == 0, + res->a0, hc_info->func_id, hc_info->arg0); +} + +static void +test_ptp_feat_hvc_enabled(const struct test_hvc_info *hc_info, struct arm_smccc_res *res) +{ + GUEST_ASSERT_3((res->a0 & BIT(ARM_SMCCC_KVM_FUNC_PTP)) != 0, + res->a0, hc_info->func_id, hc_info->arg0); +} + +static const struct test_hvc_info hvc_info[] = { + /* KVM_REG_ARM_STD_BMAP: KVM_REG_ARM_STD_BIT_TRNG_V1_0 */ + TEST_HVC_INFO(ARM_SMCCC_TRNG_VERSION, 0, NULL, NULL), + TEST_HVC_INFO(ARM_SMCCC_TRNG_FEATURES, ARM_SMCCC_TRNG_RND64, NULL, NULL), + TEST_HVC_INFO(ARM_SMCCC_TRNG_GET_UUID, 0, NULL, NULL), + TEST_HVC_INFO(ARM_SMCCC_TRNG_RND32, 0, NULL, NULL), + TEST_HVC_INFO(ARM_SMCCC_TRNG_RND64, 0, NULL, NULL), + + /* KVM_REG_ARM_STD_HYP_BMAP: KVM_REG_ARM_STD_HYP_BIT_PV_TIME */ + TEST_HVC_INFO(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, + ARM_SMCCC_HV_PV_TIME_FEATURES, NULL, NULL), + TEST_HVC_INFO(ARM_SMCCC_HV_PV_TIME_FEATURES, + ARM_SMCCC_HV_PV_TIME_ST, NULL, NULL), + TEST_HVC_INFO(ARM_SMCCC_HV_PV_TIME_ST, 0, NULL, NULL), + + /* KVM_REG_ARM_VENDOR_HYP_BMAP: KVM_REG_ARM_VENDOR_HYP_BIT_PTP */ + TEST_HVC_INFO(ARM_SMCCC_VENDOR_HYP_KVM_FEATURES_FUNC_ID, + ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID, + test_ptp_feat_hvc_disabled, test_ptp_feat_hvc_enabled), + TEST_HVC_INFO(ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID, + KVM_PTP_VIRT_COUNTER, NULL, NULL), +}; + +/* Feed false hypercall info to test the KVM behavior */ +static const struct test_hvc_info false_hvc_info[] = { + /* Feature support check against a different family of hypercalls */ + TEST_HVC_INFO(ARM_SMCCC_TRNG_FEATURES, + ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID, NULL, NULL), + TEST_HVC_INFO(ARM_SMCCC_ARCH_FEATURES_FUNC_ID, + ARM_SMCCC_TRNG_RND64, NULL, NULL), + TEST_HVC_INFO(ARM_SMCCC_HV_PV_TIME_FEATURES, + ARM_SMCCC_TRNG_RND64, NULL, NULL), +}; + +static void guest_test_hvc(const struct test_hvc_info *hc_info) +{ + unsigned int i; + struct arm_smccc_res res; + unsigned int hvc_info_arr_sz; + + hvc_info_arr_sz = + hc_info == hvc_info ? ARRAY_SIZE(hvc_info) : ARRAY_SIZE(false_hvc_info); + + for (i = 0; i < hvc_info_arr_sz; i++, hc_info++) { + + memset(&res, 0, sizeof(res)); + smccc_hvc(hc_info->func_id, hc_info->arg0, 0, 0, 0, 0, 0, 0, &res); + + switch (stage) { + case TEST_STAGE_HVC_IFACE_FEAT_DISABLED: + if (hc_info->test_hvc_disabled) + hc_info->test_hvc_disabled(hc_info, &res); + else + GUEST_ASSERT_3(res.a0 == SMCCC_RET_NOT_SUPPORTED, + res.a0, hc_info->func_id, hc_info->arg0); + break; + case TEST_STAGE_HVC_IFACE_FEAT_ENABLED: + if (hc_info->test_hvc_enabled) + hc_info->test_hvc_enabled(hc_info, &res); + else + GUEST_ASSERT_3(res.a0 != SMCCC_RET_NOT_SUPPORTED, + res.a0, hc_info->func_id, hc_info->arg0); + break; + case TEST_STAGE_HVC_IFACE_FALSE_INFO: + GUEST_ASSERT_3(res.a0 == SMCCC_RET_NOT_SUPPORTED, + res.a0, hc_info->func_id, hc_info->arg0); + break; + default: + GUEST_ASSERT_1(0, stage); + } + } +} + +static void guest_code(void) +{ + while (stage != TEST_STAGE_END) { + switch (stage) { + case TEST_STAGE_REG_IFACE: + break; + case TEST_STAGE_HVC_IFACE_FEAT_DISABLED: + case TEST_STAGE_HVC_IFACE_FEAT_ENABLED: + guest_test_hvc(hvc_info); + break; + case TEST_STAGE_HVC_IFACE_FALSE_INFO: + guest_test_hvc(false_hvc_info); + break; + default: + GUEST_ASSERT_1(0, stage); + } + + GUEST_SYNC(stage); + } + + GUEST_DONE(); +} + +static int set_fw_reg(struct kvm_vm *vm, uint64_t id, uint64_t val) +{ + struct kvm_one_reg reg = { + .id = KVM_REG_ARM_FW_REG(id), + .addr = (uint64_t)&val, + }; + + return _vcpu_ioctl(vm, 0, KVM_SET_ONE_REG, ®); +} + +static void get_fw_reg(struct kvm_vm *vm, uint64_t id, uint64_t *addr) +{ + struct kvm_one_reg reg = { + .id = KVM_REG_ARM_FW_REG(id), + .addr = (uint64_t)addr, + }; + + return vcpu_ioctl(vm, 0, KVM_GET_ONE_REG, ®); +} + +struct st_time { + uint32_t rev; + uint32_t attr; + uint64_t st_time; +}; + +#define STEAL_TIME_SIZE ((sizeof(struct st_time) + 63) & ~63) +#define ST_GPA_BASE (1 << 30) + +static void steal_time_init(struct kvm_vm *vm) +{ + uint64_t st_ipa = (ulong)ST_GPA_BASE; + unsigned int gpages; + struct kvm_device_attr dev = { + .group = KVM_ARM_VCPU_PVTIME_CTRL, + .attr = KVM_ARM_VCPU_PVTIME_IPA, + .addr = (uint64_t)&st_ipa, + }; + + gpages = vm_calc_num_guest_pages(VM_MODE_DEFAULT, STEAL_TIME_SIZE); + vm_userspace_mem_region_add(vm, VM_MEM_SRC_ANONYMOUS, ST_GPA_BASE, 1, gpages, 0); + + vcpu_ioctl(vm, 0, KVM_SET_DEVICE_ATTR, &dev); +} + +static void test_fw_regs_before_vm_start(struct kvm_vm *vm) +{ + uint64_t val; + unsigned int i; + int ret; + + for (i = 0; i < ARRAY_SIZE(fw_reg_info); i++) { + const struct kvm_fw_reg_info *reg_info = &fw_reg_info[i]; + + /* First read should be an upper limit of the features supported */ + get_fw_reg(vm, reg_info->reg, &val); + TEST_ASSERT(val == FW_REG_ULIMIT_VAL(reg_info->max_feat_bit), + "Expected all the features to be set for reg: 0x%lx; expected: 0x%llx; read: 0x%lx\n", + reg_info->reg, GENMASK_ULL(reg_info->max_feat_bit, 0), val); + + /* Test 'write' by disabling all the features of the register map */ + ret = set_fw_reg(vm, reg_info->reg, 0); + TEST_ASSERT(ret == 0, + "Failed to clear all the features of reg: 0x%lx; ret: %d\n", + reg_info->reg, errno); + + get_fw_reg(vm, reg_info->reg, &val); + TEST_ASSERT(val == 0, + "Expected all the features to be cleared for reg: 0x%lx\n", reg_info->reg); + + /* + * Test enabling a feature that's not supported. + * Avoid this check if all the bits are occupied. + */ + if (reg_info->max_feat_bit < 63) { + ret = set_fw_reg(vm, reg_info->reg, BIT(reg_info->max_feat_bit + 1)); + TEST_ASSERT(ret != 0 && errno == EINVAL, + "Unexpected behavior or return value (%d) while setting an unsupported feature for reg: 0x%lx\n", + errno, reg_info->reg); + } + } +} + +static void test_fw_regs_after_vm_start(struct kvm_vm *vm) +{ + uint64_t val; + unsigned int i; + int ret; + + for (i = 0; i < ARRAY_SIZE(fw_reg_info); i++) { + const struct kvm_fw_reg_info *reg_info = &fw_reg_info[i]; + + /* + * Before starting the VM, the test clears all the bits. + * Check if that's still the case. + */ + get_fw_reg(vm, reg_info->reg, &val); + TEST_ASSERT(val == 0, + "Expected all the features to be cleared for reg: 0x%lx\n", + reg_info->reg); + + /* + * Test setting the last read value. KVM should allow this + * even if VM has started running. + */ + ret = set_fw_reg(vm, reg_info->reg, val); + TEST_ASSERT(ret == 0, + "Failed to set the register with previously read value after Vm start for reg: 0x%lx; ret: %d\n", + reg_info->reg, errno); + + /* + * Set all the features for this register again. KVM shouldn't + * allow this as the VM is running. + */ + ret = set_fw_reg(vm, reg_info->reg, FW_REG_ULIMIT_VAL(reg_info->max_feat_bit)); + TEST_ASSERT(ret != 0 && errno == EBUSY, + "Unexpected behavior or return value (%d) while setting a feature while VM is running for reg: 0x%lx\n", + errno, reg_info->reg); + } +} + +static struct kvm_vm *test_vm_create(void) +{ + struct kvm_vm *vm; + + vm = vm_create_default(0, 0, guest_code); + + ucall_init(vm, NULL); + steal_time_init(vm); + + return vm; +} + +static struct kvm_vm *test_guest_stage(struct kvm_vm *vm) +{ + struct kvm_vm *ret_vm = vm; + + pr_debug("Stage: %d\n", stage); + + switch (stage) { + case TEST_STAGE_REG_IFACE: + test_fw_regs_after_vm_start(vm); + break; + case TEST_STAGE_HVC_IFACE_FEAT_DISABLED: + /* Start a new VM so that all the features are now enabled by default */ + kvm_vm_free(vm); + ret_vm = test_vm_create(); + break; + case TEST_STAGE_HVC_IFACE_FEAT_ENABLED: + case TEST_STAGE_HVC_IFACE_FALSE_INFO: + break; + default: + TEST_FAIL("Unknown test stage: %d\n", stage); + } + + stage++; + sync_global_to_guest(vm, stage); + + return ret_vm; +} + +static void test_run(void) +{ + struct kvm_vm *vm; + struct ucall uc; + bool guest_done = false; + + vm = test_vm_create(); + + test_fw_regs_before_vm_start(vm); + + while (!guest_done) { + vcpu_run(vm, 0); + + switch (get_ucall(vm, 0, &uc)) { + case UCALL_SYNC: + vm = test_guest_stage(vm); + break; + case UCALL_DONE: + guest_done = true; + break; + case UCALL_ABORT: + TEST_FAIL("%s at %s:%ld\n\tvalues: 0x%lx, 0x%lx; 0x%lx, stage: %u", + (const char *)uc.args[0], __FILE__, uc.args[1], + uc.args[2], uc.args[3], uc.args[4], stage); + break; + default: + TEST_FAIL("Unexpected guest exit\n"); + } + } + + kvm_vm_free(vm); +} + +int main(void) +{ + setbuf(stdout, NULL); + + test_run(); + return 0; +} From patchwork Thu Feb 24 17:25:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12759080 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 BDAB5C433F5 for ; Thu, 24 Feb 2022 17:33:04 +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: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=TM7+T5iYaqet2NwtNxm9A/H3jF9wmW5yF+BOk+zrZS8=; b=kWlFseWAsXvXLxNMCZuXWFQeWz vBl1IDsCGpYkZlR/qPNwUEBhoT9FzvNz+ouW9BRo0CnGmGGeLYHhV40fJJIdytfMQdHZrrLAjzXNC JFsLeDxStiKY31Wr8CDjEWGlMj4Dq4STKvb1ofVFPljtVEmcW80398kdrg2sBtQ0vxbIhQWB6/lWC AcOwUJcCceqMee/o6MicNz8IK9OqiPRyd8S+wCEFoj99ivq2YNhyzC1mex3tJYW6k7HBTJQWXCdYe IDphyHPa6oVj3H8z6a1i2lgL4Do7TDMmRLb0n3rbEBt3WKJJwW+UCBGShwqCdFH4NJQcJJSeLSgCv X38bPJog==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHxn-001oYu-72; Thu, 24 Feb 2022 17:31:35 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHsy-001mJe-P3 for linux-arm-kernel@lists.infradead.org; Thu, 24 Feb 2022 17:26:38 +0000 Received: by mail-pj1-x104a.google.com with SMTP id t7-20020a17090a3b4700b001bc366c58faso3924685pjf.4 for ; Thu, 24 Feb 2022 09:26:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=jmsF+28/o9uCf/VQ6k2qhkTuRm6SZhX9vjCTItav4Nc=; b=MlN/UYTncICeUsEkBDYqjV04VlUXrjRCma8eYvTC2n4PabVyNlEk1LltoOc1rlbsP5 BHwzTVQ0bQZgdqeFundXtet8O11tqSXdKmPvZbIYLXBL4MIStxKmsZImBmhLDRHyd9iP 1zX0cIBwW73iTjZNiwjKfzYpr54Js+FLQ1vYuNh2gwffgJAyV1xpp2KAPiuOFZlMQ057 X4dRf+jgoWGJTRdUWs7JthKJ9/YyXBuTdzWk6M/WKJw5dbEPLL2aShI6mjqHgWmaraNq RIB/mb6ecYxcpgdPaPcaT0j+eAXnz05OF+R9x5kVVeWEQ7R4G70Yoz6ESki6j1zEtlfP GMOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=jmsF+28/o9uCf/VQ6k2qhkTuRm6SZhX9vjCTItav4Nc=; b=I/LD2f9BEpvF8iMpzs6w64fQAP00z1PO5ZrPP1b2v4scZQvyIh+XlAsEbLhehpJckF MBaYQHwt8CJrBPAzMX2ypENYP5yEXKaX4hn3vvw3alx1pgI+SF3bJ7de2mjQtCcjex2e rjjyzOdJ9Fgybh8EFGmKQBdwuXfOmPDCSsKuWQbBxbNbjCjX31rgAWk0lyKjx9RS6skZ j3mgcfcBGKqlIc8emmg2MeIxUyNSASUIwOXzrPDo+kboUpZCY/M4yGyMlZoTBhT/Nj2l M53JOUvytlWzTHf+UFeajfH4uaAVNJkD2Bb/gLLQ9h9m2o2/QahdQC6fWsvLIQ7A94PA jApA== X-Gm-Message-State: AOAM531c9WzjLjhB2mqLxEvzPieonrhExBLTSAcqejP8M02lhdG1dDjs WfsaVXikVWJL6jsfIppnprboqomiX9l+ X-Google-Smtp-Source: ABdhPJydh3IBl9/WqQAefokxf+CHH33yyX7uFA4vfoZVHfdfqGbdHQgTzulUJSpoukHYPflZqQVnV5VDQyf+ X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a17:90b:3ec2:b0:1b9:fbeb:942b with SMTP id rm2-20020a17090b3ec200b001b9fbeb942bmr15311322pjb.55.1645723595262; Thu, 24 Feb 2022 09:26:35 -0800 (PST) Date: Thu, 24 Feb 2022 17:25:58 +0000 In-Reply-To: <20220224172559.4170192-1-rananta@google.com> Message-Id: <20220224172559.4170192-13-rananta@google.com> Mime-Version: 1.0 References: <20220224172559.4170192-1-rananta@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v4 12/13] selftests: KVM: aarch64: hypercalls: Test with KVM_CAP_ARM_REG_SCOPE From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220224_092636_872801_F02CFBFE X-CRM114-Status: GOOD ( 17.89 ) 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 Upgrade the aarch64/hypercalls test to also consider the firmware register's scope information. Thus, run the test with the capability KVM_CAP_ARM_REG_SCOPE disabled and enabled. Signed-off-by: Raghavendra Rao Ananta --- .../selftests/kvm/aarch64/hypercalls.c | 83 +++++++++++++++++-- 1 file changed, 75 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/kvm/aarch64/hypercalls.c b/tools/testing/selftests/kvm/aarch64/hypercalls.c index e4e3a286ff3e..85818b91b4fb 100644 --- a/tools/testing/selftests/kvm/aarch64/hypercalls.c +++ b/tools/testing/selftests/kvm/aarch64/hypercalls.c @@ -29,7 +29,7 @@ struct kvm_fw_reg_info { .max_feat_bit = bit_max, \ } -static const struct kvm_fw_reg_info fw_reg_info[] = { +static struct kvm_fw_reg_info fw_reg_info[] = { FW_REG_INFO(KVM_REG_ARM_STD_BMAP, KVM_REG_ARM_STD_BMAP_BIT_MAX), FW_REG_INFO(KVM_REG_ARM_STD_HYP_BMAP, KVM_REG_ARM_STD_HYP_BMAP_BIT_MAX), FW_REG_INFO(KVM_REG_ARM_VENDOR_HYP_BMAP, KVM_REG_ARM_VENDOR_HYP_BMAP_BIT_MAX), @@ -294,19 +294,78 @@ static void test_fw_regs_after_vm_start(struct kvm_vm *vm) } } -static struct kvm_vm *test_vm_create(void) +static bool test_reg_is_bmap_fw_reg(uint64_t reg) +{ + if ((reg & KVM_REG_ARM_COPROC_MASK) == KVM_REG_ARM_FW && + (reg & 0xffff) >= 0xff00) /* Bitmap firmware register space */ + return true; + + return false; +} + +static void test_fw_regs_encode_vm_scope(void) +{ + int i; + + /* + * Encode the scope as KVM_REG_ARM_SCOPE_VM for further use + * in KVM_SET_ONE_REG and KVM_GET_ONE_REG operations. + */ + for (i = 0; i < ARRAY_SIZE(fw_reg_info); i++) + fw_reg_info[i].reg |= (KVM_REG_ARM_SCOPE_VM << KVM_REG_ARM_SCOPE_SHIFT); +} + +static void test_validate_fw_regs(struct kvm_vm *vm, int scope) +{ + uint64_t i, reg; + int obtained_scope; + struct kvm_reg_list *reg_list; + + reg_list = vcpu_get_reg_list(vm, 0); + + for (i = 0; i < reg_list->n; i++) { + reg = reg_list->reg[i]; + if (!test_reg_is_bmap_fw_reg(reg)) + continue; + + /* + * Depending on KVM_CAP_ARM_REG_SCOPE, currently all the firmware + * bitmap registers are either completely VM-scoped or vCPU scoped. + */ + obtained_scope = (reg & KVM_REG_ARM_SCOPE_MASK) >> KVM_REG_ARM_SCOPE_SHIFT; + TEST_ASSERT(obtained_scope == scope, + "Incorrect scope detected for reg: %lx. Expected: %d; Obtained: %d\n", + reg, scope, obtained_scope); + } +} + +static struct kvm_vm *test_vm_create(int scope) { struct kvm_vm *vm; + struct kvm_enable_cap reg_scope_cap = { + .cap = KVM_CAP_ARM_REG_SCOPE, + }; + + if (scope == KVM_REG_ARM_SCOPE_VM && !kvm_check_cap(KVM_CAP_ARM_REG_SCOPE)) { + print_skip("Capability KVM_CAP_ARM_REG_SCOPE unavailable\n"); + return NULL; + } vm = vm_create_default(0, 0, guest_code); ucall_init(vm, NULL); steal_time_init(vm); + if (scope == KVM_REG_ARM_SCOPE_VM) { + vm_enable_cap(vm, ®_scope_cap); + test_fw_regs_encode_vm_scope(); + } + return vm; } -static struct kvm_vm *test_guest_stage(struct kvm_vm *vm) +static struct kvm_vm * +test_guest_stage(struct kvm_vm *vm, int scope) { struct kvm_vm *ret_vm = vm; @@ -319,7 +378,7 @@ static struct kvm_vm *test_guest_stage(struct kvm_vm *vm) case TEST_STAGE_HVC_IFACE_FEAT_DISABLED: /* Start a new VM so that all the features are now enabled by default */ kvm_vm_free(vm); - ret_vm = test_vm_create(); + ret_vm = test_vm_create(scope); break; case TEST_STAGE_HVC_IFACE_FEAT_ENABLED: case TEST_STAGE_HVC_IFACE_FALSE_INFO: @@ -334,14 +393,20 @@ static struct kvm_vm *test_guest_stage(struct kvm_vm *vm) return ret_vm; } -static void test_run(void) +static void test_run(int scope) { struct kvm_vm *vm; struct ucall uc; bool guest_done = false; - vm = test_vm_create(); + vm = test_vm_create(scope); + if (!vm) + return; + stage = TEST_STAGE_REG_IFACE; + sync_global_to_guest(vm, stage); + + test_validate_fw_regs(vm, scope); test_fw_regs_before_vm_start(vm); while (!guest_done) { @@ -349,7 +414,7 @@ static void test_run(void) switch (get_ucall(vm, 0, &uc)) { case UCALL_SYNC: - vm = test_guest_stage(vm); + vm = test_guest_stage(vm, scope); break; case UCALL_DONE: guest_done = true; @@ -371,6 +436,8 @@ int main(void) { setbuf(stdout, NULL); - test_run(); + test_run(KVM_REG_ARM_SCOPE_VCPU); + test_run(KVM_REG_ARM_SCOPE_VM); + return 0; } From patchwork Thu Feb 24 17:25:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raghavendra Rao Ananta X-Patchwork-Id: 12759084 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 0E64FC433F5 for ; Thu, 24 Feb 2022 17:34:08 +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: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=Gu6s09zoMo6hrNWiqVqjrZsaL6jaTnJm/QAl0u3kaMo=; b=QFUgt3EKRf0ZBLc6cgr+D1DZI1 WlSBfi80OTF8ey9Rd/c5D4rI1IbuirVALXU2jsW/+NVds5uUiBNNb6dW6cu+E04vEYRNkFXkFFyu/ p/YQGfvZHwjkEX1z+KltMY3a8VCOuo3KotDsktQXd3x/dBVd8m+Pm1Zy5Pe7lc1WBMyO817S3mriN tv1AiTZMDrdp+9wOnlJlJWxP60VxJeXS4aNepfZpHGdD2/ZkLuJdGmtW1cneewOtEckXUQ2Zoj+7h i7RiHAhzDV2AI/8LEW6ivUEzVGNloXpm2FrzqqWAsavysT2RPTivEL8FLrhiK3Jo9+upGby3rgSI3 ijhaJBNw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHyR-001ook-AI; Thu, 24 Feb 2022 17:32:15 +0000 Received: from mail-pj1-x104a.google.com ([2607:f8b0:4864:20::104a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nNHt0-001mKP-VL for linux-arm-kernel@lists.infradead.org; Thu, 24 Feb 2022 17:26:40 +0000 Received: by mail-pj1-x104a.google.com with SMTP id t12-20020a17090abc4c00b001bc770db571so1614246pjv.5 for ; Thu, 24 Feb 2022 09:26:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=qK1DQfY/agZG+Ude+bPzbHAaaA6lFwTTxSo+9IjwCXY=; b=TPsbqKhxmc0T+PxetBwAhdG6CCG7ROWrKmUGN3BsssTeSIgoXUOQnngTK58e76sGaV 3u/siqCCo3eM5DO0OYSsT4wYCrRT+O8kY+a4+AnYqBHGb0Rj5B7cI0Hp7dOYnMvbxAD8 RoAw7AYWgYK31cWIx7Yp8Ht4bfU+zuvlAoRR0OqLqR3iivh7tqnsNUSy8KpcavPHrnPn cHFxdJp1nmX7PTiWQDXtuL0nBeCqePhweoxs03ebVOn+oECM3dk8KZwiP6X63bDShGe/ UcGW8KmUCjDJRi9tzyMH1ow70Y2j+cGCEuvyTbgcVe9mx5/NjKgrxZVEBbSazCAcGvGj 1GHw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=qK1DQfY/agZG+Ude+bPzbHAaaA6lFwTTxSo+9IjwCXY=; b=kNzn8IWzPwwBucikl4L+Kc1oRLKvhClm2DeSnza7gZYla0Biee8uQ6f461iyo8Su2u jMDvJgkQ72Hck2da98XYgDavfGUoxvVnOLTQ1D67ifaLjSDRnxFPjR8ppGmXk30Bad5V HNOjHANBEzAP4doEdHXsz2o9oo+aNfZ6ASKSY4LuKDTmMSVI9bC6MMT5RogmCkeufbh4 Pp5VIWNsSF/4GSl9C/wGIZ7KBbPYn1TVezz+Ciogp49R2Q/C9zFIdImFbEymjUwxPQl8 4/0cE3EQzH/nFLGuqbbo1Ru6Lh9LqA+vQV3IDdAoB4f38fW+jfJc8HeVcgL8hSgeUPW0 HQEA== X-Gm-Message-State: AOAM531HfJ1V3rqccH0SVxTYD9ftwvQIa0BEy0pZlODsvP8suLwlUy71 p9DrDE4VpTtvQEY3Uu8RPT1PigYzLyI7 X-Google-Smtp-Source: ABdhPJwU+prJ7BpJEtXxJA5crkhbYqb6Kqs4m4pINVmy8BqVqC8ntCResa6F6puuaRPR78ifpJ3Lzgoe5HTq X-Received: from rananta-virt.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:1bcc]) (user=rananta job=sendgmr) by 2002:a05:6a00:248c:b0:4ce:1932:80dd with SMTP id c12-20020a056a00248c00b004ce193280ddmr3851504pfv.48.1645723597604; Thu, 24 Feb 2022 09:26:37 -0800 (PST) Date: Thu, 24 Feb 2022 17:25:59 +0000 In-Reply-To: <20220224172559.4170192-1-rananta@google.com> Message-Id: <20220224172559.4170192-14-rananta@google.com> Mime-Version: 1.0 References: <20220224172559.4170192-1-rananta@google.com> X-Mailer: git-send-email 2.35.1.574.g5d30c73bfb-goog Subject: [PATCH v4 13/13] selftests: KVM: aarch64: Add the bitmap firmware registers to get-reg-list From: Raghavendra Rao Ananta To: Marc Zyngier , Andrew Jones , James Morse , Alexandru Elisei , Suzuki K Poulose Cc: Paolo Bonzini , Catalin Marinas , Will Deacon , Peter Shier , Ricardo Koller , Oliver Upton , Reiji Watanabe , Jing Zhang , Raghavendra Rao Anata , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, kvm@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220224_092639_102570_57D8F9B0 X-CRM114-Status: UNSURE ( 8.23 ) X-CRM114-Notice: Please train this message. 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 Add the psuedo-firmware registers KVM_REG_ARM_STD_BMAP, KVM_REG_ARM_STD_HYP_BMAP, and KVM_REG_ARM_VENDOR_HYP_BMAP to the base_regs[] list. Signed-off-by: Raghavendra Rao Ananta Reviewed-by: Oliver Upton --- tools/testing/selftests/kvm/aarch64/get-reg-list.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/testing/selftests/kvm/aarch64/get-reg-list.c b/tools/testing/selftests/kvm/aarch64/get-reg-list.c index f769fc6cd927..42e613a7bb6a 100644 --- a/tools/testing/selftests/kvm/aarch64/get-reg-list.c +++ b/tools/testing/selftests/kvm/aarch64/get-reg-list.c @@ -686,6 +686,9 @@ static __u64 base_regs[] = { KVM_REG_ARM_FW_REG(0), KVM_REG_ARM_FW_REG(1), KVM_REG_ARM_FW_REG(2), + KVM_REG_ARM_FW_BMAP_REG(0), /* KVM_REG_ARM_STD_BMAP */ + KVM_REG_ARM_FW_BMAP_REG(1), /* KVM_REG_ARM_STD_HYP_BMAP */ + KVM_REG_ARM_FW_BMAP_REG(2), /* KVM_REG_ARM_VENDOR_HYP_BMAP */ ARM64_SYS_REG(3, 3, 14, 3, 1), /* CNTV_CTL_EL0 */ ARM64_SYS_REG(3, 3, 14, 3, 2), /* CNTV_CVAL_EL0 */ ARM64_SYS_REG(3, 3, 14, 0, 2),