Skip to contentSkip to conversation

i386: Fix signedness of hyperv_spinlock_attempts

PATCH Applied Eduardo Habkost 4 participants 11 messages Jun 15, 2019 – Jun 18, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 i386: Fix signedness of hyperv_spinlock_attempts

The current default value for hv-spinlocks is 0xFFFFFFFF (meaning "never retry"). However, the value is stored as a signed integer, making the getter of the hv-spinlocks QOM property return -1 instead of 0xFFFFFFFF.

Fix this by changing the type of X86CPU::hyperv_spinlock_attempts to uint32_t. This has no visible effect to guest operating systems, affecting just the behavior of the QOM getter.

---
 target/i386/cpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/cpu.h +1 -1
index 0732e059ec..8158d0de73 100644
@@ -1372,7 +1372,7 @@ struct X86CPU {
 
     bool hyperv_vapic;
     bool hyperv_relaxed_timing;
-    int hyperv_spinlock_attempts;
+    uint32_t hyperv_spinlock_attempts;
     char *hyperv_vendor_id;
     bool hyperv_time;
     bool hyperv_crash;
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
Reviewed-by on v1 1/1
#1 lore raw
Quoted 19 lines · Eduardo Habkost

The current default value for hv-spinlocks is 0xFFFFFFFF (meaning "never retry"). However, the value is stored as a signed integer, making the getter of the hv-spinlocks QOM property return -1 instead of 0xFFFFFFFF.

Fix this by changing the type of X86CPU::hyperv_spinlock_attempts to uint32_t. This has no visible effect to guest operating systems, affecting just the behavior of the QOM getter.

---
 target/i386/cpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/cpu.h +0 -0
index 0732e059ec..8158d0de73 100644

target/i386/cpu.h struct X86CPU { · line 1378

Quoted 8 lines
target/i386/cpu.h +1 -1
@@ -1372,7 +1372,7 @@ struct X86CPU {
 
     bool hyperv_vapic;
     bool hyperv_relaxed_timing;
-    int hyperv_spinlock_attempts;
+    uint32_t hyperv_spinlock_attempts;
     char *hyperv_vendor_id;
     bool hyperv_time;
     bool hyperv_crash;
Signature · 1 line
Vitaly
Reviewed-by on v1 1/1
#2 lore raw
In reply to Eduardo Habkost
Quoted 5 lines · Eduardo Habkost

The current default value for hv-spinlocks is 0xFFFFFFFF (meaning "never retry"). However, the value is stored as a signed integer, making the getter of the hv-spinlocks QOM property return -1 instead of 0xFFFFFFFF.

Quoted 8 lines

Fix this by changing the type of X86CPU::hyperv_spinlock_attempts to uint32_t. This has no visible effect to guest operating systems, affecting just the behavior of the QOM getter.

---
 target/i386/cpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

That said, it's tempting to just nuke qdev_prop_spinlocks and make hv-spinlocks a regular DEFINE_PROP_UINT32...

Quoted 17 lines
target/i386/cpu.h +1 -1
index 0732e059ec..8158d0de73 100644
@@ -1372,7 +1372,7 @@ struct X86CPU {
 
     bool hyperv_vapic;
     bool hyperv_relaxed_timing;
-    int hyperv_spinlock_attempts;
+    uint32_t hyperv_spinlock_attempts;
     char *hyperv_vendor_id;
     bool hyperv_time;
     bool hyperv_crash;
Signature · 1 line
2.18.0.rc1.1.g3f1ff2140
#3 lore raw
Quoted 15 lines · Roman Kagan
Quoted 5 lines · Eduardo Habkost

The current default value for hv-spinlocks is 0xFFFFFFFF (meaning "never retry"). However, the value is stored as a signed integer, making the getter of the hv-spinlocks QOM property return -1 instead of 0xFFFFFFFF.

Quoted 8 lines

Fix this by changing the type of X86CPU::hyperv_spinlock_attempts to uint32_t. This has no visible effect to guest operating systems, affecting just the behavior of the QOM getter.

---
 target/i386/cpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 4 lines

That said, it's tempting to just nuke qdev_prop_spinlocks and make hv-spinlocks a regular DEFINE_PROP_UINT32...

Agreed. The only difference is that we would validate the property at realize time instead of object_property_set().

Signature · 1 line
Eduardo
#4 lore raw
Quoted 16 lines · Eduardo Habkost
Quoted 15 lines · Roman Kagan
Quoted 13 lines · Eduardo Habkost

The current default value for hv-spinlocks is 0xFFFFFFFF (meaning "never retry"). However, the value is stored as a signed integer, making the getter of the hv-spinlocks QOM property return -1 instead of 0xFFFFFFFF.

Fix this by changing the type of X86CPU::hyperv_spinlock_attempts to uint32_t. This has no visible effect to guest operating systems, affecting just the behavior of the QOM getter.

---
 target/i386/cpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 7 lines
Quoted 4 lines

That said, it's tempting to just nuke qdev_prop_spinlocks and make hv-spinlocks a regular DEFINE_PROP_UINT32...

Agreed. The only difference is that we would validate the property at realize time instead of object_property_set().

Right. But currently it's validated to be no less than 0xfff and no bigger than 0xffffffff. The latter check would become unnecessary, and I'm unable to find any reason to do the former (neither spec references nor the log messages of the commits that introduced it).

Roman.

#5 lore raw
Quoted 22 lines · Roman Kagan
Quoted 21 lines · Eduardo Habkost
Quoted 19 lines · Roman Kagan
Quoted 5 lines · Eduardo Habkost

The current default value for hv-spinlocks is 0xFFFFFFFF (meaning "never retry"). However, the value is stored as a signed integer, making the getter of the hv-spinlocks QOM property return -1 instead of 0xFFFFFFFF.

Quoted 8 lines

Fix this by changing the type of X86CPU::hyperv_spinlock_attempts to uint32_t. This has no visible effect to guest operating systems, affecting just the behavior of the QOM getter.

---
 target/i386/cpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

That said, it's tempting to just nuke qdev_prop_spinlocks and make hv-spinlocks a regular DEFINE_PROP_UINT32...

Quoted 7 lines
Quoted 2 lines

Agreed. The only difference is that we would validate the property at realize time instead of object_property_set().

Right. But currently it's validated to be no less than 0xfff and no bigger than 0xffffffff. The latter check would become unnecessary, and I'm unable to find any reason to do the former (neither spec references nor the log messages of the commits that introduced it).

The 0xFFF lower limit was originally introduced by commit 28f52cc04d34 ("hyper-v: introduce Hyper-V support infrastructure").

Vadim, do you know where the 0xFFF limit comes from?

Signature · 1 line
Eduardo
#6 lore raw
Quoted 38 lines · Eduardo Habkost
Quoted 29 lines · Roman Kagan
Quoted 19 lines · Eduardo Habkost
Quoted 18 lines · Roman Kagan
Quoted 15 lines · Eduardo Habkost

The current default value for hv-spinlocks is 0xFFFFFFFF (meaning
"never retry"). However, the value is stored as a signed integer, making the getter of the hv-spinlocks QOM property return -1 instead of 0xFFFFFFFF.

Fix this by changing the type of X86CPU::hyperv_spinlock_attempts
to uint32_t. This has no visible effect to guest operating systems, affecting just the behavior of the QOM getter.

---
 target/i386/cpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 8 lines
Quoted 5 lines

That said, it's tempting to just nuke qdev_prop_spinlocks and make
hv-spinlocks a regular DEFINE_PROP_UINT32...

Agreed. The only difference is that we would validate the property at realize time instead of object_property_set().

Quoted 7 lines

Right. But currently it's validated to be no less than 0xfff and no
bigger than 0xffffffff. The latter check would become unnecessary, and
I'm unable to find any reason to do the former (neither spec references
nor the log messages of the commits that introduced it).

Quoted 4 lines

The 0xFFF lower limit was originally introduced by commit 28f52cc04d34 ("hyper-v: introduce Hyper-V support infrastructure").

Vadim, do you know where the 0xFFF limit comes from?

I simply took this value from Windows Server 2008 R2 that I used as a reference while working on Hyper-V support for KVM. I also remember some paper (probably published by AMD ???) mentioned that 0x2fff seemed to have the best balance for PLE logic.

Best,
Vadim.

#7 lore raw
Quoted 42 lines · Vadim Rozenfeld
Quoted 41 lines · Eduardo Habkost
Quoted 29 lines · Roman Kagan
Quoted 19 lines · Eduardo Habkost
Quoted 18 lines · Roman Kagan
Quoted 15 lines · Eduardo Habkost

The current default value for hv-spinlocks is 0xFFFFFFFF (meaning
"never retry"). However, the value is stored as a signed integer, making the getter of the hv-spinlocks QOM property return -1 instead of 0xFFFFFFFF.

Fix this by changing the type of X86CPU::hyperv_spinlock_attempts
to uint32_t. This has no visible effect to guest operating systems, affecting just the behavior of the QOM getter.

---
 target/i386/cpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 8 lines
Quoted 5 lines

That said, it's tempting to just nuke qdev_prop_spinlocks and make
hv-spinlocks a regular DEFINE_PROP_UINT32...

Agreed. The only difference is that we would validate the property at realize time instead of object_property_set().

Quoted 7 lines

Right. But currently it's validated to be no less than 0xfff and no
bigger than 0xffffffff. The latter check would become unnecessary, and
I'm unable to find any reason to do the former (neither spec references
nor the log messages of the commits that introduced it).

The 0xFFF lower limit was originally introduced by commit 28f52cc04d34 ("hyper-v: introduce Hyper-V support infrastructure").

Quoted 6 lines
Quoted 1 line

Vadim, do you know where the 0xFFF limit comes from?

I simply took this value from Windows Server 2008 R2 that I used as a reference while working on Hyper-V support for KVM. I also remember some paper (probably published by AMD ???) mentioned that 0x2fff seemed to have the best balance for PLE logic.

The question is whether the user should be disallowed to set it below 0xfff?
I don't see this mandated by the spec, so I'd rather remove the lower limit and convert the property to a regular DEFINE_PROP_UINT32.

Roman.

#8 lore raw
Quoted 50 lines · Roman Kagan
Quoted 42 lines · Vadim Rozenfeld
Quoted 41 lines · Eduardo Habkost
Quoted 29 lines · Roman Kagan
Quoted 19 lines · Eduardo Habkost
Quoted 18 lines · Roman Kagan
Quoted 15 lines · Eduardo Habkost

The current default value for hv-spinlocks is 0xFFFFFFFF (meaning
"never retry"). However, the value is stored as a signed integer, making the getter of the hv-spinlocks QOM property return -1 instead of 0xFFFFFFFF.

Fix this by changing the type of X86CPU::hyperv_spinlock_attempts
to uint32_t. This has no visible effect to guest operating systems, affecting just the behavior of the QOM getter.

---
 target/i386/cpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 8 lines
Quoted 5 lines

That said, it's tempting to just nuke qdev_prop_spinlocks and make
hv-spinlocks a regular DEFINE_PROP_UINT32...

Agreed. The only difference is that we would validate the property at realize time instead of object_property_set().

Quoted 7 lines

Right. But currently it's validated to be no less than 0xfff and no
bigger than 0xffffffff. The latter check would become unnecessary, and
I'm unable to find any reason to do the former (neither spec references
nor the log messages of the commits that introduced it).

The 0xFFF lower limit was originally introduced by commit 28f52cc04d34 ("hyper-v: introduce Hyper-V support infrastructure").

Quoted 6 lines
Quoted 1 line

Vadim, do you know where the 0xFFF limit comes from?

I simply took this value from Windows Server 2008 R2 that I used as a reference while working on Hyper-V support for KVM. I also remember some paper (probably published by AMD ???) mentioned that 0x2fff seemed to have the best balance for PLE logic.

Quoted 4 lines

The question is whether the user should be disallowed to set it below 0xfff?
I don't see this mandated by the spec, so I'd rather remove the lower limit and convert the property to a regular DEFINE_PROP_UINT32.

I've just posted a patch to that end, feel free to (dis)approve.

Roman.

#9 lore raw
In reply to Roman Kagan
Quoted 58 lines · Roman Kagan
Quoted 49 lines · Vadim Rozenfeld
Quoted 48 lines · Eduardo Habkost
Quoted 33 lines · Roman Kagan
Quoted 23 lines · Eduardo Habkost
Quoted 22 lines · Roman Kagan
Quoted 13 lines · Eduardo Habkost

The current default value for hv-spinlocks is 0xFFFFFFFF (meaning
"never retry"). However, the value is stored as a signed integer, making the getter of the hv-spinlocks QOM property
return -1 instead of 0xFFFFFFFF.

Fix this by changing the type of X86CPU::hyperv_spinlock_attempts
to uint32_t. This has no visible effect to guest operating
systems, affecting just the behavior of the QOM getter.

Quoted 4 lines
---
 target/i386/cpu.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 7 lines
Quoted 4 lines

That said, it's tempting to just nuke qdev_prop_spinlocks and
make
hv-spinlocks a regular DEFINE_PROP_UINT32...

Agreed. The only difference is that we would validate the property at realize time instead of object_property_set().

Quoted 9 lines

Right. But currently it's validated to be no less than 0xfff and
no
bigger than 0xffffffff. The latter check would become unnecessary,
and
I'm unable to find any reason to do the former (neither spec references
nor the log messages of the commits that introduced it).

The 0xFFF lower limit was originally introduced by commit 28f52cc04d34 ("hyper-v: introduce Hyper-V support infrastructure").

Quoted 7 lines
Quoted 1 line

Vadim, do you know where the 0xFFF limit comes from?

I simply took this value from Windows Server 2008 R2 that I used as a reference while working on Hyper-V support for KVM. I also remember some paper (probably published by AMD ???) mentioned
that 0x2fff seemed to have the best balance for PLE logic.

Quoted 5 lines

The question is whether the user should be disallowed to set it below 0xfff?
I don't see this mandated by the spec, so I'd rather remove the lower limit and convert the property to a regular DEFINE_PROP_UINT32.

Honestly, I don't have any strong opinions on this matter. Having some lower boundary limit seemed quite logical to me. However, if a user wants to experiment and see how the smaller number of spinlock acquire attempts before calling HvNotifyLongSpinWait will affect the overall system performance, then why not?

Vadim.

Quoted 1 line

Roman.

author Applied
#10 lore raw
In reply to Eduardo Habkost
Quoted 10 lines · Eduardo Habkost

The current default value for hv-spinlocks is 0xFFFFFFFF (meaning "never retry"). However, the value is stored as a signed integer, making the getter of the hv-spinlocks QOM property return -1 instead of 0xFFFFFFFF.

Fix this by changing the type of X86CPU::hyperv_spinlock_attempts to uint32_t. This has no visible effect to guest operating systems, affecting just the behavior of the QOM getter.

Queued on x86-next.

Signature · 1 line
Eduardo