Skip to contentSkip to conversation

KVM: arm64: Add pvtime LPT support

RFC PATCH In review Keqian Zhu 5 participants 14 messages Aug 17, 2020 – Sep 7, 2020

Subsystems (6)
Documentation KVM arm64 KVM arm64 +2 more subsystems
lore
Share & tools
lore

Keqian Zhu

author
#0 lore raw

cover KVM: arm64: Add pvtime LPT support

Hi all,

This patch series picks up the LPT pvtime feature originally developed by Steven Price: https://patchwork.kernel.org/cover/10726499/

Backgroud:

There is demand for cross-platform migration, which means we have to solve different CPU features and arch counter frequency between hosts. This patch series can solve the latter problem.

About LPT:

This implements support for Live Physical Time (LPT) which provides the guest with a method to derive a stable counter of time during which the guest is executing even when the guest is being migrated between hosts with different physical counter frequencies.

Changes on Steven Price's work:
1. LPT structure: use symmatical semantics of scale multiplier, and use fraction bits instead of "shift" to make everything clear.
2. Structure allocation: host kernel does not allocates the LPT structure, instead it is allocated by userspace through VM attributes. The save/restore functionality can be removed.
3. Since LPT structure just need update once for each guest run, add a flag to indicate the update status. This has two benifits: 1) avoid multiple update by each vCPUs. 2) If the update flag is not set, then return NOT SUPPORT for coressponding guest HVC call.
4. Add VM device attributes interface for userspace configuration.
5. Add a base LPT read/write layer to reduce code.
6. Support ptimer scaling.
7. Support timer event stream translation.

Things need concern:
1. https://developer.arm.com/docs/den0057/a needs update.
2. If a guest fails to initialize and use LPT, when it migrates to a host with different native frequency, it will see the virtual counter jump. However this concern is not a problem.
1) Guest does not support LPT or host does not enable LPT: we won't migrate guest to a host with different frequency.
2) Guest kernel faces problem when initilize LPT: guest can not boot up, so counter jump is not a problem at this situation.

Patch 2 and 3 implement host KVM part.
Patch 4 and 5 implement guest driver part.

Keqian Zhu (5):
KVM: arm64: Document pvtime LPT interface
KVM: arm64: Support Live Physical Time reporting
KVM: arm64: Provide VM device attributes for LPT time
clocksource: arm_arch_timer: Add pvtime LPT initialization
clocksource: arm_arch_timer: Use pvtime LPT

 Documentation/virt/kvm/arm/pvtime.rst |  78 +++++++++++--
 Documentation/virt/kvm/devices/vm.rst |  30 +++++
 arch/arm64/include/asm/arch_timer.h   | 179 ++++++++++++++++++++++++++--
 arch/arm64/include/asm/kvm_host.h     |  14 +++
 arch/arm64/include/uapi/asm/kvm.h     |   5 +
 arch/arm64/kvm/arm.c                  |  71 ++++++++++++
 arch/arm64/kvm/hypercalls.c           |   5 +
 arch/arm64/kvm/pvtime.c               | 212 +++++++++++++++++++++++++++++++++-
 drivers/clocksource/arm_arch_timer.c  | 120 +++++++++++++++----
 9 files changed, 669 insertions(+), 45 deletions(-)
Signature · 6 lines
1.8.3.1

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#1 lore raw

RFC PATCH 1/5 KVM: arm64: Document pvtime LPT interface

The "Arm Paravirtualized Time for Arm-Base Systems" specification DEN 0057A just contains "Stolen Time" now, as the details of "Live Physical Time" have not been fully agreed.

This introduces a new LPT structure with more understandable fields, as scale_mult and rscale_mult are symmetrical.

---
 Documentation/virt/kvm/arm/pvtime.rst | 78 ++++++++++++++++++++++++++++++-----
 Documentation/virt/kvm/devices/vm.rst | 30 ++++++++++++++
 2 files changed, 97 insertions(+), 11 deletions(-)
Documentation/virt/kvm/arm/pvtime.rst +67 -11
index 94bffe2..fd11915 100644
@@ -8,14 +8,17 @@ support for AArch64 guests:
 
 https://developer.arm.com/docs/den0057/a
 
-KVM/arm64 implements the stolen time part of this specification by providing
-some hypervisor service calls to support a paravirtualized guest obtaining a
-view of the amount of time stolen from its execution.
+KVM/arm64 implements the stolen time and live physical time (LPT) parts of this
+specification by providing some hypervisor service calls to a paravirtualized
+guest. With stolen time support, guest can obtain the amount of time stolen
+from its execution. LPT represents time during which the guest is running and
+it realizes cross-native-frequency migrations.
 
-Two new SMCCC compatible hypercalls are defined:
+Three new SMCCC compatible hypercalls are defined:
 
 * PV_TIME_FEATURES: 0xC5000020
 * PV_TIME_ST:       0xC5000021
+* PV_TIME_LPT:      0xC5000022
 
 These are only available in the SMC64/HVC64 calling convention as
 paravirtualized time is not available to 32 bit Arm guests. The existence of
@@ -26,7 +29,8 @@ PV_TIME_FEATURES
     ============= ========    ==========
     Function ID:  (uint32)    0xC5000020
     PV_call_id:   (uint32)    The function to query for support.
-                              Currently only PV_TIME_ST is supported.
+                              Currently only PV_TIME_ST and PV_TIME_LPT are
+                              supported.
     Return value: (int64)     NOT_SUPPORTED (-1) or SUCCESS (0) if the relevant
                               PV-time feature is supported by the hypervisor.
     ============= ========    ==========
@@ -39,17 +43,23 @@ PV_TIME_ST
                               NOT_SUPPORTED (-1)
     ============= ========    ==========
 
-The IPA returned by PV_TIME_ST should be mapped by the guest as normal memory
-with inner and outer write back caching attributes, in the inner shareable
-domain. A total of 16 bytes from the IPA returned are guaranteed to be
-meaningfully filled by the hypervisor (see structure below).
+PV_TIME_LPT
+    ============= ========    ==========
+    Function ID:  (uint32)    0xC5000022
+    Return value: (int64)     IPA of the LPT data structure for this guest.
+                              On failure:
+                              NOT_SUPPORTED (-1)
+    ============= ========    ==========
 
-PV_TIME_ST returns the structure for the calling VCPU.
+The IPA returned by PV_TIME_ST and PV_TIME_LPT should be mapped by the guest as
+normal memory with inner and outer write back caching attributes, in the inner
+shareable domain.
 
 Stolen Time
 -----------
 
-The structure pointed to by the PV_TIME_ST hypercall is as follows:
+A total of 16 bytes from the IPA returned are guaranteed to be meaningfully
+filled by the hypervisor. The structure description is as follows:
 
 +-------------+-------------+-------------+----------------------------+
 | Field       | Byte Length | Byte Offset | Description                |
@@ -78,3 +88,49 @@ the region using 64k pages and avoids conflicting attributes with other memory.
 
 For the user space interface see Documentation/virt/kvm/devices/vcpu.rst
 section "3. GROUP: KVM_ARM_VCPU_PVTIME_CTRL".
