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

Re: [PATCH v2 2/7] arm/mpu: Provide access to the MPU region from the C code


  • To: Ayan Kumar Halder <ayankuma@xxxxxxx>
  • From: Luca Fancellu <Luca.Fancellu@xxxxxxx>
  • Date: Tue, 8 Apr 2025 14:29:21 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=2; mx.microsoft.com 1; spf=fail (sender ip is 4.158.2.129) smtp.rcpttodomain=amd.com 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=id+0WXbyElh6DKsfM1Fx31khUsFWufY4SlXqN8P3bqI=; b=O4pu5p0j1Zi9fqIeFDKNJf4BSyPZAYd3xcbgARQA3CoJnIRO/HzjklC1gME7BAU0ckWXQf3huGcVYhEHssFXH5ZWKfxQ2BnzksToH+iVABYyEMPCizzvTW/dFivhORa1Qk23MofDUwNCwxfpv0E92td9jYWgFsfSZPq5+qEqeM2WykhOprtVsCHAXNpFKLsLTean/EqjzB4oQw8NH2k5Cf0UIaFqYK6WV58CpMrFX3Vyg2dfJgxoc/SJrzB0ipE+o7gal78gKxx7W6k6tNS6WPLnsI9e+2qoY/9ivGssGWxY2w2pDxoxGvw0SZ+0fubw9Zb0ezOMy8pdJ6t+6/KlLA==
  • 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=id+0WXbyElh6DKsfM1Fx31khUsFWufY4SlXqN8P3bqI=; b=QMIFKHzYNJxyZMjdU6xBVuadHXk9TGe2M3xjkdPtmCCCLADDBhBz76js5FbDsLu9MIEnclxaKo8Dz+pNtFuA6otzGDwLpae4pCABKayGWCSJhF/+Megijad032WeVEFdUCySZ1K72b33Q/U6I/3tLaMZ3ePEZiwf6OAhI/bRN8iGPZjuiFhKnj3gQem/jreFm69Ia0SLOuLQ84rbyBLHlyf6KrZo8iTQouZDfyQ+vdqqa8RSvaoKtxgb9u4d8tvOoZ2ms7cbG4rRyfz241pzXsCgRIN+lShs/EFhWZY4AVj31UAJigDqw8g85MeSJdb6ZGE0HoHcedjvmvtzgkDe9w==
  • Arc-seal: i=2; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=pass; b=q6C/ZJAJLaAZeaRgJY9jpTNyi1rS7J3PTfMd8ziYjdLG2Wxr4KkrNjH13IFWF8x+oqs/PTA4CTFyojrdY19tBXcZ34rmFY9HvIDrmzTGCH3JV1I8mgkRoccsNvAg2j4Lm4PbYgdv0s2W733wLdfrfkb5HSiEdBIb6Vsix8qB81KZxx7J9ttPXosbcfXSDzGKu5frhWSWLXGnyAr5WKStxQf3OeWuxtqGAzVbjlmrwpGUHn97LllIZeLBzC+556wcpmPidtA/2bt7qbGggqGd0eEHipr1VV6Mt2AfJJq5UatMCHyKnCu+NiGtvKURv8+c78CsmDCUJp9J7L5dfhhf4g==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=yMgHD7n5nkjSS1kY0Ipiy7EC1R2jRqGJ18946TShceAxFbjgPefTU7bQMOmYsXWTftGhHx2NBvbowTUL8W3viVjXUHTGHbv7ICtsUjX0/DOj0EW4+J9EnzRTVUfr868iBkfWQlCiIDlle8YazkEx3NvQ2WqKMqEvI5Dk52enoRYiOFmB2ZjRbGA922P6HLhPVkyd3/3VypksLp2t4L9Fd4MvUSTzSlHncO2UVllAi12A/xwtAeEpocKzuPMRCZkBk5Zb2XdZUHjj5990P4ovdHNzokIVmnXSj3LZbO+qU5RqFty9kgmmHthGg5yOcLf6kd9NdkHjSXoEo+0WrzXOQw==
  • 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>, Julien Grall <julien@xxxxxxx>, Bertrand Marquis <Bertrand.Marquis@xxxxxxx>, Michal Orzel <michal.orzel@xxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Tue, 08 Apr 2025 14:30:05 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Nodisclaimer: true
  • Thread-index: AQHbp52Ro+Yg+pQClU+WnJSxei+hH7OZzl8AgAAHm4A=
  • Thread-topic: [PATCH v2 2/7] arm/mpu: Provide access to the MPU region from the C code

