Skip to contentSkip to conversation

xen/mm: Introduce pte_attr_t

PATCH In review Andrew Cooper 4 participants 17 messages Apr 25, 2025 – May 1, 2025 RISC-V

lore
Share & tools
lore
#0 lore raw

v5 cover xen/mm: Introduce pte_attr_t

This is in order to support PPC needing wider flags, but I've also written it as a showcase of the new __has_include().

https://gitlab.com/xen-project/hardware/xen-staging/-/pipelines/1786141700

Andrew Cooper (1):
xen/mm: Introduce mm-types.h

Shawn Anastasio (2):
xen/mm: Switch some APIs over to pte_attr_t
ppc/mm: Introduce mm-types.h

 xen/arch/arm/mmu/pt.c               |  4 ++--
 xen/arch/ppc/include/asm/mm-types.h |  7 +++++++
 xen/arch/ppc/mm-radix.c             |  2 +-
 xen/arch/riscv/pt.c                 |  2 +-
 xen/arch/x86/mm.c                   |  6 +++---
 xen/common/efi/boot.c               |  4 ++--
 xen/common/vmap.c                   |  2 +-
 xen/include/xen/mm-types.h          | 19 +++++++++++++++++++
 xen/include/xen/mm.h                |  7 ++++---
 xen/include/xen/vmap.h              |  3 ++-
 10 files changed, 42 insertions(+), 14 deletions(-)
 create mode 100644 xen/arch/ppc/include/asm/mm-types.h
 create mode 100644 xen/include/xen/mm-types.h

base-commit: 6dc1b711ded0e477c501d4017ccb0da83d6d56a1

Signature · 1 line
2.39.5
#1 lore raw

PATCH v5 1/3 xen/mm: Introduce mm-types.h

The type used for pagetable attributes/permissions is currently unsigned int, but needs to become architecture dependent as PPC needs unsigned long.

Introduce mm-types.h to house pte_attr_t.

Given the new toolchain baseline, we can use __has_include() now to remove the need for boilerplate on most architectures.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>

__has_include() was one of the justifications for the new toolchain baseline, and is included in https://gitlab.com/xen-project/xen/-/issues/201

---
 xen/include/xen/mm-types.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 xen/include/xen/mm-types.h
xen/include/xen/mm-types.h new file +19 -0
new file mode 100644
index 000000000000..19f692e9aaa4
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef XEN_MM_TYPES_H
+#define XEN_MM_TYPES_H
+
+/*
+ * Types used to abstract away architecture-specific details in the memory
+ * management code.
+ *
+ * Architectures need only provide their own asm/mm-types.h if they want to
+ * override the defaults given here.
+ */
+#if __has_include(<asm/mm-types.h>)
+# include <asm/mm-types.h>
+#else /* !__has_include(<asm/mm-types.h>) */
+
+typedef unsigned int pte_attr_t;
+
+#endif /* !__has_include(<asm/mm-types.h>) */
+#endif /* XEN_MM_TYPES_H */
Signature · 1 line
2.39.5
Reviewed-by on v5 1/3
#2 lore raw

Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h

Quoted 2 lines · Andrew Cooper

The type used for pagetable attributes/permissions is currently unsigned int, but needs to become architecture dependent as PPC needs unsigned long.

Not only PPC, RISC-V needs it too.

Quoted 2 lines

Introduce mm-types.h to house pte_attr_t.

Do we really want a separate mm-types.h?
If yes then:

~ Oleksii

Quoted 48 lines

Given the new toolchain baseline, we can use __has_include() now to remove the need for boilerplate on most architectures.

---
CC: Jan Beulich<[email protected]>
CC: Roger Pau Monné<[email protected]>
CC: Stefano Stabellini<[email protected]>
CC: Julien Grall<[email protected]>
CC: Volodymyr Babchuk<[email protected]>
CC: Bertrand Marquis<[email protected]>
CC: Michal Orzel<[email protected]>
CC: Oleksii Kurochko<[email protected]>
CC: Shawn Anastasio<[email protected]>

__has_include() was one of the justifications for the new toolchain baseline, and is included inhttps://gitlab.com/xen-project/xen/-/issues/201

---
  xen/include/xen/mm-types.h | 19 +++++++++++++++++++
  1 file changed, 19 insertions(+)

create mode 100644 xen/include/xen/mm-types.h

xen/include/xen/mm-types.h new file +19 -0
new file mode 100644
index 000000000000..19f692e9aaa4
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef XEN_MM_TYPES_H
+#define XEN_MM_TYPES_H
+
+/*
+ * Types used to abstract away architecture-specific details in the memory
+ * management code.
+ *
+ * Architectures need only provide their own asm/mm-types.h if they want to
+ * override the defaults given here.
+ */
+#if __has_include(<asm/mm-types.h>)
+# include <asm/mm-types.h>
+#else /* !__has_include(<asm/mm-types.h>) */
+
+typedef unsigned int pte_attr_t;
+
+#endif /* !__has_include(<asm/mm-types.h>) */
+#endif /* XEN_MM_TYPES_H */
#3 lore raw

Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h

Quoted 11 lines · Oleksii Kurochko
Quoted 2 lines · Andrew Cooper

