Skip to contentSkip to conversation

viridian: implement synthetic timers

PATCH Superseded Paul Durrant 3 participants 31 messages Dec 20, 2018 – Jan 25, 2019

v1 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

cover viridian: implement synthetic timers

This is currently a fairly large feature gap between Xen and KVM.

Paul Durrant (8):
viridian: add init hooks
viridian: separately allocate domain and vcpu structures
viridian: extend init/deinit hooks into synic and time modules
viridian: add missing context save helpers into synic and time modules
viridian: use viridian_map/unmap_guest_page() for reference tsc page
viridian: add implementation of synthetic interrupt MSRs
viridian: stop directly calling
viridian_time_ref_count_freeze/thaw()...
viridian: add implementation of synthetic timers

 docs/man/xl.cfg.pod.5.in               |  12 +-
 tools/libxl/libxl.h                    |  12 +
 tools/libxl/libxl_dom.c                |   7 +
 tools/libxl/libxl_types.idl            |   2 +
 xen/arch/x86/domain.c                  |  12 +-
 xen/arch/x86/hvm/hvm.c                 |  14 +-
 xen/arch/x86/hvm/viridian/private.h    |  30 +-
 xen/arch/x86/hvm/viridian/synic.c      | 335 ++++++++++++++++--
 xen/arch/x86/hvm/viridian/time.c       | 452 ++++++++++++++++++++++---
 xen/arch/x86/hvm/viridian/viridian.c   | 137 ++++++--
 xen/arch/x86/hvm/vlapic.c              |  16 +-
 xen/include/asm-x86/hvm/domain.h       |   2 +-
 xen/include/asm-x86/hvm/hvm.h          |   7 +
 xen/include/asm-x86/hvm/vcpu.h         |   2 +-
 xen/include/asm-x86/hvm/viridian.h     |  63 +++-
 xen/include/public/arch-x86/hvm/save.h |   4 +
 xen/include/public/hvm/params.h        |  12 +-
 17 files changed, 1004 insertions(+), 115 deletions(-)

---
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Ian Jackson <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: Wei Liu <[email protected]>

Signature · 7 lines
2.20.1.2.gb21ebb671


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#1 lore raw

PATCH 1/8 viridian: add init hooks

This patch adds domain and vcpu init hooks for viridian features. The init hooks do not yet do anything; they will be added to by subsequent patches.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

---
 xen/arch/x86/hvm/hvm.c               | 14 +++++++++++++-
 xen/arch/x86/hvm/viridian/viridian.c | 10 ++++++++++
 xen/include/asm-x86/hvm/viridian.h   |  3 +++
 3 files changed, 26 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/hvm.c +13 -1
index d14ddcb527..6a1f18d8b5 100644
@@ -665,12 +665,18 @@ int hvm_domain_initialise(struct domain *d)
     if ( hvm_tsc_scaling_supported )
         d->arch.hvm.tsc_scaling_ratio = hvm_default_tsc_scaling_ratio;
 
+    rc = viridian_domain_init(d);
+    if ( rc )
+        goto fail2;
+
     rc = hvm_funcs.domain_initialise(d);
     if ( rc != 0 )
-        goto fail2;
+        goto fail3;
 
     return 0;
 
+ fail3:
+    viridian_domain_deinit(d);
  fail2:
     rtc_deinit(d);
     stdvga_deinit(d);
@@ -1539,6 +1545,10 @@ int hvm_vcpu_initialise(struct vcpu *v)
     if ( rc != 0 )
         goto fail6;
 
+    rc = viridian_vcpu_init(v);
+    if ( rc )
+        goto fail7;
+
     if ( v->vcpu_id == 0 )
     {
         /* NB. All these really belong in hvm_domain_initialise(). */
@@ -1551,6 +1561,8 @@ int hvm_vcpu_initialise(struct vcpu *v)
 
     return 0;
 
+ fail7:
+    hvm_all_ioreq_servers_remove_vcpu(d, v);
  fail6:
     nestedhvm_vcpu_destroy(v);
  fail5:
xen/arch/x86/hvm/viridian/viridian.c +10 -0
index c78b2918d9..ad110ee6f3 100644
@@ -417,6 +417,16 @@ int guest_rdmsr_viridian(const struct vcpu *v, uint32_t idx, uint64_t *val)
     return X86EMUL_OKAY;
 }
 
