Skip to contentSkip to conversation

xen: x86: copy back tsc info, not pointer to tsc info in domctl

PATCH Superseded Ian Campbell 2 participants 4 messages May 26, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xen: x86: copy back tsc info, not pointer to tsc info in domctl

In 38b37ed82705 "x86/domctl: cleanup", XEN_DOMCTL_gettscinfo was changed to use the standard copyback mechanism.

However the output TSC Info is a guerst handle, i.e. a pointer to the location for the information, copyback just copies the unchanged pointer back.

Switch back to fetching the details into a local struct and explicitly copying it back.

This caused test failures in the Cambridge instance of osstest, but not for some reason in the production instance.

---
 xen/arch/x86/domctl.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
xen/arch/x86/domctl.c +8 -5
index 684259b..e7da735 100644
@@ -703,13 +703,16 @@ long arch_do_domctl(
             ret = -EINVAL;
         else
         {
+            xen_guest_tsc_info_t info = { 0 };
+
             domain_pause(d);
-            tsc_get_info(d, &domctl->u.tsc_info.info.tsc_mode,
-                         &domctl->u.tsc_info.info.elapsed_nsec,
-                         &domctl->u.tsc_info.info.gtsc_khz,
-                         &domctl->u.tsc_info.info.incarnation);
+            tsc_get_info(d, &info.tsc_mode,
+                            &info.elapsed_nsec,
+                            &info.gtsc_khz,
+                            &info.incarnation);
+            if ( copy_to_guest(domctl->u.tsc_info.out_info, &info, 1) )
+                ret = -EFAULT;
             domain_unpause(d);
-            copyback = 1;
         }
         break;
 
Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 7 lines · Ian Campbell

In 38b37ed82705 "x86/domctl: cleanup", XEN_DOMCTL_gettscinfo was changed to use the standard copyback mechanism.

However the output TSC Info is a guerst handle, i.e. a pointer to the location for the information, copyback just copies the unchanged pointer back.

Quoted 7 lines

Switch back to fetching the details into a local struct and explicitly copying it back.

This caused test failures in the Cambridge instance of osstest, but not for some reason in the production instance.

Oops - I feel very silly for not noticing that. My testing also didn't notice this.

Quoted 16 lines
---
 xen/arch/x86/domctl.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
xen/arch/x86/domctl.c +2 -1
index 684259b..e7da735 100644
@@ -703,13 +703,16 @@ long arch_do_domctl(
             ret = -EINVAL;
         else
         {
+            xen_guest_tsc_info_t info = { 0 };
+
             domain_pause(d);
-            tsc_get_info(d, &domctl->u.tsc_info.info.tsc_mode,

xen/arch/x86/domctl.c long arch_do_domctl( · line 715

Quoted 10 lines
xen/arch/x86/domctl.c +6 -3
-                         &domctl->u.tsc_info.info.elapsed_nsec,
-                         &domctl->u.tsc_info.info.gtsc_khz,
-                         &domctl->u.tsc_info.info.incarnation);
+            tsc_get_info(d, &info.tsc_mode,
+                            &info.elapsed_nsec,
+                            &info.gtsc_khz,
+                            &info.incarnation);
+            if ( copy_to_guest(domctl->u.tsc_info.out_info, &info, 1) )
+                ret = -EFAULT;
             domain_unpause(d);

The copy_to_guest() can be after the domain_unpause().

Alternatively, being a domctl, we can change tsc_info to not be a guest handle. There is plenty of space inside the union, and it saves a further memory access.

~Andrew

#2 lore raw
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Ian Campbell

In 38b37ed82705 "x86/domctl: cleanup", XEN_DOMCTL_gettscinfo was changed to use the standard copyback mechanism.

However the output TSC Info is a guerst handle, i.e. a pointer to the location for the information, copyback just copies the unchanged pointer back.

Switch back to fetching the details into a local struct and explicitly copying it back.

Quoted 7 lines
Quoted 4 lines

This caused test failures in the Cambridge instance of osstest, but not for some reason in the production instance.

Oops - I feel very silly for not noticing that. My testing also didn't notice this.

It's pretty subtle.

My best guess is that the h/w in Cambridge tends to be older and therefore perhaps doesn't all have synchronous TSCs or something.

Quoted 20 lines
Quoted 20 lines
---
 xen/arch/x86/domctl.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
xen/arch/x86/domctl.c +3 -4
index 684259b..e7da735 100644
@@ -703,13 +703,16 @@ long arch_do_domctl(
             ret = -EINVAL;
         else
         {
+            xen_guest_tsc_info_t info = { 0 };
+
             domain_pause(d);
-            tsc_get_info(d, &domctl->u.tsc_info.info.tsc_mode,
-                         &domctl->u.tsc_info.info.elapsed_nsec,
-                         &domctl->u.tsc_info.info.gtsc_khz,
-                         &domctl->u.tsc_info.info.incarnation);
+            tsc_get_info(d, &info.tsc_mode,
Quoted 8 lines

xen/arch/x86/domctl.c long arch_do_domctl( · line 715

Quoted 6 lines
xen/arch/x86/domctl.c +5 -0
+                            &info.elapsed_nsec,
+                            &info.gtsc_khz,
+                            &info.incarnation);
+            if ( copy_to_guest(domctl->u.tsc_info.out_info, &info, 1) )
+                ret = -EFAULT;
             domain_unpause(d);

The copy_to_guest() can be after the domain_unpause().

So it can.

Quoted 3 lines

Alternatively, being a domctl, we can change tsc_info to not be a guest handle. There is plenty of space inside the union, and it saves a further memory access.

If you prefer, sure.

Perhaps fix then cleanup in a separate patch?

Ian.

#3 lore raw
Quoted 50 lines · Ian Campbell
Quoted 11 lines · Andrew Cooper
Quoted 10 lines · Ian Campbell

In 38b37ed82705 "x86/domctl: cleanup", XEN_DOMCTL_gettscinfo was changed to use the standard copyback mechanism.

However the output TSC Info is a guerst handle, i.e. a pointer to the location for the information, copyback just copies the unchanged pointer back.

Switch back to fetching the details into a local struct and explicitly copying it back.

Quoted 6 lines
Quoted 4 lines

This caused test failures in the Cambridge instance of osstest, but not for some reason in the production instance.

Oops - I feel very silly for not noticing that. My testing also didn't notice this.

It's pretty subtle.

My best guess is that the h/w in Cambridge tends to be older and therefore perhaps doesn't all have synchronous TSCs or something.

Quoted 19 lines
Quoted 19 lines
---
 xen/arch/x86/domctl.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
xen/arch/x86/domctl.c +2 -4
index 684259b..e7da735 100644
@@ -703,13 +703,16 @@ long arch_do_domctl(
             ret = -EINVAL;
         else
         {
+            xen_guest_tsc_info_t info = { 0 };
+
             domain_pause(d);
-            tsc_get_info(d, &domctl->u.tsc_info.info.tsc_mode,
-                         &domctl->u.tsc_info.info.elapsed_nsec,
-                         &domctl->u.tsc_info.info.gtsc_khz,
-                         &domctl->u.tsc_info.info.incarnation);
Quoted 8 lines

xen/arch/x86/domctl.c long arch_do_domctl( · line 715

Quoted 7 lines
xen/arch/x86/domctl.c +6 -0
+            tsc_get_info(d, &info.tsc_mode,
+                            &info.elapsed_nsec,
+                            &info.gtsc_khz,
+                            &info.incarnation);
+            if ( copy_to_guest(domctl->u.tsc_info.out_info, &info, 1) )
+                ret = -EFAULT;
             domain_unpause(d);

The copy_to_guest() can be after the domain_unpause().

Quoted 8 lines

So it can.

Quoted 3 lines

Alternatively, being a domctl, we can change tsc_info to not be a guest handle. There is plenty of space inside the union, and it saves a further memory access.

If you prefer, sure.

Perhaps fix then cleanup in a separate patch?

Can do.

For this patch (subject to the reordering), Reviewed-by: Andrew Cooper <[email protected]>

Quoted 4 lines

Ian.