The type used for pagetable attributes/permissions is currently unsigned int, but needs to become architecture dependent as PPC needs unsigned long.

Not only PPC, RISC-V needs it too.

Quoted 2 lines

Introduce mm-types.h to house pte_attr_t.

Do we really want a separate mm-types.h?

I think so, yes. It'll (hopefully) allow to avoid including xen/mm.h in a few places, in the longer run.

Jan

#4 lore raw

Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h

Quoted 10 lines · Jan Beulich
Quoted 7 lines · Oleksii Kurochko
Quoted 2 lines · Andrew Cooper

The type used for pagetable attributes/permissions is currently unsigned int, but needs to become architecture dependent as PPC needs unsigned long.

Not only PPC, RISC-V needs it too.

Quoted 1 line

Introduce mm-types.h to house pte_attr_t.

Do we really want a separate mm-types.h?

I think so, yes. It'll (hopefully) allow to avoid including xen/mm.h in a few places, in the longer run.

Yes, that's the intention.  We need to use this pattern here and elsewhere (especially sched.h) to avoid having most TUs pull in most of the world.

~Andrew

#5 lore raw

Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h

In reply to Andrew Cooper
Quoted 7 lines · Andrew Cooper

The type used for pagetable attributes/permissions is currently unsigned int, but needs to become architecture dependent as PPC needs unsigned long.

Introduce mm-types.h to house pte_attr_t.

Given the new toolchain baseline, we can use __has_include() now to remove the need for boilerplate on most architectures.

That's true now, when it's just pte_attr_t that's there. Memory management, however, is pretty different between architectures, so I wonder if in the longer run any one will remain that actually can use the common header.

Jan

#6 lore raw

Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h

Quoted 11 lines · Jan Beulich
Quoted 7 lines · Andrew Cooper

The type used for pagetable attributes/permissions is currently unsigned int, but needs to become architecture dependent as PPC needs unsigned long.

Introduce mm-types.h to house pte_attr_t.

Given the new toolchain baseline, we can use __has_include() now to remove the need for boilerplate on most architectures.

That's true now, when it's just pte_attr_t that's there. Memory management, however, is pretty different between architectures, so I wonder if in the longer run any one will remain that actually can use the common header.

Anything in xen/mm.h is common and needs architectures to provide (or use the defaults) the bits required.

asm/mm{,-types.h} still exist (when necessary) to provide the arch-specific extensions.

~Andrew

#7 lore raw

Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h

Quoted 13 lines · Andrew Cooper
Quoted 11 lines · Jan Beulich
Quoted 7 lines · Andrew Cooper

The type used for pagetable attributes/permissions is currently unsigned int, but needs to become architecture dependent as PPC needs unsigned long.

Introduce mm-types.h to house pte_attr_t.

Given the new toolchain baseline, we can use __has_include() now to remove the need for boilerplate on most architectures.

That's true now, when it's just pte_attr_t that's there. Memory management, however, is pretty different between architectures, so I wonder if in the longer run any one will remain that actually can use the common header.

Quoted 5 lines

Anything in xen/mm.h is common and needs architectures to provide (or use the defaults) the bits required.

asm/mm{,-types.h} still exist (when necessary) to provide the arch-specific extensions.

