[PATCH v2] libs/guest: don't use unsigned long as type for PFNs

Juergen Gross posted 1 patch 3 weeks, 3 days ago
Patches applied successfully (tree, apply log)
git fetch https://gitlab.com/xen-project/patchew/xen tags/patchew/20251006055939.27286-1-jgross@suse.com
tools/libs/guest/xg_dom_boot.c | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
[PATCH v2] libs/guest: don't use unsigned long as type for PFNs
Posted by Juergen Gross 3 weeks, 3 days ago
Declarations of xc_dom_console_init() and
xc_dom_console_set_disconnected() in libxenguest.h don't match their
implementation in the library.

Under arm32, xen_pfn_t is a uint64_t and wider than unsigned long.

Use xen_pfn_t for GFNs in the library to fix that. At the same time
change the parameter name of the implementation to console_gfn,
matching the interface declaration in the header and reality (it is
a GFN, not a PFN).

Fixes: b6fc307b0b00 ("libs/guest: Set console as disconnected on resume")
Fixes: 971b7d5ecbcd ("libs/guest: Set console page to disconnected")
Reported-by: Luca Fancellu <luca.fancellu@arm.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
---
V2:
- switch parameter name as well (Andrew Cooper)
---
 tools/libs/guest/xg_dom_boot.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/tools/libs/guest/xg_dom_boot.c b/tools/libs/guest/xg_dom_boot.c
index f51b6a78c8..420222cf37 100644
--- a/tools/libs/guest/xg_dom_boot.c
+++ b/tools/libs/guest/xg_dom_boot.c
@@ -430,12 +430,12 @@ int xc_dom_gnttab_init(struct xc_dom_image *dom)
 
 static int dom_console_init(xc_interface *xch,
                             uint32_t domid,
-                            unsigned long dst_pfn,
+                            xen_pfn_t console_gfn,
                             bool clear)
 {
     const size_t size = PAGE_SIZE;
     struct xencons_interface *xencons = xc_map_foreign_range(
-        xch, domid, size, PROT_WRITE, dst_pfn);
+        xch, domid, size, PROT_WRITE, console_gfn);
 
     if ( xencons == NULL )
         return -1;
