[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v8 08/13] vpci/header: program p2m with guest BAR view
On Thu, Jul 20, 2023 at 12:32:33AM +0000, Volodymyr Babchuk wrote: > From: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx> > > Take into account guest's BAR view and program its p2m accordingly: > gfn is guest's view of the BAR and mfn is the physical BAR value as set > up by the PCI bus driver in the hardware domain. Who sets that value should be left out of the commit message. On x86 PCI BARs are positioned by the firmware usually. > This way hardware domain sees physical BAR values and guest sees > emulated ones. This last sentence is kind of confusing, I would maybe write: "Hardware domain continues getting the BARs identity mapped, while for domUs the BARs are mapped at the requested guest address without modifying the BAR address in the device PCI config space." I'm afraid you are missing changes in modify_bars(): the overlaps for domU should be checked against the guest address of the BAR, not the host one. So you need to adjust the code in modify_bars() to use the newly introduced guest_reg when checking for overlaps in the domU case (and when populating the rangesets). > > Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx> > --- > Since v5: > - remove debug print in map_range callback > - remove "identity" from the debug print > Since v4: > - moved start_{gfn|mfn} calculation into map_range > - pass vpci_bar in the map_data instead of start_{gfn|mfn} > - s/guest_addr/guest_reg > Since v3: > - updated comment (Roger) > - removed gfn_add(map->start_gfn, rc); which is wrong > - use v->domain instead of v->vpci.pdev->domain > - removed odd e.g. in comment > - s/d%d/%pd in altered code > - use gdprintk for map/unmap logs > Since v2: > - improve readability for data.start_gfn and restructure ?: construct > Since v1: > - s/MSI/MSI-X in comments > --- > xen/drivers/vpci/header.c | 24 ++++++++++++++++++++---- > 1 file changed, 20 insertions(+), 4 deletions(-) > > diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c > index eb07fa0bb2..e1a448b674 100644 > --- a/xen/drivers/vpci/header.c > +++ b/xen/drivers/vpci/header.c > @@ -30,6 +30,7 @@ > > struct map_data { > struct domain *d; > + const struct vpci_bar *bar; > bool map; > }; > > @@ -41,8 +42,21 @@ static int cf_check map_range( > > for ( ; ; ) > { > + /* Start address of the BAR as seen by the guest. */ > + gfn_t start_gfn = _gfn(PFN_DOWN(is_hardware_domain(map->d) > + ? map->bar->addr > + : map->bar->guest_reg)); > + /* Physical start address of the BAR. */ > + mfn_t start_mfn = _mfn(PFN_DOWN(map->bar->addr)); > unsigned long size = e - s + 1; > > + /* > + * Ranges to be mapped don't always start at the BAR start address, > as > + * there can be holes or partially consumed ranges. Account for the > + * offset of the current address from the BAR start. > + */ > + start_gfn = gfn_add(start_gfn, s - mfn_x(start_mfn)); The rangeset for guests should contain the guest address, not the physical position of the BAR, so the logic here will be slightly different (as you will need to adjust the mfn parameter of {,un}map_mmio_regions() instead). That's so you can do overlap checking in the guest address space, as it's where the mappings will be created. > + > /* > * ARM TODOs: > * - On ARM whether the memory is prefetchable or not should be > passed > @@ -52,8 +66,8 @@ static int cf_check map_range( > * - {un}map_mmio_regions doesn't support preemption. > */ > > - rc = map->map ? map_mmio_regions(map->d, _gfn(s), size, _mfn(s)) > - : unmap_mmio_regions(map->d, _gfn(s), size, _mfn(s)); > + rc = map->map ? map_mmio_regions(map->d, start_gfn, size, _mfn(s)) > + : unmap_mmio_regions(map->d, start_gfn, size, _mfn(s)); > if ( rc == 0 ) > { > *c += size; > @@ -62,8 +76,8 @@ static int cf_check map_range( > if ( rc < 0 ) > { > printk(XENLOG_G_WARNING > - "Failed to identity %smap [%lx, %lx] for d%d: %d\n", > - map->map ? "" : "un", s, e, map->d->domain_id, rc); > + "Failed to %smap [%lx, %lx] for %pd: %d\n", > + map->map ? "" : "un", s, e, map->d, rc); I would also print the gfn -> mfn values if it's no longer an identity map. > break; > } > ASSERT(rc < size); > @@ -165,6 +179,7 @@ bool vpci_process_pending(struct vcpu *v) > if ( rangeset_is_empty(bar->mem) ) > continue; > > + data.bar = bar; Please init the .bar field at declaration, like it's done for the rest of the field. It doesn't matter if the BAR turns out to be empty (same below). Thanks, Roger.
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |