Bug 211204 - loading sysutils/memtest86+ reboots the system
Summary: loading sysutils/memtest86+ reboots the system
Status: New
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: amd64 Any
: --- Affects Some People
Assignee: freebsd-ports-bugs (Nobody)
Depends on:
Reported: 2016-07-18 16:26 UTC by bourne.identity@hotmail.com
Modified: 2020-10-19 07:23 UTC (History)
5 users (show)

See Also:
linimon: maintainer-feedback? (avg)

attempt to fix loading via freebsd boot chain (10.36 KB, patch)
2017-05-18 11:48 UTC, Andriy Gapon
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description bourne.identity@hotmail.com 2016-07-18 16:26:35 UTC
I am using FreeBSD 10.2 amd64. On my earlier i386 installation, memtest86+ ran perfectly. I recently upgraded my hardware, moving from EVM 2GB DDR3 RAM to Hynix (Hyundai) 8 GB DDR3 RAM, after which I moved to FreeBSD 10.2 amd64. When at the FreeBSD boot loader prompt, I issue the commands :

1) unload    # ok till here
2) load /boot/opt/memtest86+    # problem : the system simply does dead/reboots

Incidentally running memtest86 (not memtest86+) from a bootable CD runs on the system perfectly, producing zero errors in 2 passes secured in about 75 minutes.

I don't think it is important, but just in case it is needed, my system uses MBR partitioning with just 1 partition ada0s4a for the root partition, which holds all data.
Comment 1 Alexey Dokuchaev freebsd_committer 2017-02-28 16:43:32 UTC
I've observed similar behavior of the port: previously (on 8.4/i386) it was working as intended (with/via BOOT option), but on recent -CURRENT/amd64 it resulted in infinite reboot cycle.
Comment 2 Andriy Gapon freebsd_committer 2017-05-18 11:48:50 UTC
Created attachment 182690 [details]
attempt to fix loading via freebsd boot chain

I finally found some time to look into this and made a few interesting discoveries.

Most importantly, the current version of memtest86+, unlike all previous
versions, does not relocate itself to the low memory at the very start.  That,
of course, causes a problem when it switches to the real mode needed for making
BIOS calls.  That's why it crashed in mem_size -> query_pcbios.
I've added a patch to add that early relocation (patch-main.c).
I've changed the initial load address to a higher value as well
(patch-memtest.lds).  That way there should be a smaller chance of interfering
with the loader.

Also, it seems that the stack size was too small, at least on my system, and
some global variables got corrupted after the BIOS calls.  I've added a patch
for that too (patch-test.h).

Additionally I've fixed the SMP detection code for systems with older ACPI
versions (patch-smp.c).

Finally, I have fixed a couple of problems in the code, so that it can be
compiled with newer GCC versions (4.9.x, 5.x) (patch-test.c, patch-lib.c,
patch-io.h).  Unfortunately, resulting binaries do not work correctly, so the
compiler is still 4.8.  I suspect that the newer compilers do progressively more
aggressive optimizations and that results in the bad code because of some quite
sloppy inline assembly (incorrect constraints and clobber lists) in test.c.

Could you please test it and see if it works?
Thank you!
Comment 3 Alexey Dokuchaev freebsd_committer 2017-05-18 18:08:32 UTC
Thanks for looking into this Andriy!  I've applied the patch and rebuilt the port, and tried to load it here on my amd64 laptop, but it did not work ("don't know how to load module").  I've rebooted back to FreeBSD and tried to load it with kldload(8):

> kldload: /boot/opt/memtest86+: Unsupported file layout
Am I missing something here?  I've reverted the port to its current state but it did not change the described behavior I'm seeing.
Comment 4 Andriy Gapon freebsd_committer 2017-05-18 18:39:47 UTC
(In reply to Alexey Dokuchaev from comment #3)
This binary is obviously not a FreeBSD kernel module, so it can't be loaded with kldload.  However, loader(8) should be to load it as it is a kind of a kernel.  If you have old loader config files, then you might need to issue 'unload' first to unload the FreeBSD kernel.  I think that this information is in pkg-message.
Comment 5 sigsys 2018-04-11 02:34:31 UTC
(In reply to Andriy Gapon from comment #2)

Hi Andriy.

Damn this sounds complicated.

I had the exact same problem with sysutils/memtest86+ and gave your patch a try. Now instead of rebooting after the "load" command, I get a black screen lock up after the "boot" command (Ctrl+Alt+Del doesn't work, can't toggle the keyboard LEDs). So that's progress. Thanks for trying to fix it.

FreeBSD 11.1-STABLE #1 r330969M
CPU: AMD Phenom(tm) 9550 Quad-Core Processor (2199.21-MHz K8-class CPU)

Same version of memtest86+ (5.01) works on this computer when booting it directly from a USB drive BTW.