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

Re: [PATCH for-4.22] xen/pdx: fix off-by-one index in offset mask calculation


  • To: Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • From: Roger Pau Monné <roger.pau@xxxxxxxxxx>
  • Date: Tue, 9 Jun 2026 10:58:34 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NgvfDeRltW+4bsBSBTVgAEp8xUfe+nP6mgKZYfKQg/w=; b=YNiMxYmTW4BImzu9pIDrG/C+B7DkYq3cfUnvcfoYudiu0U/cR5AH7mvJC03JA23efzegf1GooZkzicWhX1RAdeLI5nR1++kPe7Nz6wknqAsAsxBDURdgkTdcLn1172LP88zBK9goSeNf49hcIpF9nHrkHijiywHpag+9xSjG0juyYHz0C8XsFhjm/9ksr/LrgXu0QmREyQJskWi6Gha0F82jiYfUxN4QeaYYpJFlv8ffWUZa+fwCUs9QdLxbWh0q02Q+jCqlK4sH/eLIWMFXJ6GfS/bFEv8e0KXtSzeHGJb1+Cl/vbXFDZogmWTZu1RjrEbPyivtZrlKynD6pCHx2w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Vov15qXtzf/gIxq2q8Ge1y1eqlHeyKFc945mpIh970m9cCgJ4y0NVB2SfgCFXySoAwGUpmG/cbvloijcSs+u4tM4HKoA8NSIEx2OiMCMfDJ7Z2Q6qhyOffGMqpNt5qbBD0tVYzItMscGnIyCbtxz2x00dJTOb0PQoWTl8JEIWZ30bpJRKuuPjtHiugvJ9IYnbQJMY5eM9N/eKb+yD5zIMFqoipJGn27IUqT6hfVLNdqiMzT7uVRJH8on8DGJ6JUZrG/+buTT50Du74ZKWglfG4fLfdBhGqkydDEbO1p7Sl60T3F+UifH8Hnb/cPtIlORePwMC1yoyOJsgeiU9jgTsw==
  • Authentication-results: eu.smtp.expurgate.cloud; dkim=pass header.s=selector1 header.d=citrix.com header.i="@citrix.com" header.h="From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck"
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: xen-devel@xxxxxxxxxxxxxxxxxxxx, Oleksii Kurochko <oleksii.kurochko@xxxxxxxxx>, Anthony PERARD <anthony.perard@xxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Julien Grall <julien@xxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>
  • Delivery-date: Tue, 09 Jun 2026 08:58:49 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On Tue, Jun 09, 2026 at 10:53:22AM +0200, Roger Pau Monne wrote:
> Adjust the mask calculation in case the last range is merged with the
> previous one, as then the mask must be calculated from the previous range,
> which the current one has been merged into.
> 
> Instead of fixing the off-by-one in place, move the calculation of the bit
> change mask to the next loop, after the ranges have been merged.  This
> simplifies the logic by consolidating mask calculation in a single place,
> possibly making it less error prone in the future.
> 
> Also add a test case that triggers the bug being fixed by this commit.
> 
> Fixes: c5c45bcbd6a1 ("pdx: introduce a new compression algorithm based on 
> region offsets")
> Signed-off-by: Roger Pau Monné <roger.pau@xxxxxxxxxx>
> ---
>  tools/tests/pdx/test-pdx.c | 14 ++++++++++++++
>  xen/common/pdx.c           | 13 ++++++-------
>  2 files changed, 20 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/tests/pdx/test-pdx.c b/tools/tests/pdx/test-pdx.c
> index d783186577ef..ba57f1793011 100644
> --- a/tools/tests/pdx/test-pdx.c
> +++ b/tools/tests/pdx/test-pdx.c
> @@ -191,6 +191,20 @@ int main(int argc, char **argv)
>              },
>              .compress = false,
>          },
> +        /*
> +         * 2s Dell R740, merging of ranges causes mask differences in PDX
> +         * offset mode.  Useful for checking mask calculations.
> +         */
> +        {
> +            .ranges = {
> +                { .start = 0x0000000UL, .end = 0x0080000UL },
> +                { .start = 0x0100000UL, .end = 0x3070000UL },
> +                { .start = 0x3070000UL, .end = 0x3870000UL },
> +                { .start = 0x3870000UL, .end = 0x6870000UL },
> +                { .start = 0x6870000UL, .end = 0x7070000UL },
> +            },
> +            .compress = false,
> +        },
>      };
>      int ret_code = EXIT_SUCCESS;
>  
> diff --git a/xen/common/pdx.c b/xen/common/pdx.c
> index 7e070ff962e8..a84c7d19ade4 100644
> --- a/xen/common/pdx.c
> +++ b/xen/common/pdx.c
> @@ -391,10 +391,7 @@ bool __init pfn_pdx_compression_setup(paddr_t base)
>          if ( !i ||
>               ranges[i].base_pfn >=
>               (ranges[i - 1].base_pfn + ranges[i - 1].pages) )
> -        {
> -            mask |= pdx_region_mask(ranges[i].base_pfn, ranges[i].pages);
>              continue;
> -        }
>  
>          ranges[i - 1].pages = ranges[i].base_pfn + ranges[i].pages -
>                                ranges[i - 1].base_pfn;
> @@ -402,19 +399,21 @@ bool __init pfn_pdx_compression_setup(paddr_t base)
>          if ( i + 1 < nr_ranges )
>              memmove(&ranges[i], &ranges[i + 1],
>                      (nr_ranges - (i + 1)) * sizeof(ranges[0]));
> -        else /* last range */
> -            mask |= pdx_region_mask(ranges[i].base_pfn, ranges[i].pages);
>          nr_ranges--;
>          i--;
>      }
>  
>      /*
> -     * Populate a mask with the non-equal bits of the different ranges, do 
> this
> -     * to calculate the maximum PFN shift to use as the lookup table index.
> +     * Populate two masks: one with the non-equal bits of the different 
> ranges,
> +     * another with the bits that change inside regions. Do this to calculate

Forgot to refresh the patch before sending, this line should be:

"another with the bits that change inside ranges.  Do this to calculate"

IOW: s/regions/ranges/ so that we don't mix "ranges" and "regions" in
the same paragraph which is confusing.

Thanks, Roger.



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.