All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marc Zyngier <maz@kernel.org>
To: Jianyong Wu <jianyong.wu@arm.com>
Cc: justin.he@arm.com, kvm@vger.kernel.org, netdev@vger.kernel.org,
	richardcochran@gmail.com, linux-kernel@vger.kernel.org,
	steven.price@arm.com, Andre.Przywara@arm.com,
	john.stultz@linaro.org, yangbo.lu@nxp.com, pbonzini@redhat.com,
	tglx@linutronix.de, nd@arm.com, will@kernel.org,
	kvmarm@lists.cs.columbia.edu,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v16 8/9] doc: add ptp_kvm introduction for arm64 support
Date: Tue, 02 Feb 2021 13:43:48 +0000	[thread overview]
Message-ID: <abe1ea58ddd13e43e62c25103e05fcf0@kernel.org> (raw)
In-Reply-To: <20201209060932.212364-9-jianyong.wu@arm.com>

On 2020-12-09 06:09, Jianyong Wu wrote:
> PTP_KVM implementation depends on hypercall using SMCCC. So we
> introduce a new SMCCC service ID. This doc explains how does the
> ID define and how does PTP_KVM works on arm/arm64.
> 
> Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
> ---
>  Documentation/virt/kvm/api.rst         |  9 +++++++
>  Documentation/virt/kvm/arm/index.rst   |  1 +
>  Documentation/virt/kvm/arm/ptp_kvm.rst | 31 +++++++++++++++++++++++
>  Documentation/virt/kvm/timekeeping.rst | 35 ++++++++++++++++++++++++++
>  4 files changed, 76 insertions(+)
>  create mode 100644 Documentation/virt/kvm/arm/ptp_kvm.rst
> 
> diff --git a/Documentation/virt/kvm/api.rst 
> b/Documentation/virt/kvm/api.rst
> index e00a66d72372..3769cc2f7d9c 100644
> --- a/Documentation/virt/kvm/api.rst
> +++ b/Documentation/virt/kvm/api.rst
> @@ -6390,3 +6390,12 @@ When enabled, KVM will disable paravirtual
> features provided to the
>  guest according to the bits in the KVM_CPUID_FEATURES CPUID leaf
>  (0x40000001). Otherwise, a guest may use the paravirtual features
>  regardless of what has actually been exposed through the CPUID leaf.
> +
> +8.27 KVM_CAP_PTP_KVM
> +--------------------
> +
> +:Architectures: arm64
> +
> +This capability indicates that KVM virtual PTP service is supported in 
> host.
> +It must company with the implementation of KVM virtual PTP service in 
> host
> +so VMM can probe if there is the service in host by checking this 
> capability.

This reads a bit odd. I came up with the following:

+This capability indicates that the KVM virtual PTP service is
+supported in the host. A VMM can check whether the service is
+available to the guest on migration.


> diff --git a/Documentation/virt/kvm/arm/index.rst
> b/Documentation/virt/kvm/arm/index.rst
> index 3e2b2aba90fc..78a9b670aafe 100644
> --- a/Documentation/virt/kvm/arm/index.rst
> +++ b/Documentation/virt/kvm/arm/index.rst
> @@ -10,3 +10,4 @@ ARM
>     hyp-abi
>     psci
>     pvtime
> +   ptp_kvm
> diff --git a/Documentation/virt/kvm/arm/ptp_kvm.rst
> b/Documentation/virt/kvm/arm/ptp_kvm.rst
> new file mode 100644
> index 000000000000..d729c1388a5c
> --- /dev/null
> +++ b/Documentation/virt/kvm/arm/ptp_kvm.rst
> @@ -0,0 +1,31 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +PTP_KVM support for arm/arm64
> +=============================
> +
> +PTP_KVM is used for time sync between guest and host in a high 
> precision.
> +It needs to get the wall time and counter value from the host and
> transfer these
> +to guest via hypercall service. So one more hypercall service has been 
> added.
> +
> +This new SMCCC hypercall is defined as:

It won't be new anymore the minute this is merged.

