xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Cooper <andrew.cooper3@citrix.com>
To: Xen-devel <xen-devel@lists.xen.org>
Cc: "Andrew Cooper" <andrew.cooper3@citrix.com>,
	"Wei Liu" <wei.liu2@citrix.com>,
	"Jan Beulich" <JBeulich@suse.com>,
	"Roger Pau Monné" <roger.pau@citrix.com>
Subject: [PATCH 3/5] x86/time: Rework pv_soft_rdtsc() to aid further cleanup
Date: Tue, 20 Feb 2018 11:58:41 +0000	[thread overview]
Message-ID: <1519127923-23539-4-git-send-email-andrew.cooper3@citrix.com> (raw)
In-Reply-To: <1519127923-23539-1-git-send-email-andrew.cooper3@citrix.com>

Having pv_soft_rdtsc() emulate all parts of an rdtscp is awkward, and gets in
the way of some intended cleanup.

 * Drop the rdtscp parameter and always make the caller responsible for ecx
   updates when appropriate.
 * Switch the function from being void, and return the main timestamp in the
   return value.

The regs parameter is still needed, but only for the stats collection, once
again bringing into question their utility.  The parameter can however switch
to being const.

No functional change.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
---
 xen/arch/x86/pv/emul-inv-op.c  |  7 ++++++-
 xen/arch/x86/pv/emul-priv-op.c | 12 ++++++++----
 xen/arch/x86/time.c            |  8 ++------
 xen/include/asm-x86/time.h     |  2 +-
 4 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/xen/arch/x86/pv/emul-inv-op.c b/xen/arch/x86/pv/emul-inv-op.c
index f894417..b1916b4 100644
--- a/xen/arch/x86/pv/emul-inv-op.c
+++ b/xen/arch/x86/pv/emul-inv-op.c
@@ -46,6 +46,7 @@ static int emulate_invalid_rdtscp(struct cpu_user_regs *regs)
     char opcode[3];
     unsigned long eip, rc;
     struct vcpu *v = current;
+    struct domain *currd = v->domain;
 
     eip = regs->rip;
     if ( (rc = copy_from_user(opcode, (char *)eip, sizeof(opcode))) != 0 )
@@ -56,7 +57,11 @@ static int emulate_invalid_rdtscp(struct cpu_user_regs *regs)
     if ( memcmp(opcode, "\xf\x1\xf9", sizeof(opcode)) )
         return 0;
     eip += sizeof(opcode);
-    pv_soft_rdtsc(v, regs, 1);
+
+    msr_split(regs, pv_soft_rdtsc(v, regs));
+    regs->rcx = ((currd->arch.tsc_mode == TSC_MODE_PVRDTSCP)
+                 ? currd->arch.incarnation : 0);
+
     pv_emul_instruction_done(regs, eip);
     return EXCRET_fault_fixed;
 }
diff --git a/xen/arch/x86/pv/emul-priv-op.c b/xen/arch/x86/pv/emul-priv-op.c
index 17aaf97..d4d64f2 100644
--- a/xen/arch/x86/pv/emul-priv-op.c
+++ b/xen/arch/x86/pv/emul-priv-op.c
@@ -1374,10 +1374,14 @@ int pv_emulate_privileged_op(struct cpu_user_regs *regs)
     case X86EMUL_OKAY:
         if ( ctxt.tsc & TSC_BASE )
         {
-            if ( ctxt.tsc & TSC_AUX )
-                pv_soft_rdtsc(curr, regs, 1);
-            else if ( currd->arch.vtsc )
-                pv_soft_rdtsc(curr, regs, 0);
+            if ( currd->arch.vtsc || (ctxt.tsc & TSC_AUX) )
+            {
+                msr_split(regs, pv_soft_rdtsc(curr, regs));
+
+                if ( ctxt.tsc & TSC_AUX )
+                    regs->rcx = ((currd->arch.tsc_mode == TSC_MODE_PVRDTSCP)
+                                 ? currd->arch.incarnation : 0);
+            }
             else
                 msr_split(regs, rdtsc());
         }
diff --git a/xen/arch/x86/time.c b/xen/arch/x86/time.c
index c90524d..c4ca515 100644
--- a/xen/arch/x86/time.c
+++ b/xen/arch/x86/time.c
@@ -2024,7 +2024,7 @@ u64 gtsc_to_gtime(struct domain *d, u64 tsc)
     return time;
 }
 
-void pv_soft_rdtsc(struct vcpu *v, struct cpu_user_regs *regs, int rdtscp)
+uint64_t pv_soft_rdtsc(struct vcpu *v, const struct cpu_user_regs *regs)
 {
     s_time_t now = get_s_time();
     struct domain *d = v->domain;
@@ -2045,11 +2045,7 @@ void pv_soft_rdtsc(struct vcpu *v, struct cpu_user_regs *regs, int rdtscp)
 
     spin_unlock(&d->arch.vtsc_lock);
 
-    msr_split(regs, gtime_to_gtsc(d, now));
-
-    if ( rdtscp )
-         regs->rcx =
-             (d->arch.tsc_mode == TSC_MODE_PVRDTSCP) ? d->arch.incarnation : 0;
+    return gtime_to_gtsc(d, now);
 }
 
 bool clocksource_is_tsc(void)
diff --git a/xen/include/asm-x86/time.h b/xen/include/asm-x86/time.h
index 046302e..3bac74c 100644
--- a/xen/include/asm-x86/time.h
+++ b/xen/include/asm-x86/time.h
@@ -56,7 +56,7 @@ uint64_t ns_to_acpi_pm_tick(uint64_t ns);
 
 uint64_t tsc_ticks2ns(uint64_t ticks);
 
-void pv_soft_rdtsc(struct vcpu *v, struct cpu_user_regs *regs, int rdtscp);
+uint64_t pv_soft_rdtsc(struct vcpu *v, const struct cpu_user_regs *regs);
 u64 gtime_to_gtsc(struct domain *d, u64 time);
 u64 gtsc_to_gtime(struct domain *d, u64 tsc);
 
-- 
2.1.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

  parent reply	other threads:[~2018-02-20 11:58 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-20 11:58 [RFC PATCH 0/5] x86: Multiple fixes to MSR_TSC_AUX and RDTSCP handling for guests Andrew Cooper
2018-02-20 11:58 ` [PATCH 1/5] x86/hvm: Don't shadow the domain parameter in hvm_save_cpu_msrs() Andrew Cooper
2018-02-20 14:54   ` Roger Pau Monné
2018-02-20 15:12   ` Wei Liu
2018-02-23 13:53   ` Jan Beulich
2018-02-20 11:58 ` [PATCH 2/5] x86/pv: Avoid leaking other guests' MSR_TSC_AUX values into PV context Andrew Cooper
2018-02-20 15:22   ` Wei Liu
2018-02-20 15:26     ` Andrew Cooper
2018-02-20 15:32       ` Wei Liu
2018-02-20 15:49   ` Roger Pau Monné
2018-02-23 14:04   ` Jan Beulich
2018-02-23 14:22     ` Andrew Cooper
2018-02-23 15:09       ` Jan Beulich
2018-02-26 11:25   ` Jan Beulich
2018-02-26 19:11     ` [ping] " Andrew Cooper
2018-02-27  5:38       ` Tian, Kevin
2018-02-26 19:52   ` Boris Ostrovsky
2018-02-20 11:58 ` Andrew Cooper [this message]
2018-02-20 15:32   ` [PATCH 3/5] x86/time: Rework pv_soft_rdtsc() to aid further cleanup Wei Liu
2018-02-20 16:04   ` Roger Pau Monné
2018-02-20 16:07     ` Andrew Cooper
2018-02-23 14:38   ` Jan Beulich
2018-02-20 11:58 ` [PATCH 4/5] x86/pv: Remove deferred RDTSC{, P} handling in pv_emulate_privileged_op() Andrew Cooper
2018-02-20 16:08   ` Wei Liu
2018-02-20 16:28   ` Roger Pau Monné
2018-02-20 16:37     ` Andrew Cooper
2018-02-20 17:40       ` Roger Pau Monné
2018-02-23 14:40   ` Jan Beulich
2018-02-20 11:58 ` [PATCH 5/5] x86: Rework MSR_TSC_AUX handling from scratch Andrew Cooper
2018-02-20 17:03   ` Wei Liu
2018-02-20 17:42     ` Andrew Cooper
2018-02-21 11:08       ` Wei Liu
2018-02-20 17:35   ` Roger Pau Monné
2018-02-20 18:28     ` Andrew Cooper
2018-02-21 10:13       ` Roger Pau Monné
2018-02-21 11:36   ` [PATCH v2 " Andrew Cooper
2018-02-21 12:06     ` Wei Liu
2018-02-21 13:04     ` Roger Pau Monné
2018-02-23 15:05     ` Jan Beulich
2018-02-23 15:51       ` Andrew Cooper
2018-02-26 11:30         ` Jan Beulich
2018-02-26 19:12 ` [RFC PATCH 0/5] x86: Multiple fixes to MSR_TSC_AUX and RDTSCP handling for guests Andrew Cooper
2018-02-26 19:44   ` Boris Ostrovsky
2018-02-26 23:30     ` Andrew Cooper
2018-03-09 18:05       ` Boris Ostrovsky
2018-03-09 18:41         ` Andrew Cooper
2018-03-09 19:10           ` Boris Ostrovsky

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=1519127923-23539-4-git-send-email-andrew.cooper3@citrix.com \
    --to=andrew.cooper3@citrix.com \
    --cc=JBeulich@suse.com \
    --cc=roger.pau@citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xen.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).