> > 2G: fixed 2F without the branch prediction bug. I am told the recent > > Yeeloong and Fuloong are fit with 2G processors. I am not even sure > > these can be told apart in software, as 2G supposedly reports itself as > > a 2F level. > > Does anybody have a piece of assembly code that triggers the branch > prediction bug reliably? I'd like to see if it breaks my machine.
This errata is only lethal to kernel code. When it triggers in userland, it causes memory access faults (TLB misses) which cause the branch prediction logic to abort the bogus prediction. Therefore, only the kernel needs to be modified to not risk triggering the bug. This is done by two counter-measures: 1/ The kernel is built with the -Wa,-mfix-loongson2f-btb option, which tells the assembler to insert explicit instructions to invalidate the branch prediction cache before every `jr' instruction. 2/ The kernel exception handlers perform explicit branch prediction cache invalidation on kernel<->userland execution boundaries. If you really have some time to lose on this, you can build yourself a workaround-free kernel by following these steps: 1/ edit sys/arch/loongson/conf/Makefile.loongson to remove -Wa,-mfix-loongson2f-btb from CMACHFLAGS 2/ edit sys/arch/mips64/include/loongson2.h and change the value of COP_0_DIAG_BTB_CLEAR from 0x02 to 0 3/ config(8) a new kernel, make clean, make 4/ boot new kernel 5/ run "openssl speed -elapsed" 6/ go on a coffe break 7/ notice the machine is frozen when coming back. 8/ cycle power, restore backup kernel Miod

