Skip to contentSkip to conversation

x86/cpuid: Hide the legacy cpuids[] infrastructure

PATCH In review Andrew Cooper 2 participants 12 messages Jan 11, 2017 – Jan 13, 2017

lore
Share & tools
lore
#0 lore raw

cover x86/cpuid: Hide the legacy cpuids[] infrastructure

The purpose of this series is to hide the legacy cpuid implementation entirely behind the new API. In particular, hiding domain_cpuid() in the same way that {pv,hvm}_cpuid() were hidden.

Andrew Cooper (4):
x86/domctl: Move all CPUID update logic into
update_domain_cpuid_info()
x86/cpuid: Store the toolstacks choice of hypervisor max leaf x86/cpuid: Effectively remove domain_cpuid() x86/cpuid: Move the legacy cpuids array into struct cpuid_policy

 xen/arch/x86/cpuid.c         |  32 +++++++++-
 xen/arch/x86/domain.c        |  54 +---------------
 xen/arch/x86/domctl.c        | 148 +++++++++++++++++++++++++++----------------
 xen/arch/x86/traps.c         |  19 ++----
 xen/include/asm-x86/cpuid.h  |   7 ++
 xen/include/asm-x86/domain.h |  13 ----
 6 files changed, 137 insertions(+), 136 deletions(-)
Signature · 7 lines
2.1.4


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

PATCH 1/4 x86/domctl: Move all CPUID update logic into update_domain_cpuid_info()

This simplifies the XEN_DOMCTL_set_cpuid handling, splitting the safety logic away from the internals of how an update is completed.

The legacy cpuids[] logic is left in alone in a fuction, as it wont survive very long. update_domain_cpuid_info() gains a small performance optimisation to skip all update activites for leaves which won't have any impact on the guest. This is temporary until the new hypercall API is completed.

---
CC: Jan Beulich <[email protected]>

The number hypercalls made by the toolstack is quite large, while the number which we care about will reduce as Xen does more calculations itself, at the same time as the cost of recaculations growing.

---
 xen/arch/x86/domctl.c | 140 +++++++++++++++++++++++++++++++-------------------
 1 file changed, 86 insertions(+), 54 deletions(-)
xen/arch/x86/domctl.c +86 -54
index b01a1f9..a5a56ee 100644
@@ -48,30 +48,98 @@ static int gdbsx_guest_mem_io(domid_t domid, struct xen_domctl_gdbsx_memio *iop)
     return iop->remain ? -EFAULT : 0;
 }
 
-static void update_domain_cpuid_info(struct domain *d,
+static int update_legacy_cpuid_array(struct domain *d,
                                      const xen_domctl_cpuid_t *ctl)
 {
+    cpuid_input_t *cpuid, *unused = NULL;
+    unsigned int i;
+
+    /* Try to insert ctl into d->arch.cpuids[] */
+    for ( i = 0; i < MAX_CPUID_INPUT; i++ )
+    {
+        cpuid = &d->arch.cpuids[i];
+
+        if ( cpuid->input[0] == XEN_CPUID_INPUT_UNUSED )
+        {
+            if ( !unused )
+                unused = cpuid;
+            continue;
+        }
+
+        if ( (cpuid->input[0] == ctl->input[0]) &&
+             ((cpuid->input[1] == XEN_CPUID_INPUT_UNUSED) ||
+              (cpuid->input[1] == ctl->input[1])) )
+            break;
+    }
+
+    if ( !(ctl->eax | ctl->ebx | ctl->ecx | ctl->edx) )
+    {
+        if ( i < MAX_CPUID_INPUT )
+            cpuid->input[0] = XEN_CPUID_INPUT_UNUSED;
+    }
+    else if ( i < MAX_CPUID_INPUT )
+        *cpuid = *ctl;
+    else if ( unused )
+        *unused = *ctl;
+    else
+        return -ENOENT;
+
+    return 0;
+}
+
+static int update_domain_cpuid_info(struct domain *d,
+                                    const xen_domctl_cpuid_t *ctl)
+{
     struct cpuid_policy *p = d->arch.cpuid;
     const struct cpuid_leaf leaf = { ctl->eax, ctl->ebx, ctl->ecx, ctl->edx };
+    int rc;
+
+    /*
+     * Skip update for leaves we don't care about.  This avoids the overhead
+     * of recalculate_cpuid_policy() and making d->arch.cpuids[] needlessly
+     * longer to search.
+     */
+    switch ( ctl->input[0] )
+    {
+    case 0x00000000 ... ARRAY_SIZE(p->basic.raw) - 1:
+        if ( ctl->input[0] == 7 &&
+             ctl->input[1] >= ARRAY_SIZE(p->feat.raw) )
+            return 0;
+        if ( ctl->input[0] == XSTATE_CPUID &&
+             ctl->input[1] >= ARRAY_SIZE(p->xstate.raw) )
+            return 0;
+        break;
+
+    case 0x40000000: case 0x40000100:
+        /* Only care about the max_leaf limit. */
+
+    case 0x80000000 ... 0x80000000 + ARRAY_SIZE(p->extd.raw) - 1:
+        break;
+
+    default:
+        return 0;
+    }
+
+    rc = update_legacy_cpuid_array(d, ctl);
+    if ( rc )
+        return rc;
 
     /* Insert ctl data into cpuid_policy. */
-    if ( ctl->input[0] < ARRAY_SIZE(p->basic.raw) )
+    switch ( ctl->input[0] )
     {
+    case 0x00000000 ... ARRAY_SIZE(p->basic.raw) - 1:
         if ( ctl->input[0] == 7 )
-        {
-            if ( ctl->input[1] < ARRAY_SIZE(p->feat.raw) )
-                p->feat.raw[ctl->input[1]] = leaf;
-        }
+            p->feat.raw[ctl->input[1]] = leaf;
         else if ( ctl->input[0] == XSTATE_CPUID )
-        {
-            if ( ctl->input[1] < ARRAY_SIZE(p->xstate.raw) )
-                p->xstate.raw[ctl->input[1]] = leaf;
-        }
+            p->xstate.raw[ctl->input[1]] = leaf;
         else
             p->basic.raw[ctl->input[0]] = leaf;
-    }
-    else if ( (ctl->input[0] - 0x80000000) < ARRAY_SIZE(p->extd.raw) )
+        break;
+
+    case 0x80000000 ... 0x80000000 + ARRAY_SIZE(p->extd.raw) - 1:
         p->extd.raw[ctl->input[0] - 0x80000000] = leaf;
+        break;
+    }
 
     recalculate_cpuid_policy(d);
 
@@ -243,6 +311,8 @@ static void update_domain_cpuid_info(struct domain *d,
         }
         break;
     }
