[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 2/6] tools: Introduce a non-truncating xc_xenver_extraversion()


  • To: Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>
  • From: Christian Lindig <christian.lindig@xxxxxxxxxx>
  • Date: Wed, 18 Jan 2023 13:35:07 +0000
  • Accept-language: en-GB, en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=citrix.com; dmarc=pass action=none header.from=citrix.com; dkim=pass header.d=citrix.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=LD1tWbftmkRjFPtPgfou7M08XKpMsZ7prFIdojMsm8c=; b=DjQkfGqXT7sNum+APTp7PYqr6ZEoTcf994ZhQXLyzlqPokf4+LViFq05abxYO7TGSSN1lrkHKGTDuM1HhlbM/PrhfJWaLWVUmdnZRqdZXfPKsjKV0sl8dCUyvpRDwWvYYxMmtWqU+8efyLiXANiKz4WOoBP561QuC4M6y78t46pEra5ZirBnTRAV1gxmJjc3Yjaf6Qken6jA1k7ozd3/3R7bkCkd1R6gfle1ovsdZSQHStqAICZPoGIGw/3Pc0V3gX0aj+M5ron46diCVD3LS/Vs6beJ9y0ynZsvvF4651AmxG/kkkebiAJKEP8k9kJgFS65Su1h1I7WJCPC3ba89w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YtjfvgzrwkI2QywwcbmLcAwY13p7RVbWxX5megmxlKJWZRaOrWpIGC2wWRFfz+zEH3D44/tONk7bkAwvv0/QiSJee49FDCAaEa+nxglhhvK3E8rOSKXKeMoAyv0wLAR8x9Qm61YopYRaQFFx9tJQNix5DxAdldBHfY7+IHvx5sGGOUc6lyhbtiWXTpl6MK1XuRx+egYFpXft0ccjLQVUur+3wSWB6PgytxTNl3Jm4E2xLHFFgu4CVQrEOY0Xl5b2cQPaO1UCr5XuxIx2ag2wycVZbMWxOB0oyTZAyoCwjcnPKY5aTGbaI++F27y1TEmpfZ9BcukvbItXmdounUwTfg==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=citrix.com;
  • Cc: Xen-devel <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Wei Liu <wl@xxxxxxx>, Anthony Perard <anthony.perard@xxxxxxxxxx>, Juergen Gross <jgross@xxxxxxxx>, David Scott <dave@xxxxxxxxxx>, Edwin Torok <edvin.torok@xxxxxxxxxx>, Rob Hoes <Rob.Hoes@xxxxxxxxxx>
  • Delivery-date: Wed, 18 Jan 2023 13:35:18 +0000
  • Ironport-data: A9a23:T+AwNqBnbpCUSRVW/xTiw5YqxClBgxIJ4kV8jS/XYbTApD9w1TdTy GAeXzyHOPveMWWhfo1zO4q0/BlQvJ/SyNFkQQY4rX1jcSlH+JHPbTi7wuUcHAvJd5GeExg3h yk6QoOdRCzhZiaE/n9BCpC48T8nk/nNHuCnYAL9EngZbRd+Tys8gg5Ulec8g4p56fC0GArIs t7pyyHlEAbNNwVcbyRFtMpvlDs15K6p4GpB7gRiDRx2lAS2e0c9Xcp3yZ6ZdxMUcqEMdsamS uDKyq2O/2+x13/B3fv8z94X2mVTKlLjFVDmZkh+AsBOsTAbzsAG6Y4pNeJ0VKtio27hc+ada jl6ncfYpQ8BZsUgkQmGOvVSO3kW0aZuoNcrLZUj2CA6IoKvn3bEmp1T4E8K0YIwuaVPPW5B3 6YjMjUyVxqipOzmwJCjRbw57igjBJGD0II3nFhFlGucJ9B2BJfJTuPN+MNS2yo2ioZWB/HCa sEFaD1pKhPdfxlIPVRRA5U79AuqriCnL3sE9xTI+OxuvTm7IA9ZidABNPLeesaLXtlUl0Deo mPA82X2KhobKMae2XyO9XfEaurnzHmlAthCT+fQGvhCr2e8+GgdLjwve3CDrbqmil+iC/1nA hlBksYphe1onKCxdfHtUhv9rHOasxo0X9tLD/Z8+AyL0rDT4QuSGi4DVDEpQMMinN87Q3otz FDht9HmHzt0q5WOVGmQsLyTqFuaNSELIEcYaCQDTA9D5MPsyLzflTrKR9dnVaSz3tv8HGiqx yjQ9XZvwbIOkcQMyqO3u0jdhC6hrYTISQhz4RjLWmWi7UVyY4vNi5GU1GU3JM1odO6xJmRtd lBe8yRCxIji1a2wqRE=
  • Ironport-hdrordr: A9a23:o9eI+q0CudJa8JxF+5ywDgqjBLokLtp133Aq2lEZdPUCSL38qy nIpoV46faUskdzZJhEo7q90ca7LE80maQY3WBzB9eftWvd1ldARbsKheDfKlbbehEWmNQz6U /QGJIObOHNMQ==
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHZKnsgoIAIvLZD2kO3NYPKMb1VtK6kLLyA
  • Thread-topic: [PATCH 2/6] tools: Introduce a non-truncating xc_xenver_extraversion()