> +
> +* ARM_SMCCC_HYP_KVM_PTP_FUNC_ID: 0x86000001
> +
> +As both 32 and 64-bits ptp_kvm client should be supported, we choose
> SMC32/HVC32
> +calling convention.
> +
> +ARM_SMCCC_HYP_KVM_PTP_FUNC_ID:
> +
> +    =============    ==========    ==========
> +    Function ID:     (uint32)      0x86000001
> +    Arguments:       (uint32)      ARM_PTP_PHY_COUNTER(1) or
> ARM_PTP_VIRT_COUNTER(0)
> +                                   which indicate acquiring physical 
> counter or
> +                                   virtual counter respectively.
> +    Return Value:    val0(uint32)  NOT_SUPPORTED(-1) or upper 32 bits
> of wall clock time(64-bits).
> +                     val1(uint32)  Lower 32 bits of wall clock time.
> +                     val2(uint32)  Upper 32 bits of counter 
> cycle(64-bits).
> +                     val3(uint32)  Lower 32 bits of counter cycle.
> +    Endianness:                    No Restrictions.
> +    =============    ==========    ==========
> +
> +More info see section 5 in Documentation/virt/kvm/timekeeping.rst.

I've tidied this up like this:

diff --git a/Documentation/virt/kvm/arm/ptp_kvm.rst 
b/Documentation/virt/kvm/arm/ptp_kvm.rst
index d729c1388a5c..68cffb50d8bf 100644
--- a/Documentation/virt/kvm/arm/ptp_kvm.rst
+++ b/Documentation/virt/kvm/arm/ptp_kvm.rst
@@ -3,29 +3,23 @@
  PTP_KVM support for arm/arm64
  =============================

-PTP_KVM is used for time sync between guest and host in a high 
precision.
-It needs to get the wall time and counter value from the host and 
transfer these
-to guest via hypercall service. So one more hypercall service has been 
added.
-
-This new SMCCC hypercall is defined as:
+PTP_KVM is used for high precision time sync between host and guests.
+It relies on transferring the wall clock and counter value from the
+host to the guest using a KVM-specific hypercall.

  * ARM_SMCCC_HYP_KVM_PTP_FUNC_ID: 0x86000001

-As both 32 and 64-bits ptp_kvm client should be supported, we choose 
SMC32/HVC32
-calling convention.
-
-ARM_SMCCC_HYP_KVM_PTP_FUNC_ID:
+This hypercall uses the SMC32/HVC32 calling convention:

+ARM_SMCCC_HYP_KVM_PTP_FUNC_ID
      =============    ==========    ==========
      Function ID:     (uint32)      0x86000001
-    Arguments:       (uint32)      ARM_PTP_PHY_COUNTER(1) or 
ARM_PTP_VIRT_COUNTER(0)
-                                   which indicate acquiring physical 
counter or
-                                   virtual counter respectively.
-    Return Value:    val0(uint32)  NOT_SUPPORTED(-1) or upper 32 bits 
of wall clock time(64-bits).
-                     val1(uint32)  Lower 32 bits of wall clock time.
-                     val2(uint32)  Upper 32 bits of counter 
cycle(64-bits).
-                     val3(uint32)  Lower 32 bits of counter cycle.
+    Arguments:       (uint32)      KVM_PTP_VIRT_COUNTER(0)
+                                   KVM_PTP_PHYS_COUNTER(1)
+    Return Values:   (int32)       NOT_SUPPORTED(-1) on error, or
+                     (uint32)      Upper 32 bits of wall clock time 
(r0)
+                     (uint32)      Lower 32 bits of wall clock time 
(r1)
+                     (uint32)      Upper 32 bits of counter (r2)
+                     (uint32)      Lower 32 bits of counter (r3)
      Endianness:                    No Restrictions.
      =============    ==========    ==========
-
-More info see section 5 in Documentation/virt/kvm/timekeeping.rst.