Sure, but you kind of avoid my question: Are you reasonably certain more than one arch will still be able to use the defaults, once a few more things appear in this header? (IOW: Won't we be better off having each arch have its asm/mm-types.h right away?)

Jan

#8 lore raw

Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h

Quoted 16 lines · Jan Beulich
Quoted 15 lines · Andrew Cooper
Quoted 11 lines · Jan Beulich
Quoted 7 lines · Andrew Cooper

The type used for pagetable attributes/permissions is currently unsigned int, but needs to become architecture dependent as PPC needs unsigned long.

Introduce mm-types.h to house pte_attr_t.

Given the new toolchain baseline, we can use __has_include() now to remove the need for boilerplate on most architectures.

That's true now, when it's just pte_attr_t that's there. Memory management, however, is pretty different between architectures, so I wonder if in the longer run any one will remain that actually can use the common header.

Anything in xen/mm.h is common and needs architectures to provide (or use the defaults) the bits required.

Quoted 6 lines
Quoted 2 lines

asm/mm{,-types.h} still exist (when necessary) to provide the arch-specific extensions.

Sure, but you kind of avoid my question: Are you reasonably certain more than one arch will still be able to use the defaults, once a few more things appear in this header? (IOW: Won't we be better off having each arch have its asm/mm-types.h right away?)

I can't predict the future, but my gut feeling is that it's not going to diverge very much.

If needs be, we can go to conditional override for specific bits.  Or, if I'm wrong, I'm wrong.  It's not hard to change.

~Andrew

#9 lore raw

Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h

Quoted 24 lines · Andrew Cooper
Quoted 16 lines · Jan Beulich
Quoted 15 lines · Andrew Cooper
Quoted 11 lines · Jan Beulich
Quoted 7 lines · Andrew Cooper

The type used for pagetable attributes/permissions is currently unsigned int, but needs to become architecture dependent as PPC needs unsigned long.

Introduce mm-types.h to house pte_attr_t.

Given the new toolchain baseline, we can use __has_include() now to remove the need for boilerplate on most architectures.

That's true now, when it's just pte_attr_t that's there. Memory management, however, is pretty different between architectures, so I wonder if in the longer run any one will remain that actually can use the common header.

Anything in xen/mm.h is common and needs architectures to provide (or use the defaults) the bits required.

Quoted 6 lines
Quoted 2 lines

asm/mm{,-types.h} still exist (when necessary) to provide the arch-specific extensions.

Sure, but you kind of avoid my question: Are you reasonably certain more than one arch will still be able to use the defaults, once a few more things appear in this header? (IOW: Won't we be better off having each arch have its asm/mm-types.h right away?)

Quoted 5 lines

I can't predict the future, but my gut feeling is that it's not going to diverge very much.

If needs be, we can go to conditional override for specific bits.  Or, if I'm wrong, I'm wrong.  It's not hard to change.

Well, feel free then to put in with Oleksii's R-b.

Jan

Reviewed-by on v5 1/3
#10 lore raw

Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h

In reply to Andrew Cooper
Quoted 9 lines · Andrew Cooper

The type used for pagetable attributes/permissions is currently unsigned int, but needs to become architecture dependent as PPC needs unsigned long.

Introduce mm-types.h to house pte_attr_t.

Given the new toolchain baseline, we can use __has_include() now to remove the need for boilerplate on most architectures.

Quoted 46 lines

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>

__has_include() was one of the justifications for the new toolchain baseline, and is included in https://gitlab.com/xen-project/xen/-/issues/201

---
 xen/include/xen/mm-types.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 xen/include/xen/mm-types.h
xen/include/xen/mm-types.h new file +19 -0
new file mode 100644
index 000000000000..19f692e9aaa4
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef XEN_MM_TYPES_H
+#define XEN_MM_TYPES_H
+
+/*
+ * Types used to abstract away architecture-specific details in the memory
+ * management code.
+ *
+ * Architectures need only provide their own asm/mm-types.h if they want to
+ * override the defaults given here.
+ */
+#if __has_include(<asm/mm-types.h>)
+# include <asm/mm-types.h>
+#else /* !__has_include(<asm/mm-types.h>) */
+
+typedef unsigned int pte_attr_t;
+
+#endif /* !__has_include(<asm/mm-types.h>) */
+#endif /* XEN_MM_TYPES_H */
Signature · 1 line
2.39.5
#11 lore raw

PATCH v5 2/3 xen/mm: Switch some APIs over to pte_attr_t

In reply to Andrew Cooper

From: Shawn Anastasio <[email protected]>

Several APIs take an architecture-dependent set of flags in an unsigned int, but this needs to be a wider type to support PPC.

The new type pte_attr_t has been introduced for this purpose, so switch to it in map_pages_to_xen(), __vmap() and modify_xen_mappings{,_lite}().

No functional change.

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>

---
 xen/arch/arm/mmu/pt.c   | 4 ++--
 xen/arch/ppc/mm-radix.c | 2 +-
 xen/arch/riscv/pt.c     | 2 +-
 xen/arch/x86/mm.c       | 6 +++---
 xen/common/efi/boot.c   | 4 ++--
 xen/common/vmap.c       | 2 +-
 xen/include/xen/mm.h    | 7 ++++---
 xen/include/xen/vmap.h  | 3 ++-
 8 files changed, 16 insertions(+), 14 deletions(-)
xen/arch/arm/mmu/pt.c +2 -2
index 11cb1c66dac8..4726e713efd3 100644
@@ -696,7 +696,7 @@ static int xen_pt_update(unsigned long virt,
 int map_pages_to_xen(unsigned long virt,
                      mfn_t mfn,
                      unsigned long nr_mfns,
-                     unsigned int flags)
+                     pte_attr_t flags)
 {
     return xen_pt_update(virt, mfn, nr_mfns, flags);
 }
@@ -714,7 +714,7 @@ int destroy_xen_mappings(unsigned long s, unsigned long e)
     return xen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, 0);
 }
 
-int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)
+int modify_xen_mappings(unsigned long s, unsigned long e, pte_attr_t nf)
 {
     ASSERT(IS_ALIGNED(s, PAGE_SIZE));
     ASSERT(IS_ALIGNED(e, PAGE_SIZE));
xen/arch/ppc/mm-radix.c +1 -1
index 9a00ae416af0..d5385ec9dd4b 100644
@@ -265,7 +265,7 @@ int destroy_xen_mappings(unsigned long s, unsigned long e)
 int map_pages_to_xen(unsigned long virt,
                      mfn_t mfn,
                      unsigned long nr_mfns,
-                     unsigned int flags)
+                     pte_attr_t flags)
 {
     BUG_ON("unimplemented");
 }