> On 17 Jan 2023, at 13:53, Andrew Cooper <andrew.cooper3@xxxxxxxxxx> wrote:
> 
> ... which uses XENVER_extraversion2.
> 
> In order to do sensibly, use manual hypercall buffer handling.  Not only does
> this avoid an extra bounce buffer (we need to strip the xen_varbuf_t header
> anyway), it's also shorter and easlier to follow.
> 
> Update libxl and the ocaml stubs to match.  No API/ABI change in either.
> 
> With this change made, `xl info` can now correctly access a >15 char
> extraversion:
> 
>  # xl info xen_version
>  4.18-unstable+REALLY LONG EXTRAVERSION
> 
> Signed-off-by: Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
> ---
> CC: Wei Liu <wl@xxxxxxx>
> CC: Anthony PERARD <anthony.perard@xxxxxxxxxx>
> CC: Juergen Gross <jgross@xxxxxxxx>
> CC: Christian Lindig <christian.lindig@xxxxxxxxxx>
> CC: David Scott <dave@xxxxxxxxxx>
> CC: Edwin Torok <edvin.torok@xxxxxxxxxx>
> CC: Rob Hoes <Rob.Hoes@xxxxxxxxxx>

Acked-by: Christian Lindig <christian.lindig@xxxxxxxxxx>

