qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

finding all the places in an AddressSpace that alias a specific address


From: Peter Maydell
Subject: finding all the places in an AddressSpace that alias a specific address
Date: Fri, 12 Mar 2021 16:05:58 +0000

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]