xen/arch/riscv/pt.c +1 -1
index 857619d48df1..918b1b91abde 100644
@@ -504,7 +504,7 @@ static int pt_update(vaddr_t virt, mfn_t mfn,
 int map_pages_to_xen(unsigned long virt,
                      mfn_t mfn,
                      unsigned long nr_mfns,
-                     unsigned int flags)
+                     pte_attr_t flags)
 {
     /*
      * Ensure that flags has PTE_VALID bit as map_pages_to_xen() is supposed
xen/arch/x86/mm.c +3 -3
index 1cf236516789..0e6c766be4aa 100644
@@ -5442,7 +5442,7 @@ int map_pages_to_xen(
     unsigned long virt,
     mfn_t mfn,
     unsigned long nr_mfns,
-    unsigned int flags)
+    pte_attr_t flags)
 {
     bool locking = system_state > SYS_STATE_boot;
     l3_pgentry_t *pl3e = NULL, ol3e;
@@ -5860,7 +5860,7 @@ int __init populate_pt_range(unsigned long virt, unsigned long nr_mfns)
  *
  * It is an error to call with present flags over an unpopulated range.
  */
-int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)
+int modify_xen_mappings(unsigned long s, unsigned long e, pte_attr_t nf)
 {
     bool locking = system_state > SYS_STATE_boot;
     l3_pgentry_t *pl3e = NULL;
@@ -6156,7 +6156,7 @@ int destroy_xen_mappings(unsigned long s, unsigned long e)
  * the non-inclusive boundary will be updated.
  */
 void init_or_livepatch modify_xen_mappings_lite(
-    unsigned long s, unsigned long e, unsigned int nf)
+    unsigned long s, unsigned long e, pte_attr_t nf)
 {
     unsigned long v = s, fm, flags;
 
xen/common/efi/boot.c +2 -2
index 143b5681ba92..e39fbc3529c4 100644
@@ -1676,7 +1676,7 @@ void __init efi_init_memory(void)
     struct rt_extra {
         struct rt_extra *next;
         unsigned long smfn, emfn;
-        unsigned int prot;
+        pte_attr_t prot;
     } *extra, *extra_head = NULL;
 
     free_ebmalloc_unused_mem();
@@ -1691,7 +1691,7 @@ void __init efi_init_memory(void)
         EFI_MEMORY_DESCRIPTOR *desc = efi_memmap + i;
         u64 len = desc->NumberOfPages << EFI_PAGE_SHIFT;
         unsigned long smfn, emfn;
-        unsigned int prot = PAGE_HYPERVISOR_RWX;
+        pte_attr_t prot = PAGE_HYPERVISOR_RWX;
         paddr_t mem_base;
         unsigned long mem_npages;
 
xen/common/vmap.c +1 -1
index 47225fecc067..d6991421f3f7 100644
@@ -222,7 +222,7 @@ static void vm_free(const void *va)
 }
 
 void *__vmap(const mfn_t *mfn, unsigned int granularity,
-             unsigned int nr, unsigned int align, unsigned int flags,
+             unsigned int nr, unsigned int align, pte_attr_t flags,
              enum vmap_region type)
 {
     void *va = vm_alloc(nr * granularity, align, type);
xen/include/xen/mm.h +4 -3
index ae1c48a61545..e89942b87d1e 100644
@@ -64,6 +64,7 @@
 #include <xen/bug.h>
 #include <xen/compiler.h>
 #include <xen/mm-frame.h>
+#include <xen/mm-types.h>
 #include <xen/types.h>
 #include <xen/list.h>
 #include <xen/spinlock.h>
@@ -113,11 +114,11 @@ int map_pages_to_xen(
     unsigned long virt,
     mfn_t mfn,
     unsigned long nr_mfns,
-    unsigned int flags);
+    pte_attr_t flags);
 /* Alter the permissions of a range of Xen virtual address space. */
-int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf);
+int modify_xen_mappings(unsigned long s, unsigned long e, pte_attr_t nf);
 void modify_xen_mappings_lite(unsigned long s, unsigned long e,
-                              unsigned int nf);
+                              pte_attr_t nf);
 int destroy_xen_mappings(unsigned long s, unsigned long e);
 /* Retrieve the MFN mapped by VA in Xen virtual address space. */
 mfn_t xen_map_to_mfn(unsigned long va);
xen/include/xen/vmap.h +2 -1
index 26c831757a11..327a2597826d 100644
@@ -9,6 +9,7 @@
 #define __XEN_VMAP_H__
 
 #include <xen/mm-frame.h>
+#include <xen/mm-types.h>
 #include <xen/page-size.h>
 
 /* Identifiers for the linear ranges tracked by vmap */
