Re: [PATCH v19 3/7] ptp: Reorganize ptp_kvm.c to make it arch-independent

2021-04-07 Thread Marc Zyngier
On Wed, 07 Apr 2021 16:13:34 +0100,
Richard Cochran  wrote:
> 
> On Wed, Apr 07, 2021 at 10:28:44AM +0100, Marc Zyngier wrote:
> > On Tue, 30 Mar 2021 15:54:26 +0100,
> > Marc Zyngier  wrote:
> > > 
> > > From: Jianyong Wu 
> > > 
> > > Currently, the ptp_kvm module contains a lot of x86-specific code.
> > > Let's move this code into a new arch-specific file in the same directory,
> > > and rename the arch-independent file to ptp_kvm_common.c.
> > > 
> > > Reviewed-by: Andre Przywara 
> > > Signed-off-by: Jianyong Wu 
> > > Signed-off-by: Marc Zyngier 
> > > Link: 
> > > https://lore.kernel.org/r/20201209060932.212364-4-jianyong...@arm.com
> > 
> > Richard, Paolo,
> > 
> > Can I get an Ack on this and patch #7? We're getting pretty close to
> > the next merge window, and this series has been going on for a couple
> > of years now...
> 
> For both patches:
> 
> Acked-by: Richard Cochran 

Cheers Richard, much appreciated.

M.

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


Re: [PATCH v19 3/7] ptp: Reorganize ptp_kvm.c to make it arch-independent

2021-04-07 Thread Richard Cochran
On Wed, Apr 07, 2021 at 10:28:44AM +0100, Marc Zyngier wrote:
> On Tue, 30 Mar 2021 15:54:26 +0100,
> Marc Zyngier  wrote:
> > 
> > From: Jianyong Wu 
> > 
> > Currently, the ptp_kvm module contains a lot of x86-specific code.
> > Let's move this code into a new arch-specific file in the same directory,
> > and rename the arch-independent file to ptp_kvm_common.c.
> > 
> > Reviewed-by: Andre Przywara 
> > Signed-off-by: Jianyong Wu 
> > Signed-off-by: Marc Zyngier 
> > Link: https://lore.kernel.org/r/20201209060932.212364-4-jianyong...@arm.com
> 
> Richard, Paolo,
> 
> Can I get an Ack on this and patch #7? We're getting pretty close to
> the next merge window, and this series has been going on for a couple
> of years now...

For both patches:

Acked-by: Richard Cochran 


Re: [PATCH v19 3/7] ptp: Reorganize ptp_kvm.c to make it arch-independent

2021-04-07 Thread Marc Zyngier
On Tue, 30 Mar 2021 15:54:26 +0100,
Marc Zyngier  wrote:
> 
> From: Jianyong Wu 
> 
> Currently, the ptp_kvm module contains a lot of x86-specific code.
> Let's move this code into a new arch-specific file in the same directory,
> and rename the arch-independent file to ptp_kvm_common.c.
> 
> Reviewed-by: Andre Przywara 
> Signed-off-by: Jianyong Wu 
> Signed-off-by: Marc Zyngier 
> Link: https://lore.kernel.org/r/20201209060932.212364-4-jianyong...@arm.com

Richard, Paolo,

Can I get an Ack on this and patch #7? We're getting pretty close to
the next merge window, and this series has been going on for a couple
of years now...

Thanks,

M.

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


[PATCH v19 3/7] ptp: Reorganize ptp_kvm.c to make it arch-independent

2021-03-30 Thread Marc Zyngier
From: Jianyong Wu 

Currently, the ptp_kvm module contains a lot of x86-specific code.
Let's move this code into a new arch-specific file in the same directory,
and rename the arch-independent file to ptp_kvm_common.c.

Reviewed-by: Andre Przywara 
Signed-off-by: Jianyong Wu 
Signed-off-by: Marc Zyngier 
Link: https://lore.kernel.org/r/20201209060932.212364-4-jianyong...@arm.com
---
 drivers/ptp/Makefile|  1 +
 drivers/ptp/{ptp_kvm.c => ptp_kvm_common.c} | 84 +-
 drivers/ptp/ptp_kvm_x86.c   | 97 +
 include/linux/ptp_kvm.h | 19 
 4 files changed, 139 insertions(+), 62 deletions(-)
 rename drivers/ptp/{ptp_kvm.c => ptp_kvm_common.c} (60%)
 create mode 100644 drivers/ptp/ptp_kvm_x86.c
 create mode 100644 include/linux/ptp_kvm.h