@@ -445,22 +445,22 @@ static int dom_console_init(xc_interface *xch,
     xencons->connection = XENCONSOLE_DISCONNECTED;
 
     munmap(xencons, size);
-    xc_domain_cacheflush(xch, domid, dst_pfn, 1);
+    xc_domain_cacheflush(xch, domid, console_gfn, 1);
     return 0;
 }
 
 int xc_dom_console_init(xc_interface *xch,
                         uint32_t domid,
-                        unsigned long dst_pfn)
+                        xen_pfn_t console_gfn)
 {
-    return dom_console_init(xch, domid, dst_pfn, true);
+    return dom_console_init(xch, domid, console_gfn, true);
 }
 
 int xc_dom_console_set_disconnected(xc_interface *xch,
                                     uint32_t domid,
-                                    unsigned long dst_pfn)
+                                    xen_pfn_t console_gfn)
 {
-    return dom_console_init(xch, domid, dst_pfn, false);
+    return dom_console_init(xch, domid, console_gfn, false);
 }
 
 /*
-- 
2.51.0
Re: [PATCH v2] libs/guest: don't use unsigned long as type for PFNs
Posted by Jason Andryuk 3 weeks, 3 days ago
On 2025-10-06 01:59, Juergen Gross wrote:
> Declarations of xc_dom_console_init() and
> xc_dom_console_set_disconnected() in libxenguest.h don't match their
> implementation in the library.
> 
> Under arm32, xen_pfn_t is a uint64_t and wider than unsigned long.
> 
> Use xen_pfn_t for GFNs in the library to fix that. At the same time
> change the parameter name of the implementation to console_gfn,
> matching the interface declaration in the header and reality (it is
> a GFN, not a PFN).
> 
> Fixes: b6fc307b0b00 ("libs/guest: Set console as disconnected on resume")
> Fixes: 971b7d5ecbcd ("libs/guest: Set console page to disconnected")
> Reported-by: Luca Fancellu <luca.fancellu@arm.com>
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
> V2:
> - switch parameter name as well (Andrew Cooper)

Thanks for doing this.  I ran the original series through CI, but didn't 
know that omits an arm32 toolstack build.

I see it's already in the tree, but here's an after-the-fact:

Reviewed-by: Jason Andryuk <jason.andryuk@amd.com>

Thanks again,
Jason
Re: [PATCH v2] libs/guest: don't use unsigned long as type for PFNs
Posted by Oleksii Kurochko 3 weeks, 3 days ago
On 10/6/25 7:59 AM, Juergen Gross wrote:
> Declarations of xc_dom_console_init() and
> xc_dom_console_set_disconnected() in libxenguest.h don't match their
> implementation in the library.
>
> Under arm32, xen_pfn_t is a uint64_t and wider than unsigned long.
>
> Use xen_pfn_t for GFNs in the library to fix that. At the same time
> change the parameter name of the implementation to console_gfn,
> matching the interface declaration in the header and reality (it is
> a GFN, not a PFN).
>
> Fixes: b6fc307b0b00 ("libs/guest: Set console as disconnected on resume")
> Fixes: 971b7d5ecbcd ("libs/guest: Set console page to disconnected")
> Reported-by: Luca Fancellu<luca.fancellu@arm.com>
> Signed-off-by: Juergen Gross<jgross@suse.com>

Release-Acked-By: Oleksii Kurochko<oleksii.kurochko@gmail.com>

Thanks.

~ Oleksii

> ---
> V2:
> - switch parameter name as well (Andrew Cooper)
> ---
>   tools/libs/guest/xg_dom_boot.c | 14 +++++++-------
>   1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/tools/libs/guest/xg_dom_boot.c b/tools/libs/guest/xg_dom_boot.c
> index f51b6a78c8..420222cf37 100644
> --- a/tools/libs/guest/xg_dom_boot.c
> +++ b/tools/libs/guest/xg_dom_boot.c
> @@ -430,12 +430,12 @@ int xc_dom_gnttab_init(struct xc_dom_image *dom)
>   
>   static int dom_console_init(xc_interface *xch,
>                               uint32_t domid,
> -                            unsigned long dst_pfn,
> +                            xen_pfn_t console_gfn,
>                               bool clear)
>   {
>       const size_t size = PAGE_SIZE;
>       struct xencons_interface *xencons = xc_map_foreign_range(
> -        xch, domid, size, PROT_WRITE, dst_pfn);
> +        xch, domid, size, PROT_WRITE, console_gfn);
>   
>       if ( xencons == NULL )
>           return -1;
> @@ -445,22 +445,22 @@ static int dom_console_init(xc_interface *xch,
>       xencons->connection = XENCONSOLE_DISCONNECTED;
>   
>       munmap(xencons, size);
> -    xc_domain_cacheflush(xch, domid, dst_pfn, 1);
> +    xc_domain_cacheflush(xch, domid, console_gfn, 1);
>       return 0;
>   }
>   
>   int xc_dom_console_init(xc_interface *xch,
>                           uint32_t domid,
> -                        unsigned long dst_pfn)
> +                        xen_pfn_t console_gfn)
>   {
> -    return dom_console_init(xch, domid, dst_pfn, true);
> +    return dom_console_init(xch, domid, console_gfn, true);
>   }
>   
>   int xc_dom_console_set_disconnected(xc_interface *xch,
>                                       uint32_t domid,
> -                                    unsigned long dst_pfn)
> +                                    xen_pfn_t console_gfn)
>   {
> -    return dom_console_init(xch, domid, dst_pfn, false);
> +    return dom_console_init(xch, domid, console_gfn, false);
>   }
>   
>   /*
Re: [PATCH v2] libs/guest: don't use unsigned long as type for PFNs
Posted by Luca Fancellu 3 weeks, 3 days ago
Hi Juergen,

> On 6 Oct 2025, at 06:59, Juergen Gross <jgross@suse.com> wrote:
> 
> Declarations of xc_dom_console_init() and
> xc_dom_console_set_disconnected() in libxenguest.h don't match their
> implementation in the library.
> 
> Under arm32, xen_pfn_t is a uint64_t and wider than unsigned long.
> 
> Use xen_pfn_t for GFNs in the library to fix that. At the same time
> change the parameter name of the implementation to console_gfn,
> matching the interface declaration in the header and reality (it is
> a GFN, not a PFN).
> 
> Fixes: b6fc307b0b00 ("libs/guest: Set console as disconnected on resume")
> Fixes: 971b7d5ecbcd ("libs/guest: Set console page to disconnected")
> Reported-by: Luca Fancellu <luca.fancellu@arm.com>
> Signed-off-by: Juergen Gross <jgross@suse.com>
> ---
> V2:
> - switch parameter name as well (Andrew Cooper)
> ---

Reviewed-by: Luca Fancellu <luca.fancellu@arm.com>
Tested-by: Luca Fancellu <luca.fancellu@arm.com>

Cheers,
Luca