> diff --git a/Documentation/virt/kvm/timekeeping.rst
> b/Documentation/virt/kvm/timekeeping.rst
> index 21ae7efa29ba..c81383e38372 100644
> --- a/Documentation/virt/kvm/timekeeping.rst
> +++ b/Documentation/virt/kvm/timekeeping.rst
> @@ -13,6 +13,7 @@ Timekeeping Virtualization for X86-Based 
> Architectures
>     2) Timing Devices
>     3) TSC Hardware
>     4) Virtualization Problems
> +   5) KVM virtual PTP clock
> 
>  1. Overview
>  ===========
> @@ -643,3 +644,37 @@ by using CPU utilization itself as a signalling
> channel.  Preventing such
>  problems would require completely isolated virtual time which may not 
> track
>  real time any longer.  This may be useful in certain security or QA 
> contexts,
>  but in general isn't recommended for real-world deployment scenarios.
> +
> +5. KVM virtual PTP clock
> +========================
> +
> +NTP (Network Time Protocol) is often used to sync time in a VM. 
> Unfortunately,
> +the precision of NTP is limited due to unknown delays in the network.
> +
> +KVM virtual PTP clock (PTP_KVM) offers another way to sync time in VM; 
> use the
> +host's clock rather than one from a remote machine. Having a 
> synchronization
> +mechanism for the virtualization environment allows us to keep all the 
> guests
> +running on the same host in sync.
> +In general, the delay of communication between host and guest is quite
> +small, so ptp_kvm can offer time sync precision up to in order of 
> nanoseconds.
> +Please keep in mind that ptp_kvm just limits itself to be a channel 
> which
> +transmits the remote clock from host to guest. An application, eg. 
> chrony, is
> +needed in usersapce of VM in order to set the guest time.
> +
> +After ptp_kvm is initialized, there will be a new device node under 
> /dev called
> +ptp%d. A guest userspace service, like chrony, can use this device to 
> get host
> +walltime, sometimes also counter cycle, which depends on the service 
> it calls.
> +Then this guest userspace service can use those data to do the time 
> sync for
> +the guest.
> +The following is the work flow of ptp_kvm:
> +
> +a) time sync service in guest userspace call ioctl on ptp device 
> /dev/ptp%d.
> +b) ptp_kvm module in guest receives this request then invokes 
> hypercall to
> +   route into host kernel to request host's walltime/counter cycle.
> +c) ptp_kvm hypercall service on the host responds to the request and 
> sends data
> +   back.
> +d) ptp in guest copies the data to userspace.
> +
> +ptp_kvm consists of components running on the guest and host. Step 2
> consists of
> +a guest driver making a hypercall whilst step 3 involves the
> hypervisor responding
> +with information.

I don't think we need any of this here, as the whole file
focuses on x86-specific issues for timekeeping. If we want
to document KVM PTP, this should probably be a separate document.

Thanks,

         M.
-- 
Jazz is not dead. It just smells funny...
_______________________________________________
kvmarm mailing list
kvmarm@lists.cs.columbia.edu
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <maz@kernel.org>
To: Jianyong Wu <jianyong.wu@arm.com>
Cc: Mark.Rutland@arm.com, justin.he@arm.com, kvm@vger.kernel.org,
	suzuki.poulose@arm.com, netdev@vger.kernel.org,
	richardcochran@gmail.com, Steve.Capper@arm.com,
	linux-kernel@vger.kernel.org, steven.price@arm.com,
	Andre.Przywara@arm.com, john.stultz@linaro.org,
	yangbo.lu@nxp.com, pbonzini@redhat.com, tglx@linutronix.de,
	nd@arm.com, will@kernel.org, kvmarm@lists.cs.columbia.edu,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v16 8/9] doc: add ptp_kvm introduction for arm64 support
Date: Tue, 02 Feb 2021 13:43:48 +0000	[thread overview]
Message-ID: <abe1ea58ddd13e43e62c25103e05fcf0@kernel.org> (raw)
In-Reply-To: <20201209060932.212364-9-jianyong.wu@arm.com>

On 2020-12-09 06:09, Jianyong Wu wrote:
> PTP_KVM implementation depends on hypercall using SMCCC. So we
> introduce a new SMCCC service ID. This doc explains how does the
> ID define and how does PTP_KVM works on arm/arm64.
> 
> Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
> ---
>  Documentation/virt/kvm/api.rst         |  9 +++++++
>  Documentation/virt/kvm/arm/index.rst   |  1 +
>  Documentation/virt/kvm/arm/ptp_kvm.rst | 31 +++++++++++++++++++++++
>  Documentation/virt/kvm/timekeeping.rst | 35 ++++++++++++++++++++++++++
>  4 files changed, 76 insertions(+)
>  create mode 100644 Documentation/virt/kvm/arm/ptp_kvm.rst
> 
> diff --git a/Documentation/virt/kvm/api.rst 
> b/Documentation/virt/kvm/api.rst
> index e00a66d72372..3769cc2f7d9c 100644
> --- a/Documentation/virt/kvm/api.rst
> +++ b/Documentation/virt/kvm/api.rst
> @@ -6390,3 +6390,12 @@ When enabled, KVM will disable paravirtual
> features provided to the
>  guest according to the bits in the KVM_CPUID_FEATURES CPUID leaf
>  (0x40000001). Otherwise, a guest may use the paravirtual features
>  regardless of what has actually been exposed through the CPUID leaf.
> +
> +8.27 KVM_CAP_PTP_KVM
> +--------------------
> +
> +:Architectures: arm64
> +
> +This capability indicates that KVM virtual PTP service is supported in 
> host.
> +It must company with the implementation of KVM virtual PTP service in 
> host
> +so VMM can probe if there is the service in host by checking this 
> capability.

This reads a bit odd. I came up with the following:

+This capability indicates that the KVM virtual PTP service is
+supported in the host. A VMM can check whether the service is
+available to the guest on migration.


> diff --git a/Documentation/virt/kvm/arm/index.rst
> b/Documentation/virt/kvm/arm/index.rst
> index 3e2b2aba90fc..78a9b670aafe 100644
> --- a/Documentation/virt/kvm/arm/index.rst
> +++ b/Documentation/virt/kvm/arm/index.rst
> @@ -10,3 +10,4 @@ ARM
>     hyp-abi
>     psci
>     pvtime
> +   ptp_kvm
> diff --git a/Documentation/virt/kvm/arm/ptp_kvm.rst
> b/Documentation/virt/kvm/arm/ptp_kvm.rst
> new file mode 100644
> index 000000000000..d729c1388a5c
> --- /dev/null
> +++ b/Documentation/virt/kvm/arm/ptp_kvm.rst
> @@ -0,0 +1,31 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +PTP_KVM support for arm/arm64
> +=============================
> +
> +PTP_KVM is used for time sync between guest and host in a high 
> precision.
> +It needs to get the wall time and counter value from the host and
> transfer these
> +to guest via hypercall service. So one more hypercall service has been 
> added.
> +
> +This new SMCCC hypercall is defined as:

It won't be new anymore the minute this is merged.

> +
> +* ARM_SMCCC_HYP_KVM_PTP_FUNC_ID: 0x86000001
> +
> +As both 32 and 64-bits ptp_kvm client should be supported, we choose
> SMC32/HVC32
> +calling convention.
> +
> +ARM_SMCCC_HYP_KVM_PTP_FUNC_ID:
> +
> +    =============    ==========    ==========
> +    Function ID:     (uint32)      0x86000001
> +    Arguments:       (uint32)      ARM_PTP_PHY_COUNTER(1) or
> ARM_PTP_VIRT_COUNTER(0)
> +                                   which indicate acquiring physical 
> counter or
> +                                   virtual counter respectively.
> +    Return Value:    val0(uint32)  NOT_SUPPORTED(-1) or upper 32 bits
> of wall clock time(64-bits).
> +                     val1(uint32)  Lower 32 bits of wall clock time.
> +                     val2(uint32)  Upper 32 bits of counter 
> cycle(64-bits).
> +                     val3(uint32)  Lower 32 bits of counter cycle.
> +    Endianness:                    No Restrictions.
> +    =============    ==========    ==========
> +
> +More info see section 5 in Documentation/virt/kvm/timekeeping.rst.

I've tidied this up like this:

diff --git a/Documentation/virt/kvm/arm/ptp_kvm.rst 
b/Documentation/virt/kvm/arm/ptp_kvm.rst
index d729c1388a5c..68cffb50d8bf 100644
--- a/Documentation/virt/kvm/arm/ptp_kvm.rst
+++ b/Documentation/virt/kvm/arm/ptp_kvm.rst
@@ -3,29 +3,23 @@
  PTP_KVM support for arm/arm64
  =============================

-PTP_KVM is used for time sync between guest and host in a high 
precision.
-It needs to get the wall time and counter value from the host and 
transfer these
-to guest via hypercall service. So one more hypercall service has been 
added.
-
-This new SMCCC hypercall is defined as:
+PTP_KVM is used for high precision time sync between host and guests.
+It relies on transferring the wall clock and counter value from the
+host to the guest using a KVM-specific hypercall.

  * ARM_SMCCC_HYP_KVM_PTP_FUNC_ID: 0x86000001

-As both 32 and 64-bits ptp_kvm client should be supported, we choose 
SMC32/HVC32
-calling convention.
-
-ARM_SMCCC_HYP_KVM_PTP_FUNC_ID:
+This hypercall uses the SMC32/HVC32 calling convention:

+ARM_SMCCC_HYP_KVM_PTP_FUNC_ID
      =============    ==========    ==========
      Function ID:     (uint32)      0x86000001
-    Arguments:       (uint32)      ARM_PTP_PHY_COUNTER(1) or 
ARM_PTP_VIRT_COUNTER(0)
-                                   which indicate acquiring physical 
counter or
-                                   virtual counter respectively.
-    Return Value:    val0(uint32)  NOT_SUPPORTED(-1) or upper 32 bits 
of wall clock time(64-bits).
-                     val1(uint32)  Lower 32 bits of wall clock time.
-                     val2(uint32)  Upper 32 bits of counter 
cycle(64-bits).
-                     val3(uint32)  Lower 32 bits of counter cycle.
+    Arguments:       (uint32)      KVM_PTP_VIRT_COUNTER(0)
+                                   KVM_PTP_PHYS_COUNTER(1)
+    Return Values:   (int32)       NOT_SUPPORTED(-1) on error, or
+                     (uint32)      Upper 32 bits of wall clock time 
(r0)
+                     (uint32)      Lower 32 bits of wall clock time 
(r1)
+                     (uint32)      Upper 32 bits of counter (r2)
+                     (uint32)      Lower 32 bits of counter (r3)
      Endianness:                    No Restrictions.
      =============    ==========    ==========
-
-More info see section 5 in Documentation/virt/kvm/timekeeping.rst.

> diff --git a/Documentation/virt/kvm/timekeeping.rst
> b/Documentation/virt/kvm/timekeeping.rst
> index 21ae7efa29ba..c81383e38372 100644
> --- a/Documentation/virt/kvm/timekeeping.rst
> +++ b/Documentation/virt/kvm/timekeeping.rst
> @@ -13,6 +13,7 @@ Timekeeping Virtualization for X86-Based 
> Architectures
>     2) Timing Devices
>     3) TSC Hardware
>     4) Virtualization Problems
> +   5) KVM virtual PTP clock
> 
>  1. Overview
>  ===========
> @@ -643,3 +644,37 @@ by using CPU utilization itself as a signalling
> channel.  Preventing such
>  problems would require completely isolated virtual time which may not 
> track
>  real time any longer.  This may be useful in certain security or QA 
> contexts,
>  but in general isn't recommended for real-world deployment scenarios.
> +
> +5. KVM virtual PTP clock
> +========================
> +
> +NTP (Network Time Protocol) is often used to sync time in a VM. 
> Unfortunately,
> +the precision of NTP is limited due to unknown delays in the network.
> +
> +KVM virtual PTP clock (PTP_KVM) offers another way to sync time in VM; 
> use the
> +host's clock rather than one from a remote machine. Having a 
> synchronization
> +mechanism for the virtualization environment allows us to keep all the 
> guests
> +running on the same host in sync.
> +In general, the delay of communication between host and guest is quite
> +small, so ptp_kvm can offer time sync precision up to in order of 
> nanoseconds.
> +Please keep in mind that ptp_kvm just limits itself to be a channel 
> which
> +transmits the remote clock from host to guest. An application, eg. 
> chrony, is
> +needed in usersapce of VM in order to set the guest time.
> +
> +After ptp_kvm is initialized, there will be a new device node under 
> /dev called
> +ptp%d. A guest userspace service, like chrony, can use this device to 
> get host
> +walltime, sometimes also counter cycle, which depends on the service 
> it calls.
> +Then this guest userspace service can use those data to do the time 
> sync for
> +the guest.
> +The following is the work flow of ptp_kvm:
> +
> +a) time sync service in guest userspace call ioctl on ptp device 
> /dev/ptp%d.
> +b) ptp_kvm module in guest receives this request then invokes 
> hypercall to
> +   route into host kernel to request host's walltime/counter cycle.
> +c) ptp_kvm hypercall service on the host responds to the request and 
> sends data
> +   back.
> +d) ptp in guest copies the data to userspace.
> +
> +ptp_kvm consists of components running on the guest and host. Step 2
> consists of
> +a guest driver making a hypercall whilst step 3 involves the
> hypervisor responding
> +with information.

I don't think we need any of this here, as the whole file
focuses on x86-specific issues for timekeeping. If we want
to document KVM PTP, this should probably be a separate document.

Thanks,

         M.
-- 
Jazz is not dead. It just smells funny...

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

WARNING: multiple messages have this Message-ID (diff)
From: Marc Zyngier <maz@kernel.org>
To: Jianyong Wu <jianyong.wu@arm.com>
Cc: netdev@vger.kernel.org, yangbo.lu@nxp.com,
	john.stultz@linaro.org, tglx@linutronix.de, pbonzini@redhat.com,
	richardcochran@gmail.com, Mark.Rutland@arm.com, will@kernel.org,
	suzuki.poulose@arm.com, Andre.Przywara@arm.com,
	steven.price@arm.com, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org,
	Steve.Capper@arm.com, justin.he@arm.com, nd@arm.com
Subject: Re: [PATCH v16 8/9] doc: add ptp_kvm introduction for arm64 support
Date: Tue, 02 Feb 2021 13:43:48 +0000	[thread overview]
Message-ID: <abe1ea58ddd13e43e62c25103e05fcf0@kernel.org> (raw)
In-Reply-To: <20201209060932.212364-9-jianyong.wu@arm.com>