@@ -57,7 +58,7 @@ void vm_init_type(enum vmap_region type, void *start, void *end);
  * @return Pointer to the mapped area on success; NULL otherwise.
  */
 void *__vmap(const mfn_t *mfn, unsigned int granularity, unsigned int nr,
-             unsigned int align, unsigned int flags, enum vmap_region type);
+             unsigned int align, pte_attr_t flags, enum vmap_region type);
 
 /*
  * Map an array of pages contiguously into the VMAP_DEFAULT vmap region
Signature · 1 line
2.39.5
#12 lore raw

Re: [PATCH v5 2/3] xen/mm: Switch some APIs over to pte_attr_t

Quoted 24 lines · Andrew Cooper

From: Shawn Anastasio<[email protected]>

Several APIs take an architecture-dependent set of flags in an unsigned int, but this needs to be a wider type to support PPC.

The new type pte_attr_t has been introduced for this purpose, so switch to it in map_pages_to_xen(), __vmap() and modify_xen_mappings{,_lite}().

No functional change.

---
CC: Jan Beulich<[email protected]>
CC: Roger Pau Monné<[email protected]>
CC: Stefano Stabellini<[email protected]>
CC: Julien Grall<[email protected]>
CC: Volodymyr Babchuk<[email protected]>
CC: Bertrand Marquis<[email protected]>
CC: Michal Orzel<[email protected]>
CC: Oleksii Kurochko<[email protected]>
CC: Shawn Anastasio<[email protected]>

Quoted 4 lines
---
  xen/arch/arm/mmu/pt.c   | 4 ++--
  xen/arch/ppc/mm-radix.c | 2 +-
  xen/arch/riscv/pt.c     | 2 +-

As I wrote here, probably, as a part of this patch we also wants to do the following changes:
https://lore.kernel.org/xen-devel/[email protected]/T/#u

I'm okay with sending the mentioned changes in the link as a separate patch when I will introduce Svpmbt extension which uses 61 and 62 bits. Let me know if you are okay with that?

If you think that these changes should be part of this patch then something similar for Arm should be done too now.

~ Oleksii

Quoted 169 lines
  xen/arch/x86/mm.c       | 6 +++---
  xen/common/efi/boot.c   | 4 ++--
  xen/common/vmap.c       | 2 +-
  xen/include/xen/mm.h    | 7 ++++---
  xen/include/xen/vmap.h  | 3 ++-
  8 files changed, 16 insertions(+), 14 deletions(-)
xen/arch/arm/mmu/pt.c +2 -2
index 11cb1c66dac8..4726e713efd3 100644
@@ -696,7 +696,7 @@ static int xen_pt_update(unsigned long virt,
  int map_pages_to_xen(unsigned long virt,
                       mfn_t mfn,
                       unsigned long nr_mfns,
-                     unsigned int flags)
+                     pte_attr_t flags)
  {
      return xen_pt_update(virt, mfn, nr_mfns, flags);
  }
@@ -714,7 +714,7 @@ int destroy_xen_mappings(unsigned long s, unsigned long e)
      return xen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, 0);
  }
 
-int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)
+int modify_xen_mappings(unsigned long s, unsigned long e, pte_attr_t nf)
  {
      ASSERT(IS_ALIGNED(s, PAGE_SIZE));
      ASSERT(IS_ALIGNED(e, PAGE_SIZE));
xen/arch/ppc/mm-radix.c +1 -1
index 9a00ae416af0..d5385ec9dd4b 100644
@@ -265,7 +265,7 @@ int destroy_xen_mappings(unsigned long s, unsigned long e)
  int map_pages_to_xen(unsigned long virt,
                       mfn_t mfn,
                       unsigned long nr_mfns,
-                     unsigned int flags)
+                     pte_attr_t flags)
  {
      BUG_ON("unimplemented");
  }
xen/arch/riscv/pt.c +1 -1
index 857619d48df1..918b1b91abde 100644
@@ -504,7 +504,7 @@ static int pt_update(vaddr_t virt, mfn_t mfn,
  int map_pages_to_xen(unsigned long virt,
                       mfn_t mfn,
                       unsigned long nr_mfns,
-                     unsigned int flags)
+                     pte_attr_t flags)
  {
      /*
       * Ensure that flags has PTE_VALID bit as map_pages_to_xen() is supposed
xen/arch/x86/mm.c +3 -3
index 1cf236516789..0e6c766be4aa 100644
@@ -5442,7 +5442,7 @@ int map_pages_to_xen(
      unsigned long virt,
      mfn_t mfn,
      unsigned long nr_mfns,
-    unsigned int flags)
+    pte_attr_t flags)
  {
      bool locking = system_state > SYS_STATE_boot;
      l3_pgentry_t *pl3e = NULL, ol3e;
@@ -5860,7 +5860,7 @@ int __init populate_pt_range(unsigned long virt, unsigned long nr_mfns)
   *
   * It is an error to call with present flags over an unpopulated range.
   */
-int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)
+int modify_xen_mappings(unsigned long s, unsigned long e, pte_attr_t nf)
  {
      bool locking = system_state > SYS_STATE_boot;
      l3_pgentry_t *pl3e = NULL;
@@ -6156,7 +6156,7 @@ int destroy_xen_mappings(unsigned long s, unsigned long e)
   * the non-inclusive boundary will be updated.
   */
  void init_or_livepatch modify_xen_mappings_lite(
-    unsigned long s, unsigned long e, unsigned int nf)
+    unsigned long s, unsigned long e, pte_attr_t nf)
  {
      unsigned long v = s, fm, flags;
 
xen/common/efi/boot.c +2 -2
index 143b5681ba92..e39fbc3529c4 100644
@@ -1676,7 +1676,7 @@ void __init efi_init_memory(void)
      struct rt_extra {
          struct rt_extra *next;
          unsigned long smfn, emfn;
-        unsigned int prot;
+        pte_attr_t prot;
      } *extra, *extra_head = NULL;
 
      free_ebmalloc_unused_mem();
@@ -1691,7 +1691,7 @@ void __init efi_init_memory(void)
          EFI_MEMORY_DESCRIPTOR *desc = efi_memmap + i;
          u64 len = desc->NumberOfPages << EFI_PAGE_SHIFT;
          unsigned long smfn, emfn;
-        unsigned int prot = PAGE_HYPERVISOR_RWX;
+        pte_attr_t prot = PAGE_HYPERVISOR_RWX;
          paddr_t mem_base;
          unsigned long mem_npages;
 
xen/common/vmap.c +1 -1
index 47225fecc067..d6991421f3f7 100644
@@ -222,7 +222,7 @@ static void vm_free(const void *va)
  }
 
  void *__vmap(const mfn_t *mfn, unsigned int granularity,
-             unsigned int nr, unsigned int align, unsigned int flags,
+             unsigned int nr, unsigned int align, pte_attr_t flags,
               enum vmap_region type)
  {
      void *va = vm_alloc(nr * granularity, align, type);
xen/include/xen/mm.h +4 -3
index ae1c48a61545..e89942b87d1e 100644
@@ -64,6 +64,7 @@
  #include <xen/bug.h>
  #include <xen/compiler.h>
  #include <xen/mm-frame.h>
+#include <xen/mm-types.h>
  #include <xen/types.h>
  #include <xen/list.h>
  #include <xen/spinlock.h>
@@ -113,11 +114,11 @@ int map_pages_to_xen(
      unsigned long virt,
      mfn_t mfn,
      unsigned long nr_mfns,
-    unsigned int flags);
+    pte_attr_t flags);
  /* Alter the permissions of a range of Xen virtual address space. */
