kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Andrew Jones <drjones@redhat.com>
Cc: Oliver Upton <oupton@google.com>,
	kvmarm@lists.cs.columbia.edu, pshier@google.com,
	ricarkol@google.com, rananta@google.com, reijiw@google.com,
	jingzhangos@google.com, kvm@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org, james.morse@arm.com,
	Alexandru.Elisei@arm.com, suzuki.poulose@arm.com,
	Peter Maydell <peter.maydell@linaro.org>
Subject: Re: KVM/arm64: Guest ABI changes do not appear rollback-safe
Date: Thu, 26 Aug 2021 10:43:45 +0100	[thread overview]
Message-ID: <874kbcpmlq.wl-maz@kernel.org> (raw)
In-Reply-To: <20210826085429.b67fzkshhl3s2vfr@gator.home>

On Thu, 26 Aug 2021 09:54:29 +0100,
Andrew Jones <drjones@redhat.com> wrote:

[...]

> I see Marc just replied stating we'll probably just have a single
> register. The KVM_GET_SUPPORTED_CPUID type of ioctl would be
> overkill in that case (get-one_reg is enough). Anyway it can
> always be added later if we expand into more registers.

Here's what I propose for the KVM-specific hypercalls. Compile tested
only, plenty of nits to sort out. But you'll get the general idea.
Something similar could be implemented for ARM-architected hypercalls
such as TRNG.

	M.

diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h
index f8be56d5342b..3fcca7cc9668 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;
+
+	/* Bitmap of enabled hypercalls */
+	unsigned long hc_bmap;
 };
 
 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..8d7a1a93f12c 100644
--- a/arch/arm64/include/uapi/asm/kvm.h
+++ b/arch/arm64/include/uapi/asm/kvm.h
@@ -281,6 +281,9 @@ 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)
 
+#define KVM_REG_ARM_KVM_SPECIFIC_HYPERCALLS_0	KVM_REG_ARM_FW_REG(3)
+#define KVM_REG_ARM_KVM_SPECIFIC_HYPERCALLS_1	KVM_REG_ARM_FW_REG(4)
+
 /* 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 fe102cd2e518..dbc136675b02 100644
--- a/arch/arm64/kvm/arm.c
+++ b/arch/arm64/kvm/arm.c
@@ -130,6 +130,13 @@ static void set_default_spectre(struct kvm *kvm)
 		kvm->arch.pfr0_csv3 = 1;
 }
 
+
+static void set_default_vendor_hypercalls(struct kvm *kvm)
+{
+	kvm->arch.hc_bmap = (BIT(ARM_SMCCC_KVM_FUNC_FEATURES) |
+			     BIT(ARM_SMCCC_KVM_FUNC_PTP));
+}
+
 /**
  * kvm_arch_init_vm - initializes a VM data structure
  * @kvm:	pointer to the KVM struct
@@ -156,6 +163,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);
+	set_default_vendor_hypercalls(kvm);
 
 	return ret;
 out_free_stage2_pgd:
diff --git a/arch/arm64/kvm/hypercalls.c b/arch/arm64/kvm/hypercalls.c
index 30da78f72b3b..11f79e790f7d 100644
--- a/arch/arm64/kvm/hypercalls.c
+++ b/arch/arm64/kvm/hypercalls.c
@@ -127,8 +127,7 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu)
 		val[3] = ARM_SMCCC_VENDOR_HYP_UID_KVM_REG_3;
 		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);
+		val[0] = vcpu->kvm->arch.hc_bmap;
 		break;
 	case ARM_SMCCC_VENDOR_HYP_KVM_PTP_FUNC_ID:
 		kvm_ptp_get_time(vcpu, val);
diff --git a/arch/arm64/kvm/psci.c b/arch/arm64/kvm/psci.c
index 74c47d420253..ceef0c706d50 100644
--- a/arch/arm64/kvm/psci.c
+++ b/arch/arm64/kvm/psci.c
@@ -404,21 +404,26 @@ int kvm_psci_call(struct kvm_vcpu *vcpu)
 	};
 }
 
+static const u64 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_KVM_SPECIFIC_HYPERCALLS_0,
+};
+
 int kvm_arm_get_fw_num_regs(struct kvm_vcpu *vcpu)
 {
-	return 3;		/* PSCI version and two workaround registers */
+	return ARRAY_SIZE(fw_reg_ids);
 }
 
 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;