> 
> Note: There is a marginal risk for a memory leak in the ocaml bindings, but
> it turns out we have the same bug elsewhere and fixing that is going to be
> rather complicated.
> ---
> tools/include/xenctrl.h             |  6 +++
> tools/libs/ctrl/xc_version.c        | 75 +++++++++++++++++++++++++++++++++++++
> tools/libs/light/libxl.c            |  4 +-
> tools/ocaml/libs/xc/xenctrl_stubs.c |  9 +++--
> 4 files changed, 87 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/include/xenctrl.h b/tools/include/xenctrl.h
> index 23037874d3d5..1e88d49371a4 100644
> --- a/tools/include/xenctrl.h
> +++ b/tools/include/xenctrl.h
> @@ -1604,6 +1604,12 @@ long xc_memory_op(xc_interface *xch, unsigned int cmd, 
> void *arg, size_t len);
> 
> int xc_version(xc_interface *xch, int cmd, void *arg);
> 
> +/*
> + * Wrappers around XENVER_* subops.  Callers must pass the returned pointer 
> to
> + * free().
> + */
> +char *xc_xenver_extraversion(xc_interface *xch);
> +
> int xc_flask_op(xc_interface *xch, xen_flask_op_t *op);
> 
> /*
> diff --git a/tools/libs/ctrl/xc_version.c b/tools/libs/ctrl/xc_version.c
> index 60e107dcee0b..2c14474feec5 100644
> --- a/tools/libs/ctrl/xc_version.c
> +++ b/tools/libs/ctrl/xc_version.c
> @@ -81,3 +81,78 @@ int xc_version(xc_interface *xch, int cmd, void *arg)
> 
>     return rc;
> }
> +
> +/*
> + * Raw hypercall wrapper, letting us pass NULL and things which aren't of
> + * xc_hypercall_buffer_t *.
> + */
> +static int do_xen_version_raw(xc_interface *xch, int cmd, void *hbuf)
> +{
> +    return xencall2(xch->xcall, __HYPERVISOR_xen_version,
> +                    cmd, (unsigned long)hbuf);
> +}
> +
> +/*
> + * Issues a xen_varbuf_t subop, using manual hypercall buffer handling to
> + * avoid unnecessary buffering.
> + *
> + * On failure, returns NULL.  errno probably useful.
> + * On success, returns a pointer which must be freed with 
> xencall_free_buffer().
> + */
> +static xen_varbuf_t *varbuf_op(xc_interface *xch, unsigned int subop)
> +{
> +    xen_varbuf_t *hbuf = NULL;
> +    ssize_t sz;
> +
> +    sz = do_xen_version_raw(xch, subop, NULL);
> +    if ( sz < 0 )
> +        return NULL;
> +
> +    hbuf = xencall_alloc_buffer(xch->xcall, sizeof(*hbuf) + sz);
> +    if ( !hbuf )
> +        return NULL;
> +
> +    hbuf->len = sz;
> +
> +    sz = do_xen_version_raw(xch, subop, hbuf);
> +    if ( sz < 0 )
> +    {
> +        xencall_free_buffer(xch->xcall, hbuf);
> +        return NULL;
> +    }
> +
> +    hbuf->len = sz;
> +    return hbuf;
> +}
> +
> +/*
> + * Wrap varbuf_op() to obtain a simple string.  Copy out of the hypercall
> + * buffer, stripping the xen_varbuf_t header and appending a NUL terminator.
> + *
> + * On failure, returns NULL, errno probably useful.
> + * On success, returns a pointer which must be free()'d.
> + */
> +static char *varbuf_simple_string(xc_interface *xch, unsigned int subop)
> +{
> +    xen_varbuf_t *hbuf = varbuf_op(xch, subop);
> +    char *res;
> +
> +    if ( !hbuf )
> +        return NULL;
> +
> +    res = malloc(hbuf->len + 1);
> +    if ( res )
> +    {
> +        memcpy(res, hbuf->buf, hbuf->len);
> +        res[hbuf->len] = '\0';
> +    }
> +
> +    xencall_free_buffer(xch->xcall, hbuf);
> +
> +    return res;
> +}
> +
> +char *xc_xenver_extraversion(xc_interface *xch)
> +{
> +    return varbuf_simple_string(xch, XENVER_extraversion2);
> +}
> diff --git a/tools/libs/light/libxl.c b/tools/libs/light/libxl.c
> index a0bf7d186f69..3e16e568839c 100644
> --- a/tools/libs/light/libxl.c
> +++ b/tools/libs/light/libxl.c
> @@ -581,7 +581,6 @@ const libxl_version_info* 
> libxl_get_version_info(libxl_ctx *ctx)
> {
>     GC_INIT(ctx);
>     union {
> -        xen_extraversion_t xen_extra;
>         xen_compile_info_t xen_cc;
>         xen_changeset_info_t xen_chgset;
>         xen_capabilities_info_t xen_caps;
> @@ -600,8 +599,7 @@ const libxl_version_info* 
> libxl_get_version_info(libxl_ctx *ctx)
>     info->xen_version_major = xen_version >> 16;
>     info->xen_version_minor = xen_version & 0xFF;
> 
> -    xc_version(ctx->xch, XENVER_extraversion, &u.xen_extra);
> -    info->xen_version_extra = libxl__strdup(NOGC, u.xen_extra);
> +    info->xen_version_extra = xc_xenver_extraversion(ctx->xch);
> 
>     xc_version(ctx->xch, XENVER_compile_info, &u.xen_cc);
>     info->compiler = libxl__strdup(NOGC, u.xen_cc.compiler);
> diff --git a/tools/ocaml/libs/xc/xenctrl_stubs.c 
> b/tools/ocaml/libs/xc/xenctrl_stubs.c
> index 2fba9c5e94d6..f3ce12dd8683 100644
> --- a/tools/ocaml/libs/xc/xenctrl_stubs.c
> +++ b/tools/ocaml/libs/xc/xenctrl_stubs.c
> @@ -929,9 +929,8 @@ CAMLprim value stub_xc_version_version(value xch)
> {
>       CAMLparam1(xch);
>       CAMLlocal1(result);
> -     xen_extraversion_t extra;
> +     char *extra;
>       long packed;
> -     int retval;
> 
>       caml_enter_blocking_section();
>       packed = xc_version(_H(xch), XENVER_version, NULL);
> @@ -941,10 +940,10 @@ CAMLprim value stub_xc_version_version(value xch)
>               failwith_xc(_H(xch));
> 
>       caml_enter_blocking_section();
> -     retval = xc_version(_H(xch), XENVER_extraversion, &extra);
> +     extra = xc_xenver_extraversion(_H(xch));
>       caml_leave_blocking_section();
> 
> -     if (retval)
> +     if (!extra)
>               failwith_xc(_H(xch));
> 
>       result = caml_alloc_tuple(3);
> @@ -953,6 +952,8 @@ CAMLprim value stub_xc_version_version(value xch)
>       Store_field(result, 1, Val_int(packed & 0xffff));
>       Store_field(result, 2, caml_copy_string(extra));
> 
> +     free(extra);
> +
>       CAMLreturn(result);
> }
> 
> -- 
> 2.11.0
> 




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.