linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Wei Wang <wei.w.wang@intel.com>
Cc: yang.zhang.wz@gmail.com, virtio-dev@lists.oasis-open.org,
	riel@redhat.com, quan.xu0@gmail.com, kvm@vger.kernel.org,
	nilal@redhat.com, liliang.opensource@gmail.com,
	linux-kernel@vger.kernel.org, mhocko@kernel.org,
	linux-mm@kvack.org, pbonzini@redhat.com,
	akpm@linux-foundation.org,
	virtualization@lists.linux-foundation.org
Subject: Re: [virtio-dev] Re: [PATCH v22 2/3] virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_VQ
Date: Wed, 24 Jan 2018 06:31:14 +0200	[thread overview]
Message-ID: <20180124063009-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <5A67FB10.2050201@intel.com>

On Wed, Jan 24, 2018 at 11:18:40AM +0800, Wei Wang wrote:
> On 01/22/2018 07:25 PM, Wei Wang wrote:
> > On 01/19/2018 08:39 PM, Michael S. Tsirkin wrote:
> > > On Fri, Jan 19, 2018 at 11:44:21AM +0800, Wei Wang wrote:
> > > > On 01/18/2018 12:44 AM, Michael S. Tsirkin wrote:
> > > > > On Wed, Jan 17, 2018 at 01:10:11PM +0800, Wei Wang wrote:
> > > > > 
> > > > > > +        vb->start_cmd_id = cmd_id;
> > > > > > +        queue_work(vb->balloon_wq, &vb->report_free_page_work);
> > > > > It seems that if a command was already queued (with a different id),
> > > > > this will result in new command id being sent to host twice,
> > > > > which will
> > > > > likely confuse the host.
> > > > I think that case won't happen, because
> > > > - the host sends a cmd id to the guest via the config, while the
> > > > guest acks
> > > > back the received cmd id via the virtqueue;
> > > > - the guest ack back a cmd id only when a new cmd id is received
> > > > from the
> > > > host, that is the above check:
> > > > 
> > > >      if (cmd_id != vb->start_cmd_id) { --> the driver only queues the
> > > > reporting work only when a new cmd id is received
> > > >                          /*
> > > >                           * Host requests to start the reporting
> > > > by sending a
> > > >                           * new cmd id.
> > > >                           */
> > > >                          WRITE_ONCE(vb->report_free_page, true);
> > > >                          vb->start_cmd_id = cmd_id;
> > > >                          queue_work(vb->balloon_wq,
> > > > &vb->report_free_page_work);
> > > >      }
> > > > 
> > > > So the same cmd id wouldn't queue the reporting work twice.
> > > > 
> > > Like this:
> > > 
> > >         vb->start_cmd_id = cmd_id;
> > >         queue_work(vb->balloon_wq, &vb->report_free_page_work);
> > > 
> > > command id changes
> > > 
> > >         vb->start_cmd_id = cmd_id;
> > > 
> > > work executes
> > > 
> > >         queue_work(vb->balloon_wq, &vb->report_free_page_work);
> > > 
> > > work executes again
> > > 
> > 
> > If we think about the whole working flow, I think this case couldn't
> > happen:
> > 
> > 1) device send cmd_id=1 to driver;
> > 2) driver receives cmd_id=1 in the config and acks cmd_id=1 to the
> > device via the vq;
> > 3) device revives cmd_id=1;
> > 4) device wants to stop the reporting by sending cmd_id=STOP;
> > 5) driver receives cmd_id=STOP from the config, and acks cmd_id=STOP to
> > the device via the vq;
> > 6) device sends cmd_id=2 to driver;
> > ...
> > 
> > cmd_id=2 won't come after cmd_id=1, there will be a STOP cmd in between
> > them (STOP won't queue the work).
> > 
> > How about defining the correct device behavior in the spec:
> > The device Should NOT send a second cmd id to the driver until a STOP
> > cmd ack for the previous cmd id has been received from the guest.
> 
> 
> Thanks for the comments, and I adopted most of them in the new posted v23
> patches. The above discussion is the one that I haven't included. If you
> could still see issues in the above analysis, please let me know. Thanks.
> 
> Best,
> Wei
> 
> 
>

Yes, I think you should just fix the race in the driver.

-- 
MST

  reply	other threads:[~2018-01-24  4:31 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-17  5:10 [PATCH v22 0/3] Virtio-balloon: support free page reporting Wei Wang
2018-01-17  5:10 ` [PATCH v22 1/3] mm: support reporting free page blocks Wei Wang
2018-01-17  5:10 ` [PATCH v22 2/3] virtio-balloon: VIRTIO_BALLOON_F_FREE_PAGE_VQ Wei Wang
2018-01-17  8:21   ` Pankaj Gupta
2018-01-17  9:00     ` Wei Wang
2018-01-17  9:27       ` Pankaj Gupta
2018-01-17 10:47         ` Wei Wang
2018-01-17 16:44   ` Michael S. Tsirkin
2018-01-18 13:30     ` Tetsuo Handa
2018-01-18 19:09       ` Michael S. Tsirkin
2018-01-18 21:11         ` Tetsuo Handa
2018-01-18 22:32           ` Michael S. Tsirkin
2018-01-20 14:23             ` Tetsuo Handa
2018-01-19  3:44     ` Wei Wang
2018-01-19 12:39       ` Michael S. Tsirkin
2018-01-22 11:25         ` [virtio-dev] " Wei Wang
2018-01-24  3:18           ` Wei Wang
2018-01-24  4:31             ` Michael S. Tsirkin [this message]
2018-01-24  4:29           ` Michael S. Tsirkin
2018-01-24 11:28             ` Wei Wang
2018-01-19  6:24     ` Wei Wang
2018-01-17  5:10 ` [PATCH v22 3/3] virtio-balloon: don't report free pages when page poisoning is enabled Wei Wang
2018-01-18 22:37   ` Michael S. Tsirkin

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=20180124063009-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=kvm@vger.kernel.org \
    --cc=liliang.opensource@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=mhocko@kernel.org \
    --cc=nilal@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=quan.xu0@gmail.com \
    --cc=riel@redhat.com \
    --cc=virtio-dev@lists.oasis-open.org \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=wei.w.wang@intel.com \
    --cc=yang.zhang.wz@gmail.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;
as well as URLs for NNTP newsgroup(s).