On Tue, May 20, 2025 at 03:53:10PM +0200, Paolo Bonzini wrote:
> On 5/20/25 13:30, Magnus Kulke wrote:
> > Qemu maps regions of userland multiple times into the guest. The MSHV
> > kernel driver detects those overlapping regions and rejects those
> > mappings.
> 
> Can you explain what you see?  QEMU doesn't do that, just look at KVM code:

Hey Paolo, I appreciate that you took a look so swiftly, we'll try to
accomodate and post a fixed series up soon.

I think what I am referring to is a "memory region alias", e.g. in this
mtree output (machine q35 + seabios):

00000000000e0000-00000000000fffff (prio 1, rom): alias isa-bios @pc.bios 
0000000000020000-000000000003ffff
...
00000000fffc0000-00000000ffffffff (prio 0, rom): pc.bios

parts of the bios are mapped into different regions on the guest. a
code path for such a mapping that is refused by the MSHV kernel driver
would start in hw/i386/pc.c:894

memory_region_init_alias(ram_below_4g, NULL, "ram-below-4g", machine->ram,
                         0, x86ms->below_4g_mem_size);
memory_region_add_subregion(system_memory, 0, ram_below_4g);

eventually that ends up in a hv call that registers a region, but the
userspace_addr of pc.bios is already registered, so the mapping of an alias
slice is rejected by the kernel driver.

best,

magnus

> 
> static bool kvm_check_memslot_overlap(struct kvm_memslots *slots, int id,
>                                       gfn_t start, gfn_t end)
> {
>         struct kvm_memslot_iter iter;
> 
>         kvm_for_each_memslot_in_gfn_range(&iter, slots, start, end) {
>                 if (iter.slot->id != id)
>                         return true;
>         }
> 
>         return false;
> }
> 
> ...
> 
>         if ((change == KVM_MR_CREATE || change == KVM_MR_MOVE) &&
>             kvm_check_memslot_overlap(slots, id, base_gfn, base_gfn + npages))
>                 return -EEXIST;
> 
> 
> Paolo
> 

Reply via email to