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

Re: [PATCH v3 7/7] arm/mpu: Implement setup_mpu for MPU system


  • To: Julien Grall <julien@xxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Mon, 14 Apr 2025 15:17:36 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=pass (sender ip is 4.158.2.129) smtp.rcpttodomain=xen.org smtp.mailfrom=arm.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=arm.com; dkim=pass (signature was verified) header.d=arm.com; arc=pass (0 oda=1 ltdi=1 spf=[1,1,smtp.mailfrom=arm.com] dkim=[1,1,header.d=arm.com] dmarc=[1,1,header.from=arm.com])
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
  • Arc-message-signature: i=2; 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=f+MA1cxj9Cc9vtjGDIpAVEEuIDJnU63CRrVmp05o6aI=; b=ec8/nif+CughualCpYQEeFvfn/dz3Yr7FtBeVB1T3n9UZf6emvgXETLiTJOASxdGLHTiqm5Hm0z5uStUTGClDnYN34LCveuQHxhiRha91Ez+4rbnZ3MwnsH7EOEp6mwxJCt44oU7mkXSTSyfRSBaL7fSKgOaDHB8+2GKaaSObGv0a0EEroNLBRtTlu2evAJJBHaVKi7vDG1/EIEiLaZ4SnHnjhU0vGzaMvMN2bwAH2/y1awEEZWKzk/ubWmosWrDIxT3zJgFew2udXeGl4UjBs7BDxfh3PU+bRTAJES9iomsojpO0Xb6vMzzzEhNqTcb/zS3CXDM9nVnZQTjHkdtyA==
  • 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=f+MA1cxj9Cc9vtjGDIpAVEEuIDJnU63CRrVmp05o6aI=; b=ILUwLfvnwPzj4ia7tD5NW9iFluNkydFcodwzcwrSLXGI75JNca2OpZ5dCOTg8vH/pSPFfLfyxjF4tSxRnLyCDfucreLy15IqEig1/PbcifC8NmX3E9qOMcToU+EGwtm/5JCv1jrqkvH2JdAiV8qMt2rYTGS6BtWF7ppmF9qneu8iejmeCI+/mOt84YavUkM3Y5UEJN0vand6hMfBhzpKxIPFjORj9rG8JjVU1RocFEzBiGsUkpfs0VmzYKZy1Ywa5bhXzjK7Gl/mAb/PQ3zwuwchw606dyI/VlK9zkyDFGMinKxmQcXQKNTDsa2RyJBRawn3QU0F82lDXPEUJkrUWA==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=v00PYA6EWHVfVg8k+woAi/qXTqZGXX2TXQGt5vdwrghgYe31rXJ5ts4OVt06aTXUzvyM+heIirRhXRRnRplNgCD8gIXfiFfvJWzma3jBHkEOjRE4HkdI/uj/uU/gG/GkARGfZu9dNHKdBbVZzRZSidvlV6ijPkpZGFZGyThOqvX4Zl+Lgb6PYI2hrX+giE7DbN7x1s/rO2GHNsMTnFZ8ZZuT4QS8vsae6IimJ6S7RFGSUfgT3fIxieb6zVkGjG39ZqcfO+NHvkgji4SYZM/Gzo62gGmMVa+L8/yxWX11nteRNQluj6DUPVQ/GPQIa341zO92gItyCQndNw+nUIH1YQ==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lhQVoRIUN6ZShbwnEa7HYAR6F6lvMD5NvB/ryPPuNpHZ0imElfQC/D+BXKTXqll3/unx9x9NnVKsunYlAGa14MINDUZm74XwMHWGrt0dns9apbAmpZFIcLt5FFNaoi7mqS9z8gRYvmwysvOEfHwKe8bfGMRZ7HepeRK5rPvq/14vaTMRnJmVzPWjl6u5pnegdeYby6YSDIxnzb9oL5bQRfnLd1DX6q35+sHtmYuWYYqcBkH7WRb1eEfL9fAgfeN6+GS+/VV+APcA5Svy7+vekXFKfC7LNF2HnqOG7kUYnHQcwXjAQumbiL2br+HJnCBwcEUqeOxnmKLtr0q9x4mD4w==
  • Authentication-results-original: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=arm.com;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Stefano Stabellini <sstabellini@xxxxxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Mon, 14 Apr 2025 15:18:20 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Thread-index: AQHbqvIOcqFIKG0Dnkidmosr/dM7hLOjFvuAgAAzsIA=
  • Thread-topic: [PATCH v3 7/7] arm/mpu: Implement setup_mpu for MPU system

HI Julien,

