Page MenuHomeFreeBSD

Enable use of ofwcons for early debug
ClosedPublic

Authored by luporl on Jun 14 2019, 7:05 PM.
Referenced Files
Unknown Object (File)
Tue, Nov 5, 3:55 PM
Unknown Object (File)
Oct 1 2024, 1:28 PM
Unknown Object (File)
Sep 30 2024, 11:32 PM
Unknown Object (File)
Sep 27 2024, 4:19 AM
Unknown Object (File)
Sep 11 2024, 9:26 PM
Unknown Object (File)
Sep 11 2024, 9:26 PM
Unknown Object (File)
Sep 8 2024, 10:18 PM
Unknown Object (File)
Sep 4 2024, 10:45 PM

Details

Summary

This change enables the use of OpenFirmware Console (ofwcons), even when VGA is available, allowing early kernel messages to be seen, that is important in case of crashes before VGA console initialization.

This is specially useful in virtualized environments, where the user/developer doesn't have full control of the virtualization engine (e.g. OpenStack).

In order to use ofwcons when a (virtual) VGA display and USB keyboard are enabled, OFW FB must be disabled, to avoid its selection by vt. To this end, the following tunable was added:
hw.ofwfb.disable=1

Because ofwcons relies on OF_read and OF_write, FDT must also be disabled for it to work:
unset usefdt

With the settings above, output will start to appear on the console, but will cause a panic after the kernel starts using the console mutex, that is of spin type, that conflicts with ofw_real sleepable mutex. To handle this, a new, optional, spin mutex is used in ofw_real, to guard all operations, except for the bounce memory allocation, that can sleep. The use of this spin mutex is enabled by the following tunable:
machdep.ofw.mtx_spin=1

With the settings above, the system is able to boot up to the login/single user shell. However, console input doesn't work.
Also, if a panic occurs before VGA/USB keyboard are initialized, the user won't be able to use KDB to investigate the issue.

The problem is that ofwcons input stops working after the kernel calls OFW quiesce. To skip this call, the following tunable was added:
debug.quiesce_ofw=0

Note that not calling OFW quiesce is not recommended, as conflicts between kernel and OFW trying to control the hardware may occur.
Nevertheless, this can still be useful for debugging, if used with care.

In a standard QEMU/PPC64/pseries configuration, xhci and vscsi must be disabled, to avoid conflicts with OFW when quiesce is not called:
hint.xhci.0.disabled=1
hint.vscsi.0.disabled=1

And then finally ofwcons can be used, both for output as well as input.

Summarizing, to enable the use of ofwcons, the following settings are needed:

(output only):
unset usefdt
hw.ofwfb.disable=1 (new)
machdep.ofw.mtx_spin=1 (new)

(input and output)
/* output only settings */
debug.quiesce_ofw=0 (new)
hint.xhci.0.disabled=1 (this can vary)
hint.vscsi.0.disabled=1 (this can vary)

All new tunables introduced by this change are off by default, so that there should be no behavior changes if they are not manually specified or added to loader.conf.

Diff Detail

Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 24851
Build 23600: arc lint + arc unit

Event Timeline

I like the idea, it beats having to compile a custom kernel. This is also relevant on some of my macintoshes, where the keyboard works in OFW but not in the kernel debugger when I have an early crash.

I like the concept overall. A couple nits. Also, can you document this somewhere, maybe in of_real.c?

sys/powerpc/ofw/ofw_real.c
344

I think this should be a "machdep." tunable, now "hw.".

sys/powerpc/pseries/platform_chrp.c
173

I would name this "debug.quiesce_ofw" or similar, to enforce the fact that this is intended for debugging only.

  • Address review's comments
  • Fixed an issue in ofw_real_mtx_unlock()
This revision is now accepted and ready to land.Dec 8 2019, 9:07 PM
This revision was automatically updated to reflect the committed changes.