From: Ayan Kumar Halder <ayankuma@amd.com>
To: Penny Zheng <Penny.Zheng@arm.com>, xen-devel@lists.xenproject.org
Cc: Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien@xen.org>,
Bertrand Marquis <bertrand.marquis@arm.com>,
Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>,
Wei Chen <wei.chen@arm.com>
Subject: Re: [PATCH v3 34/52] xen/mpu: destroy an existing entry in Xen MPU memory mapping table
Date: Fri, 30 Jun 2023 17:17:38 +0100 [thread overview]
Message-ID: <87564d07-391b-7dfa-e28f-e13d73e67811@amd.com> (raw)
In-Reply-To: <20230626033443.2943270-35-Penny.Zheng@arm.com>
On 26/06/2023 04:34, Penny Zheng wrote:
> CAUTION: This message has originated from an External Source. Please use proper judgment and caution when opening attachments, clicking links, or responding to this email.
>
>
> This commit expands xen_mpumap_update/xen_mpumap_update_entry to include
> destroying an existing entry.
>
> We define a new helper "control_xen_mpumap_region_from_index" to enable/disable
> the MPU region based on index. If region is within [0, 31], we could quickly
> disable the MPU region through PRENR_EL2 which provides direct access to the
> PRLAR_EL2.EN bits of EL2 MPU regions.
>
> Rignt now, we only support destroying a *WHOLE* MPU memory region,
> part-region removing is not supported, as in worst case, it will
> leave two fragments behind.
>
> Signed-off-by: Penny Zheng <penny.zheng@arm.com>
> Signed-off-by: Wei Chen <wei.chen@arm.com>
> ---
> v3:
> - make pr_get_base()/pr_get_limit() static inline
> - need an isb to ensure register write visible before zeroing the entry
> ---
> xen/arch/arm/include/asm/arm64/mpu.h | 2 +
> xen/arch/arm/include/asm/arm64/sysregs.h | 3 +
> xen/arch/arm/mm.c | 5 ++
> xen/arch/arm/mpu/mm.c | 74 ++++++++++++++++++++++++
> 4 files changed, 84 insertions(+)
>
> diff --git a/xen/arch/arm/include/asm/arm64/mpu.h b/xen/arch/arm/include/asm/arm64/mpu.h
> index 715ea69884..aee7947223 100644
> --- a/xen/arch/arm/include/asm/arm64/mpu.h
> +++ b/xen/arch/arm/include/asm/arm64/mpu.h
> @@ -25,6 +25,8 @@
> #define REGION_UART_SEL 0x07
> #define MPUIR_REGION_MASK ((_AC(1, UL) << 8) - 1)
>
> +#define MPU_PRENR_BITS 32
This is common to R52 and R82.
Thus, you can put it in the common file (may be
xen/arch/arm/include/asm/mpu/mm.h)
> +
> /* Access permission attributes. */
> /* Read/Write at EL2, No Access at EL1/EL0. */
> #define AP_RW_EL2 0x0
> diff --git a/xen/arch/arm/include/asm/arm64/sysregs.h b/xen/arch/arm/include/asm/arm64/sysregs.h
> index c8a679afdd..96c025053b 100644
> --- a/xen/arch/arm/include/asm/arm64/sysregs.h
> +++ b/xen/arch/arm/include/asm/arm64/sysregs.h
> @@ -509,6 +509,9 @@
> /* MPU Type registers encode */
> #define MPUIR_EL2 S3_4_C0_C0_4
>
> +/* MPU Protection Region Enable Register encode */
> +#define PRENR_EL2 S3_4_C6_C1_1
> +
> #endif
>
> /* Access to system registers */
> diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c
> index 8625066256..247d17cfa1 100644
> --- a/xen/arch/arm/mm.c
> +++ b/xen/arch/arm/mm.c
> @@ -164,7 +164,12 @@ int destroy_xen_mappings(unsigned long s, unsigned long e)
> ASSERT(IS_ALIGNED(s, PAGE_SIZE));
> ASSERT(IS_ALIGNED(e, PAGE_SIZE));
> ASSERT(s <= e);
> +#ifndef CONFIG_HAS_MPU
> return xen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, 0);
> +#else
> + return xen_mpumap_update(virt_to_maddr((void *)s),
> + virt_to_maddr((void *)e), 0);
> +#endif
> }
Refer my comment in previous patch.
You can have two implementations of this function 1)
xen/arch/arm/mmu/mm.c 2) xen/arch/arm/mpu/mm.h
>
> int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int flags)
> diff --git a/xen/arch/arm/mpu/mm.c b/xen/arch/arm/mpu/mm.c
> index 0a65b58dc4..a40055ae5e 100644
> --- a/xen/arch/arm/mpu/mm.c
> +++ b/xen/arch/arm/mpu/mm.c
> @@ -425,6 +425,59 @@ static int mpumap_contain_region(pr_t *table, uint8_t nr_regions,
> return MPUMAP_REGION_FAILED;
> }
>
> +/* Disable or enable EL2 MPU memory region at index #index */
> +static void control_mpu_region_from_index(uint8_t index, bool enable)
> +{
> + pr_t region;
> +
> + read_protection_region(®ion, index);
> + if ( !region_is_valid(®ion) ^ enable )
> + {
> + printk(XENLOG_WARNING
> + "mpu: MPU memory region[%u] is already %s\n", index,
> + enable ? "enabled" : "disabled");
> + return;
> + }
> +
> + /*
> + * ARM64v8R provides PRENR_EL2 to have direct access to the
> + * PRLAR_EL2.EN bits of EL2 MPU regions from 0 to 31.
> + */
> + if ( index < MPU_PRENR_BITS )
> + {
> + uint64_t orig, after;
> +
> + orig = READ_SYSREG(PRENR_EL2);
> + if ( enable )
> + /* Set respective bit */
> + after = orig | (1UL << index);
> + else
> + /* Clear respective bit */
> + after = orig & (~(1UL << index));
> + WRITE_SYSREG(after, PRENR_EL2);
> + }
> + else
> + {
> + region.prlar.reg.en = enable ? 1 : 0;
> + write_protection_region((const pr_t*)®ion, index);
> + }
> + /* Ensure the write before zeroing the entry */
dsb(); /* to ensure write completes */
> + isb();
> +
> + /* Update according bitfield in xen_mpumap_mask */
> + spin_lock(&xen_mpumap_alloc_lock);
> +
> + if ( enable )
> + set_bit(index, xen_mpumap_mask);
> + else
> + {
> + clear_bit(index, xen_mpumap_mask);
> + memset(&xen_mpumap[index], 0, sizeof(pr_t));
> + }
> +
> + spin_unlock(&xen_mpumap_alloc_lock);
> +}
> +
> /*
> * Update an entry in Xen MPU memory region mapping table(xen_mpumap) at
> * the index @idx.
> @@ -461,6 +514,27 @@ static int xen_mpumap_update_entry(paddr_t base, paddr_t limit,
>
> write_protection_region((const pr_t*)(&xen_mpumap[idx]), idx);
> }
> + else
> + {
> + /*
> + * Currently, we only support destroying a *WHOLE* MPU memory region,
> + * part-region removing is not supported, as in worst case, it will
> + * leave two fragments behind.
> + * part-region removing will be introduced only when actual usage
> + * comes.
> + */
> + if ( rc == MPUMAP_REGION_INCLUSIVE )
> + {
> + region_printk("mpu: part-region removing is not supported\n");
> + return -EINVAL;
> + }
> +
> + /* We are removing the region */
> + if ( rc != MPUMAP_REGION_FOUND )
> + return -EINVAL;
> +
> + control_mpu_region_from_index(idx, false);
> + }
>
> return 0;
> }
> --
> 2.25.1
>
>
- Ayan
next prev parent reply other threads:[~2023-06-30 16:18 UTC|newest]
Thread overview: 160+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-26 3:33 [PATCH v3 00/52] xen/arm: Add Armv8-R64 MPU support to Xen - Part#1 Penny Zheng
2023-06-26 3:33 ` [PATCH v3 01/52] xen/arm: remove xen_phys_start and xenheap_phys_end from config.h Penny Zheng
2023-06-26 3:33 ` [PATCH v3 02/52] xen/arm: make ARM_EFI selectable for Arm64 Penny Zheng
2023-06-28 8:05 ` Julien Grall
2023-07-05 11:20 ` [RANDCONFIG failure] " Andrew Cooper
2023-07-05 11:46 ` Julien Grall
2023-07-05 11:58 ` Julien Grall
2023-06-26 3:33 ` [PATCH v3 03/52] xen/arm: add an option to define Xen start address for Armv8-R Penny Zheng
2023-07-04 10:36 ` Ayan Kumar Halder
2023-07-04 11:47 ` Julien Grall
2023-07-04 12:02 ` Ayan Kumar Halder
2023-07-04 12:10 ` Julien Grall
2023-07-06 6:36 ` Penny Zheng
2023-07-04 19:21 ` Julien Grall
2023-07-06 6:38 ` Penny Zheng
2023-06-26 3:33 ` [PATCH v3 04/52] xen/arm: add .text.idmap in ld script for Xen identity map sections Penny Zheng
2023-07-04 19:24 ` Julien Grall
2023-06-26 3:33 ` [PATCH v3 05/52] xen/arm64: head: Introduce enable_boot_mmu and enable_runtime_mmu Penny Zheng
2023-07-04 11:07 ` Ayan Kumar Halder
2023-07-04 21:24 ` Julien Grall
2023-07-05 3:41 ` Penny Zheng
2023-06-26 3:33 ` [PATCH v3 06/52] xen/arm: introduce CONFIG_HAS_MMU Penny Zheng
2023-07-04 11:14 ` Ayan Kumar Halder
2023-07-04 11:44 ` Julien Grall
2023-07-04 12:04 ` Ayan Kumar Halder
2023-07-05 3:55 ` Penny Zheng
2023-06-26 3:33 ` [PATCH v3 07/52] xen/arm64: prepare for moving MMU related code from head.S Penny Zheng
2023-07-04 21:35 ` Julien Grall
2023-07-05 4:07 ` Penny Zheng
2023-06-26 3:33 ` [PATCH v3 08/52] xen/arm64: move MMU related code from head.S to mmu/head.S Penny Zheng
2023-07-04 11:51 ` Ayan Kumar Halder
2023-07-04 21:46 ` Julien Grall
2023-07-05 4:49 ` Penny Zheng
2023-07-05 10:11 ` Julien Grall
2023-07-05 10:43 ` Julien Grall
2023-07-06 6:47 ` Penny Zheng
2023-06-26 3:34 ` [PATCH v3 09/52] xen/arm: use PA == VA for EARLY_UART_VIRTUAL_ADDRESS on MPU systems Penny Zheng
2023-07-04 19:25 ` Julien Grall
2023-07-06 7:05 ` Penny Zheng
2023-06-26 3:34 ` [PATCH v3 10/52] xen/arm: Move MMU related definitions from config.h to mmu/layout.h Penny Zheng
2023-07-04 21:54 ` Julien Grall
2023-07-05 6:51 ` Penny Zheng
2023-07-05 10:30 ` Julien Grall
2023-07-06 7:36 ` Penny Zheng
2023-07-06 8:08 ` Julien Grall
2023-06-26 3:34 ` [PATCH v3 11/52] xen/arm: mmu: fold FIXMAP into MMU system Penny Zheng
2023-07-04 22:12 ` Julien Grall
2023-07-05 8:19 ` Penny Zheng
2023-07-05 10:31 ` Julien Grall
2023-07-06 8:00 ` Penny Zheng
2023-06-26 3:34 ` [PATCH v3 12/52] xen/mmu: extract early uart mapping from setup_fixmap Penny Zheng
2023-07-04 22:25 ` Julien Grall
2023-07-05 9:03 ` Penny Zheng
2023-07-05 10:35 ` Julien Grall
2023-07-06 8:01 ` Penny Zheng
2023-06-26 3:34 ` [PATCH v3 13/52] xen/mmu: extract mmu-specific codes from mm.c/mm.h Penny Zheng
2023-06-26 3:34 ` [PATCH v3 14/52] xen/mmu: move MMU-specific setup_mm to mmu/setup.c Penny Zheng
2023-06-26 3:34 ` [PATCH v3 15/52] xen: make VMAP only support in MMU system Penny Zheng
2023-06-26 6:00 ` Jan Beulich
2023-06-28 5:38 ` Penny Zheng
2023-06-28 7:59 ` Julien Grall
2023-06-28 8:41 ` Penny Zheng
2023-06-28 8:53 ` Julien Grall
2023-07-04 12:21 ` Jan Beulich
2023-06-26 3:34 ` [PATCH v3 16/52] xen/mmu: relocate copy_from_paddr into setup.c Penny Zheng
2023-06-26 3:34 ` [PATCH v3 17/52] xen/arm: do not give memory back to static heap Penny Zheng
2023-06-26 3:34 ` [PATCH v3 18/52] xen/arm: only map the init text section RW in free_init_memory Penny Zheng
2023-06-26 3:34 ` [PATCH v3 19/52] xen/arm: switch to use ioremap_xxx in common file Penny Zheng
2023-06-26 3:34 ` [PATCH v3 20/52] xen/mmu: move MMU specific P2M code to mmu/p2m.c and mmu/p2m.h Penny Zheng
2023-06-26 3:34 ` [PATCH v3 21/52] xen: introduce CONFIG_HAS_PAGING_MEMPOOL Penny Zheng
2023-06-26 7:01 ` Jan Beulich
2023-06-28 5:40 ` Penny Zheng
2023-06-26 3:34 ` [PATCH v3 22/52] xen/mmu: enable SMMU subsystem only in MMU Penny Zheng
2023-06-26 3:34 ` [PATCH v3 23/52] xen/arm: create mpu/layout.h for MPU related address definitions Penny Zheng
2023-06-26 3:34 ` [PATCH v3 24/52] xen/mpu: build up start-of-day Xen MPU memory region map Penny Zheng
2023-06-28 10:55 ` Ayan Kumar Halder
2023-06-28 11:17 ` Julien Grall
2023-06-28 13:22 ` Ayan Kumar Halder
2023-06-28 13:42 ` Julien Grall
2023-06-29 11:21 ` Ayan Kumar Halder
2023-06-29 11:55 ` Julien Grall
2023-06-30 9:26 ` Ayan Kumar Halder
2023-06-30 9:43 ` Julien Grall
2023-06-30 10:09 ` Andrew Cooper
2023-06-26 3:34 ` [PATCH v3 25/52] xen/mpu: introduce helpers for MPU enablement Penny Zheng
2023-06-26 3:34 ` [PATCH v3 26/52] xen/mpu: map early uart when earlyprintk on Penny Zheng
2023-06-26 3:34 ` [PATCH v3 27/52] xen/mpu: introduce setup_mm_mappings Penny Zheng
2023-06-29 14:05 ` Ayan Kumar Halder
2023-06-29 14:29 ` Julien Grall
2023-06-29 14:50 ` Ayan Kumar Halder
2023-06-30 2:41 ` Penny Zheng
2023-06-26 3:34 ` [PATCH v3 28/52] xen/mpu: plump virt/maddr conversion in MPU system Penny Zheng
2023-06-29 14:20 ` Ayan Kumar Halder
2023-06-29 14:23 ` Andrew Cooper
2023-06-29 14:44 ` Ayan Kumar Halder
2023-06-29 15:14 ` Julien Grall
2023-06-30 2:40 ` Penny Zheng
2023-06-26 3:34 ` [PATCH v3 29/52] xen/mpu: introduce a pair helper read_protection_region()/write_protection_region() Penny Zheng
2023-06-26 3:34 ` [PATCH v3 30/52] xen/mpu: populate a new region in Xen MPU mapping table Penny Zheng
2023-06-28 10:05 ` Ayan Kumar Halder
2023-06-28 10:08 ` Ayan Kumar Halder
2023-06-28 10:13 ` Penny Zheng
2023-06-26 3:34 ` [PATCH v3 31/52] xen/mpu: make early_fdt_map support in MPU systems Penny Zheng
2023-06-29 17:22 ` Ayan Kumar Halder
2023-06-30 4:07 ` Penny Zheng
2023-06-30 10:49 ` Ayan Kumar Halder
2023-06-30 11:22 ` Julien Grall
2023-06-30 14:42 ` Ayan Kumar Halder
2023-06-30 15:02 ` Julien Grall
2023-07-03 5:12 ` Penny Zheng
2023-07-03 9:20 ` Julien Grall
2023-07-13 3:12 ` Penny Zheng
2023-07-14 16:44 ` Julien Grall
2023-06-26 3:34 ` [PATCH v3 32/52] xen/mpu: implement MPU version of setup_mm in mpu/setup.c Penny Zheng
2023-06-26 3:34 ` [PATCH v3 33/52] xen/mpu: initialize frametable in MPU system Penny Zheng
2023-06-30 15:19 ` Ayan Kumar Halder
2023-07-03 6:10 ` Penny Zheng
2023-07-03 9:31 ` Julien Grall
2023-07-05 9:53 ` Penny Zheng
2023-07-05 13:52 ` Julien Grall
2023-07-13 7:16 ` Penny Zheng
2023-06-26 3:34 ` [PATCH v3 34/52] xen/mpu: destroy an existing entry in Xen MPU memory mapping table Penny Zheng
2023-06-30 16:17 ` Ayan Kumar Halder [this message]
2023-07-03 7:08 ` Penny Zheng
2023-06-26 3:34 ` [PATCH v3 35/52] xen/arm: map static memory on demand Penny Zheng
2023-07-04 15:10 ` Ayan Kumar Halder
2023-07-05 10:16 ` Penny Zheng
2023-07-05 13:33 ` Ayan Kumar Halder
2023-07-13 5:59 ` Penny Zheng
2023-06-26 3:34 ` [PATCH v3 36/52] xen/mpu: implememt ioremap_xxx in MPU Penny Zheng
2023-07-05 14:01 ` Ayan Kumar Halder
2023-07-13 7:09 ` Penny Zheng
2023-06-26 3:34 ` [PATCH v3 37/52] xen/mpu: implement MPU version of copy_from_paddr Penny Zheng
2023-06-26 3:34 ` [PATCH v3 38/52] xen/mpu: map domain page in MPU system Penny Zheng
2023-06-26 3:34 ` [PATCH v3 39/52] xen/mpu: support free_init_memory " Penny Zheng
2023-06-26 3:34 ` [PATCH v3 40/52] xen/mpu: implement remove_early_mappings " Penny Zheng
2023-06-26 3:34 ` [PATCH v3 41/52] xen/mpu: Use secure hypervisor timer " Penny Zheng
2023-06-26 3:34 ` [PATCH v3 42/52] xen/mpu: implement setup_virt_paging for " Penny Zheng
2023-07-04 17:49 ` Ayan Kumar Halder
2023-07-05 10:20 ` Penny Zheng
2023-06-26 3:34 ` [PATCH v3 43/52] xen/mpu: configure VSTCR_EL2 in " Penny Zheng
2023-07-05 14:21 ` Ayan Kumar Halder
2023-07-13 7:12 ` Penny Zheng
2023-06-26 3:34 ` [PATCH v3 44/52] xen/mpu: P2M initialization " Penny Zheng
2023-07-05 15:35 ` Ayan Kumar Halder
2023-07-13 7:22 ` Penny Zheng
2023-06-26 3:34 ` [PATCH v3 45/52] xen/mpu: insert an new entry into guest physmap " Penny Zheng
2023-07-05 16:27 ` Ayan Kumar Halder
2023-06-26 3:34 ` [PATCH v3 46/52] xen/mpu: look up entry in p2m table Penny Zheng
2023-06-26 3:34 ` [PATCH v3 47/52] xen/mpu: support vcpu context switch in MPU system Penny Zheng
2023-06-26 3:34 ` [PATCH v3 48/52] xen/mpu: enable MMIO region trap " Penny Zheng
2023-06-26 3:34 ` [PATCH v3 49/52] xen/mpu: enable device passthrough " Penny Zheng
2023-06-26 3:34 ` [PATCH v3 50/52] xen/mpu: dump debug message " Penny Zheng
2023-06-26 3:34 ` [PATCH v3 51/52] xen/mpu: create stubs of function/variables for UNSUPPORTED features Penny Zheng
2023-06-26 3:34 ` [PATCH v3 52/52] xen/arm: add Kconfig option CONFIG_HAS_MPU to enable MPU system support Penny Zheng
2023-07-05 17:20 ` Ayan Kumar Halder
2023-07-05 19:51 ` Julien Grall
2023-07-04 14:17 ` [PATCH v3 00/52] xen/arm: Add Armv8-R64 MPU support to Xen - Part#1 Ayan Kumar Halder
2023-07-04 19:19 ` Julien Grall
2023-07-05 10:40 ` Julien Grall
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=87564d07-391b-7dfa-e28f-e13d73e67811@amd.com \
--to=ayankuma@amd.com \
--cc=Penny.Zheng@arm.com \
--cc=Volodymyr_Babchuk@epam.com \
--cc=bertrand.marquis@arm.com \
--cc=julien@xen.org \
--cc=sstabellini@kernel.org \
--cc=wei.chen@arm.com \
--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.