target/i386: Fixed size of constant for Windows
PATCH 1/1 target/i386: Fixed size of constant for Windows
~0UL has 64 bits on Linux and 32 bits on Windows.
Fixes: https://gitlab.com/qemu-project/qemu/-/issues/512".
--- target/i386/tcg/sysemu/misc_helper.c | 2 +- target/i386/tcg/sysemu/svm_helper.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
target/i386/tcg/sysemu/misc_helper.c +1 -1
@@ -97,7 +97,7 @@ void helper_write_crN(CPUX86State *env, int reg, target_ulong t0)break ;case 3 :if ((env->efer &MSR_EFER_LMA ) && - (t0 & ((~0UL ) <<env_archcpu (env)->phys_bits))) { + (t0 & ((~0ULL ) <<env_archcpu (env)->phys_bits))) {cpu_vmexit (env,SVM_EXIT_ERR ,0 ,GETPC ()); }if (!(env->efer &MSR_EFER_LMA )) {
target/i386/tcg/sysemu/svm_helper.c +1 -1
@@ -290,7 +290,7 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) } new_cr3 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.cr3));if ((env->efer &MSR_EFER_LMA ) && - (new_cr3 & ((~0UL ) << cpu->phys_bits))) { + (new_cr3 & ((~0ULL ) << cpu->phys_bits))) {cpu_vmexit (env,SVM_EXIT_ERR ,0 ,GETPC ()); } new_cr4 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.cr4));
Signature · 1 line
2.25.1
Quoted 3 lines · Lara Lazier
~0UL has 64 bits on Linux and 32 bits on Windows.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/512
Quoted 12 lines
Reported-by Volker Rümelin <[email protected]>Signed-off-by Lara Lazier <[email protected]>--- target/i386/tcg/sysemu/misc_helper.c | 2 +- target/i386/tcg/sysemu/svm_helper.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)target/i386/tcg/sysemu/misc_helper.c +0
-0
target/i386/tcg/sysemu/misc_helper.c void helper_write_crN(CPUX86State *env, int reg, target_ulong t0) · line 100
Quoted 5 lines
target/i386/tcg/sysemu/misc_helper.c +1
-1@@ -97,7 +97,7 @@ void helper_write_crN(CPUX86State *env, int reg, target_ulong t0)break ;case 3 :if ((env->efer &MSR_EFER_LMA ) && - (t0 & ((~0UL ) <<env_archcpu (env)->phys_bits))) { + (t0 & ((~0ULL ) <<env_archcpu (env)->phys_bits))) {
Maybe safer to use extract64()? I'm not sure how many bits you want to check, so used TARGET_LONG_BITS:
extract64(t0, env_archcpu(env)->phys_bits,
TARGET_LONG_BITS - env_archcpu(env)->phys_bits) {Quoted 9 lines
target/i386/tcg/sysemu/misc_helper.c +0
-0cpu_vmexit (env,SVM_EXIT_ERR ,0 ,GETPC ()); }if (!(env->efer &MSR_EFER_LMA )) {target/i386/tcg/sysemu/svm_helper.c +0
-0
target/i386/tcg/sysemu/svm_helper.c void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) · line 296
Quoted 8 lines
target/i386/tcg/sysemu/svm_helper.c +1
-1@@ -290,7 +290,7 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) } new_cr3 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.cr3));if ((env->efer &MSR_EFER_LMA ) && - (new_cr3 & ((~0UL ) << cpu->phys_bits))) { + (new_cr3 & ((~0ULL ) << cpu->phys_bits))) {cpu_vmexit (env,SVM_EXIT_ERR ,0 ,GETPC ()); } new_cr4 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.cr4));
Any idea how to avoid that class of bug? Some CFLAG or plain checkpatch?
Peter Maydell
Reviewed-byQuoted 30 lines · Philippe Mathieu-Daudé
Quoted 3 lines · Lara Lazier
~0UL has 64 bits on Linux and 32 bits on Windows.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/512
Fixes 3407259b20c ("target/i386: Added consistency checks for CR3")Quoted 12 lines
Reported-by Volker Rümelin <[email protected]>Signed-off-by Lara Lazier <[email protected]>--- target/i386/tcg/sysemu/misc_helper.c | 2 +- target/i386/tcg/sysemu/svm_helper.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)target/i386/tcg/sysemu/misc_helper.c +0
-0target/i386/tcg/sysemu/misc_helper.c void helper_write_crN(CPUX86State *env, int reg, target_ulong t0) · line 100
Quoted 5 lines
target/i386/tcg/sysemu/misc_helper.c +1
-1@@ -97,7 +97,7 @@ void helper_write_crN(CPUX86State *env, int reg, target_ulong t0)break ;case 3 :if ((env->efer &MSR_EFER_LMA ) && - (t0 & ((~0UL ) <<env_archcpu (env)->phys_bits))) { + (t0 & ((~0ULL ) <<env_archcpu (env)->phys_bits))) {Maybe safer to use
extract64()? I'm not sure how many bits you want to check, so usedTARGET_LONG_BITS:
Quoted 2 lines
extract64(t0, env_archcpu(env)->phys_bits,
TARGET_LONG_BITS - env_archcpu(env)->phys_bits) {The repetition of the 'phys_bits' expression in both the shift and the length field is pretty awkward. Maybe
t0 & ~MAKE_64BIT_MASK(0, env_archcpu(env)->phys_bits)
But for this bugfix I think just fixing the suffix is fine.
Quoted 11 lines
Quoted 11 lines
target/i386/tcg/sysemu/misc_helper.c +0
-0cpu_vmexit (env,SVM_EXIT_ERR ,0 ,GETPC ()); }if (!(env->efer &MSR_EFER_LMA )) {target/i386/tcg/sysemu/svm_helper.c +0
-0@@ -290,7 +290,7 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) } new_cr3 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.cr3)); if ((env->efer & MSR_EFER_LMA) &&
Quoted 8 lines
target/i386/tcg/sysemu/svm_helper.c void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) · line 296
Quoted 6 lines
target/i386/tcg/sysemu/svm_helper.c +1
-1- (new_cr3 & ((~0UL) << cpu->phys_bits))) { + (new_cr3 & ((~0ULL) << cpu->phys_bits))) {cpu_vmexit (env,SVM_EXIT_ERR ,0 ,GETPC ()); } new_cr4 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.cr4));Any idea how to avoid that class of bug? Some CFLAG or plain checkpatch?
In general the 'UL' is often dubious and worth checking -- either 'U' suffices or you wanted 'ULL'. But in a few places where you're actually working with 'unsigned long' it's what you need, so I'm not sure a checkpatch rule would be possible.
-- PMM
Philippe Mathieu-Daudé
Reviewed-byQuoted 31 lines · Peter Maydell
Quoted 30 lines · Philippe Mathieu-Daudé
Quoted 3 lines · Lara Lazier
~0UL has 64 bits on Linux and 32 bits on Windows.
Resolves: https://gitlab.com/qemu-project/qemu/-/issues/512
Fixes 3407259b20c ("target/i386: Added consistency checks for CR3")Quoted 12 lines
Reported-by Volker Rümelin <[email protected]>Signed-off-by Lara Lazier <[email protected]>--- target/i386/tcg/sysemu/misc_helper.c | 2 +- target/i386/tcg/sysemu/svm_helper.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)target/i386/tcg/sysemu/misc_helper.c +0
-0target/i386/tcg/sysemu/misc_helper.c void helper_write_crN(CPUX86State *env, int reg, target_ulong t0) · line 100
Quoted 5 lines
target/i386/tcg/sysemu/misc_helper.c +1
-1@@ -97,7 +97,7 @@ void helper_write_crN(CPUX86State *env, int reg, target_ulong t0)break ;case 3 :if ((env->efer &MSR_EFER_LMA ) && - (t0 & ((~0UL ) <<env_archcpu (env)->phys_bits))) { + (t0 & ((~0ULL ) <<env_archcpu (env)->phys_bits))) {Maybe safer to use
extract64()? I'm not sure how many bits you want to check, so usedTARGET_LONG_BITS:
Quoted 7 lines
Quoted 2 lines
extract64(t0, env_archcpu(env)->phys_bits, TARGET_LONG_BITS - env_archcpu(env)->phys_bits) {The repetition of the '
phys_bits' expression in both the shift and the length field is pretty awkward. Maybet0 & ~MAKE_64BIT_MASK(0, env_archcpu(env)->phys_bits)
Ah, nicer.
Quoted 1 line
But for this bugfix I think just fixing the suffix is fine.
Sure.
Quoted 2 lines
Reviewed-by Peter Maydell <[email protected]>
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
target/i386/tcg/sysemu/misc_helper.c +0
-0cpu_vmexit (env,SVM_EXIT_ERR ,0 ,GETPC ()); }if (!(env->efer &MSR_EFER_LMA )) {target/i386/tcg/sysemu/svm_helper.c +0
-0@@ -290,7 +290,7 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) } new_cr3 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.cr3)); if ((env->efer & MSR_EFER_LMA) &&Quoted 8 lines
target/i386/tcg/sysemu/svm_helper.c void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) · line 296
Quoted 6 lines
target/i386/tcg/sysemu/svm_helper.c +1
-1- (new_cr3 & ((~0UL) << cpu->phys_bits))) { + (new_cr3 & ((~0ULL) << cpu->phys_bits))) {cpu_vmexit (env,SVM_EXIT_ERR ,0 ,GETPC ()); } new_cr4 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.cr4));Any idea how to avoid that class of bug? Some CFLAG or plain checkpatch?
Quoted 4 lines
In general the 'UL' is often dubious and worth checking -- either 'U' suffices or you wanted 'ULL'. But in a few places where you're actually working with 'unsigned long' it's what you need, so I'm not sure a checkpatch rule would be possible.
OK, thanks.
Paolo Bonzini
AppliedQuoted 29 lines · Lara Lazier
~0UL has 64 bits on Linux and 32 bits on Windows.
Fixes: https://gitlab.com/qemu-project/qemu/-/issues/512".Reported-by Volker Rümelin <[email protected]>Signed-off-by Lara Lazier <[email protected]>--- target/i386/tcg/sysemu/misc_helper.c | 2 +- target/i386/tcg/sysemu/svm_helper.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)target/i386/tcg/sysemu/misc_helper.c +1
-1@@ -97,7 +97,7 @@ void helper_write_crN(CPUX86State *env, int reg, target_ulong t0)break ;case 3 :if ((env->efer &MSR_EFER_LMA ) && - (t0 & ((~0UL ) <<env_archcpu (env)->phys_bits))) { + (t0 & ((~0ULL ) <<env_archcpu (env)->phys_bits))) {cpu_vmexit (env,SVM_EXIT_ERR ,0 ,GETPC ()); }if (!(env->efer &MSR_EFER_LMA )) {target/i386/tcg/sysemu/svm_helper.c +0
-0
target/i386/tcg/sysemu/svm_helper.c void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) · line 296
Quoted 8 lines
target/i386/tcg/sysemu/svm_helper.c +1
-1@@ -290,7 +290,7 @@ void helper_vmrun(CPUX86State *env, int aflag, int next_eip_addend) } new_cr3 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.cr3));if ((env->efer &MSR_EFER_LMA ) && - (new_cr3 & ((~0UL ) << cpu->phys_bits))) { + (new_cr3 & ((~0ULL ) << cpu->phys_bits))) {cpu_vmexit (env,SVM_EXIT_ERR ,0 ,GETPC ()); } new_cr4 = x86_ldq_phys(cs, env->vm_vmcb + offsetof(struct vmcb, save.cr4));
Queued, thanks.
Paolo