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

Andrew Cooper posted 3 patches 7 months, 4 weeks ago
[PATCH v5 1/3] xen/mm: Introduce mm-types.h
Posted by Andrew Cooper 7 months, 4 weeks ago
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.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
---
CC: Jan Beulich <JBeulich@suse.com>
CC: Roger Pau Monné <roger.pau@citrix.com>
CC: Stefano Stabellini <sstabellini@kernel.org>
CC: Julien Grall <julien@xen.org>
CC: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
CC: Bertrand Marquis <bertrand.marquis@arm.com>
CC: Michal Orzel <michal.orzel@amd.com>
CC: Oleksii Kurochko <oleksii.kurochko@gmail.com>
CC: Shawn Anastasio <sanastasio@raptorengineering.com>

__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

diff --git a/xen/include/xen/mm-types.h b/xen/include/xen/mm-types.h
new file mode 100644
index 000000000000..19f692e9aaa4
--- /dev/null
+++ b/xen/include/xen/mm-types.h
@@ -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 */
-- 
2.39.5


Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h
Posted by Stefano Stabellini 7 months, 3 weeks ago
On Fri, 25 Apr 2025, Andrew Cooper wrote:
> 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.
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
> CC: Jan Beulich <JBeulich@suse.com>
> CC: Roger Pau Monné <roger.pau@citrix.com>
> CC: Stefano Stabellini <sstabellini@kernel.org>
> CC: Julien Grall <julien@xen.org>
> CC: Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
> CC: Bertrand Marquis <bertrand.marquis@arm.com>
> CC: Michal Orzel <michal.orzel@amd.com>
> CC: Oleksii Kurochko <oleksii.kurochko@gmail.com>
> CC: Shawn Anastasio <sanastasio@raptorengineering.com>
> 
> __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
> 
> diff --git a/xen/include/xen/mm-types.h b/xen/include/xen/mm-types.h
> new file mode 100644
> index 000000000000..19f692e9aaa4
> --- /dev/null
> +++ b/xen/include/xen/mm-types.h
> @@ -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 */
> -- 
> 2.39.5
> 
Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h
Posted by Jan Beulich 7 months, 4 weeks ago
On 25.04.2025 13:24, Andrew Cooper wrote:
> 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
Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h
Posted by Andrew Cooper 7 months, 4 weeks ago
On 25/04/2025 1:48 pm, Jan Beulich wrote:
> On 25.04.2025 13:24, Andrew Cooper wrote:
>> 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
Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h
Posted by Jan Beulich 7 months, 4 weeks ago
On 25.04.2025 15:05, Andrew Cooper wrote:
> On 25/04/2025 1:48 pm, Jan Beulich wrote:
>> On 25.04.2025 13:24, Andrew Cooper wrote:
>>> 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.

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
Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h
Posted by Andrew Cooper 7 months, 4 weeks ago
On 25/04/2025 2:13 pm, Jan Beulich wrote:
> On 25.04.2025 15:05, Andrew Cooper wrote:
>> On 25/04/2025 1:48 pm, Jan Beulich wrote:
>>> On 25.04.2025 13:24, Andrew Cooper wrote:
>>>> 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.
> 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

Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h
Posted by Jan Beulich 7 months, 4 weeks ago
On 25.04.2025 15:48, Andrew Cooper wrote:
> On 25/04/2025 2:13 pm, Jan Beulich wrote:
>> On 25.04.2025 15:05, Andrew Cooper wrote:
>>> On 25/04/2025 1:48 pm, Jan Beulich wrote:
>>>> On 25.04.2025 13:24, Andrew Cooper wrote:
>>>>> 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.
>> 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.

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

Jan

Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h
Posted by Oleksii Kurochko 7 months, 4 weeks ago
On 4/25/25 1:24 PM, Andrew Cooper wrote:
> 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.

>
> Introduce mm-types.h to house pte_attr_t.

Do we really want a separate mm-types.h?
If yes then:
  Reviewed-by: Oleksii Kurochko<oleksii.kurochko@gmail.com>

~ Oleksii

>
> Given the new toolchain baseline, we can use __has_include() now to remove the
> need for boilerplate on most architectures.
>
> Signed-off-by: Andrew Cooper<andrew.cooper3@citrix.com>
> ---
> CC: Jan Beulich<JBeulich@suse.com>
> CC: Roger Pau Monné<roger.pau@citrix.com>
> CC: Stefano Stabellini<sstabellini@kernel.org>
> CC: Julien Grall<julien@xen.org>
> CC: Volodymyr Babchuk<Volodymyr_Babchuk@epam.com>
> CC: Bertrand Marquis<bertrand.marquis@arm.com>
> CC: Michal Orzel<michal.orzel@amd.com>
> CC: Oleksii Kurochko<oleksii.kurochko@gmail.com>
> CC: Shawn Anastasio<sanastasio@raptorengineering.com>
>
> __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
>
> diff --git a/xen/include/xen/mm-types.h b/xen/include/xen/mm-types.h
> new file mode 100644
> index 000000000000..19f692e9aaa4
> --- /dev/null
> +++ b/xen/include/xen/mm-types.h
> @@ -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 */
Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h
Posted by Jan Beulich 7 months, 4 weeks ago
On 25.04.2025 13:29, Oleksii Kurochko wrote:
> 
> On 4/25/25 1:24 PM, Andrew Cooper wrote:
>> 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.
> 
>>
>> 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
Re: [PATCH v5 1/3] xen/mm: Introduce mm-types.h
Posted by Andrew Cooper 7 months, 4 weeks ago
On 25/04/2025 1:45 pm, Jan Beulich wrote:
> On 25.04.2025 13:29, Oleksii Kurochko wrote:
>> On 4/25/25 1:24 PM, Andrew Cooper wrote:
>>> 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.
>>
>>> 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