* finding all the places in an AddressSpace that alias a specific address
@ 2021-03-12 16:05 Peter Maydell
2021-03-22 18:51 ` Paolo Bonzini
0 siblings, 1 reply; 2+ messages in thread
From: Peter Maydell @ 2021-03-12 16:05 UTC (permalink / raw)
To: QEMU Developers; +Cc: Paolo Bonzini
I'm trying to fix an issue in Arm M-profile, where on reset the
CPU is supposed to load its initial PC and SP from a vector table.
This goes wrong if the vector table is in a guest image file (loaded
by the rom-blob loader) at address X which is not the same as the vector
table address Y but which is an aliased view of the same underlying RAM
(ie accesses to both X and Y go to the same real guest RAM).
Really the problem here is a reset-ordering one: the CPU reset code
runs before the hw/core/loader.c code has written the guest image
files to RAM. We currently try to work around that with:
rom = rom_ptr(vecbase, 8);
if (rom) {
/* Address zero is covered by ROM which hasn't yet been
* copied into physical memory.
*/
initial_msp = ldl_p(rom);
initial_pc = ldl_p(rom + 4);
} else {
/* Address zero not covered by a ROM blob, or the ROM blob
* is in non-modifiable memory and this is a second reset after
* it got copied into memory. In the latter case, rom_ptr
* will return a NULL pointer and we should use ldl_phys instead.
*/
initial_msp = ldl_phys(s->as, vecbase);
initial_pc = ldl_phys(s->as, vecbase + 4);
}
But the rom_ptr() check only matches if the ROM blob
is at the actual same guest address as the vector table base.
Arguably what we should try to sort out is the reset-ordering problem,
but that's a big job. I thought maybe we could for the moment at least
make the workaround we have today handle aliases.
For that I would need to find all the addresses in an AddressSpace
that alias vecbase, so that we can call rom_ptr() on all of them.
I think something like this would work:
hwaddr xlat, len;
RCU_READ_LOCK_GUARD();
FlatView *fv = address_space_to_flatview(s->as);
MemoryRegion *main_mr = flatview_translate(fv, vecbase, &xlat, &len,
false, MEMTXATTRS_UNSPECIFIED);
flatview_for_each_range(fv, callback_fn, ...);
where callback_fn() does:
if (mr != main_mr) {
return;
}
do arithmetic with flatview range start and len, etc to figure
out the overall address in the AS corresponding to vecbase
rom = rom_ptr(that_addr);
...
Does this seem like it would work ? Is there a nicer way ?
thanks
-- PMM
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: finding all the places in an AddressSpace that alias a specific address
2021-03-12 16:05 finding all the places in an AddressSpace that alias a specific address Peter Maydell
@ 2021-03-22 18:51 ` Paolo Bonzini
0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2021-03-22 18:51 UTC (permalink / raw)
To: Peter Maydell, QEMU Developers
On 12/03/21 17:05, Peter Maydell wrote:
> For that I would need to find all the addresses in an AddressSpace
> that alias vecbase, so that we can call rom_ptr() on all of them.
> I think something like this would work:
>
> hwaddr xlat, len;
> RCU_READ_LOCK_GUARD();
> FlatView *fv = address_space_to_flatview(s->as);
> MemoryRegion *main_mr = flatview_translate(fv, vecbase, &xlat, &len,
> false, MEMTXATTRS_UNSPECIFIED);
> flatview_for_each_range(fv, callback_fn, ...);
>
> where callback_fn() does:
> if (mr != main_mr) {
> return;
> }
> do arithmetic with flatview range start and len, etc to figure
> out the overall address in the AS corresponding to vecbase
> rom = rom_ptr(that_addr);
> ...
>
> Does this seem like it would work ? Is there a nicer way ?
Yes, it should work. I can't think of a nicer way, except of course
wrapping it in a nicer that hides the walk.
For what it's worth, it wouldn't be a problem to make FlatRange public
and export FOR_EACH_FLAT_RANGE as well.
Paolo
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-03-22 18:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-12 16:05 finding all the places in an AddressSpace that alias a specific address Peter Maydell
2021-03-22 18:51 ` Paolo Bonzini
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).