xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: "Jan Beulich" <JBeulich@suse.com>
To: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Cc: Wei Liu <wei.liu2@citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
	andrew.cooper3@citrix.com,
	Ian Jackson <ian.jackson@eu.citrix.com>,
	mpohlack@amazon.de, ross.lagerwall@citrix.com,
	xen-devel@lists.xenproject.org,
	Daniel De Graaf <dgdegra@tycho.nsa.gov>,
	sasha.levin@oracle.com
Subject: Re: [PATCH v4 12/34] xen/xsplice: Hypervisor implementation of XEN_XSPLICE_op
Date: Wed, 23 Mar 2016 07:51:29 -0600	[thread overview]
Message-ID: <56F2AD7102000078000DFAEB@prv-mh.provo.novell.com> (raw)
In-Reply-To: <1458064616-23101-13-git-send-email-konrad.wilk@oracle.com>

>>> On 15.03.16 at 18:56, <konrad.wilk@oracle.com> wrote:
> --- a/xen/common/Kconfig
> +++ b/xen/common/Kconfig
> @@ -168,4 +168,15 @@ config SCHED_DEFAULT
>  
>  endmenu
>  
> +# Enable/Disable xsplice support
> +config XSPLICE
> +	bool "xSplice live patching support"
> +	default y

Isn't it a little early in the series to default this to on?

And then of course the EXPERT question comes up again. No
matter that IanC is no longer around to help with the
argumentation, the point he has been making about too many
flavors ending up in the wild continues to apply.

> @@ -460,6 +461,12 @@ long do_sysctl(XEN_GUEST_HANDLE_PARAM(xen_sysctl_t) u_sysctl)
>          ret = tmem_control(&op->u.tmem_op);
>          break;
>  
> +    case XEN_SYSCTL_xsplice_op:
> +        ret = xsplice_op(&op->u.xsplice);
> +        if ( ret != -ENOSYS )
> +            copyback = 1;
> +        break;

Why is ENOSYS special here, but not e.g. EOPNOTSUPP?