+
+    return 0;
 }
 
 void arch_get_domain_info(const struct domain *d,
@@ -869,53 +939,15 @@ long arch_do_domctl(
     }
 
     case XEN_DOMCTL_set_cpuid:
-    {
-        const xen_domctl_cpuid_t *ctl = &domctl->u.cpuid;
-        cpuid_input_t *cpuid, *unused = NULL;
-
         if ( d == currd ) /* no domain_pause() */
-        {
             ret = -EINVAL;
-            break;
-        }
-
-        for ( i = 0; i < MAX_CPUID_INPUT; i++ )
-        {
-            cpuid = &d->arch.cpuids[i];
-
-            if ( cpuid->input[0] == XEN_CPUID_INPUT_UNUSED )
-            {
-                if ( !unused )
-                    unused = cpuid;
-                continue;
-            }
-
-            if ( (cpuid->input[0] == ctl->input[0]) &&
-                 ((cpuid->input[1] == XEN_CPUID_INPUT_UNUSED) ||
-                  (cpuid->input[1] == ctl->input[1])) )
-                break;
-        }
-
-        domain_pause(d);
-
-        if ( !(ctl->eax | ctl->ebx | ctl->ecx | ctl->edx) )
+        else
         {
-            if ( i < MAX_CPUID_INPUT )
-                cpuid->input[0] = XEN_CPUID_INPUT_UNUSED;
+            domain_pause(d);
+            ret = update_domain_cpuid_info(d, &domctl->u.cpuid);
+            domain_unpause(d);
         }
-        else if ( i < MAX_CPUID_INPUT )
-            *cpuid = *ctl;
-        else if ( unused )
-            *unused = *ctl;
-        else
-            ret = -ENOENT;
-
-        if ( !ret )
-            update_domain_cpuid_info(d, ctl);
-
-        domain_unpause(d);
         break;
-    }
 
     case XEN_DOMCTL_gettscinfo:
         if ( d == currd ) /* no domain_pause() */
Signature · 7 lines
2.1.4


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

Re: [PATCH 1/4] x86/domctl: Move all CPUID update logic into update_domain_cpuid_info()

Quoted 11 lines
Quoted 1 line
Quoted 1 line · On 11.01.17 at 18:44, <[email protected]> wrote:

This simplifies the XEN_DOMCTL_set_cpuid handling, splitting the safety logic away from the internals of how an update is completed.

The legacy cpuids[] logic is left in alone in a fuction, as it wont survive very long. update_domain_cpuid_info() gains a small performance optimisation
to skip all update activites for leaves which won't have any impact on the guest. This is temporary until the new hypercall API is completed.

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

#3 lore raw

PATCH 2/4 x86/cpuid: Store the toolstacks choice of hypervisor max leaf

In reply to Andrew Cooper

This removes all dependencies on the legacy cpuids[] array from cpuid_hypervisor_leaves(). Swap a BUG() to an ASSERT_UNREACHABLE(), because in the unlikely case that we hit it, returning all zeros to the guest is fine.

---
CC: Jan Beulich <[email protected]>

This maintains the same toolstack-visible behaviour. The interface will be altered when doing the toolstack CPUID changes.

---
 xen/arch/x86/domctl.c       |  8 ++++++++
 xen/arch/x86/traps.c        | 19 +++++--------------
 xen/include/asm-x86/cpuid.h |  3 +++
 3 files changed, 16 insertions(+), 14 deletions(-)
xen/arch/x86/domctl.c +8 -0
index a5a56ee..038521a 100644
@@ -136,6 +136,14 @@ static int update_domain_cpuid_info(struct domain *d,
             p->basic.raw[ctl->input[0]] = leaf;
         break;
 
+    case 0x40000000:
+        p->hv_limit = ctl->eax;
+        break;
+
+    case 0x40000100:
+        p->hv2_limit = ctl->eax;
+        break;
+
     case 0x80000000 ... 0x80000000 + ARRAY_SIZE(p->extd.raw) - 1:
         p->extd.raw[ctl->input[0] - 0x80000000] = leaf;
         break;
xen/arch/x86/traps.c +5 -14
index 7bb42ac..4f29c3a 100644
@@ -906,26 +906,17 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf,
                              uint32_t subleaf, struct cpuid_leaf *res)
 {
     const struct domain *d = v->domain;
+    const struct cpuid_policy *p = d->arch.cpuid;
     uint32_t base = is_viridian_domain(d) ? 0x40000100 : 0x40000000;
     uint32_t idx  = leaf - base;
-    uint32_t limit, dummy;
+    unsigned int limit = is_viridian_domain(d) ? p->hv2_limit : p->hv_limit;
 
-    if ( idx > XEN_CPUID_MAX_NUM_LEAVES )
-        return; /* Avoid unnecessary pass through domain_cpuid() */
-
-    domain_cpuid(d, base, 0, &limit, &dummy, &dummy, &dummy);
     if ( limit == 0 )
         /* Default number of leaves */
         limit = XEN_CPUID_MAX_NUM_LEAVES;
     else
-    {
-        /* User-specified number of leaves */
-        limit &= 0xff;
-        if ( limit < 2 )
-            limit = 2;
-        else if ( limit > XEN_CPUID_MAX_NUM_LEAVES )
-            limit = XEN_CPUID_MAX_NUM_LEAVES;
-    }
+        /* Clamp toolstack value between 2 and MAX_NUM_LEAVES. */
+        limit = min(max(limit, 2u), XEN_CPUID_MAX_NUM_LEAVES + 0u);
 
     if ( idx > limit )
         return;
@@ -1015,7 +1006,7 @@ void cpuid_hypervisor_leaves(const struct vcpu *v, uint32_t leaf,
         break;
 
     default:
-        BUG();
+        ASSERT_UNREACHABLE();
     }
 }
 
xen/include/asm-x86/cpuid.h +3 -0
index 5b1448a..38e3975 100644
@@ -200,6 +200,9 @@ struct cpuid_policy
 #undef __DECL_BITFIELD
 #undef _DECL_BITFIELD
 #undef DECL_BITFIELD
+
+    /* Toolstack selected Hypervisor max_leaf (if non-zero). */
+    uint8_t hv_limit, hv2_limit;
 };
 
 /* Fill in a featureset bitmap from a CPUID policy. */