+
+Live Physical Time
+-----------
+
+A total of 48 bytes from the IPA returned are guaranteed to be meaningfully
+filled by the hypervisor. The structure description is as follows:
+
++-----------------+-------------+-------------+----------------------------+
+| Field           | Byte Length | Byte Offset | Description                |
++=================+=============+=============+============================+
+| Revision        |      4      |      0      | Must be 0 for version 1.0  |
++-----------------+-------------+-------------+----------------------------+
+| Attributes      |      4      |      4      | Must be 0                  |
++-----------------+-------------+-------------+----------------------------+
+| sequence_number |      8      |      8      | Bit 0: reserved            |
+|                 |             |             | Bits 1-63: number of runs, |
+|                 |             |             | including the initial run. |
++-----------------+-------------+-------------+----------------------------|
+| native_freq     |      4      |      16     | Native frequency           |
++-----------------+-------------+-------------+----------------------------|
+| pv_freq         |      4      |      20     | Paravirtualized frequency  |
+|                 |             |             | seen by guest              |
++-----------------+-------------+-------------+----------------------------|
+| scale_mult      |      8      |      24     | Multiplier to scale native |
+|                 |             |             | cycles to PV cycles        |
++-----------------+-------------+-------------+----------------------------|
+| rscale_mult     |      8      |      32     | Multiplier to reversely    |
+|                 |             |             | scale PV cycles to native  |
+|                 |             |             | cycles                     |
++-----------------+-------------+-------------+----------------------------|
+| fracbits        |      4      |      40     | The bits of fraction of    |
+|                 |             |             | scale_mult                 |
++-----------------+-------------+-------------+----------------------------|
+| rfracbits       |      4      |      44     | The bits of fraction of    |
+|                 |             |             | rscale_mult                |
++-----------------+-------------+-------------+----------------------------|
+
+All values in the structure are stored little-endian.
+
+The structure will be updated by the hypervisor prior to scheduling VCPUs. It
+will be present within a reserved region of the normal memory given to the
+guest. The guest should not attempt to write into this memory. There is a
+structure per guest.
+
+For the user space interface see Documentation/virt/kvm/devices/vm.rst
+section "6. GROUP: KVM_ARM_VM_PVTIME_LPT_CTRL".
Documentation/virt/kvm/devices/vm.rst +30 -0
index 0aa5b1c..7e5a189 100644
@@ -314,3 +314,33 @@ Allows userspace to query the status of migration mode.
 	     if it is enabled
 :Returns:   -EFAULT if the given address is not accessible from kernel space;
 	    0 in case of success.
+
+6. GROUP: KVM_ARM_VM_PVTIME_LPT_CTRL
+====================================
+
+:Architectures: ARM64
+
+6.1. ATTRIBUTE: KVM_ARM_VM_PVTIME_LPT_IPA (r/w)
+-----------------------------------------------
+
+Specifies the base address of the live physical time (LPT) structure for this
+guest. The base address must be 64 byte aligned and exist within a valid guest
+memory region. See Documentation/virt/kvm/arm/pvtime.rst for more information
+including the layout of the LPT structure.
+
+Parameters: 64-bit base address
+Returns: -ENXIO:  LPT not implemented
+         -EEXIST: Base address already set for this guest
+         -EINVAL: Base address not 64 byte aligned or not within guest memory
+
+6.2. ATTRIBUTE: KVM_ARM_VM_PVTIME_LPT_FREQ (r/w)
+------------------------------------------------
+
+Specifies the paravirtualized (PV) frequency for this guest. The PV frequency
+is independent with native frequency, so we can support cross-native-frequency
+migration.
+
+Parameters: 32-bit PV frequency
+Returns: -ENXIO:  LPT not implemented
+         -EEXIST: PV frequency already set for this guest
+         -EINVAL: PV frequency is zero
Signature · 1 line
1.8.3.1
author
#2 lore raw

RFC PATCH 2/5 KVM: arm64: Support Live Physical Time reporting

In reply to Keqian Zhu

Provide a method for a guest to derive a paravirtualized counter/timer which isn't dependent on the host's counter frequency. This allows a guest to be migrated onto a new host which doesn't have the same frequency without the virtual counter being disturbed.

The host provides a shared structure which contains coefficients that can be used to map the real counter from the host (the Arm "virtual counter") to a paravirtualized view of time. On migration the new host updates the coefficients to ensure that the guests view of time (after using the coefficients) doesn't change and that the derived counter progresses at the same real frequency.

---
 arch/arm64/include/asm/kvm_host.h |  10 +++
 arch/arm64/kvm/arm.c              |   7 +++
 arch/arm64/kvm/hypercalls.c       |   5 ++
 arch/arm64/kvm/pvtime.c           | 125 +++++++++++++++++++++++++++++++++++++-
 4 files changed, 146 insertions(+), 1 deletion(-)
arch/arm64/include/asm/kvm_host.h +10 -0
index e21d4a0..0c6a564 100644
@@ -95,6 +95,13 @@ struct kvm_arch {
 	 * supported.
 	 */
 	bool return_nisv_io_abort_to_user;
+
+	/* Guest PV Live Physical Time state */
+	struct {
+		u32 fpv; /* PV frequency */
+		gpa_t base; /* Base IPA of shared structure */
+		bool updated; /* Indicate whether it is updated by KVM */
+	} lpt;
 };
 
 #define KVM_NR_MEM_OBJS     40