diff --git a/drivers/ptp/Makefile b/drivers/ptp/Makefile
index db5aef3bddc6..d11eeb5811d1 100644
--- a/drivers/ptp/Makefile
+++ b/drivers/ptp/Makefile
@@ -4,6 +4,7 @@
 #
 
 ptp-y  := ptp_clock.o ptp_chardev.o ptp_sysfs.o
+ptp_kvm-$(CONFIG_X86)  := ptp_kvm_x86.o ptp_kvm_common.o
 obj-$(CONFIG_PTP_1588_CLOCK)   += ptp.o
 obj-$(CONFIG_PTP_1588_CLOCK_DTE)   += ptp_dte.o
 obj-$(CONFIG_PTP_1588_CLOCK_INES)  += ptp_ines.o
diff --git a/drivers/ptp/ptp_kvm.c b/drivers/ptp/ptp_kvm_common.c
similarity index 60%
rename from drivers/ptp/ptp_kvm.c
rename to drivers/ptp/ptp_kvm_common.c
index 658d33fc3195..721ddcede5e1 100644
--- a/drivers/ptp/ptp_kvm.c
+++ b/drivers/ptp/ptp_kvm_common.c
@@ -8,11 +8,11 @@
 #include 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
-#include 
-#include 
 #include 
 
 #include 
@@ -24,56 +24,29 @@ struct kvm_ptp_clock {
 
 static DEFINE_SPINLOCK(kvm_ptp_lock);
 
-static struct pvclock_vsyscall_time_info *hv_clock;
-
-static struct kvm_clock_pairing clock_pair;
-static phys_addr_t clock_pair_gpa;
-
 static int ptp_kvm_get_time_fn(ktime_t *device_time,
   struct system_counterval_t *system_counter,
   void *ctx)
 {
-   unsigned long ret;
+   long ret;
+   u64 cycle;
struct timespec64 tspec;
-   unsigned version;
-   int cpu;
-   struct pvclock_vcpu_time_info *src;
+   struct clocksource *cs;
 
spin_lock(_ptp_lock);
 
preempt_disable_notrace();
-   cpu = smp_processor_id();
-   src = _clock[cpu].pvti;
-
-   do {
-   /*
-* We are using a TSC value read in the hosts
-* kvm_hc_clock_pairing handling.
-* So any changes to tsc_to_system_mul
-* and tsc_shift or any other pvclock
-* data invalidate that measurement.
-*/
-   version = pvclock_read_begin(src);
-
-   ret = kvm_hypercall2(KVM_HC_CLOCK_PAIRING,
-clock_pair_gpa,
-KVM_CLOCK_PAIRING_WALLCLOCK);
-   if (ret != 0) {
-   pr_err_ratelimited("clock pairing hypercall ret %lu\n", 
ret);
-   spin_unlock(_ptp_lock);
-   preempt_enable_notrace();
-   return -EOPNOTSUPP;
-   }
-
-   tspec.tv_sec = clock_pair.sec;
-   tspec.tv_nsec = clock_pair.nsec;
-   ret = __pvclock_read_cycles(src, clock_pair.tsc);
-   } while (pvclock_read_retry(src, version));
+   ret = kvm_arch_ptp_get_crosststamp(, , );
+   if (ret) {
+   spin_unlock(_ptp_lock);
+   preempt_enable_notrace();
+   return ret;
+   }
 
preempt_enable_notrace();
 
-   system_counter->cycles = ret;
-   system_counter->cs = _clock;
+   system_counter->cycles = cycle;
+   system_counter->cs = cs;
 
*device_time = timespec64_to_ktime(tspec);
 
@@ -111,22 +84,17 @@ static int ptp_kvm_settime(struct ptp_clock_info *ptp,
 
 static int ptp_kvm_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts)
 {
-   unsigned long ret;
+   long ret;
struct timespec64 tspec;
 
spin_lock(_ptp_lock);
 
-   ret = kvm_hypercall2(KVM_HC_CLOCK_PAIRING,
-clock_pair_gpa,
-KVM_CLOCK_PAIRING_WALLCLOCK);
-   if (ret != 0) {
-   pr_err_ratelimited("clock offset hypercall ret %lu\n", ret);
+   ret = kvm_arch_ptp_get_clock();
+   if (ret) {
spin_unlock(_ptp_lock);
-   return -EOPNOTSUPP;
+   return ret;
}
 
-   tspec.tv_sec = clock_pair.sec;
-   tspec.tv_nsec = clock_pair.nsec;
spin_unlock(_ptp_lock);
 
memcpy(ts, , sizeof(struct timespec64));
@@ -168,19 +136,11 @@ static int __init ptp_kvm_init(void)
 {
long ret;
 
-   if (!kvm_para_available())
-   return -ENODEV;
-
-