On Fri, 3 Mar 2023 15:09:08 +0000 Jonathan Cameron <jonathan.came...@huawei.com> wrote:
> Current implementation is very simple so many of the corner > cases do not exist (e.g. fragmenting larger poison list entries) > > Signed-off-by: Jonathan Cameron <jonathan.came...@huawei.com> Another case in here of directly accessing MemoryRegion->size. I'll fix that up for v5. ... > diff --git a/hw/mem/cxl_type3.c b/hw/mem/cxl_type3.c > index 21e3a84785..0d9de0ee03 100644 > --- a/hw/mem/cxl_type3.c > +++ b/hw/mem/cxl_type3.c > @@ -919,6 +919,41 @@ static void set_lsa(CXLType3Dev *ct3d, const void *buf, > uint64_t size, > */ > } > > +static bool set_cacheline(CXLType3Dev *ct3d, uint64_t dpa_offset, uint8_t > *data) > +{ > + MemoryRegion *vmr = NULL, *pmr = NULL; > + AddressSpace *as; > + > + if (ct3d->hostvmem) { > + vmr = host_memory_backend_get_memory(ct3d->hostvmem); > + } > + if (ct3d->hostpmem) { > + pmr = host_memory_backend_get_memory(ct3d->hostpmem); > + } > + > + if (!vmr && !pmr) { > + return false; > + } > + > + if (dpa_offset + 64 > int128_get64(ct3d->cxl_dstate.mem_size)) { > + return false; > + } > + > + if (vmr) { > + if (dpa_offset < int128_get64(vmr->size)) { > + as = &ct3d->hostvmem_as; > + } else { > + as = &ct3d->hostpmem_as; > + dpa_offset -= vmr->size; Michael pointed out we shouldn't do this in the Volatile series. Fixed the same way here with memory_region_size() here and instead of the int128_get64 above. > + } > + } else { > + as = &ct3d->hostpmem_as; > + } > + > + address_space_write(as, dpa_offset, MEMTXATTRS_UNSPECIFIED, &data, 64); > + return true; > +} > +