> On 14 Apr 2025, at 13:12, Julien Grall <julien@xxxxxxx> wrote:
> 
> Hi Luca,
> 
> On 11/04/2025 23:56, Luca Fancellu wrote:
>> Implement the function setup_mpu that will logically track the MPU
>> regions defined by hardware registers, start introducing data
>> structures and functions to track the status from the C world.
>> The xen_mpumap_mask bitmap is used to track which MPU region are
>> enabled at runtime.
>> This function is called from setup_mm() which full implementation
>> will be provided in a later stage.
>> Signed-off-by: Luca Fancellu <luca.fancellu@xxxxxxx>
>> ---
>> v3 changes:
>>  - Moved PRENR_MASK define to common.
>> ---
>> ---
>>  xen/arch/arm/include/asm/mpu.h |  2 ++
>>  xen/arch/arm/mpu/mm.c          | 49 +++++++++++++++++++++++++++++++++-
>>  2 files changed, 50 insertions(+), 1 deletion(-)
>> diff --git a/xen/arch/arm/include/asm/mpu.h b/xen/arch/arm/include/asm/mpu.h
>> index eba5086cde97..77d0566f9780 100644
>> --- a/xen/arch/arm/include/asm/mpu.h
>> +++ b/xen/arch/arm/include/asm/mpu.h
>> @@ -20,6 +20,8 @@
>>  #define NUM_MPU_REGIONS_MASK    (NUM_MPU_REGIONS - 1)
>>  #define MAX_MPU_REGIONS         NUM_MPU_REGIONS_MASK
>>  +#define PRENR_MASK  GENMASK(31, 0)
>> +
>>  /* Access permission attributes. */
>>  /* Read/Write at EL2, No Access at EL1/EL0. */
>>  #define AP_RW_EL2 0x0
>> diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c
>> index 635d1f5a2ba0..e0a40489a7fc 100644
>> --- a/xen/arch/arm/mpu/mm.c
>> +++ b/xen/arch/arm/mpu/mm.c
>> @@ -14,6 +14,17 @@
>>    struct page_info *frame_table;
>>  +/* Maximum number of supported MPU memory regions by the EL2 MPU. */
> > +uint8_t __ro_after_init max_xen_mpumap;
> 
> Are this variable and ...
> 
>> +
>> +/*
>> + * Bitmap xen_mpumap_mask is to record the usage of EL2 MPU memory regions.
>> + * Bit 0 represents MPU memory region 0, bit 1 represents MPU memory
>> + * region 1, ..., and so on.
>> + * If a MPU memory region gets enabled, set the according bit to 1.
>> + */
>> +DECLARE_BITMAP(xen_mpumap_mask, MAX_MPU_REGIONS);
> 
> ... this one meant to be global? If yes, then they need to have a declaration 
> in the header. If not, then you want to add 'static'.

yes they are meant to be global, I’ll add a declaration in the header.

> 
> > +
>>  /* EL2 Xen MPU memory region mapping table. */
>>  pr_t xen_mpumap[MAX_MPU_REGIONS];
>>  @@ -222,9 +233,45 @@ pr_t pr_of_xenaddr(paddr_t base, paddr_t limit, 
>> unsigned attr)
>>      return region;
>>  }
>>  +/*
>> + * The code in this function needs to track the regions programmed in
>> + * arm64/mpu/head.S
>> + */
>> +static void __init setup_mpu(void)
>> +{
>> +    register_t prenr;
>> +    unsigned int i = 0;
>> +
>> +    /*
>> +     * MPUIR_EL2.Region[0:7] identifies the number of regions supported by
>> +     * the EL2 MPU.
>> +     */
>> +    max_xen_mpumap = (uint8_t)(READ_SYSREG(MPUIR_EL2) & 
>> NUM_MPU_REGIONS_MASK);
>> +
>> +    /* PRENR_EL2 has the N bit set if the N region is enabled, N < 32 */
>> +    prenr = (READ_SYSREG(PRENR_EL2) & PRENR_MASK);
>> +
>> +    /*
>> +     * Set the bitfield for regions enabled in assembly boot-time.
>> +     * This code works under the assumption that the code in head.S has
>> +     * allocated and enabled regions below 32 (N < 32).
>> +     
> This is a bit fragile. I think it would be better if the bitmap is set by 
> head.S as we add the regions. Same for ...

So, I was trying to avoid that because in that case we need to place xen_mpumap 
out of the BSS and start
manipulating the bitmap from asm, instead I was hoping to use the C code, I 
understand that if someone
wants to have more than 31 region as boot region this might break, but it’s 
also a bit unlikely?

So I was balancing the pros to manipulate everything from the C world against 
the cons (boot region > 31).

Is it still your preferred way to handle everything from asm?

Cheers,
Luca


 


Rackspace

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