On 2020-12-09 06:09, Jianyong Wu wrote:
> PTP_KVM implementation depends on hypercall using SMCCC. So we
> introduce a new SMCCC service ID. This doc explains how does the
> ID define and how does PTP_KVM works on arm/arm64.
> 
> Signed-off-by: Jianyong Wu <jianyong.wu@arm.com>
> ---
>  Documentation/virt/kvm/api.rst         |  9 +++++++
>  Documentation/virt/kvm/arm/index.rst   |  1 +
>  Documentation/virt/kvm/arm/ptp_kvm.rst | 31 +++++++++++++++++++++++
>  Documentation/virt/kvm/timekeeping.rst | 35 ++++++++++++++++++++++++++
>  4 files changed, 76 insertions(+)
>  create mode 100644 Documentation/virt/kvm/arm/ptp_kvm.rst
> 
> diff --git a/Documentation/virt/kvm/api.rst 
> b/Documentation/virt/kvm/api.rst
> index e00a66d72372..3769cc2f7d9c 100644
> --- a/Documentation/virt/kvm/api.rst
> +++ b/Documentation/virt/kvm/api.rst
> @@ -6390,3 +6390,12 @@ When enabled, KVM will disable paravirtual
> features provided to the
>  guest according to the bits in the KVM_CPUID_FEATURES CPUID leaf
>  (0x40000001). Otherwise, a guest may use the paravirtual features
>  regardless of what has actually been exposed through the CPUID leaf.
> +
> +8.27 KVM_CAP_PTP_KVM
> +--------------------
> +
> +:Architectures: arm64
> +
> +This capability indicates that KVM virtual PTP service is supported in 
> host.
> +It must company with the implementation of KVM virtual PTP service in 
> host
> +so VMM can probe if there is the service in host by checking this 
> capability.

This reads a bit odd. I came up with the following:

+This capability indicates that the KVM virtual PTP service is
+supported in the host. A VMM can check whether the service is
+available to the guest on migration.


> diff --git a/Documentation/virt/kvm/arm/index.rst
> b/Documentation/virt/kvm/arm/index.rst
> index 3e2b2aba90fc..78a9b670aafe 100644
> --- a/Documentation/virt/kvm/arm/index.rst
> +++ b/Documentation/virt/kvm/arm/index.rst
> @@ -10,3 +10,4 @@ ARM
>     hyp-abi
>     psci
>     pvtime
> +   ptp_kvm
> diff --git a/Documentation/virt/kvm/arm/ptp_kvm.rst
> b/Documentation/virt/kvm/arm/ptp_kvm.rst
> new file mode 100644
> index 000000000000..d729c1388a5c
> --- /dev/null
> +++ b/Documentation/virt/kvm/arm/ptp_kvm.rst
> @@ -0,0 +1,31 @@
> +.. SPDX-License-Identifier: GPL-2.0
> +
> +PTP_KVM support for arm/arm64
> +=============================
> +
> +PTP_KVM is used for time sync between guest and host in a high 
> precision.
> +It needs to get the wall time and counter value from the host and
> transfer these
> +to guest via hypercall service. So one more hypercall service has been 
> added.
> +
> +This new SMCCC hypercall is defined as:

It won't be new anymore the minute this is merged.

> +
> +* ARM_SMCCC_HYP_KVM_PTP_FUNC_ID: 0x86000001
> +
> +As both 32 and 64-bits ptp_kvm client should be supported, we choose
> SMC32/HVC32
> +calling convention.
> +
> +ARM_SMCCC_HYP_KVM_PTP_FUNC_ID:
> +
> +    =============    ==========    ==========
> +    Function ID:     (uint32)      0x86000001
> +    Arguments:       (uint32)      ARM_PTP_PHY_COUNTER(1) or
> ARM_PTP_VIRT_COUNTER(0)
> +                                   which indicate acquiring physical 
> counter or
> +                                   virtual counter respectively.
> +    Return Value:    val0(uint32)  NOT_SUPPORTED(-1) or upper 32 bits
> of wall clock time(64-bits).
> +                     val1(uint32)  Lower 32 bits of wall clock time.
> +                     val2(uint32)  Upper 32 bits of counter 
> cycle(64-bits).
> +                     val3(uint32)  Lower 32 bits of counter cycle.
> +    Endianness:                    No Restrictions.
> +    =============    ==========    ==========
> +
> +More info see section 5 in Documentation/virt/kvm/timekeeping.rst.

I've tidied this up like this:

diff --git a/Documentation/virt/kvm/arm/ptp_kvm.rst 
b/Documentation/virt/kvm/arm/ptp_kvm.rst
index d729c1388a5c..68cffb50d8bf 100644
--- a/Documentation/virt/kvm/arm/ptp_kvm.rst
+++ b/Documentation/virt/kvm/arm/ptp_kvm.rst
@@ -3,29 +3,23 @@
  PTP_KVM support for arm/arm64
  =============================