+	int i;
 
-	if (put_user(KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_2, uindices++))
-		return -EFAULT;
+	for (i = 0; i < ARRAY_SIZE(fw_reg_ids); i++) {
+		if (put_user(fw_reg_ids[i], uindices++))
+			return -EFAULT;
+	}
 
 	return 0;
 }
@@ -477,6 +482,10 @@ 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_KVM_SPECIFIC_HYPERCALLS_0:
+		val = vcpu->kvm->arch.hc_bmap;
+		break;
+	case KVM_REG_ARM_KVM_SPECIFIC_HYPERCALLS_1:
 	default:
 		return -ENOENT;
 	}
@@ -515,8 +524,9 @@ int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 				return -EINVAL;
 			vcpu->kvm->arch.psci_version = val;
 			return 0;
+		default:
+			return -EINVAL;
 		}
-		break;
 	}
 
 	case KVM_REG_ARM_SMCCC_ARCH_WORKAROUND_1:
@@ -563,9 +573,16 @@ int kvm_arm_set_fw_reg(struct kvm_vcpu *vcpu, const struct kvm_one_reg *reg)
 			return -EINVAL;
 
 		return 0;
+	case KVM_REG_ARM_KVM_SPECIFIC_HYPERCALLS_0:
+		/* FIXME: no vcpu should have run */
+		/* Exclude any unknown bit */
+		if (val & ~(BIT(ARM_SMCCC_KVM_FUNC_FEATURES) |
+			    BIT(ARM_SMCCC_KVM_FUNC_PTP)))
+			return -EINVAL;
+		vcpu->kvm->arch.hc_bmap = val;
+		return 0;
+	case KVM_REG_ARM_KVM_SPECIFIC_HYPERCALLS_1:
 	default:
 		return -ENOENT;
 	}
-
-	return -EINVAL;
 }

-- 
Without deviation from the norm, progress is not possible.

      reply	other threads:[~2021-08-26  9:43 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-24 21:15 KVM/arm64: Guest ABI changes do not appear rollback-safe Oliver Upton
2021-08-24 21:34 ` [RFC PATCH] KVM: arm64: Allow VMMs to opt-out of KVM_CAP_PTP_KVM Oliver Upton
2021-08-25  9:27 ` KVM/arm64: Guest ABI changes do not appear rollback-safe Marc Zyngier
2021-08-25 10:02   ` Oliver Upton
2021-08-25 10:39     ` Marc Zyngier
2021-08-25 15:07       ` Andrew Jones
2021-08-25 18:14         ` Oliver Upton
2021-08-26  8:37           ` Marc Zyngier
2021-08-26 18:49             ` Oliver Upton
2021-08-27  7:40               ` Andrew Jones
2021-09-29 18:22                 ` Oliver Upton
2021-09-30  7:32                   ` Marc Zyngier
2021-09-30 17:24                     ` Oliver Upton
2021-10-01 11:43                       ` Marc Zyngier
2021-10-01 15:38                         ` Oliver Upton
2022-01-25  3:47                           ` Raghavendra Rao Ananta
2022-01-25  8:45                             ` Marc Zyngier
2022-01-25 17:29                               ` Oliver Upton
2022-02-08  9:46                                 ` Marc Zyngier
2022-02-08  9:56                                   ` Oliver Upton
2022-02-08 16:58                                     ` Sean Christopherson
2022-02-08 17:48                                       ` Marc Zyngier
2021-08-26  8:49           ` Andrew Jones
2021-08-26  8:54             ` Andrew Jones
2021-08-26  9:43               ` Marc Zyngier [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874kbcpmlq.wl-maz@kernel.org \
    --to=maz@kernel.org \
    --cc=Alexandru.Elisei@arm.com \
    --cc=drjones@redhat.com \
    --cc=james.morse@arm.com \
    --cc=jingzhangos@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=oupton@google.com \
    --cc=peter.maydell@linaro.org \
    --cc=pshier@google.com \
    --cc=rananta@google.com \
    --cc=reijiw@google.com \
    --cc=ricarkol@google.com \
    --cc=suzuki.poulose@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).