Signature · 7 lines
2.1.4


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

Re: [PATCH 2/4] x86/cpuid: Store the toolstacks choice of hypervisor max leaf

Quoted 4 lines
Quoted 1 line
Quoted 1 line · On 11.01.17 at 18:44, <[email protected]> wrote:

xen/arch/x86/domctl.c static int update_domain_cpuid_info(struct domain *d, · line 145

Quoted 10 lines
xen/arch/x86/domctl.c +7 -0
@@ -136,6 +136,14 @@ static int update_domain_cpuid_info(struct domain *d,
             p->basic.raw[ctl->input[0]] = leaf;
         break;
 
+    case 0x40000000:
+        p->hv_limit = ctl->eax;
+        break;
+
+    case 0x40000100:
+        p->hv2_limit = ctl->eax;
+        break;

Generally the patch is fine, but do we really need to store two limits here? Can't we rely on the Viridian flag to be set first, so we could use it here? And if indeed we can't right now, should it not be made so as a first step?

Jan

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

#5 lore raw

Re: [PATCH 2/4] x86/cpuid: Store the toolstacks choice of hypervisor max leaf

Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 11.01.17 at 18:44, <[email protected]> wrote:
xen/arch/x86/domctl.c +0 -0
@@ -136,6 +136,14 @@ static int update_domain_cpuid_info(struct domain *d,
             p->basic.raw[ctl->input[0]] = leaf;
         break;
 
Quoted 9 lines

xen/arch/x86/domctl.c static int update_domain_cpuid_info(struct domain *d, · line 145

Quoted 7 lines
xen/arch/x86/domctl.c +7 -0
+    case 0x40000000:
+        p->hv_limit = ctl->eax;
+        break;
+
+    case 0x40000100:
+        p->hv2_limit = ctl->eax;
+        break;

Generally the patch is fine, but do we really need to store two limits here?

Currently yes, because that is the ABI the toolstack expects.

Quoted 2 lines

Can't we rely on the Viridian flag to be set first, so we could use it here?

You objected to implicit assumptions like this before. I think it might be safe given the current ordering in libxl and xenguest, but...

Quoted 1 line

And if indeed we can't right now, should it not be made so as a first step?

.. I plan to rework this all differently when altering the toolstack half of CPUID.

Several Viridian and Xen fields work like plain feature words, and I want the toolstack to control those in the same manner as other CPUID information, even down to selecting which APIs/ABIs to make visible by choosing the entirety of leaf 0x40000x00. In particular, this gives us a debugging mechanism previously lacking to actually hide the Xen leaves entirely (We are the only hypervisor which doesn't have this option).

For now, I'd prefer to avoid making unnecessary toolstack changes.

~Andrew

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

Reviewed-by
#6 lore raw

Re: [PATCH 2/4] x86/cpuid: Store the toolstacks choice of hypervisor max leaf

Quoted 19 lines
Quoted 1 line
Quoted 1 line · On 13.01.17 at 12:45, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 11.01.17 at 18:44, <[email protected]> wrote:
xen/arch/x86/domctl.c +0 -0
@@ -136,6 +136,14 @@ static int update_domain_cpuid_info(struct domain *d,
             p->basic.raw[ctl->input[0]] = leaf;
         break;
 
Quoted 9 lines

xen/arch/x86/domctl.c static int update_domain_cpuid_info(struct domain *d, · line 145

Quoted 7 lines
xen/arch/x86/domctl.c +7 -0
+    case 0x40000000:
+        p->hv_limit = ctl->eax;
+        break;
+
+    case 0x40000100:
+        p->hv2_limit = ctl->eax;
+        break;

Generally the patch is fine, but do we really need to store two limits here?

Quoted 7 lines

Currently yes, because that is the ABI the toolstack expects.

Quoted 2 lines

Can't we rely on the Viridian flag to be set first, so we could use it here?

You objected to implicit assumptions like this before. I think it might be safe given the current ordering in libxl and xenguest, but...

Indeed I did, but there are things which clearly ought to be set very early, and others where the ordering can be any. It's those latter cases where I don't think we should expect certain tool stack behavior, whereas for the former I think we should not only require it, but even aim at enforcing it (by rejecting the operation if it is being done too late, because it would alter decisions taken in the past).

Quoted 5 lines
Quoted 1 line

And if indeed we can't right now, should it not be made so as a first step?

.. I plan to rework this all differently when altering the toolstack half of CPUID.

Quoted 8 lines

Several Viridian and Xen fields work like plain feature words, and I want the toolstack to control those in the same manner as other CPUID information, even down to selecting which APIs/ABIs to make visible by choosing the entirety of leaf 0x40000x00. In particular, this gives us a debugging mechanism previously lacking to actually hide the Xen leaves entirely (We are the only hypervisor which doesn't have this option).

For now, I'd prefer to avoid making unnecessary toolstack changes.

Fair enough.

Jan

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

#7 lore raw

Re: [PATCH 2/4] x86/cpuid: Store the toolstacks choice of hypervisor max leaf

Quoted 24 lines · Jan Beulich
Quoted 18 lines
Quoted 1 line
Quoted 1 line · On 13.01.17 at 12:45, <[email protected]> wrote:
Quoted 7 lines · Jan Beulich
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 11.01.17 at 18:44, <[email protected]> wrote:
xen/arch/x86/domctl.c +0 -0
@@ -136,6 +136,14 @@ static int update_domain_cpuid_info(struct domain *d,
             p->basic.raw[ctl->input[0]] = leaf;
         break;
 
Quoted 9 lines

xen/arch/x86/domctl.c static int update_domain_cpuid_info(struct domain *d, · line 145

Quoted 7 lines
xen/arch/x86/domctl.c +7 -0
+    case 0x40000000:
+        p->hv_limit = ctl->eax;
+        break;
+
+    case 0x40000100:
+        p->hv2_limit = ctl->eax;
+        break;

Generally the patch is fine, but do we really need to store two limits here?

Quoted 6 lines

Currently yes, because that is the ABI the toolstack expects.

Quoted 2 lines

Can't we rely on the Viridian flag to be set first, so we could use it here?

You objected to implicit assumptions like this before. I think it might be safe given the current ordering in libxl and xenguest, but...

Quoted 7 lines

Indeed I did, but there are things which clearly ought to be set very early, and others where the ordering can be any. It's those latter cases where I don't think we should expect certain tool stack behavior, whereas for the former I think we should not only require it, but even aim at enforcing it (by rejecting the operation if it is being done too late, because it would alter decisions taken in the past).

By the time I am done with the toolstack side, setting a CPUID policy will have to come before allocating any RAM, so we have a suitable maxphysaddr to audit against.

Quoted 12 lines
Quoted 12 lines
Quoted 2 lines

And if indeed we can't right now, should it not be made so as a first step?

.. I plan to rework this all differently when altering the toolstack half of CPUID.

Several Viridian and Xen fields work like plain feature words, and I want the toolstack to control those in the same manner as other CPUID information, even down to selecting which APIs/ABIs to make visible by choosing the entirety of leaf 0x40000x00. In particular, this gives us a debugging mechanism previously lacking to actually hide the Xen leaves entirely (We are the only hypervisor which doesn't have this option).

Quoted 4 lines
Quoted 1 line

For now, I'd prefer to avoid making unnecessary toolstack changes.

Fair enough.

Thanks.

~Andrew

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

#8 lore raw

PATCH 3/4 x86/cpuid: Effectively remove domain_cpuid()

In reply to Andrew Cooper

The only callers of domain_cpuid() are the legacy cpuid path via {pv,hvm}_cpuid(). Move domain_cpuid() to being private in cpuid.c, with an adjusted API to use struct cpuid_leaf rather than individual pointers.

The ITSC clobbering logic is dropped. It is no longer necessary now that the logic has moved into recalculate_cpuid_policy()

---
CC: Jan Beulich <[email protected]>

---
 xen/arch/x86/cpuid.c         | 24 ++++++++++++++++++++++--
 xen/arch/x86/domain.c        | 40 ----------------------------------------
 xen/include/asm-x86/domain.h |  8 --------
 3 files changed, 22 insertions(+), 50 deletions(-)
xen/arch/x86/cpuid.c +22 -2
index b685874..e173ff7 100644
@@ -350,6 +350,26 @@ int init_domain_cpuid_policy(struct domain *d)
     return 0;
 }
 
+static void domain_cpuid(const struct domain *d, uint32_t leaf,
+                         uint32_t subleaf, struct cpuid_leaf *res)
+{
+    unsigned int i;
+
+    for ( i = 0; i < MAX_CPUID_INPUT; i++ )
+    {
+        cpuid_input_t *cpuid = &d->arch.cpuids[i];
+
+        if ( (cpuid->input[0] == leaf) &&
+             ((cpuid->input[1] == XEN_CPUID_INPUT_UNUSED) ||
+              (cpuid->input[1] == subleaf)) )
+        {
+            *res = (struct cpuid_leaf){ cpuid->eax, cpuid->ebx,
+                                        cpuid->ecx, cpuid->edx };
+            return;
+        }
+    }
+}
+
 static void pv_cpuid(uint32_t leaf, uint32_t subleaf, struct cpuid_leaf *res)
 {
     struct vcpu *curr = current;
@@ -357,7 +377,7 @@ static void pv_cpuid(uint32_t leaf, uint32_t subleaf, struct cpuid_leaf *res)
     const struct cpuid_policy *p = currd->arch.cpuid;
 
     if ( !is_control_domain(currd) && !is_hardware_domain(currd) )
-        domain_cpuid(currd, leaf, subleaf, &res->a, &res->b, &res->c, &res->d);
+        domain_cpuid(currd, leaf, subleaf, res);
     else
         cpuid_count_leaf(leaf, subleaf, res);
 
@@ -620,7 +640,7 @@ static void hvm_cpuid(uint32_t leaf, uint32_t subleaf, struct cpuid_leaf *res)
     struct domain *d = v->domain;
     const struct cpuid_policy *p = d->arch.cpuid;
 
-    domain_cpuid(d, leaf, subleaf, &res->a, &res->b, &res->c, &res->d);
+    domain_cpuid(d, leaf, subleaf, res);
 
     switch ( leaf )
     {
xen/arch/x86/domain.c +0 -40
index 319cc8a..6fc1242 100644
@@ -2622,46 +2622,6 @@ void arch_dump_vcpu_info(struct vcpu *v)
     vpmu_dump(v);
 }
 
-void domain_cpuid(
-    const struct domain *d,
-    unsigned int  input,
-    unsigned int  sub_input,
-    unsigned int  *eax,
-    unsigned int  *ebx,
-    unsigned int  *ecx,
-    unsigned int  *edx)
-{
-    cpuid_input_t *cpuid;
-    int i;
-
-    for ( i = 0; i < MAX_CPUID_INPUT; i++ )
-    {
-        cpuid = &d->arch.cpuids[i];
-
-        if ( (cpuid->input[0] == input) &&
-             ((cpuid->input[1] == XEN_CPUID_INPUT_UNUSED) ||
-              (cpuid->input[1] == sub_input)) )
-        {
-            *eax = cpuid->eax;
-            *ebx = cpuid->ebx;
-            *ecx = cpuid->ecx;
-            *edx = cpuid->edx;
-
-            /*
-             * Do not advertise host's invariant TSC unless the TSC is
-             * emulated, or the domain cannot migrate to other hosts.
-             */
-            if ( (input == 0x80000007) && /* Advanced Power Management */
-                 !d->disable_migrate && !d->arch.vtsc )
-                *edx &= ~cpufeat_mask(X86_FEATURE_ITSC);
-
-            return;
-        }
-    }
-
-    *eax = *ebx = *ecx = *edx = 0;
-}
-
 void vcpu_kick(struct vcpu *v)
 {
     /*
xen/include/asm-x86/domain.h +0 -8
index 896e78d..9e3a07b 100644
@@ -617,14 +617,6 @@ unsigned long pv_guest_cr4_fixup(const struct vcpu *, unsigned long guest_cr4);
              X86_CR4_OSXSAVE | X86_CR4_SMEP |               \
              X86_CR4_FSGSBASE | X86_CR4_SMAP))
 
-void domain_cpuid(const struct domain *d,
-                  unsigned int  input,
-                  unsigned int  sub_input,
-                  unsigned int  *eax,
-                  unsigned int  *ebx,
-                  unsigned int  *ecx,
-                  unsigned int  *edx);
-
 #define domain_max_vcpus(d) (is_hvm_domain(d) ? HVM_MAX_VCPUS : MAX_VIRT_CPUS)
 
 static inline struct vcpu_guest_context *alloc_vcpu_guest_context(void)
Signature · 7 lines
2.1.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on v1 3/4
#9 lore raw

Re: [PATCH 3/4] x86/cpuid: Effectively remove domain_cpuid()

Quoted 9 lines
Quoted 1 line
Quoted 1 line · On 11.01.17 at 18:44, <[email protected]> wrote:

The only callers of domain_cpuid() are the legacy cpuid path via {pv,hvm}_cpuid(). Move domain_cpuid() to being private in cpuid.c, with an adjusted API to use struct cpuid_leaf rather than individual pointers.

The ITSC clobbering logic is dropped. It is no longer necessary now that the logic has moved into recalculate_cpuid_policy()

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

#10 lore raw

PATCH 4/4 x86/cpuid: Move the legacy cpuids array into struct cpuid_policy

In reply to Andrew Cooper

This hides the legacy details inside the cpuid subsystem, where they will eventually be dropped entirely.

No functional change.

---
CC: Jan Beulich <[email protected]>

---
 xen/arch/x86/cpuid.c         | 10 +++++++++-
 xen/arch/x86/domain.c        | 14 +-------------
 xen/arch/x86/domctl.c        |  4 ++--
 xen/include/asm-x86/cpuid.h  |  4 ++++
 xen/include/asm-x86/domain.h |  5 -----
 5 files changed, 16 insertions(+), 21 deletions(-)
xen/arch/x86/cpuid.c +9 -1
index e173ff7..20cb25b 100644
@@ -338,6 +338,8 @@ void recalculate_cpuid_policy(struct domain *d)
 
 int init_domain_cpuid_policy(struct domain *d)
 {
+    unsigned int i;
+
     d->arch.cpuid = xmalloc(struct cpuid_policy);
 
     if ( !d->arch.cpuid )
@@ -347,6 +349,12 @@ int init_domain_cpuid_policy(struct domain *d)
 
     recalculate_cpuid_policy(d);
 
+    for ( i = 0; i < MAX_CPUID_INPUT; i++ )
+    {
+        d->arch.cpuid->legacy[i].input[0] = XEN_CPUID_INPUT_UNUSED;
+        d->arch.cpuid->legacy[i].input[1] = XEN_CPUID_INPUT_UNUSED;
+    }
+
     return 0;
 }
 
@@ -357,7 +365,7 @@ static void domain_cpuid(const struct domain *d, uint32_t leaf,
 
     for ( i = 0; i < MAX_CPUID_INPUT; i++ )
     {
-        cpuid_input_t *cpuid = &d->arch.cpuids[i];
+        xen_domctl_cpuid_t *cpuid = &d->arch.cpuid->legacy[i];
 
         if ( (cpuid->input[0] == leaf) &&
              ((cpuid->input[1] == XEN_CPUID_INPUT_UNUSED) ||
xen/arch/x86/domain.c +1 -13
index 6fc1242..44ee92a 100644
@@ -503,7 +503,7 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
 int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                        struct xen_arch_domainconfig *config)
 {
-    int i, paging_initialised = 0;
+    int paging_initialised = 0;
     int rc = -ENOMEM;
 
     if ( config == NULL && !is_idle_domain(d) )
@@ -606,16 +606,6 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
         if ( (rc = init_domain_cpuid_policy(d)) )
             goto fail;
 
-        d->arch.cpuids = xmalloc_array(cpuid_input_t, MAX_CPUID_INPUT);
-        rc = -ENOMEM;
-        if ( d->arch.cpuids == NULL )
-            goto fail;
-        for ( i = 0; i < MAX_CPUID_INPUT; i++ )
-        {
-            d->arch.cpuids[i].input[0] = XEN_CPUID_INPUT_UNUSED;
-            d->arch.cpuids[i].input[1] = XEN_CPUID_INPUT_UNUSED;
-        }
-
         d->arch.x86_vendor = boot_cpu_data.x86_vendor;
         d->arch.x86        = boot_cpu_data.x86;
         d->arch.x86_model  = boot_cpu_data.x86_model;
@@ -678,7 +668,6 @@ int arch_domain_create(struct domain *d, unsigned int domcr_flags,
     iommu_domain_destroy(d);
     cleanup_domain_irq_mapping(d);
     free_xenheap_page(d->shared_info);
-    xfree(d->arch.cpuids);
     xfree(d->arch.cpuid);
     if ( paging_initialised )
         paging_final_teardown(d);
@@ -697,7 +686,6 @@ void arch_domain_destroy(struct domain *d)
         hvm_domain_destroy(d);
 
     xfree(d->arch.e820);
-    xfree(d->arch.cpuids);
     xfree(d->arch.cpuid);
 
     free_domain_pirqs(d);
xen/arch/x86/domctl.c +2 -2
index 038521a..772c5d2 100644
@@ -51,13 +51,13 @@ static int gdbsx_guest_mem_io(domid_t domid, struct xen_domctl_gdbsx_memio *iop)
 static int update_legacy_cpuid_array(struct domain *d,
                                      const xen_domctl_cpuid_t *ctl)
 {
-    cpuid_input_t *cpuid, *unused = NULL;
+    xen_domctl_cpuid_t *cpuid, *unused = NULL;
     unsigned int i;
 
     /* Try to insert ctl into d->arch.cpuids[] */
     for ( i = 0; i < MAX_CPUID_INPUT; i++ )
     {
-        cpuid = &d->arch.cpuids[i];
+        cpuid = &d->arch.cpuid->legacy[i];
 
         if ( cpuid->input[0] == XEN_CPUID_INPUT_UNUSED )
         {
xen/include/asm-x86/cpuid.h +4 -0
index 38e3975..b359b38 100644
@@ -203,6 +203,10 @@ struct cpuid_policy
 
     /* Toolstack selected Hypervisor max_leaf (if non-zero). */
     uint8_t hv_limit, hv2_limit;
+
+    /* Temporary: Legacy data array. */
+#define MAX_CPUID_INPUT 40
+    xen_domctl_cpuid_t legacy[MAX_CPUID_INPUT];
 };
 
 /* Fill in a featureset bitmap from a CPUID policy. */
xen/include/asm-x86/domain.h +0 -5
index 9e3a07b..eb6227d 100644
@@ -234,9 +234,6 @@ struct paging_vcpu {
     struct shadow_vcpu shadow;
 };
 
-#define MAX_CPUID_INPUT 40
-typedef xen_domctl_cpuid_t cpuid_input_t;
-
 #define MAX_NESTEDP2M 10
 
 #define MAX_ALTP2M      10 /* arbitrary */
@@ -360,8 +357,6 @@ struct arch_domain
      */
     uint8_t x87_fip_width;
 
-    cpuid_input_t *cpuids;
-
     /* CPUID Policy. */
     struct cpuid_policy *cpuid;
 
Signature · 7 lines
2.1.4


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

Re: [PATCH 4/4] x86/cpuid: Move the legacy cpuids array into struct cpuid_policy

Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 11.01.17 at 18:44, <[email protected]> wrote:

This hides the legacy details inside the cpuid subsystem, where they will eventually be dropped entirely.

No functional change.

xen/arch/x86/domain.c static bool emulation_flags_ok(const struct domain *d, uint32_t emflags) · line 506

Quoted 8 lines
xen/arch/x86/domain.c +1 -1
@@ -503,7 +503,7 @@ static bool emulation_flags_ok(const struct domain *d, uint32_t emflags)
 int arch_domain_create(struct domain *d, unsigned int domcr_flags,
                        struct xen_arch_domainconfig *config)
 {
-    int i, paging_initialised = 0;
+    int paging_initialised = 0;

But please consider taking the opportunity to change this to bool.

Jan

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