[SeaBIOS] [PATCH] shadow: set code segment to high rom region when enabling RAM
kevin at koconnor.net
Fri Dec 14 19:45:16 CET 2018
On Fri, Dec 14, 2018 at 01:08:46PM +0300, Евгений Яковлев wrote:
> I think we have a problem right now if during emulation first pci config
> write in __make_bios_writeable_intel we decide to issue qmp system_reset.
> Based on what i could gather from crashed instances we have something like
> 1. seabios issues pci_config_writel to reprogram 0xF0000-0xFFFFF and 0xD0000
> - 0xC7FFF. VCPU thread exits into qemu usermode to emulate this.
> 2. At this time we issue system_reset through qmp. When VCPU thread decided
> to return to KVM it releases BQL, main event loop sees system_reset, stops
> cpus and calls reset handlers. So, we're doing a soft reset.
> 3. Q35 ICH9 reset emulation does not reset PAMs to default values
> 4. Upon re-entering reset vector seabios checks for PAM0 & 0x10 and decides
> that we have enabled ram previously and does not jump to
> __make_bios_writeable_intel in high memory relying on the fact that code is
> in low memory already. However this assumption only holds true for 0xC8FFFF
> - 0xEFFFF because we didn't have a chance to reprogram those PAMs during
> previous runs. We also didn't memcpy anything previously, so we're now may
> execute junk from F-segment.
> What do you think about this scenario? I would be happy to fix this but i
> would be happy to get your advise on how to proceed and if all of my
> assumptions are correct.
Interesting. So, to summarize, there is a race condition with a reset
signal if it arrives between the point SeaBIOS sets the pam registers
and completes its memcpy.
Not sure how to best address that. Is it even possible to close that
race? (That is, if QEMU doesn't reset the pam registers, could the
reboot immediately start execution at junk f-segment code?)
Is this only a problem if the reset signal occurs within the first few
milliseconds of the the very first boot?
> Also, maybe original fix is still useful since we're not relying on all
> jumps/calls to be relative anymore?
My personal opinion is that the x86 segment/offset stuff is so arcane
that it's best to avoid it. I don't think gcc will (in practice) emit
an absolute function call.
More information about the SeaBIOS