Skip to contentSkip to conversation

linux-user: ppc64: fix ARCH_206 bit in AT_HWCAP

PATCH Superseded Michael Walle 3 participants 5 messages Aug 16, 2016 – Sep 20, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: ppc64: fix ARCH_206 bit in AT_HWCAP

Only the POWER[789] CPUs should have the ARCH_206 bit set. This is what the linux kernel does. I guess this was also the intention of commit 0e019746. We have to make sure all *206 bits are set.

---
checkpatch.pl flags one warning, but I think this is a false positive.

 linux-user/elfload.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux-user/elfload.c +2 -1
index f807baf..4945d48 100644
@@ -742,7 +742,8 @@ static uint32_t get_elf_hwcap(void)
 #define GET_FEATURE(flag, feature)                                      \
     do { if (cpu->env.insns_flags & flag) { features |= feature; } } while (0)
 #define GET_FEATURE2(flag, feature)                                      \
-    do { if (cpu->env.insns_flags2 & flag) { features |= feature; } } while (0)
+    do { if ((cpu->env.insns_flags2 & flag) == flag) \
+         { features |= feature; } } while (0)
     GET_FEATURE(PPC_64B, QEMU_PPC_FEATURE_64);
     GET_FEATURE(PPC_FLOAT, QEMU_PPC_FEATURE_HAS_FPU);
     GET_FEATURE(PPC_ALTIVEC, QEMU_PPC_FEATURE_HAS_ALTIVEC);
Signature · 1 line
2.1.4
#1 lore raw
Your series seems to have some coding style problems. See output below for more information:

Hi,

Your series seems to have some coding style problems. See output below for more information:

Message-id: [email protected]
Subject: [Qemu-devel] [PATCH] linux-user: ppc64: fix ARCH_206 bit in AT_HWCAP
Type: series

=== TEST SCRIPT BEGIN ===
#!/bin/bash

BASE=base
n=1
total=$(git log --oneline $BASE.. | wc -l)
failed=0

# Useful git options
git config --local diff.renamelimit 0
git config --local diff.renames True

commits="$(git log --format=%H --reverse $BASE..)" for c in $commits; do

    echo "Checking PATCH $n/$total: $(git show --no-patch --format=%s $c)..."
    if ! git show $c --format=email | ./scripts/checkpatch.pl --mailback -; then
        failed=1
        echo
    fi
    n=$((n+1))

done

exit $failed
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384 From https://github.com/patchew-project/qemu
* [new tag] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
b0ee12f linux-user: ppc64: fix ARCH_206 bit in AT_HWCAP

=== OUTPUT BEGIN ===
Checking PATCH 1/1: linux-user: ppc64: fix ARCH_206 bit in AT_HWCAP...
ERROR: braces {} are necessary for all arms of this statement #22: FILE: linux-user/elfload.c:745:
+ do { if ((cpu->env.insns_flags2 & flag) == flag) \
[...]

total: 1 errors, 0 warnings, 9 lines checked

Your patch has style problems, please review. If any of these errors are false positives report them to the maintainer, see CHECKPATCH in MAINTAINERS.

=== OUTPUT END ===

Test command exited with code: 1

---
Email generated automatically by Patchew [http://patchew.org/].
Please send your feedback to [email protected]

#2 lore raw
In reply to Michael Walle
Quoted 3 lines · Michael Walle

Only the POWER[789] CPUs should have the ARCH_206 bit set. This is what the linux kernel does. I guess this was also the intention of commit 0e019746. We have to make sure all *206 bits are set.

Hrm.. it's not clear to me how this patch fixes things. What was incorrect with the previous logic?

Quoted 4 lines

---
checkpatch.pl flags one warning, but I think this is a false positive.

Yes, I think so to, but..

Quoted 8 lines
 linux-user/elfload.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux-user/elfload.c +0 -0
index f807baf..4945d48 100644

linux-user/elfload.c static uint32_t get_elf_hwcap(void) · line 746

Quoted 6 lines
linux-user/elfload.c +2 -1
@@ -742,7 +742,8 @@ static uint32_t get_elf_hwcap(void)
 #define GET_FEATURE(flag, feature)                                      \
     do { if (cpu->env.insns_flags & flag) { features |= feature; } } while (0)
 #define GET_FEATURE2(flag, feature)                                      \
-    do { if (cpu->env.insns_flags2 & flag) { features |= feature; } } while (0)
+    do { if ((cpu->env.insns_flags2 & flag) == flag) \
+         { features |= feature; } } while (0)

..given that you're splitting this to >1 line, I think you might as well expand it fully into a more normal indent style, which should also shut up the stylebot.

Quoted 3 lines
linux-user/elfload.c +0 -0
     GET_FEATURE(PPC_64B, QEMU_PPC_FEATURE_64);
     GET_FEATURE(PPC_FLOAT, QEMU_PPC_FEATURE_HAS_FPU);
     GET_FEATURE(PPC_ALTIVEC, QEMU_PPC_FEATURE_HAS_ALTIVEC);
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#3 lore raw

Am 2016-09-20 04:23, schrieb David Gibson:

Quoted 7 lines · Michael Walle
Quoted 3 lines

Only the POWER[789] CPUs should have the ARCH_206 bit set. This is what the linux kernel does. I guess this was also the intention of commit 0e019746. We have to make sure all *206 bits are set.

Hrm.. it's not clear to me how this patch fixes things. What was incorrect with the previous logic?

ah, i guess the patch has too few context. in the previous logic, only one bit in "flag" had to be set and the expression would evaluate to true. This is correct if there is only one bit set in "flag", but GET_FEATURE2 is also used with multiple bits set in "flag":

    GET_FEATURE2((PPC2_BCTAR_ISA207 | PPC2_LSQ_ISA207 | PPC2_ALTIVEC_207 
|
                  PPC2_ISA207S), QEMU_PPC_FEATURE2_ARCH_2_07);

Ahh, I've just seen that Tom's mail wasn't CCed to the mailinglist:

Am 2016-08-01 14:17, schrieb Tom Musta:

Quoted 5 lines

I took a quick look at the qemu and linux code and I think I agree with Michael's analysis. The HWCAP bit seems to mean that the entire ISA is supported and therefore excludes all of these implementations (like e5500) which picked and chose some aspects of that ISA version.

Quoted 34 lines

Hope all is well with you, Alex!

Quoted 29 lines · Michael Walle

Hi,

ok this was a tough one. Programs which links to ceil() aborts with invalid instruction. The instruction was "frip", which isn't supported on e5500 or e500mc. Turns out the libc checks the AT_HWCAP field (dunno if that has to do with multilib support) and uses the optimized power5 code if the ARCH_2_06 bit is set. linux-user sets the ARCH_2_06 bit in case of a e5500 core, which is wrong IMHO. In fact the linux kernel sets this bit only for POWER[789] CPUs.

The line which sets this bit in linux-user is:

#define GET_FEATURE2(flag, feature)
\
do { if (cpu->env.insns_flags2 & flag) { features |= feature; } } while (0)

GET_FEATURE2((PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 | PPC2_ATOMIC_ISA206 |
PPC2_FP_CVT_ISA206 | PPC2_FP_TST_ISA206), QEMU_PPC_FEATURE_ARCH_2_06);

PPC2_PERM_ISA206 is set for the e5500/e500mc core. Is this really intended to set the ARCH_2_06 bit if _any_ of the listed bits is set or should it set the ARCH_2_06 bit only if _all_ bits are set. Eg.

#define GET_FEATURES(flag, feature)
do { if (cpu->env.insns_flags2 & flag == flag) { features |= feature; } } while (0)

-michael

#4 lore raw
Quoted 11 lines · Michael Walle

Am 2016-09-20 04:23, schrieb David Gibson:

Quoted 9 lines · Michael Walle
Quoted 5 lines

Only the POWER[789] CPUs should have the ARCH_206 bit set. This is what the
linux kernel does. I guess this was also the intention of commit 0e019746.
We have to make sure all *206 bits are set.

Hrm.. it's not clear to me how this patch fixes things. What was incorrect with the previous logic?

Quoted 7 lines

ah, i guess the patch has too few context. in the previous logic, only one bit in "flag" had to be set and the expression would evaluate to true. This is correct if there is only one bit set in "flag", but GET_FEATURE2 is also used with multiple bits set in "flag":

    GET_FEATURE2((PPC2_BCTAR_ISA207 | PPC2_LSQ_ISA207 | PPC2_ALTIVEC_207 |
                  PPC2_ISA207S), QEMU_PPC_FEATURE2_ARCH_2_07);

Ah, right, that makes sense.

Quoted 2 lines

Ahh, I've just seen that Tom's mail wasn't CCed to the mailinglist:

Ok. But regardless of that, this explanation needs to be in the commit message for the benefit of people looking back in future.

Please resend with a commit message expanded to include the above explanation, and I expect I'll commit it.

Quoted 45 lines

Am 2016-08-01 14:17, schrieb Tom Musta:

Quoted 5 lines

I took a quick look at the qemu and linux code and I think I agree with Michael's analysis. The HWCAP bit seems to mean that the entire ISA is supported and therefore excludes all of these implementations (like e5500) which picked and chose some aspects of that ISA version.

Quoted 34 lines

Hope all is well with you, Alex!

Quoted 29 lines · Michael Walle

Hi,

ok this was a tough one. Programs which links to ceil() aborts with invalid instruction. The instruction was "frip", which isn't supported on e5500 or e500mc. Turns out the libc checks the AT_HWCAP field (dunno if that has to do with multilib support) and uses the optimized power5 code if the ARCH_2_06 bit is set. linux-user sets the ARCH_2_06 bit in case of a e5500 core, which is wrong IMHO. In fact the linux kernel sets this bit only for POWER[789] CPUs.

The line which sets this bit in linux-user is:

#define GET_FEATURE2(flag, feature)
\
do { if (cpu->env.insns_flags2 & flag) { features |= feature; } } while (0)

GET_FEATURE2((PPC2_PERM_ISA206 | PPC2_DIVE_ISA206 | PPC2_ATOMIC_ISA206 |
PPC2_FP_CVT_ISA206 | PPC2_FP_TST_ISA206), QEMU_PPC_FEATURE_ARCH_2_06);

PPC2_PERM_ISA206 is set for the e5500/e500mc core. Is this really intended to set the ARCH_2_06 bit if _any_ of the listed bits is set or should it set the ARCH_2_06 bit only if _all_ bits are set. Eg.

#define GET_FEATURES(flag, feature)
do { if (cpu->env.insns_flags2 & flag == flag) { features |= feature; } } while (0)

-michael

Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson