From: Luca Fancellu <Luca.Fancellu@arm.com>
To: "Orzel, Michal" <Michal.Orzel@amd.com>
Cc: "xen-devel@lists.xenproject.org" <xen-devel@lists.xenproject.org>,
Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>,
Bertrand Marquis <Bertrand.Marquis@arm.com>,
Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Subject: Re: [PATCH v4 3/7] arm/mpu: Provide and populate MPU C data structures
Date: Wed, 30 Apr 2025 12:22:37 +0000 [thread overview]
Message-ID: <CE38FEAB-180D-478D-99E5-855CEEB870E9@arm.com> (raw)
In-Reply-To: <7fa8309f-0f5b-4842-bb0a-8c6e1fe5c11f@amd.com>
Hi Michal,
> On 30 Apr 2025, at 11:57, Orzel, Michal <Michal.Orzel@amd.com> wrote:
>
>
>
> On 29/04/2025 17:20, Luca Fancellu wrote:
>> Provide some data structure in the C world to track the MPU
>> status, these structures will be filled at boot by the assembly
>> early code with the boot MPU regions and afterwards they will be
>> used at runtime.
>>
>> Provide methods to update a bitmap created with DECLARE_BITMAP
>> from the assembly code for both Arm32 and Arm64.
>>
>> Modify Arm64 assembly boot code to reset any unused MPU region,
>> initialise 'max_xen_mpumap' with the number of supported MPU
> IMO this is not a good name because there's nothing there suggesting that this
> variable stores the number. Maybe max_mpu_regions or max_xen_mpumap_regions.
ok I will change it
>>
>> /* x0: region sel */
>> mov x0, xzr
>> /* Xen text section. */
>> @@ -74,6 +77,16 @@ FUNC(enable_boot_cpu_mm)
>> prepare_xen_region x0, x1, x2, x3, x4, x5, attr_prbar=REGION_DEVICE_PRBAR, attr_prlar=REGION_DEVICE_PRLAR
>> #endif
>>
>> +zero_mpu:
>> + /* Reset remaining MPU regions */
>> + cmp x0, x5
>> + beq out_zero_mpu
>> + mov x1, #0
>> + mov x2, #1
> Shouldn't we mark the region as emtpy (base == limit) when doing region clear?
So the macro takes an exclusive range, inside it will change to inclusive by doing limit-1,
so the region will be empty.
>
>
>> @@ -0,0 +1,67 @@
>> +/* SPDX-License-Identifier: GPL-2.0-only */
>> +
>> +/*
>> + * Sets a bit in a bitmap declared by DECLARE_BITMAP, symbol name passed through
>> + * bitmap_symbol.
>> + *
>> + * bitmap_set_bit: symbol of the bitmap declared by DECLARE_BITMAP
>> + * bit: bit number to be set in the bitmap
>> + * tmp1-tmp4: temporary registers used for the computation
>> + *
>> + * Preserves bit.
> Here you say it is preserved, yet...
>
>> + * Output:
>> + * tmp1: Address of the word containing the changed bit.
>> + * Clobbers: bit, tmp1, tmp2, tmp3, tmp4.
> ... here you list is as clobbered.
right, I’ll fix that
>
>> + */
>> +.macro bitmap_set_bit bitmap_symbol, bit, tmp1, tmp2, tmp3, tmp4
>> + adr_l \tmp1, \bitmap_symbol
>> + mov \tmp2, #(BYTES_PER_LONG - 1)
>> + mvn \tmp2, \tmp2
>> + lsr \tmp3, \bit, #3
>> + and \tmp2, \tmp3, \tmp2
>> + add \tmp1, \tmp1, \tmp2 // bitmap_symbol + (bit/BITS_PER_LONG)*BYTES_PER_LONG
> We don't use // style comments. Please use /* */
sure, I’ll change here and in the rest of the patch
>>
>>
>> #define MPU_REGION_SHIFT 6
>> @@ -17,6 +21,7 @@
>> #define NUM_MPU_REGIONS_SHIFT 8
>> #define NUM_MPU_REGIONS (_AC(1, UL) << NUM_MPU_REGIONS_SHIFT)
>> #define NUM_MPU_REGIONS_MASK (NUM_MPU_REGIONS - 1)
>> +#define MAX_MPU_REGION_NR 255
> Shouldn't you define it using NUM_MPU_REGIONS? It should have the same
> definition as mask.
Maybe I misunderstood your comment in the previous patch, ok I will use:
#define MAX_MPU_REGION_NR NUM_MPU_REGIONS_MASK
>>
>> +
>> +.macro store_pair reg1, reg2, dst
>> + stp \reg1, \reg2, [\dst]
> Why 8 instead of 4 spaces?
I’ll fix
>>
>> /*
>> * Macro to prepare and set a EL2 MPU memory region.
>> * We will also create an according MPU memory region entry, which
>> * is a structure of pr_t, in table \prmap.
>> *
>> * sel: region selector
>> - * base: reg storing base address
>> - * limit: reg storing limit address
>> + * tmp1: reg storing base address
>> + * tmp2: reg storing limit address
> I think this change is not needed. The parameters should be named base and limit
> because this is what you expect caller to pass. Inside the function, you can do
> whatever you want with these registers and caller does not care as long as you
> mention if they are clobbered or not. Same in C world. You can reuse the
> parameter for a different internal purpose inside a function.
ok I’ll revert back
>>
>> +
>> + /* Load pair into xen_mpumap and invalidate cache */
>> + mov \tmp1, \sel
>> + lsl \tmp1, \tmp1, #XEN_MPUMAP_ENTRY_SHIFT
> You could get rid of these 2 extra instructions and instead do:
>
>> + adr_l \tmp2, xen_mpumap
>> + add \tmp2, \tmp2, \tmp1
> add \tmp2, \tmp2, \sel, lsl #XEN_MPUMAP_ENTRY_SHIFT
yep, I’ll use it
> which combines everything in one go.
>
>> + store_pair \prbar, \prlar, \tmp2
>> + invalidate_dcache_one \tmp2
>> +
>> + /* Set/clear xen_mpumap_mask bitmap */
>> + tst \prlar, #PRLAR_ELx_EN
>> + bne 2f
>> + // Region is disabled, clear the bit in the bitmap
> Comment style, here and elsewhere
>
>> + bitmap_clear_bit xen_mpumap_mask, \sel, \tmp1, \tmp2, \prbar, \prlar
>> + b 3f
>> +
>> +2:
>> + // Region is enabled, set the bit in the bitmap
>> + bitmap_set_bit xen_mpumap_mask, \sel, \tmp1, \tmp2, \prbar, \prlar
> Wouldn't it be better to first clear the entire bitmap before setting up the
> regions (i.e. all regions disabled) and then only have the set part here?
well we are going to set up all region anyway, doing that here will save some time
spent on barriers and cache invalidation, maybe not much, but still…
Cheers,
Luca
next prev parent reply other threads:[~2025-04-30 12:23 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-29 15:20 [PATCH v4 0/7] First chunk for Arm R82 and MPU support Luca Fancellu
2025-04-29 15:20 ` [PATCH v4 1/7] docs/arm: Document Xen booting protocol on Armv8-R Luca Fancellu
2025-04-29 17:11 ` Ayan Kumar Halder
2025-04-30 6:37 ` Orzel, Michal
2025-04-30 6:58 ` Luca Fancellu
2025-04-30 7:04 ` Orzel, Michal
2025-04-30 7:22 ` Luca Fancellu
2025-05-06 11:44 ` Julien Grall
2025-05-06 12:24 ` Luca Fancellu
2025-05-06 12:29 ` Julien Grall
2025-05-06 12:40 ` Luca Fancellu
2025-04-29 15:20 ` [PATCH v4 2/7] arm/mpu: Introduce MPU memory region map structure Luca Fancellu
2025-04-30 6:50 ` Orzel, Michal
2025-05-06 11:50 ` Julien Grall
2025-04-29 15:20 ` [PATCH v4 3/7] arm/mpu: Provide and populate MPU C data structures Luca Fancellu
2025-04-30 6:56 ` Luca Fancellu
2025-04-30 10:57 ` Orzel, Michal
2025-04-30 12:22 ` Luca Fancellu [this message]
2025-04-29 15:20 ` [PATCH v4 4/7] arm/mpu: Provide access to the MPU region from the C code Luca Fancellu
2025-05-05 11:56 ` Orzel, Michal
2025-05-06 8:45 ` Luca Fancellu
2025-04-29 15:20 ` [PATCH v4 5/7] arm/mpu: Introduce utility functions for the pr_t type Luca Fancellu
2025-05-05 12:08 ` Orzel, Michal
2025-05-06 8:45 ` Luca Fancellu
2025-04-29 15:20 ` [PATCH v4 6/7] arm/mpu: Provide a constructor for " Luca Fancellu
2025-04-29 17:16 ` Ayan Kumar Halder
2025-04-29 19:39 ` Luca Fancellu
2025-05-06 10:06 ` Orzel, Michal
2025-05-06 12:56 ` Luca Fancellu
2025-05-06 13:51 ` Julien Grall
2025-05-06 13:53 ` Luca Fancellu
2025-05-06 13:29 ` Luca Fancellu
2025-04-29 15:20 ` [PATCH v4 7/7] arm/mpu: Introduce MPU memory mapping flags Luca Fancellu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CE38FEAB-180D-478D-99E5-855CEEB870E9@arm.com \
--to=luca.fancellu@arm.com \
--cc=Bertrand.Marquis@arm.com \
--cc=Michal.Orzel@amd.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=julien@xen.org \
--cc=sstabellini@kernel.org \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.