+int viridian_vcpu_init(struct vcpu *v)
+{
+    return 0;
+}
+
+int viridian_domain_init(struct domain *d)
+{
+    return 0;
+}
+
 void viridian_vcpu_deinit(struct vcpu *v)
 {
     viridian_synic_wrmsr(v, HV_X64_MSR_VP_ASSIST_PAGE, 0);
xen/include/asm-x86/hvm/viridian.h +3 -0
index ec5ef8d3f9..f072838955 100644
@@ -80,6 +80,9 @@ viridian_hypercall(struct cpu_user_regs *regs);
 void viridian_time_ref_count_freeze(struct domain *d);
 void viridian_time_ref_count_thaw(struct domain *d);
 
+int viridian_vcpu_init(struct vcpu *v);
+int viridian_domain_init(struct domain *d);
+
 void viridian_vcpu_deinit(struct vcpu *v);
 void viridian_domain_deinit(struct domain *d);
 
Signature · 7 lines
2.20.1.2.gb21ebb671


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 1/8
#2 lore raw

Re: [PATCH 1/8] viridian: add init hooks

Quoted 4 lines · Paul Durrant

This patch adds domain and vcpu init hooks for viridian features. The init hooks do not yet do anything; they will be added to by subsequent patches.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#3 lore raw

Re: [PATCH 1/8] viridian: add init hooks

In reply to Paul Durrant
Quoted 4 lines · Paul Durrant

This patch adds domain and vcpu init hooks for viridian features. The init hooks do not yet do anything; they will be added to by subsequent patches.

Please can we start by fixing the current, broken, initialisation and destruction logic ?

To get rid of DOMCTL_setmaxvcpus, we need the *_destroy() logic to be fully idempotent.  Also, viridian_domain_deinit() should not call into viridian_vcpu_deinit(), and viridian_vcpu_deinit() shouldn't be faking up a write to the assist page.

AFAICT, the deinit path is all entirely pointless at the moment and can be deleted.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#4 lore raw

Re: [PATCH 1/8] viridian: add init hooks

Quoted 8 lines · Andrew Cooper
Quoted 4 lines · Paul Durrant

This patch adds domain and vcpu init hooks for viridian features. The init hooks do not yet do anything; they will be added to by subsequent patches.

Please can we start by fixing the current, broken, initialisation and destruction logic ?

Quoted 7 lines

To get rid of DOMCTL_setmaxvcpus, we need the *_destroy() logic to be fully idempotent.  Also, viridian_domain_deinit() should not call into viridian_vcpu_deinit(), and viridian_vcpu_deinit() shouldn't be faking up a write to the assist page.

AFAICT, the deinit path is all entirely pointless at the moment and can be deleted.

Given that we are now going to be allocating non-trivial structures for viridian domains, I'd like to float the idea of changing viridian initialisation to be a domaincreate flag, rather than blindly assuming that all HVM guests want it.

I think this is going to be necessary part of fixing CPUID policy derivation in the longterm, because regenerating the policy when HVM_PARAM_VIRIDIAN changes isn't viable.

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#5 lore raw

Re: [PATCH 1/8] viridian: add init hooks

Quoted 24 lines

-----Original Message-----
From: Andrew Cooper
Sent: 02 January 2019 17:37
To: Paul Durrant <[email protected]>; [email protected]
Cc: Wei Liu <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>
Subject: Re: [Xen-devel] [PATCH 1/8] viridian: add init hooks

Quoted 2 lines · Andrew Cooper
Quoted 1 line · Paul Durrant

This patch adds domain and vcpu init hooks for viridian features. The

init

Quoted 1 line
Quoted 1 line

hooks do not yet do anything; they will be added to by subsequent

patches.

Quoted 10 lines
Quoted 2 lines

Please can we start by fixing the current, broken, initialisation and destruction logic ?

To get rid of DOMCTL_setmaxvcpus, we need the *_destroy() logic to be fully idempotent.  Also, viridian_domain_deinit() should not call into viridian_vcpu_deinit(), and viridian_vcpu_deinit() shouldn't be faking up a write to the assist page.

Quoted 7 lines
Quoted 2 lines

AFAICT, the deinit path is all entirely pointless at the moment and can be deleted.

Given that we are now going to be allocating non-trivial structures for viridian domains, I'd like to float the idea of changing viridian initialisation to be a domaincreate flag, rather than blindly assuming that all HVM guests want it.

That would certainly be cleaner but sounds non-trivial.

Quoted 5 lines

I think this is going to be necessary part of fixing CPUID policy derivation in the longterm, because regenerating the policy when HVM_PARAM_VIRIDIAN changes isn't viable.

Indeed, but again it's 'longterm'.

Paul

Quoted 1 line

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#6 lore raw

Re: [PATCH 1/8] viridian: add init hooks

Quoted 38 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Paul Durrant
Sent: 03 January 2019 09:08
To: Andrew Cooper <[email protected]>; xen- [email protected]
Cc: Wei Liu <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>
Subject: Re: [Xen-devel] [PATCH 1/8] viridian: add init hooks

Quoted 4 lines

-----Original Message-----
From: Andrew Cooper
Sent: 02 January 2019 17:37
To: Paul Durrant <[email protected]>; xen-

[email protected]

Quoted 1 line
Cc Wei Liu <[email protected]>; Jan Beulich <[email protected]>;

Roger

Quoted 20 lines

Pau Monne <[email protected]>
Subject: Re: [Xen-devel] [PATCH 1/8] viridian: add init hooks

Quoted 2 lines · Andrew Cooper
Quoted 1 line · Paul Durrant

This patch adds domain and vcpu init hooks for viridian features. The

init

Quoted 1 line
Quoted 1 line

hooks do not yet do anything; they will be added to by subsequent

patches.

Quoted 11 lines
Quoted 2 lines

Please can we start by fixing the current, broken, initialisation and destruction logic ?

To get rid of DOMCTL_setmaxvcpus, we need the *_destroy() logic to be fully idempotent.  Also, viridian_domain_deinit() should not call into viridian_vcpu_deinit(), and viridian_vcpu_deinit() shouldn't be faking up a write to the assist page.

AFAICT, the deinit path is all entirely pointless at the moment and

can

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

be deleted.

Given that we are now going to be allocating non-trivial structures for viridian domains, I'd like to float the idea of changing viridian initialisation to be a domaincreate flag, rather than blindly assuming that all HVM guests want it.

That would certainly be cleaner but sounds non-trivial.

Looking at this a little more... Viridian is an x86 specific thing, so an extra flag in xen_arch_domainconfig would seem most appropriate. This would then need to wired into the appropriate place(s) in libxl. I'll have a look at how much work this is likely to be.

Paul

Quoted 9 lines
Quoted 6 lines

I think this is going to be necessary part of fixing CPUID policy derivation in the longterm, because regenerating the policy when HVM_PARAM_VIRIDIAN changes isn't viable.

Indeed, but again it's 'longterm'.

Quoted 7 lines

Paul

Quoted 1 line

~Andrew

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#7 lore raw

Re: [PATCH 1/8] viridian: add init hooks

Quoted 62 lines

-----Original Message-----
From: Paul Durrant
Sent: 03 January 2019 10:38
To: Paul Durrant <[email protected]>; Andrew Cooper <[email protected]>; [email protected]
Cc: Wei Liu <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>
Subject: RE: [Xen-devel] [PATCH 1/8] viridian: add init hooks

Quoted 2 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On

Behalf

Quoted 5 lines

Of Paul Durrant
Sent: 03 January 2019 09:08
To: Andrew Cooper <[email protected]>; xen- [email protected]
Cc: Wei Liu <[email protected]>; Jan Beulich <[email protected]>;

Roger

Quoted 16 lines

Pau Monne <[email protected]>
Subject: Re: [Xen-devel] [PATCH 1/8] viridian: add init hooks

Quoted 4 lines

-----Original Message-----
From: Andrew Cooper
Sent: 02 January 2019 17:37
To: Paul Durrant <[email protected]>; xen-

[email protected]

Quoted 1 line
Cc Wei Liu <[email protected]>; Jan Beulich <[email protected]>;

Roger

Quoted 6 lines

Pau Monne <[email protected]>
Subject: Re: [Xen-devel] [PATCH 1/8] viridian: add init hooks

Quoted 2 lines · Andrew Cooper
Quoted 1 line · Paul Durrant

This patch adds domain and vcpu init hooks for viridian features.

The

Quoted 6 lines
Quoted 6 lines

init

Quoted 1 line
Quoted 1 line

hooks do not yet do anything; they will be added to by subsequent

patches.

Quoted 3 lines
Quoted 2 lines

Please can we start by fixing the current, broken, initialisation

and

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

destruction logic ?

To get rid of DOMCTL_setmaxvcpus, we need the *_destroy() logic to

be

Quoted 1 line
Quoted 1 line
Quoted 1 line

fully idempotent.  Also, viridian_domain_deinit() should not call

into

Quoted 1 line
Quoted 1 line
Quoted 1 line

viridian_vcpu_deinit(), and viridian_vcpu_deinit() shouldn't be

faking

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

up a write to the assist page.

AFAICT, the deinit path is all entirely pointless at the moment and

can

Quoted 3 lines
Quoted 1 line

be deleted.

Given that we are now going to be allocating non-trivial structures

for

Quoted 4 lines
Quoted 3 lines

viridian domains, I'd like to float the idea of changing viridian initialisation to be a domaincreate flag, rather than blindly assuming that all HVM guests want it.

Quoted 6 lines
Quoted 1 line

That would certainly be cleaner but sounds non-trivial.

Looking at this a little more... Viridian is an x86 specific thing, so an extra flag in xen_arch_domainconfig would seem most appropriate. This would then need to wired into the appropriate place(s) in libxl. I'll have a look at how much work this is likely to be.

Would something along the lines of the following (as yet untested and incomplete) patch be acceptable?

(I've blindly coded the Ocaml $MAGIC and just hardcoded the flag in the stub)

---8<---

tools/libxl/libxl_x86.c +6 -0
index c0f88a7eaa..17b1e9bf2a 100644
@@ -7,9 +7,15 @@ int libxl__arch_domain_prepare_config(libxl__gc *gc,
                                       libxl_domain_config *d_config,
                                       struct xen_domctl_createdomain *config)
 {
+    bool viridian;
+
+    viridian = libxl_defbool_val(d_config->b_info.u.hvm.viridian);
+
     switch(d_config->c_info.type) {
     case LIBXL_DOMAIN_TYPE_HVM:
         config->arch.emulation_flags = (XEN_X86_EMU_ALL & ~XEN_X86_EMU_VPCI);
+        if (viridian)
+            config->arch.feature_flags = XEN_X86_FEAT_VIRIDIAN;
         break;
     case LIBXL_DOMAIN_TYPE_PVH:
         config->arch.emulation_flags = XEN_X86_EMU_LAPIC;
tools/ocaml/libs/xc/xenctrl.ml +4 -0
index a57130a3c3..b8199776a7 100644
@@ -47,9 +47,13 @@ type x86_arch_emulation_flags =
        | X86_EMU_PIT
        | X86_EMU_USE_PIRQ
 
+type x86_arch_feature_flags =
+       | X86_FEAT_VIRIDIAN
+
 type xen_x86_arch_domainconfig =
 {
        emulation_flags: x86_arch_emulation_flags list;
+       feature_flags: x86_arch_feature_flags list;
 }
 
 type arch_domainconfig =
tools/ocaml/libs/xc/xenctrl.mli +4 -0
index 476bbecb90..a851fd115d 100644
@@ -41,8 +41,12 @@ type x86_arch_emulation_flags =
   | X86_EMU_PIT
   | X86_EMU_USE_PIRQ
 
+type x86_arch_feature_flags =
+  | X86_FEAT_VIRIDIAN
+
 type xen_x86_arch_domainconfig = {
   emulation_flags: x86_arch_emulation_flags list;
+  feature_flags: x86_arch_feature_flags list;
 }
 
 type arch_domainconfig =
tools/ocaml/libs/xc/xenctrl_stubs.c +1 -1
index c4fdc58b2d..a5ef3bb160 100644
@@ -166,7 +166,7 @@ CAMLprim value stub_xc_domain_create(value xch, value config)
                        cfg.arch.emulation_flags |= 1u << Int_val(Field(l, 0));
 
 #undef VAL_EMUL_FLAGS
-
+               cfg.arch.feature_flags = XEN_X86_FEAT_VIRIDIAN;
 #else
                caml_failwith("Unhandled: x86");
 #endif
xen/arch/x86/domain.c +4 -1
index ed2a57a8a6..c820cf334d 100644
@@ -586,7 +586,10 @@ int arch_domain_create(struct domain *d,
 
     if ( is_hvm_domain(d) )
     {
-        if ( (rc = hvm_domain_initialise(d)) != 0 )
+        bool enable_viridian =
+            config->arch.feature_flags & XEN_X86_FEAT_VIRIDIAN;
+
+        if ( (rc = hvm_domain_initialise(d, enable_viridian)) != 0 )
             goto fail;
     }
     else if ( is_pv_domain(d) )
xen/arch/x86/hvm/hvm.c +1 -1
index 6a1f18d8b5..351994e905 100644
@@ -575,7 +575,7 @@ static int hvm_print_line(
     return X86EMUL_OKAY;
 }
 
-int hvm_domain_initialise(struct domain *d)
+int hvm_domain_initialise(struct domain *d, bool enable_viridian)
 {
     unsigned int nr_gsis;
     int rc;
xen/include/asm-x86/hvm/hvm.h +1 -1
index 7892f98c7b..6bde613dd8 100644
@@ -241,7 +241,7 @@ extern s8 hvm_port80_allowed;
 extern const struct hvm_function_table *start_svm(void);
 extern const struct hvm_function_table *start_vmx(void);
 
-int hvm_domain_initialise(struct domain *d);
+int hvm_domain_initialise(struct domain *d, bool enable_viridian);
 void hvm_domain_relinquish_resources(struct domain *d);
 void hvm_domain_destroy(struct domain *d);
 void hvm_domain_soft_reset(struct domain *d);
xen/include/public/arch-x86/xen.h +4 -0
index 629cb2ba40..467aa8bbf0 100644
@@ -304,6 +304,10 @@ struct xen_arch_domainconfig {
                                      XEN_X86_EMU_PIT | XEN_X86_EMU_USE_PIRQ |\
                                      XEN_X86_EMU_VPCI)
     uint32_t emulation_flags;
+
+#define _XEN_X86_FEAT_VIRIDIAN      0
+#define XEN_X86_FEAT_VIRIDIAN       (1U<<_XEN_X86_FEAT_VIRIDIAN)
+    uint32_t feature_flags;
 };
 
 /* Location of online VCPU bitmap. */

---8<---

Paul
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#8 lore raw

Re: [PATCH 1/8] viridian: add init hooks

Quoted 1 line · Paul Durrant
Quoted 1 line

-----Original Message-----

[...]

Quoted 10 lines
Quoted 5 lines

Looking at this a little more... Viridian is an x86 specific thing, so an extra flag in xen_arch_domainconfig would seem most appropriate. This would then need to wired into the appropriate place(s) in libxl. I'll have a look at how much work this is likely to be.

Would something along the lines of the following (as yet untested and incomplete) patch be acceptable?

(I've blindly coded the Ocaml $MAGIC and just hardcoded the flag in the stub)

Not sure if your question is directed to me or not.

I think this patch is independent of this series to hand?

Quoted 12 lines

---8<---

xen/arch/x86/hvm/hvm.c +1 -1
-int hvm_domain_initialise(struct domain *d)
+int hvm_domain_initialise(struct domain *d, bool enable_viridian)
 {
     unsigned int nr_gsis;
     int rc;
xen/include/asm-x86/hvm/hvm.h +0 -0
index 7892f98c7b..6bde613dd8 100644

xen/include/asm-x86/hvm/hvm.h extern s8 hvm_port80_allowed; · line 244

Quoted 5 lines
xen/include/asm-x86/hvm/hvm.h +1 -1
@@ -241,7 +241,7 @@ extern s8 hvm_port80_allowed;
 extern const struct hvm_function_table *start_svm(void);
 extern const struct hvm_function_table *start_vmx(void);
 
-int hvm_domain_initialise(struct domain *d);
+int hvm_domain_initialise(struct domain *d, bool enable_viridian);

hvm_domain_initialise (and pv_domain_initialise) used to take a xen_arch_domain_config. I think you can introduce it back.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#9 lore raw

Re: [PATCH 1/8] viridian: add init hooks

Quoted 23 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 25 January 2019 14:23
To: Paul Durrant <[email protected]>
Cc: Andrew Cooper <[email protected]>; xen- [email protected]; Wei Liu <[email protected]>; Jan Beulich <[email protected]>; Roger Pau Monne <[email protected]>
Subject: Re: [Xen-devel] [PATCH 1/8] viridian: add init hooks

Quoted 1 line · Paul Durrant
Quoted 1 line

-----Original Message-----

[...]

Quoted 2 lines
Quoted 2 lines

Looking at this a little more... Viridian is an x86 specific thing, so

an

Quoted 2 lines
Quoted 2 lines

extra flag in xen_arch_domainconfig would seem most appropriate. This would then need to wired into the appropriate place(s) in libxl. I'll

have

Quoted 3 lines
Quoted 1 line

a look at how much work this is likely to be.

Would something along the lines of the following (as yet untested and

incomplete) patch be acceptable?

Quoted 1 line
Quoted 7 lines
Quoted 1 line

(I've blindly coded the Ocaml $MAGIC and just hardcoded the flag in the

stub)

Quoted 1 line

Not sure if your question is directed to me or not.

I think this patch is independent of this series to hand?

Yes, it was a stab at an incremental patch to do what Andy wanted.

Quoted 17 lines

xen/include/asm-

Quoted 9 lines

---8<---

xen/arch/x86/hvm/hvm.c +1 -1
-int hvm_domain_initialise(struct domain *d)
+int hvm_domain_initialise(struct domain *d, bool enable_viridian)
 {
     unsigned int nr_gsis;
     int rc;
xen/include/asm- renamed from xen/include/asm-x86/hvm/hvm.h +0 -0

x86/hvm/hvm.h

Quoted 7 lines

index 7892f98c7b..6bde613dd8 100644

xen/include/asm-x86/hvm/hvm.h +0 -0
@@ -241,7 +241,7 @@ extern s8 hvm_port80_allowed;
 extern const struct hvm_function_table *start_svm(void);
 extern const struct hvm_function_table *start_vmx(void);
 
Quoted 5 lines

xen/include/asm-x86/hvm/hvm.h extern s8 hvm_port80_allowed; · line 244

Quoted 2 lines
xen/include/asm-x86/hvm/hvm.h +1 -1
-int hvm_domain_initialise(struct domain *d);
+int hvm_domain_initialise(struct domain *d, bool enable_viridian);

hvm_domain_initialise (and pv_domain_initialise) used to take a xen_arch_domain_config. I think you can introduce it back.

I'm going to side-step the whole issue for the moment. I don't think this series is the right place to be making the change. Yes, it out-of-lining the structs and thus enables the optimization, but allocating them unconditionally is essentially only equivalent to leaving them inline in terms of memory cost.

Paul

Quoted 2 lines

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#10 lore raw

Re: [PATCH 1/8] viridian: add init hooks

In reply to Andrew Cooper
Quoted 16 lines

-----Original Message-----
From: Andrew Cooper
Sent: 02 January 2019 16:08
To: Paul Durrant <[email protected]>; [email protected]
Cc: Jan Beulich <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>
Subject: Re: [PATCH 1/8] viridian: add init hooks

Quoted 1 line · Paul Durrant

This patch adds domain and vcpu init hooks for viridian features. The

init

Quoted 1 line

hooks do not yet do anything; they will be added to by subsequent

patches.

Quoted 2 lines
Quoted 7 lines

Please can we start by fixing the current, broken, initialisation and destruction logic ?

To get rid of DOMCTL_setmaxvcpus, we need the *_destroy() logic to be fully idempotent.  Also, viridian_domain_deinit() should not call into viridian_vcpu_deinit(), and viridian_vcpu_deinit() shouldn't be faking up a write to the assist page.

The deinit calling logic is not changed by this patch... the domain deinit function has always called into the vcpu deinit function. I can try dropping it if you want.
The zero write to the assist page MSR is there to cause the mapping to be freed, which is necessary to avoid a leak. It is a somewhat hacky way of doing it though, I agree, and it is changed by a later patch in the series.

Quoted 4 lines

AFAICT, the deinit path is all entirely pointless at the moment and can be deleted.

It is not required at this stage, but it will be required later and I generally prefer to introduce mirrored pairs of hooks in the same patch rather than separate patches in the same series.

Paul

~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#11 lore raw

PATCH 2/8 viridian: separately allocate domain and vcpu structures

In reply to Paul Durrant

Currently the viridian_domain and viridian_vcpu structures are inline in the hvm_domain and hvm_vcpu structures respectively. Subsequent patches will need to add sizable extra fields to the viridian structures which will cause the PAGE_SIZE limit of the overall vcpu structure to be exceeded. This patch, therefore, uses the new init hooks to separately allocate the structures and converts the 'viridian' fields in hvm_domain and hvm_cpu to be pointers to these allocations.

NOTE: The patch also introduced the 'is_viridian_vcpu' macro to avoid
introducing a second evaluation of 'is_viridian_domain' with an open-coded 'v->domain' argument. This macro will also be further used in a subsequent patch.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

---
 xen/arch/x86/hvm/viridian/synic.c    | 40 +++++++--------
 xen/arch/x86/hvm/viridian/time.c     | 32 ++++++------
 xen/arch/x86/hvm/viridian/viridian.c | 75 ++++++++++++++++++----------
 xen/include/asm-x86/hvm/domain.h     |  2 +-
 xen/include/asm-x86/hvm/hvm.h        |  4 ++
 xen/include/asm-x86/hvm/vcpu.h       |  2 +-
 6 files changed, 90 insertions(+), 65 deletions(-)
xen/arch/x86/hvm/viridian/synic.c +20 -20
index a6ebbbc9f5..20731c2379 100644
@@ -30,7 +30,7 @@ typedef union _HV_VP_ASSIST_PAGE
 
 void viridian_apic_assist_set(struct vcpu *v)
 {
-    HV_VP_ASSIST_PAGE *ptr = v->arch.hvm.viridian.vp_assist.ptr;
+    HV_VP_ASSIST_PAGE *ptr = v->arch.hvm.viridian->vp_assist.ptr;
 
     if ( !ptr )
         return;
@@ -40,25 +40,25 @@ void viridian_apic_assist_set(struct vcpu *v)
      * wrong and the VM will most likely hang so force a crash now
      * to make the problem clear.
      */
-    if ( v->arch.hvm.viridian.apic_assist_pending )
+    if ( v->arch.hvm.viridian->apic_assist_pending )
         domain_crash(v->domain);
 
-    v->arch.hvm.viridian.apic_assist_pending = true;
+    v->arch.hvm.viridian->apic_assist_pending = true;
     ptr->ApicAssist.no_eoi = 1;
 }
 
 bool viridian_apic_assist_completed(struct vcpu *v)
 {
-    HV_VP_ASSIST_PAGE *ptr = v->arch.hvm.viridian.vp_assist.ptr;
+    HV_VP_ASSIST_PAGE *ptr = v->arch.hvm.viridian->vp_assist.ptr;
 
     if ( !ptr )
         return false;
 
-    if ( v->arch.hvm.viridian.apic_assist_pending &&
+    if ( v->arch.hvm.viridian->apic_assist_pending &&
          !ptr->ApicAssist.no_eoi )
     {
         /* An EOI has been avoided */
-        v->arch.hvm.viridian.apic_assist_pending = false;
+        v->arch.hvm.viridian->apic_assist_pending = false;
         return true;
     }
 
@@ -67,13 +67,13 @@ bool viridian_apic_assist_completed(struct vcpu *v)
 
 void viridian_apic_assist_clear(struct vcpu *v)
 {
-    HV_VP_ASSIST_PAGE *ptr = v->arch.hvm.viridian.vp_assist.ptr;
+    HV_VP_ASSIST_PAGE *ptr = v->arch.hvm.viridian->vp_assist.ptr;
 
     if ( !ptr )
         return;
 
     ptr->ApicAssist.no_eoi = 0;
-    v->arch.hvm.viridian.apic_assist_pending = false;
+    v->arch.hvm.viridian->apic_assist_pending = false;
 }
 
 int viridian_synic_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)
@@ -95,12 +95,12 @@ int viridian_synic_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)
 
     case HV_X64_MSR_VP_ASSIST_PAGE:
         /* release any previous mapping */
-        viridian_unmap_guest_page(&v->arch.hvm.viridian.vp_assist);
-        v->arch.hvm.viridian.vp_assist.msr.raw = val;
+        viridian_unmap_guest_page(&v->arch.hvm.viridian->vp_assist);
+        v->arch.hvm.viridian->vp_assist.msr.raw = val;
         viridian_dump_guest_page(v, "VP_ASSIST",
-                                 &v->arch.hvm.viridian.vp_assist);
-        if ( v->arch.hvm.viridian.vp_assist.msr.fields.enabled )
-            viridian_map_guest_page(v, &v->arch.hvm.viridian.vp_assist);
+                                 &v->arch.hvm.viridian->vp_assist);
+        if ( v->arch.hvm.viridian->vp_assist.msr.fields.enabled )
+            viridian_map_guest_page(v, &v->arch.hvm.viridian->vp_assist);
         break;
 
     default:
@@ -132,7 +132,7 @@ int viridian_synic_rdmsr(const struct vcpu *v, uint32_t idx, uint64_t *val)
         break;
 
     case HV_X64_MSR_VP_ASSIST_PAGE:
-        *val = v->arch.hvm.viridian.vp_assist.msr.raw;
+        *val = v->arch.hvm.viridian->vp_assist.msr.raw;
         break;
 
     default:
@@ -146,18 +146,18 @@ int viridian_synic_rdmsr(const struct vcpu *v, uint32_t idx, uint64_t *val)
 void viridian_synic_save_vcpu_ctxt(const struct vcpu *v,
                                    struct hvm_viridian_vcpu_context *ctxt)
 {
-    ctxt->apic_assist_pending = v->arch.hvm.viridian.apic_assist_pending;
-    ctxt->vp_assist_msr = v->arch.hvm.viridian.vp_assist.msr.raw;
+    ctxt->apic_assist_pending = v->arch.hvm.viridian->apic_assist_pending;
+    ctxt->vp_assist_msr = v->arch.hvm.viridian->vp_assist.msr.raw;
 }
 
 void viridian_synic_load_vcpu_ctxt(
     struct vcpu *v, const struct hvm_viridian_vcpu_context *ctxt)
 {
-    v->arch.hvm.viridian.vp_assist.msr.raw = ctxt->vp_assist_msr;
-    if ( v->arch.hvm.viridian.vp_assist.msr.fields.enabled )
-        viridian_map_guest_page(v, &v->arch.hvm.viridian.vp_assist);
+    v->arch.hvm.viridian->vp_assist.msr.raw = ctxt->vp_assist_msr;
+    if ( v->arch.hvm.viridian->vp_assist.msr.fields.enabled )
+        viridian_map_guest_page(v, &v->arch.hvm.viridian->vp_assist);
 
-    v->arch.hvm.viridian.apic_assist_pending = ctxt->apic_assist_pending;
+    v->arch.hvm.viridian->apic_assist_pending = ctxt->apic_assist_pending;
 }
 
 /*
xen/arch/x86/hvm/viridian/time.c +15 -17
index 840a82b457..42367f6460 100644
@@ -27,7 +27,7 @@ typedef struct _HV_REFERENCE_TSC_PAGE
 
 static void dump_reference_tsc(const struct domain *d)
 {
-    const union viridian_page_msr *rt = &d->arch.hvm.viridian.reference_tsc;
+    const union viridian_page_msr *rt = &d->arch.hvm.viridian->reference_tsc;
 
     if ( !rt->fields.enabled )
         return;
@@ -38,7 +38,7 @@ static void dump_reference_tsc(const struct domain *d)
 
 static void update_reference_tsc(struct domain *d, bool initialize)
 {
-    unsigned long gmfn = d->arch.hvm.viridian.reference_tsc.fields.pfn;
+    unsigned long gmfn = d->arch.hvm.viridian->reference_tsc.fields.pfn;
     struct page_info *page = get_page_from_gfn(d, gmfn, NULL, P2M_ALLOC);
     HV_REFERENCE_TSC_PAGE *p;
 
@@ -121,9 +121,8 @@ static int64_t raw_trc_val(struct domain *d)
 
 void viridian_time_ref_count_freeze(struct domain *d)
 {
-    struct viridian_time_ref_count *trc;
-
-    trc = &d->arch.hvm.viridian.time_ref_count;
+    struct viridian_time_ref_count *trc =
+        &d->arch.hvm.viridian->time_ref_count;
 
     if ( test_and_clear_bit(_TRC_running, &trc->flags) )
         trc->val = raw_trc_val(d) + trc->off;
@@ -131,9 +130,8 @@ void viridian_time_ref_count_freeze(struct domain *d)
 
 void viridian_time_ref_count_thaw(struct domain *d)
 {
-    struct viridian_time_ref_count *trc;
-
-    trc = &d->arch.hvm.viridian.time_ref_count;
+    struct viridian_time_ref_count *trc =
+        &d->arch.hvm.viridian->time_ref_count;
 
     if ( !d->is_shutting_down &&
          !test_and_set_bit(_TRC_running, &trc->flags) )
@@ -150,9 +148,9 @@ int viridian_time_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)
         if ( !(viridian_feature_mask(d) & HVMPV_reference_tsc) )
             return X86EMUL_EXCEPTION;
 
-        d->arch.hvm.viridian.reference_tsc.raw = val;
+        d->arch.hvm.viridian->reference_tsc.raw = val;
         dump_reference_tsc(d);
-        if ( d->arch.hvm.viridian.reference_tsc.fields.enabled )
+        if ( d->arch.hvm.viridian->reference_tsc.fields.enabled )
             update_reference_tsc(d, true);
         break;
 
@@ -189,13 +187,13 @@ int viridian_time_rdmsr(const struct vcpu *v, uint32_t idx, uint64_t *val)
         if ( !(viridian_feature_mask(d) & HVMPV_reference_tsc) )
             return X86EMUL_EXCEPTION;
 
-        *val = d->arch.hvm.viridian.reference_tsc.raw;
+        *val = d->arch.hvm.viridian->reference_tsc.raw;
         break;
 
     case HV_X64_MSR_TIME_REF_COUNT:
     {
         struct viridian_time_ref_count *trc =
-            &d->arch.hvm.viridian.time_ref_count;
+            &d->arch.hvm.viridian->time_ref_count;
 
         if ( !(viridian_feature_mask(d) & HVMPV_time_ref_count) )
             return X86EMUL_EXCEPTION;
@@ -219,17 +217,17 @@ int viridian_time_rdmsr(const struct vcpu *v, uint32_t idx, uint64_t *val)
 void viridian_time_save_domain_ctxt(
     const struct domain *d, struct hvm_viridian_domain_context *ctxt)
 {
-    ctxt->time_ref_count = d->arch.hvm.viridian.time_ref_count.val;
-    ctxt->reference_tsc = d->arch.hvm.viridian.reference_tsc.raw;
+    ctxt->time_ref_count = d->arch.hvm.viridian->time_ref_count.val;
+    ctxt->reference_tsc = d->arch.hvm.viridian->reference_tsc.raw;
 }
 
 void viridian_time_load_domain_ctxt(
     struct domain *d, const struct hvm_viridian_domain_context *ctxt)
 {
-    d->arch.hvm.viridian.time_ref_count.val = ctxt->time_ref_count;
-    d->arch.hvm.viridian.reference_tsc.raw = ctxt->reference_tsc;
+    d->arch.hvm.viridian->time_ref_count.val = ctxt->time_ref_count;
+    d->arch.hvm.viridian->reference_tsc.raw = ctxt->reference_tsc;
 
-    if ( d->arch.hvm.viridian.reference_tsc.fields.enabled )
+    if ( d->arch.hvm.viridian->reference_tsc.fields.enabled )
         update_reference_tsc(d, false);
 }
 
xen/arch/x86/hvm/viridian/viridian.c +49 -26

187 lines not on this page · raw message

xen/include/asm-x86/hvm/domain.h +1 -1
index 3e7331817f..6c7c4f5aa6 100644
@@ -154,7 +154,7 @@ struct hvm_domain {
     /* hypervisor intercepted msix table */
     struct list_head       msixtbl_list;
 
-    struct viridian_domain viridian;
+    struct viridian_domain *viridian;
 
     bool_t                 hap_enabled;
     bool_t                 mem_sharing_enabled;
xen/include/asm-x86/hvm/hvm.h +4 -0
index 0a10b51554..d8df6f4352 100644
@@ -461,6 +461,9 @@ static inline bool hvm_get_guest_bndcfgs(struct vcpu *v, u64 *val)
 #define is_viridian_domain(d) \
     (is_hvm_domain(d) && (viridian_feature_mask(d) & HVMPV_base_freq))
 
+#define is_viridian_vcpu(v) \
+    is_viridian_domain((v)->domain)
+
 #define has_viridian_time_ref_count(d) \
     (is_viridian_domain(d) && (viridian_feature_mask(d) & HVMPV_time_ref_count))
 
@@ -760,6 +763,7 @@ static inline bool hvm_has_set_descriptor_access_exiting(void)
 }
 
 #define is_viridian_domain(d) ((void)(d), false)
+#define is_viridian_vcpu(v) ((void)(v), false)
 #define has_viridian_time_ref_count(d) ((void)(d), false)
 #define hvm_long_mode_active(v) ((void)(v), false)
 #define hvm_get_guest_time(v) ((void)(v), 0)
xen/include/asm-x86/hvm/vcpu.h +1 -1
index c8a40f6d55..be9fa5b5a4 100644
@@ -200,7 +200,7 @@ struct hvm_vcpu {
     /* Pending hw/sw interrupt (.vector = -1 means nothing pending). */
     struct x86_event     inject_event;
 
-    struct viridian_vcpu viridian;
+    struct viridian_vcpu *viridian;
 };
 
 #endif /* __ASM_X86_HVM_VCPU_H__ */
Signature · 7 lines
2.20.1.2.gb21ebb671


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 2/8
#12 lore raw

Re: [PATCH 2/8] viridian: separately allocate domain and vcpu structures

xen/arch/x86/hvm/viridian/viridian.c int guest_rdmsr_viridian(const struct vcpu *v, uint32_t idx, uint64_t *val) · line 449

Quoted 12 lines · Paul Durrant

void viridian_vcpu_deinit(struct vcpu *v)
{

xen/arch/x86/hvm/viridian/viridian.c +8 -1
-    viridian_synic_wrmsr(v, HV_X64_MSR_VP_ASSIST_PAGE, 0);
+    if ( !v->arch.hvm.viridian )
+        return;
+
+    if ( is_viridian_vcpu(v) )
+        viridian_synic_wrmsr(v, HV_X64_MSR_VP_ASSIST_PAGE, 0);
+
+    xfree(v->arch.hvm.viridian);
+    v->arch.hvm.viridian = NULL;

Please use XFREE() here and below.

With it fixed:

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#13 lore raw

Re: [PATCH 2/8] viridian: separately allocate domain and vcpu structures

Quoted 12 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 02 January 2019 15:55
To: Paul Durrant <[email protected]>
Cc: [email protected]; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>
Subject: Re: [PATCH 2/8] viridian: separately allocate domain and vcpu structures

Quoted 1 line · Paul Durrant
Quoted 13 lines

xen/arch/x86/hvm/viridian/viridian.c int guest_rdmsr_viridian(const struct vcpu *v, uint32_t idx, uint64_t *val) · line 449

Quoted 11 lines

void viridian_vcpu_deinit(struct vcpu *v)
{

xen/arch/x86/hvm/viridian/viridian.c +8 -1
-    viridian_synic_wrmsr(v, HV_X64_MSR_VP_ASSIST_PAGE, 0);
+    if ( !v->arch.hvm.viridian )
+        return;
+
+    if ( is_viridian_vcpu(v) )
+        viridian_synic_wrmsr(v, HV_X64_MSR_VP_ASSIST_PAGE, 0);
+
+    xfree(v->arch.hvm.viridian);
+    v->arch.hvm.viridian = NULL;

Please use XFREE() here and below.

Ooh, I didn't know about that bit of macro magic.

Quoted 4 lines

With it fixed:

Thanks,

Paul

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#14 lore raw

PATCH 3/8 viridian: extend init/deinit hooks into synic and time modules

In reply to Paul Durrant

This patch simply adds domain and vcpu init/deinit hooks into the synic and time modules and wires them into viridian_[domain|vcpu]_[init|deinit](). Only one of the hooks is currently needed (to unmap the 'VP Assist' page) but subsequent patches will make use of the others.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

---
 xen/arch/x86/hvm/viridian/private.h  | 12 ++++++++++++
 xen/arch/x86/hvm/viridian/synic.c    | 19 +++++++++++++++++++
 xen/arch/x86/hvm/viridian/time.c     | 18 ++++++++++++++++++
 xen/arch/x86/hvm/viridian/viridian.c | 14 +++++++++++++-
 4 files changed, 62 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/viridian/private.h +12 -0
index 398b22f12d..040c3c991d 100644
@@ -74,6 +74,12 @@
 int viridian_synic_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val);
 int viridian_synic_rdmsr(const struct vcpu *v, uint32_t idx, uint64_t *val);
 
+int viridian_synic_vcpu_init(struct vcpu *v);
+int viridian_synic_domain_init(struct domain *d);
+
+void viridian_synic_vcpu_deinit(struct vcpu *v);
+void viridian_synic_domain_deinit(struct domain *d);
+
 void viridian_synic_save_vcpu_ctxt(const struct vcpu *v,
                                    struct hvm_viridian_vcpu_context *ctxt);
 void viridian_synic_load_vcpu_ctxt(
@@ -82,6 +88,12 @@ void viridian_synic_load_vcpu_ctxt(
 int viridian_time_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val);
 int viridian_time_rdmsr(const struct vcpu *v, uint32_t idx, uint64_t *val);
 
+int viridian_time_vcpu_init(struct vcpu *v);
+int viridian_time_domain_init(struct domain *d);
+
+void viridian_time_vcpu_deinit(struct vcpu *v);
+void viridian_time_domain_deinit(struct domain *d);
+
 void viridian_time_save_domain_ctxt(
     const struct domain *d, struct hvm_viridian_domain_context *ctxt);
 void viridian_time_load_domain_ctxt(
xen/arch/x86/hvm/viridian/synic.c +19 -0
index 20731c2379..9892bf279d 100644
@@ -143,6 +143,25 @@ int viridian_synic_rdmsr(const struct vcpu *v, uint32_t idx, uint64_t *val)
     return X86EMUL_OKAY;
 }
 
+int viridian_synic_vcpu_init(struct vcpu *v)
+{
+    return 0;
+}
+
+int viridian_synic_domain_init(struct domain *d)
+{
+    return 0;
+}
+
+void viridian_synic_vcpu_deinit(struct vcpu *v)
+{
+    viridian_unmap_guest_page(&v->arch.hvm.viridian->vp_assist);
+}
+
+void viridian_synic_domain_deinit(struct domain *d)
+{
+}
+
 void viridian_synic_save_vcpu_ctxt(const struct vcpu *v,
                                    struct hvm_viridian_vcpu_context *ctxt)
 {
xen/arch/x86/hvm/viridian/time.c +18 -0
index 42367f6460..b1d67035e4 100644
@@ -214,6 +214,24 @@ int viridian_time_rdmsr(const struct vcpu *v, uint32_t idx, uint64_t *val)
     return X86EMUL_OKAY;
 }
 
+int viridian_time_vcpu_init(struct vcpu *v)
+{
+    return 0;
+}
+
+int viridian_time_domain_init(struct domain *d)
+{
+    return 0;
+}
+
+void viridian_time_vcpu_deinit(struct vcpu *v)
+{
+}
+
+void viridian_time_domain_deinit(struct domain *d)
+{
+}
+
 void viridian_time_save_domain_ctxt(
     const struct domain *d, struct hvm_viridian_domain_context *ctxt)
 {
xen/arch/x86/hvm/viridian/viridian.c +13 -1
index e200e2ed1d..4c0f04df8c 100644
@@ -424,6 +424,9 @@ int viridian_vcpu_init(struct vcpu *v)
     if ( !v->arch.hvm.viridian )
         return -ENOMEM;
 
+    viridian_synic_vcpu_init(v);
+    viridian_time_vcpu_init(v);
+
     return 0;
 }
 
@@ -434,6 +437,9 @@ int viridian_domain_init(struct domain *d)
     if ( !d->arch.hvm.viridian )
         return -ENOMEM;
 
+    viridian_synic_domain_init(d);
+    viridian_time_domain_init(d);
+
     return 0;
 }
 
@@ -443,7 +449,10 @@ void viridian_vcpu_deinit(struct vcpu *v)
         return;
 
     if ( is_viridian_vcpu(v) )
-        viridian_synic_wrmsr(v, HV_X64_MSR_VP_ASSIST_PAGE, 0);
+    {
+        viridian_time_vcpu_deinit(v);
+        viridian_synic_vcpu_deinit(v);
+    }
 
     xfree(v->arch.hvm.viridian);
     v->arch.hvm.viridian = NULL;
@@ -459,6 +468,9 @@ void viridian_domain_deinit(struct domain *d)
     if ( !d->arch.hvm.viridian )
         return;
 
+    viridian_time_domain_deinit(d);
+    viridian_synic_domain_deinit(d);
+
     xfree(d->arch.hvm.viridian);
     d->arch.hvm.viridian = NULL;
 }
Signature · 7 lines
2.20.1.2.gb21ebb671


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#15 lore raw

Re: [PATCH 3/8] viridian: extend init/deinit hooks into synic and time modules

xen/arch/x86/hvm/viridian/viridian.c int viridian_vcpu_init(struct vcpu *v) · line 429

Quoted 11 lines · Paul Durrant
xen/arch/x86/hvm/viridian/viridian.c +3 -0
index e200e2ed1d..4c0f04df8c 100644
@@ -424,6 +424,9 @@ int viridian_vcpu_init(struct vcpu *v)
     if ( !v->arch.hvm.viridian )
         return -ENOMEM;
 
+    viridian_synic_vcpu_init(v);
+    viridian_time_vcpu_init(v);
+

Should these functions' return values be checked? They may fail judging from the fact that they aren't void functions.

Quoted 14 lines
xen/arch/x86/hvm/viridian/viridian.c +3 -0
     return 0;
 }
 
@@ -434,6 +437,9 @@ int viridian_domain_init(struct domain *d)
     if ( !d->arch.hvm.viridian )
         return -ENOMEM;
 
+    viridian_synic_domain_init(d);
+    viridian_time_domain_init(d);
+
     return 0;
 }
 

xen/arch/x86/hvm/viridian/viridian.c void viridian_vcpu_deinit(struct vcpu *v) · line 446

Quoted 4 lines
xen/arch/x86/hvm/viridian/viridian.c +0 -1
@@ -443,7 +449,10 @@ void viridian_vcpu_deinit(struct vcpu *v)
         return;
 
     if ( is_viridian_vcpu(v) )
-        viridian_synic_wrmsr(v, HV_X64_MSR_VP_ASSIST_PAGE, 0);

Where is this now? It's not in the synic deinit function as far as I can tell. Oh, it is used to unmap the vp_assist page so the call to viridian_synic_wrmsr is superseded by an unmap call directly. It should be fine here.

Wei.

Quoted 20 lines
xen/arch/x86/hvm/viridian/viridian.c +7 -0
+    {
+        viridian_time_vcpu_deinit(v);
+        viridian_synic_vcpu_deinit(v);
+    }
 
     xfree(v->arch.hvm.viridian);
     v->arch.hvm.viridian = NULL;
@@ -459,6 +468,9 @@ void viridian_domain_deinit(struct domain *d)
     if ( !d->arch.hvm.viridian )
         return;
 
+    viridian_time_domain_deinit(d);
+    viridian_synic_domain_deinit(d);
+
     xfree(d->arch.hvm.viridian);
     d->arch.hvm.viridian = NULL;
 }
Signature · 1 line
2.20.1.2.gb21ebb671

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#16 lore raw

Re: [PATCH 3/8] viridian: extend init/deinit hooks into synic and time modules

Quoted 22 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 02 January 2019 15:55
To: Paul Durrant <[email protected]>
Cc: [email protected]; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>
Subject: Re: [PATCH 3/8] viridian: extend init/deinit hooks into synic and time modules

Review

Quoted 1 line · Paul Durrant
(quoted diff) +0 -0

b/xen/arch/x86/hvm/viridian/viridian.c

Quoted 7 lines

index e200e2ed1d..4c0f04df8c 100644

xen/arch/x86/hvm/viridian/viridian.c +0 -0
@@ -424,6 +424,9 @@ int viridian_vcpu_init(struct vcpu *v)
     if ( !v->arch.hvm.viridian )
         return -ENOMEM;
 
Quoted 6 lines

xen/arch/x86/hvm/viridian/viridian.c int viridian_vcpu_init(struct vcpu *v) · line 429

Quoted 3 lines
xen/arch/x86/hvm/viridian/viridian.c +3 -0
+    viridian_synic_vcpu_init(v);
+    viridian_time_vcpu_init(v);
+

Should these functions' return values be checked? They may fail judging from the fact that they aren't void functions.

Yes, indeed they should.

Quoted 17 lines
Quoted 17 lines
xen/arch/x86/hvm/viridian/viridian.c +3 -0
     return 0;
 }
 
@@ -434,6 +437,9 @@ int viridian_domain_init(struct domain *d)
     if ( !d->arch.hvm.viridian )
         return -ENOMEM;
 
+    viridian_synic_domain_init(d);
+    viridian_time_domain_init(d);
+
     return 0;
 }
 
@@ -443,7 +449,10 @@ void viridian_vcpu_deinit(struct vcpu *v)
         return;
 
Quoted 7 lines

xen/arch/x86/hvm/viridian/viridian.c void viridian_vcpu_deinit(struct vcpu *v) · line 446

Quoted 2 lines
xen/arch/x86/hvm/viridian/viridian.c +0 -1
     if ( is_viridian_vcpu(v) )
-        viridian_synic_wrmsr(v, HV_X64_MSR_VP_ASSIST_PAGE, 0);

Where is this now? It's not in the synic deinit function as far as I can tell. Oh, it is used to unmap the vp_assist page so the call to viridian_synic_wrmsr is superseded by an unmap call directly. It should be fine here.

Yes, that's right.

Paul

Quoted 14 lines

Wei.

Quoted 11 lines
xen/arch/x86/hvm/viridian/viridian.c +4 -0
+    {
+        viridian_time_vcpu_deinit(v);
+        viridian_synic_vcpu_deinit(v);
+    }
 
     xfree(v->arch.hvm.viridian);
     v->arch.hvm.viridian = NULL;
@@ -459,6 +468,9 @@ void viridian_domain_deinit(struct domain *d)
     if ( !d->arch.hvm.viridian )
         return;
 
Quoted 9 lines
Quoted 9 lines
xen/arch/x86/hvm/viridian/viridian.c +3 -1
+    viridian_time_domain_deinit(d);
+    viridian_synic_domain_deinit(d);
+
     xfree(d->arch.hvm.viridian);
     d->arch.hvm.viridian = NULL;
 }
--

2.20.1.2.gb21ebb671

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#17 lore raw

PATCH 4/8 viridian: add missing context save helpers into synic and time modules

In reply to Paul Durrant

Currently the time module lacks vcpu context save helpers and the synic module lacks domain context save helpers. These helpers are not yet required but subsequent patches will require at least some of them so this patch completes the set to avoid introducing them in an ad-hoc way.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

---
 xen/arch/x86/hvm/viridian/private.h | 10 ++++++++++
 xen/arch/x86/hvm/viridian/synic.c   | 11 +++++++++++
 xen/arch/x86/hvm/viridian/time.c    | 10 ++++++++++
 3 files changed, 31 insertions(+)
xen/arch/x86/hvm/viridian/private.h +10 -0
index 040c3c991d..1864bab3d5 100644
@@ -85,6 +85,11 @@ void viridian_synic_save_vcpu_ctxt(const struct vcpu *v,
 void viridian_synic_load_vcpu_ctxt(
     struct vcpu *v, const struct hvm_viridian_vcpu_context *ctxt);
 
+void viridian_synic_save_domain_ctxt(
+    const struct domain *d, struct hvm_viridian_domain_context *ctxt);
+void viridian_synic_load_domain_ctxt(
+    struct domain *d, const struct hvm_viridian_domain_context *ctxt);
+
 int viridian_time_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val);
 int viridian_time_rdmsr(const struct vcpu *v, uint32_t idx, uint64_t *val);
 
@@ -94,6 +99,11 @@ int viridian_time_domain_init(struct domain *d);
 void viridian_time_vcpu_deinit(struct vcpu *v);
 void viridian_time_domain_deinit(struct domain *d);
 
+void viridian_time_save_vcpu_ctxt(
+    const struct vcpu *v, struct hvm_viridian_vcpu_context *ctxt);
+void viridian_time_load_vcpu_ctxt(
+    struct vcpu *v, const struct hvm_viridian_vcpu_context *ctxt);
+
 void viridian_time_save_domain_ctxt(
     const struct domain *d, struct hvm_viridian_domain_context *ctxt);
 void viridian_time_load_domain_ctxt(
xen/arch/x86/hvm/viridian/synic.c +11 -0
index 9892bf279d..5707b79d99 100644
@@ -179,6 +179,17 @@ void viridian_synic_load_vcpu_ctxt(
     v->arch.hvm.viridian->apic_assist_pending = ctxt->apic_assist_pending;
 }
 
+void viridian_synic_save_domain_ctxt(
+    const struct domain *d, struct hvm_viridian_domain_context *ctxt)
+{
+}
+
+void viridian_synic_load_domain_ctxt(
+    struct domain *d, const struct hvm_viridian_domain_context *ctxt)
+{
+}
+
+
 /*
  * Local variables:
  * mode: C
xen/arch/x86/hvm/viridian/time.c +10 -0
index b1d67035e4..9225bdf9ab 100644
@@ -232,6 +232,16 @@ void viridian_time_domain_deinit(struct domain *d)
 {
 }
 
+void viridian_time_save_vcpu_ctxt(
+    const struct vcpu *v, struct hvm_viridian_vcpu_context *ctxt)
+{
+}
+
+void viridian_time_load_vcpu_ctxt(
+    struct vcpu *v, const struct hvm_viridian_vcpu_context *ctxt)
+{
+}
+
 void viridian_time_save_domain_ctxt(
     const struct domain *d, struct hvm_viridian_domain_context *ctxt)
 {
Signature · 7 lines
2.20.1.2.gb21ebb671


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 4/8
#18 lore raw

Re: [PATCH 4/8] viridian: add missing context save helpers into synic and time modules

Quoted 6 lines · Paul Durrant

Currently the time module lacks vcpu context save helpers and the synic module lacks domain context save helpers. These helpers are not yet required but subsequent patches will require at least some of them so this patch completes the set to avoid introducing them in an ad-hoc way.

I would have hooked up the helpers to their respective callsites in this patch instead of later ones, but I think this is just a matter of personal taste.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#19 lore raw

PATCH 5/8 viridian: use viridian_map/unmap_guest_page() for reference tsc page

In reply to Paul Durrant

Whilst the reference tsc page does not currently need to be kept mapped after it is initially set up (or updated after migrate), the code can be simplified by using the common guest page map/unmap and dump functions. New functionality added by a subsequent patch will also require the page to kept mapped for the lifetime of the domain.

NOTE: Because the reference tsc page is per-domain rather than per-vcpu
this patch also changes viridian_map_guest_page() to take a domain pointer rather than a vcpu pointer.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

---
 xen/arch/x86/hvm/viridian/private.h  |  2 +-
 xen/arch/x86/hvm/viridian/synic.c    |  8 +++-
 xen/arch/x86/hvm/viridian/time.c     | 57 ++++++++++------------------
 xen/arch/x86/hvm/viridian/viridian.c |  3 +-
 xen/include/asm-x86/hvm/viridian.h   |  2 +-
 5 files changed, 28 insertions(+), 44 deletions(-)
xen/arch/x86/hvm/viridian/private.h +1 -1
index 1864bab3d5..0bf34eefe0 100644
@@ -111,7 +111,7 @@ void viridian_time_load_domain_ctxt(
 
 void viridian_dump_guest_page(const struct vcpu *v, const char *name,
                               const struct viridian_page *vp);
-void viridian_map_guest_page(struct vcpu *v, struct viridian_page *vp);
+void viridian_map_guest_page(struct domain *d, struct viridian_page *vp);
 void viridian_unmap_guest_page(struct viridian_page *vp);
 
 #endif /* X86_HVM_VIRIDIAN_PRIVATE_H */
xen/arch/x86/hvm/viridian/synic.c +6 -2
index 5707b79d99..35bd2125fc 100644
@@ -78,6 +78,8 @@ void viridian_apic_assist_clear(struct vcpu *v)
 
 int viridian_synic_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)
 {
+    struct domain *d = v->domain;
+
     switch ( idx )
     {
     case HV_X64_MSR_EOI:
@@ -100,7 +102,7 @@ int viridian_synic_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)
         viridian_dump_guest_page(v, "VP_ASSIST",
                                  &v->arch.hvm.viridian->vp_assist);
         if ( v->arch.hvm.viridian->vp_assist.msr.fields.enabled )
-            viridian_map_guest_page(v, &v->arch.hvm.viridian->vp_assist);
+            viridian_map_guest_page(d, &v->arch.hvm.viridian->vp_assist);
         break;
 
     default:
@@ -172,9 +174,11 @@ void viridian_synic_save_vcpu_ctxt(const struct vcpu *v,
 void viridian_synic_load_vcpu_ctxt(
     struct vcpu *v, const struct hvm_viridian_vcpu_context *ctxt)
 {
+    struct domain *d = v->domain;
+
     v->arch.hvm.viridian->vp_assist.msr.raw = ctxt->vp_assist_msr;
     if ( v->arch.hvm.viridian->vp_assist.msr.fields.enabled )
-        viridian_map_guest_page(v, &v->arch.hvm.viridian->vp_assist);
+        viridian_map_guest_page(d, &v->arch.hvm.viridian->vp_assist);
 
     v->arch.hvm.viridian->apic_assist_pending = ctxt->apic_assist_pending;
 }
xen/arch/x86/hvm/viridian/time.c +19 -38

110 lines not on this page · raw message

xen/arch/x86/hvm/viridian/viridian.c +1 -2
index 4c0f04df8c..9da87379b7 100644
@@ -643,9 +643,8 @@ void viridian_dump_guest_page(const struct vcpu *v, const char *name,
            v, name, (unsigned long)vp->msr.fields.pfn);
 }
 
-void viridian_map_guest_page(struct vcpu *v, struct viridian_page *vp)
+void viridian_map_guest_page(struct domain *d, struct viridian_page *vp)
 {
-    struct domain *d = v->domain;
     unsigned long gmfn = vp->msr.fields.pfn;
     struct page_info *page;
 
xen/include/asm-x86/hvm/viridian.h +1 -1
index f072838955..1d281d825e 100644
@@ -65,7 +65,7 @@ struct viridian_domain
     union viridian_guest_os_id_msr guest_os_id;
     union viridian_page_msr hypercall_gpa;
     struct viridian_time_ref_count time_ref_count;
-    union viridian_page_msr reference_tsc;
+    struct viridian_page reference_tsc;
 };
 
 void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf,
Signature · 7 lines
2.20.1.2.gb21ebb671


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 5/8
#20 lore raw

Re: [PATCH 5/8] viridian: use viridian_map/unmap_guest_page() for reference tsc page

Quoted 29 lines · Paul Durrant

Whilst the reference tsc page does not currently need to be kept mapped after it is initially set up (or updated after migrate), the code can be simplified by using the common guest page map/unmap and dump functions. New functionality added by a subsequent patch will also require the page to kept mapped for the lifetime of the domain.

NOTE: Because the reference tsc page is per-domain rather than per-vcpu
this patch also changes viridian_map_guest_page() to take a domain pointer rather than a vcpu pointer.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

---
 xen/arch/x86/hvm/viridian/private.h  |  2 +-
 xen/arch/x86/hvm/viridian/synic.c    |  8 +++-
 xen/arch/x86/hvm/viridian/time.c     | 57 ++++++++++------------------
 xen/arch/x86/hvm/viridian/viridian.c |  3 +-
 xen/include/asm-x86/hvm/viridian.h   |  2 +-
 5 files changed, 28 insertions(+), 44 deletions(-)
xen/arch/x86/hvm/viridian/private.h +0 -0
index 1864bab3d5..0bf34eefe0 100644

xen/arch/x86/hvm/viridian/private.h void viridian_time_load_domain_ctxt( · line 114

Quoted 5 lines
xen/arch/x86/hvm/viridian/private.h +1 -1
@@ -111,7 +111,7 @@ void viridian_time_load_domain_ctxt(
 
 void viridian_dump_guest_page(const struct vcpu *v, const char *name,
                               const struct viridian_page *vp);
-void viridian_map_guest_page(struct vcpu *v, struct viridian_page *vp);
+void viridian_map_guest_page(struct domain *d, struct viridian_page *vp);

Since you modify this anyway, can you constify struct domain?

With that:

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#21 lore raw

Re: [PATCH 5/8] viridian: use viridian_map/unmap_guest_page() for reference tsc page

Quoted 44 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 02 January 2019 15:55
To: Paul Durrant <[email protected]>
Cc: [email protected]; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu <[email protected]>; Roger Pau Monne <[email protected]>
Subject: Re: [PATCH 5/8] viridian: use viridian_map/unmap_guest_page() for reference tsc page

Quoted 3 lines · Paul Durrant

Whilst the reference tsc page does not currently need to be kept mapped after it is initially set up (or updated after migrate), the code can be simplified by using the common guest page map/unmap and dump

functions.

Quoted 1 line

New functionality added by a subsequent patch will also require the page

to

Quoted 20 lines

kept mapped for the lifetime of the domain.

NOTE: Because the reference tsc page is per-domain rather than per-vcpu
this patch also changes viridian_map_guest_page() to take a domain pointer rather than a vcpu pointer.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

---
 xen/arch/x86/hvm/viridian/private.h  |  2 +-
 xen/arch/x86/hvm/viridian/synic.c    |  8 +++-
 xen/arch/x86/hvm/viridian/time.c     | 57 ++++++++++------------------
 xen/arch/x86/hvm/viridian/viridian.c |  3 +-
 xen/include/asm-x86/hvm/viridian.h   |  2 +-
 5 files changed, 28 insertions(+), 44 deletions(-)

Review

Quoted 1 line
(quoted diff) +0 -0

b/xen/arch/x86/hvm/viridian/private.h

Quoted 5 lines

index 1864bab3d5..0bf34eefe0 100644

xen/arch/x86/hvm/viridian/private.h +0 -0
@@ -111,7 +111,7 @@ void viridian_time_load_domain_ctxt(
 
Quoted 8 lines

xen/arch/x86/hvm/viridian/private.h void viridian_time_load_domain_ctxt(

Quoted 4 lines
xen/arch/x86/hvm/viridian/private.h +1 -1
 void viridian_dump_guest_page(const struct vcpu *v, const char *name,
                               const struct viridian_page *vp);
-void viridian_map_guest_page(struct vcpu *v, struct viridian_page *vp);
+void viridian_map_guest_page(struct domain *d, struct viridian_page

*vp);

Since you modify this anyway, can you constify struct domain?

Yes, I guess that should be do-able now that the viridian_page is in a separate allocation unit.

Quoted 3 lines

With that:

Thanks,

Paul

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#22 lore raw

Re: [PATCH 5/8] viridian: use viridian_map/unmap_guest_page() for reference tsc page

Quoted 66 lines

-----Original Message-----
From: Xen-devel [mailto:[email protected]] On Behalf Of Paul Durrant
Sent: 03 January 2019 09:20
To: Wei Liu <[email protected]>
Cc: [email protected]; Roger Pau Monne <[email protected]>; Wei Liu <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>
Subject: Re: [Xen-devel] [PATCH 5/8] viridian: use viridian_map/unmap_guest_page() for reference tsc page

Quoted 6 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 02 January 2019 15:55
To: Paul Durrant <[email protected]>
Cc: [email protected]; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>; Wei Liu

<[email protected]>;

Quoted 2 lines

Roger Pau Monne <[email protected]>
Subject: Re: [PATCH 5/8] viridian: use viridian_map/unmap_guest_page()

for

Quoted 4 lines

reference tsc page

Quoted 1 line · Paul Durrant

Whilst the reference tsc page does not currently need to be kept

mapped

Quoted 4 lines
Quoted 2 lines

after it is initially set up (or updated after migrate), the code can be simplified by using the common guest page map/unmap and dump

functions.

Quoted 1 line

New functionality added by a subsequent patch will also require the

page

Quoted 4 lines

to

Quoted 3 lines

kept mapped for the lifetime of the domain.

NOTE: Because the reference tsc page is per-domain rather than per-

vcpu

Quoted 1 line
Quoted 1 line

this patch also changes viridian_map_guest_page() to take a

domain

Quoted 12 lines
Quoted 8 lines

pointer rather than a vcpu pointer.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

Quoted 4 lines
---
 xen/arch/x86/hvm/viridian/private.h  |  2 +-
 xen/arch/x86/hvm/viridian/synic.c    |  8 +++-
 xen/arch/x86/hvm/viridian/time.c     | 57 ++++++++++-----------------

-

Quoted 6 lines

Review

Quoted 5 lines
 xen/arch/x86/hvm/viridian/viridian.c |  3 +-
 xen/include/asm-x86/hvm/viridian.h   |  2 +-
 5 files changed, 28 insertions(+), 44 deletions(-)
(quoted diff) +0 -0

b/xen/arch/x86/hvm/viridian/private.h

Quoted 8 lines

xen/arch/x86/hvm/viridian/private.h void viridian_time_load_domain_ctxt( · line 114

Quoted 8 lines

index 1864bab3d5..0bf34eefe0 100644

xen/arch/x86/hvm/viridian/private.h +0 -1
@@ -111,7 +111,7 @@ void viridian_time_load_domain_ctxt(
 
 void viridian_dump_guest_page(const struct vcpu *v, const char *name,
                               const struct viridian_page *vp);
-void viridian_map_guest_page(struct vcpu *v, struct viridian_page

*vp);

Quoted 8 lines
Quoted 5 lines

xen/arch/x86/hvm/viridian/private.h void viridian_time_load_domain_ctxt( · line 114

Quoted 1 line
xen/arch/x86/hvm/viridian/private.h +1 -0
+void viridian_map_guest_page(struct domain *d, struct viridian_page

*vp);

Since you modify this anyway, can you constify struct domain?

Yes, I guess that should be do-able now that the viridian_page is in a separate allocation unit.

Alas, no. The call to get_page_from_gfn() takes a non-const struct domain pointer, and I'm not opening that can of worms. Does your R-b still stand?

Paul

Quoted 5 lines
Quoted 4 lines

With that:

Quoted 8 lines

Thanks,

Paul

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#23 lore raw

Re: [PATCH 5/8] viridian: use viridian_map/unmap_guest_page() for reference tsc page

On Mon, Jan 07, 2019 at 03:35:41PM +0000, Paul Durrant wrote:
[...]

Quoted 6 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
                               const struct viridian_page *vp);

-void viridian_map_guest_page(struct vcpu *v, struct viridian_page

*vp);

Quoted 3 lines
Quoted 1 line

+void viridian_map_guest_page(struct domain *d, struct viridian_page

*vp);

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Since you modify this anyway, can you constify struct domain?

Yes, I guess that should be do-able now that the viridian_page is in a separate allocation unit.

Alas, no. The call to get_page_from_gfn() takes a non-const struct domain pointer, and I'm not opening that can of worms. Does your R-b still stand?

Yes.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#24 lore raw

Re: [PATCH 5/8] viridian: use viridian_map/unmap_guest_page() for reference tsc page

Quoted 22 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 07 January 2019 15:48
To: Paul Durrant <[email protected]>
Cc: Wei Liu <[email protected]>; [email protected]; Roger Pau Monne <[email protected]>; Jan Beulich <[email protected]>; Andrew Cooper <[email protected]>
Subject: Re: [PATCH 5/8] viridian: use viridian_map/unmap_guest_page() for reference tsc page

On Mon, Jan 07, 2019 at 03:35:41PM +0000, Paul Durrant wrote:
[...]

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Quoted 2 lines
                               const struct viridian_page *vp);

-void viridian_map_guest_page(struct vcpu *v, struct viridian_page

*vp);

Quoted 1 line
Quoted 1 line

+void viridian_map_guest_page(struct domain *d, struct

viridian_page

Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

*vp);

Since you modify this anyway, can you constify struct domain?

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, I guess that should be do-able now that the viridian_page is in a separate allocation unit.

Alas, no. The call to get_page_from_gfn() takes a non-const struct

domain pointer, and I'm not opening that can of worms. Does your R-b still stand?

Yes.

Cool. Thanks :-)

Paul

Quoted 2 lines

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#25 lore raw

PATCH 6/8 viridian: add implementation of synthetic interrupt MSRs

In reply to Paul Durrant

This patch introduces an implementation of the SCONTROL, SVERSION, SIEFP, SIMP, EOM and SINT0-15 SynIC MSRs. No message source is added and, as such, nothing will yet generate a synthetic interrupt. A subsequent patch will add an implementation of synthetic timers which will need the infrastructure added by this patch to deliver expiry messages to the guest.

NOTE: A 'synic' option is added to the toolstack viridian enlightenments
enumeration but is deliberately not documented as enabling these SynIC registers without a message source is only useful for debugging.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

---
 tools/libxl/libxl.h                    |   6 +
 tools/libxl/libxl_dom.c                |   3 +
 tools/libxl/libxl_types.idl            |   1 +
 xen/arch/x86/hvm/viridian/synic.c      | 215 +++++++++++++++++++++++++
 xen/arch/x86/hvm/viridian/viridian.c   |  16 ++
 xen/arch/x86/hvm/vlapic.c              |  16 +-
 xen/include/asm-x86/hvm/hvm.h          |   3 +
 xen/include/asm-x86/hvm/viridian.h     |  24 +++
 xen/include/public/arch-x86/hvm/save.h |   2 +
 xen/include/public/hvm/params.h        |   7 +-
 10 files changed, 291 insertions(+), 2 deletions(-)
tools/libxl/libxl.h +6 -0
index a38e5cdba2..a923a380d3 100644
@@ -318,6 +318,12 @@
  */
 #define LIBXL_HAVE_VIRIDIAN_CRASH_CTL 1
 
+/*
+ * LIBXL_HAVE_VIRIDIAN_SYNIC indicates that the 'synic' value
+ * is present in the viridian enlightenment enumeration.
+ */
+#define LIBXL_HAVE_VIRIDIAN_SYNIC 1
+
 /*
  * LIBXL_HAVE_BUILDINFO_HVM_ACPI_LAPTOP_SLATE indicates that
  * libxl_domain_build_info has the u.hvm.acpi_laptop_slate field.
tools/libxl/libxl_dom.c +3 -0
index 6160991af3..fb758d2ac3 100644
@@ -317,6 +317,9 @@ static int hvm_set_viridian_features(libxl__gc *gc, uint32_t domid,
     if (libxl_bitmap_test(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_CRASH_CTL))
         mask |= HVMPV_crash_ctl;
 
+    if (libxl_bitmap_test(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_SYNIC))
+        mask |= HVMPV_synic;
+
     if (mask != 0 &&
         xc_hvm_param_set(CTX->xch,
                          domid,
tools/libxl/libxl_types.idl +1 -0
index 51cf06a3a2..ee5eed2945 100644
@@ -228,6 +228,7 @@ libxl_viridian_enlightenment = Enumeration("viridian_enlightenment", [
     (4, "hcall_remote_tlb_flush"),
     (5, "apic_assist"),
     (6, "crash_ctl"),
+    (7, "synic"),
     ])
 
 libxl_hdtype = Enumeration("hdtype", [
xen/arch/x86/hvm/viridian/synic.c +215 -0

283 lines not on this page · raw message

xen/arch/x86/hvm/viridian/viridian.c +16 -0
index 9da87379b7..dc53724468 100644
@@ -177,6 +177,8 @@ void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf,
             mask.AccessPartitionReferenceCounter = 1;
         if ( viridian_feature_mask(d) & HVMPV_reference_tsc )
             mask.AccessPartitionReferenceTsc = 1;
+        if ( viridian_feature_mask(d) & HVMPV_synic )
+            mask.AccessSynicRegs = 1;
 
         u.mask = mask;
 
@@ -306,8 +308,16 @@ int guest_wrmsr_viridian(struct vcpu *v, uint32_t idx, uint64_t val)
     case HV_X64_MSR_ICR:
     case HV_X64_MSR_TPR:
     case HV_X64_MSR_VP_ASSIST_PAGE:
+    case HV_X64_MSR_SCONTROL:
+    case HV_X64_MSR_SVERSION:
+    case HV_X64_MSR_SIEFP:
+    case HV_X64_MSR_SIMP:
+    case HV_X64_MSR_EOM:
+    case HV_X64_MSR_SINT0 ... HV_X64_MSR_SINT15:
         return viridian_synic_wrmsr(v, idx, val);
 
+    case HV_X64_MSR_TSC_FREQUENCY:
+    case HV_X64_MSR_APIC_FREQUENCY:
     case HV_X64_MSR_REFERENCE_TSC:
         return viridian_time_wrmsr(v, idx, val);
 
@@ -379,6 +389,12 @@ int guest_rdmsr_viridian(const struct vcpu *v, uint32_t idx, uint64_t *val)
     case HV_X64_MSR_ICR:
     case HV_X64_MSR_TPR:
     case HV_X64_MSR_VP_ASSIST_PAGE:
+    case HV_X64_MSR_SCONTROL:
+    case HV_X64_MSR_SVERSION:
+    case HV_X64_MSR_SIEFP:
+    case HV_X64_MSR_SIMP:
+    case HV_X64_MSR_EOM:
+    case HV_X64_MSR_SINT0 ... HV_X64_MSR_SINT15:
         return viridian_synic_rdmsr(v, idx, val);
 
     case HV_X64_MSR_TSC_FREQUENCY:
xen/arch/x86/hvm/vlapic.c +15 -1
index a1a43cd792..45d6ef91da 100644
@@ -461,11 +461,15 @@ void vlapic_EOI_set(struct vlapic *vlapic)
 
 void vlapic_handle_EOI(struct vlapic *vlapic, u8 vector)
 {
+    struct vcpu *v = vlapic_vcpu(vlapic);
     struct domain *d = vlapic_domain(vlapic);
 
     if ( vlapic_test_vector(vector, &vlapic->regs->data[APIC_TMR]) )
         vioapic_update_EOI(d, vector);
 
+    if ( has_viridian_synic(v->domain) )
+        viridian_synic_ack_sint(v, vector);
+
     hvm_dpci_msi_eoi(d, vector);
 }
 
@@ -1301,6 +1305,13 @@ int vlapic_has_pending_irq(struct vcpu *v)
     if ( !vlapic_enabled(vlapic) )
         return -1;
 
+    /*
+     * Poll the viridian message queues before checking the IRR since
+     * a sythetic interrupt may be asserted during the poll.
+     */
+    if ( has_viridian_synic(v->domain) )
+        viridian_synic_poll_messages(v);
+
     irr = vlapic_find_highest_irr(vlapic);
     if ( irr == -1 )
         return -1;
@@ -1360,7 +1371,10 @@ int vlapic_ack_pending_irq(struct vcpu *v, int vector, bool_t force_ack)
     }
 
  done:
-    vlapic_set_vector(vector, &vlapic->regs->data[APIC_ISR]);
+    if ( !has_viridian_synic(v->domain) ||
+         !viridian_synic_is_auto_eoi_sint(v, vector) )
+        vlapic_set_vector(vector, &vlapic->regs->data[APIC_ISR]);
+
     vlapic_clear_irr(vector, vlapic);
     return 1;
 }
xen/include/asm-x86/hvm/hvm.h +3 -0
index d8df6f4352..7892f98c7b 100644
@@ -470,6 +470,9 @@ static inline bool hvm_get_guest_bndcfgs(struct vcpu *v, u64 *val)
 #define has_viridian_apic_assist(d) \
     (is_viridian_domain(d) && (viridian_feature_mask(d) & HVMPV_apic_assist))
 
+#define has_viridian_synic(d) \
+    (is_viridian_domain(d) && (viridian_feature_mask(d) & HVMPV_synic))
+
 static inline void hvm_inject_exception(
     unsigned int vector, unsigned int type,
     unsigned int insn_len, int error_code)
xen/include/asm-x86/hvm/viridian.h +24 -0
index 1d281d825e..6d40d391e1 100644
@@ -26,10 +26,30 @@ struct viridian_page
     void *ptr;
 };
 
+union viridian_sint_msr
+{
+    uint64_t raw;
+    struct
+    {
+        uint64_t vector:8;
+        uint64_t reserved_preserved1:8;
+        uint64_t mask:1;
+        uint64_t auto_eoi:1;
+        uint64_t polling:1;
+        uint64_t reserved_preserved2:45;
+    } fields;
+};
+
 struct viridian_vcpu
 {
     struct viridian_page vp_assist;
     bool apic_assist_pending;
+    uint64_t scontrol;
+    uint64_t siefp;
+    struct viridian_page simp;
+    union viridian_sint_msr sint[16];
+    uint8_t vector_to_sintx[256];
+    unsigned long msg_pending;
     uint64_t crash_param[5];
 };
 
@@ -90,6 +110,10 @@ void viridian_apic_assist_set(struct vcpu *v);
 bool viridian_apic_assist_completed(struct vcpu *v);
 void viridian_apic_assist_clear(struct vcpu *v);
 
+bool viridian_synic_is_auto_eoi_sint(struct vcpu *v, uint8_t vector);
+void viridian_synic_poll_messages(struct vcpu *v);
+void viridian_synic_ack_sint(struct vcpu *v, uint8_t vector);
+
 #endif /* __ASM_X86_HVM_VIRIDIAN_H__ */
 
 /*
xen/include/public/arch-x86/hvm/save.h +2 -0
index 40be84ecda..ec3e4df12c 100644
@@ -602,6 +602,8 @@ struct hvm_viridian_vcpu_context {
     uint64_t vp_assist_msr;
     uint8_t  apic_assist_pending;
     uint8_t  _pad[7];
+    uint64_t simp_msr;
+    uint64_t sint_msr[16];
 };
 
 DECLARE_HVM_SAVE_TYPE(VIRIDIAN_VCPU, 17, struct hvm_viridian_vcpu_context);
xen/include/public/hvm/params.h +6 -1
index 72f633ef2d..e7e3c7c892 100644
@@ -146,6 +146,10 @@
 #define _HVMPV_crash_ctl 6
 #define HVMPV_crash_ctl (1 << _HVMPV_crash_ctl)
 
+/* Enable SYNIC MSRs */
+#define _HVMPV_synic 7
+#define HVMPV_synic (1 << _HVMPV_synic)
+
 #define HVMPV_feature_mask \
         (HVMPV_base_freq | \
          HVMPV_no_freq | \
@@ -153,7 +157,8 @@
          HVMPV_reference_tsc | \
          HVMPV_hcall_remote_tlb_flush | \
          HVMPV_apic_assist | \
-         HVMPV_crash_ctl)
+         HVMPV_crash_ctl | \
+         HVMPV_synic)
 
 #endif
 
Signature · 7 lines
2.20.1.2.gb21ebb671


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
#26 lore raw

Re: [PATCH 6/8] viridian: add implementation of synthetic interrupt MSRs

Quoted 23 lines · Paul Durrant

This patch introduces an implementation of the SCONTROL, SVERSION, SIEFP, SIMP, EOM and SINT0-15 SynIC MSRs. No message source is added and, as such, nothing will yet generate a synthetic interrupt. A subsequent patch will add an implementation of synthetic timers which will need the infrastructure added by this patch to deliver expiry messages to the guest.

NOTE: A 'synic' option is added to the toolstack viridian enlightenments
enumeration but is deliberately not documented as enabling these SynIC registers without a message source is only useful for debugging.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

Quoted 4 lines
---
 tools/libxl/libxl.h                    |   6 +
 tools/libxl/libxl_dom.c                |   3 +
 tools/libxl/libxl_types.idl            |   1 +

It seems that xl changes are missing?

Quoted 57 lines
 xen/arch/x86/hvm/viridian/synic.c      | 215 +++++++++++++++++++++++++
 xen/arch/x86/hvm/viridian/viridian.c   |  16 ++
 xen/arch/x86/hvm/vlapic.c              |  16 +-
 xen/include/asm-x86/hvm/hvm.h          |   3 +
 xen/include/asm-x86/hvm/viridian.h     |  24 +++
 xen/include/public/arch-x86/hvm/save.h |   2 +
 xen/include/public/hvm/params.h        |   7 +-
 10 files changed, 291 insertions(+), 2 deletions(-)
tools/libxl/libxl.h +6 -0
index a38e5cdba2..a923a380d3 100644
@@ -318,6 +318,12 @@
  */
 #define LIBXL_HAVE_VIRIDIAN_CRASH_CTL 1
 
+/*
+ * LIBXL_HAVE_VIRIDIAN_SYNIC indicates that the 'synic' value
+ * is present in the viridian enlightenment enumeration.
+ */
+#define LIBXL_HAVE_VIRIDIAN_SYNIC 1
+
 /*
  * LIBXL_HAVE_BUILDINFO_HVM_ACPI_LAPTOP_SLATE indicates that
  * libxl_domain_build_info has the u.hvm.acpi_laptop_slate field.
tools/libxl/libxl_dom.c +3 -0
index 6160991af3..fb758d2ac3 100644
@@ -317,6 +317,9 @@ static int hvm_set_viridian_features(libxl__gc *gc, uint32_t domid,
     if (libxl_bitmap_test(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_CRASH_CTL))
         mask |= HVMPV_crash_ctl;
 
+    if (libxl_bitmap_test(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_SYNIC))
+        mask |= HVMPV_synic;
+
     if (mask != 0 &&
         xc_hvm_param_set(CTX->xch,
                          domid,
tools/libxl/libxl_types.idl +1 -0
index 51cf06a3a2..ee5eed2945 100644
@@ -228,6 +228,7 @@ libxl_viridian_enlightenment = Enumeration("viridian_enlightenment", [
     (4, "hcall_remote_tlb_flush"),
     (5, "apic_assist"),
     (6, "crash_ctl"),
+    (7, "synic"),
     ])
 
 libxl_hdtype = Enumeration("hdtype", [
xen/arch/x86/hvm/viridian/synic.c +0 -0
index 35bd2125fc..8a819c8161 100644

xen/arch/x86/hvm/viridian/synic.c line 11

Quoted 4 lines
xen/arch/x86/hvm/viridian/synic.c +1 -0
@@ -8,11 +8,13 @@
 
 #include <xen/domain_page.h>
 #include <xen/hypercall.h>
+#include <xen/nospec.h>

This header is included by array_index_nospec is not used anywhere.

I'm afraid I will need to shelve reviewing the rest for a while because I haven't read the viridian spec.

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#27 lore raw

Re: [PATCH 6/8] viridian: add implementation of synthetic interrupt MSRs

Quoted 45 lines

-----Original Message-----
From: Wei Liu [mailto:[email protected]]
Sent: 02 January 2019 15:56
To: Paul Durrant <[email protected]>
Cc: [email protected]; Ian Jackson <[email protected]>; Wei Liu <[email protected]>; Andrew Cooper <[email protected]>; George Dunlap <[email protected]>; Jan Beulich <[email protected]>; Julien Grall <[email protected]>; Konrad Rzeszutek Wilk <[email protected]>; Stefano Stabellini <[email protected]>; Tim (Xen.org) <[email protected]>; Roger Pau Monne <[email protected]>
Subject: Re: [PATCH 6/8] viridian: add implementation of synthetic interrupt MSRs

Quoted 1 line · Paul Durrant

This patch introduces an implementation of the SCONTROL, SVERSION,

SIEFP,

Quoted 1 line

SIMP, EOM and SINT0-15 SynIC MSRs. No message source is added and, as

such,

Quoted 2 lines

nothing will yet generate a synthetic interrupt. A subsequent patch will add an implementation of synthetic timers which will need the

infrastructure

Quoted 19 lines

added by this patch to deliver expiry messages to the guest.

NOTE: A 'synic' option is added to the toolstack viridian enlightenments
enumeration but is deliberately not documented as enabling these SynIC registers without a message source is only useful for debugging.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

Quoted 4 lines
---
 tools/libxl/libxl.h                    |   6 +
 tools/libxl/libxl_dom.c                |   3 +
 tools/libxl/libxl_types.idl            |   1 +
Quoted 1 line

It seems that xl changes are missing?

No xl changes are needed thanks to the magic that is libxl enum parsing :-)

Quoted 64 lines

tools/libxl/libxl_dom.c static int hvm_set_viridian_features(libxl__gc *gc,

Quoted 32 lines
 xen/arch/x86/hvm/viridian/synic.c      | 215 +++++++++++++++++++++++++
 xen/arch/x86/hvm/viridian/viridian.c   |  16 ++
 xen/arch/x86/hvm/vlapic.c              |  16 +-
 xen/include/asm-x86/hvm/hvm.h          |   3 +
 xen/include/asm-x86/hvm/viridian.h     |  24 +++
 xen/include/public/arch-x86/hvm/save.h |   2 +
 xen/include/public/hvm/params.h        |   7 +-
 10 files changed, 291 insertions(+), 2 deletions(-)
tools/libxl/libxl.h +6 -0
index a38e5cdba2..a923a380d3 100644
@@ -318,6 +318,12 @@
  */
 #define LIBXL_HAVE_VIRIDIAN_CRASH_CTL 1
 
+/*
+ * LIBXL_HAVE_VIRIDIAN_SYNIC indicates that the 'synic' value
+ * is present in the viridian enlightenment enumeration.
+ */
+#define LIBXL_HAVE_VIRIDIAN_SYNIC 1
+
 /*
  * LIBXL_HAVE_BUILDINFO_HVM_ACPI_LAPTOP_SLATE indicates that
  * libxl_domain_build_info has the u.hvm.acpi_laptop_slate field.
tools/libxl/libxl_dom.c +0 -0
index 6160991af3..fb758d2ac3 100644
@@ -317,6 +317,9 @@ static int hvm_set_viridian_features(libxl__gc *gc,

uint32_t domid,

tools/libxl/libxl_dom.c static int hvm_set_viridian_features(libxl__gc *gc, · line 317

Quoted 1 line
tools/libxl/libxl_dom.c +0 -0
     if (libxl_bitmap_test(&enlightenments,

LIBXL_VIRIDIAN_ENLIGHTENMENT_CRASH_CTL))

tools/libxl/libxl_dom.c static int hvm_set_viridian_features(libxl__gc *gc, uint32_t domid,

Quoted 3 lines
tools/libxl/libxl_dom.c +1 -0
         mask |= HVMPV_crash_ctl;
 
+    if (libxl_bitmap_test(&enlightenments,

LIBXL_VIRIDIAN_ENLIGHTENMENT_SYNIC))

tools/libxl/libxl_types.idl libxl_viridian_enlightenment =

Quoted 10 lines
tools/libxl/libxl_dom.c +2 -0
+        mask |= HVMPV_synic;
+
     if (mask != 0 &&
         xc_hvm_param_set(CTX->xch,
                          domid,
tools/libxl/libxl_types.idl +0 -0
index 51cf06a3a2..ee5eed2945 100644
@@ -228,6 +228,7 @@ libxl_viridian_enlightenment =

Enumeration("viridian_enlightenment", [

Review

Quoted 8 lines
tools/libxl/libxl_types.idl +1 -0
     (4, "hcall_remote_tlb_flush"),
     (5, "apic_assist"),
     (6, "crash_ctl"),
+    (7, "synic"),
     ])
 
 libxl_hdtype = Enumeration("hdtype", [
(quoted diff) +0 -0

b/xen/arch/x86/hvm/viridian/synic.c

Quoted 5 lines

index 35bd2125fc..8a819c8161 100644

xen/arch/x86/hvm/viridian/synic.c +0 -0
@@ -8,11 +8,13 @@
 
Quoted 5 lines

xen/arch/x86/hvm/viridian/synic.c line 11

Quoted 3 lines
xen/arch/x86/hvm/viridian/synic.c +1 -0
 #include <xen/domain_page.h>
 #include <xen/hypercall.h>
+#include <xen/nospec.h>

This header is included by array_index_nospec is not used anywhere.

Ah yes, I originally thought I needed it but then changed my mind.

Quoted 3 lines

I'm afraid I will need to shelve reviewing the rest for a while because I haven't read the viridian spec.

Sections 10, 11 and 12 are the ones relevant to this series. The spec. is not exactly a great read though :-(

Paul

Quoted 2 lines

Wei.

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#28 lore raw

PATCH 7/8 viridian: stop directly calling viridian_time_ref_count_freeze/thaw()...

In reply to Paul Durrant

...from arch_domain_shutdown/pause/unpause().

A subsequent patch will introduce an implementaion of synthetic timers which will also need freeze/thaw hooks, so make the exported hooks more generic and call through to (re-named and static) time_ref_count_freeze/thaw functions.

NOTE: This patch also introduces a new time_ref_count() helper to return
the current counter value. This is currently only used by the MSR read handler but the synthetic timer code will also need to use it.

---
Cc: Jan Beulich <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

---
 xen/arch/x86/domain.c              | 12 ++++++------
 xen/arch/x86/hvm/viridian/time.c   | 24 +++++++++++++++++++++---
 xen/include/asm-x86/hvm/viridian.h |  4 ++--
 3 files changed, 29 insertions(+), 11 deletions(-)
xen/arch/x86/domain.c +6 -6
index 32dc4253ff..ed2a57a8a6 100644
@@ -658,20 +658,20 @@ void arch_domain_destroy(struct domain *d)
 
 void arch_domain_shutdown(struct domain *d)
 {
-    if ( has_viridian_time_ref_count(d) )
-        viridian_time_ref_count_freeze(d);
+    if ( is_viridian_domain(d) )
+        viridian_time_domain_freeze(d);
 }
 
 void arch_domain_pause(struct domain *d)
 {
-    if ( has_viridian_time_ref_count(d) )
-        viridian_time_ref_count_freeze(d);
+    if ( is_viridian_domain(d) )
+        viridian_time_domain_freeze(d);
 }
 
 void arch_domain_unpause(struct domain *d)
 {
-    if ( has_viridian_time_ref_count(d) )
-        viridian_time_ref_count_thaw(d);
+    if ( is_viridian_domain(d) )
+        viridian_time_domain_thaw(d);
 }
 
 int arch_domain_soft_reset(struct domain *d)
xen/arch/x86/hvm/viridian/time.c +21 -3
index e8924adfa1..cb7162c2d4 100644
@@ -91,7 +91,7 @@ static int64_t raw_trc_val(struct domain *d)
     return scale_delta(tsc, &tsc_to_ns) / 100ul;
 }
 
-void viridian_time_ref_count_freeze(struct domain *d)
+static void time_ref_count_freeze(struct domain *d)
 {
     struct viridian_time_ref_count *trc =
         &d->arch.hvm.viridian->time_ref_count;
@@ -100,7 +100,7 @@ void viridian_time_ref_count_freeze(struct domain *d)
         trc->val = raw_trc_val(d) + trc->off;
 }
 
-void viridian_time_ref_count_thaw(struct domain *d)
+static void time_ref_count_thaw(struct domain *d)
 {
     struct viridian_time_ref_count *trc =
         &d->arch.hvm.viridian->time_ref_count;
@@ -110,6 +110,24 @@ void viridian_time_ref_count_thaw(struct domain *d)
         trc->off = (int64_t)trc->val - raw_trc_val(d);
 }
 
+static int64_t time_ref_count(struct domain *d)
+{
+    struct viridian_time_ref_count *trc =
+        &d->arch.hvm.viridian->time_ref_count;
+
+    return raw_trc_val(d) + trc->off;
+}
+
+void viridian_time_domain_freeze(struct domain *d)
+{
+    time_ref_count_freeze(d);
+}
+
+void viridian_time_domain_thaw(struct domain *d)
+{
+    time_ref_count_thaw(d);
+}
+
 int viridian_time_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val)
 {
     struct domain *d = v->domain;
@@ -179,7 +197,7 @@ int viridian_time_rdmsr(const struct vcpu *v, uint32_t idx, uint64_t *val)
             printk(XENLOG_G_INFO "d%d: VIRIDIAN MSR_TIME_REF_COUNT: accessed\n",
                    d->domain_id);
 
-        *val = raw_trc_val(d) + trc->off;
+        *val = time_ref_count(d);
         break;
     }
 
xen/include/asm-x86/hvm/viridian.h +2 -2
index 6d40d391e1..9a493cf048 100644
@@ -97,8 +97,8 @@ int guest_rdmsr_viridian(const struct vcpu *v, uint32_t idx, uint64_t *val);
 int
 viridian_hypercall(struct cpu_user_regs *regs);
 
-void viridian_time_ref_count_freeze(struct domain *d);
-void viridian_time_ref_count_thaw(struct domain *d);
+void viridian_time_domain_freeze(struct domain *d);
+void viridian_time_domain_thaw(struct domain *d);
 
 int viridian_vcpu_init(struct vcpu *v);
 int viridian_domain_init(struct domain *d);
Signature · 7 lines
2.20.1.2.gb21ebb671


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Reviewed-by on v1 7/8
#29 lore raw

Re: [PATCH 7/8] viridian: stop directly calling viridian_time_ref_count_freeze/thaw()...

Quoted 7 lines · Paul Durrant

...from arch_domain_shutdown/pause/unpause().

A subsequent patch will introduce an implementaion of synthetic timers which will also need freeze/thaw hooks, so make the exported hooks more generic and call through to (re-named and static) time_ref_count_freeze/thaw functions.

Quoted 6 lines

NOTE: This patch also introduces a new time_ref_count() helper to return
the current counter value. This is currently only used by the MSR read handler but the synthetic timer code will also need to use it.

---

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel

#30 lore raw

PATCH 8/8 viridian: add implementation of synthetic timers

In reply to Paul Durrant

This patch introduces an implementation of the STIMER0-15_CONFIG/COUNT MSRs and hence a the first SynIC message source.

The new (and documented) 'stimer' viridian enlightenment group may be specified to enable this feature.

NOTE: It is necessary for correct operation that timer expiration and
message delivery time-stamping use the same time source as the guest. The specification is ambiguous but testing with a Windows 10 1803 guest has shown that using the partition reference counter as a source whilst the guest is using RDTSC and the reference tsc page does not work correctly. Therefore the time_now() function is used. This implements the algorithm for acquiring partition reference time that is documented in the specifiction. This requires use of 128-bit arithmetic and hence __int128_t values are used in the calculation, although the result is a signed 64-bit value.

---
Cc: Ian Jackson <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Andrew Cooper <[email protected]>
Cc: George Dunlap <[email protected]>
Cc: Jan Beulich <[email protected]>
Cc: Julien Grall <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Tim Deegan <[email protected]>
Cc: "Roger Pau Monné" <[email protected]>

---
 docs/man/xl.cfg.pod.5.in               |  12 +-
 tools/libxl/libxl.h                    |   6 +
 tools/libxl/libxl_dom.c                |   4 +
 tools/libxl/libxl_types.idl            |   1 +
 xen/arch/x86/hvm/viridian/private.h    |   6 +
 xen/arch/x86/hvm/viridian/synic.c      |  48 +++-
 xen/arch/x86/hvm/viridian/time.c       | 327 +++++++++++++++++++++++++
 xen/arch/x86/hvm/viridian/viridian.c   |  21 ++
 xen/include/asm-x86/hvm/viridian.h     |  30 +++
 xen/include/public/arch-x86/hvm/save.h |   2 +
 xen/include/public/hvm/params.h        |   7 +-
 11 files changed, 460 insertions(+), 4 deletions(-)
docs/man/xl.cfg.pod.5.in +10 -2
index 3b92f39d8d..5496eb2db8 100644
@@ -2251,11 +2251,19 @@ This group incorporates the crash control MSRs. These enlightenments
 allow Windows to write crash information such that it can be logged
 by Xen.
 
+=item B<stimer>
+
+This set incorporates the SynIC and synthetic timer MSRs. Windows will
+use synthetic timers in preference to emulated HPET for a source of
+ticks and hence enabling this group will ensure that ticks will be
+consistent with use of an enlightened time source (B<time_ref_count> or
+B<reference_tsc>).
+
 =item B<defaults>
 
 This is a special value that enables the default set of groups, which
-is currently the B<base>, B<freq>, B<time_ref_count>, B<apic_assist>
-and B<crash_ctl> groups.
+is currently the B<base>, B<freq>, B<time_ref_count>, B<apic_assist>,
+B<crash_ctl> and B<stimer> groups.
 
 =item B<all>
 
tools/libxl/libxl.h +6 -0
index a923a380d3..c8f219b0d3 100644
@@ -324,6 +324,12 @@
  */
 #define LIBXL_HAVE_VIRIDIAN_SYNIC 1
 
+/*
+ * LIBXL_HAVE_VIRIDIAN_STIMER indicates that the 'stimer' value
+ * is present in the viridian enlightenment enumeration.
+ */
+#define LIBXL_HAVE_VIRIDIAN_STIMER 1
+
 /*
  * LIBXL_HAVE_BUILDINFO_HVM_ACPI_LAPTOP_SLATE indicates that
  * libxl_domain_build_info has the u.hvm.acpi_laptop_slate field.
tools/libxl/libxl_dom.c +4 -0
index fb758d2ac3..2ee0f82ee7 100644
@@ -269,6 +269,7 @@ static int hvm_set_viridian_features(libxl__gc *gc, uint32_t domid,
         libxl_bitmap_set(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_TIME_REF_COUNT);
         libxl_bitmap_set(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_APIC_ASSIST);
         libxl_bitmap_set(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_CRASH_CTL);
+        libxl_bitmap_set(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_STIMER);
     }
 
     libxl_for_each_set_bit(v, info->u.hvm.viridian_enable) {
@@ -320,6 +321,9 @@ static int hvm_set_viridian_features(libxl__gc *gc, uint32_t domid,
     if (libxl_bitmap_test(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_SYNIC))
         mask |= HVMPV_synic;
 
+    if (libxl_bitmap_test(&enlightenments, LIBXL_VIRIDIAN_ENLIGHTENMENT_STIMER))
+        mask |= HVMPV_time_ref_count | HVMPV_synic | HVMPV_stimer;
+
     if (mask != 0 &&
         xc_hvm_param_set(CTX->xch,
                          domid,
tools/libxl/libxl_types.idl +1 -0
index ee5eed2945..494e0bb2f6 100644
@@ -229,6 +229,7 @@ libxl_viridian_enlightenment = Enumeration("viridian_enlightenment", [
     (5, "apic_assist"),
     (6, "crash_ctl"),
     (7, "synic"),
+    (8, "stimer"),
     ])
 
 libxl_hdtype = Enumeration("hdtype", [
xen/arch/x86/hvm/viridian/private.h +6 -0
index 0bf34eefe0..6f81f62b60 100644
@@ -74,6 +74,10 @@
 int viridian_synic_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val);
 int viridian_synic_rdmsr(const struct vcpu *v, uint32_t idx, uint64_t *val);
 
+bool viridian_synic_deliver_timer_msg(struct vcpu *v, unsigned int sintx,
+                                      unsigned int index,
+                                      int64_t expiration, int64_t delivery);
+
 int viridian_synic_vcpu_init(struct vcpu *v);
 int viridian_synic_domain_init(struct domain *d);
 
@@ -93,6 +97,8 @@ void viridian_synic_load_domain_ctxt(
 int viridian_time_wrmsr(struct vcpu *v, uint32_t idx, uint64_t val);
 int viridian_time_rdmsr(const struct vcpu *v, uint32_t idx, uint64_t *val);
 
+void viridian_time_poll_timers(struct vcpu *v);
+
 int viridian_time_vcpu_init(struct vcpu *v);
 int viridian_time_domain_init(struct domain *d);
 
xen/arch/x86/hvm/viridian/synic.c +47 -1

54 lines not on this page · raw message

xen/arch/x86/hvm/viridian/time.c +327 -0

382 lines not on this page · raw message

xen/arch/x86/hvm/viridian/viridian.c +21 -0
index dc53724468..9e3034afc3 100644
@@ -179,6 +179,8 @@ void cpuid_viridian_leaves(const struct vcpu *v, uint32_t leaf,
             mask.AccessPartitionReferenceTsc = 1;
         if ( viridian_feature_mask(d) & HVMPV_synic )
             mask.AccessSynicRegs = 1;
+        if ( viridian_feature_mask(d) & HVMPV_stimer )
+            mask.AccessSyntheticTimerRegs = 1;
 
         u.mask = mask;
 
@@ -319,6 +321,15 @@ int guest_wrmsr_viridian(struct vcpu *v, uint32_t idx, uint64_t val)
     case HV_X64_MSR_TSC_FREQUENCY:
     case HV_X64_MSR_APIC_FREQUENCY:
     case HV_X64_MSR_REFERENCE_TSC:
+    case HV_X64_MSR_TIME_REF_COUNT:
+    case HV_X64_MSR_STIMER0_CONFIG:
+    case HV_X64_MSR_STIMER0_COUNT:
+    case HV_X64_MSR_STIMER1_CONFIG:
+    case HV_X64_MSR_STIMER1_COUNT:
+    case HV_X64_MSR_STIMER2_CONFIG:
+    case HV_X64_MSR_STIMER2_COUNT:
+    case HV_X64_MSR_STIMER3_CONFIG:
+    case HV_X64_MSR_STIMER3_COUNT:
         return viridian_time_wrmsr(v, idx, val);
 
     case HV_X64_MSR_CRASH_P0:
@@ -401,6 +412,14 @@ int guest_rdmsr_viridian(const struct vcpu *v, uint32_t idx, uint64_t *val)
     case HV_X64_MSR_APIC_FREQUENCY:
     case HV_X64_MSR_REFERENCE_TSC:
     case HV_X64_MSR_TIME_REF_COUNT:
+    case HV_X64_MSR_STIMER0_CONFIG:
+    case HV_X64_MSR_STIMER0_COUNT:
+    case HV_X64_MSR_STIMER1_CONFIG:
+    case HV_X64_MSR_STIMER1_COUNT:
+    case HV_X64_MSR_STIMER2_CONFIG:
+    case HV_X64_MSR_STIMER2_COUNT:
+    case HV_X64_MSR_STIMER3_CONFIG:
+    case HV_X64_MSR_STIMER3_COUNT:
         return viridian_time_rdmsr(v, idx, val);
 
     case HV_X64_MSR_CRASH_P0:
@@ -750,6 +769,7 @@ static int viridian_save_vcpu_ctxt(struct vcpu *v, hvm_domain_context_t *h)
     if ( !is_viridian_vcpu(v) )
         return 0;
 
+    viridian_time_save_vcpu_ctxt(v, &ctxt);
     viridian_synic_save_vcpu_ctxt(v, &ctxt);
 
     return hvm_save_entry(VIRIDIAN_VCPU, v->vcpu_id, h, &ctxt);
@@ -776,6 +796,7 @@ static int viridian_load_vcpu_ctxt(struct domain *d,
         return -EINVAL;
 
     viridian_synic_load_vcpu_ctxt(v, &ctxt);
+    viridian_time_load_vcpu_ctxt(v, &ctxt);
 
     return 0;
 }
xen/include/asm-x86/hvm/viridian.h +30 -0
index 9a493cf048..32da65a064 100644
@@ -40,6 +40,33 @@ union viridian_sint_msr
     } fields;
 };
 
+union viridian_stimer_config_msr
+{
+    uint64_t raw;
+    struct
+    {
+        uint64_t enabled:1;
+        uint64_t periodic:1;
+        uint64_t lazy:1;
+        uint64_t auto_enable:1;
+        uint64_t vector:8;
+        uint64_t direct_mode:1;
+        uint64_t reserved_zero1:3;
+        uint64_t sintx:4;
+        uint64_t reserved_zero2:44;
+    } fields;
+};
+
+struct viridian_stimer {
+    struct vcpu *v;
+    struct timer timer;
+    union viridian_stimer_config_msr config;
+    uint64_t count;
+    int64_t expiration;
+    s_time_t timeout;
+    bool started;
+};
+
 struct viridian_vcpu
 {
     struct viridian_page vp_assist;
@@ -50,6 +77,9 @@ struct viridian_vcpu
     union viridian_sint_msr sint[16];
     uint8_t vector_to_sintx[256];
     unsigned long msg_pending;
+    struct viridian_stimer stimer[4];
+    unsigned long stimer_enabled;
+    unsigned long stimer_pending;
     uint64_t crash_param[5];
 };
 
xen/include/public/arch-x86/hvm/save.h +2 -0
index ec3e4df12c..8344aa471f 100644
@@ -604,6 +604,8 @@ struct hvm_viridian_vcpu_context {
     uint8_t  _pad[7];
     uint64_t simp_msr;
     uint64_t sint_msr[16];
+    uint64_t stimer_config_msr[4];
+    uint64_t stimer_count_msr[4];
 };
 
 DECLARE_HVM_SAVE_TYPE(VIRIDIAN_VCPU, 17, struct hvm_viridian_vcpu_context);
xen/include/public/hvm/params.h +6 -1
index e7e3c7c892..e06b0942d0 100644
@@ -150,6 +150,10 @@
 #define _HVMPV_synic 7
 #define HVMPV_synic (1 << _HVMPV_synic)
 
+/* Enable STIMER MSRs */
+#define _HVMPV_stimer 8
+#define HVMPV_stimer (1 << _HVMPV_stimer)
+
 #define HVMPV_feature_mask \
         (HVMPV_base_freq | \
          HVMPV_no_freq | \
@@ -158,7 +162,8 @@
          HVMPV_hcall_remote_tlb_flush | \
          HVMPV_apic_assist | \
          HVMPV_crash_ctl | \
-         HVMPV_synic)
+         HVMPV_synic | \
+         HVMPV_stimer)
 
 #endif
 
Signature · 7 lines
2.20.1.2.gb21ebb671


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel