From: "Michael S. Tsirkin" <mst@redhat.com>
To: Christian Borntraeger <borntraeger@de.ibm.com>
Cc: Wei Wang <wei.w.wang@intel.com>,
virtio-dev@lists.oasis-open.org, linux-kernel@vger.kernel.org,
virtualization@lists.linux-foundation.org, kvm@vger.kernel.org,
cohuck@redhat.com, pbonzini@redhat.com, dgilbert@redhat.com,
pasic@linux.ibm.com
Subject: Re: [PATCH v3 1/3] virtio-balloon: tweak config_changed implementation
Date: Mon, 14 Jan 2019 19:53:35 -0500 [thread overview]
Message-ID: <20190114195151-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <4ea022d4-6b89-b481-5747-871e154dd21a@de.ibm.com>
On Mon, Jan 07, 2019 at 02:49:03PM +0100, Christian Borntraeger wrote:
>
>
> On 07.01.2019 08:01, Wei Wang wrote:
> > virtio-ccw has deadlock issues with reading the config space inside the
> > interrupt context, so we tweak the virtballoon_changed implementation
> > by moving the config read operations into the related workqueue contexts.
> > The config_read_bitmap is used as a flag to the workqueue callbacks
> > about the related config fields that need to be read.
> >
> > The cmd_id_received is also renamed to cmd_id_received_cache, and
> > the value should be obtained via virtio_balloon_cmd_id_received.
> >
> > Reported-by: Christian Borntraeger <borntraeger@de.ibm.com>
> > Signed-off-by: Wei Wang <wei.w.wang@intel.com>
> > Reviewed-by: Cornelia Huck <cohuck@redhat.com>
> > Reviewed-by: Halil Pasic <pasic@linux.ibm.com>
>
> Together with
> virtio_pci: use queue idx instead of array idx to set up the vq
> virtio: don't allocate vqs when names[i] = NULL
>
> Tested-by: Christian Borntraeger <borntraeger@de.ibm.com>
>
> as already said, would be good to add cc stable (and a Fixes: tag)
I don't think you did that.
Did it manually as the pull needed some manual handling
but I won't next time and you will have to send it to
Greg yourself.
>
> > ---
> > drivers/virtio/virtio_balloon.c | 98 +++++++++++++++++++++++++++--------------
> > 1 file changed, 65 insertions(+), 33 deletions(-)
> >
> > diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c
> > index 728ecd1..fb12fe2 100644
> > --- a/drivers/virtio/virtio_balloon.c
> > +++ b/drivers/virtio/virtio_balloon.c
> > @@ -61,6 +61,10 @@ enum virtio_balloon_vq {
> > VIRTIO_BALLOON_VQ_MAX
> > };
> >
> > +enum virtio_balloon_config_read {
> > + VIRTIO_BALLOON_CONFIG_READ_CMD_ID = 0,
> > +};
> > +
> > struct virtio_balloon {
> > struct virtio_device *vdev;
> > struct virtqueue *inflate_vq, *deflate_vq, *stats_vq, *free_page_vq;
> > @@ -77,14 +81,20 @@ struct virtio_balloon {
> > /* Prevent updating balloon when it is being canceled. */
> > spinlock_t stop_update_lock;
> > bool stop_update;
> > + /* Bitmap to indicate if reading the related config fields are needed */
> > + unsigned long config_read_bitmap;
> >
> > /* The list of allocated free pages, waiting to be given back to mm */
> > struct list_head free_page_list;
> > spinlock_t free_page_list_lock;
> > /* The number of free page blocks on the above list */
> > unsigned long num_free_page_blocks;
> > - /* The cmd id received from host */
> > - u32 cmd_id_received;
> > + /*
> > + * The cmd id received from host.
> > + * Read it via virtio_balloon_cmd_id_received to get the latest value
> > + * sent from host.
> > + */
> > + u32 cmd_id_received_cache;
> > /* The cmd id that is actively in use */
> > __virtio32 cmd_id_active;
> > /* Buffer to store the stop sign */
> > @@ -390,37 +400,31 @@ static unsigned long return_free_pages_to_mm(struct virtio_balloon *vb,
> > return num_returned;
> > }
> >
> > +static void virtio_balloon_queue_free_page_work(struct virtio_balloon *vb)
> > +{
> > + if (!virtio_has_feature(vb->vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT))
> > + return;
> > +
> > + /* No need to queue the work if the bit was already set. */
> > + if (test_and_set_bit(VIRTIO_BALLOON_CONFIG_READ_CMD_ID,
> > + &vb->config_read_bitmap))
> > + return;
> > +
> > + queue_work(vb->balloon_wq, &vb->report_free_page_work);
> > +}
> > +
> > static void virtballoon_changed(struct virtio_device *vdev)
> > {
> > struct virtio_balloon *vb = vdev->priv;
> > unsigned long flags;
> > - s64 diff = towards_target(vb);
> > -
> > - if (diff) {
> > - spin_lock_irqsave(&vb->stop_update_lock, flags);
> > - if (!vb->stop_update)
> > - queue_work(system_freezable_wq,
> > - &vb->update_balloon_size_work);
> > - spin_unlock_irqrestore(&vb->stop_update_lock, flags);
> > - }
> >
> > - if (virtio_has_feature(vdev, VIRTIO_BALLOON_F_FREE_PAGE_HINT)) {
> > - virtio_cread(vdev, struct virtio_balloon_config,
> > - free_page_report_cmd_id, &vb->cmd_id_received);
> > - if (vb->cmd_id_received == VIRTIO_BALLOON_CMD_ID_DONE) {
> > - /* Pass ULONG_MAX to give back all the free pages */
> > - return_free_pages_to_mm(vb, ULONG_MAX);
> > - } else if (vb->cmd_id_received != VIRTIO_BALLOON_CMD_ID_STOP &&
> > - vb->cmd_id_received !=
> > - virtio32_to_cpu(vdev, vb->cmd_id_active)) {
> > - spin_lock_irqsave(&vb->stop_update_lock, flags);
> > - if (!vb->stop_update) {
> > - queue_work(vb->balloon_wq,
> > - &vb->report_free_page_work);
> > - }
> > - spin_unlock_irqrestore(&vb->stop_update_lock, flags);
> > - }
> > + spin_lock_irqsave(&vb->stop_update_lock, flags);
> > + if (!vb->stop_update) {
> > + queue_work(system_freezable_wq,
> > + &vb->update_balloon_size_work);
> > + virtio_balloon_queue_free_page_work(vb);
> > }
> > + spin_unlock_irqrestore(&vb->stop_update_lock, flags);
> > }
> >
> > static void update_balloon_size(struct virtio_balloon *vb)
> > @@ -527,6 +531,17 @@ static int init_vqs(struct virtio_balloon *vb)
> > return 0;
> > }
> >
> > +static u32 virtio_balloon_cmd_id_received(struct virtio_balloon *vb)
> > +{
> > + if (test_and_clear_bit(VIRTIO_BALLOON_CONFIG_READ_CMD_ID,
> > + &vb->config_read_bitmap))
> > + virtio_cread(vb->vdev, struct virtio_balloon_config,
> > + free_page_report_cmd_id,
> > + &vb->cmd_id_received_cache);
> > +
> > + return vb->cmd_id_received_cache;
> > +}
> > +
> > static int send_cmd_id_start(struct virtio_balloon *vb)
> > {
> > struct scatterlist sg;
> > @@ -537,7 +552,8 @@ static int send_cmd_id_start(struct virtio_balloon *vb)
> > while (virtqueue_get_buf(vq, &unused))
> > ;
> >
> > - vb->cmd_id_active = cpu_to_virtio32(vb->vdev, vb->cmd_id_received);
> > + vb->cmd_id_active = virtio32_to_cpu(vb->vdev,
> > + virtio_balloon_cmd_id_received(vb));
> > sg_init_one(&sg, &vb->cmd_id_active, sizeof(vb->cmd_id_active));
> > err = virtqueue_add_outbuf(vq, &sg, 1, &vb->cmd_id_active, GFP_KERNEL);
> > if (!err)
> > @@ -620,7 +636,8 @@ static int send_free_pages(struct virtio_balloon *vb)
> > * stop the reporting.
> > */
> > cmd_id_active = virtio32_to_cpu(vb->vdev, vb->cmd_id_active);
> > - if (cmd_id_active != vb->cmd_id_received)
> > + if (unlikely(cmd_id_active !=
> > + virtio_balloon_cmd_id_received(vb)))
> > break;
> >
> > /*
> > @@ -637,11 +654,9 @@ static int send_free_pages(struct virtio_balloon *vb)
> > return 0;
> > }
> >
> > -static void report_free_page_func(struct work_struct *work)
> > +static void virtio_balloon_report_free_page(struct virtio_balloon *vb)
> > {
> > int err;
> > - struct virtio_balloon *vb = container_of(work, struct virtio_balloon,
> > - report_free_page_work);
> > struct device *dev = &vb->vdev->dev;
> >
> > /* Start by sending the received cmd id to host with an outbuf. */
> > @@ -659,6 +674,23 @@ static void report_free_page_func(struct work_struct *work)
> > dev_err(dev, "Failed to send a stop id, err = %d\n", err);
> > }
> >
> > +static void report_free_page_func(struct work_struct *work)
> > +{
> > + struct virtio_balloon *vb = container_of(work, struct virtio_balloon,
> > + report_free_page_work);
> > + u32 cmd_id_received;
> > +
> > + cmd_id_received = virtio_balloon_cmd_id_received(vb);
> > + if (cmd_id_received == VIRTIO_BALLOON_CMD_ID_DONE) {
> > + /* Pass ULONG_MAX to give back all the free pages */
> > + return_free_pages_to_mm(vb, ULONG_MAX);
> > + } else if (cmd_id_received != VIRTIO_BALLOON_CMD_ID_STOP &&
> > + cmd_id_received !=
> > + virtio32_to_cpu(vb->vdev, vb->cmd_id_active)) {
> > + virtio_balloon_report_free_page(vb);
> > + }
> > +}
> > +
> > #ifdef CONFIG_BALLOON_COMPACTION
> > /*
> > * virtballoon_migratepage - perform the balloon page migration on behalf of
> > @@ -885,7 +917,7 @@ static int virtballoon_probe(struct virtio_device *vdev)
> > goto out_del_vqs;
> > }
> > INIT_WORK(&vb->report_free_page_work, report_free_page_func);
> > - vb->cmd_id_received = VIRTIO_BALLOON_CMD_ID_STOP;
> > + vb->cmd_id_received_cache = VIRTIO_BALLOON_CMD_ID_STOP;
> > vb->cmd_id_active = cpu_to_virtio32(vb->vdev,
> > VIRTIO_BALLOON_CMD_ID_STOP);
> > vb->cmd_id_stop = cpu_to_virtio32(vb->vdev,
> >
next prev parent reply other threads:[~2019-01-15 0:53 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-07 7:01 [PATCH v3 0/3] virtio-balloon: tweak config_changed Wei Wang
2019-01-07 7:01 ` [PATCH v3 1/3] virtio-balloon: tweak config_changed implementation Wei Wang
2019-01-07 13:44 ` Michael S. Tsirkin
2019-01-07 13:47 ` Michael S. Tsirkin
2019-01-07 13:49 ` Christian Borntraeger
2019-01-08 5:35 ` Wei Wang
2019-01-08 8:46 ` Christian Borntraeger
2019-01-09 10:35 ` Wei Wang
2019-01-09 12:07 ` Christian Borntraeger
2019-01-09 14:52 ` Michael S. Tsirkin
2019-01-09 18:22 ` Christian Borntraeger
2019-01-09 18:31 ` Michael S. Tsirkin
2019-01-09 14:49 ` Michael S. Tsirkin
2019-01-15 0:53 ` Michael S. Tsirkin [this message]
2019-01-07 7:01 ` [PATCH v3 2/3] virtio-balloon: improve update_balloon_size_func Wei Wang
2019-01-15 1:00 ` Michael S. Tsirkin
2019-01-15 2:18 ` Wei Wang
2019-01-07 7:01 ` [PATCH v3 3/3] virtio_balloon: remove the unnecessary 0-initialization Wei Wang
2019-01-07 14:07 ` Cornelia Huck
2019-01-07 13:40 ` [PATCH v3 0/3] virtio-balloon: tweak config_changed Christian Borntraeger
2019-01-07 13:45 ` Michael S. Tsirkin
2019-01-07 13:50 ` Christian Borntraeger
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=20190114195151-mutt-send-email-mst@kernel.org \
--to=mst@redhat.com \
--cc=borntraeger@de.ibm.com \
--cc=cohuck@redhat.com \
--cc=dgilbert@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pasic@linux.ibm.com \
--cc=pbonzini@redhat.com \
--cc=virtio-dev@lists.oasis-open.org \
--cc=virtualization@lists.linux-foundation.org \
--cc=wei.w.wang@intel.com \
/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