Message ID | 20210701095635.15648-11-olaf@aepfle.de (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | leftover from 2020 | expand |
On 01/07/2021 10:56, 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> Subject needs correcting after v2. However, given that this is in the save/restore common header, does it really need a prefix? Simply is_known_page_type() seems good enough. > > v02: > - rename xc_is_known_page_type to sr_is_known_page_type > - move from ctrl/xc_private.h to saverestore/common.h (jgross) > --- > tools/libs/saverestore/common.h | 33 +++++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/common.h > index ca2eb47a4f..07c506360c 100644 > --- a/tools/libs/saverestore/common.h > +++ b/tools/libs/saverestore/common.h > @@ -467,6 +467,39 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned int count, > /* Handle a STATIC_DATA_END record. */ > int handle_static_data_end(struct xc_sr_context *ctx); > > +/* Sanitiy check for types returned by Xen */ > +static inline bool sr_is_known_page_type(xen_pfn_t type) uint32_t > +{ > + bool ret; The logic will be rather shorter and cleaner to read by dropping ret and using return directly out of the switch. > + > + switch (type) Spaces. I can fix up everything on commit if you're happy with the suggestions. ~Andrew
Am Fri, 2 Jul 2021 20:20:08 +0100 schrieb Andrew Cooper <andrew.cooper3@citrix.com>: > Subject needs correcting after v2. Apparently I missed some places while removing the old "xc_" prefix. > However, given that this is in the save/restore common header, does it > really need a prefix? Simply is_known_page_type() seems good enough. Sure, the possibility of clashes is probably low. > > +/* Sanitiy check for types returned by Xen */ > > +static inline bool sr_is_known_page_type(xen_pfn_t type) > uint32_t Why is this better than returning 'bool'? > I can fix up everything on commit if you're happy with the suggestions. Yes, I'm certainly fine with it. Olaf
On 05/07/2021 09:22, Olaf Hering wrote: > Am Fri, 2 Jul 2021 20:20:08 +0100 > schrieb Andrew Cooper <andrew.cooper3@citrix.com>: >>> +/* Sanitiy check for types returned by Xen */ >>> +static inline bool sr_is_known_page_type(xen_pfn_t type) >> uint32_t > Why is this better than returning 'bool'? For the parameter sorry, not the return type. All type fields are uniformly uint32_t elsewhere. > >> I can fix up everything on commit if you're happy with the suggestions. > Yes, I'm certainly fine with it. Ok - I'll put together a branch. ~Andrew
Am Mon, 5 Jul 2021 10:51:50 +0100
schrieb Andrew Cooper <andrew.cooper3@citrix.com>:
> All type fields are uniformly uint32_t elsewhere.
To me it looks like xc_get_pfn_type_batch writes to an array of xen_pfn_t.
Olaf
diff --git a/tools/libs/saverestore/common.h b/tools/libs/saverestore/common.h index ca2eb47a4f..07c506360c 100644 --- a/tools/libs/saverestore/common.h +++ b/tools/libs/saverestore/common.h @@ -467,6 +467,39 @@ int populate_pfns(struct xc_sr_context *ctx, unsigned int count, /* Handle a STATIC_DATA_END record. */ int handle_static_data_end(struct xc_sr_context *ctx); +/* Sanitiy check for types returned by Xen */ +static inline bool sr_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: /* Synthetic type in Xen 4.2 - 4.5 */ + case XEN_DOMCTL_PFINFO_BROKEN: + ret = true; + break; + default: + ret = false; + break; + } + return ret; +} + #endif /* * Local variables:
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> v02: - rename xc_is_known_page_type to sr_is_known_page_type - move from ctrl/xc_private.h to saverestore/common.h (jgross) --- tools/libs/saverestore/common.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)