Hi Ayan,

> On 8 Apr 2025, at 15:02, Ayan Kumar Halder <ayankuma@xxxxxxx> wrote:
> 
> Hi Luca,
> 
>> 
>> +static void prepare_selector(uint8_t sel)
>> +{
>> +    /*
>> +     * {read,write}_protection_region works using the direct access to the 
>> 0..15
>> +     * regions, so in order to save the isb() overhead, change the 
>> PRSELR_EL2
>> +     * only when needed, so when the upper 4 bits of the selector will 
>> change.
>> +     */
>> +    sel &= 0xF0U;
>> +    if ( READ_SYSREG(PRSELR_EL2) != sel )
>> +    {
>> +        WRITE_SYSREG(sel, PRSELR_EL2);
>> +        isb();
>> +    }
> 
> This needs to be arm64 specific. Refer ARM DDI 0600A.d ID120821
> 
> G1.3.19  PRBAR<n>_EL2, /* I guess this is what you are following */
> 
> Provides access to the base address for the MPU region determined by the 
> value of 'n' and
> PRSELR_EL2.REGION as PRSELR_EL2.REGION<7:4>:n.
> 
> 
> Whereas for arm32 . Refer ARM DDI 0568A.c ID110520
> 
> E2.2.3 HPRBAR<n>,
> 
> Provides access to the base addresses for the first 32 defined EL2 MPU 
> regions.
> 
> /* Here we do not need to use HPRSELR for region selection */
> 
> 
> If you want to make the code similar between arm32 and arm64, then I can 
> suggest you can use these registers.
> 
> G1.3.17 PRBAR_EL2
> 
> Provides access to the base addresses for the EL2 MPU region. 
> PRSELR_EL2.REGION determines
> which MPU region is selected.
> 
> E2.2.2 HPRBAR
> 
> Provides indirect access to the base address of the EL2 MPU region currently 
> defined by
> HPRSELR.
> 
> Let me know if it makes sense.
> 
> - Ayan

Ok I didin’t get that before, what do you think if I modify the code as in this 
diff (not tested):

diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c
index fe05c8097155..1bc6d7a77296 100644
--- a/xen/arch/arm/mpu/mm.c
+++ b/xen/arch/arm/mpu/mm.c
@@ -58,19 +58,21 @@ static void __init __maybe_unused build_assertions(void)
     BUILD_BUG_ON(PAGE_SIZE != SZ_4K);
 }
 
-static void prepare_selector(uint8_t sel)
+static void prepare_selector(uint8_t *sel)
 {
+    uint8_t cur_sel = *sel;
     /*
      * {read,write}_protection_region works using the direct access to the 
0..15
      * regions, so in order to save the isb() overhead, change the PRSELR_EL2
      * only when needed, so when the upper 4 bits of the selector will change.
      */
-    sel &= 0xF0U;
-    if ( READ_SYSREG(PRSELR_EL2) != sel )
+    cur_sel &= 0xF0U;
+    if ( READ_SYSREG(PRSELR_EL2) != cur_sel )
     {
-        WRITE_SYSREG(sel, PRSELR_EL2);
+        WRITE_SYSREG(cur_sel, PRSELR_EL2);
         isb();
     }
+    *sel = *sel & 0xFU;
 }
 
 /*
@@ -102,7 +104,7 @@ void read_protection_region(pr_t *pr_read, uint8_t sel)
      */
     prepare_selector(sel);
 
-    switch ( sel & 0xFU )
+    switch ( sel )
     {
         GENERATE_READ_PR_REG_CASE(0, pr_read);
         GENERATE_READ_PR_REG_CASE(1, pr_read);
@@ -140,7 +142,7 @@ void write_protection_region(const pr_t *pr_write, uint8_t 
sel)
      */
     prepare_selector(sel);
 
-    switch ( sel & 0xFU )
+    switch ( sel )
     {
         GENERATE_WRITE_PR_REG_CASE(0, pr_write);
         GENERATE_WRITE_PR_REG_CASE(1, pr_write);

And later you will use some #ifdef CONFIG_ARM_32 inside prepare_selector() to 
check
that the code is passing up to the max supported region or panic.
And in {read,write}_protection_region() you could add some #ifdef CONFIG_ARM_32 
to add
the case generators for regions from 16 to 23 since R52 can address them 
directly.

What do you think?

Cheers,
Luca





 


Rackspace

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