Re: [PATCH v3 1/3] tools/xenctrl: add xc_get_cpu_version()

2023-03-21 Thread Andrew Cooper
On 21/03/2023 11:47 am, Sergey Dyasli wrote:
> diff --git a/tools/libs/ctrl/xc_misc.c b/tools/libs/ctrl/xc_misc.c
> index 265f15ec2d..f2f6e4348e 100644
> --- a/tools/libs/ctrl/xc_misc.c
> +++ b/tools/libs/ctrl/xc_misc.c
> @@ -226,6 +226,26 @@ int xc_microcode_update(xc_interface *xch, const void 
> *buf, size_t len)
>  return ret;
>  }
>  
> +int xc_get_cpu_version(xc_interface *xch, struct xenpf_pcpu_version *cpu_ver)
> +{
> +int ret;
> +DECLARE_PLATFORM_OP;
> +
> +if ( !xch || !cpu_ver )
> +return -1;

We don't check parameters like this anywhere else.  It's library code,
and the caller is required to DTRT.

Also, we're phasing out the use of the DECLARE macros.  This wants to
change to

struct xen_platform_op op = {
    .cmd = XENPF_get_cpu_version,
    .u.pcpu_version.xen_cpuid = cpu_ver->xen_cpuid,
};

Both can be fixed on commit, if you're happy.

~Andrew



[PATCH v3 1/3] tools/xenctrl: add xc_get_cpu_version()

2023-03-21 Thread Sergey Dyasli
As a wrapper for XENPF_get_cpu_version platform op.

Signed-off-by: Sergey Dyasli 
---
 tools/include/xenctrl.h   |  1 +
 tools/libs/ctrl/xc_misc.c | 20 
 2 files changed, 21 insertions(+)

diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
index 23037874d3..8aa747dc2e 100644
--- a/tools/include/xenctrl.h
+++ b/tools/include/xenctrl.h
@@ -1186,6 +1186,7 @@ int xc_physinfo(xc_interface *xch, xc_physinfo_t *info);
 int xc_cputopoinfo(xc_interface *xch, unsigned *max_cpus,
xc_cputopo_t *cputopo);
 int xc_microcode_update(xc_interface *xch, const void *buf, size_t len);
+int xc_get_cpu_version(xc_interface *xch, struct xenpf_pcpu_version *cpu_ver);
 int xc_numainfo(xc_interface *xch, unsigned *max_nodes,
 xc_meminfo_t *meminfo, uint32_t *distance);
 int xc_pcitopoinfo(xc_interface *xch, unsigned num_devs,
diff --git a/tools/libs/ctrl/xc_misc.c b/tools/libs/ctrl/xc_misc.c
index 265f15ec2d..f2f6e4348e 100644
--- a/tools/libs/ctrl/xc_misc.c
+++ b/tools/libs/ctrl/xc_misc.c
@@ -226,6 +226,26 @@ int xc_microcode_update(xc_interface *xch, const void 
*buf, size_t len)
 return ret;
 }
 
+int xc_get_cpu_version(xc_interface *xch, struct xenpf_pcpu_version *cpu_ver)
+{
+int ret;
+DECLARE_PLATFORM_OP;
+
+if ( !xch || !cpu_ver )
+return -1;
+
+platform_op.cmd = XENPF_get_cpu_version;
+platform_op.u.pcpu_version.xen_cpuid = cpu_ver->xen_cpuid;
+
+ret = do_platform_op(xch, _op);
+if ( ret != 0 )
+return ret;
+
+*cpu_ver = platform_op.u.pcpu_version;
+
+return 0;
+}
+
 int xc_cputopoinfo(xc_interface *xch, unsigned *max_cpus,
xc_cputopo_t *cputopo)
 {
-- 
2.17.1