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

Re: [PATCH v5 5/6] arm/mpu: Introduce utility functions for the pr_t type


  • To: Luca Fancellu <luca.fancellu@xxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
  • From: "Orzel, Michal" <michal.orzel@xxxxxxx>
  • Date: Thu, 22 May 2025 10:48:44 +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=p1LBU9Kn1Os0qoiuZLo3U/AMfrFQTFFhLK8MerzpK2A=; b=pGiO6aQVBQNoITwjP3vsrd5lBQFMQDkUOEeSt4Xlfoiij9X3WOzF6cYL9dPjAVc9WvxNWgfdlNX9XeFk0QMKSdoYNBppMnuWu+I40jPx/ybq2ka8jMfC8h4NNVWWo8iIvt/ngTdT0gnVTPwLwsVr2b+p5pCNCKoUazvhkEmJ7bxyJ2r6yqRRMEjbOTxQ11vUeWbA5Dfvom2v4TPAugY7fZGIZH4atFi8/3if8kosTRrBeXy3qkiIzrTBUmBKG40oEnG7SosmN8NVf1znjZ3I6ZIG4BbI/Xi9iQD514Bv8Cr5ej3JbNCyNfVXmsk9uUt7QzOSjHVLP62D0cjjGa/ZqA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=d9i4o41MC2Zd5J0JPA3qDgQR7YTDWKHHAUGR75Z6HqTwaVh7nA7EOSCNTmaRrFu/oSNETA9BFk+v4pQ2G08+7cQQ9wH3WkIM56Lb0jXoNKATs9sVJUBTHeDz22ALZTEd7VgSX+eedbTAG5DFDBOuK6v5e3Lt1gcEJqE1OmBcNQqueBIWFN+LipINQTzuWwVHbsv/RmFOdSzTfmxDg99sVBdJp84WY32ajEILd4ogyvIVG9meqe83gzHscQbj2Ji2rPrIzT7JmdTC4UyGDMZ2JyeVjxUTeKbByVj6flw2BWFiu5irOTeOS7gUd0Ogb/Ex1CIb0Ra2Nrnq17WVbBqtWw==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com;
  • Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <bertrand.marquis@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Thu, 22 May 2025 08:49:01 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>


On 13/05/2025 10:45, Luca Fancellu wrote:
> Introduce a few utility functions to manipulate and handle the
> pr_t type.
> 
> Signed-off-by: Luca Fancellu <luca.fancellu@xxxxxxx>
> ---
> v5 changes:
>  - Don't rely on bitfield and use the mask MPU_REGION_RES0 for
>    pr_set_base and pr_set_limit to make it explicit. Fixed typos
>    in commit message.
> v4 changes:
>  - Modify comment on top of the helpers. Clarify pr_set_limit
>    takes exclusive address.
>    Protected common code with #ifdef Arm64 until Arm32 is ready
>    with pr_t
> ---
>  xen/arch/arm/include/asm/mpu.h | 65 ++++++++++++++++++++++++++++++++++
>  1 file changed, 65 insertions(+)
> 
> diff --git a/xen/arch/arm/include/asm/mpu.h b/xen/arch/arm/include/asm/mpu.h
> index fb93b8b19d24..b90ae8eab662 100644
> --- a/xen/arch/arm/include/asm/mpu.h
> +++ b/xen/arch/arm/include/asm/mpu.h
> @@ -23,6 +23,71 @@
>  #define NUM_MPU_REGIONS_MASK    (NUM_MPU_REGIONS - 1)
>  #define MAX_MPU_REGION_NR       NUM_MPU_REGIONS_MASK
>  
> +#ifndef __ASSEMBLY__
> +
> +#ifdef CONFIG_ARM_64
> +/*
> + * Set base address of MPU protection region.
> + *
> + * @pr: pointer to the protection region structure.
> + * @base: base address as base of the protection region.
> + */
> +static inline void pr_set_base(pr_t *pr, paddr_t base)
> +{
> +    pr->prbar.reg.base = ((base & ~MPU_REGION_RES0) >> MPU_REGION_SHIFT);
> +}
> +
> +/*
> + * Set limit address of MPU protection region.
> + *
> + * @pr: pointer to the protection region structure.
> + * @limit: exclusive address as limit of the protection region.
> + */
> +static inline void pr_set_limit(pr_t *pr, paddr_t limit)
> +{
> +    pr->prlar.reg.limit = (((limit - 1) & ~MPU_REGION_RES0)
Might be worth adding a comment that PRLAR expects inclusive limit hence (limit 
-1).

> +                           >> MPU_REGION_SHIFT);
> +}
> +
> +/*
> + * Access to get base address of MPU protection region.
> + * The base address shall be zero extended.
> + *
> + * @pr: pointer to the protection region structure.
> + * @return: Base address configured for the passed protection region.
> + */
> +static inline paddr_t pr_get_base(pr_t *pr)
Why not const?

> +{
> +    return (paddr_t)(pr->prbar.reg.base << MPU_REGION_SHIFT);
> +}
> +
> +/*
> + * Access to get limit address of MPU protection region.
> + * The limit address shall be concatenated with 0x3f.
> + *
> + * @pr: pointer to the protection region structure.
> + * @return: Inclusive limit address configured for the passed protection 
> region.
> + */
> +static inline paddr_t pr_get_limit(pr_t *pr)
Why not const?

> +{
> +    return (paddr_t)((pr->prlar.reg.limit << MPU_REGION_SHIFT)
> +                     | ~MPU_REGION_MASK);
> +}
> +
> +/*
> + * Checks if the protection region is valid (enabled).
NIT: in other helpers you use imperative mood, so this should be "Check if"
> + *
> + * @pr: pointer to the protection region structure.
> + * @return: True if the region is valid (enabled), false otherwise.
> + */
> +static inline bool region_is_valid(pr_t *pr)
Why not const?

> +{
> +    return pr->prlar.reg.en;
> +}
> +#endif
Please add /* CONFIG_ARM_64 */

> +
> +#endif /* __ASSEMBLY__ */
> +
>  #endif /* __ARM_MPU_H__ */
>  
>  /*


~Michal




 


Rackspace

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