-PTP_KVM is used for time sync between guest and host in a high 
precision.
-It needs to get the wall time and counter value from the host and 
transfer these
-to guest via hypercall service. So one more hypercall service has been 
added.
-
-This new SMCCC hypercall is defined as:
+PTP_KVM is used for high precision time sync between host and guests.
+It relies on transferring the wall clock and counter value from the
+host to the guest using a KVM-specific hypercall.

  * ARM_SMCCC_HYP_KVM_PTP_FUNC_ID: 0x86000001

-As both 32 and 64-bits ptp_kvm client should be supported, we choose 
SMC32/HVC32
-calling convention.
-
-ARM_SMCCC_HYP_KVM_PTP_FUNC_ID:
+This hypercall uses the SMC32/HVC32 calling convention:

+ARM_SMCCC_HYP_KVM_PTP_FUNC_ID
      =============    ==========    ==========
      Function ID:     (uint32)      0x86000001
-    Arguments:       (uint32)      ARM_PTP_PHY_COUNTER(1) or 
ARM_PTP_VIRT_COUNTER(0)
-                                   which indicate acquiring physical 
counter or
-                                   virtual counter respectively.
-    Return Value:    val0(uint32)  NOT_SUPPORTED(-1) or upper 32 bits 
of wall clock time(64-bits).
-                     val1(uint32)  Lower 32 bits of wall clock time.
-                     val2(uint32)  Upper 32 bits of counter 
cycle(64-bits).
-                     val3(uint32)  Lower 32 bits of counter cycle.
+    Arguments:       (uint32)      KVM_PTP_VIRT_COUNTER(0)
+                                   KVM_PTP_PHYS_COUNTER(1)
+    Return Values:   (int32)       NOT_SUPPORTED(-1) on error, or
+                     (uint32)      Upper 32 bits of wall clock time 
(r0)
+                     (uint32)      Lower 32 bits of wall clock time 
(r1)
+                     (uint32)      Upper 32 bits of counter (r2)
+                     (uint32)      Lower 32 bits of counter (r3)
      Endianness:                    No Restrictions.
      =============    ==========    ==========
-
-More info see section 5 in Documentation/virt/kvm/timekeeping.rst.

> diff --git a/Documentation/virt/kvm/timekeeping.rst
> b/Documentation/virt/kvm/timekeeping.rst
> index 21ae7efa29ba..c81383e38372 100644
> --- a/Documentation/virt/kvm/timekeeping.rst
> +++ b/Documentation/virt/kvm/timekeeping.rst
> @@ -13,6 +13,7 @@ Timekeeping Virtualization for X86-Based 
> Architectures
>     2) Timing Devices
>     3) TSC Hardware
>     4) Virtualization Problems
> +   5) KVM virtual PTP clock
> 
>  1. Overview
>  ===========
> @@ -643,3 +644,37 @@ by using CPU utilization itself as a signalling
> channel.  Preventing such
>  problems would require completely isolated virtual time which may not 
> track
>  real time any longer.  This may be useful in certain security or QA 
> contexts,
>  but in general isn't recommended for real-world deployment scenarios.
> +
> +5. KVM virtual PTP clock
> +========================
> +
> +NTP (Network Time Protocol) is often used to sync time in a VM. 
> Unfortunately,
> +the precision of NTP is limited due to unknown delays in the network.
> +
> +KVM virtual PTP clock (PTP_KVM) offers another way to sync time in VM; 
> use the
> +host's clock rather than one from a remote machine. Having a 
> synchronization
> +mechanism for the virtualization environment allows us to keep all the 
> guests
> +running on the same host in sync.
> +In general, the delay of communication between host and guest is quite
> +small, so ptp_kvm can offer time sync precision up to in order of 
> nanoseconds.
> +Please keep in mind that ptp_kvm just limits itself to be a channel 
> which
> +transmits the remote clock from host to guest. An application, eg. 
> chrony, is
> +needed in usersapce of VM in order to set the guest time.
> +
> +After ptp_kvm is initialized, there will be a new device node under 
> /dev called
> +ptp%d. A guest userspace service, like chrony, can use this device to 
> get host
> +walltime, sometimes also counter cycle, which depends on the service 
> it calls.
> +Then this guest userspace service can use those data to do the time 
> sync for
> +the guest.
> +The following is the work flow of ptp_kvm:
> +
> +a) time sync service in guest userspace call ioctl on ptp device 
> /dev/ptp%d.
> +b) ptp_kvm module in guest receives this request then invokes 
> hypercall to
> +   route into host kernel to request host's walltime/counter cycle.
> +c) ptp_kvm hypercall service on the host responds to the request and 
> sends data
> +   back.
> +d) ptp in guest copies the data to userspace.
> +
> +ptp_kvm consists of components running on the guest and host. Step 2
> consists of
> +a guest driver making a hypercall whilst step 3 involves the
> hypervisor responding
> +with information.

I don't think we need any of this here, as the whole file
focuses on x86-specific issues for timekeeping. If we want
to document KVM PTP, this should probably be a separate document.

Thanks,

         M.
-- 
Jazz is not dead. It just smells funny...

  reply	other threads:[~2021-02-02 13:43 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-09  6:09 [PATCH v16 0/9] Enable ptp_kvm for arm/arm64 Jianyong Wu
2020-12-09  6:09 ` Jianyong Wu
2020-12-09  6:09 ` Jianyong Wu
2020-12-09  6:09 ` [PATCH v16 1/9] arm64: Probe for the presence of KVM hypervisor Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2021-02-02 13:18   ` Marc Zyngier
2021-02-02 13:18     ` Marc Zyngier
2021-02-02 13:18     ` Marc Zyngier
2020-12-09  6:09 ` [PATCH v16 2/9] arm/arm64: KVM: Advertise KVM UID to guests via SMCCC Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2020-12-09  6:09 ` [PATCH v16 3/9] ptp: Reorganize ptp_kvm module to make it arch-independent Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2020-12-09 10:23   ` kernel test robot
2020-12-09 10:23     ` kernel test robot
2020-12-09 10:23   ` [RFC PATCH] ptp: clock_pair_gpa can be static kernel test robot
2020-12-09 10:23     ` kernel test robot
2021-02-02 13:23   ` [PATCH v16 3/9] ptp: Reorganize ptp_kvm module to make it arch-independent Marc Zyngier
2021-02-02 13:23     ` Marc Zyngier
2021-02-02 13:23     ` Marc Zyngier
2020-12-09  6:09 ` [PATCH v16 4/9] time: Add mechanism to recognize clocksource in time_get_snapshot Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2020-12-09  6:09 ` [PATCH v16 5/9] clocksource: Add clocksource id for arm arch counter Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2020-12-09  6:09 ` [PATCH v16 6/9] arm64/kvm: Add hypercall service for kvm ptp Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2021-02-02 13:32   ` Marc Zyngier
2021-02-02 13:32     ` Marc Zyngier
2021-02-02 13:32     ` Marc Zyngier
2020-12-09  6:09 ` [PATCH v16 7/9] ptp: arm/arm64: Enable ptp_kvm for arm/arm64 Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2021-02-02 13:37   ` Marc Zyngier
2021-02-02 13:37     ` Marc Zyngier
2021-02-02 13:37     ` Marc Zyngier
2020-12-09  6:09 ` [PATCH v16 8/9] doc: add ptp_kvm introduction for arm64 support Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2021-02-02 13:43   ` Marc Zyngier [this message]
2021-02-02 13:43     ` Marc Zyngier
2021-02-02 13:43     ` Marc Zyngier
2020-12-09  6:09 ` [PATCH v16 9/9] arm64: Add kvm capability check extension for ptp_kvm Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2020-12-09  6:09   ` Jianyong Wu
2021-02-02 13:44   ` Marc Zyngier
2021-02-02 13:44     ` Marc Zyngier
2021-02-02 13:44     ` Marc Zyngier
2021-01-06  8:29 ` [PATCH v16 0/9] Enable ptp_kvm for arm/arm64 Jianyong Wu
2021-01-06  8:29   ` Jianyong Wu
2021-01-06  8:29   ` Jianyong Wu
2021-02-02 14:15 ` Marc Zyngier
2021-02-02 14:15   ` Marc Zyngier
2021-02-02 14:15   ` Marc Zyngier
2021-02-03  2:40   ` Jianyong Wu
2021-02-03  2:40     ` Jianyong Wu
2021-02-03  2:40     ` Jianyong Wu

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=abe1ea58ddd13e43e62c25103e05fcf0@kernel.org \
    --to=maz@kernel.org \
    --cc=Andre.Przywara@arm.com \
    --cc=jianyong.wu@arm.com \
    --cc=john.stultz@linaro.org \
    --cc=justin.he@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nd@arm.com \
    --cc=netdev@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=richardcochran@gmail.com \
    --cc=steven.price@arm.com \
    --cc=tglx@linutronix.de \
    --cc=will@kernel.org \
    --cc=yangbo.lu@nxp.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.