@@ -506,6 +513,9 @@ int io_mem_abort(struct kvm_vcpu *vcpu, struct kvm_run *run,
 gpa_t kvm_init_stolen_time(struct kvm_vcpu *vcpu);
 void kvm_update_stolen_time(struct kvm_vcpu *vcpu);
 
+gpa_t kvm_init_lpt_time(struct kvm *kvm);
+int kvm_update_lpt_time(struct kvm *kvm);
+
 int kvm_arm_pvtime_set_attr(struct kvm_vcpu *vcpu,
 			    struct kvm_device_attr *attr);
 int kvm_arm_pvtime_get_attr(struct kvm_vcpu *vcpu,
arch/arm64/kvm/arm.c +7 -0
index 90cb905..671f1461 100644
@@ -135,6 +135,9 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
 	/* The maximum number of VCPUs is limited by the host's GIC model */
 	kvm->arch.max_vcpus = kvm_arm_default_max_vcpus();
 
+	/* Should be setup by userspace before guest run */
+	kvm->arch.lpt.base = GPA_INVALID;
+
 	return ret;
 out_free_stage2_pgd:
 	kvm_free_stage2_pgd(kvm);
@@ -528,6 +531,10 @@ static int kvm_vcpu_first_run_init(struct kvm_vcpu *vcpu)
 
 	vcpu->arch.has_run_once = true;
 
+	ret = kvm_update_lpt_time(kvm);
+	if (ret)
+		return ret;
+
 	if (likely(irqchip_in_kernel(kvm))) {
 		/*
 		 * Map the VGIC hardware resources before running a vcpu the
arch/arm64/kvm/hypercalls.c +5 -0
index 550dfa3..254491b 100644
@@ -62,6 +62,11 @@ int kvm_hvc_call_handler(struct kvm_vcpu *vcpu)
 		if (gpa != GPA_INVALID)
 			val = gpa;
 		break;
+	case ARM_SMCCC_HV_PV_TIME_LPT:
+		gpa = kvm_init_lpt_time(vcpu->kvm);
+		if (gpa != GPA_INVALID)
+			val = gpa;
+		break;
 	default:
 		return kvm_psci_call(vcpu);
 	}
arch/arm64/kvm/pvtime.c +124 -1

134 lines not on this page · raw message

Signature · 6 lines
1.8.3.1

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#3 lore raw

RFC PATCH 3/5 KVM: arm64: Provide VM device attributes for LPT time

In reply to Keqian Zhu

Allow user space to inform the KVM host what the PV frequency is and where in the physical memory map the paravirtualized LPT time structures should be located. User space can set attributes on the VM for that guest.

The address is given in terms of the physical address visible to the guest and must be 64 byte aligned. The guest will discover the address via a hypercall. PV frequency is 32 bits and must not be 0.

---
 arch/arm64/include/asm/kvm_host.h |  4 ++
 arch/arm64/include/uapi/asm/kvm.h |  5 +++
 arch/arm64/kvm/arm.c              | 64 ++++++++++++++++++++++++++++
 arch/arm64/kvm/pvtime.c           | 87 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 160 insertions(+)
arch/arm64/include/asm/kvm_host.h +4 -0
index 0c6a564..cbe330c 100644
@@ -523,6 +523,10 @@ int kvm_arm_pvtime_get_attr(struct kvm_vcpu *vcpu,
 int kvm_arm_pvtime_has_attr(struct kvm_vcpu *vcpu,
 			    struct kvm_device_attr *attr);
 
+int kvm_arm_pvtime_lpt_set_attr(struct kvm *kvm, struct kvm_device_attr *attr);
+int kvm_arm_pvtime_lpt_get_attr(struct kvm *kvm, struct kvm_device_attr *attr);
+int kvm_arm_pvtime_lpt_has_attr(struct kvm *kvm, struct kvm_device_attr *attr);
+
 static inline void kvm_arm_pvtime_vcpu_init(struct kvm_vcpu_arch *vcpu_arch)
 {
 	vcpu_arch->steal.base = GPA_INVALID;
arch/arm64/include/uapi/asm/kvm.h +5 -0
index ba85bb2..7b045c7 100644
@@ -325,6 +325,11 @@ struct kvm_vcpu_events {
 #define   KVM_DEV_ARM_VGIC_SAVE_PENDING_TABLES	3
 #define   KVM_DEV_ARM_ITS_CTRL_RESET		4
 
+/* Device Control API on kvm fd */
+#define KVM_ARM_VM_PVTIME_LPT_CTRL	0
+#define   KVM_ARM_VM_PVTIME_LPT_IPA	0
+#define   KVM_ARM_VM_PVTIME_LPT_FREQ	1
+
 /* Device Control API on vcpu fd */
 #define KVM_ARM_VCPU_PMU_V3_CTRL	0
 #define   KVM_ARM_VCPU_PMU_V3_IRQ	0
arch/arm64/kvm/arm.c +64 -0

81 lines not on this page · raw message

arch/arm64/kvm/pvtime.c +87 -0

90 lines not on this page · raw message

Signature · 6 lines
1.8.3.1

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#4 lore raw

RFC PATCH 4/5 clocksource: arm_arch_timer: Add pvtime LPT initialization

In reply to Keqian Zhu

Enable paravirtualized time to be used in a KVM guest if the host supports it. This allows the guest to derive a counter which is clocked at a persistent rate even when the guest is migrated.

If we discover that the system supports SMCCC v1.1 then we probe to determine whether the hypervisor supports paravirtualized features and finally whether it supports "Live Physical Time" reporting. If so a shared structure is made available to the guest containing coefficients to calculate the derived clock.

---
 drivers/clocksource/arm_arch_timer.c | 69 ++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
drivers/clocksource/arm_arch_timer.c +69 -0
index 6c3e841..eb2e57a 100644
@@ -26,6 +26,7 @@
 #include <linux/acpi.h>
 
 #include <asm/arch_timer.h>
+#include <asm/pvclock-abi.h>
 #include <asm/virt.h>
 
 #include <clocksource/arm_arch_timer.h>
@@ -84,6 +85,66 @@ static int __init early_evtstrm_cfg(char *buf)
 }
 early_param("clocksource.arm_arch_timer.evtstrm", early_evtstrm_cfg);
 
+/* PV-time LPT */
+#ifdef CONFIG_ARM64
+struct pvclock_vm_lpt_time *lpt_info;
+EXPORT_SYMBOL_GPL(lpt_info);
+DEFINE_STATIC_KEY_FALSE(pvclock_lpt_key_enabled);
+EXPORT_SYMBOL_GPL(pvclock_lpt_key_enabled);
+
+static bool has_pv_lpt_clock(void)
+{
+	struct arm_smccc_res res;
+
+	if (arm_smccc_1_1_get_conduit() == SMCCC_CONDUIT_NONE)
+		return false;
+
+	arm_smccc_1_1_invoke(ARM_SMCCC_ARCH_FEATURES_FUNC_ID,
+			   ARM_SMCCC_HV_PV_TIME_FEATURES, &res);
+	if (res.a0 != SMCCC_RET_SUCCESS)
+		return false;
+
+	arm_smccc_1_1_invoke(ARM_SMCCC_HV_PV_TIME_FEATURES,
+			     ARM_SMCCC_HV_PV_TIME_LPT, &res);
+	return res.a0 == SMCCC_RET_SUCCESS;
+}
+
+static int pvclock_lpt_init(void)
+{
+	struct arm_smccc_res res;
+
+	if (!has_pv_lpt_clock())
+		return 0;
+
+	arm_smccc_1_1_invoke(ARM_SMCCC_HV_PV_TIME_LPT, 0, &res);
+	if (res.a0 == SMCCC_RET_NOT_SUPPORTED)
+		return 0;
+
+	lpt_info = memremap(res.a0, sizeof(*lpt_info), MEMREMAP_WB);
+	if (!lpt_info) {
+		pr_warn("Failed to map pvclock LPT data structure\n");
+		return -EFAULT;
+	}
+
+	if (le32_to_cpu(lpt_info->revision) != 0 ||
+	    le32_to_cpu(lpt_info->attributes) != 0) {
+		pr_warn_once("Unexpected revision or attributes "
+			     "in pvclock LPT data structure\n");
+		return -EFAULT;
+	}
+
+	static_branch_enable(&pvclock_lpt_key_enabled);
+	pr_info("Using pvclock LPT\n");
+	return 0;
+}
+#else /* CONFIG_ARM64 */
+static int pvclock_lpt_init(void)
+{
+	return 0;
+}
+#endif /* CONFIG_ARM64 */
+
+
 /*
  * Architected system timer support.
  */
@@ -1285,6 +1346,10 @@ static int __init arch_timer_of_init(struct device_node *np)
 
 	arch_timer_populate_kvm_info();
 
+	ret = pvclock_lpt_init();
+	if (ret)
+		return ret;
+
 	rate = arch_timer_get_cntfrq();
 	arch_timer_of_configure_rate(rate, np);
 
@@ -1613,6 +1678,10 @@ static int __init arch_timer_acpi_init(struct acpi_table_header *table)
 
 	arch_timer_populate_kvm_info();
 
+	ret = pvclock_lpt_init();
+	if (ret)
+		return ret;
+
 	/*
 	 * When probing via ACPI, we have no mechanism to override the sysreg
 	 * CNTFRQ value. This *must* be correct.
Signature · 6 lines
1.8.3.1

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
author
#5 lore raw

RFC PATCH 5/5 clocksource: arm_arch_timer: Use pvtime LPT

In reply to Keqian Zhu

Enable paravirtualized time to be used in a KVM guest if the host supports it. This allows the guest to derive a counter which is clocked at a persistent rate even when the guest is migrated.

If we discover that the system supports SMCCC v1.1 then we probe to determine whether the hypervisor supports paravirtualized features and finally whether it supports "Live Physical Time" reporting. If so a shared structure is made available to the guest containing coefficients to calculate the derived clock.

The guest kernel uses the coefficients to present a clock to user space that is always clocked at the same rate whenever the guest is running ('live'), even if the physical clock changes (due to the guest being migrated).

The existing workaround framework for CNTVCT is used to trap user space accesses to the timer registers so we can present the derived clock.

---
 arch/arm64/include/asm/arch_timer.h  | 179 ++++++++++++++++++++++++++++++++---
 drivers/clocksource/arm_arch_timer.c |  59 +++++++-----
 2 files changed, 204 insertions(+), 34 deletions(-)
arch/arm64/include/asm/arch_timer.h +168 -11
index 9f0ec21..bbaecf1 100644
@@ -10,6 +10,7 @@
 
 #include <asm/barrier.h>
 #include <asm/hwcap.h>
+#include <asm/pvclock-abi.h>
 #include <asm/sysreg.h>
 
 #include <linux/bug.h>
@@ -64,25 +65,178 @@ struct arch_timer_erratum_workaround {
 DECLARE_PER_CPU(const struct arch_timer_erratum_workaround *,
 		timer_unstable_counter_workaround);
 
+
+extern struct pvclock_vm_lpt_time *lpt_info;
+DECLARE_STATIC_KEY_FALSE(pvclock_lpt_key_enabled);
+
+/* LPT read/write base layer */
+
+#define lpt_read_base(target, trans, read) ({				\
+	__le64 _seq_begin, _seq_end;					\
+	u64 _nval, _pval;						\
+									\
+	do {								\
+		_seq_begin = READ_ONCE(lpt_info->sequence_number);	\
+		/* LPT structure can be treated as readonly device */	\
+		rmb();							\
+									\
+		_nval = read(target);					\
+		_pval = trans(_nval);					\
+									\
+		rmb();							\
+		_seq_end = READ_ONCE(lpt_info->sequence_number);	\
+	} while (unlikely(_seq_begin != _seq_end));			\
+									\
+	_pval;								\
+})
+
+#define lpt_write_base(val, target, trans, write) ({			\
+	__le64 _seq_begin, _seq_end;					\
+	u64 _pval = val;						\
+	u64 _nval;							\
+									\
+	do {								\
+		_seq_begin = READ_ONCE(lpt_info->sequence_number);	\
+		/* LPT structure can be treated as readonly device */	\
+		rmb();							\
+									\
+		_nval = trans(_pval);					\
+		write(_nval, target);					\
+									\
+		rmb();							\
+		_seq_end = READ_ONCE(lpt_info->sequence_number);	\
+	} while (unlikely(_seq_begin != _seq_end));			\
+})
+
+#define lpt_read(target, trans, read) ({				\
+	u64 _val;							\
+									\
+	if (static_branch_unlikely(&pvclock_lpt_key_enabled)) {		\
+		_val = lpt_read_base(target, trans, read);		\
+	} else {							\
+		_val = read(target);					\
+	}								\
+									\
+	_val;								\
+})
+
+#define lpt_write(val, target, trans, write) ({				\
+	if (static_branch_unlikely(&pvclock_lpt_key_enabled)) {		\
+		lpt_write_base(val, target, trans, write);		\
+	} else {							\
+		write(val, target);					\
+	}								\
+})
+
+/* LPT read/write layer for timer and count */
+
+static inline u64 native_to_pv_cycles(u64 cnt)
+{
+	u64 scale_mult = le64_to_cpu(lpt_info->scale_mult);
+	u32 fracbits = le32_to_cpu(lpt_info->fracbits);
+
+	return mul_u64_u64_shr(scale_mult, cnt, fracbits);
+}
+
+static inline u64 pv_to_native_cycles(u64 cnt)
+{
+	u64 rscale_mult = le64_to_cpu(lpt_info->rscale_mult);
+	u32 rfracbits = le32_to_cpu(lpt_info->rfracbits);
+
+	return mul_u64_u64_shr(rscale_mult, cnt, rfracbits);
+}
+
+#define arch_timer_read_mediated(reg) ({				\
+	lpt_read(reg, native_to_pv_cycles, read_sysreg);		\
+})
+
+#define arch_timer_write_mediated(val, reg) ({				\
+	u64 _val = val;							\
+	lpt_write(_val, reg, pv_to_native_cycles, write_sysreg);	\
+})
+
+#define mem_timer_read_mediated(addr) ({				\
+	lpt_read(addr, native_to_pv_cycles, readl_relaxed);		\
+})
+
+#define mem_timer_write_mediated(val, addr) ({				\
+	u64 _val = val;							\
+	lpt_write(_val, addr, pv_to_native_cycles, writel_relaxed);	\
+})
+
+/* LPT read/write layer for cntkctl_el1 */
+
+static inline int cntkctl_evnti_shift(void)
+{
+	u32 native_freq = le32_to_cpu(lpt_info->native_freq);
+	u32 pv_freq = le32_to_cpu(lpt_info->pv_freq);
+	int div, shift;
+
+	if (pv_freq >= native_freq)
+		div = pv_freq / native_freq;
+	else
+		div = native_freq / pv_freq;
+
+	/* Find the closest power of two to the divisor */
+	shift = fls(div);
+	if ((shift == 1) || (shift > 1 && !(shift & (1 << (shift - 2)))))
+		shift--;
+
+	return pv_freq >= native_freq ? shift : -shift;
+}
+
+static inline u64 parse_cntkctl(u64 val, bool native_to_pv)
+{
+	int evnti = (val >> ARCH_TIMER_EVT_TRIGGER_SHIFT) & 0xF;
+
+	if (native_to_pv)
+		evnti = evnti + cntkctl_evnti_shift();
+	else
+		evnti = evnti - cntkctl_evnti_shift();
+
+	evnti = min(15, max(0, evnti));
+	val &= ~ARCH_TIMER_EVT_TRIGGER_MASK;
+	val |= evnti << ARCH_TIMER_EVT_TRIGGER_SHIFT;
+
+	return val;
+}
+
+#define TRANS_CNTKCTL_N(nval) ({					\
+	parse_cntkctl(nval, true);					\
+})
+
+#define TRANS_CNTKCTL_P(pval) ({					\
+	parse_cntkctl(pval, false);					\
+})
+
+#define arch_timer_read_cntkctl_mediated() ({				\
+	lpt_read(cntkctl_el1, TRANS_CNTKCTL_N, read_sysreg);		\
+})
+
+#define arch_timer_write_cntkctl_mediated(val) ({			\
+	u64 _val = val;							\
+	lpt_write(_val, cntkctl_el1, TRANS_CNTKCTL_P, write_sysreg);	\
+})
+
 /* inline sysreg accessors that make erratum_handler() work */
 static inline notrace u32 arch_timer_read_cntp_tval_el0(void)
 {
-	return read_sysreg(cntp_tval_el0);
+	return arch_timer_read_mediated(cntp_tval_el0);
 }
 
 static inline notrace u32 arch_timer_read_cntv_tval_el0(void)
 {
-	return read_sysreg(cntv_tval_el0);
+	return arch_timer_read_mediated(cntv_tval_el0);
 }
 
 static inline notrace u64 arch_timer_read_cntpct_el0(void)
 {
-	return read_sysreg(cntpct_el0);
+	return arch_timer_read_mediated(cntpct_el0);
 }
 
 static inline notrace u64 arch_timer_read_cntvct_el0(void)
 {
-	return read_sysreg(cntvct_el0);
+	return arch_timer_read_mediated(cntvct_el0);
 }
 
 #define arch_timer_reg_read_stable(reg)					\
@@ -110,7 +264,7 @@ void arch_timer_reg_write_cp15(int access, enum arch_timer_reg reg, u32 val)
 			write_sysreg(val, cntp_ctl_el0);
 			break;
 		case ARCH_TIMER_REG_TVAL:
-			write_sysreg(val, cntp_tval_el0);
+			arch_timer_write_mediated(val, cntp_tval_el0);
 			break;
 		}
 	} else if (access == ARCH_TIMER_VIRT_ACCESS) {
@@ -119,7 +273,7 @@ void arch_timer_reg_write_cp15(int access, enum arch_timer_reg reg, u32 val)
 			write_sysreg(val, cntv_ctl_el0);
 			break;
 		case ARCH_TIMER_REG_TVAL:
-			write_sysreg(val, cntv_tval_el0);
+			arch_timer_write_mediated(val, cntv_tval_el0);
 			break;
 		}
 	}
@@ -151,17 +305,20 @@ u32 arch_timer_reg_read_cp15(int access, enum arch_timer_reg reg)
 
 static inline u32 arch_timer_get_cntfrq(void)
 {
-	return read_sysreg(cntfrq_el0);
+	if (static_branch_unlikely(&pvclock_lpt_key_enabled))
+		return le32_to_cpu(lpt_info->pv_freq);
+	else
+		return read_sysreg(cntfrq_el0);
 }
 
 static inline u32 arch_timer_get_cntkctl(void)
 {
-	return read_sysreg(cntkctl_el1);
+	return arch_timer_read_cntkctl_mediated();
 }
 
 static inline void arch_timer_set_cntkctl(u32 cntkctl)
 {
-	write_sysreg(cntkctl, cntkctl_el1);
+	arch_timer_write_cntkctl_mediated(cntkctl);
 	isb();
 }
 
@@ -199,7 +356,7 @@ static __always_inline u64 __arch_counter_get_cntpct(void)
 	u64 cnt;
 
 	isb();
-	cnt = read_sysreg(cntpct_el0);
+	cnt = arch_timer_read_mediated(cntpct_el0);
 	arch_counter_enforce_ordering(cnt);
 	return cnt;
 }
@@ -219,7 +376,7 @@ static __always_inline u64 __arch_counter_get_cntvct(void)
 	u64 cnt;
 
 	isb();
-	cnt = read_sysreg(cntvct_el0);
+	cnt = arch_timer_read_mediated(cntvct_el0);
 	arch_counter_enforce_ordering(cnt);
 	return cnt;
 }
drivers/clocksource/arm_arch_timer.c +36 -23

150 lines not on this page · raw message

Signature · 6 lines
1.8.3.1

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
#6 lore raw

Re: [RFC PATCH 5/5] clocksource: arm_arch_timer: Use pvtime LPT

[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch]

Hi Keqian,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on tip/timers/core]
[also build test ERROR on arm64/for-next/core v5.9-rc1 next-20200817] [cannot apply to kvmarm/next kvm/linux-next]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Keqian-Zhu/KVM-arm64-Add-pvtime-LPT-support/20200817-164436
base:   https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git 0099808553ad4f9c04ad7afd966f6d7f470f247f
config: arm64-randconfig-r005-20200817 (attached as .config)
compiler: aarch64-linux-gcc (GCC) 9.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross ARCH=arm64

If you fix the issue, kindly add following tag as appropriate

All errors (new ones prefixed by >>):

In file included from include/linux/byteorder/little_endian.h:5,

                    from arch/arm64/include/uapi/asm/byteorder.h:23,
                    from include/asm-generic/bitops/le.h:6,
                    from arch/arm64/include/asm/bitops.h:29,
                    from include/linux/bitops.h:29,
                    from include/linux/of.h:15,
                    from include/linux/irqdomain.h:35,
                    from include/linux/acpi.h:13,
                    from include/acpi/apei.h:9,
                    from include/acpi/ghes.h:5,
                    from include/linux/arm_sdei.h:8,
                    from arch/arm64/kernel/asm-offsets.c:10:
   arch/arm64/include/asm/arch_timer.h: In function 'native_to_pv_cycles':
>> arch/arm64/include/asm/arch_timer.h:135:39: error: dereferencing pointer to incomplete type 'struct pvclock_vm_lpt_time'
     135 |  u64 scale_mult = le64_to_cpu(lpt_info->scale_mult);
         |                                       ^~
   include/uapi/linux/byteorder/little_endian.h:32:51: note: in definition of macro '__le64_to_cpu'
      32 | #define __le64_to_cpu(x) ((__force __u64)(__le64)(x))
         |                                                   ^
   arch/arm64/include/asm/arch_timer.h:135:19: note: in expansion of macro 'le64_to_cpu'
     135 |  u64 scale_mult = le64_to_cpu(lpt_info->scale_mult);
         |                   ^~~~~~~~~~~

make[2]: *** [scripts/Makefile.build:114: arch/arm64/kernel/asm-offsets.s] Error 1 make[2]: Target '__build' not remade because of errors.
make[1]: *** [Makefile:1185: prepare0] Error 2
make[1]: Target 'prepare' not remade because of errors.
make: *** [Makefile:185: __sub-make] Error 2
make: Target 'prepare' not remade because of errors.

# https://github.com/0day-ci/linux/commit/47f3527190b7f8b53c7c48c278fc7aecef3ef812
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Keqian-Zhu/KVM-arm64-Add-pvtime-LPT-support/20200817-164436 git checkout 47f3527190b7f8b53c7c48c278fc7aecef3ef812
vim +135 arch/arm64/include/asm/arch_timer.h

