[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[xen staging] x86/time: use fake read_tsc()



commit 120e26c2bb0097a589d718b1b58d7052ccce4458
Author:     Jan Beulich <jbeulich@xxxxxxxx>
AuthorDate: Tue Apr 5 11:40:58 2022 +0200
Commit:     Jan Beulich <jbeulich@xxxxxxxx>
CommitDate: Tue Apr 5 11:40:58 2022 +0200

    x86/time: use fake read_tsc()
    
    Go a step further than bed9ae54df44 ("x86/time: switch platform timer
    hooks to altcall") did and eliminate the "real" read_tsc() altogether:
    It's not used except in pointer comparisons, and hence it looks overall
    more safe to simply poison plt_tsc's read_counter hook.
    
    Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>
    Reviewed-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
---
 xen/arch/x86/time.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
index 90fbd23cc0..b01acd390d 100644
--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -607,16 +607,18 @@ static s64 __init cf_check init_tsc(struct 
platform_timesource *pts)
     return ret;
 }
 
-static uint64_t __init cf_check read_tsc(void)
-{
-    return rdtsc_ordered();
-}
+/*
+ * plt_tsc's read_counter hook is not (and should not be) invoked via the
+ * struct field. To avoid carrying an unused, indirectly reachable function,
+ * poison the field with an easily identifiable non-canonical pointer.
+ */
+#define READ_TSC_POISON ((uint64_t(*)(void))0x75C75C75C75C75C0ul)
 
 static struct platform_timesource __initdata_cf_clobber plt_tsc =
 {
     .id = "tsc",
     .name = "TSC",
-    .read_counter = read_tsc,
+    .read_counter = READ_TSC_POISON,
     /*
      * Calculations for platform timer overflow assume u64 boundary.
      * Hence we set to less than 64, such that the TSC wraparound is
@@ -846,7 +848,7 @@ static uint64_t read_counter(void)
      * hence we can't invoke read_tsc() that way. Special case it here, open-
      * coding the function call at the same time.
      */
-    return plt_src.read_counter != read_tsc
+    return plt_src.read_counter != READ_TSC_POISON
            ? alternative_call(plt_src.read_counter)
            : rdtsc_ordered();
 }
@@ -2510,7 +2512,7 @@ uint64_t pv_soft_rdtsc(const struct vcpu *v, const struct 
cpu_user_regs *regs)
 
 bool clocksource_is_tsc(void)
 {
-    return plt_src.read_counter == read_tsc;
+    return plt_src.read_counter == READ_TSC_POISON;
 }
 
 int host_tsc_is_safe(void)
--
generated by git-patchbot for /home/xen/git/xen.git#staging



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.