[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu PATCH v2 9/9] hw/mem/cxl_type3: Add dpa range validation for a
From: |
Jonathan Cameron |
Subject: |
Re: [Qemu PATCH v2 9/9] hw/mem/cxl_type3: Add dpa range validation for accesses to dc regions |
Date: |
Wed, 30 Aug 2023 16:37:20 +0100 |
> > +
> > +/*
> > + * This function check whether a dpa range [dpa, dpa + len) has been backed
> > + * with dc extents, used when validating read/write to dc regions
> > + */
> > +static bool test_region_block_backed(CXLType3Dev *ct3d, uint64_t dpa,
> > + uint64_t len)
> > +{
> > + int i;
> > + CXLDCD_Region *region = &ct3d->dc.regions[0];
> > + uint64_t nbits;
> > + long nr;
> > +
> > + if (dpa < region->base
> > + || dpa >= region->base + ct3d->dc.total_capacity)
> > + return false;
> > +
> > + /*
> > + * spec 3.0 9.13.3: Regions are used in increasing-DPA order, with
> > + * Region 0 being used for the lowest DPA of Dynamic Capacity and
> > + * Region 7 for the highest DPA.
> > + * So we check from the last region to find where the dpa belongs.
> > + * access across multiple regions is not allowed.
> > + */
> > + for (i = ct3d->dc.num_regions - 1; i >= 0; i--) {
> > + region = &ct3d->dc.regions[i];
> > + if (dpa >= region->base) {
> > + break;
> > + }
> > + }
> > +
> > + nr = (dpa - region->base) / region->block_size;
>
> > + nbits = len / region->block_size;
oops. Len is probably always smaller than block_size (typically 8 or less)
so nbits always 0. Should be 1 in those cases.
> > + return find_next_zero_bit(region->blk_bitmap, nbits, nr) >= nr +
> > nbits;
>
> The 2nd parameter to find_next_zero_bit is the length of the bitmap, so
> shouldn't this be something like (also considering that len is the
> read/write len, and will be smaller than the region block size):
>
> nbits = DIV_ROUND_UP(len, region->block_size);
>
>
> return find_next_zero_bit(region->blk_bitmap, nbits + nr, nr) ==
> nbits + nr;
Agreed with your suggestion. I'll carry that in my forward port of this
series for now and update my tree at
gitlab.com/jic23/qemu branch will probably be cxl-2023-08-30
a bit later today.
Jonathan