Skip to contentSkip to conversation

x86/cpu: Use max host physical address if -cpu max option is applied

PATCH In review Yang Weijiang 3 participants 9 messages Jan 13, 2021 – Jan 25, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/cpu: Use max host physical address if -cpu max option is applied

QEMU option -cpu max(max_features) means "Enables all features supported by the accelerator in the current host", this looks true for all the features except guest max physical address width, so add this patch to enable it.

---
 target/i386/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/cpu.c +1 -1
index 35459a38bb..b5943406f7 100644
@@ -6673,7 +6673,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
                 warned = true;
             }
 
-            if (cpu->host_phys_bits) {
+            if (cpu->host_phys_bits || cpu->max_features) {
                 /* The user asked for us to use the host physical bits */
                 cpu->phys_bits = host_phys_bits;
                 if (cpu->host_phys_bits_limit &&
Signature · 1 line
2.17.2
#1 lore raw
Quoted 15 lines · Yang Weijiang

QEMU option -cpu max(max_features) means "Enables all features supported by the accelerator in the current host", this looks true for all the features except guest max physical address width, so add this patch to enable it.

---
  target/i386/cpu.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/cpu.c +0 -0
index 35459a38bb..b5943406f7 100644

target/i386/cpu.c static void x86_cpu_realizefn(DeviceState *dev, Error **errp) · line 6679

Quoted 8 lines
target/i386/cpu.c +1 -1
@@ -6673,7 +6673,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
                  warned = true;
              }
 
-            if (cpu->host_phys_bits) {
+            if (cpu->host_phys_bits || cpu->max_features) {
                  /* The user asked for us to use the host physical bits */
                  cpu->phys_bits = host_phys_bits;
                  if (cpu->host_phys_bits_limit &&

Can you check if this works?

target/i386/cpu.c +0 -0
index 35459a38bb..72a79e6019 100644
@@ -4319,6 +4319,7 @@ static void max_x86_cpu_initfn(Object *obj)
         if (lmce_supported()) {
             object_property_set_bool(OBJECT(cpu), "lmce", true, 
&error_abort);
         }
+        object_property_set_bool(OBJECT(cpu), "host-phys-bits", true, &error_abort);
     } else {
         object_property_set_str(OBJECT(cpu), "vendor", CPUID_VENDOR_AMD,
                                 &error_abort);

It should allow people to use -cpu max,host-phys-bits=false.

Thanks,

Paolo

#2 lore raw
Quoted 10 lines · Paolo Bonzini
Quoted 9 lines · Yang Weijiang

QEMU option -cpu max(max_features) means "Enables all features supported by the accelerator in the current host", this looks true for all the features except guest max physical address width, so add this patch to enable it.

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

target/i386/cpu.c static void x86_cpu_realizefn(DeviceState *dev, Error **errp) · line 6679

Quoted 13 lines
target/i386/cpu.c +1 -1
index 35459a38bb..b5943406f7 100644
@@ -6673,7 +6673,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
                  warned = true;
              }
-            if (cpu->host_phys_bits) {
+            if (cpu->host_phys_bits || cpu->max_features) {
                  /* The user asked for us to use the host physical bits */
                  cpu->phys_bits = host_phys_bits;
                  if (cpu->host_phys_bits_limit &&
 

Can you check if this works?

Hi, Paolo,
Yes, below change works for kvm-unit-test/access. Would you add the patch?

Thanks!

Quoted 21 lines
target/i386/cpu.c +1 -0
index 35459a38bb..72a79e6019 100644
@@ -4319,6 +4319,7 @@ static void max_x86_cpu_initfn(Object *obj)
         if (lmce_supported()) {
             object_property_set_bool(OBJECT(cpu), "lmce", true,
 &error_abort);
         }
+        object_property_set_bool(OBJECT(cpu), "host-phys-bits", true,
 &error_abort);
     } else {

object_property_set_str(OBJECT(cpu), "vendor", CPUID_VENDOR_AMD,
&error_abort);

It should allow people to use -cpu max,host-phys-bits=false.

Thanks,

Paolo

#3 lore raw

Yes, thanks.

Paolo

Il mer 13 gen 2021, 15:52 Yang Weijiang <[email protected]> ha scritto:

Quoted 61 lines · Paolo Bonzini
Quoted 2 lines · Yang Weijiang
Quoted 1 line

QEMU option -cpu max(max_features) means "Enables all features

supported by

Quoted 1 line
Quoted 1 line

the accelerator in the current host", this looks true for all the

features

Quoted 1 line
Quoted 1 line

except guest max physical address width, so add this patch to enable

it.

Quoted 11 lines

target/i386/cpu.c static void x86_cpu_realizefn(DeviceState *dev,

Quoted 11 lines
---
  target/i386/cpu.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/cpu.c +0 -0
index 35459a38bb..b5943406f7 100644
@@ -6673,7 +6673,7 @@ static void x86_cpu_realizefn(DeviceState *dev,

Error **errp)

Quoted 5 lines

target/i386/cpu.c static void x86_cpu_realizefn(DeviceState *dev, · line 6676

Quoted 5 lines
target/i386/cpu.c +1 -1
                  warned = true;
              }
-            if (cpu->host_phys_bits) {
+            if (cpu->host_phys_bits || cpu->max_features) {
                  /* The user asked for us to use the host physical

bits */

Quoted 6 lines

target/i386/cpu.c static void x86_cpu_realizefn(DeviceState *dev, · line 6679

Quoted 3 lines
target/i386/cpu.c +0 -0
                  cpu->phys_bits = host_phys_bits;
                  if (cpu->host_phys_bits_limit &&
 

Can you check if this works?

Hi, Paolo,
Yes, below change works for kvm-unit-test/access. Would you add the patch?

Thanks!

Quoted 21 lines
target/i386/cpu.c +1 -0
index 35459a38bb..72a79e6019 100644
@@ -4319,6 +4319,7 @@ static void max_x86_cpu_initfn(Object *obj)
         if (lmce_supported()) {
             object_property_set_bool(OBJECT(cpu), "lmce", true,
 &error_abort);
         }
+        object_property_set_bool(OBJECT(cpu), "host-phys-bits", true,
 &error_abort);
     } else {

object_property_set_str(OBJECT(cpu), "vendor", CPUID_VENDOR_AMD,
&error_abort);

It should allow people to use -cpu max,host-phys-bits=false.

Thanks,

Paolo

#4 lore raw
In reply to Yang Weijiang
Quoted 26 lines · Yang Weijiang

QEMU option -cpu max(max_features) means "Enables all features supported by the accelerator in the current host", this looks true for all the features except guest max physical address width, so add this patch to enable it.

---
 target/i386/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/cpu.c +1 -1
index 35459a38bb..b5943406f7 100644
@@ -6673,7 +6673,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
                 warned = true;
             }
 
-            if (cpu->host_phys_bits) {
+            if (cpu->host_phys_bits || cpu->max_features) {
                 /* The user asked for us to use the host physical bits */
                 cpu->phys_bits = host_phys_bits;
                 if (cpu->host_phys_bits_limit &&
Signature · 1 line
2.17.2

Hi,

This patch as commit 5a140b255d ("x86/cpu: Use max host physical address if -cpu max option is applied") prevents me from using '-cpu host' while booting an i386_defconfig kernel.

$ qemu-system-i386 \
-append console=ttyS0 \
-cpu host \
-display none \
-enable-kvm \
-initrd rootfs.cpio \
-kernel bzImage \
-serial mon:stdio
qemu-system-i386: phys-bits should be between 32 and 36  (but is 48)

Am I expected to pass "-cpu host,host-phys-bits=false" now or did this do something unexpected?

Cheers,
Nathan

#5 lore raw
Quoted 44 lines · Nathan Chancellor
Quoted 26 lines · Yang Weijiang

QEMU option -cpu max(max_features) means "Enables all features supported by the accelerator in the current host", this looks true for all the features except guest max physical address width, so add this patch to enable it.

---
 target/i386/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/cpu.c +1 -1
index 35459a38bb..b5943406f7 100644
@@ -6673,7 +6673,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
                 warned = true;
             }
 
-            if (cpu->host_phys_bits) {
+            if (cpu->host_phys_bits || cpu->max_features) {
                 /* The user asked for us to use the host physical bits */
                 cpu->phys_bits = host_phys_bits;
                 if (cpu->host_phys_bits_limit &&
Signature · 1 line
2.17.2

Hi,

This patch as commit 5a140b255d ("x86/cpu: Use max host physical address if -cpu max option is applied") prevents me from using '-cpu host' while booting an i386_defconfig kernel.

$ qemu-system-i386 \
(quoted diff) +0 -7
-append console=ttyS0 \
-cpu host \
-display none \
-enable-kvm \
-initrd rootfs.cpio \
-kernel bzImage \
-serial mon:stdio

qemu-system-i386: phys-bits should be between 32 and 36 (but is 48)

Quoted 3 lines

Am I expected to pass "-cpu host,host-phys-bits=false" now or did this do something unexpected?

Hi, Nathan,
Could you try Paolo's latest patch?

[PULL 03/31] x86/cpu: Use max host physical address if -cpu max option is applied

target/i386/cpu.c +2 -0
@@ -4319,6 +4319,7 @@ static void max_x86_cpu_initfn(Object *obj)
         if (lmce_supported()) {
             object_property_set_bool(OBJECT(cpu), "lmce", true, &error_abort);
         }
+        object_property_set_bool(OBJECT(cpu), "host-phys-bits", true,
+ &error_abort);
     } else {
         object_property_set_str(OBJECT(cpu), "vendor", CPUID_VENDOR_AMD,
                                 &error_abort);
Quoted 2 lines

Cheers,
Nathan

#6 lore raw
Quoted 45 lines · Yang Weijiang
Quoted 44 lines · Nathan Chancellor
Quoted 26 lines · Yang Weijiang

QEMU option -cpu max(max_features) means "Enables all features supported by the accelerator in the current host", this looks true for all the features except guest max physical address width, so add this patch to enable it.

---
 target/i386/cpu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
target/i386/cpu.c +1 -1
index 35459a38bb..b5943406f7 100644
@@ -6673,7 +6673,7 @@ static void x86_cpu_realizefn(DeviceState *dev, Error **errp)
                 warned = true;
             }
 
-            if (cpu->host_phys_bits) {
+            if (cpu->host_phys_bits || cpu->max_features) {
                 /* The user asked for us to use the host physical bits */
                 cpu->phys_bits = host_phys_bits;
                 if (cpu->host_phys_bits_limit &&
Signature · 1 line
2.17.2

Hi,

This patch as commit 5a140b255d ("x86/cpu: Use max host physical address if -cpu max option is applied") prevents me from using '-cpu host' while booting an i386_defconfig kernel.

$ qemu-system-i386 \
(quoted diff) +0 -7
-append console=ttyS0 \
-cpu host \
-display none \
-enable-kvm \
-initrd rootfs.cpio \
-kernel bzImage \
-serial mon:stdio

qemu-system-i386: phys-bits should be between 32 and 36 (but is 48)

Quoted 7 lines
Quoted 3 lines

Am I expected to pass "-cpu host,host-phys-bits=false" now or did this do something unexpected?

Hi, Nathan,
Could you try Paolo's latest patch?

[PULL 03/31] x86/cpu: Use max host physical address if -cpu max option is applied

Hi Yang,

That is the version of the patch I tried, which has been pulled into the master branch.

Cheers,
Nathan

#7 lore raw
Quoted 14 lines · Nathan Chancellor
Quoted 14 lines
Quoted 14 lines

This patch as commit 5a140b255d ("x86/cpu: Use max host physical address if -cpu max option is applied") prevents me from using '-cpu host' while booting an i386_defconfig kernel.

$ qemu-system-i386 \
(quoted diff) +0 -7
-append console=ttyS0 \
-cpu host \
-display none \
-enable-kvm \
-initrd rootfs.cpio \
-kernel bzImage \
-serial mon:stdio

qemu-system-i386: phys-bits should be between 32 and 36 (but is 48)

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Am I expected to pass "-cpu host,host-phys-bits=false" now or did this do something unexpected?

Yes, it's setting the LM bit for a 32-bit guest.

Does this work for you?

target/i386/cpu.c +5 -0
index 72a79e6019..70df57337f 100644
@@ -5081,6 +5081,11 @@ static uint64_t x86_cpu_get_supported_feature_word(FeatureWord w,
     } else {
         return ~0;
     }
+#ifdef TARGET_I386
+    if (wi->cpuid.eax = 0x80000001) {
+        r &= ~CPUID_EXT2_LM;
+    }
+#endif
     if (migratable_only) {
         r &= x86_cpu_get_migratable_flags(w);
     }

Paolo

Quoted 13 lines
Quoted 4 lines

Hi, Nathan,
Could you try Paolo's latest patch?

[PULL 03/31] x86/cpu: Use max host physical address if -cpu max option is applied

Hi Yang,

That is the version of the patch I tried, which has been pulled into the master branch.

Cheers,
Nathan

#8 lore raw
Quoted 15 lines · Paolo Bonzini
Quoted 14 lines · Nathan Chancellor
Quoted 14 lines
Quoted 14 lines

This patch as commit 5a140b255d ("x86/cpu: Use max host physical address if -cpu max option is applied") prevents me from using '-cpu host' while booting an i386_defconfig kernel.

$ qemu-system-i386 \
(quoted diff) +0 -7
-append console=ttyS0 \
-cpu host \
-display none \
-enable-kvm \
-initrd rootfs.cpio \
-kernel bzImage \
-serial mon:stdio

qemu-system-i386: phys-bits should be between 32 and 36 (but is 48)

Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

Am I expected to pass "-cpu host,host-phys-bits=false" now or did this do something unexpected?

Yes, it's setting the LM bit for a 32-bit guest.

Does this work for you?

Yes, it does!

target/i386/cpu.c static uint64_t · line 5086

Quoted 11 lines
target/i386/cpu.c +2 -0
index 72a79e6019..70df57337f 100644
@@ -5081,6 +5081,11 @@ static uint64_t
 x86_cpu_get_supported_feature_word(FeatureWord w,
     } else {
         return ~0;
     }
+#ifdef TARGET_I386
+    if (wi->cpuid.eax = 0x80000001) {

This should be a '==':

../target/i386/cpu.c: In function ‘x86_cpu_get_supported_feature_word’:
../target/i386/cpu.c:5085:9: error: suggest parentheses around assignment used as truth value [-Werror=parentheses]
5085 | if (wi->cpuid.eax = 0x80000001) {
| ^~
cc1: all warnings being treated as errors

Quoted 8 lines
target/i386/cpu.c +3 -0
+        r &= ~CPUID_EXT2_LM;
+    }
+#endif
     if (migratable_only) {
         r &= x86_cpu_get_migratable_flags(w);
     }
Quoted 15 lines

Paolo

Quoted 13 lines
Quoted 4 lines

Hi, Nathan,
Could you try Paolo's latest patch?

[PULL 03/31] x86/cpu: Use max host physical address if -cpu max option is applied

Hi Yang,

That is the version of the patch I tried, which has been pulled into the master branch.

Cheers,
Nathan

V>