diff mbox

[v1] x86/hvm: Expose MSR_SHADOW_GS_BASE

Message ID 1504262665-28092-1-git-send-email-aisaila@bitdefender.com (mailing list archive)
State New, archived
Headers show

Commit Message

Alexandru Stefan ISAILA Sept. 1, 2017, 10:44 a.m. UTC
This patch is adding an new param in the hvm_hw_cpu structure
so it can be exposed to user space.

Signed-off-by: Alexandru Isaila <aisaila@bitdefender.com>
---
 xen/arch/x86/hvm/hvm.c                 | 4 ++++
 xen/include/public/arch-x86/hvm/save.h | 2 ++
 2 files changed, 6 insertions(+)

Comments

Andrew Cooper Sept. 1, 2017, 10:55 a.m. UTC | #1
On 01/09/17 11:44, Alexandru Isaila wrote:
> diff --git a/xen/include/public/arch-x86/hvm/save.h b/xen/include/public/arch-x86/hvm/save.h
> index fd7bf3f..e6e8e87 100644
> --- a/xen/include/public/arch-x86/hvm/save.h
> +++ b/xen/include/public/arch-x86/hvm/save.h
> @@ -134,6 +134,8 @@ struct hvm_hw_cpu {
>      /* msr for em64t */
>      uint64_t shadow_gs;
>  
> +    uint64_t shadow_gs_base;
> +

You presumably haven't tried migrating across this boundary?  (Things
will explode rather impressively when you try to restore LSTAR into SMASK.)

What's wrong with the shadow_gs in context here?

~Andrew

>      /* msr content saved/restored. */
>      uint64_t msr_flags; /* Obsolete, ignored. */
>      uint64_t msr_lstar;
Jan Beulich Sept. 1, 2017, 10:55 a.m. UTC | #2
>>> On 01.09.17 at 12:44, <aisaila@bitdefender.com> wrote:
> This patch is adding an new param in the hvm_hw_cpu structure
> so it can be exposed to user space.

But you don't say why.

> --- a/xen/include/public/arch-x86/hvm/save.h
> +++ b/xen/include/public/arch-x86/hvm/save.h
> @@ -134,6 +134,8 @@ struct hvm_hw_cpu {
>      /* msr for em64t */
>      uint64_t shadow_gs;
>  
> +    uint64_t shadow_gs_base;

You can't alter a public interface structure like this. The one here
is used for migration, so migrating guests from an older hypervisor
would break.

But what's more funny - you're adding a field next to what looks
like already has the value you're after.

Jan
Razvan Cojocaru Sept. 1, 2017, 11:09 a.m. UTC | #3
On 01.09.2017 13:55, Andrew Cooper wrote:
> On 01/09/17 11:44, Alexandru Isaila wrote:
>> diff --git a/xen/include/public/arch-x86/hvm/save.h b/xen/include/public/arch-x86/hvm/save.h
>> index fd7bf3f..e6e8e87 100644
>> --- a/xen/include/public/arch-x86/hvm/save.h
>> +++ b/xen/include/public/arch-x86/hvm/save.h
>> @@ -134,6 +134,8 @@ struct hvm_hw_cpu {
>>       /* msr for em64t */
>>       uint64_t shadow_gs;
>>   
>> +    uint64_t shadow_gs_base;
>> +
> 
> You presumably haven't tried migrating across this boundary?  (Things
> will explode rather impressively when you try to restore LSTAR into SMASK.)
> 
> What's wrong with the shadow_gs in context here?

Nothing, we've missed that, while grepping xen/ for MSR_SHADOW_GS_BASE 
and 0xc0000102. My fault, should have checked more thoroughly. Apologies.


Thanks,
Razvan
diff mbox

Patch

diff --git a/xen/arch/x86/hvm/hvm.c b/xen/arch/x86/hvm/hvm.c
index 6cb903d..519333c 100644
--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -834,6 +834,8 @@  static int hvm_save_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)
         ctxt.gs_base = seg.base;
         ctxt.gs_arbytes = seg.attr;
 
+        rdmsrl(MSR_SHADOW_GS_BASE, ctxt.shadow_gs_base);
+
         hvm_get_segment_register(v, x86_seg_tr, &seg);
         ctxt.tr_sel = seg.sel;
         ctxt.tr_limit = seg.limit;
@@ -1090,6 +1092,8 @@  static int hvm_load_cpu_ctxt(struct domain *d, hvm_domain_context_t *h)
     seg.attr = ctxt.gs_arbytes;
     hvm_set_segment_register(v, x86_seg_gs, &seg);
 
+    wrmsrl(MSR_SHADOW_GS_BASE, ctxt.shadow_gs_base);
+
     seg.sel = ctxt.tr_sel;
     seg.limit = ctxt.tr_limit;
     seg.base = ctxt.tr_base;
diff --git a/xen/include/public/arch-x86/hvm/save.h b/xen/include/public/arch-x86/hvm/save.h
index fd7bf3f..e6e8e87 100644
--- a/xen/include/public/arch-x86/hvm/save.h
+++ b/xen/include/public/arch-x86/hvm/save.h
@@ -134,6 +134,8 @@  struct hvm_hw_cpu {
     /* msr for em64t */
     uint64_t shadow_gs;
 
+    uint64_t shadow_gs_base;
+
     /* msr content saved/restored. */
     uint64_t msr_flags; /* Obsolete, ignored. */
     uint64_t msr_lstar;