* [PATCH] libx86: Elide more empty CPUID leaves when serialising a policy
@ 2019-05-22 15:50 Andrew Cooper
2019-05-22 15:50 ` [Xen-devel] " Andrew Cooper
` (2 more replies)
0 siblings, 3 replies; 14+ messages in thread
From: Andrew Cooper @ 2019-05-22 15:50 UTC (permalink / raw)
To: Xen-devel; +Cc: Andrew Cooper, Wei Liu, Jan Beulich, Roger Pau Monné
x86_cpuid_copy_to_buffer() currently serialises the full content of the
various subleaf unions. While leaves 4, 0xb and 0xd don't have a concrete
max_subleaf field, they do have well defined upper bounds.
Diffing the results of `xen-cpuid -p` shows the resutling saving:
@@ -1,5 +1,5 @@
Xen reports there are maximum 114 leaves and 1 MSRs
-Raw policy: 93 leaves, 1 MSRs
+Raw policy: 38 leaves, 1 MSRs
CPUID:
leaf subleaf -> eax ebx ecx edx
00000000:ffffffff -> 00000016:756e6547:6c65746e:49656e69
@@ -32,7 +32,7 @@ Raw policy: 93 leaves, 1 MSRs
MSRs:
index -> value
000000ce -> 0000000080000000
-Host policy: 93 leaves, 1 MSRs
+Host policy: 33 leaves, 1 MSRs
CPUID:
leaf subleaf -> eax ebx ecx edx
00000000:ffffffff -> 0000000d:756e6547:6c65746e:49656e69
which is mostly due to no longer writing out 64 leaves for xstate when (on
this CoffeeLake system) 8 will do.
Extend the unit tests to cover empty and partially filled subleaf unions.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
---
tools/tests/cpu-policy/test-cpu-policy.c | 71 ++++++++++++++++++++++++++++++++
xen/lib/x86/cpuid.c | 24 ++++++++++-
2 files changed, 94 insertions(+), 1 deletion(-)
diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-policy/test-cpu-policy.c
index beced5e..fd96c0b 100644
--- a/tools/tests/cpu-policy/test-cpu-policy.c
+++ b/tools/tests/cpu-policy/test-cpu-policy.c
@@ -65,6 +65,77 @@ static void test_cpuid_serialise_success(void)
.name = "empty policy",
.nr_leaves = 4,
},
+
+ /* Leaf 4 serialisation stops at the first subleaf with type 0. */
+ {
+ .name = "empty leaf 4",
+ .p = {
+ .basic.max_leaf = 4,
+ },
+ .nr_leaves = 4 + 4,
+ },
+ {
+ .name = "partial leaf 4",
+ .p = {
+ .basic.max_leaf = 4,
+ .cache.subleaf[0].type = 1,
+ },
+ .nr_leaves = 4 + 4 + 1,
+ },
+
+ /* Leaf 7 serialisation stops at max_subleaf. */
+ {
+ .name = "empty leaf 7",
+ .p = {
+ .basic.max_leaf = 7,
+ },
+ .nr_leaves = 4 + 7,
+ },
+ {
+ .name = "partial leaf 7",
+ .p = {
+ .basic.max_leaf = 7,
+ .feat.max_subleaf = 1,
+ },
+ .nr_leaves = 4 + 7 + 1,
+ },
+
+ /* Leaf 0xb serialisation stops at the first subleaf with type 0. */
+ {
+ .name = "empty leaf 0xb",
+ .p = {
+ .basic.max_leaf = 0xb,
+ },
+ .nr_leaves = 4 + 0xb,
+ },
+ {
+ .name = "partial leaf 0xb",
+ .p = {
+ .basic.max_leaf = 0xb,
+ .topo.subleaf[0].type = 1,
+ },
+ .nr_leaves = 4 + 0xb + 1,
+ },
+
+ /*
+ * Leaf 0xd serialisation automatically has two leaves, and stops the
+ * highest bit set in {xcr0,xss}_{high,low}.
+ */
+ {
+ .name = "empty leaf 0xd",
+ .p = {
+ .basic.max_leaf = 0xd,
+ },
+ .nr_leaves = 4 + 0xd + 1,
+ },
+ {
+ .name = "partial 0xd",
+ .p = {
+ .basic.max_leaf = 0xd,
+ .xstate.xcr0_low = 7,
+ },
+ .nr_leaves = 4 + 0xd + 1 + 1,
+ },
};
printf("Testing CPUID serialise success:\n");
diff --git a/xen/lib/x86/cpuid.c b/xen/lib/x86/cpuid.c
index 23619c7..dcab1e7 100644
--- a/xen/lib/x86/cpuid.c
+++ b/xen/lib/x86/cpuid.c
@@ -242,7 +242,12 @@ int x86_cpuid_copy_to_buffer(const struct cpuid_policy *p,
{
case 0x4:
for ( subleaf = 0; subleaf < ARRAY_SIZE(p->cache.raw); ++subleaf )
+ {
COPY_LEAF(leaf, subleaf, &p->cache.raw[subleaf]);
+
+ if ( p->cache.subleaf[subleaf].type == 0 )
+ break;
+ }
break;
case 0x7:
@@ -254,13 +259,30 @@ int x86_cpuid_copy_to_buffer(const struct cpuid_policy *p,
case 0xb:
for ( subleaf = 0; subleaf < ARRAY_SIZE(p->topo.raw); ++subleaf )
+ {
COPY_LEAF(leaf, subleaf, &p->topo.raw[subleaf]);
+
+ if ( p->topo.subleaf[subleaf].type == 0 )
+ break;
+ }
break;
case 0xd:
- for ( subleaf = 0; subleaf < ARRAY_SIZE(p->xstate.raw); ++subleaf )
+ {
+ uint64_t xstates;
+
+ COPY_LEAF(leaf, 0, &p->xstate.raw[0]);
+ COPY_LEAF(leaf, 1, &p->xstate.raw[1]);
+
+ xstates = ((uint64_t)(p->xstate.xcr0_high | p->xstate.xss_high) << 32);
+ xstates |= (p->xstate.xcr0_low | p->xstate.xss_low);
+
+ for ( xstates >>= 2, subleaf = 2;
+ xstates && subleaf < ARRAY_SIZE(p->xstate.raw);
+ xstates >>= 1, ++subleaf )
COPY_LEAF(leaf, subleaf, &p->xstate.raw[subleaf]);
break;
+ }
default:
COPY_LEAF(leaf, XEN_CPUID_NO_SUBLEAF, &p->basic.raw[leaf]);
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [Xen-devel] [PATCH] libx86: Elide more empty CPUID leaves when serialising a policy
2019-05-22 15:50 [PATCH] libx86: Elide more empty CPUID leaves when serialising a policy Andrew Cooper
@ 2019-05-22 15:50 ` Andrew Cooper
2019-05-23 8:33 ` Jan Beulich
2019-05-23 10:27 ` [PATCH] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy Andrew Cooper
2 siblings, 0 replies; 14+ messages in thread
From: Andrew Cooper @ 2019-05-22 15:50 UTC (permalink / raw)
To: Xen-devel; +Cc: Andrew Cooper, Wei Liu, Jan Beulich, Roger Pau Monné
x86_cpuid_copy_to_buffer() currently serialises the full content of the
various subleaf unions. While leaves 4, 0xb and 0xd don't have a concrete
max_subleaf field, they do have well defined upper bounds.
Diffing the results of `xen-cpuid -p` shows the resutling saving:
@@ -1,5 +1,5 @@
Xen reports there are maximum 114 leaves and 1 MSRs
-Raw policy: 93 leaves, 1 MSRs
+Raw policy: 38 leaves, 1 MSRs
CPUID:
leaf subleaf -> eax ebx ecx edx
00000000:ffffffff -> 00000016:756e6547:6c65746e:49656e69
@@ -32,7 +32,7 @@ Raw policy: 93 leaves, 1 MSRs
MSRs:
index -> value
000000ce -> 0000000080000000
-Host policy: 93 leaves, 1 MSRs
+Host policy: 33 leaves, 1 MSRs
CPUID:
leaf subleaf -> eax ebx ecx edx
00000000:ffffffff -> 0000000d:756e6547:6c65746e:49656e69
which is mostly due to no longer writing out 64 leaves for xstate when (on
this CoffeeLake system) 8 will do.
Extend the unit tests to cover empty and partially filled subleaf unions.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
---
tools/tests/cpu-policy/test-cpu-policy.c | 71 ++++++++++++++++++++++++++++++++
xen/lib/x86/cpuid.c | 24 ++++++++++-
2 files changed, 94 insertions(+), 1 deletion(-)
diff --git a/tools/tests/cpu-policy/test-cpu-policy.c b/tools/tests/cpu-policy/test-cpu-policy.c
index beced5e..fd96c0b 100644
--- a/tools/tests/cpu-policy/test-cpu-policy.c
+++ b/tools/tests/cpu-policy/test-cpu-policy.c
@@ -65,6 +65,77 @@ static void test_cpuid_serialise_success(void)
.name = "empty policy",
.nr_leaves = 4,
},
+
+ /* Leaf 4 serialisation stops at the first subleaf with type 0. */
+ {
+ .name = "empty leaf 4",
+ .p = {
+ .basic.max_leaf = 4,
+ },
+ .nr_leaves = 4 + 4,
+ },
+ {
+ .name = "partial leaf 4",
+ .p = {
+ .basic.max_leaf = 4,
+ .cache.subleaf[0].type = 1,
+ },
+ .nr_leaves = 4 + 4 + 1,
+ },
+
+ /* Leaf 7 serialisation stops at max_subleaf. */
+ {
+ .name = "empty leaf 7",
+ .p = {
+ .basic.max_leaf = 7,
+ },
+ .nr_leaves = 4 + 7,
+ },
+ {
+ .name = "partial leaf 7",
+ .p = {
+ .basic.max_leaf = 7,
+ .feat.max_subleaf = 1,
+ },
+ .nr_leaves = 4 + 7 + 1,
+ },
+
+ /* Leaf 0xb serialisation stops at the first subleaf with type 0. */
+ {
+ .name = "empty leaf 0xb",
+ .p = {
+ .basic.max_leaf = 0xb,
+ },
+ .nr_leaves = 4 + 0xb,
+ },
+ {
+ .name = "partial leaf 0xb",
+ .p = {
+ .basic.max_leaf = 0xb,
+ .topo.subleaf[0].type = 1,
+ },
+ .nr_leaves = 4 + 0xb + 1,
+ },
+
+ /*
+ * Leaf 0xd serialisation automatically has two leaves, and stops the
+ * highest bit set in {xcr0,xss}_{high,low}.
+ */
+ {
+ .name = "empty leaf 0xd",
+ .p = {
+ .basic.max_leaf = 0xd,
+ },
+ .nr_leaves = 4 + 0xd + 1,
+ },
+ {
+ .name = "partial 0xd",
+ .p = {
+ .basic.max_leaf = 0xd,
+ .xstate.xcr0_low = 7,
+ },
+ .nr_leaves = 4 + 0xd + 1 + 1,
+ },
};
printf("Testing CPUID serialise success:\n");
diff --git a/xen/lib/x86/cpuid.c b/xen/lib/x86/cpuid.c
index 23619c7..dcab1e7 100644
--- a/xen/lib/x86/cpuid.c
+++ b/xen/lib/x86/cpuid.c
@@ -242,7 +242,12 @@ int x86_cpuid_copy_to_buffer(const struct cpuid_policy *p,
{
case 0x4:
for ( subleaf = 0; subleaf < ARRAY_SIZE(p->cache.raw); ++subleaf )
+ {
COPY_LEAF(leaf, subleaf, &p->cache.raw[subleaf]);
+
+ if ( p->cache.subleaf[subleaf].type == 0 )
+ break;
+ }
break;
case 0x7:
@@ -254,13 +259,30 @@ int x86_cpuid_copy_to_buffer(const struct cpuid_policy *p,
case 0xb:
for ( subleaf = 0; subleaf < ARRAY_SIZE(p->topo.raw); ++subleaf )
+ {
COPY_LEAF(leaf, subleaf, &p->topo.raw[subleaf]);
+
+ if ( p->topo.subleaf[subleaf].type == 0 )
+ break;
+ }
break;
case 0xd:
- for ( subleaf = 0; subleaf < ARRAY_SIZE(p->xstate.raw); ++subleaf )
+ {
+ uint64_t xstates;
+
+ COPY_LEAF(leaf, 0, &p->xstate.raw[0]);
+ COPY_LEAF(leaf, 1, &p->xstate.raw[1]);
+
+ xstates = ((uint64_t)(p->xstate.xcr0_high | p->xstate.xss_high) << 32);
+ xstates |= (p->xstate.xcr0_low | p->xstate.xss_low);
+
+ for ( xstates >>= 2, subleaf = 2;
+ xstates && subleaf < ARRAY_SIZE(p->xstate.raw);
+ xstates >>= 1, ++subleaf )
COPY_LEAF(leaf, subleaf, &p->xstate.raw[subleaf]);
break;
+ }
default:
COPY_LEAF(leaf, XEN_CPUID_NO_SUBLEAF, &p->basic.raw[leaf]);
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH] libx86: Elide more empty CPUID leaves when serialising a policy
2019-05-22 15:50 [PATCH] libx86: Elide more empty CPUID leaves when serialising a policy Andrew Cooper
2019-05-22 15:50 ` [Xen-devel] " Andrew Cooper
@ 2019-05-23 8:33 ` Jan Beulich
2019-05-23 8:33 ` [Xen-devel] " Jan Beulich
2019-05-23 10:38 ` Andrew Cooper
2019-05-23 10:27 ` [PATCH] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy Andrew Cooper
2 siblings, 2 replies; 14+ messages in thread
From: Jan Beulich @ 2019-05-23 8:33 UTC (permalink / raw)
To: Andrew Cooper; +Cc: xen-devel, Wei Liu, Roger Pau Monne
>>> On 22.05.19 at 17:50, <andrew.cooper3@citrix.com> wrote:
> x86_cpuid_copy_to_buffer() currently serialises the full content of the
> various subleaf unions. While leaves 4, 0xb and 0xd don't have a concrete
> max_subleaf field, they do have well defined upper bounds.
>
> Diffing the results of `xen-cpuid -p` shows the resutling saving:
>
> @@ -1,5 +1,5 @@
> Xen reports there are maximum 114 leaves and 1 MSRs
> -Raw policy: 93 leaves, 1 MSRs
> +Raw policy: 38 leaves, 1 MSRs
> CPUID:
> leaf subleaf -> eax ebx ecx edx
> 00000000:ffffffff -> 00000016:756e6547:6c65746e:49656e69
> @@ -32,7 +32,7 @@ Raw policy: 93 leaves, 1 MSRs
> MSRs:
> index -> value
> 000000ce -> 0000000080000000
> -Host policy: 93 leaves, 1 MSRs
> +Host policy: 33 leaves, 1 MSRs
> CPUID:
> leaf subleaf -> eax ebx ecx edx
> 00000000:ffffffff -> 0000000d:756e6547:6c65746e:49656e69
>
> which is mostly due to no longer writing out 64 leaves for xstate when (on
> this CoffeeLake system) 8 will do.
>
> Extend the unit tests to cover empty and partially filled subleaf unions.
>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
For the lib/x86/ part
Reviewed-by: Jan Beulich <jbeulich@suse.com>
For the test harness part
Acked-by: Jan Beulich <jbeulich@suse.com>
No idea how else I should represent that I didn't look overly closely
at the harness additions.
Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Xen-devel] [PATCH] libx86: Elide more empty CPUID leaves when serialising a policy
2019-05-23 8:33 ` Jan Beulich
@ 2019-05-23 8:33 ` Jan Beulich
2019-05-23 10:38 ` Andrew Cooper
1 sibling, 0 replies; 14+ messages in thread
From: Jan Beulich @ 2019-05-23 8:33 UTC (permalink / raw)
To: Andrew Cooper; +Cc: xen-devel, Wei Liu, Roger Pau Monne
>>> On 22.05.19 at 17:50, <andrew.cooper3@citrix.com> wrote:
> x86_cpuid_copy_to_buffer() currently serialises the full content of the
> various subleaf unions. While leaves 4, 0xb and 0xd don't have a concrete
> max_subleaf field, they do have well defined upper bounds.
>
> Diffing the results of `xen-cpuid -p` shows the resutling saving:
>
> @@ -1,5 +1,5 @@
> Xen reports there are maximum 114 leaves and 1 MSRs
> -Raw policy: 93 leaves, 1 MSRs
> +Raw policy: 38 leaves, 1 MSRs
> CPUID:
> leaf subleaf -> eax ebx ecx edx
> 00000000:ffffffff -> 00000016:756e6547:6c65746e:49656e69
> @@ -32,7 +32,7 @@ Raw policy: 93 leaves, 1 MSRs
> MSRs:
> index -> value
> 000000ce -> 0000000080000000
> -Host policy: 93 leaves, 1 MSRs
> +Host policy: 33 leaves, 1 MSRs
> CPUID:
> leaf subleaf -> eax ebx ecx edx
> 00000000:ffffffff -> 0000000d:756e6547:6c65746e:49656e69
>
> which is mostly due to no longer writing out 64 leaves for xstate when (on
> this CoffeeLake system) 8 will do.
>
> Extend the unit tests to cover empty and partially filled subleaf unions.
>
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
For the lib/x86/ part
Reviewed-by: Jan Beulich <jbeulich@suse.com>
For the test harness part
Acked-by: Jan Beulich <jbeulich@suse.com>
No idea how else I should represent that I didn't look overly closely
at the harness additions.
Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] libx86: Elide more empty CPUID leaves when serialising a policy
2019-05-23 8:33 ` Jan Beulich
2019-05-23 8:33 ` [Xen-devel] " Jan Beulich
@ 2019-05-23 10:38 ` Andrew Cooper
2019-05-23 10:38 ` [Xen-devel] " Andrew Cooper
1 sibling, 1 reply; 14+ messages in thread
From: Andrew Cooper @ 2019-05-23 10:38 UTC (permalink / raw)
To: Jan Beulich; +Cc: xen-devel, Wei Liu, Roger Pau Monne
On 23/05/2019 09:33, Jan Beulich wrote:
>>>> On 22.05.19 at 17:50, <andrew.cooper3@citrix.com> wrote:
>> x86_cpuid_copy_to_buffer() currently serialises the full content of the
>> various subleaf unions. While leaves 4, 0xb and 0xd don't have a concrete
>> max_subleaf field, they do have well defined upper bounds.
>>
>> Diffing the results of `xen-cpuid -p` shows the resutling saving:
>>
>> @@ -1,5 +1,5 @@
>> Xen reports there are maximum 114 leaves and 1 MSRs
>> -Raw policy: 93 leaves, 1 MSRs
>> +Raw policy: 38 leaves, 1 MSRs
>> CPUID:
>> leaf subleaf -> eax ebx ecx edx
>> 00000000:ffffffff -> 00000016:756e6547:6c65746e:49656e69
>> @@ -32,7 +32,7 @@ Raw policy: 93 leaves, 1 MSRs
>> MSRs:
>> index -> value
>> 000000ce -> 0000000080000000
>> -Host policy: 93 leaves, 1 MSRs
>> +Host policy: 33 leaves, 1 MSRs
>> CPUID:
>> leaf subleaf -> eax ebx ecx edx
>> 00000000:ffffffff -> 0000000d:756e6547:6c65746e:49656e69
>>
>> which is mostly due to no longer writing out 64 leaves for xstate when (on
>> this CoffeeLake system) 8 will do.
>>
>> Extend the unit tests to cover empty and partially filled subleaf unions.
>>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> For the lib/x86/ part
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
Thanks.
> For the test harness part
> Acked-by: Jan Beulich <jbeulich@suse.com>
> No idea how else I should represent that I didn't look overly closely
> at the harness additions.
Well - I can state that the additions to the test harness did find bugs.
Overall, I think the content of tools/tests/ is of relatively little
importance in the grand scheme of things. I certainly don't spend as
much time reviewing the test_x86_emulator changes as the changes to
x86_emulate() itself.
~Andrew
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Xen-devel] [PATCH] libx86: Elide more empty CPUID leaves when serialising a policy
2019-05-23 10:38 ` Andrew Cooper
@ 2019-05-23 10:38 ` Andrew Cooper
0 siblings, 0 replies; 14+ messages in thread
From: Andrew Cooper @ 2019-05-23 10:38 UTC (permalink / raw)
To: Jan Beulich; +Cc: xen-devel, Wei Liu, Roger Pau Monne
On 23/05/2019 09:33, Jan Beulich wrote:
>>>> On 22.05.19 at 17:50, <andrew.cooper3@citrix.com> wrote:
>> x86_cpuid_copy_to_buffer() currently serialises the full content of the
>> various subleaf unions. While leaves 4, 0xb and 0xd don't have a concrete
>> max_subleaf field, they do have well defined upper bounds.
>>
>> Diffing the results of `xen-cpuid -p` shows the resutling saving:
>>
>> @@ -1,5 +1,5 @@
>> Xen reports there are maximum 114 leaves and 1 MSRs
>> -Raw policy: 93 leaves, 1 MSRs
>> +Raw policy: 38 leaves, 1 MSRs
>> CPUID:
>> leaf subleaf -> eax ebx ecx edx
>> 00000000:ffffffff -> 00000016:756e6547:6c65746e:49656e69
>> @@ -32,7 +32,7 @@ Raw policy: 93 leaves, 1 MSRs
>> MSRs:
>> index -> value
>> 000000ce -> 0000000080000000
>> -Host policy: 93 leaves, 1 MSRs
>> +Host policy: 33 leaves, 1 MSRs
>> CPUID:
>> leaf subleaf -> eax ebx ecx edx
>> 00000000:ffffffff -> 0000000d:756e6547:6c65746e:49656e69
>>
>> which is mostly due to no longer writing out 64 leaves for xstate when (on
>> this CoffeeLake system) 8 will do.
>>
>> Extend the unit tests to cover empty and partially filled subleaf unions.
>>
>> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
> For the lib/x86/ part
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
Thanks.
> For the test harness part
> Acked-by: Jan Beulich <jbeulich@suse.com>
> No idea how else I should represent that I didn't look overly closely
> at the harness additions.
Well - I can state that the additions to the test harness did find bugs.
Overall, I think the content of tools/tests/ is of relatively little
importance in the grand scheme of things. I certainly don't spend as
much time reviewing the test_x86_emulator changes as the changes to
x86_emulate() itself.
~Andrew
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy
2019-05-22 15:50 [PATCH] libx86: Elide more empty CPUID leaves when serialising a policy Andrew Cooper
2019-05-22 15:50 ` [Xen-devel] " Andrew Cooper
2019-05-23 8:33 ` Jan Beulich
@ 2019-05-23 10:27 ` Andrew Cooper
2019-05-23 10:27 ` [Xen-devel] " Andrew Cooper
2019-05-23 11:52 ` Jan Beulich
2 siblings, 2 replies; 14+ messages in thread
From: Andrew Cooper @ 2019-05-23 10:27 UTC (permalink / raw)
To: Xen-devel; +Cc: Andrew Cooper, Wei Liu, Jan Beulich, Roger Pau Monné
This avoids opencoding the slightly-awkward logic. More uses of these
wrappers will be introduced shortly.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
I've decided to introduce this patch ahead of "[PATCH] libx86: Elide more
empty CPUID leaves when serialising a policy" (which simplifies the xstate
hunk a little) as I've found yet more cases where I need to use
cpuid_policy_xstates(), and opencoding them all seemed very silly.
---
xen/arch/x86/xstate.c | 8 ++------
xen/include/xen/lib/x86/cpuid.h | 12 ++++++++++++
xen/lib/x86/cpuid.c | 3 +--
3 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c
index 3da609a..04da569 100644
--- a/xen/arch/x86/xstate.c
+++ b/xen/arch/x86/xstate.c
@@ -660,9 +660,7 @@ static bool valid_xcr0(u64 xcr0)
int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_accum,
const struct xsave_hdr *hdr)
{
- const struct cpuid_policy *cp = d->arch.cpuid;
- uint64_t xcr0_max =
- ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
+ uint64_t xcr0_max = cpuid_policy_xcr0(d->arch.cpuid);
unsigned int i;
if ( (hdr->xstate_bv & ~xcr0_accum) ||
@@ -686,9 +684,7 @@ int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_accum,
int handle_xsetbv(u32 index, u64 new_bv)
{
struct vcpu *curr = current;
- const struct cpuid_policy *cp = curr->domain->arch.cpuid;
- uint64_t xcr0_max =
- ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
+ uint64_t xcr0_max = cpuid_policy_xcr0(curr->domain->arch.cpuid);
u64 mask;
if ( index != XCR_XFEATURE_ENABLED_MASK )
diff --git a/xen/include/xen/lib/x86/cpuid.h b/xen/include/xen/lib/x86/cpuid.h
index 252d2c9..ea4db5b 100644
--- a/xen/include/xen/lib/x86/cpuid.h
+++ b/xen/include/xen/lib/x86/cpuid.h
@@ -308,6 +308,18 @@ static inline void cpuid_featureset_to_policy(
p->feat._7a1 = fs[FEATURESET_7a1];
}
+static inline uint64_t cpuid_policy_xcr0(const struct cpuid_policy *p)
+{
+ return ((uint64_t)p->xstate.xcr0_high << 32) | p->xstate.xcr0_low;
+}
+
+static inline uint64_t cpuid_policy_xstates(const struct cpuid_policy *p)
+{
+ uint64_t val = p->xstate.xcr0_high | p->xstate.xss_high;
+
+ return (val << 32) | p->xstate.xcr0_low | p->xstate.xss_low;
+}
+
const uint32_t *x86_cpuid_lookup_deep_deps(uint32_t feature);
/**
diff --git a/xen/lib/x86/cpuid.c b/xen/lib/x86/cpuid.c
index 23619c7..74c5b18 100644
--- a/xen/lib/x86/cpuid.c
+++ b/xen/lib/x86/cpuid.c
@@ -144,8 +144,7 @@ void x86_cpuid_policy_fill_native(struct cpuid_policy *p)
cpuid_count_leaf(0xd, 0, &p->xstate.raw[0]);
cpuid_count_leaf(0xd, 1, &p->xstate.raw[1]);
- xstates = ((uint64_t)(p->xstate.xcr0_high | p->xstate.xss_high) << 32);
- xstates |= (p->xstate.xcr0_low | p->xstate.xss_low);
+ xstates = cpuid_policy_xstates(p);
for ( i = 2; i < min_t(unsigned int, 63,
ARRAY_SIZE(p->xstate.raw)); ++i )
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [Xen-devel] [PATCH] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy
2019-05-23 10:27 ` [PATCH] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy Andrew Cooper
@ 2019-05-23 10:27 ` Andrew Cooper
2019-05-23 11:52 ` Jan Beulich
1 sibling, 0 replies; 14+ messages in thread
From: Andrew Cooper @ 2019-05-23 10:27 UTC (permalink / raw)
To: Xen-devel; +Cc: Andrew Cooper, Wei Liu, Jan Beulich, Roger Pau Monné
This avoids opencoding the slightly-awkward logic. More uses of these
wrappers will be introduced shortly.
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Wei Liu <wei.liu2@citrix.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
I've decided to introduce this patch ahead of "[PATCH] libx86: Elide more
empty CPUID leaves when serialising a policy" (which simplifies the xstate
hunk a little) as I've found yet more cases where I need to use
cpuid_policy_xstates(), and opencoding them all seemed very silly.
---
xen/arch/x86/xstate.c | 8 ++------
xen/include/xen/lib/x86/cpuid.h | 12 ++++++++++++
xen/lib/x86/cpuid.c | 3 +--
3 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/xen/arch/x86/xstate.c b/xen/arch/x86/xstate.c
index 3da609a..04da569 100644
--- a/xen/arch/x86/xstate.c
+++ b/xen/arch/x86/xstate.c
@@ -660,9 +660,7 @@ static bool valid_xcr0(u64 xcr0)
int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_accum,
const struct xsave_hdr *hdr)
{
- const struct cpuid_policy *cp = d->arch.cpuid;
- uint64_t xcr0_max =
- ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
+ uint64_t xcr0_max = cpuid_policy_xcr0(d->arch.cpuid);
unsigned int i;
if ( (hdr->xstate_bv & ~xcr0_accum) ||
@@ -686,9 +684,7 @@ int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_accum,
int handle_xsetbv(u32 index, u64 new_bv)
{
struct vcpu *curr = current;
- const struct cpuid_policy *cp = curr->domain->arch.cpuid;
- uint64_t xcr0_max =
- ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
+ uint64_t xcr0_max = cpuid_policy_xcr0(curr->domain->arch.cpuid);
u64 mask;
if ( index != XCR_XFEATURE_ENABLED_MASK )
diff --git a/xen/include/xen/lib/x86/cpuid.h b/xen/include/xen/lib/x86/cpuid.h
index 252d2c9..ea4db5b 100644
--- a/xen/include/xen/lib/x86/cpuid.h
+++ b/xen/include/xen/lib/x86/cpuid.h
@@ -308,6 +308,18 @@ static inline void cpuid_featureset_to_policy(
p->feat._7a1 = fs[FEATURESET_7a1];
}
+static inline uint64_t cpuid_policy_xcr0(const struct cpuid_policy *p)
+{
+ return ((uint64_t)p->xstate.xcr0_high << 32) | p->xstate.xcr0_low;
+}
+
+static inline uint64_t cpuid_policy_xstates(const struct cpuid_policy *p)
+{
+ uint64_t val = p->xstate.xcr0_high | p->xstate.xss_high;
+
+ return (val << 32) | p->xstate.xcr0_low | p->xstate.xss_low;
+}
+
const uint32_t *x86_cpuid_lookup_deep_deps(uint32_t feature);
/**
diff --git a/xen/lib/x86/cpuid.c b/xen/lib/x86/cpuid.c
index 23619c7..74c5b18 100644
--- a/xen/lib/x86/cpuid.c
+++ b/xen/lib/x86/cpuid.c
@@ -144,8 +144,7 @@ void x86_cpuid_policy_fill_native(struct cpuid_policy *p)
cpuid_count_leaf(0xd, 0, &p->xstate.raw[0]);
cpuid_count_leaf(0xd, 1, &p->xstate.raw[1]);
- xstates = ((uint64_t)(p->xstate.xcr0_high | p->xstate.xss_high) << 32);
- xstates |= (p->xstate.xcr0_low | p->xstate.xss_low);
+ xstates = cpuid_policy_xstates(p);
for ( i = 2; i < min_t(unsigned int, 63,
ARRAY_SIZE(p->xstate.raw)); ++i )
--
2.1.4
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy
2019-05-23 10:27 ` [PATCH] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy Andrew Cooper
2019-05-23 10:27 ` [Xen-devel] " Andrew Cooper
@ 2019-05-23 11:52 ` Jan Beulich
2019-05-23 11:52 ` [Xen-devel] " Jan Beulich
2019-05-23 11:59 ` Andrew Cooper
1 sibling, 2 replies; 14+ messages in thread
From: Jan Beulich @ 2019-05-23 11:52 UTC (permalink / raw)
To: Andrew Cooper; +Cc: xen-devel, Wei Liu, Roger Pau Monne
>>> On 23.05.19 at 12:27, <andrew.cooper3@citrix.com> wrote:
> --- a/xen/arch/x86/xstate.c
> +++ b/xen/arch/x86/xstate.c
> @@ -660,9 +660,7 @@ static bool valid_xcr0(u64 xcr0)
> int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_accum,
> const struct xsave_hdr *hdr)
> {
> - const struct cpuid_policy *cp = d->arch.cpuid;
> - uint64_t xcr0_max =
> - ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
> + uint64_t xcr0_max = cpuid_policy_xcr0(d->arch.cpuid);
> unsigned int i;
>
> if ( (hdr->xstate_bv & ~xcr0_accum) ||
> @@ -686,9 +684,7 @@ int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_accum,
> int handle_xsetbv(u32 index, u64 new_bv)
> {
> struct vcpu *curr = current;
> - const struct cpuid_policy *cp = curr->domain->arch.cpuid;
> - uint64_t xcr0_max =
> - ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
> + uint64_t xcr0_max = cpuid_policy_xcr0(curr->domain->arch.cpuid);
In both cases the variables are more appropriately named than
the new helper. While I agree it's slightly more typing, did you
consider calling it cpuid_policy_xcr0_max()?
> --- a/xen/include/xen/lib/x86/cpuid.h
> +++ b/xen/include/xen/lib/x86/cpuid.h
> @@ -308,6 +308,18 @@ static inline void cpuid_featureset_to_policy(
> p->feat._7a1 = fs[FEATURESET_7a1];
> }
>
> +static inline uint64_t cpuid_policy_xcr0(const struct cpuid_policy *p)
> +{
> + return ((uint64_t)p->xstate.xcr0_high << 32) | p->xstate.xcr0_low;
> +}
> +
> +static inline uint64_t cpuid_policy_xstates(const struct cpuid_policy *p)
> +{
> + uint64_t val = p->xstate.xcr0_high | p->xstate.xss_high;
> +
> + return (val << 32) | p->xstate.xcr0_low | p->xstate.xss_low;
> +}
How about also having cpuid_policy_xss() (or cpuid_policy_xss_max())
and then simply making cpuid_policy_xstates() combine the two
results?
Anyway, as I can also live with things as they are, with or without
either of the suggested changes
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Xen-devel] [PATCH] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy
2019-05-23 11:52 ` Jan Beulich
@ 2019-05-23 11:52 ` Jan Beulich
2019-05-23 11:59 ` Andrew Cooper
1 sibling, 0 replies; 14+ messages in thread
From: Jan Beulich @ 2019-05-23 11:52 UTC (permalink / raw)
To: Andrew Cooper; +Cc: xen-devel, Wei Liu, Roger Pau Monne
>>> On 23.05.19 at 12:27, <andrew.cooper3@citrix.com> wrote:
> --- a/xen/arch/x86/xstate.c
> +++ b/xen/arch/x86/xstate.c
> @@ -660,9 +660,7 @@ static bool valid_xcr0(u64 xcr0)
> int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_accum,
> const struct xsave_hdr *hdr)
> {
> - const struct cpuid_policy *cp = d->arch.cpuid;
> - uint64_t xcr0_max =
> - ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
> + uint64_t xcr0_max = cpuid_policy_xcr0(d->arch.cpuid);
> unsigned int i;
>
> if ( (hdr->xstate_bv & ~xcr0_accum) ||
> @@ -686,9 +684,7 @@ int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_accum,
> int handle_xsetbv(u32 index, u64 new_bv)
> {
> struct vcpu *curr = current;
> - const struct cpuid_policy *cp = curr->domain->arch.cpuid;
> - uint64_t xcr0_max =
> - ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
> + uint64_t xcr0_max = cpuid_policy_xcr0(curr->domain->arch.cpuid);
In both cases the variables are more appropriately named than
the new helper. While I agree it's slightly more typing, did you
consider calling it cpuid_policy_xcr0_max()?
> --- a/xen/include/xen/lib/x86/cpuid.h
> +++ b/xen/include/xen/lib/x86/cpuid.h
> @@ -308,6 +308,18 @@ static inline void cpuid_featureset_to_policy(
> p->feat._7a1 = fs[FEATURESET_7a1];
> }
>
> +static inline uint64_t cpuid_policy_xcr0(const struct cpuid_policy *p)
> +{
> + return ((uint64_t)p->xstate.xcr0_high << 32) | p->xstate.xcr0_low;
> +}
> +
> +static inline uint64_t cpuid_policy_xstates(const struct cpuid_policy *p)
> +{
> + uint64_t val = p->xstate.xcr0_high | p->xstate.xss_high;
> +
> + return (val << 32) | p->xstate.xcr0_low | p->xstate.xss_low;
> +}
How about also having cpuid_policy_xss() (or cpuid_policy_xss_max())
and then simply making cpuid_policy_xstates() combine the two
results?
Anyway, as I can also live with things as they are, with or without
either of the suggested changes
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy
2019-05-23 11:52 ` Jan Beulich
2019-05-23 11:52 ` [Xen-devel] " Jan Beulich
@ 2019-05-23 11:59 ` Andrew Cooper
2019-05-23 11:59 ` [Xen-devel] " Andrew Cooper
2019-05-23 12:08 ` Jan Beulich
1 sibling, 2 replies; 14+ messages in thread
From: Andrew Cooper @ 2019-05-23 11:59 UTC (permalink / raw)
To: Jan Beulich; +Cc: xen-devel, Wei Liu, Roger Pau Monne
On 23/05/2019 12:52, Jan Beulich wrote:
>>>> On 23.05.19 at 12:27, <andrew.cooper3@citrix.com> wrote:
>> --- a/xen/arch/x86/xstate.c
>> +++ b/xen/arch/x86/xstate.c
>> @@ -660,9 +660,7 @@ static bool valid_xcr0(u64 xcr0)
>> int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_accum,
>> const struct xsave_hdr *hdr)
>> {
>> - const struct cpuid_policy *cp = d->arch.cpuid;
>> - uint64_t xcr0_max =
>> - ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
>> + uint64_t xcr0_max = cpuid_policy_xcr0(d->arch.cpuid);
>> unsigned int i;
>>
>> if ( (hdr->xstate_bv & ~xcr0_accum) ||
>> @@ -686,9 +684,7 @@ int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_accum,
>> int handle_xsetbv(u32 index, u64 new_bv)
>> {
>> struct vcpu *curr = current;
>> - const struct cpuid_policy *cp = curr->domain->arch.cpuid;
>> - uint64_t xcr0_max =
>> - ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
>> + uint64_t xcr0_max = cpuid_policy_xcr0(curr->domain->arch.cpuid);
> In both cases the variables are more appropriately named than
> the new helper. While I agree it's slightly more typing, did you
> consider calling it cpuid_policy_xcr0_max()?
Fine.
>
>> --- a/xen/include/xen/lib/x86/cpuid.h
>> +++ b/xen/include/xen/lib/x86/cpuid.h
>> @@ -308,6 +308,18 @@ static inline void cpuid_featureset_to_policy(
>> p->feat._7a1 = fs[FEATURESET_7a1];
>> }
>>
>> +static inline uint64_t cpuid_policy_xcr0(const struct cpuid_policy *p)
>> +{
>> + return ((uint64_t)p->xstate.xcr0_high << 32) | p->xstate.xcr0_low;
>> +}
>> +
>> +static inline uint64_t cpuid_policy_xstates(const struct cpuid_policy *p)
>> +{
>> + uint64_t val = p->xstate.xcr0_high | p->xstate.xss_high;
>> +
>> + return (val << 32) | p->xstate.xcr0_low | p->xstate.xss_low;
>> +}
> How about also having cpuid_policy_xss() (or cpuid_policy_xss_max())
> and then simply making cpuid_policy_xstates() combine the two
> results?
I started with that, but the resulting code was a little awkward to
read, and the asm generation was a little worse due to promoting
everything first.
I don't think we need cpuid_policy_xss{,_max}() until we actually
implement something for guests (most likely CET at this rate).
>
> Anyway, as I can also live with things as they are, with or without
> either of the suggested changes
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
Thanks (although I'm still happy to play around with naming).
~Andrew
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Xen-devel] [PATCH] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy
2019-05-23 11:59 ` Andrew Cooper
@ 2019-05-23 11:59 ` Andrew Cooper
2019-05-23 12:08 ` Jan Beulich
1 sibling, 0 replies; 14+ messages in thread
From: Andrew Cooper @ 2019-05-23 11:59 UTC (permalink / raw)
To: Jan Beulich; +Cc: xen-devel, Wei Liu, Roger Pau Monne
On 23/05/2019 12:52, Jan Beulich wrote:
>>>> On 23.05.19 at 12:27, <andrew.cooper3@citrix.com> wrote:
>> --- a/xen/arch/x86/xstate.c
>> +++ b/xen/arch/x86/xstate.c
>> @@ -660,9 +660,7 @@ static bool valid_xcr0(u64 xcr0)
>> int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_accum,
>> const struct xsave_hdr *hdr)
>> {
>> - const struct cpuid_policy *cp = d->arch.cpuid;
>> - uint64_t xcr0_max =
>> - ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
>> + uint64_t xcr0_max = cpuid_policy_xcr0(d->arch.cpuid);
>> unsigned int i;
>>
>> if ( (hdr->xstate_bv & ~xcr0_accum) ||
>> @@ -686,9 +684,7 @@ int validate_xstate(const struct domain *d, uint64_t xcr0, uint64_t xcr0_accum,
>> int handle_xsetbv(u32 index, u64 new_bv)
>> {
>> struct vcpu *curr = current;
>> - const struct cpuid_policy *cp = curr->domain->arch.cpuid;
>> - uint64_t xcr0_max =
>> - ((uint64_t)cp->xstate.xcr0_high << 32) | cp->xstate.xcr0_low;
>> + uint64_t xcr0_max = cpuid_policy_xcr0(curr->domain->arch.cpuid);
> In both cases the variables are more appropriately named than
> the new helper. While I agree it's slightly more typing, did you
> consider calling it cpuid_policy_xcr0_max()?
Fine.
>
>> --- a/xen/include/xen/lib/x86/cpuid.h
>> +++ b/xen/include/xen/lib/x86/cpuid.h
>> @@ -308,6 +308,18 @@ static inline void cpuid_featureset_to_policy(
>> p->feat._7a1 = fs[FEATURESET_7a1];
>> }
>>
>> +static inline uint64_t cpuid_policy_xcr0(const struct cpuid_policy *p)
>> +{
>> + return ((uint64_t)p->xstate.xcr0_high << 32) | p->xstate.xcr0_low;
>> +}
>> +
>> +static inline uint64_t cpuid_policy_xstates(const struct cpuid_policy *p)
>> +{
>> + uint64_t val = p->xstate.xcr0_high | p->xstate.xss_high;
>> +
>> + return (val << 32) | p->xstate.xcr0_low | p->xstate.xss_low;
>> +}
> How about also having cpuid_policy_xss() (or cpuid_policy_xss_max())
> and then simply making cpuid_policy_xstates() combine the two
> results?
I started with that, but the resulting code was a little awkward to
read, and the asm generation was a little worse due to promoting
everything first.
I don't think we need cpuid_policy_xss{,_max}() until we actually
implement something for guests (most likely CET at this rate).
>
> Anyway, as I can also live with things as they are, with or without
> either of the suggested changes
> Reviewed-by: Jan Beulich <jbeulich@suse.com>
Thanks (although I'm still happy to play around with naming).
~Andrew
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy
2019-05-23 11:59 ` Andrew Cooper
2019-05-23 11:59 ` [Xen-devel] " Andrew Cooper
@ 2019-05-23 12:08 ` Jan Beulich
2019-05-23 12:08 ` [Xen-devel] " Jan Beulich
1 sibling, 1 reply; 14+ messages in thread
From: Jan Beulich @ 2019-05-23 12:08 UTC (permalink / raw)
To: Andrew Cooper; +Cc: xen-devel, Wei Liu, Roger Pau Monne
>>> On 23.05.19 at 13:59, <andrew.cooper3@citrix.com> wrote:
> On 23/05/2019 12:52, Jan Beulich wrote:
>>>>> On 23.05.19 at 12:27, <andrew.cooper3@citrix.com> wrote:
>>> --- a/xen/include/xen/lib/x86/cpuid.h
>>> +++ b/xen/include/xen/lib/x86/cpuid.h
>>> @@ -308,6 +308,18 @@ static inline void cpuid_featureset_to_policy(
>>> p->feat._7a1 = fs[FEATURESET_7a1];
>>> }
>>>
>>> +static inline uint64_t cpuid_policy_xcr0(const struct cpuid_policy *p)
>>> +{
>>> + return ((uint64_t)p->xstate.xcr0_high << 32) | p->xstate.xcr0_low;
>>> +}
>>> +
>>> +static inline uint64_t cpuid_policy_xstates(const struct cpuid_policy *p)
>>> +{
>>> + uint64_t val = p->xstate.xcr0_high | p->xstate.xss_high;
>>> +
>>> + return (val << 32) | p->xstate.xcr0_low | p->xstate.xss_low;
>>> +}
>> How about also having cpuid_policy_xss() (or cpuid_policy_xss_max())
>> and then simply making cpuid_policy_xstates() combine the two
>> results?
>
> I started with that, but the resulting code was a little awkward to
> read, and the asm generation was a little worse due to promoting
> everything first.
>
> I don't think we need cpuid_policy_xss{,_max}() until we actually
> implement something for guests (most likely CET at this rate).
Well, let's stick to what you have then.
Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [Xen-devel] [PATCH] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy
2019-05-23 12:08 ` Jan Beulich
@ 2019-05-23 12:08 ` Jan Beulich
0 siblings, 0 replies; 14+ messages in thread
From: Jan Beulich @ 2019-05-23 12:08 UTC (permalink / raw)
To: Andrew Cooper; +Cc: xen-devel, Wei Liu, Roger Pau Monne
>>> On 23.05.19 at 13:59, <andrew.cooper3@citrix.com> wrote:
> On 23/05/2019 12:52, Jan Beulich wrote:
>>>>> On 23.05.19 at 12:27, <andrew.cooper3@citrix.com> wrote:
>>> --- a/xen/include/xen/lib/x86/cpuid.h
>>> +++ b/xen/include/xen/lib/x86/cpuid.h
>>> @@ -308,6 +308,18 @@ static inline void cpuid_featureset_to_policy(
>>> p->feat._7a1 = fs[FEATURESET_7a1];
>>> }
>>>
>>> +static inline uint64_t cpuid_policy_xcr0(const struct cpuid_policy *p)
>>> +{
>>> + return ((uint64_t)p->xstate.xcr0_high << 32) | p->xstate.xcr0_low;
>>> +}
>>> +
>>> +static inline uint64_t cpuid_policy_xstates(const struct cpuid_policy *p)
>>> +{
>>> + uint64_t val = p->xstate.xcr0_high | p->xstate.xss_high;
>>> +
>>> + return (val << 32) | p->xstate.xcr0_low | p->xstate.xss_low;
>>> +}
>> How about also having cpuid_policy_xss() (or cpuid_policy_xss_max())
>> and then simply making cpuid_policy_xstates() combine the two
>> results?
>
> I started with that, but the resulting code was a little awkward to
> read, and the asm generation was a little worse due to promoting
> everything first.
>
> I don't think we need cpuid_policy_xss{,_max}() until we actually
> implement something for guests (most likely CET at this rate).
Well, let's stick to what you have then.
Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel
^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2019-05-23 12:08 UTC | newest]
Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-22 15:50 [PATCH] libx86: Elide more empty CPUID leaves when serialising a policy Andrew Cooper
2019-05-22 15:50 ` [Xen-devel] " Andrew Cooper
2019-05-23 8:33 ` Jan Beulich
2019-05-23 8:33 ` [Xen-devel] " Jan Beulich
2019-05-23 10:38 ` Andrew Cooper
2019-05-23 10:38 ` [Xen-devel] " Andrew Cooper
2019-05-23 10:27 ` [PATCH] libx86: Introduce wrappers for extracting XCR0/XSS from a cpuid policy Andrew Cooper
2019-05-23 10:27 ` [Xen-devel] " Andrew Cooper
2019-05-23 11:52 ` Jan Beulich
2019-05-23 11:52 ` [Xen-devel] " Jan Beulich
2019-05-23 11:59 ` Andrew Cooper
2019-05-23 11:59 ` [Xen-devel] " Andrew Cooper
2019-05-23 12:08 ` Jan Beulich
2019-05-23 12:08 ` [Xen-devel] " Jan Beulich
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).