[PATCH v1 2/3] xen: introduce shared_info_to_gfn()

Penny Zheng posted 3 patches 6 days, 9 hours ago
[PATCH v1 2/3] xen: introduce shared_info_to_gfn()
Posted by Penny Zheng 6 days, 9 hours ago
On ARM, mfn_to_gfn() is a simple identity macro that actually does not return
the correct GFN for domains other than direct-map ones, so getdomaininfo() is
returning the wrong shared_info_frame on ARM.

Introduce a common shared_info_to_gfn(d) macro to output correct GFN for both
ARM and x86 in getdomaininfo():
- ARM: uses page_get_xenheap_gfn() to read the stored GFN
- x86: simply wraps the existing mfn_to_gfn() solution which consults the M2P
       table

Suggested-by: Alejandro Vallejo <alejandro.garciavallejo@amd.com>
Signed-off-by: Penny Zheng <penny.zheng@amd.com>
---
 xen/arch/arm/include/asm/mm.h  | 2 ++
 xen/arch/x86/include/asm/p2m.h | 3 +++
 xen/common/domctl.c            | 3 +--
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/xen/arch/arm/include/asm/mm.h b/xen/arch/arm/include/asm/mm.h
index d1873ec212..8d61b74e4f 100644
--- a/xen/arch/arm/include/asm/mm.h
+++ b/xen/arch/arm/include/asm/mm.h
@@ -308,6 +308,8 @@ struct page_info *get_page_from_gva(struct vcpu *v, vaddr_t va,
 /* Xen always owns P2M on ARM */
 #define set_gpfn_from_mfn(mfn, pfn) do { (void) (mfn), (void)(pfn); } while (0)
 #define mfn_to_gfn(d, mfn) ((void)(d), _gfn(mfn_x(mfn)))
+#define shared_info_to_gfn(d) \
+    page_get_xenheap_gfn(virt_to_page((d)->shared_info))
 
 /* Arch-specific portion of memory_op hypercall. */
 long arch_memory_op(int op, XEN_GUEST_HANDLE_PARAM(void) arg);
diff --git a/xen/arch/x86/include/asm/p2m.h b/xen/arch/x86/include/asm/p2m.h
index 3a5a5fd43c..725403b28f 100644
--- a/xen/arch/x86/include/asm/p2m.h
+++ b/xen/arch/x86/include/asm/p2m.h
@@ -582,6 +582,9 @@ static inline gfn_t mfn_to_gfn(const struct domain *d, mfn_t mfn)
         return _gfn(mfn_x(mfn));
 }
 
+#define shared_info_to_gfn(d) \
+    mfn_to_gfn((d), _mfn(virt_to_mfn((d)->shared_info)))
+
 #ifdef CONFIG_ALTP2M
 #define AP2MGET_prepopulate true
 #define AP2MGET_query false
diff --git a/xen/common/domctl.c b/xen/common/domctl.c
index 93738931c5..284926aa61 100644
--- a/xen/common/domctl.c
+++ b/xen/common/domctl.c
@@ -104,8 +104,7 @@ void getdomaininfo(struct domain *d, struct xen_domctl_getdomaininfo *info)
 #ifdef CONFIG_MEM_PAGING
     info->paged_pages       = atomic_read(&d->paged_pages);
 #endif
-    info->shared_info_frame =
-        gfn_x(mfn_to_gfn(d, _mfn(virt_to_mfn(d->shared_info))));
+    info->shared_info_frame = gfn_x(shared_info_to_gfn(d));
     BUG_ON(SHARED_M2P(info->shared_info_frame));
 
     info->cpupool = cpupool_get_id(d);
-- 
2.43.0
Re: [PATCH v1 2/3] xen: introduce shared_info_to_gfn()
Posted by Orzel, Michal 2 days, 8 hours ago

On 27/03/2026 08:50, Penny Zheng wrote:
> On ARM, mfn_to_gfn() is a simple identity macro that actually does not return
> the correct GFN for domains other than direct-map ones, so getdomaininfo() is
> returning the wrong shared_info_frame on ARM.
> 
> Introduce a common shared_info_to_gfn(d) macro to output correct GFN for both
> ARM and x86 in getdomaininfo():
> - ARM: uses page_get_xenheap_gfn() to read the stored GFN
> - x86: simply wraps the existing mfn_to_gfn() solution which consults the M2P
>        table
> 
> Suggested-by: Alejandro Vallejo <alejandro.garciavallejo@amd.com>
> Signed-off-by: Penny Zheng <penny.zheng@amd.com>
> ---
>  xen/arch/arm/include/asm/mm.h  | 2 ++
>  xen/arch/x86/include/asm/p2m.h | 3 +++
>  xen/common/domctl.c            | 3 +--
Seeing you only added this macro for Arm and x86, the RISCV and PPC builds will
likely fail to build.

Other than that, I agree with Jan that this requires a Fixes tag and the changes
look good.

~Michal
Re: [PATCH v1 2/3] xen: introduce shared_info_to_gfn()
Posted by Jan Beulich 3 days, 3 hours ago
On 27.03.2026 08:50, Penny Zheng wrote:
> On ARM, mfn_to_gfn() is a simple identity macro that actually does not return
> the correct GFN for domains other than direct-map ones, so getdomaininfo() is
> returning the wrong shared_info_frame on ARM.
> 
> Introduce a common shared_info_to_gfn(d) macro to output correct GFN for both
> ARM and x86 in getdomaininfo():
> - ARM: uses page_get_xenheap_gfn() to read the stored GFN
> - x86: simply wraps the existing mfn_to_gfn() solution which consults the M2P
>        table
> 
> Suggested-by: Alejandro Vallejo <alejandro.garciavallejo@amd.com>
> Signed-off-by: Penny Zheng <penny.zheng@amd.com>

Acked-by: Jan Beulich <jbeulich@suse.com>
preferably with ...

> --- a/xen/arch/x86/include/asm/p2m.h
> +++ b/xen/arch/x86/include/asm/p2m.h
> @@ -582,6 +582,9 @@ static inline gfn_t mfn_to_gfn(const struct domain *d, mfn_t mfn)
>          return _gfn(mfn_x(mfn));
>  }
>  
> +#define shared_info_to_gfn(d) \
> +    mfn_to_gfn((d), _mfn(virt_to_mfn((d)->shared_info)))

... the excess parentheses removed from the first argument. (Can be
adjusted while committing if no other need for a v2 arises.)

It also looks as if this change was independent of patch 1. As indicated
before, such information would be useful to supply right away, as it
allows this patch to go in ahead of patch 1 (if acks arrive here but not
there).

Btw, shouldn't there be a Fixes: tag? If so, and if this then was to be
backported, it being (in)dependent of patch 1 would become yet more
relevant.

Jan