From: Anthony PERARD <anthony.perard@citrix.com>
To: Dario Faggioli <dfaggioli@suse.com>
Cc: <xen-devel@lists.xenproject.org>, James Fehlig <jfehlig@suse.com>,
Wei Liu <wl@xen.org>, Juergen Gross <jgross@suse.com>
Subject: Re: [PATCH 2/2] tools/libs/light: don't touch nr_vcpus_out if listing vcpus and returning NULL
Date: Thu, 13 Jan 2022 12:38:41 +0000 [thread overview]
Message-ID: <YeAdUZB4/51PC176@perard> (raw)
In-Reply-To: <164200570276.24755.1849386285622380597.stgit@work>
On Wed, Jan 12, 2022 at 05:41:42PM +0100, Dario Faggioli wrote:
> If we are in libvxl_list_vcpu() and we are returning NULL, let's avoid
extra 'v' ^ here.
> touching the output parameter *nr_vcpus_out (which should contain the
> number of vcpus in the list). Ideally, the caller initialized it to 0,
> which is therefore consistent with us returning NULL (or, as an alternative,
> we can explicitly set it to 0 if we're returning null... But just not
> touching it seems the best behavior).
>
> In fact, the current behavior is especially problematic if, for
> instance, a domain is destroyed after we have done some steps of the
> for() loop. In which case, calls like xc_vcpu_getinfo() or
> xc_vcpu_getaffinity() will start to fail, and we return back to the
> caller inconsistent information, such as a NULL list of vcpus, but a
> modified and not 0 any longer, number of vcpus in the list.
>
> Signed-off-by: Dario Faggioli <dfaggioli@suse.com>
> Tested-by: James Fehlig <jfehlig@suse.com>
> ---
> diff --git a/tools/libs/light/libxl_domain.c b/tools/libs/light/libxl_domain.c
> index 544a9bf59d..aabc264e16 100644
> --- a/tools/libs/light/libxl_domain.c
> +++ b/tools/libs/light/libxl_domain.c
> @@ -1705,6 +1706,7 @@ libxl_vcpuinfo *libxl_list_vcpu(libxl_ctx *ctx, uint32_t domid,
> ptr->vcpu_time = vcpuinfo.cpu_time;
> }
> GC_FREE;
> + *nr_vcpus_out = nr_vcpus;
Can you swap those two lines, to keep GC_FREE just before return?
> return ret;
>
> err:
> diff --git a/tools/libs/light/libxl_numa.c b/tools/libs/light/libxl_numa.c
> index 3679028c79..b04e3917a0 100644
> --- a/tools/libs/light/libxl_numa.c
> +++ b/tools/libs/light/libxl_numa.c
> @@ -219,8 +219,10 @@ static int nr_vcpus_on_nodes(libxl__gc *gc, libxl_cputopology *tinfo,
> goto next;
>
> vinfo = libxl_list_vcpu(CTX, dinfo[i].domid, &nr_dom_vcpus, &nr_cpus);
> - if (vinfo == NULL)
> + if (vinfo == NULL) {
> + assert(nr_dom_vcpus == 0);
I don't think this assert is necessary.
> goto next;
> + }
Otherwise, this patch looks fine.
Thanks,
--
Anthony PERARD
next prev parent reply other threads:[~2022-01-13 12:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-12 16:41 [PATCH 0/2] libs/light: fix a race when domain are destroied and created concurrently Dario Faggioli
2022-01-12 16:41 ` [PATCH 1/2] tools/libs/light: numa placement: don't try to free a NULL list of vcpus Dario Faggioli
2022-01-13 12:05 ` Anthony PERARD
2022-01-14 23:22 ` Dario Faggioli
2022-01-17 15:56 ` Anthony PERARD
2022-01-19 9:02 ` Dario Faggioli
2022-01-12 16:41 ` [PATCH 2/2] tools/libs/light: don't touch nr_vcpus_out if listing vcpus and returning NULL Dario Faggioli
2022-01-13 12:38 ` Anthony PERARD [this message]
2022-01-13 11:46 ` [PATCH 0/2] libs/light: fix a race when domain are destroied and created concurrently Dario Faggioli
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=YeAdUZB4/51PC176@perard \
--to=anthony.perard@citrix.com \
--cc=dfaggioli@suse.com \
--cc=jfehlig@suse.com \
--cc=jgross@suse.com \
--cc=wl@xen.org \
--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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.