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

Re: [PATCH v2 1/6] arm/mpu: Find MPU region by range


  • To: Hari Limaye <hari.limaye@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: "Orzel, Michal" <michal.orzel@xxxxxxx>
  • Date: Mon, 7 Jul 2025 09:47:40 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.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=6/ma3ghPtFIuLAVgzvFQt0x9lIB8S9+o1bj/dktAF/I=; b=APM3fU7oGYfD1KstEpTvVmZFl3qXGRAusiIUhFn3TxW1jetTcWuFDzTB9jr6DX9QoK/Q5RwIAA/ZsdHQY0H/Nw1+yJD5veNVD1UIRbvxHJNw02+Ys8q7Ms9KrdoTEdYv/Ea4duFvAB1xiQwZzYa96R0uCxwwOEunvLssDYtByfCS9TM+nvDh6bNWhD139fxpLep1gbrqCllPJfCw/K/BCxVAxpQY84jy+E2hVV7EKzNToV7Aq/yrBiZ54Q5H2W7UehFzdmB83BDF4BEeSshS4vMDvgj++uQbBNaTJ0vFJe9qlhA33fCC0vIgTdXwPQZSZO2g0BXqILlhsE6XZe64kw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=wrIrDlv3jvcHhGKjCI2ivAHKJbDq5ldY55WRCUJ6kgoi3NJmVum4H8GTeMvkTnkS8TfLBsDmpd47T2Ap5/lHkT8RqZf66tdFi273fXwmexwFuU9pLr9KFBfxc3wI7h7HGGyy4Zg+b7O5fCUfPpdG0j6rfXc+KIB75i9y4B4f1gvfVGsxBKa+XKQUQr4UR3y08tkvFkb9MA8vI/5pbyQFnG9Ufqu/JO+JpBKN66S00SzpN1mp5oQcv9VxoMQTXrlX74HhdfFmh3ACfB5bCK0LxXX9wjVCYJz/t6LE8Cx8Y7lEzlrpufKoPj5Jei+87GpQxDEgd83eyqbR+rpGkch+Zg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com;
  • Cc: luca.fancellu@xxxxxxx, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Mon, 07 Jul 2025 07:47:57 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 02/07/2025 16:13, Hari Limaye wrote:
> From: Luca Fancellu <luca.fancellu@xxxxxxx>
> 
> Implement a function to find the index of a MPU region in the xen_mpumap
> MPU region array. This function will be used in future commits to
> implement creating and destroying MPU regions.
> 
> Signed-off-by: Luca Fancellu <luca.fancellu@xxxxxxx>
> Signed-off-by: Hari Limaye <hari.limaye@xxxxxxx>
> ---
> Changes from v1:
> - Update commit message
> - Remove internal _index variable
> - Simplify logic by disallowing NULL index parameter
> - Use normal printk
> - Reorder conditional checks
> - Update some comments
> ---
>  xen/arch/arm/include/asm/mpu/mm.h | 29 +++++++++++++++++
>  xen/arch/arm/mpu/mm.c             | 52 +++++++++++++++++++++++++++++++
>  2 files changed, 81 insertions(+)
> 
> diff --git a/xen/arch/arm/include/asm/mpu/mm.h 
> b/xen/arch/arm/include/asm/mpu/mm.h
> index a7f970b465..81e47b9d0b 100644
> --- a/xen/arch/arm/include/asm/mpu/mm.h
> +++ b/xen/arch/arm/include/asm/mpu/mm.h
> @@ -10,6 +10,13 @@
>  #include <asm/mm.h>
>  #include <asm/mpu.h>
>  
> +#define MPUMAP_REGION_OVERLAP      -1
> +#define MPUMAP_REGION_NOTFOUND      0
> +#define MPUMAP_REGION_FOUND         1
> +#define MPUMAP_REGION_INCLUSIVE     2
> +
> +#define INVALID_REGION_IDX     0xFFU
> +
>  extern struct page_info *frame_table;
>  
>  extern uint8_t max_mpu_regions;
> @@ -75,6 +82,28 @@ void write_protection_region(const pr_t *pr_write, uint8_t 
> sel);
>   */
>  pr_t pr_of_addr(paddr_t base, paddr_t limit, unsigned int flags);
>  
> +/*
> + * Checks whether a given memory range is present in the provided table of
> + * MPU protection regions.
> + *
> + * @param table         Array of pr_t protection regions.
> + * @param r_regions     Number of elements in `table`.
> + * @param base          Start of the memory region to be checked (inclusive).
> + * @param limit         End of the memory region to be checked (exclusive).
> + * @param index         Set to the index of the region if an exact or 
> inclusive
> + *                      match is found, and INVALID_REGION otherwise.
> + * @return: Return code indicating the result of the search:
> + *          MPUMAP_REGION_NOTFOUND: no part of the range is present in 
> `table`
> + *          MPUMAP_REGION_FOUND: found an exact match in `table`
> + *          MPUMAP_REGION_INCLUSIVE: found an inclusive match in `table`
> + *          MPUMAP_REGION_OVERLAP: found an overlap with a mapping in `table`
> + *
> + * Note: make sure that the range [`base`, `limit`) refers to the memory 
> region
> + * inclusive of `base` and exclusive of `limit`.
> + */
> +int mpumap_contains_region(pr_t *table, uint8_t nr_regions, paddr_t base,
> +                          paddr_t limit, uint8_t *index);
> +
>  #endif /* __ARM_MPU_MM_H__ */
>  
>  /*
> diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c
> index ccfb37a67b..25e7f36c1e 100644
> --- a/xen/arch/arm/mpu/mm.c
> +++ b/xen/arch/arm/mpu/mm.c
> @@ -110,6 +110,58 @@ pr_t pr_of_addr(paddr_t base, paddr_t limit, unsigned 
> int flags)
>      return region;
>  }
>  
> +int mpumap_contains_region(pr_t *table, uint8_t nr_regions, paddr_t base,
> +                          paddr_t limit, uint8_t *index)
> +{
> +    ASSERT(index);
> +    *index = INVALID_REGION_IDX;
> +
> +    /* Convert [base, limit) to [base, limit - 1] for inclusive comparison */
> +    limit = limit - 1;
> +
> +    if ( limit < base )
> +    {
> +        printk("Base address %#"PRIpaddr" must be smaller than limit address 
> %#"PRIpaddr"\n",
Given this message, what about region being empty i.e. limit == base? Is it
worth continuing the function?

> +               base, limit);
Here you print limit as inclusive but below as exclusive. Why the difference?

> +        return -EINVAL;
> +    }
> +
> +    for (uint8_t i = 0; i < nr_regions; i++ )
Space before ( and uint8_t.

~Michal




 


Rackspace

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