[PATCH v16 22/23] target/i386: fix host_cpu_adjust_phys_bits error handling

Claudio Fontana posted 23 patches 5 years ago
Maintainers: Thomas Huth <thuth@redhat.com>, Stafford Horne <shorne@gmail.com>, Colin Xu <colin.xu@intel.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, "Michael S. Tsirkin" <mst@redhat.com>, Aurelien Jarno <aurelien@aurel32.net>, Marcelo Tosatti <mtosatti@redhat.com>, Michael Walle <michael@walle.cc>, Chris Wulff <crwulff@gmail.com>, Cameron Esfahani <dirty@apple.com>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Sagar Karandikar <sagark@eecs.berkeley.edu>, Peter Maydell <peter.maydell@linaro.org>, Yoshinori Sato <ysato@users.sourceforge.jp>, Riku Voipio <riku.voipio@iki.fi>, David Hildenbrand <david@redhat.com>, Stefano Stabellini <sstabellini@kernel.org>, Paolo Bonzini <pbonzini@redhat.com>, Roman Bolshakov <r.bolshakov@yadro.com>, Sunil Muthuswamy <sunilmut@microsoft.com>, Paul Durrant <paul@xen.org>, Eduardo Habkost <ehabkost@redhat.com>, Greg Kurz <groug@kaod.org>, Max Filippov <jcmvbkbc@gmail.com>, Laurent Vivier <lvivier@redhat.com>, Michael Rolnik <mrolnik@gmail.com>, "Hervé Poussineau" <hpoussin@reactos.org>, Cornelia Huck <cohuck@redhat.com>, Bastian Koppelmann <kbastian@mail.uni-paderborn.de>, Aleksandar Rikalo <aleksandar.rikalo@syrmia.com>, Guan Xuetao <gxt@mprc.pku.edu.cn>, Palmer Dabbelt <palmer@dabbelt.com>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, Richard Henderson <richard.henderson@linaro.org>, Jiaxun Yang <jiaxun.yang@flygoat.com>, Artyom Tarasenko <atar4qemu@gmail.com>, Laurent Vivier <laurent@vivier.eu>, Marek Vasut <marex@denx.de>, Alistair Francis <Alistair.Francis@wdc.com>, Anthony Perard <anthony.perard@citrix.com>, David Gibson <david@gibson.dropbear.id.au>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Wenchao Wang <wenchao.wang@intel.com>, Sarah Harris <S.E.Harris@kent.ac.uk>, Anthony Green <green@moxielogic.com>
There is a newer version of this series
[PATCH v16 22/23] target/i386: fix host_cpu_adjust_phys_bits error handling
Posted by Claudio Fontana 5 years ago
move the check for phys_bits outside of host_cpu_adjust_phys_bits,
because otherwise it is impossible to return an error condition
explicitly.

Signed-off-by: Claudio Fontana <cfontana@suse.de>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
---
 target/i386/host-cpu.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/target/i386/host-cpu.c b/target/i386/host-cpu.c
index 9cfe56ce41..d07d41c34c 100644
--- a/target/i386/host-cpu.c
+++ b/target/i386/host-cpu.c
@@ -50,7 +50,7 @@ static void host_cpu_enable_cpu_pm(X86CPU *cpu)
     env->features[FEAT_1_ECX] |= CPUID_EXT_MONITOR;
 }
 
-static uint32_t host_cpu_adjust_phys_bits(X86CPU *cpu, Error **errp)
+static uint32_t host_cpu_adjust_phys_bits(X86CPU *cpu)
 {
     uint32_t host_phys_bits = host_cpu_phys_bits();
     uint32_t phys_bits = cpu->phys_bits;
@@ -77,14 +77,6 @@ static uint32_t host_cpu_adjust_phys_bits(X86CPU *cpu, Error **errp)
         }
     }
 
-    if (phys_bits &&
-        (phys_bits > TARGET_PHYS_ADDR_SPACE_BITS ||
-         phys_bits < 32)) {
-        error_setg(errp, "phys-bits should be between 32 and %u "
-                   " (but is %u)",
-                   TARGET_PHYS_ADDR_SPACE_BITS, phys_bits);
-    }
-
     return phys_bits;
 }
 
@@ -97,7 +89,17 @@ void host_cpu_realizefn(CPUState *cs, Error **errp)
         host_cpu_enable_cpu_pm(cpu);
     }
     if (env->features[FEAT_8000_0001_EDX] & CPUID_EXT2_LM) {
-        cpu->phys_bits = host_cpu_adjust_phys_bits(cpu, errp);
+        uint32_t phys_bits = host_cpu_adjust_phys_bits(cpu);
+
+        if (phys_bits &&
+            (phys_bits > TARGET_PHYS_ADDR_SPACE_BITS ||
+             phys_bits < 32)) {
+            error_setg(errp, "phys-bits should be between 32 and %u "
+                       " (but is %u)",
+                       TARGET_PHYS_ADDR_SPACE_BITS, phys_bits);
+            return;
+        }
+        cpu->phys_bits = phys_bits;
     }
 }
 
-- 
2.26.2


Re: [PATCH v16 22/23] target/i386: fix host_cpu_adjust_phys_bits error handling
Posted by Richard Henderson 5 years ago
On 2/4/21 6:39 AM, Claudio Fontana wrote:
> move the check for phys_bits outside of host_cpu_adjust_phys_bits,
> because otherwise it is impossible to return an error condition
> explicitly.
> 
> Signed-off-by: Claudio Fontana <cfontana@suse.de>
> Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
> ---
>  target/i386/host-cpu.c | 22 ++++++++++++----------
>  1 file changed, 12 insertions(+), 10 deletions(-)

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>

r~