Skip to content

Commit 9be3b2f

Browse files
ptp/kvm, arm_arch_timer: Set system_counterval_t.cs_id to constant
Identify the clocksources used by ptp_kvm by setting the clocksource ID enum constants. This avoids dereferencing struct clocksource. Once the system_counterval_t.cs member will be removed, this will also avoid the need to obtain clocksource pointers from kvm_arch_ptp_get_crosststamp(). The clocksource IDs are associated to timestamps requested from the KVM hypervisor, so the proper clocksource ID is known at the ptp_kvm request site. While at it, also make the ptp_kvm_get_time_fn() 'ret' variable type int as that's what the function return value is. Signed-off-by: Peter Hilber <peter.hilber@opensynergy.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20240201010453.2212371-6-peter.hilber@opensynergy.com
1 parent 576bd49 commit 9be3b2f

5 files changed

Lines changed: 16 additions & 9 deletions

File tree

drivers/clocksource/arm_arch_timer.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1807,7 +1807,8 @@ TIMER_ACPI_DECLARE(arch_timer, ACPI_SIG_GTDT, arch_timer_acpi_init);
18071807
#endif
18081808

18091809
int kvm_arch_ptp_get_crosststamp(u64 *cycle, struct timespec64 *ts,
1810-
struct clocksource **cs)
1810+
struct clocksource **cs,
1811+
enum clocksource_ids *cs_id)
18111812
{
18121813
struct arm_smccc_res hvc_res;
18131814
u32 ptp_counter;
@@ -1833,6 +1834,8 @@ int kvm_arch_ptp_get_crosststamp(u64 *cycle, struct timespec64 *ts,
18331834
*cycle = (u64)hvc_res.a2 << 32 | hvc_res.a3;
18341835
if (cs)
18351836
*cs = &clocksource_counter;
1837+
if (cs_id)
1838+
*cs_id = CSID_ARM_ARCH_COUNTER;
18361839

18371840
return 0;
18381841
}

drivers/ptp/ptp_kvm_arm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@ void kvm_arch_ptp_exit(void)
2828

2929
int kvm_arch_ptp_get_clock(struct timespec64 *ts)
3030
{
31-
return kvm_arch_ptp_get_crosststamp(NULL, ts, NULL);
31+
return kvm_arch_ptp_get_crosststamp(NULL, ts, NULL, NULL);
3232
}

drivers/ptp/ptp_kvm_common.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*
55
* Copyright (C) 2017 Red Hat Inc.
66
*/
7-
#include <linux/clocksource.h>
87
#include <linux/device.h>
98
#include <linux/err.h>
109
#include <linux/init.h>
@@ -29,15 +28,16 @@ static int ptp_kvm_get_time_fn(ktime_t *device_time,
2928
struct system_counterval_t *system_counter,
3029
void *ctx)
3130
{
32-
long ret;
33-
u64 cycle;
31+
enum clocksource_ids cs_id;
3432
struct timespec64 tspec;
3533
struct clocksource *cs;
34+
u64 cycle;
35+
int ret;
3636

3737
spin_lock(&kvm_ptp_lock);
3838

3939
preempt_disable_notrace();
40-
ret = kvm_arch_ptp_get_crosststamp(&cycle, &tspec, &cs);
40+
ret = kvm_arch_ptp_get_crosststamp(&cycle, &tspec, &cs, &cs_id);
4141
if (ret) {
4242
spin_unlock(&kvm_ptp_lock);
4343
preempt_enable_notrace();
@@ -48,7 +48,7 @@ static int ptp_kvm_get_time_fn(ktime_t *device_time,
4848

4949
system_counter->cycles = cycle;
5050
system_counter->cs = cs;
51-
system_counter->cs_id = cs->id;
51+
system_counter->cs_id = cs_id;
5252

5353
*device_time = timespec64_to_ktime(tspec);
5454

drivers/ptp/ptp_kvm_x86.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ int kvm_arch_ptp_get_clock(struct timespec64 *ts)
9393
}
9494

9595
int kvm_arch_ptp_get_crosststamp(u64 *cycle, struct timespec64 *tspec,
96-
struct clocksource **cs)
96+
struct clocksource **cs,
97+
enum clocksource_ids *cs_id)
9798
{
9899
struct pvclock_vcpu_time_info *src;
99100
unsigned int version;
@@ -124,6 +125,7 @@ int kvm_arch_ptp_get_crosststamp(u64 *cycle, struct timespec64 *tspec,
124125
} while (pvclock_read_retry(src, version));
125126

126127
*cs = &kvm_clock;
128+
*cs_id = CSID_X86_KVM_CLK;
127129

128130
return 0;
129131
}

include/linux/ptp_kvm.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef _PTP_KVM_H_
99
#define _PTP_KVM_H_
1010

11+
#include <linux/clocksource_ids.h>
1112
#include <linux/types.h>
1213

1314
struct timespec64;
@@ -17,6 +18,7 @@ int kvm_arch_ptp_init(void);
1718
void kvm_arch_ptp_exit(void);
1819
int kvm_arch_ptp_get_clock(struct timespec64 *ts);
1920
int kvm_arch_ptp_get_crosststamp(u64 *cycle,
20-
struct timespec64 *tspec, struct clocksource **cs);
21+
struct timespec64 *tspec, struct clocksource **cs,
22+
enum clocksource_ids *cs_id);
2123

2224
#endif /* _PTP_KVM_H_ */

0 commit comments

Comments
 (0)