-int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf);
+int modify_xen_mappings(unsigned long s, unsigned long e, pte_attr_t nf);
  void modify_xen_mappings_lite(unsigned long s, unsigned long e,
-                              unsigned int nf);
+                              pte_attr_t nf);
  int destroy_xen_mappings(unsigned long s, unsigned long e);
  /* Retrieve the MFN mapped by VA in Xen virtual address space. */
  mfn_t xen_map_to_mfn(unsigned long va);
xen/include/xen/vmap.h +2 -1
index 26c831757a11..327a2597826d 100644
@@ -9,6 +9,7 @@
  #define __XEN_VMAP_H__
 
  #include <xen/mm-frame.h>
+#include <xen/mm-types.h>
  #include <xen/page-size.h>
 
  /* Identifiers for the linear ranges tracked by vmap */
@@ -57,7 +58,7 @@ void vm_init_type(enum vmap_region type, void *start, void *end);
   * @return Pointer to the mapped area on success; NULL otherwise.
   */
  void *__vmap(const mfn_t *mfn, unsigned int granularity, unsigned int nr,
-             unsigned int align, unsigned int flags, enum vmap_region type);
+             unsigned int align, pte_attr_t flags, enum vmap_region type);
 
  /*
   * Map an array of pages contiguously into the VMAP_DEFAULT vmap region
Reviewed-by on v5 2/3
#13 lore raw

Re: [PATCH v5 2/3] xen/mm: Switch some APIs over to pte_attr_t

In reply to Andrew Cooper
Quoted 8 lines · Andrew Cooper

From: Shawn Anastasio <[email protected]>

Several APIs take an architecture-dependent set of flags in an unsigned int, but this needs to be a wider type to support PPC.

The new type pte_attr_t has been introduced for this purpose, so switch to it in map_pages_to_xen(), __vmap() and modify_xen_mappings{,_lite}().

Quoted 6 lines

No functional change.

Quoted 186 lines

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>

---
 xen/arch/arm/mmu/pt.c   | 4 ++--
 xen/arch/ppc/mm-radix.c | 2 +-
 xen/arch/riscv/pt.c     | 2 +-
 xen/arch/x86/mm.c       | 6 +++---
 xen/common/efi/boot.c   | 4 ++--
 xen/common/vmap.c       | 2 +-
 xen/include/xen/mm.h    | 7 ++++---
 xen/include/xen/vmap.h  | 3 ++-
 8 files changed, 16 insertions(+), 14 deletions(-)
xen/arch/arm/mmu/pt.c +2 -2
index 11cb1c66dac8..4726e713efd3 100644
@@ -696,7 +696,7 @@ static int xen_pt_update(unsigned long virt,
 int map_pages_to_xen(unsigned long virt,
                      mfn_t mfn,
                      unsigned long nr_mfns,
-                     unsigned int flags)
+                     pte_attr_t flags)
 {
     return xen_pt_update(virt, mfn, nr_mfns, flags);
 }
@@ -714,7 +714,7 @@ int destroy_xen_mappings(unsigned long s, unsigned long e)
     return xen_pt_update(s, INVALID_MFN, (e - s) >> PAGE_SHIFT, 0);
 }
 
-int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)
+int modify_xen_mappings(unsigned long s, unsigned long e, pte_attr_t nf)
 {
     ASSERT(IS_ALIGNED(s, PAGE_SIZE));
     ASSERT(IS_ALIGNED(e, PAGE_SIZE));
xen/arch/ppc/mm-radix.c +1 -1
index 9a00ae416af0..d5385ec9dd4b 100644
@@ -265,7 +265,7 @@ int destroy_xen_mappings(unsigned long s, unsigned long e)
 int map_pages_to_xen(unsigned long virt,
                      mfn_t mfn,
                      unsigned long nr_mfns,
-                     unsigned int flags)
+                     pte_attr_t flags)
 {
     BUG_ON("unimplemented");
 }
xen/arch/riscv/pt.c +1 -1
index 857619d48df1..918b1b91abde 100644
@@ -504,7 +504,7 @@ static int pt_update(vaddr_t virt, mfn_t mfn,
 int map_pages_to_xen(unsigned long virt,
                      mfn_t mfn,
                      unsigned long nr_mfns,
-                     unsigned int flags)
+                     pte_attr_t flags)
 {
     /*
      * Ensure that flags has PTE_VALID bit as map_pages_to_xen() is supposed
xen/arch/x86/mm.c +3 -3
index 1cf236516789..0e6c766be4aa 100644
@@ -5442,7 +5442,7 @@ int map_pages_to_xen(
     unsigned long virt,
     mfn_t mfn,
     unsigned long nr_mfns,
-    unsigned int flags)
+    pte_attr_t flags)
 {
     bool locking = system_state > SYS_STATE_boot;
     l3_pgentry_t *pl3e = NULL, ol3e;
@@ -5860,7 +5860,7 @@ int __init populate_pt_range(unsigned long virt, unsigned long nr_mfns)
  *
  * It is an error to call with present flags over an unpopulated range.
  */
