[PATCH v3 08/20] xen/riscv: add new p2m types and helper macros for type classification

Oleksii Kurochko posted 20 patches 3 months ago
There is a newer version of this series
[PATCH v3 08/20] xen/riscv: add new p2m types and helper macros for type classification
Posted by Oleksii Kurochko 3 months ago
- Extended p2m_type_t with additional types: p2m_mmio_direct,
  p2m_grant_map_{rw,ro}.
- Added macros to classify memory types: P2M_RAM_TYPES, P2M_GRANT_TYPES.
- Introduced helper predicates: p2m_is_ram(), p2m_is_any_ram().
- Define p2m_mmio_direct to tell handle_passthrough_prop() from common
  code how to map device memory.

Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
---
Changes in V3:
 - Drop p2m_ram_ro.
 - Rename p2m_mmio_direct_dev to p2m_mmio_direct_io to make it more RISC-V specicific.
 - s/p2m_mmio_direct_dev/p2m_mmio_direct_io.
---
Changes in V2:
 - Drop stuff connected to foreign mapping as it isn't necessary for RISC-V
   right now.
---
 xen/arch/riscv/include/asm/p2m.h | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/xen/arch/riscv/include/asm/p2m.h b/xen/arch/riscv/include/asm/p2m.h
index 3c37a708db..5f253da1dd 100644
--- a/xen/arch/riscv/include/asm/p2m.h
+++ b/xen/arch/riscv/include/asm/p2m.h
@@ -62,8 +62,30 @@ struct p2m_domain {
 typedef enum {
     p2m_invalid = 0,    /* Nothing mapped here */
     p2m_ram_rw,         /* Normal read/write domain RAM */
+    p2m_mmio_direct_io, /* Read/write mapping of genuine Device MMIO area,
+                           PTE_PBMT_IO will be used for such mappings */
+    p2m_ext_storage,    /* Following types'll be stored outsude PTE bits: */
+    p2m_grant_map_rw,   /* Read/write grant mapping */
+    p2m_grant_map_ro,   /* Read-only grant mapping */
 } p2m_type_t;
 
+#define p2m_mmio_direct p2m_mmio_direct_io
+
+/* We use bitmaps and mask to handle groups of types */
+#define p2m_to_mask(t_) BIT(t_, UL)
+
+/* RAM types, which map to real machine frames */
+#define P2M_RAM_TYPES (p2m_to_mask(p2m_ram_rw))
+
+/* Grant mapping types, which map to a real frame in another VM */
+#define P2M_GRANT_TYPES (p2m_to_mask(p2m_grant_map_rw) | \
+                         p2m_to_mask(p2m_grant_map_ro))
+
+/* Useful predicates */
+#define p2m_is_ram(t_) (p2m_to_mask(t_) & P2M_RAM_TYPES)
+#define p2m_is_any_ram(t_) (p2m_to_mask(t_) & \
+                            (P2M_RAM_TYPES | P2M_GRANT_TYPES))
+
 #include <xen/p2m-common.h>
 
 static inline int get_page_and_type(struct page_info *page,
-- 
2.50.1
Re: [PATCH v3 08/20] xen/riscv: add new p2m types and helper macros for type classification
Posted by Jan Beulich 2 months, 3 weeks ago
On 31.07.2025 17:58, Oleksii Kurochko wrote:
> - Extended p2m_type_t with additional types: p2m_mmio_direct,
>   p2m_grant_map_{rw,ro}.
> - Added macros to classify memory types: P2M_RAM_TYPES, P2M_GRANT_TYPES.
> - Introduced helper predicates: p2m_is_ram(), p2m_is_any_ram().
> - Define p2m_mmio_direct to tell handle_passthrough_prop() from common
>   code how to map device memory.
> 
> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>

Almost ready to be acked, except for ...

> --- a/xen/arch/riscv/include/asm/p2m.h
> +++ b/xen/arch/riscv/include/asm/p2m.h
> @@ -62,8 +62,30 @@ struct p2m_domain {
>  typedef enum {
>      p2m_invalid = 0,    /* Nothing mapped here */
>      p2m_ram_rw,         /* Normal read/write domain RAM */
> +    p2m_mmio_direct_io, /* Read/write mapping of genuine Device MMIO area,
> +                           PTE_PBMT_IO will be used for such mappings */
> +    p2m_ext_storage,    /* Following types'll be stored outsude PTE bits: */
> +    p2m_grant_map_rw,   /* Read/write grant mapping */
> +    p2m_grant_map_ro,   /* Read-only grant mapping */
>  } p2m_type_t;
>  
> +#define p2m_mmio_direct p2m_mmio_direct_io

... this (see reply to patch 09).

> +/* We use bitmaps and mask to handle groups of types */
> +#define p2m_to_mask(t_) BIT(t_, UL)

I notice that you moved the underscore to the back of the parameters,
compared to how Arm has it. I wonder though: What use are these
underscores in the first place, here and below? (There are macros where
conflicts could arise, but the ones here don't fall in that group,
afaict.)

Jan
Re: [PATCH v3 08/20] xen/riscv: add new p2m types and helper macros for type classification
Posted by Oleksii Kurochko 2 months, 3 weeks ago
On 8/4/25 4:16 PM, Jan Beulich wrote:
> On 31.07.2025 17:58, Oleksii Kurochko wrote:
>> - Extended p2m_type_t with additional types: p2m_mmio_direct,
>>    p2m_grant_map_{rw,ro}.
>> - Added macros to classify memory types: P2M_RAM_TYPES, P2M_GRANT_TYPES.
>> - Introduced helper predicates: p2m_is_ram(), p2m_is_any_ram().
>> - Define p2m_mmio_direct to tell handle_passthrough_prop() from common
>>    code how to map device memory.
>>
>> Signed-off-by: Oleksii Kurochko<oleksii.kurochko@gmail.com>
> Almost ready to be acked, except for ...
>
>> --- a/xen/arch/riscv/include/asm/p2m.h
>> +++ b/xen/arch/riscv/include/asm/p2m.h
>> @@ -62,8 +62,30 @@ struct p2m_domain {
>>   typedef enum {
>>       p2m_invalid = 0,    /* Nothing mapped here */
>>       p2m_ram_rw,         /* Normal read/write domain RAM */
>> +    p2m_mmio_direct_io, /* Read/write mapping of genuine Device MMIO area,
>> +                           PTE_PBMT_IO will be used for such mappings */
>> +    p2m_ext_storage,    /* Following types'll be stored outsude PTE bits: */
>> +    p2m_grant_map_rw,   /* Read/write grant mapping */
>> +    p2m_grant_map_ro,   /* Read-only grant mapping */
>>   } p2m_type_t;
>>   
>> +#define p2m_mmio_direct p2m_mmio_direct_io
> ... this (see reply to patch 09).
>
>> +/* We use bitmaps and mask to handle groups of types */
>> +#define p2m_to_mask(t_) BIT(t_, UL)
> I notice that you moved the underscore to the back of the parameters,
> compared to how Arm has it. I wonder though: What use are these
> underscores in the first place, here and below? (There are macros where
> conflicts could arise, but the ones here don't fall in that group,
> afaict.)

Good point, there is really no name conflicts here, so underscore could
be just dropped.

~ Oleksii