132
133 static inline u64 native_to_pv_cycles(u64 cnt)
134 {

 > 135		u64 scale_mult = le64_to_cpu(lpt_info->scale_mult);

136 u32 fracbits = le32_to_cpu(lpt_info->fracbits);
137
138 return mul_u64_u64_shr(scale_mult, cnt, fracbits);
139 }
140

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org

maintainer
#7 lore raw
In reply to Keqian Zhu
Quoted 36 lines · Keqian Zhu

Hi all,

This patch series picks up the LPT pvtime feature originally developed by Steven Price: https://patchwork.kernel.org/cover/10726499/

Backgroud:

There is demand for cross-platform migration, which means we have to solve different CPU features and arch counter frequency between hosts. This patch series can solve the latter problem.

About LPT:

This implements support for Live Physical Time (LPT) which provides the guest with a method to derive a stable counter of time during which the guest is executing even when the guest is being migrated between hosts with different physical counter frequencies.

Changes on Steven Price's work:
1. LPT structure: use symmatical semantics of scale multiplier, and use fraction bits instead of "shift" to make everything clear.
2. Structure allocation: host kernel does not allocates the LPT structure, instead it is allocated by userspace through VM attributes. The
save/restore
functionality can be removed.
3. Since LPT structure just need update once for each guest run, add a flag to indicate the update status. This has two benifits: 1) avoid multiple
update
by each vCPUs. 2) If the update flag is not set, then return NOT
SUPPORT for
coressponding guest HVC call.
4. Add VM device attributes interface for userspace configuration.
5. Add a base LPT read/write layer to reduce code.
6. Support ptimer scaling.
7. Support timer event stream translation.

Quoted 2 lines

Things need concern:
1. https://developer.arm.com/docs/den0057/a needs update.

LPT was explicitly removed from the spec because it doesn't really solve the problem, specially for the firmware: EFI knows nothing about this, for example. How is it going to work? Also, nobody was ever able to explain how this would work for nested virt.

ARMv8.4 and ARMv8.6 have the feature set that is required to solve this problem without adding more PV to the kernel.

        M.
Signature · 5 lines
Jazz is not dead. It just smells funny...
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
#8 lore raw
Quoted 37 lines · Marc Zyngier
Quoted 33 lines · Keqian Zhu

Hi all,

This patch series picks up the LPT pvtime feature originally developed by Steven Price: https://patchwork.kernel.org/cover/10726499/

Backgroud:

There is demand for cross-platform migration, which means we have to solve different CPU features and arch counter frequency between hosts. This patch series can solve the latter problem.

About LPT:

This implements support for Live Physical Time (LPT) which provides the guest with a method to derive a stable counter of time during which the guest is executing even when the guest is being migrated between hosts with different physical counter frequencies.

Changes on Steven Price's work:
1. LPT structure: use symmatical semantics of scale multiplier, and use fraction bits instead of "shift" to make everything clear.
2. Structure allocation: host kernel does not allocates the LPT structure, instead it is allocated by userspace through VM attributes. The save/restore functionality can be removed.
3. Since LPT structure just need update once for each guest run, add a flag to indicate the update status. This has two benifits: 1) avoid multiple update by each vCPUs. 2) If the update flag is not set, then return NOT SUPPORT for coressponding guest HVC call.
4. Add VM device attributes interface for userspace configuration.
5. Add a base LPT read/write layer to reduce code.
6. Support ptimer scaling.
7. Support timer event stream translation.

Quoted 2 lines

Things need concern:
1. https://developer.arm.com/docs/den0057/a needs update.

Quoted 8 lines

LPT was explicitly removed from the spec because it doesn't really solve the problem, specially for the firmware: EFI knows nothing about this, for example. How is it going to work? Also, nobody was ever able to explain how this would work for nested virt.

ARMv8.4 and ARMv8.6 have the feature set that is required to solve this problem without adding more PV to the kernel.

Hi Marc,

These are good points, however we do still have the situation that CPUs that don't have ARMv8.4/8.6 clearly cannot implement this. I presume the use-case Keqian is looking at predates the necessary support in the CPU - Keqian if you can provide more details on the architecture(s) involved that would be helpful.

Nested virt is indeed more of an issue - we did have some ideas around using SDEI that never made it to the spec. However I would argue that the most pragmatic approach would be to not support the combination of nested virt and LPT. Hopefully that can wait until the counter scaling support is available and not require PV.

We are discussing (re-)releasing the spec with the LPT parts added. If you have fundamental objections then please me know.

Thanks,

Steve
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

author
#9 lore raw
Quoted 51 lines · Steven Price
Quoted 37 lines · Marc Zyngier
Quoted 33 lines · Keqian Zhu

Hi all,

This patch series picks up the LPT pvtime feature originally developed by Steven Price: https://patchwork.kernel.org/cover/10726499/

Backgroud:

There is demand for cross-platform migration, which means we have to solve different CPU features and arch counter frequency between hosts. This patch series can solve the latter problem.

About LPT:

This implements support for Live Physical Time (LPT) which provides the guest with a method to derive a stable counter of time during which the guest is executing even when the guest is being migrated between hosts with different physical counter frequencies.

Changes on Steven Price's work:
1. LPT structure: use symmatical semantics of scale multiplier, and use fraction bits instead of "shift" to make everything clear.
2. Structure allocation: host kernel does not allocates the LPT structure, instead it is allocated by userspace through VM attributes. The save/restore functionality can be removed.
3. Since LPT structure just need update once for each guest run, add a flag to indicate the update status. This has two benifits: 1) avoid multiple update by each vCPUs. 2) If the update flag is not set, then return NOT SUPPORT for coressponding guest HVC call.
4. Add VM device attributes interface for userspace configuration.
5. Add a base LPT read/write layer to reduce code.
6. Support ptimer scaling.
7. Support timer event stream translation.

Quoted 2 lines

Things need concern:
1. https://developer.arm.com/docs/den0057/a needs update.

Quoted 8 lines

LPT was explicitly removed from the spec because it doesn't really solve the problem, specially for the firmware: EFI knows nothing about this, for example. How is it going to work? Also, nobody was ever able to explain how this would work for nested virt.

ARMv8.4 and ARMv8.6 have the feature set that is required to solve this problem without adding more PV to the kernel.

Hi Marc,

These are good points, however we do still have the situation that CPUs that don't have ARMv8.4/8.6 clearly cannot implement this. I presume the use-case Keqian is looking at predates the necessary support in the CPU - Keqian if you can provide more details on the architecture(s) involved that would be helpful.

Quoted 9 lines

Nested virt is indeed more of an issue - we did have some ideas around using SDEI that never made it to the spec. However I would argue that the most pragmatic approach would be to not support the combination of nested virt and LPT. Hopefully that can wait until the counter scaling support is available and not require PV.

We are discussing (re-)releasing the spec with the LPT parts added. If you have fundamental objections then please me know.

Thanks,

Steve
.

Hi Marc and Steven,

In fact, I have realize a demo which utilize v8.6-ECV to present a constant timer freq to guest. It seems work well, but this approach has some shortcoming:

