[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: Tue, 15 Apr 2025 07:55:16 +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=/2fKqZ5wnNPzUBs4RD7wTwKYGvs3QOO9TxGt/wG8g08=; b=STsHQhkiqYVia/kyjRIfg2MrU9+zhq2Sb8hCHSKxzNraMmebQ4kF5+N/gyX9jmYaH+j1zEBUfX+Gl0B8UeS8EDLJ1Fzf5qzbATgIU85KgGP8R7ao65VFXDG26fNUA42UTb86zlHMqcd9KJi58I/I1zUEI/baAbJytBtJgkbcCyvdiOaYK5srj1bF8acuXRA8SBS98UWt8COv9c29uxbYhL5cK9+jAjsa6dENW/owVkAwiV37gwyRNcyY8y7Fa0KIrEv++EXlqzHvZAa3VDYqksHlZbYv3ATgurDkSVaFxYpF5+zlN3pVImNeLJnKPxA88F4BlTHMD6ixdgQXdGG2jw==
  • 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=/2fKqZ5wnNPzUBs4RD7wTwKYGvs3QOO9TxGt/wG8g08=; b=GDeGhgUWs9/uThmwXm4pRSTwv316vh2DOkf20Be68/OAp9OrlU43dP+fib1G8sxqCHVqyTq8eTxkWAg/pFGjxhdhzfaVCgsmqqtiBJz6rs0DBrVKi0vaBbqoPnuca/3RfXWQJeRkKzFAT/7+6YfZPyFBJSGqEfrGVnSU7Ya3quEW5FQ89Xhb4ebS0wr8iW60pELpI7h/RdSK5qb1uWuFb2HgItRvQjkjDJLlXCrIGPKbyYGjdkoBXFjDojqv9rig9H1q5vMFHkrYXIdAVAJ4G22mXc/lk6KlrUJoi9q0HjRwaOfj7zckb9RAP6vKj5ncZNzbSi7ZbuwkDUevyxeP/Q==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=pxfv9bblthxMq/mmOkSFvCX0ko3V7HhV8MaPgCHWI6fHQXHjqeQIz06zOYh45LMHZPmiLM/gyyoOPR5WvU1DmR/x8WH1RuUBKYSoIgND1qdvhzPDJ9+gJh+cEfNfs63ejGnCevHcVN7G6uSdVsqEHfYxPv6sbSxJGP4hkbD32G5gXT2WWBv9Ek/9w0NBtZk95cNqrwdH6kr535pXYyoDIdF0BQCTV9FZDCVtt+LbHSGcJnSxFwzTzjXxoA++sF5QvOWXNmxfyZe5n0omLjqYjmyfOstf0Frqb8Qowsi0rAoVzVBqrR8VHuyU3OdRYcAHYZxN2wS9MOfotn01l3sV4g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vDDjOA6m+AqvZ38NVh7VmlrzjRWTAT/2nh5ZGw7AGOrzq4NDxmLlK+tvEbHYZ6Hg+vR/fO5BacQFnkiOL1WsVLWGhT1iyFW6q4SqaXkJWRs98NRj9ZgUPkiqBwZYnWlkLXb4KggOcNFHo/DmB6pfb7qycejg0Rr9jKDkfebU8gBJ42RJVcCCnxIoSg9ROReSxd2XsYpjpz1gNS5lqpvhbTZpsfISKahaWDtUFI53m2wVUVfiPInA0mKxbYRTXVAn7Tul7X0rfuImfDvd8dLIfyfjNU10G9UuFODQ1O9sBTBzU5I1Zj6kNOqqhQ78eVmPp/dYjRcZVtxPwbAqz5IvKA==
  • 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: Tue, 15 Apr 2025 07:56:08 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Thread-index: AQHbqvIOcqFIKG0Dnkidmosr/dM7hLOjFvuAgAAzsICAAJ2ngIAAeRkA
  • Thread-topic: [PATCH v3 7/7] arm/mpu: Implement setup_mpu for MPU system

Hi Julien,

>>>> +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?
> 
> The 31 is only part of the problem. The other problem is there is at least 
> one other places in Xen (i.e. as early_fdt_map()) which will also create an 
> entry in the MPU before setup_mm()/setup_mpu() is called. I am a bit 
> concerned that the assumption is going to spread and yet we have no way to 
> programmatically check if this will be broken.

If we would like to find ways, we could check eventually for clashes on enabled 
MPU regions;
so the only part where a region is created in the C world without the 
assistance of xen_mpumap is early_fdt_map(),
asserts etc could be used in one or both setup_mpu and early_fdt_map to prevent 
breakage.

> 
> Furthermore, right now, you are hardcoding the slot used and updating the 
> MPU. But if you had the bitmap updated, you could just look up for a free 
> slot.

of course, but still the early DTB map is temporary and it will be gone after 
boot, so it won’t impact much unless I’m
missing something. 

> 
>> 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?
> 
> Yes. I don't think the change in asm will be large and this would allow to 
> remove other assumptions (like in the FDT mapping code).

not large, but still something to be maintained, we will need arm64/arm32 code 
to set/clear bits on the bitmap
(causing duplication with bitops.c), code to save things on the xen_mpumap, 
code to clean/invalidate dcache for the entries in xen_mpumap and finally we 
will need to keep the code aligned to the implementation of the bitmap
(which is fairly stable, but still needs to be taken into account).

> 
> As a side note, I noticed that the MPU entries are not cleared before we 
> enable the MPU. Is there anything in the boot protocol that guarantee all the 
> entries will be invalid? If not, then I think we need to clear the entries.
> 
> Otherwise, your current logic doesn't work. That said, I think it would still 
> be necessary even if we get rid of your logic because we don't know the 
> content of the MPU entries.

The PRLAR.EN bit resets to zero on a warm reset, so any region will be always 
disabled unless programmed, I thought it is enough.

Cheers,
Luca


 


Rackspace

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