xen/arch/arm/domain.c | 17 ----------------- xen/arch/ppc/stubs.c | 10 ---------- xen/arch/riscv/stubs.c | 10 ---------- xen/arch/x86/domain.c | 15 ++------------- xen/arch/x86/include/asm/pv/domain.h | 3 +++ xen/common/domain.c | 23 +++++++++++++++++++++++ 6 files changed, 28 insertions(+), 50 deletions(-)
From: Roger Pau Monne <roger.pau@citrix.com>
Move x86's free_domain_struct() to common code since it is shared between
architectures.
Move the x86 version of alloc_domain_struct() to common code as most of the
logic is architecture-independent. To handle the remaining architectural
differences, introduce arch_alloc_domain_struct_bits() for x86-specific
allocation requirements.
No functional change.
Suggested-By: Jan Beulich <jbeulich@suse.com>
[Introduce an arch-specific function instead of using a weak function]
Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
---
Changes in v2:
- CI test results: https://gitlab.com/xen-project/people/olkur/xen/-/pipelines/2180836457
- Introduce an arch-specific function to handle differences between arch-es
in domain structure allocation requirements, instead of relying on a weak
function.
- Add Suggested-by: Jan Beulich <jbeulich@suse.com>.
- Move free_domain_struct() to common code.
- Update the commit message.
---
xen/arch/arm/domain.c | 17 -----------------
xen/arch/ppc/stubs.c | 10 ----------
xen/arch/riscv/stubs.c | 10 ----------
xen/arch/x86/domain.c | 15 ++-------------
xen/arch/x86/include/asm/pv/domain.h | 3 +++
xen/common/domain.c | 23 +++++++++++++++++++++++
6 files changed, 28 insertions(+), 50 deletions(-)
diff --git a/xen/arch/arm/domain.c b/xen/arch/arm/domain.c
index ab78444335..3e3a1fb9f5 100644
--- a/xen/arch/arm/domain.c
+++ b/xen/arch/arm/domain.c
@@ -480,23 +480,6 @@ void startup_cpu_idle_loop(void)
reset_stack_and_jump(idle_loop);
}
-struct domain *alloc_domain_struct(void)
-{
- struct domain *d;
- BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE);
- d = alloc_xenheap_pages(0, 0);
- if ( d == NULL )
- return NULL;
-
- clear_page(d);
- return d;
-}
-
-void free_domain_struct(struct domain *d)
-{
- free_xenheap_page(d);
-}
-
void dump_pageframe_info(struct domain *d)
{
diff --git a/xen/arch/ppc/stubs.c b/xen/arch/ppc/stubs.c
index 75ebcae5e2..9953ea1c6c 100644
--- a/xen/arch/ppc/stubs.c
+++ b/xen/arch/ppc/stubs.c
@@ -147,11 +147,6 @@ void startup_cpu_idle_loop(void)
BUG_ON("unimplemented");
}
-void free_domain_struct(struct domain *d)
-{
- BUG_ON("unimplemented");
-}
-
void dump_pageframe_info(struct domain *d)
{
BUG_ON("unimplemented");
@@ -269,11 +264,6 @@ void vcpu_kick(struct vcpu *v)
BUG_ON("unimplemented");
}
-struct domain *alloc_domain_struct(void)
-{
- BUG_ON("unimplemented");
-}
-
struct vcpu *alloc_vcpu_struct(const struct domain *d)
{
BUG_ON("unimplemented");
diff --git a/xen/arch/riscv/stubs.c b/xen/arch/riscv/stubs.c
index 340ed3cd6c..fe7d85ee1d 100644
--- a/xen/arch/riscv/stubs.c
+++ b/xen/arch/riscv/stubs.c
@@ -121,11 +121,6 @@ void startup_cpu_idle_loop(void)
BUG_ON("unimplemented");
}
-void free_domain_struct(struct domain *d)
-{
- BUG_ON("unimplemented");
-}
-
void dump_pageframe_info(struct domain *d)
{
BUG_ON("unimplemented");
@@ -243,11 +238,6 @@ void vcpu_kick(struct vcpu *v)
BUG_ON("unimplemented");
}
-struct domain *alloc_domain_struct(void)
-{
- BUG_ON("unimplemented");
-}
-
struct vcpu *alloc_vcpu_struct(const struct domain *d)
{
BUG_ON("unimplemented");
diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
index 3a21e035f4..34a02f089e 100644
--- a/xen/arch/x86/domain.c
+++ b/xen/arch/x86/domain.c
@@ -463,10 +463,8 @@ void domain_cpu_policy_changed(struct domain *d)
}
}
-struct domain *alloc_domain_struct(void)
+unsigned int arch_alloc_domain_struct_bits(void)
{
- struct domain *d;
-
/*
* Without CONFIG_BIGMEM, we pack the PDX of the domain structure into
* a 32-bit field within the page_info structure. Hence the MEMF_bits()
@@ -492,16 +490,7 @@ struct domain *alloc_domain_struct(void)
- 1;
#endif
- BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE);
- d = alloc_xenheap_pages(0, MEMF_bits(bits));
- if ( d != NULL )
- clear_page(d);
- return d;
-}
-
-void free_domain_struct(struct domain *d)
-{
- free_xenheap_page(d);
+ return bits;
}
struct vcpu *alloc_vcpu_struct(const struct domain *d)
diff --git a/xen/arch/x86/include/asm/pv/domain.h b/xen/arch/x86/include/asm/pv/domain.h
index 582d004051..6e65bc22fc 100644
--- a/xen/arch/x86/include/asm/pv/domain.h
+++ b/xen/arch/x86/include/asm/pv/domain.h
@@ -18,6 +18,9 @@ extern int8_t opt_pv32;
# define opt_pv32 false
#endif
+unsigned int arch_alloc_domain_struct_bits(void);
+#define arch_alloc_domin_struct_bits arch_alloc_domain_struct_bits
+
/*
* PCID values for the address spaces of 64-bit pv domains:
*
diff --git a/xen/common/domain.c b/xen/common/domain.c
index 3b6e9471c4..b51ce375df 100644
--- a/xen/common/domain.c
+++ b/xen/common/domain.c
@@ -799,6 +799,29 @@ static int sanitise_domain_config(struct xen_domctl_createdomain *config)
return arch_sanitise_domain_config(config);
}
+struct domain *alloc_domain_struct(void)
+{
+ struct domain *d;
+ unsigned int bits = 0;
+
+#ifdef arch_alloc_domin_struct_bits
+ bits = arch_alloc_domin_struct_bits();
+#endif
+
+ BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE);
+
+ d = alloc_xenheap_pages(0, MEMF_bits(bits));
+ if ( d != NULL )
+ clear_page(d);
+
+ return d;
+}
+
+void free_domain_struct(struct domain *d)
+{
+ free_xenheap_page(d);
+}
+
struct domain *domain_create(domid_t domid,
struct xen_domctl_createdomain *config,
unsigned int flags)
--
2.52.0
On 26.11.25 16:32, Oleksii Kurochko wrote:
> From: Roger Pau Monne <roger.pau@citrix.com>
>
> Move x86's free_domain_struct() to common code since it is shared between
> architectures.
>
> Move the x86 version of alloc_domain_struct() to common code as most of the
> logic is architecture-independent. To handle the remaining architectural
> differences, introduce arch_alloc_domain_struct_bits() for x86-specific
> allocation requirements.
>
> No functional change.
>
> Suggested-By: Jan Beulich <jbeulich@suse.com>
> [Introduce an arch-specific function instead of using a weak function]
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
> ---
> Changes in v2:
> - CI test results: https://gitlab.com/xen-project/people/olkur/xen/-/pipelines/2180836457
> - Introduce an arch-specific function to handle differences between arch-es
> in domain structure allocation requirements, instead of relying on a weak
> function.
> - Add Suggested-by: Jan Beulich <jbeulich@suse.com>.
> - Move free_domain_struct() to common code.
> - Update the commit message.
> ---
> xen/arch/arm/domain.c | 17 -----------------
> xen/arch/ppc/stubs.c | 10 ----------
> xen/arch/riscv/stubs.c | 10 ----------
> xen/arch/x86/domain.c | 15 ++-------------
> xen/arch/x86/include/asm/pv/domain.h | 3 +++
> xen/common/domain.c | 23 +++++++++++++++++++++++
> 6 files changed, 28 insertions(+), 50 deletions(-)
>
[...]
> diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
> index 3a21e035f4..34a02f089e 100644
> --- a/xen/arch/x86/domain.c
> +++ b/xen/arch/x86/domain.c
> @@ -463,10 +463,8 @@ void domain_cpu_policy_changed(struct domain *d)
> }
> }
>
> -struct domain *alloc_domain_struct(void)
> +unsigned int arch_alloc_domain_struct_bits(void)
> {
> - struct domain *d;
> -
> /*
> * Without CONFIG_BIGMEM, we pack the PDX of the domain structure into
> * a 32-bit field within the page_info structure. Hence the MEMF_bits()
> @@ -492,16 +490,7 @@ struct domain *alloc_domain_struct(void)
> - 1;
> #endif
>
> - BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE);
> - d = alloc_xenheap_pages(0, MEMF_bits(bits));
> - if ( d != NULL )
> - clear_page(d);
> - return d;
> -}
> -
> -void free_domain_struct(struct domain *d)
> -{
> - free_xenheap_page(d);
> + return bits;
> }
>
> struct vcpu *alloc_vcpu_struct(const struct domain *d)
> diff --git a/xen/arch/x86/include/asm/pv/domain.h b/xen/arch/x86/include/asm/pv/domain.h
> index 582d004051..6e65bc22fc 100644
> --- a/xen/arch/x86/include/asm/pv/domain.h
> +++ b/xen/arch/x86/include/asm/pv/domain.h
> @@ -18,6 +18,9 @@ extern int8_t opt_pv32;
> # define opt_pv32 false
> #endif
>
> +unsigned int arch_alloc_domain_struct_bits(void);
> +#define arch_alloc_domin_struct_bits arch_alloc_domain_struct_bits
Is it intentionally placed in PV header x86/include/asm/pv/domain.h?
--
Best regards,
-grygorii
On 11/26/25 9:35 PM, Grygorii Strashko wrote:
>
>
> On 26.11.25 16:32, Oleksii Kurochko wrote:
>> From: Roger Pau Monne <roger.pau@citrix.com>
>>
>> Move x86's free_domain_struct() to common code since it is shared
>> between
>> architectures.
>>
>> Move the x86 version of alloc_domain_struct() to common code as most
>> of the
>> logic is architecture-independent. To handle the remaining architectural
>> differences, introduce arch_alloc_domain_struct_bits() for x86-specific
>> allocation requirements.
>>
>> No functional change.
>>
>> Suggested-By: Jan Beulich <jbeulich@suse.com>
>> [Introduce an arch-specific function instead of using a weak function]
>> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
>> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
>> ---
>> Changes in v2:
>> - CI test results:
>> https://gitlab.com/xen-project/people/olkur/xen/-/pipelines/2180836457
>> - Introduce an arch-specific function to handle differences between
>> arch-es
>> in domain structure allocation requirements, instead of relying on
>> a weak
>> function.
>> - Add Suggested-by: Jan Beulich <jbeulich@suse.com>.
>> - Move free_domain_struct() to common code.
>> - Update the commit message.
>> ---
>> xen/arch/arm/domain.c | 17 -----------------
>> xen/arch/ppc/stubs.c | 10 ----------
>> xen/arch/riscv/stubs.c | 10 ----------
>> xen/arch/x86/domain.c | 15 ++-------------
>> xen/arch/x86/include/asm/pv/domain.h | 3 +++
>> xen/common/domain.c | 23 +++++++++++++++++++++++
>> 6 files changed, 28 insertions(+), 50 deletions(-)
>>
>
> [...]
>
>> diff --git a/xen/arch/x86/domain.c b/xen/arch/x86/domain.c
>> index 3a21e035f4..34a02f089e 100644
>> --- a/xen/arch/x86/domain.c
>> +++ b/xen/arch/x86/domain.c
>> @@ -463,10 +463,8 @@ void domain_cpu_policy_changed(struct domain *d)
>> }
>> }
>> -struct domain *alloc_domain_struct(void)
>> +unsigned int arch_alloc_domain_struct_bits(void)
>> {
>> - struct domain *d;
>> -
>> /*
>> * Without CONFIG_BIGMEM, we pack the PDX of the domain
>> structure into
>> * a 32-bit field within the page_info structure. Hence the
>> MEMF_bits()
>> @@ -492,16 +490,7 @@ struct domain *alloc_domain_struct(void)
>> - 1;
>> #endif
>> - BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE);
>> - d = alloc_xenheap_pages(0, MEMF_bits(bits));
>> - if ( d != NULL )
>> - clear_page(d);
>> - return d;
>> -}
>> -
>> -void free_domain_struct(struct domain *d)
>> -{
>> - free_xenheap_page(d);
>> + return bits;
>> }
>> struct vcpu *alloc_vcpu_struct(const struct domain *d)
>> diff --git a/xen/arch/x86/include/asm/pv/domain.h
>> b/xen/arch/x86/include/asm/pv/domain.h
>> index 582d004051..6e65bc22fc 100644
>> --- a/xen/arch/x86/include/asm/pv/domain.h
>> +++ b/xen/arch/x86/include/asm/pv/domain.h
>> @@ -18,6 +18,9 @@ extern int8_t opt_pv32;
>> # define opt_pv32 false
>> #endif
>> +unsigned int arch_alloc_domain_struct_bits(void);
>> +#define arch_alloc_domin_struct_bits arch_alloc_domain_struct_bits
>
> Is it intentionally placed in PV header x86/include/asm/pv/domain.h?
Oh, I missed that it is inside PV header. It should be in asm/domain.h, thanks for noticing that!
~ Oleksii
On 26.11.2025 15:32, Oleksii Kurochko wrote:
> --- a/xen/arch/x86/include/asm/pv/domain.h
> +++ b/xen/arch/x86/include/asm/pv/domain.h
> @@ -18,6 +18,9 @@ extern int8_t opt_pv32;
> # define opt_pv32 false
> #endif
>
> +unsigned int arch_alloc_domain_struct_bits(void);
> +#define arch_alloc_domin_struct_bits arch_alloc_domain_struct_bits
There was an 'a' lost in the identifier.
> --- a/xen/common/domain.c
> +++ b/xen/common/domain.c
> @@ -799,6 +799,29 @@ static int sanitise_domain_config(struct xen_domctl_createdomain *config)
> return arch_sanitise_domain_config(config);
> }
>
> +struct domain *alloc_domain_struct(void)
> +{
> + struct domain *d;
> + unsigned int bits = 0;
> +
> +#ifdef arch_alloc_domin_struct_bits
> + bits = arch_alloc_domin_struct_bits();
> +#endif
Maybe
#ifndef arch_alloc_domain_struct_bits
# define arch_alloc_domain_struct_bits() 0
#endif
ahead of the use and then simply
unsigned int bits = arch_alloc_domain_struct_bits();
?
> + BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE);
> +
> + d = alloc_xenheap_pages(0, MEMF_bits(bits));
I'd go a little farther and allow the arch to specify all the memflags that
are wanted. Then the hook name would also be less ambiguous, as "bits" can
mean many things. Perhaps arch_alloc_domain_struct_memflags() or, since
"memflags" kind of implies allocation, arch_domain_struct_memflags()?
Jan
On 11/26/25 4:19 PM, Jan Beulich wrote:
> On 26.11.2025 15:32, Oleksii Kurochko wrote:
>> --- a/xen/arch/x86/include/asm/pv/domain.h
>> +++ b/xen/arch/x86/include/asm/pv/domain.h
>> @@ -18,6 +18,9 @@ extern int8_t opt_pv32;
>> # define opt_pv32 false
>> #endif
>>
>> +unsigned int arch_alloc_domain_struct_bits(void);
>> +#define arch_alloc_domin_struct_bits arch_alloc_domain_struct_bits
> There was an 'a' lost in the identifier.
>
>> --- a/xen/common/domain.c
>> +++ b/xen/common/domain.c
>> @@ -799,6 +799,29 @@ static int sanitise_domain_config(struct xen_domctl_createdomain *config)
>> return arch_sanitise_domain_config(config);
>> }
>>
>> +struct domain *alloc_domain_struct(void)
>> +{
>> + struct domain *d;
>> + unsigned int bits = 0;
>> +
>> +#ifdef arch_alloc_domin_struct_bits
>> + bits = arch_alloc_domin_struct_bits();
>> +#endif
> Maybe
>
> #ifndef arch_alloc_domain_struct_bits
> # define arch_alloc_domain_struct_bits() 0
> #endif
>
> ahead of the use and then simply
>
> unsigned int bits = arch_alloc_domain_struct_bits();
>
> ?
>
>> + BUILD_BUG_ON(sizeof(*d) > PAGE_SIZE);
>> +
>> + d = alloc_xenheap_pages(0, MEMF_bits(bits));
> I'd go a little farther and allow the arch to specify all the memflags that
> are wanted. Then the hook name would also be less ambiguous, as "bits" can
> mean many things. Perhaps arch_alloc_domain_struct_memflags() or, since
> "memflags" kind of implies allocation, arch_domain_struct_memflags()?
I also thought about returning memflags from the hook instead of bits. Lets
then return memflags.
I will apply all other comments too.
Thanks.
~ Oleksii
© 2016 - 2025 Red Hat, Inc.