1. Guest access to cntvct cntv_ctl cntv_tval cntv_cval must trap to EL2. Every trap will take about hundreds of nano-seconds. For every timer interrupt, there is about 5~6 traps, so it will spend several us (this seems not a serious problem :-) ). But trap will cause big deviation for nano-sleep.
2. We have to make cntfrq be a context of guest. However, only the highest exception level has right to modify cntfrq. It means we have to add a new SMC call.
3. cntkctl controls event stream freq, so KVM should also translate the guest access of cntkctl. However we cannot trap guest access of that. Any solution for this problem?

I think LPT as a software solution can solve these problems. However, as Marc said, UEFI knows nothing about LPT, and it will access vtimer/counter directly. The key point is how serious the impact is on UEFI.

I can see that some UEFI runtime services and drivers/applications will access timer/counter. For runtime services, it is OK. Because we can translate the result which return from UEFI for Linux. For drivers/applications, they will feel time goes faster or slower after migration. This is a problem indeed :-)

Thanks,
Keqian

maintainer
#10 lore raw
In reply to Steven Price

Hi Steven,

Quoted 53 lines · Steven Price
Quoted 42 lines · Marc Zyngier
Quoted 38 lines · Keqian Zhu

Hi all,

This patch series picks up the LPT pvtime feature originally developed by Steven Price: https://patchwork.kernel.org/cover/10726499/

Backgroud:

There is demand for cross-platform migration, which means we have to solve different CPU features and arch counter frequency between hosts. This patch series can solve the latter problem.

About LPT:

This implements support for Live Physical Time (LPT) which provides the guest with a method to derive a stable counter of time during which the guest is executing even when the guest is being migrated between hosts with different physical counter frequencies.

Changes on Steven Price's work:
1. LPT structure: use symmatical semantics of scale multiplier, and use fraction bits instead of "shift" to make everything clear.
2. Structure allocation: host kernel does not allocates the LPT structure,
   instead it is allocated by userspace through VM attributes. The save/restore
   functionality can be removed.
3. Since LPT structure just need update once for each guest run, add a flag to
   indicate the update status. This has two benifits: 1) avoid multiple update
   by each vCPUs. 2) If the update flag is not set, then return NOT SUPPORT for
   coressponding guest HVC call.
4. Add VM device attributes interface for userspace configuration.
5. Add a base LPT read/write layer to reduce code.
6. Support ptimer scaling.
7. Support timer event stream translation.

Quoted 2 lines

Things need concern:
1. https://developer.arm.com/docs/den0057/a needs update.

Quoted 8 lines

LPT was explicitly removed from the spec because it doesn't really solve the problem, specially for the firmware: EFI knows nothing about this, for example. How is it going to work? Also, nobody was ever able to explain how this would work for nested virt.

ARMv8.4 and ARMv8.6 have the feature set that is required to solve this problem without adding more PV to the kernel.

Quoted 7 lines

Hi Marc,

These are good points, however we do still have the situation that CPUs that don't have ARMv8.4/8.6 clearly cannot implement this. I presume the use-case Keqian is looking at predates the necessary support in the CPU - Keqian if you can provide more details on the architecture(s) involved that would be helpful.