> +struct payload {
> +    uint32_t state;                      /* One of the XSPLICE_STATE_*. */
> +    int32_t rc;                          /* 0 or -XEN_EXX. */
> +    struct list_head list;               /* Linked to 'payload_list'. */
> +    char name[XEN_XSPLICE_NAME_SIZE + 1];/* Name of it. */

Could I talk you into reducing XEN_XSPLICE_NAME_SIZE to 127,
to avoid needless padding in places like this one?

> +static int verify_name(const xen_xsplice_name_t *name)
> +{
> +    if ( name->size == 0 || name->size > XEN_XSPLICE_NAME_SIZE )
> +        return -EINVAL;
> +
> +    if ( name->pad[0] || name->pad[1] || name->pad[2] )

I'd like to ask for consistency here: Either always use == 0 / != 0,
or always omit the latter and use ! in place of the former.

> +static int verify_payload(const xen_sysctl_xsplice_upload_t *upload)
> +{
> +    if ( verify_name(&upload->name) )
> +        return -EINVAL;
> +
> +    if ( upload->size == 0 )
> +        return -EINVAL;
> +
> +    if ( !guest_handle_okay(upload->payload, upload->size) )

Careful here - upload->size is uint64_t, yet array_access_ok() makes
assumptions on not too large a size getting passed. I.e. I think you
want to apply an upper bound to the size right here - for example, it
can't reasonably be bigger than XEN_VIRT_END - XEN_VIRT_START
if I remember correctly how you intend to place those payloads.

> +static int find_payload(const xen_xsplice_name_t *name, struct payload **f)

Perhaps neater to use the xen/err.h constructs here instead
of indirection?

> +{
> +    struct payload *data;
> +    XEN_GUEST_HANDLE_PARAM(char) str;
> +    char n[XEN_XSPLICE_NAME_SIZE + 1] = { 0 };

This pointlessly zeroes the entire array. Just set str[name->size]
to zero after the copy-in.

> +    int rc = -EINVAL;

Pointless initializer.

> +    rc = verify_name(name);
> +    if ( rc )
> +        return rc;
> +
> +    str = guest_handle_cast(name->name, char);

Why do you need a cast here?

> +    if ( copy_from_guest(n, str, name->size) )

You validated the address range already, so __copy_from_guest()
will be just fine and more efficient.

> +        return -EFAULT;
> +
> +    spin_lock_recursive(&payload_lock);

Why do you need a recursive lock here? I think something like this
should be reasoned about in the commit message.

> +/*
> + * We MUST be holding the payload_lock spinlock.
> + */

Single line comment (but kind of redundant with ...

> +static void free_payload(struct payload *data)
> +{
> +    ASSERT(spin_is_locked(&payload_lock));

... this anyway).

> +static int xsplice_upload(xen_sysctl_xsplice_upload_t *upload)
> +{
> +    struct payload *data = NULL;

Pointless initializer.

> +    void *raw_data = NULL;
> +    int rc;
> +
> +    rc = verify_payload(upload);
> +    if ( rc )
> +        return rc;
> +
> +    rc = find_payload(&upload->name, &data);
> +    if ( rc == 0 /* Found. */ )
> +        return -EEXIST;
> +
> +    if ( rc != -ENOENT )
> +        return rc;
> +
> +    data = xzalloc(struct payload);
> +    if ( !data )
> +        return -ENOMEM;
> +
> +    rc = -EFAULT;
> +    if ( copy_from_guest(data->name, upload->name.name, upload->name.size) )

__copy_from_guest()

> +        goto out;
> +
> +    rc = -ENOMEM;
> +    raw_data = vzalloc(upload->size);

vmalloc()

> +    if ( !raw_data )
> +        goto out;
> +
> +    rc = -EFAULT;
> +    if ( copy_from_guest(raw_data, upload->payload, upload->size) )

__copy_from_guest()

> +        goto out;
> +
> +    data->state = XSPLICE_STATE_CHECKED;
> +    data->rc = 0;

This is redundant with the xzalloc() above.

> +    INIT_LIST_HEAD(&data->list);
> +
> +    spin_lock_recursive(&payload_lock);
> +    list_add_tail(&data->list, &payload_list);
> +    payload_cnt++;
> +    payload_version++;
> +    spin_unlock_recursive(&payload_lock);
> +
> + out:
> +    vfree(raw_data);

By here you allocated and filled raw_data. And now you
unconditionally free it. What is that good for?

> +    if ( rc )
> +    {
> +        xfree(data);
> +    }

The use of braces here is inconsistent with all of the rest of this
function.

> +static int xsplice_get(xen_sysctl_xsplice_get_t *get)
> +{
> +    struct payload *data;
> +    int rc;
> +
> +    rc = verify_name(&get->name);
> +    if ( rc )
> +        return rc;
> +
> +    rc = find_payload(&get->name, &data);
> +    if ( rc )
> +        return rc;
> +
> +    get->status.state = data->state;
> +    get->status.rc = data->rc;

What guarantees that data didn't get freed by the time you get here?

> +static int xsplice_list(xen_sysctl_xsplice_list_t *list)
> +{
> +    xen_xsplice_status_t status;
> +    struct payload *data;
> +    unsigned int idx = 0, i = 0;
> +    int rc = 0;
> +
> +    if ( list->nr > 1024 )
> +        return -E2BIG;
> +
> +    if ( list->pad != 0 )
> +        return -EINVAL;
> +
> +    if ( !guest_handle_okay(list->status, sizeof(status) * list->nr) ||
> +         !guest_handle_okay(list->name, XEN_XSPLICE_NAME_SIZE * list->nr) ||
> +         !guest_handle_okay(list->len, sizeof(uint32_t) * list->nr) )

guest_handle_okay() already takes into account the element size,
i.e. it's only the middle one which needs to do any multiplication.

> +        return -EINVAL;
> +
> +    spin_lock_recursive(&payload_lock);
> +    if ( list->idx > payload_cnt || !list->nr )

The list->nr check could move up outside the locked region (e.g.
merge with the pad field check).

> +    {
> +        spin_unlock_recursive(&payload_lock);
> +        return -EINVAL;
> +    }
> +
> +    list_for_each_entry( data, &payload_list, list )

Aren't you lacking a list->version check prior to entering this loop
(which would then mean you don't need to store it below, but only
on the error path from that check)?

> +    {
> +        uint32_t len;
> +
> +        if ( list->idx > i++ )
> +            continue;
> +
> +        status.state = data->state;
> +        status.rc = data->rc;
> +        len = strlen(data->name);
> +
> +        /* N.B. 'idx' != 'i'. */
> +        if ( __copy_to_guest_offset(list->name, idx * XEN_XSPLICE_NAME_SIZE,
> +                                    data->name, len) ||
> +             __copy_to_guest_offset(list->len, idx, &len, 1) ||

You're not coping the NUL terminator here, which makes the result
more cumbersome to consume by the caller. Perhaps
XEN_XSPLICE_NAME_SIZE should remain to be 128 (other than
suggested above), but be specified to include the terminator?

> +             __copy_to_guest_offset(list->status, idx, &status, 1) )
> +        {
> +            rc = -EFAULT;
> +            break;
> +        }
> +
> +        idx++;
> +
> +        if ( hypercall_preempt_check() || (idx + 1 > list->nr) )

idx >= list->nr would seem easier to grok. Also the two should be
switched, as hypercall_preempt_check() is the more expensive of
the two checks.

> +static int xsplice_action(xen_sysctl_xsplice_action_t *action)
> +{
> +    struct payload *data;
> +    int rc;
> +
> +    rc = verify_name(&action->name);
> +    if ( rc )
> +        return rc;
> +
> +    spin_lock_recursive(&payload_lock);
> +    rc = find_payload(&action->name, &data);
> +    if ( rc )
> +        goto out;
> +
> +    switch ( action->cmd )
> +    {
> +    case XSPLICE_ACTION_CHECK:
> +        if ( data->state == XSPLICE_STATE_CHECKED )
> +        {
> +            /* No implementation yet. */
> +            data->state = XSPLICE_STATE_CHECKED;
> +            data->rc = 0;
> +            rc = 0;

rc is zero already.

> +        }
> +        break;
> +
> +    case XSPLICE_ACTION_UNLOAD:
> +        if ( data->state == XSPLICE_STATE_CHECKED )
> +        {
> +            free_payload(data);
> +            /* No touching 'data' from here on! */

Poison the pointer to make sure?

> +            rc = 0;
> +        }
> +        break;
> +
> +    case XSPLICE_ACTION_REVERT:
> +        if ( data->state == XSPLICE_STATE_APPLIED )
> +        {
> +            /* No implementation yet. */
> +            data->state = XSPLICE_STATE_CHECKED;
> +            data->rc = 0;
> +            rc = 0;
> +        }
> +        break;
> +
> +    case XSPLICE_ACTION_APPLY:
> +        if ( (data->state == XSPLICE_STATE_CHECKED) )

Stray parentheses.

> +static void xsplice_printall(unsigned char key)
> +{
> +    struct payload *data;
> +
> +    spin_lock_recursive(&payload_lock);

I think this would better be a try-lock, bailing if the acquire failed.

Jan

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

  parent reply	other threads:[~2016-03-23 13:51 UTC|newest]

Thread overview: 124+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-15 17:56 [PATCH v4] xSplice v1 design and implementation Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 01/34] compat/x86: Remove unncessary #define Konrad Rzeszutek Wilk
2016-03-15 18:57   ` Andrew Cooper
2016-03-16 11:08   ` Jan Beulich
2016-03-17  0:44     ` Konrad Rzeszutek Wilk
2016-03-17  7:45       ` Jan Beulich
2016-03-15 17:56 ` [PATCH v4 02/34] libxc: Remove dead code (XENVER_capabilities) Konrad Rzeszutek Wilk
2016-03-15 18:04   ` Andrew Cooper
2016-03-15 18:08     ` Konrad Rzeszutek Wilk
2016-03-16 18:11   ` Wei Liu
2016-03-15 17:56 ` [PATCH v4 03/34] xsm/xen_version: Add XSM for the xen_version hypercall Konrad Rzeszutek Wilk
2016-03-18 11:55   ` Jan Beulich
2016-03-18 17:26     ` Konrad Rzeszutek Wilk
2016-03-21 11:22       ` Jan Beulich
2016-03-22 16:10         ` Konrad Rzeszutek Wilk
2016-03-22 17:54           ` Daniel De Graaf
2016-03-22 17:49   ` Daniel De Graaf
2016-03-24 15:34   ` anshul makkar
2016-03-24 19:19     ` Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 04/34] HYPERCALL_version_op. New hypercall mirroring XENVER_ but sane Konrad Rzeszutek Wilk
2016-03-15 18:29   ` Andrew Cooper
2016-03-15 20:19     ` Konrad Rzeszutek Wilk
2016-03-17  1:38       ` Konrad Rzeszutek Wilk
2016-03-17 14:28         ` Andrew Cooper
2016-03-18 12:36         ` Jan Beulich
2016-03-18 19:22           ` Konrad Rzeszutek Wilk
2016-03-21 12:45             ` Jan Beulich
2016-03-22 15:52               ` Konrad Rzeszutek Wilk
2016-03-22 16:06                 ` Jan Beulich
2016-03-22 18:57                   ` Konrad Rzeszutek Wilk
2016-03-22 19:28                     ` Andrew Cooper
2016-03-22 20:39                       ` Konrad Rzeszutek Wilk
2016-03-23  8:56                         ` Jan Beulich
2016-03-24  2:37                           ` Konrad Rzeszutek Wilk
2016-03-24  9:15                             ` Jan Beulich
2016-03-24 11:39                               ` Konrad Rzeszutek Wilk
2016-03-22 17:51   ` Daniel De Graaf
2016-03-15 17:56 ` [PATCH v4 05/34] libxc/libxl/python/xenstat: Use new XEN_VERSION_OP hypercall Konrad Rzeszutek Wilk
2016-03-15 18:45   ` Andrew Cooper
2016-03-16 12:31   ` George Dunlap
2016-03-16 18:11   ` Wei Liu
2016-03-17  1:08     ` Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 06/34] x86/arm: Add BUGFRAME_NR define and BUILD checks Konrad Rzeszutek Wilk
2016-03-15 18:54   ` Andrew Cooper
2016-03-16 11:49   ` Julien Grall
2016-03-18 12:40   ` Jan Beulich
2016-03-18 19:59     ` Konrad Rzeszutek Wilk
2016-03-21 12:49       ` Jan Beulich
2016-03-22 15:39         ` Konrad Rzeszutek Wilk
2016-03-22 15:58           ` Jan Beulich
2016-03-15 17:56 ` [PATCH v4 07/34] arm/x86: Use struct virtual_region to do bug, symbol, and (x86) exception tables Konrad Rzeszutek Wilk
2016-03-15 19:24   ` Andrew Cooper
2016-03-15 19:34     ` Konrad Rzeszutek Wilk
2016-03-15 19:51       ` Andrew Cooper
2016-03-15 20:02         ` Andrew Cooper
2016-03-16 10:33           ` Jan Beulich
2016-03-18 13:07   ` Jan Beulich
2016-03-22 20:18     ` Konrad Rzeszutek Wilk
2016-03-23  8:19       ` Jan Beulich
2016-03-23 11:17         ` Julien Grall
2016-03-23 11:21           ` Jan Beulich
2016-03-24  2:49         ` Konrad Rzeszutek Wilk
2016-03-24  9:20           ` Jan Beulich
2016-03-15 17:56 ` [PATCH v4 08/34] vmap: Make the while loop less fishy Konrad Rzeszutek Wilk
2016-03-15 19:33   ` Andrew Cooper
2016-03-17 11:49     ` Jan Beulich
2016-03-17 14:37       ` Andrew Cooper
2016-03-17 15:30         ` Jan Beulich
2016-03-17 16:06           ` Ian Jackson
2016-03-17 11:48   ` Jan Beulich
2016-03-17 16:08   ` Ian Jackson
2016-03-21 12:04     ` George Dunlap
2016-03-21 13:26       ` Jan Beulich
2016-03-21 14:22         ` George Dunlap
2016-03-21 15:05           ` Jan Beulich
2016-03-15 17:56 ` [PATCH v4 09/34] vmap: ASSERT on NULL Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 10/34] vmap: Add vmalloc_cb and vfree_cb Konrad Rzeszutek Wilk
2016-03-18 13:20   ` Jan Beulich
2016-03-15 17:56 ` [PATCH v4 11/34] xsplice: Design document Konrad Rzeszutek Wilk
2016-03-23 11:18   ` Jan Beulich
2016-03-23 20:12     ` Konrad Rzeszutek Wilk
2016-03-23 20:21       ` Konrad Rzeszutek Wilk
2016-03-24  3:15     ` Konrad Rzeszutek Wilk
2016-03-24  9:32       ` Jan Beulich
2016-03-15 17:56 ` [PATCH v4 12/34] xen/xsplice: Hypervisor implementation of XEN_XSPLICE_op Konrad Rzeszutek Wilk
2016-03-16 12:12   ` Julien Grall
2016-03-16 19:58     ` Konrad Rzeszutek Wilk
2016-03-23 13:51   ` Jan Beulich [this message]
2016-03-24  3:13     ` Konrad Rzeszutek Wilk
2016-03-24  9:29       ` Jan Beulich
2016-03-15 17:56 ` [PATCH v4 13/34] libxc: Implementation of XEN_XSPLICE_op in libxc Konrad Rzeszutek Wilk
2016-03-16 18:12   ` Wei Liu
2016-03-16 20:36     ` Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 14/34] xen-xsplice: Tool to manipulate xsplice payloads Konrad Rzeszutek Wilk
2016-03-16 18:12   ` Wei Liu
2016-03-15 17:56 ` [PATCH v4 15/34] xsplice: Add helper elf routines Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 16/34] xsplice: Implement payload loading Konrad Rzeszutek Wilk
2016-03-22 17:25   ` Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 17/34] xsplice: Implement support for applying/reverting/replacing patches Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 18/34] x86/xen_hello_world.xsplice: Test payload for patching 'xen_extra_version' Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 19/34] xsplice, symbols: Implement symbol name resolution on address Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 20/34] x86, xsplice: Print payload's symbol name and payload name in backtraces Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 21/34] xsplice: Add .xsplice.hooks functions and test-case Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 22/34] xsplice: Add support for bug frames Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 23/34] xsplice: Add support for exception tables Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 24/34] xsplice: Add support for alternatives Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 25/34] build_id: Provide ld-embedded build-ids Konrad Rzeszutek Wilk
2016-03-16 18:34   ` Julien Grall
2016-03-16 21:02     ` Konrad Rzeszutek Wilk
2016-03-17  1:12       ` Konrad Rzeszutek Wilk
2016-03-17 11:08         ` Julien Grall
2016-03-17 13:39           ` Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 26/34] HYPERCALL_version_op: Add VERSION_OP_build_id to retrieve build-id Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 27/34] libxl: info: Display build_id of the hypervisor using XEN_VERSION_OP_build_id Konrad Rzeszutek Wilk
2016-03-16 18:12   ` Wei Liu
2016-03-15 17:56 ` [PATCH v4 28/34] xsplice: Print build_id in keyhandler and on bootup Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 29/34] xsplice: Stacking build-id dependency checking Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 30/34] xsplice/xen_replace_world: Test-case for XSPLICE_ACTION_REPLACE Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 31/34] xsplice: Print dependency and payloads build_id in the keyhandler Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 32/34] xsplice: Prevent duplicate payloads from being loaded Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 33/34] xsplice: Add support for shadow variables Konrad Rzeszutek Wilk
2016-03-15 17:56 ` [PATCH v4 34/34] MAINTAINERS/xsplice: Add myself and Ross as the maintainers Konrad Rzeszutek Wilk
2016-03-16 11:10   ` Jan Beulich
2016-03-17  0:44     ` Konrad Rzeszutek Wilk

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56F2AD7102000078000DFAEB@prv-mh.provo.novell.com \
    --to=jbeulich@suse.com \
    --cc=andrew.cooper3@citrix.com \
    --cc=dgdegra@tycho.nsa.gov \
    --cc=ian.jackson@eu.citrix.com \
    --cc=konrad.wilk@oracle.com \
    --cc=mpohlack@amazon.de \
    --cc=ross.lagerwall@citrix.com \
    --cc=sasha.levin@oracle.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=wei.liu2@citrix.com \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).