mirror of
https://github.com/openwall/john.git
synced 2026-12-03 18:45:21 +07:00
[GH-ISSUE #2861] Build failures on Linux/PPC64 #1820
Labels
No labels
bug
core branch
documentation
enhancement
enhancement
fixed - pending verify
fuzz bug
good first issue
invalid
invalid
maintenance/cleanup
new cracking mode
new format
new tool
non-trivial
notes/external issues
portability
question
RFC / discussion
testing
WONTFIX
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
openwall/john#1820
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @solardiz on GitHub (Nov 9, 2017).
Original GitHub issue: https://github.com/openwall/john/issues/2861
Trying to build today's bleeding-jumbo on GCC Compile Farm's "gcc110" configures as:
That was simple
./configurewith no options. Apparently, it didn't detect AltiVec? (The hardware supports AltiVec.) Anyway, the build fails with many errors like:and many more like these, in other source files too, indicating that our source files try to use SIMD anyway.
I've tried these, to no avail:
although the ways the build failed changed. In none of these cases would
./configureexplicitly say it'd use AltiVec. I think we should introduce end-user friendly configure options to enable/disable SIMD (and have those options substitute the needed platform-specific compiler flags automatically).BTW, there are also these warnings:
@solardiz commented on GitHub (Nov 9, 2017):
@magnumripper and/or @jfoug, do you have GCC Compile Farm accounts? If not, you can apply for them. I'd prefer that you figure this out and fix it. ;-)
@jfoug commented on GitHub (Nov 11, 2017):
I am setting up a QEMU PPC64 system (hopefully). I have also applied for a GCC compile farm account, but it listed the acceptance was by hand, and would take several days at least. I have not heard back on that yet. But hopefully the 8.8.0 Debian PPC64 VM will work, and if so, will provide a nice controlled environment to look into these type bugs.
Note, there is nothing in configure to detect SIMD other than x64 variants, and now a few others (like neon). NOTE, there will likely be a WHOLE lot of failure, once we go to BE SIMD code in many formats. Time will tell, for sure ;) Almost all of the work inside the SIMD defines, worked under assumption of LE byte ordering. Hopefully, this VM will emulate AltVec SIMD instructions also, and make development / testing work out much easier.
@jfoug commented on GitHub (Nov 12, 2017):
Warnings fixed:
60b9362a4and14dd15e4c@jfoug commented on GitHub (Nov 13, 2017):
I have (finally) gotten an AltiVec build working (well it runs) on the ppc. It was not easy, so far.
As I expected, all (or most) formats fail, since there was assumptions made for the SIMD code that SIMD builds would be in LE format. I will see if I can easily figure this out. We should be mostly able to hide the endianity using the GETPOS macros
@jfoug commented on GitHub (Nov 13, 2017):
here are the hacks I have done so far to get this far (talking to myself here)
Made changes to configure.ac and m4/jtr_ppc.m4 Changed the original PPC macro to be PPC64LE Added a new PPC64 macro. Added this output to the PPC64 macro: CPU_BEST_FLAGS="-maltivec -mvsx -mpower8-vector -m64" Also made changes to configure.ac to use this PPC64 macro
CFLAGS="-O2 -m64" ./configure
Had to apt-get install all of the power64 stuff I could
Edited aes/Makefile and aes/openssl/Makefile (adding the -m64)
Made changes to the ./Makefile, LDFLAGS (added /usr/lib64 /usr/lib)
LD_LIBRARY_PATH needed updated (/lib64:/usr/lib) Note, when I build oSSL, I screwed up and did not properly set the output patch to be /lib64, since I was not aware of where it should be.
Removed encfs format (uses some oSSL that was not compatible with my build)
Edited listconf.c removing the oSSL versioning code that is not part of my library.
I may be leaving something out, but I think that is most of it.
Now, john runs, but all AltiVec formats fail (as I expected). But this provides a basis to figure out how to make them work. Once one is completed, then most should be easy. Then there will likely be some (10% or so), that require some other smallish porting changes.
@solardiz commented on GitHub (Nov 13, 2017):
Thank you, Jim! I'd expect the DES-based formats from core to work fine with AltiVec, since they do in core. (In fact, historically JtR's bitslice DES first reached 128-bit SIMD with AltiVec and only later with SSE.) Is this not the case?
@solardiz commented on GitHub (Nov 13, 2017):
Here's
john-1.8.0.11built withmake -j linux-ppc32-altivecon gcc110:@solardiz commented on GitHub (Nov 13, 2017):
linux-ppc64-altivecbuild failed. Now fixed in core with:Also added
-fno-strict-aliasingtoOPT_INLINEfor both linux-ppc*-altivec targets.Oh, and
MD5_IMMturned out to be more optimal here (unexpected), for both 32-bit and 64-bit. With all of these changes, 64-bit produces:Except for md5crypt (where MD5_IMM made a difference), other performance changes seen here are probably mostly a random fluctuation rather than a genuine difference between 32-bit and 64-bit builds.
@jfoug commented on GitHub (Nov 13, 2017):
descrypt does not appear to use AltiVec instructions in the build I did. md5crypt does use AltiVec, and fails.
Note, I likely will not have time to dig into this until later in the week (possibly not until the weekend)
@jfoug commented on GitHub (Nov 13, 2017):
I have looked into some of the jumbo formats, and Doing this for AltiVec (or any BE SIMD), will be pretty much a full rewrite of a LOT of code. Anything dealing with any interleaved buffers will require code changes. I was hoping that simply updating the GETPOS() macro would suffice. In some instances that may be the case, but that likely will not be the rule.
@solardiz commented on GitHub (Nov 13, 2017):
This shouldn't be so difficult to fix. Lei Zhang got AltiVec working for us in 64-bit BE builds in 2015. We just seem to have broken this since, and we need to unbreak it.
http://www.openwall.com/lists/john-dev/2015/07/10/1
http://www.openwall.com/lists/john-dev/2015/07/10/2
@jfoug commented on GitHub (Nov 14, 2017):
I have gotten AltiVec code working for rawMD5 format. I will post the diff, and will also create another bug list. That bug list will be to port all SIMD formats to work properly for any build with BE/LE SIMD BE/LE non-SIMD and in either OMP or Non. That task will NOT be a small undertaking. But now with the first one done, at least I have a template for replacing the set_key optimized function, and for proceeding forward with other formats. But it is just a slow processes. A lot of dump_stuff_mmx() calls get scattered all over the place, working to figure things out. The longest time here, was finding the actual RIGHT byte layout for the format hash to work at all. Also, I am not 100% sure about REVERSE_STEPS code. I made a change to cmp_exact to simply skip the first 32 bit value (since it was already tested in the cmp_one/cmp_all tests. Here it the change (most debugging removed, only a small commented out section left)
This code is NOT checked in, because I have probably broken the non-simd BE porting. I will have to investigate that, and possibly use this simplified method.
@jfoug commented on GitHub (Nov 14, 2017):
Getting this to work on BE without SIMD should be easy. Simply change the code removal in binary() and source(). Then do the byte swapping if building for a non-SIMD BE system. for BE-SIMD systems, we do not swap here. We will have the final crypt value in machine layout, so we want to keep the binary in machine layout, so it is easy to match (same for source, since the binary was not swapped).
But for non-SIMD BE systems, within the binary_hash and cmp() we want the data swapped. so that it is returned to proper LE format (since the oSSL code will put the results back into LE format).
@jfoug commented on GitHub (Nov 14, 2017):
Here are timings (take with grain of salt, since running in a QEMU emulation VM)
The non-SIMD is 32 bit, the AltiVec is 64 bit But this still shows 3.6x improvment (4X SIMD), so it appears to be running fairly well.
@jfoug commented on GitHub (Nov 14, 2017):
I now have LE and BE algorithm examples working (raw-md4/5 and raw-sha1) in #2888
Its all good, just a LOT of work to get these all ported. It is going to get much harder on some of the formats, simply figuring out just what needs swapped, and being able to do so without impacting any other builds. there are a LOT of SIMD stuff. The ugly stuff, like dynamic and some of the special 'include' pbkdf2 type stuff will likely not be fun, but once figured out, will probably not be that big of a deal
@jfoug commented on GitHub (Nov 14, 2017):
Btw, I have been getting 3.6x improvements. Lei was getting only about 3.2x I would BET that his work was before the new set_key() logic. That extra 11% sounds about like the gains received in the new set_key handling data 4 bytes at a time, and why @magnum moved to using that logic.
@solardiz commented on GitHub (Nov 14, 2017):
That's a fine bet, but of course you can't compare even relative speeds on real hardware vs. VMs with that kind of precision. Things vary a lot even between hardware platforms. Often the scalar peak instruction issue rate is higher than SIMD's (e.g., 4 vs. 3 on Haswell). For example, I saw something like 42M c/s in a 64-bit scalar build vs. 59M c/s in the AltiVec build for descrypt on gcc110 - that's not even a 2x speedup from SIMD on that platform, although much greater speedup was seen on Power Macs in 2005 or so. This really varies between CPUs a lot. Perhaps there's some room for tuning of descrypt on that system for better AltiVec performance, though.
@jfoug commented on GitHub (Nov 14, 2017):
true enough.
Well, I will get the other 32 bit BE raw formats done, and then turn my eyes to the 64 bit BE formats (SHA2 stuff) Once the raw-* stuff is done, I might have a look at the pbkdf2 include magic. That is used by a lot of formats, so if things work out, it may kill a lot of birds with just getting those includes done properly.
@jfoug commented on GitHub (Nov 15, 2017):
getting the pbkdf2-hmac-sha1.h fixed (all other pbkdf2-hmac-.h files already were BE ready), got a lot of formats working. I still have about 80 formats left, but this now looks MUCH more manageable than having 150-200 formats needing ported. The nice thing about when I originally wrote the pbkdf2-hmac-.h helpers, is that you get it rignt, and all formats 'work', YET it is very very fast (near optimal). there are still a few formats using PBKDF2 which are failing. But most of those use PBKDF2 t generate a session key, and it is almost certain, that the key generated will require swapping. But hopefully a large part of those formats will be easy. There already is swapping code in the non-SIMD logic path. It just has to also be in this new path. IIRC, the pbkdf2 include code 'may' have a param which avoids the final swap. If that is the case, then many of these may work by simply changing a calling param when in BE
@jfoug commented on GitHub (Nov 15, 2017):
But I do need to get on this bug also, and get a proper configure (and possibly changes to some core building), so that the AltiVec (and PPC64 building 32 bit) works fine, on a generic ./configure && make -sj8 && ../run/john -test-full=0 manner
@kholia already is asking just wtf I did to get things to work. Well, on the configure he is doing, I simply changed arch.h->ppc64.h to arch.h->ppc32.h (since it is building with a 32 bit compiler) that really boils down to the configure NOT using the 64 bit compiler (if it is installed). I had to add a CFLAGS="-O2 -m64" to get the 64 bit stuff. I would rather be forced to include CFLAGS="-O2 -m32" to get a 32 bit build on this box, and have the 64 bit be the default, which is what should be the way things work.
@jfoug commented on GitHub (Nov 20, 2017):
Not sure if this bug is also linked to this alignment bug, but if not https://github.com/magnumripper/JohnTheRipper/issues/2868 also is part of this porting.
We have had 2 long standing assumptions when it came to SIMD building.
Both of those assumptions are no longer true, and both are being addressed. It is overall somewhat trivial porting code, BUT there is a lot of it. Also, 'SOME' of the porting code is not so trivial, and requires a lot of dump_stuff() and dump_stuff_mmx() calls to actually find out what really requires alignment swapping.
@jfoug commented on GitHub (Nov 27, 2017):
@solardiz
Can you try building again with this patch applied? The patch gets my QEMU ppc64BE working just fine. I do have to add a special -I and -L to get gmp working, but that is likely just my setup. I hope this would work on got GCC compile machines (I still do not have an account)
Things changed:
NOTE there may be other systems which we need to kick up the 64 bit flags to get the compiler ready.
@jfoug commented on GitHub (Nov 27, 2017):
I am also looking at making this change to the above code (configure.ac) This just makes sure that on 64 bit builds, IF the compiler handles the -m64, that we insert that flag into the 3 needed flags PRIOR to the real workhorse code being done during configure run.
@kholia commented on GitHub (Nov 28, 2017):
@jfoug Can you please push this patch to a topic branch in your repository? It seems that copy-pasting patches from the diffs posted on GitHub doesn't work all the time.
@jfoug commented on GitHub (Nov 30, 2017):
@solardiz please check out #2942 and make sure it works properly on the GCC compile 10 machine (the power64 box)
@jfoug commented on GitHub (Nov 30, 2017):
@solardiz Looking at Makefile.legacy, we do have a ppc64 and ppc64 altvec target. They use different arch.h headers (thats ok, configure should use just one).
The question I have, is the ppc64alt.h setup PROPERLY for altivec? If so, I will adjust ppc64.h so that if built by Makefile.legacy, it will still behave the same, but I will copy in data needed into ppc64.h to make it 'appear' like the proper header file (the ppc64alt.h) IF building under autoconf. I have added logic to output a HAVE_ALTIVEC along with the HAVE_Powerpc64 (if ALTIVEC is not present). I can use those defines within ppc64.h to get things right. I just need to know if ppc64alt.h is 'right'
@jfoug commented on GitHub (Nov 30, 2017):
One note on #2942 I will work to get SIMD_PARA_* things right, BUT we really need to have someone with access to real ppc64 iron to validate that the right PARA values are used.
@magnumripper commented on GitHub (Nov 30, 2017):
/me thinks you should set all of them to 1 until we can test on the real deal.
@jfoug commented on GitHub (Nov 30, 2017):
I have tested 1, 2, 3 (testing 4). Speeds are gradually getting higher for all hashes. I am hopeful there will be some top cap.
But there was a really big improvment on some formats (30% or so) going from 1 to 2. BUT this IS only on a VM, so we really need hardware to know if the right choices are made.
here are the current speeds I have seen
@jfoug commented on GitHub (Nov 30, 2017):
I believe now that #2942 is complete. Yes, we need to get ppc64.h correct (SIMD_PARA_* values), but that can easily be done later. The configure (and other items) porting is done, and passed all CI testing.
@magnumripper commented on GitHub (Nov 30, 2017):
Running in an emulator, that says absolutely nothing about how real hardware would react. Safest bet is setting it to 1.
@solardiz commented on GitHub (Dec 1, 2017):
Yes, core tree's
ppc64alt.hworks correctly on thisgcc110machine. (And this confirms it's normally 64-bit BE, despite of what we just saw inmsron the confused build of your ppc64 tree.)@jfoug commented on GitHub (Dec 6, 2017):
I am getting closer now (but further away in some circumstances, lol). I have fully ported ppc64.h and ppc32.h, so that on they behave like this:
on core or legacy, ppc64.h and ppc32.h will be used on non-altivec builds. ppc64alt.h and ppc32alt.h are used for altivec builds.
Then in ./configure builds, I call special functions for a 4 ppc variants (powerpc32, powerpc32le, powerpc64 and powerpc64le). There are 2 separate autoconf macros for this (one for 32 bit, and one for 64 bit), even though the additional command line options were the same. We may in the end find that different options are better for one or the other. Then if those macros detect altivec instructions, they set a CPU flag, listing HAVE_ALTIVEC. On autoconf builds, only the ppc32.h and ppc64.h are included.
So on a config build, with the HAVE_ALTIVEC flag either set or not, the ppc32.h will look like either like the 'legacy' ppc32.h (for non altivec builds), or ppc32alt.h for HAVE_ALTIVEC builds. The same goes for ppc64 header. Now, I may make some minor chagnes, and simply wrap the entire ppc32.h in a define, and if set, simply include the ppc32alt.h That might be a better solution, since then the code really is in only 1 place. NOTE, I think I will do that, right now.
But once done, I now am getting some format test failures (I was pretty sure I had all these worked out before, darn!). I will get them fixed, then move on to the 32 bit, and make sure that with/without altivec is happy and testing everything.
I will NOT be setting the SIMD_PARA_* values. Someone with real iron needs to do this. I kept increasing them, and continued to get better performance on the QEMU VM I am running under, but that is almost certainly not relative to real hardware, and just a side affect of having less overhead marshalling or something within the VM doing more of the same work.
I hope to have this working fully today.
@jfoug commented on GitHub (Dec 6, 2017):
@solardiz I have put out this PR (mostly to expose these changes so you can more easily test against real iron)
#2974
@jfoug commented on GitHub (Dec 7, 2017):
With
90313f4I believe that this port is now fully working. ppc32.h and ppc64.h are now tri purpose. On john core or Makefile.legacy build, they are non SIMD headers. On configure builds, they will be either the non-SIMD, or the SIMD build (of right machine word type), based upon JOHN_ALTIVEC define being set or not.NOTE ALTIVEC2 is not addressed.
NOTE SIMD_PARA_* values are all set to 1, and need someone with real HW to tune them properly
NOTE in configure, altivec is built, IF the compiler supports it. This would cause issues cross compiling.
NOTE there is no CPUID work done either in configure script OR in john proper. Thus the builds are 'blind', AND there is no way to build fallback CPU builds.
NOTE we handle altivec in both 32 and 64 bit builds (I had to fix the psudeo-intrinsics.h file)
NOTE code passes UBSan and ASAN (but test was on LE system). As slow as my PPC64 system is, I really do NOT want to be forced to test ASAN or UBSan. that would probably take all day per test.
TODO 1. tune SIMD_PARA_* values
TODO 2. look into CPUID code. This would be a good place to also handle the ALTIVEC2 presence.
TODO 3. add ALTIVEC2
@solardiz do we want to close this task (for all purposes, it really IS done, the rest is tuning) ?
@solardiz commented on GitHub (Dec 8, 2017):
Thanks, Jim. On gcc110:
The configure check for AltiVec based on compiler support will probably also cause issues on older or cut-down POWER architecture chips lacking AltiVec but running a compiler that supports AltiVec. This is not ideal, but OK for now. Your separate work on an option to disable SIMD could provide a workaround for this.
BTW, if you happen to have an old Intel Mac with OS X 10.5, you could use its pre-installed Rosetta for pretty fast emulation of PPC32 with AltiVec - I used just that previously. It feels roughly like a real PPC G4, so something like 600 MHz, on a 2 GHz Core 2 Duo. Way faster than QEMU. Apple's Xcode of the time was readily capable of cross-compiling to PPC with AltiVec - JtR proper still includes make targets for that.
@solardiz commented on GitHub (Dec 8, 2017):
Looks like it starts and stays in 32-bit mode. Weird. Probably I misunderstand MSR. John proper has similar MSR values, but works fine (built as linux-ppc64-altivec):
@solardiz commented on GitHub (Dec 8, 2017):
There's not a single
stqinstruction (but plenty ofstd) in my build of John proper, even though the object files and binaries are "64-bit":@solardiz commented on GitHub (Dec 8, 2017):
OK,
stqis not such a basic instruction. In POWER architecture terminology, quadword is 128-bit, and one of the changes of ISA 2.07 (not supported on these CPUs) is:"Allow lq/stq in Little-Endian Mode: Removes the restriction that the lq and stq instructions can only operate in Big-Endian mode."
However, at least per configure's detection we are in big-endian mode, so by that description I'd expect
stqto work on a CPU from just prior to that architecture revision (POWER7 instead of POWER8). But maybe not.So we probably need to look for and remove a gcc flag that enabled use of
stqfor this build.@solardiz commented on GitHub (Dec 8, 2017):
Oh, also found: "In versions of the architecture prior to 2.07, this instruction was privileged." This explains why it's failing for us - we're not in the kernel.
@solardiz commented on GitHub (Dec 8, 2017):
There's still
-mpower8-vectorgetting into Makefile, and the code still fails to build when I remove that. Jim, I might have misunderstood you - I thought you meant you implemented AltiVec1-only builds this time, without AltiVec2, but what we have is the opposite. While we may close this issue because the default build completes (albeit presumably only with a recent enough compiler to support AltiVec2), the resulting binary is partially non-working on anything pre-AltiVec2 and no other binary can currently be produced... so I'm not exactly comfortable closing this.@solardiz commented on GitHub (Dec 8, 2017):
Jim, how did you manage to make AltiVec work for me for bitslice DES in this build, given that you still enable
-mpower8-vector? Or is this just luck?Regarding MSR, I read up on it more and that only confirmed my prior understanding. So I suspect it's misreporting by gdb. Many bits in MSR have to be altered on interrupt (pages 950-951 in the 2.07 manual specify exactly which and how), but there got to be a way for the kernel to figure out the MSR value of the interrupted process. Yet maybe that info is somehow not fully available to or not used by gdb.
@jfoug commented on GitHub (Dec 8, 2017):
Ok, so that is only valid on ALTIVEC2? btw, I know very little about this CPU, I have simply been taking code/switches from Makefile.legacy and merging the ppc64.h / ppc64alt.h and then fixing compile/runtime problems I have seen in the emulator. Knowing the how/why/when of what is really happening in the iron, is over me (that is why I put out the call to get the SIMD_PARAP_* stuff done)
Ok, I add the -mpower8-vector blindly in the makefile. This was due to it being in the target for ppc in Makefile.legacy. So, what are our options here? Do we really need to wait until we get CPUID, so that I can check compile flags, and then make sure those compile flags can actually run on the iron being used?
@jfoug commented on GitHub (Dec 8, 2017):
I made no change at all. Whoever ported this code at one point may have made changes, but I have touched it not at all. I did change some of the #defines (to follow ppc[32][64]alt.h) but that is it. With those build flags, it works like a champ in QEMU. NOTE, I am hosting that env on a Haswell laptop (has AVX2), so it is possible that the emulator is allowing ALTIVEC2 instructions by converting over to AVX2
Does anyone know of a good CPUID stand along (with source) for power?
@magnumripper commented on GitHub (Dec 8, 2017):
Minor OT nitpick:
Please replace these warnings so they only appear during build and not during ./configure (the Stribog one doesn't show during configure).
@jfoug commented on GitHub (Dec 8, 2017):
I have the --enable-withoutsimd ready to go. I will finish up testing on that flag, but this one should allow a configure build on a ppc Altivec1 enabled machine (until we can figure it out). Also, the existing
make -f Makefile.legacy linux-ppcp[64]targets could also be used. Yep, Makefile.legacy is deprecated, but that dinosaur simply does not die and go away ;)That being said, I will see if there is something i can do within the QEMU environment to disable ALTIVEC2 capability, so that I can get the crashes like you are getting, and figure out proper requirements for probing for Altivec1 and for Altivec2.
But at this time, I think we hold this issue open a bit more. Yep it works fine for me. But I really hate putting it out if it can not run on things using older HW, unless we totally disable those SIMD instructions.
@jfoug commented on GitHub (Dec 8, 2017):
Still OT:
@magnumripper I saw that myself, and just have not gotten around to it.
Note, I had to do a little 'extra', to get the rawSHA*ng formats to NOT be placed into the fmt.h files when building non-simd. I have to have the arch.h files give themselves a lobotomy and be told to. so I had to add that 'do it' compile switch to the buildling lines for the fmt_.h We may want to visit how I did the new command line switch. I added a totally new one. We may want to instead drop it into CFLAGS_EX or something (which would have been picked up by the gcc lines to make the fmt_*.h)
But as for rar, I saw the warnings also, just have not gotten to them yet. IIRC, the warnings also show up for the rawSHA*_ng.c files, so the #if logic to skip warning in fmt header builds has to be added there also.
@magnumripper commented on GitHub (Dec 8, 2017):
Again OT but seriously, do not commit that until you changed it to --disable-simd. I swear I will pull your access rights to the repo 😉 😆
@jfoug commented on GitHub (Dec 8, 2017):
Imagine that. Hmm, I got feedback I was needing, and nothing bad listed, 'cept my easter-egg ;)
@solardiz commented on GitHub (Dec 8, 2017):
-mpower8-vectorisn't in Makefile of JtR proper, nor in Makefile.legacy in jumbo. I suggest you try dropping it, see the resulting build errors from missing the AltiVec2 intrinsics (SIMD 64-bit adds, I think), and rework that code not to require those intrinsics when building without that option. The result will be a build working on AltiVec1, even though it would probably run a bit slower than we otherwise could on a machine capable of AltiVec2.@jfoug commented on GitHub (Dec 8, 2017):
hmm, If i did not get -mpower8-vector from the makefile/makefile.legacy, i wonder where the F i got it from ???
I will do some additional work with and without it, and hopefully we can get some CPUID stuff addressed also.
@jfoug commented on GitHub (Dec 8, 2017):
I have found this code, BUT it only tests for existance of ALTIVEC. It does not list how to test for extension 2
http://freevec.org/function/altivec_runtime_detection_linux
http://www.freehackers.org/thomas/2011/05/13/how-to-detect-altivec-availability-on-linuxppc-at-runtime/
If we use code like this, how should we attribute it?
@solardiz Please test this program (I wrote it from the code above) and run this on the gcc #10 and post the results.
Running on my QEMU, I get this:
This is probably as close to a CPUID we will be able to get for ppc
@solardiz commented on GitHub (Dec 8, 2017):
I was not specifically looking for it, but per my reading of the 2.07 arch manual earlier today it appears that some bits in MSR reflect whether the current thread can use VSX or not, etc. So maybe look in there and try that? It'd be one inline asm instruction to extract MSR into a variable.
@solardiz commented on GitHub (Dec 8, 2017):
@jfoug commented on GitHub (Dec 8, 2017):
Ok, I think this likely is what i need to look for:
I can write a simple probe function in configure, that checks for that bit. If not set, then no ALTIVEC is used. I actually do not know all of the changed needed is pseudo_intrinsics.h to get this to compile/work for ALTIVEC1 Whoever ported the only did so for AltiVEC2 instruction capable machines. So for now, I will limit to that usage, and that is the best I can do.
@jfoug commented on GitHub (Dec 8, 2017):
Damn, I see your reply now, and it has VSX :( I will look for other items . I NOTE that a LOT of the HWCAP2 features are missing. Could this be VEC_CRYPTO ? Or ARCH_2_07 ?
@solardiz commented on GitHub (Dec 8, 2017):
I think we don't need nor use VSX ("vector-scalar floating-point instructions" per Wikipedia). We need and use PPC_FEATURE_HAS_ALTIVEC and with the current code also PPC_FEATURE2_ARCH_2_07 (implies AltiVec2). If you can't (conditionally) remove the dependency on AltiVec2, then perhaps just check for PPC_FEATURE2_ARCH_2_07. You can drop the
-mvsx, although it probably doesn't matter (its support is implied with 2.07 anyway).@jfoug commented on GitHub (Dec 8, 2017):
We absolutely MUST use VSX with the current written code:
Without SVX, we can not do any 64 bit variable vectors
From https://gcc.gnu.org/onlinedocs/gcc-4.5.3/gcc/PowerPC-AltiVec_002fVSX-Built_002din-Functions.html
The code as currently written in pseudo_intrins will only compile properly if -msvx and -mpower8vector are both set. I do not know how to make changes yet, for any other mode.
So what i need to do, is to find what minimal CPUID type bits are required for the existing logic, and only enable it (at configure time, and we likely should put same check into john proper), and if those flags are not set, do not use altivec.
Then someone with more knowledge can later add altivec for more situations.
Ok, is the ARCH_2_07 the flag I need to look for that is lacking on the gcc build box in question? If so, then I can check for altivec bit, and the arch_207 bit. Then later if we get changed code, and can deal with v1 altivec, we can go with just altivec bit and still run if the 207 bit is lacking.
@jfoug commented on GitHub (Dec 9, 2017):
As for VSX, I mean the -mvsx If that flag is not there, then the 64 bit vectors fail. I think we need all 3 compiler flags and the code as it is today.
I have a simple c cpuid that I will compile within configure, it will only add ALTIVEC code (the code we have today), if all 3 of those bits are seen in the feature[2] flags. Then someone can figure out how to get the Altivec code running without the VSX/ALTIVEC2 extensions, and once we have that, we can fall back to using that code, IF the ALTIVEC feature flag is set. If that flag is not set, we simply fall back to using -m64/-32 only and build a non-SIMD product.
@jfoug commented on GitHub (Dec 9, 2017):
@solardiz Please try
56016ced8(and77fa28b26since I forgot to autoconf prior to checking it in) on gcc-10 when you get a chance. It should build, but not include the AltiVec codes, since as written, it will not work on that machine.It works fine on my QEMU, since it can handle the ALTIVEC2 stuff.
Once we are happy here, someone can look at what it would take to get pseudo_intrinsics.h working for ALTIVEC1. When we are there, I can make changes to configure, so that it will inform the build on which flavor of SIMD to use, so that it works faster, BUT does not cause crashes.
It may be that things like x86.S already are written to work this way (or whereever the DES crap is for SIMD). howeever, out intrisics currently do NOT work. They only handle code which can deal with -msvx and -power8vector code (i.e. ALTIVEC2 I believe).
But the patch here, reads from /proc/self/auvx and will only allow ALTIVEC builds is all required attributes are found.
@jfoug commented on GitHub (Dec 9, 2017):
@solardiz hold up a bit. i found logic problems in the script. part of the fun of working on the same section of code for 2 different tasks (ppc port and no-simd configure logic)
@jfoug commented on GitHub (Dec 9, 2017):
heres a fun way to view the HW on the PPC ;)
@jfoug commented on GitHub (Dec 9, 2017):
@solardiz Please try the lastest bleeding-jumbo. This should build fine, and run fine on the gcc machine.
ALTIVEC should be disabled on that box.
Once we know that it works properly there, we can close this topic. We should re-open a topic to port to ALTIVEC1 SIMD, if that is desired. That is past my current skill set.
@jfoug commented on GitHub (Dec 9, 2017):
@solardiz
Please run this on the GCC box-10, and list results:
I believe we have to code for these situations.
if ./ppc_cpuid PPC_FEATURE2_ARCH_2_07 returns 1.
set gcc flags -maltivec -msvx -mpower8-vector -DJOHN_WITH_ALTIVEC2
if ./ppc_cpuid PPC_FEATURE2_ARCH_2_07 returns 0. but both PPC_FEATURE_HAS_ALTIVEC and PPC_FEATURE_HAS_VSX return 1 (i.e. altivec v1 with VSX, vsx is required for long/long long data vector type)
set gcc flags -maltivec -msvx
Then we need to get the code working without the -mpower8-vector, and only enable that (current code we have today), with the JOHN_WITH_ALTIVEC2 define set. We will use that switch to chose the code.
I can easily code the plumbing for this, with the exception of getting the code working 'without' power8-vector. I will give it a shot, but I am not sure I am capable of getting that part done.
@jfoug commented on GitHub (Dec 9, 2017):
I have found this type problem on other warez also. It looks like the *add_epi64() type is NOT compatible with AltiVec, prior to POWER8 level. and if the iron does not have the 2_07 level
(power 8), you may be able to compile the code, BUT it is going to crash :(https://github.com/IvantheDugtrio/veclib/blob/master/vec128intlib.c
If someone can show how to write a compatible vadd_epi64() for us, I will certainly use it. Until then, john will only be ALTIVEC SIMD comapatible with Power8 or above.
I am going to see if the SIMD code (minus the simd-intrinsics logic is compatible with <POWER8 hardware. I am not sure i can easily get a build to add SIMD to core john, but have the simd-intrinsics.c code NOT be used. It may simply be better to scrap work to get SIMD for altivec on <POWER8, unless someone is able to provide a replacement for vadd_epi64()
@solardiz commented on GitHub (Dec 9, 2017):
Somehow the machine is unreachable now. As I recall, I was able to build your previous revision of bleeding-jumbo (which I commented on in here) without
-mvsx, but with-mpower8-vector. Probably the latter implies the former? That would make sense to me as-mpower8-vectormeans ISA 2.07, which includes VSX too.As to builds for AltiVec1, when we're able to make those again, perhaps they wouldn't require VSX because we'd have to avoid 64-bit integer types within SIMD when we're on pre-2.07 (pre-POWER8) anyway.
And yes, you're right - we need to implement SIMD 64-bit integer add with plain AltiVec intrinsics when we don't have that as an intrinsic. I think it shouldn't be that hard: do an equivalent 32-bit add and then add 1 to the odd-numbered 32-bit elements if the corresponding even-numbered element is smaller than any of the two operands. There's probably a SIMD comparison intrinsic which could be used to get 32-bit all 0's or all 1's, then we shift that by 32 bits to the left and 32-bit SIMD add it again. That's probably ~4 intrinsics (and instructions) total to replace this missing SIMD 64-bit add.
@solardiz commented on GitHub (Dec 9, 2017):
The problem with the approach at hardware feature detection you've taken so far is that it's Linux-specific. Ideally, we'd also support AIX, older OS X, and maybe *BSD's.
@jfoug commented on GitHub (Dec 9, 2017):
Do those not use ELF ?
@jfoug commented on GitHub (Dec 9, 2017):
That was really the ONLY code I was able to find on ALTIVEC detection short of catching exceptions.
Now we 'could' perform the excpetion checking like i had done in the past for SSE* logic. Simply write a tiny stub program that exits with (0) return code. then build and run. If the return is 0, the code executed without exception. Even though I found some 'do not do it that way' comments about exception probing, I think that doing this with totally stand alone processes within the configure testing would be an option. It would not be ideal for a cpuid INSIDE running john. The comments made about hidden gotchas were when code would use the exception model, but not clean things up well, it could cause problems later on in the run. BUT within configure, I do not see that problem. The stub process will run or not. If not, we know that THIS machine can not handle the code. We would still need some way to do runtime cpuid checks inside john.
@solardiz commented on GitHub (Dec 9, 2017):
This varies, but I was referring to the dependency on
/proc/self/auxv, which is part of Linux procfs and is unlikely to be available on other systems except possibly through Linux "emulation" (or compatibility layer) where it might be available (I'd guess on some of the *BSD's, but I don't really know).@solardiz commented on GitHub (Dec 9, 2017):
Have you looked into my idea of checking MSR bits?
@jfoug commented on GitHub (Dec 9, 2017):
I no longer use /proc/self/auvx I walk the env pointer to the end, and then walk a dual-long array from there.
Same data as in the /proc/self/auvx, but now is ELF layout dependent.\
This is the new code. done inside main() It is the same code as before, just gets the data from the running process, not from a file in the /proc/self/* part of the OS.
NOTE, this code DOES require these headers, however:
So from the directory name, the AT_HWCAP (and other AT_* flags), 'may' be Linux special logic. The <asm/cputable.h> appears to be ppc specific. I do not see that file on other systems. NOTE, the program DOES have this to start with, so it will ONLY build on a PPC system:
@jfoug commented on GitHub (Dec 9, 2017):
No I have not done so yet.
@jfoug commented on GitHub (Dec 9, 2017):
Here is what I am using to 'find' this data. now for processing, the defines for the type of data IS in a </linux/*> header, so if it is not linux, we may have to find it in other ways. BUT I think this appears to be how an ELF[64] process is laid out in memory.
This was a page I used to change the logic.
http://articles.manugarg.com/aboutelfauxiliaryvectors
@solardiz commented on GitHub (Dec 9, 2017):
I've been using https://static2.rpteng.com/TALOS/documentation/PowerISA_V2.07_PUBLIC.pdf (very long and detailed), but I can't find the table with MSR bits in there anymore. ;-(
@solardiz commented on GitHub (Dec 9, 2017):
BTW, there's also a document on ISA 3.0 from Nov 2015, and somehow it's down to ~1200 pages from 2.07's ~1500 pages. Overall, it looks similar. And I also can't find that table in there, although I recall seeing it in the 2.07 manual previously.
@jfoug commented on GitHub (Dec 9, 2017):
From this file:
#include <linux/auxvec.h>I only use these values, and they were the same on Fedora linux (running in VM), and the Debian running PCC64 in QEUM. But again, Linux vs Linux. I think I can get to a OpenBSD machine, and test (simply dumping the data, not trying to interpret.On all systems, the first 17 were set (actually, there were more than 17 now). then there are > 31. I saw a few of them, like 32, but i am not using them right now.
AT_NULL is 0 (duh)
AT_HWCAP is 16
AT_HWCAP2 is 26
here is what was on PPC64 (only defines left). there are actually 2 files. <linux/auxvec.h> and <asm/auxvec.h> Same was seen on the Intel side NOTE, the lower number (in linux/auxvec.h) are the same without regard to the OS. it looks like each OS gets it's own unique enumerations put int <asm/auxvec.h> and should not be used, without KNOWING we are building for that OS.
I will dig into the link you list. NOTE, this is all still someone POC, until we find a better way to do it ;)
@jfoug commented on GitHub (Dec 9, 2017):
ISA 3.0 is not in HW yet, correct? Isn't that for POWER9
@solardiz commented on GitHub (Dec 9, 2017):
Yes, ISA 3.0 is POWER9, but I think POWER9 is already starting to appear in hardware.
@jfoug commented on GitHub (Dec 9, 2017):
Ok as for POWER9, all I had found was 'future hardware', but that does not mean it is not already out.
Btw, isnt reading from MSR a privileged operation?
@solardiz commented on GitHub (Dec 9, 2017):
ISA 2.07 page 857-858 "3.2.1 Machine State Register" bits 38 (VEC), 40 (VSX). I don't know if reading from MSR is privileged or not.
@jfoug commented on GitHub (Dec 9, 2017):
There is a PVR register. It contains version of the processor (2 16 bit values). It can be read, but requires privilege.
www.csit-sun.pub.ro/~cpop/Documentatie_SMP/...PowerPC/PowerPc/.../pemch2.pdf
@ghost commented on GitHub (Dec 10, 2017):
Just taking notes. After the recent changes
From:
To:
@solardiz commented on GitHub (Dec 10, 2017):
Jim, have you found out if the 64-bit MSR can be read by user code or not?
While your parsing of the auxv vector might work on some non-Linux, this won't even build on non-Linux:
@jfoug commented on GitHub (Dec 10, 2017):
yes @solardiz I do understand the implications, and it is very likely that reading the auxvec data is not going to be compatible outside of Linux.
@jfoug commented on GitHub (Dec 12, 2017):
@claudioandre please try again, after
2de66d38dIn that change to the ppc_cpuid.c, I use a define, looking for gnu_linux. If it finds gnu_linux, then the code should compile and be able to walk the auxv array. Otherwise, it simply returns '1' for each of the flags.So on non linux systems it will use AlitVEC if the compiler supports it. If that build fails, the user will have to do a configure forcing SIMD usage off, using the --simd-disable I do not see any other way, until we find a CPUID that works fully and properly and is portable to all PPC chips and OS's.
@jfoug commented on GitHub (Dec 12, 2017):
@claudioandre I see there was a bug in original submission. But with this change, how is this working on your PPC OpenBSD box, which had problems after this ppc_cpuid.c file was added to the configure script?
@ghost commented on GitHub (Dec 12, 2017):
Not yet fully tested (latest patch SIMD problems). Anyway:
BTW: are you guys sure NEON configure detection is working?
@jfoug commented on GitHub (Dec 12, 2017):
I am pretty sure the NEON code worked on my RPI3 last winter
@solardiz commented on GitHub (Dec 12, 2017):
Testing current bleeding-jumbo on gcc110:
but the configure nevertheless succeeds:
Build is OK, too:
Now running tests.
@solardiz commented on GitHub (Dec 12, 2017):
@solardiz commented on GitHub (Dec 12, 2017):
The same 8 fail with OMP_NUM_THREADS=1
@jfoug commented on GitHub (Dec 12, 2017):
That is a bug in the shell if logic, and likely the version or which actual shell is being used. I may simply have to split up the if block (testing 4 items), into 4 ifs.
But the failures concern me. I was starting on a path down porting wpapsk to BE, but I will put that asside for a bit, and check this out. NOTE, @claudioandre fixed the 2 warnings already in the ppc_cpuid.c file, so those are handled.
@solardiz commented on GitHub (Dec 12, 2017):
OMP_NUM_THREADS=1 ./john -test-full=0doesn't give more failures, but it gives different info:@solardiz commented on GitHub (Dec 12, 2017):
The line is:
I don't see it as necessarily problematic - it's just weird. But it should probably be:
So we invoke
testjust once, not 3 times.@jfoug commented on GitHub (Dec 12, 2017):
The test-full results for some things, gives results which do not translate back to the exact failure string like the -test=x does. This probably should be an issue on its own.
It may be that within -test-full mode, we first perform a -test=0 call (emulate) prior to doing the extra work of test-full. That would flush out the errors more properly (easier to associate back to the offending hash), and it would do the -test-full So then there would be no reason to do -test= and -test-full= The -test-full should simply cover all bases.
@solardiz commented on GitHub (Dec 12, 2017):
OMP_NUM_THREADS=60 ./john -test-full=0:@jfoug commented on GitHub (Dec 12, 2017):
Understood, but when I did that, I was getting the error you are listing (test: too many arguments). That is why I reverted back to 4 independent test statements and shell booleans
@solardiz commented on GitHub (Dec 12, 2017):
In the non-Linux portion of
ppc_cpuid.c, you assume thatargv[1]is non-NULL, and will segfault if it is. Intentional?@jfoug commented on GitHub (Dec 12, 2017):
No, not intentional. The program is never really written to be used, on non-linux, outside of the controlled usage in configure. It gives ZERO information. But yes, that crash is not what was expected.
All that I wanted to do, is to NOT return a failure, or have a compiler failure on a non-linux system. It simply says that everything is there, thus canceling out the cpuid logic, and building SIMD if the compiler supports doing so. Then on those non-linux systems if the build fails (i.e. SIMD support is not new enough) the user will have to run configure adding the --disable-simd flag. That flag totally avoids all the SIMD checking within the m4/jtr_ppc.m4 macros.
@solardiz commented on GitHub (Dec 12, 2017):
The problem is:
That's multiple arguments to the outer command:
The fix is to add more double-quotes:
@jfoug commented on GitHub (Dec 12, 2017):
Ok, can fix.
Can you re-run with the corrected configure file ?
It should build a Makefile that will not function (contains the ALTIVEC logic that we know fails), IF this is a non-linux system. or it should have the ALTIVEC stuff stripped out if this is a Linux build.
I know the error of a bad test clause, but am not sure what code was skipped. I will change the jtr_ppc.m4 to have quotes around the shell runs.
@jfoug commented on GitHub (Dec 12, 2017):
Ok, I have a non-simd build, and am setting the failures you are seeing (good). So I can set about getting these non-simd failures fixed.
This may end up being some alter_endanity code, that I had wrapped with (SIMD_COEF_32) or something, recently. which really should have been for all BE. The changes should not be too hard, since we had all of these working on BE until recent changes for the SIMD porting.
@solardiz commented on GitHub (Dec 12, 2017):
Jim, I guess you meant
<= 1there (it is possible to invoke a program withargc == 0, even if that's tricky) and the message looks like it's missing a word.@solardiz commented on GitHub (Dec 12, 2017):
This works for me:
@jfoug commented on GitHub (Dec 14, 2017):
I believe this topic is now complete, yes?
There could be another topic opened for better cpuid, and for support of AltiVec1 (or POWER7?) instruction handling. But in all, all formats are ported to BE both SIMD and nonSIMD, the configure script fully handles ppc64 and 32 (both BE/LE). AltiVec (POWER8) is fully functioning and. So IMHO, this topic is completed, and i am closing it.
@solardiz commented on GitHub (Dec 14, 2017):
I've just confirmed that the build still works (without SIMD on the POWER7 box) and tests now pass (except for 6 errors about unify case with --test-full=1, but that's a separate issue). Thanks, Jim!
@jfoug commented on GitHub (Dec 14, 2017):
The case issues should be addressed shortly, and yes, separate issue. The biggest deal (and why we had a --test-full=1) was that the logic in formats.c for doing that test was buggy, and that is why it was moved outside of the --test-full=0 logic (which is used in the build bots). Now, i have finally gotten that logic fixed, found 2 formats which really did have the bug (and fixed them). So if that is an issue here, on a build not updated to that version, and that is the ONLY issue (other than not handling POWER7 Altivec), then all looks good.
Btw, I will have an update to cpu_id.c (may have pushed it already) that handles argc==0, and returns a more clear error string on non-Linux systems. But that should not be any impact to the configure. the same logic works when used the way configure uses it.