-int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf)
+int modify_xen_mappings(unsigned long s, unsigned long e, pte_attr_t nf)
 {
     bool locking = system_state > SYS_STATE_boot;
     l3_pgentry_t *pl3e = NULL;
@@ -6156,7 +6156,7 @@ int destroy_xen_mappings(unsigned long s, unsigned long e)
  * the non-inclusive boundary will be updated.
  */
 void init_or_livepatch modify_xen_mappings_lite(
-    unsigned long s, unsigned long e, unsigned int nf)
+    unsigned long s, unsigned long e, pte_attr_t nf)
 {
     unsigned long v = s, fm, flags;
 
xen/common/efi/boot.c +2 -2
index 143b5681ba92..e39fbc3529c4 100644
@@ -1676,7 +1676,7 @@ void __init efi_init_memory(void)
     struct rt_extra {
         struct rt_extra *next;
         unsigned long smfn, emfn;
-        unsigned int prot;
+        pte_attr_t prot;
     } *extra, *extra_head = NULL;
 
     free_ebmalloc_unused_mem();
@@ -1691,7 +1691,7 @@ void __init efi_init_memory(void)
         EFI_MEMORY_DESCRIPTOR *desc = efi_memmap + i;
         u64 len = desc->NumberOfPages << EFI_PAGE_SHIFT;
         unsigned long smfn, emfn;
-        unsigned int prot = PAGE_HYPERVISOR_RWX;
+        pte_attr_t prot = PAGE_HYPERVISOR_RWX;
         paddr_t mem_base;
         unsigned long mem_npages;
 
xen/common/vmap.c +1 -1
index 47225fecc067..d6991421f3f7 100644
@@ -222,7 +222,7 @@ static void vm_free(const void *va)
 }
 
 void *__vmap(const mfn_t *mfn, unsigned int granularity,
-             unsigned int nr, unsigned int align, unsigned int flags,
+             unsigned int nr, unsigned int align, pte_attr_t flags,
              enum vmap_region type)
 {
     void *va = vm_alloc(nr * granularity, align, type);
xen/include/xen/mm.h +4 -3
index ae1c48a61545..e89942b87d1e 100644
@@ -64,6 +64,7 @@
 #include <xen/bug.h>
 #include <xen/compiler.h>
 #include <xen/mm-frame.h>
+#include <xen/mm-types.h>
 #include <xen/types.h>
 #include <xen/list.h>
 #include <xen/spinlock.h>
@@ -113,11 +114,11 @@ int map_pages_to_xen(
     unsigned long virt,
     mfn_t mfn,
     unsigned long nr_mfns,
-    unsigned int flags);
+    pte_attr_t flags);
 /* Alter the permissions of a range of Xen virtual address space. */
-int modify_xen_mappings(unsigned long s, unsigned long e, unsigned int nf);
+int modify_xen_mappings(unsigned long s, unsigned long e, pte_attr_t nf);
 void modify_xen_mappings_lite(unsigned long s, unsigned long e,
-                              unsigned int nf);
+                              pte_attr_t nf);
 int destroy_xen_mappings(unsigned long s, unsigned long e);
 /* Retrieve the MFN mapped by VA in Xen virtual address space. */
 mfn_t xen_map_to_mfn(unsigned long va);
xen/include/xen/vmap.h +2 -1
index 26c831757a11..327a2597826d 100644
@@ -9,6 +9,7 @@
 #define __XEN_VMAP_H__
 
 #include <xen/mm-frame.h>
+#include <xen/mm-types.h>
 #include <xen/page-size.h>
 
 /* Identifiers for the linear ranges tracked by vmap */
