diff mbox series

[v20210601,05/38] tools: add xc_is_known_page_type to libxenctrl

Message ID 20210601161118.18986-6-olaf@aepfle.de (mailing list archive)
State Superseded
Headers show
Series leftover from 2020 | expand

Commit Message

Olaf Hering June 1, 2021, 4:10 p.m. UTC
Users of xc_get_pfn_type_batch may want to sanity check the data
returned by Xen. Add a simple helper for this purpose.

Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
 tools/libs/ctrl/xc_private.h | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Comments

Jürgen Groß June 2, 2021, 6:51 a.m. UTC | #1
On 01.06.21 18:10, Olaf Hering wrote:
> Users of xc_get_pfn_type_batch may want to sanity check the data
> returned by Xen. Add a simple helper for this purpose.
> 
> Signed-off-by: Olaf Hering <olaf@aepfle.de>
> ---
>   tools/libs/ctrl/xc_private.h | 33 +++++++++++++++++++++++++++++++++
>   1 file changed, 33 insertions(+)
> 
> diff --git a/tools/libs/ctrl/xc_private.h b/tools/libs/ctrl/xc_private.h
> index 5d2c7274fb..afb08aafe1 100644
> --- a/tools/libs/ctrl/xc_private.h
> +++ b/tools/libs/ctrl/xc_private.h
> @@ -421,6 +421,39 @@ void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom,
>   int xc_get_pfn_type_batch(xc_interface *xch, uint32_t dom,
>                             unsigned int num, xen_pfn_t *);
>   
> +/* Sanitiy check for types returned by Xen */
> +static inline bool xc_is_known_page_type(xen_pfn_t type)
> +{
> +    bool ret;
> +
> +    switch (type)

I think you should not imply the planned use case here. It would be
better to use "switch (type & XEN_DOMCTL_PFINFO_LTAB_MASK)".

I'm on the edge regarding putting the new function into xc_private.h.
In the end your use case is _not_ to call the new function from
libxenctrl.


Juergen
Olaf Hering June 2, 2021, 11:10 a.m. UTC | #2
Am Wed, 2 Jun 2021 08:51:45 +0200
schrieb Juergen Gross <jgross@suse.com>:

> I think you should not imply the planned use case here. It would be
> better to use "switch (type & XEN_DOMCTL_PFINFO_LTAB_MASK)".
> 
> I'm on the edge regarding putting the new function into xc_private.h.
> In the end your use case is _not_ to call the new function from
> libxenctrl.


I'm not sure what that means.
One or the other has to be rebased to the new state.


Olaf
Jürgen Groß June 2, 2021, 11:48 a.m. UTC | #3
On 02.06.21 13:10, Olaf Hering wrote:
> Am Wed, 2 Jun 2021 08:51:45 +0200
> schrieb Juergen Gross <jgross@suse.com>:
> 
>> I think you should not imply the planned use case here. It would be
>> better to use "switch (type & XEN_DOMCTL_PFINFO_LTAB_MASK)".
>>
>> I'm on the edge regarding putting the new function into xc_private.h.
>> In the end your use case is _not_ to call the new function from
>> libxenctrl.
> 
> 
> I'm not sure what that means.

The name xc_private.h indicates that this header file is supposed to be
used only inside of libxenctrl. I know that this isn't true today, but
I don't think new misuses should be added to this file.

> One or the other has to be rebased to the new state.

You can add the same functions to some libxensaverestore prvate header
instead.


Juergen
diff mbox series

Patch

diff --git a/tools/libs/ctrl/xc_private.h b/tools/libs/ctrl/xc_private.h
index 5d2c7274fb..afb08aafe1 100644
--- a/tools/libs/ctrl/xc_private.h
+++ b/tools/libs/ctrl/xc_private.h
@@ -421,6 +421,39 @@  void *xc_map_foreign_ranges(xc_interface *xch, uint32_t dom,
 int xc_get_pfn_type_batch(xc_interface *xch, uint32_t dom,
                           unsigned int num, xen_pfn_t *);
 
+/* Sanitiy check for types returned by Xen */
+static inline bool xc_is_known_page_type(xen_pfn_t type)
+{
+    bool ret;
+
+    switch (type)
+    {
+    case XEN_DOMCTL_PFINFO_NOTAB:
+
+    case XEN_DOMCTL_PFINFO_L1TAB:
+    case XEN_DOMCTL_PFINFO_L1TAB | XEN_DOMCTL_PFINFO_LPINTAB:
+
+    case XEN_DOMCTL_PFINFO_L2TAB:
+    case XEN_DOMCTL_PFINFO_L2TAB | XEN_DOMCTL_PFINFO_LPINTAB:
+
+    case XEN_DOMCTL_PFINFO_L3TAB:
+    case XEN_DOMCTL_PFINFO_L3TAB | XEN_DOMCTL_PFINFO_LPINTAB:
+
+    case XEN_DOMCTL_PFINFO_L4TAB:
+    case XEN_DOMCTL_PFINFO_L4TAB | XEN_DOMCTL_PFINFO_LPINTAB:
+
+    case XEN_DOMCTL_PFINFO_XTAB:
+    case XEN_DOMCTL_PFINFO_XALLOC:
+    case XEN_DOMCTL_PFINFO_BROKEN:
+        ret = true;
+        break;
+    default:
+        ret = false;
+        break;
+    }
+    return ret;
+}
+
 void bitmap_64_to_byte(uint8_t *bp, const uint64_t *lp, int nbits);
 void bitmap_byte_to_64(uint64_t *lp, const uint8_t *bp, int nbits);