From: David Hildenbrand <david@redhat.com>
To: Alexander Duyck <alexander.duyck@gmail.com>, mst@redhat.com
Cc: virtio-dev@lists.oasis-open.org, qemu-devel@nongnu.org
Subject: Re: [PATCH 1/2] virtio-balloon: Prevent guest from starting a report when we didn't request one
Date: Mon, 22 Jun 2020 10:10:14 +0200 [thread overview]
Message-ID: <acac152a-8be5-aa5c-ca52-e5ffc90b6ed4@redhat.com> (raw)
In-Reply-To: <20200619215309.25598.7553.stgit@localhost.localdomain>
On 19.06.20 23:53, Alexander Duyck wrote:
> From: Alexander Duyck <alexander.h.duyck@linux.intel.com>
>
> Based on code review it appears possible for the driver to force the device
> out of a stopped state when hinting by repeating the last ID it was
> provided.
Indeed, thanks for noticing.
>
> Prevent this by only allowing a transition to the start state when we are
> in the requested state. This way the driver is only allowed to send one
> descriptor that will transition the device into the start state. All others
> will leave it in the stop state once it has finished.
>
> In addition add the necessary locking to provent any potential races
s/provent/prevent/
> between the accesses of the cmd_id and the status.
>
> Fixes: c13c4153f76d ("virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_HINT")
> Signed-off-by: Alexander Duyck <alexander.h.duyck@linux.intel.com>
> ---
> hw/virtio/virtio-balloon.c | 11 +++++++----
> 1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
> index 10507b2a430a..7f3af266f674 100644
> --- a/hw/virtio/virtio-balloon.c
> +++ b/hw/virtio/virtio-balloon.c
> @@ -527,7 +527,8 @@ static bool get_free_page_hints(VirtIOBalloon *dev)
> ret = false;
> goto out;
> }
> - if (id == dev->free_page_report_cmd_id) {
> + if (dev->free_page_report_status == FREE_PAGE_REPORT_S_REQUESTED &&
> + id == dev->free_page_report_cmd_id) {
> dev->free_page_report_status = FREE_PAGE_REPORT_S_START;
> } else {
> /*
But doesn't that mean that, after the first hint, all further ones will
be discarded and we'll enter the STOP state in the else case? Or am I
missing something?
Shouldn't this be something like
if (id == dev->free_page_report_cmd_id) {
if (dev->free_page_report_status == FREE_PAGE_REPORT_S_REQUESTED) {
dev->free_page_report_status = FREE_PAGE_REPORT_S_START;
}
/* Stay in FREE_PAGE_REPORT_S_START as long as the cmd_id match .*/
} else { ...
> @@ -592,14 +593,16 @@ static void virtio_balloon_free_page_start(VirtIOBalloon *s)
> return;
> }
>
> - if (s->free_page_report_cmd_id == UINT_MAX) {
> + qemu_mutex_lock(&s->free_page_lock);
> +
> + if (s->free_page_report_cmd_id++ == UINT_MAX) {
> s->free_page_report_cmd_id =
> VIRTIO_BALLOON_FREE_PAGE_REPORT_CMD_ID_MIN;
> - } else {
> - s->free_page_report_cmd_id++;
> }
Somewhat unrelated cleanup.
>
> s->free_page_report_status = FREE_PAGE_REPORT_S_REQUESTED;
> + qemu_mutex_unlock(&s->free_page_lock);
> +
> virtio_notify_config(vdev);
> }
>
>
--
Thanks,
David / dhildenb
next prev parent reply other threads:[~2020-06-22 8:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-19 21:53 [PATCH 0/2] virtio-balloon: Free page hinting clean-ups Alexander Duyck
2020-06-19 21:53 ` [PATCH 1/2] virtio-balloon: Prevent guest from starting a report when we didn't request one Alexander Duyck
2020-06-22 8:10 ` David Hildenbrand [this message]
2020-06-22 22:37 ` Alexander Duyck
2020-06-23 6:54 ` David Hildenbrand
2020-06-19 21:53 ` [PATCH 2/2] virtio-balloon: Replace free page hinting references to 'report' with 'hint' Alexander Duyck
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=acac152a-8be5-aa5c-ca52-e5ffc90b6ed4@redhat.com \
--to=david@redhat.com \
--cc=alexander.duyck@gmail.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=virtio-dev@lists.oasis-open.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).