My take on this is that it is a fictional use case. In my experience, migration happens across *identical* systems, and *any* difference visible to guests will cause things to go wrong. Errata management gets in the way, as usual (name *one* integration that isn't broken one way or another!).

Allowing migration across heterogeneous hosts requires a solution to the errata management problem, which everyone (including me) has decided to ignore so far (and I claim that not having a constant timer frequency exposed to guests is an architecture bug).

Quoted 2 lines

Nested virt is indeed more of an issue - we did have some ideas around using SDEI that never made it to the spec.

SDEI? Sigh... Why would SDEI be useful for NV and not for !NV?

Quoted 4 lines

However I would argue that the most pragmatic approach would be to not support the combination of nested virt and LPT. Hopefully that can wait until the counter scaling support is available and not require PV.

And have yet another set of band aids that paper over the fact that we can't get a consistent story on virtualization? No, thank you.

NV is (IMHO) much more important than LPT as it has a chance of getting used. LPT is just another tick box, and the fact that ARM is ready to ignore sideline a decent portion of the architecture is a clear sign that it hasn't been thought out.

Quoted 2 lines

We are discussing (re-)releasing the spec with the LPT parts added. If you have fundamental objections then please me know.

I do, see above. I'm stating that the use case doesn't really exist given the state of the available HW and the fragmentation of the architecture, and that ignoring the most important innovation in the virtualization architecture since ARMv7 is at best short-sighted.

Time scaling is just an instance of the errata management problem, and that is the issue that needs solving. Papering over part of the problem is not helping.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#11 lore raw

Hi Marc,

Sorry for the slow response, I've been on holiday.

Quoted 7 lines · Marc Zyngier

Hi Steven,

Quoted 3 lines · Steven Price
Quoted 1 line · Marc Zyngier

On 2020-08-17 09:41, Keqian Zhu wrote:

[...]

Quoted 21 lines
Quoted 13 lines
Quoted 4 lines
Quoted 3 lines

Things need concern:
1. https://developer.arm.com/docs/den0057/a needs update.

Quoted 8 lines

LPT was explicitly removed from the spec because it doesn't really solve the problem, specially for the firmware: EFI knows nothing about this, for example. How is it going to work? Also, nobody was ever able to explain how this would work for nested virt.

ARMv8.4 and ARMv8.6 have the feature set that is required to solve this problem without adding more PV to the kernel.

Quoted 7 lines

Hi Marc,

These are good points, however we do still have the situation that CPUs that don't have ARMv8.4/8.6 clearly cannot implement this. I presume the use-case Keqian is looking at predates the necessary support in the CPU - Keqian if you can provide more details on the architecture(s) involved that would be helpful.

Quoted 5 lines

My take on this is that it is a fictional use case. In my experience, migration happens across *identical* systems, and *any* difference visible to guests will cause things to go wrong. Errata management gets in the way, as usual (name *one* integration that isn't broken one way or another!).

Keqian appears to have a use case - but obviously I don't know the details. I guess Keqian needs to convince you of that.

Quoted 4 lines

Allowing migration across heterogeneous hosts requires a solution to the errata management problem, which everyone (including me) has decided to ignore so far (and I claim that not having a constant timer frequency exposed to guests is an architecture bug).

I agree - errata management needs to be solved before LPT. Between restricted subsets of hosts this doesn't seem impossible, but I guess we should stall LPT until a credible solution is proposed. I'm certainly not proposing one at the moment.

Quoted 4 lines
Quoted 2 lines

Nested virt is indeed more of an issue - we did have some ideas around using SDEI that never made it to the spec.

SDEI? Sigh... Why would SDEI be useful for NV and not for !NV?

SDEI provides a way of injecting a synchronous exception on migration - although that certainly isn't the only possible mechanism. For NV we have the problem that a guest-guest may be running at the point of migration. However it's not practical for the host hypervisor to provide the necessary table directly to the guest-guest which means the guest-hypervisor must update the tables before the guest-guest is allowed to run on the new host. The only plausible route I could see for this is injecting a synchronous exception into the guest (per VCPU) to ensure any guest-guests running are exited at migration time.

!NV is easier because we don't have to worry about multiple levels of para-virtualisation.

Quoted 5 lines
Quoted 4 lines

However I would argue that the most pragmatic approach would be to not support the combination of nested virt and LPT. Hopefully that can wait until the counter scaling support is available and not require PV.

Quoted 7 lines

And have yet another set of band aids that paper over the fact that we can't get a consistent story on virtualization? No, thank you.

NV is (IMHO) much more important than LPT as it has a chance of getting used. LPT is just another tick box, and the fact that ARM is ready to ignore sideline a decent portion of the architecture is a clear sign that it hasn't been thought out.

Different people have different priorities. NV is definitely important for many people. LPT may also be important if you've already got a bunch of VMs running on machines and you want to be able to (gradually) replace them with newer hosts which happen to have a different clock frequency. Those VMs running now clearly aren't using NV.

However, I have to admit it's not me that has the use-case, so I'll leave it for others who might actually know the specifics to explain the details.

Quoted 11 lines
Quoted 2 lines

We are discussing (re-)releasing the spec with the LPT parts added. If you have fundamental objections then please me know.

I do, see above. I'm stating that the use case doesn't really exist given the state of the available HW and the fragmentation of the architecture, and that ignoring the most important innovation in the virtualization architecture since ARMv7 is at best short-sighted.

Time scaling is just an instance of the errata management problem, and that is the issue that needs solving. Papering over part of the problem is not helping.

I fully agree - errata management is definitely the first step that needs solving. This is why I abandoned LPT originally because I don't have a generic solution and the testing I did involved really ugly hacks just to make the migration possible.

For now I propose we (again) park LPT until some progress has been made on errata management.

Thanks,

Steve

author
#12 lore raw

Hi Marc and Steven,

Quoted 34 lines · Steven Price

Hi Marc,

Sorry for the slow response, I've been on holiday.

Quoted 7 lines · Marc Zyngier

Hi Steven,

Quoted 3 lines · Steven Price
Quoted 1 line · Marc Zyngier

On 2020-08-17 09:41, Keqian Zhu wrote:

[...]

Quoted 21 lines
Quoted 20 lines
Quoted 4 lines
Quoted 3 lines

Things need concern:
1. https://developer.arm.com/docs/den0057/a needs update.

Quoted 8 lines

LPT was explicitly removed from the spec because it doesn't really solve the problem, specially for the firmware: EFI knows nothing about this, for example. How is it going to work? Also, nobody was ever able to explain how this would work for nested virt.

ARMv8.4 and ARMv8.6 have the feature set that is required to solve this problem without adding more PV to the kernel.

Hi Marc,

These are good points, however we do still have the situation that CPUs that don't have ARMv8.4/8.6 clearly cannot implement this. I presume the use-case Keqian is looking at predates the necessary support in the CPU - Keqian if you can provide more details on the architecture(s) involved that would be helpful.

Quoted 7 lines
Quoted 5 lines

My take on this is that it is a fictional use case. In my experience, migration happens across *identical* systems, and *any* difference visible to guests will cause things to go wrong. Errata management gets in the way, as usual (name *one* integration that isn't broken one way or another!).

Keqian appears to have a use case - but obviously I don't know the details. I guess Keqian needs to convince you of that.

Sure, there is use case, but I'm very sorry that it's inconvenient to show the detail. Maybe cross-chip migration will be supported by arm64 eventually, so I think use case is not a key problem.

Quoted 46 lines
Quoted 5 lines

Allowing migration across heterogeneous hosts requires a solution to the errata management problem, which everyone (including me) has decided to ignore so far (and I claim that not having a constant timer frequency exposed to guests is an architecture bug).

I agree - errata management needs to be solved before LPT. Between restricted subsets of hosts this doesn't seem impossible, but I guess we should stall LPT until a credible solution is proposed. I'm certainly not proposing one at the moment.

Quoted 4 lines
Quoted 2 lines

Nested virt is indeed more of an issue - we did have some ideas around using SDEI that never made it to the spec.

SDEI? Sigh... Why would SDEI be useful for NV and not for !NV?

SDEI provides a way of injecting a synchronous exception on migration - although that certainly isn't the only possible mechanism. For NV we have the problem that a guest-guest may be running at the point of migration. However it's not practical for the host hypervisor to provide the necessary table directly to the guest-guest which means the guest-hypervisor must update the tables before the guest-guest is allowed to run on the new host. The only plausible route I could see for this is injecting a synchronous exception into the guest (per VCPU) to ensure any guest-guests running are exited at migration time.

!NV is easier because we don't have to worry about multiple levels of para-virtualisation.

Quoted 5 lines
Quoted 4 lines

However I would argue that the most pragmatic approach would be to not support the combination of nested virt and LPT. Hopefully that can wait until the counter scaling support is available and not require PV.

Quoted 7 lines

And have yet another set of band aids that paper over the fact that we can't get a consistent story on virtualization? No, thank you.

NV is (IMHO) much more important than LPT as it has a chance of getting used. LPT is just another tick box, and the fact that ARM is ready to ignore sideline a decent portion of the architecture is a clear sign that it hasn't been thought out.

Different people have different priorities. NV is definitely important for many people. LPT may also be important if you've already got a bunch of VMs running on machines and you want to be able to (gradually) replace them with newer hosts which happen to have a different clock frequency. Those VMs running now clearly aren't using NV.

However, I have to admit it's not me that has the use-case, so I'll leave it for others who might actually know the specifics to explain the details.

Quoted 11 lines
Quoted 2 lines

We are discussing (re-)releasing the spec with the LPT parts added. If you have fundamental objections then please me know.

I do, see above. I'm stating that the use case doesn't really exist given the state of the available HW and the fragmentation of the architecture, and that ignoring the most important innovation in the virtualization architecture since ARMv7 is at best short-sighted.

Time scaling is just an instance of the errata management problem, and that is the issue that needs solving. Papering over part of the problem is not helping.

Quoted 8 lines

I fully agree - errata management is definitely the first step that needs solving. This is why I abandoned LPT originally because I don't have a generic solution and the testing I did involved really ugly hacks just to make the migration possible.

For now I propose we (again) park LPT until some progress has been made on errata management.

Thanks,

Steve
.

As we have discussed, to support the vtimer part of cross-chip migration, we still face many problems. Firstly, we have no complete solution to realize the basic functionality. For PV solution, LPT just handles Linux kernel, other SW agents are not involved. For non-PV solution, ARMv8.4 ext and ARMv8.6 ext is not enough. Besides the basic functionality, we should concern errata management and NV (I think this is not urgent).

Giving above, I agree with Steven that re-park LPT.

Thanks,
Keqian

maintainer
#13 lore raw
In reply to Steven Price
Quoted 5 lines · Steven Price
Quoted 1 line · Marc Zyngier

On 2020-08-17 09:41, Keqian Zhu wrote:

We are discussing (re-)releasing the spec with the LPT parts added. If you have fundamental objections then please me know.

Like Marc, I argued strongly for the removal of the LPT bits on the premise that it didn't really work (e.g. when transistioning between SW agents) and so it was a pure maintenance burden.

I don't think the technical arguments have changed, and I don't think it's a good idea to try to ressurect this. Please rope me in if this comes up in internal discussions.

Mark.