@@ -57,7 +58,7 @@ void vm_init_type(enum vmap_region type, void *start, void *end);
  * @return Pointer to the mapped area on success; NULL otherwise.
  */
 void *__vmap(const mfn_t *mfn, unsigned int granularity, unsigned int nr,
-             unsigned int align, unsigned int flags, enum vmap_region type);
+             unsigned int align, pte_attr_t flags, enum vmap_region type);
 
 /*
  * Map an array of pages contiguously into the VMAP_DEFAULT vmap region
Signature · 1 line
2.39.5
#14 lore raw

PATCH v5 3/3 ppc/mm: Introduce mm-types.h

In reply to Andrew Cooper

From: Shawn Anastasio <[email protected]>

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>

Possibly not for taking on it's own (might be better with the PPC implemenation of map_pages_to_xen()).

Nevertheless, this patch alone now does trip:

  diff --git a/xen/common/vmap.c b/xen/common/vmap.c
  index d6991421f3f7..9552806dba39 100644
  --- a/xen/common/vmap.c
  +++ b/xen/common/vmap.c
  @@ -228,6 +228,8 @@ void *__vmap(const mfn_t *mfn, unsigned int granularity,
       void *va = vm_alloc(nr * granularity, align, type);
       unsigned long cur = (unsigned long)va;

  +    BUILD_BUG_ON(sizeof(pte_attr_t) != 4);
  +
       for ( ; va && nr--; ++mfn, cur += PAGE_SIZE * granularity )
       {
           if ( map_pages_to_xen(cur, *mfn, granularity, flags) )

in PPC builds only.

---
 xen/arch/ppc/include/asm/mm-types.h | 7 +++++++
 1 file changed, 7 insertions(+)
 create mode 100644 xen/arch/ppc/include/asm/mm-types.h
xen/arch/ppc/include/asm/mm-types.h new file +7 -0
new file mode 100644
index 000000000000..06a3af1c6eda
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef PPC_MM_TYPES_H
+#define PPC_MM_TYPES_H
+
+typedef unsigned long pte_attr_t;
+
+#endif /* PPC_MM_TYPES_H */
Signature · 1 line
2.39.5
#15 lore raw

Re: [PATCH v5 3/3] ppc/mm: Introduce mm-types.h

Quoted 27 lines · Andrew Cooper

From: Shawn Anastasio<[email protected]>

---
CC: Jan Beulich<[email protected]>
CC: Roger Pau Monné<[email protected]>
CC: Stefano Stabellini<[email protected]>
CC: Julien Grall<[email protected]>
CC: Volodymyr Babchuk<[email protected]>
CC: Bertrand Marquis<[email protected]>
CC: Michal Orzel<[email protected]>
CC: Oleksii Kurochko<[email protected]>
CC: Shawn Anastasio<[email protected]>

Possibly not for taking on it's own (might be better with the PPC implemenation of map_pages_to_xen()).

Nevertheless, this patch alone now does trip:

   diff --git a/xen/common/vmap.c b/xen/common/vmap.c
   index d6991421f3f7..9552806dba39 100644
   --- a/xen/common/vmap.c
   +++ b/xen/common/vmap.c
   @@ -228,6 +228,8 @@ void *__vmap(const mfn_t *mfn, unsigned int granularity,
        void *va = vm_alloc(nr * granularity, align, type);
        unsigned long cur = (unsigned long)va;
Quoted 2 lines

+ BUILD_BUG_ON(sizeof(pte_attr_t) != 4);
+

Could you please clarify what kind of changes should done in the case if sizeof(pte_attr_t) == 8 (unsigned long)?

~ Oleksii

Quoted 23 lines
        for ( ; va && nr--; ++mfn, cur += PAGE_SIZE * granularity )
        {
            if ( map_pages_to_xen(cur, *mfn, granularity, flags) )

in PPC builds only.

---
  xen/arch/ppc/include/asm/mm-types.h | 7 +++++++
  1 file changed, 7 insertions(+)

create mode 100644 xen/arch/ppc/include/asm/mm-types.h

xen/arch/ppc/include/asm/mm-types.h new file +7 -0
new file mode 100644
index 000000000000..06a3af1c6eda
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef PPC_MM_TYPES_H
+#define PPC_MM_TYPES_H
+
+typedef unsigned long pte_attr_t;
+
+#endif /* PPC_MM_TYPES_H */
#16 lore raw

Re: [PATCH v5 3/3] ppc/mm: Introduce mm-types.h

Quoted 30 lines · Oleksii Kurochko
Quoted 27 lines · Andrew Cooper

From: Shawn Anastasio <[email protected]>

---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Julien Grall <[email protected]>
CC: Volodymyr Babchuk <[email protected]>
CC: Bertrand Marquis <[email protected]>
CC: Michal Orzel <[email protected]>
CC: Oleksii Kurochko <[email protected]>
CC: Shawn Anastasio <[email protected]>

Possibly not for taking on it's own (might be better with the PPC implemenation of map_pages_to_xen()).

Nevertheless, this patch alone now does trip:

  diff --git a/xen/common/vmap.c b/xen/common/vmap.c
  index d6991421f3f7..9552806dba39 100644
  --- a/xen/common/vmap.c
  +++ b/xen/common/vmap.c
  @@ -228,6 +228,8 @@ void *__vmap(const mfn_t *mfn, unsigned int granularity,
       void *va = vm_alloc(nr * granularity, align, type);
       unsigned long cur = (unsigned long)va;
Quoted 4 lines
Quoted 2 lines

+ BUILD_BUG_ON(sizeof(pte_attr_t) != 4);
+

Could you please clarify what kind of changes should done in the case if sizeof(pte_attr_t) == 8 (unsigned long)?

Nothing.  This is simply to demonstrate that __has_include() is working, and is making PPC different to all the other architectures.

~Andrew.