Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation]

2020-06-30 Thread Roger Pau Monné
On Mon, Jun 29, 2020 at 07:20:35PM +, Anchal Agarwal wrote:
> On Fri, Jun 26, 2020 at 11:12:39AM +0200, Roger Pau Monné wrote:
> > So the frontend should do:
> > 
> > - Switch to Closed state (and cleanup everything required).
> > - Wait for backend to switch to Closed state (must be done
> >   asynchronously, handled in blkback_changed).
> > - Switch frontend to XenbusStateInitialising, that will in turn force
> >   the backend to switch to XenbusStateInitWait.
> > - After that it should just follow the normal connection procedure.
> > 
> > I think the part that's missing is the frontend doing the state change
> > to XenbusStateInitialising when the backend switches to the Closed
> > state.
> > 
> > > I was of the view we may just want to mark frontend closed which should do
> > > the job of freeing resources and then following the same flow as
> > > blkfront_restore. That does not seems to work correctly 100% of the time.
> > 
> > I think the missing part is that you must wait for the backend to
> > switch to the Closed state, or else the switch to
> > XenbusStateInitialising won't be picked up correctly by the backend
> > (because it's still doing it's cleanup).
> > 
> > Using blkfront_restore might be an option, but you need to assert the
> > backend is in the initial state before using that path.
> >
> Yes, I agree and I make sure that XenbusStateInitialising only triggers
> on frontend once backend is disconnected. msleep in a loop not that graceful 
> but
> works.
> Frontend only switches to XenbusStateInitialising once it sees backend
> as Closed. The issue here is and may require more debugging is:
> 1. Hibernate instance->Closing failed, artificially created situation by not
> marking frontend Closed in the first place during freezing.
> 2. System comes back up fine restored to 'backend connected'.

I'm not sure I'm following what is happening here, what should happen
IMO is that the backend will eventually reach the Closed state? Ie:
the frontend has initiated the disconnection from the backend by
setting the Closing state, and the backend will have to eventually
reach the Closed state.

At that point the frontend can initiate a reconnection by switching to
the Initialising state.

> 3. Re-run (1) again without reboot
> 4. (4) fails to recover basically freezing does not fail at all which is weird
>because it should timeout as it passes through same path. It hits a BUG in
>talk_to_blkback() and instance crashes.

It's hard to tell exactly. I guess you would have to figure what makes
the frontend not get stuck at the same place as the first attempt.

Roger.


Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation]

2020-06-29 Thread Anchal Agarwal
On Fri, Jun 26, 2020 at 11:12:39AM +0200, Roger Pau Monné wrote:
> CAUTION: This email originated from outside of the organization. Do not click 
> links or open attachments unless you can confirm the sender and know the 
> content is safe.
> 
> 
> 
> On Thu, Jun 25, 2020 at 06:36:59PM +, Anchal Agarwal wrote:
> > On Tue, Jun 23, 2020 at 10:19:03AM +0200, Roger Pau Monné wrote:
> > > CAUTION: This email originated from outside of the organization. Do not 
> > > click links or open attachments unless you can confirm the sender and 
> > > know the content is safe.
> > >
> > >
> > >
> > > On Tue, Jun 23, 2020 at 12:43:14AM +, Anchal Agarwal wrote:
> > > > On Mon, Jun 22, 2020 at 10:38:46AM +0200, Roger Pau Monné wrote:
> > > > > CAUTION: This email originated from outside of the organization. Do 
> > > > > not click links or open attachments unless you can confirm the sender 
> > > > > and know the content is safe.
> > > > >
> > > > >
> > > > >
> > > > > On Fri, Jun 19, 2020 at 11:43:12PM +, Anchal Agarwal wrote:
> > > > > > On Wed, Jun 17, 2020 at 10:35:28AM +0200, Roger Pau Monné wrote:
> > > > > > > CAUTION: This email originated from outside of the organization. 
> > > > > > > Do not click links or open attachments unless you can confirm the 
> > > > > > > sender and know the content is safe.
> > > > > > >
> > > > > > >
> > > > > > >
> > > > > > > On Tue, Jun 16, 2020 at 09:49:25PM +, Anchal Agarwal wrote:
> > > > > > > > On Thu, Jun 04, 2020 at 09:05:48AM +0200, Roger Pau Monné wrote:
> > > > > > > > > CAUTION: This email originated from outside of the 
> > > > > > > > > organization. Do not click links or open attachments unless 
> > > > > > > > > you can confirm the sender and know the content is safe.
> > > > > > > > > On Wed, Jun 03, 2020 at 11:33:52PM +, Agarwal, Anchal 
> > > > > > > > > wrote:
> > > > > > > > > >  CAUTION: This email originated from outside of the 
> > > > > > > > > > organization. Do not click links or open attachments unless 
> > > > > > > > > > you can confirm the sender and know the content is safe.
> > > > > > > > > > > + xenbus_dev_error(dev, err, "Freezing 
> > > > > > > > > > timed out;"
> > > > > > > > > > > +  "the device may become 
> > > > > > > > > > inconsistent state");
> > > > > > > > > >
> > > > > > > > > > Leaving the device in this state is quite bad, as it's 
> > > > > > > > > > in a closed
> > > > > > > > > > state and with the queues frozen. You should make an 
> > > > > > > > > > attempt to
> > > > > > > > > > restore things to a working state.
> > > > > > > > > >
> > > > > > > > > > You mean if backend closed after timeout? Is there a way to 
> > > > > > > > > > know that? I understand it's not good to
> > > > > > > > > > leave it in this state however, I am still trying to find 
> > > > > > > > > > if there is a good way to know if backend is still 
> > > > > > > > > > connected after timeout.
> > > > > > > > > > Hence the message " the device may become inconsistent 
> > > > > > > > > > state".  I didn't see a timeout not even once on my end so 
> > > > > > > > > > that's why
> > > > > > > > > > I may be looking for an alternate perspective here. may be 
> > > > > > > > > > need to thaw everything back intentionally is one thing I 
> > > > > > > > > > could think of.
> > > > > > > > >
> > > > > > > > > You can manually force this state, and then check that it 
> > > > > > > > > will behave
> > > > > > > > > correctly. I would expect that on a failure to disconnect 
> > > > > > > > > from the
> > > > > > > > > backend you should switch the frontend to the 'Init' state in 
> > > > > > > > > order to
> > > > > > > > > try to reconnect to the backend when possible.
> > > > > > > > >
> > > > > > > > From what I understand forcing manually is, failing the freeze 
> > > > > > > > without
> > > > > > > > disconnect and try to revive the connection by unfreezing the
> > > > > > > > queues->reconnecting to backend [which never got diconnected]. 
> > > > > > > > May be even
> > > > > > > > tearing down things manually because I am not sure what state 
> > > > > > > > will frontend
> > > > > > > > see if backend fails to to disconnect at any point in time. I 
> > > > > > > > assumed connected.
> > > > > > > > Then again if its "CONNECTED" I may not need to tear down 
> > > > > > > > everything and start
> > > > > > > > from Initialising state because that may not work.
> > > > > > > >
> > > > > > > > So I am not so sure about backend's state so much, lets say if  
> > > > > > > > xen_blkif_disconnect fail,
> > > > > > > > I don't see it getting handled in the backend then what will be 
> > > > > > > > backend's state?
> > > > > > > > Will it still switch xenbus state to 'Closed'? If not what will 
> > > > > > > > frontend see,
> > > > > > > > if it tries to read backend's state through 
> > > > > > > > xenbus_read_driver_state ?
> > > > > > > >
> > > > > > > > So the flow be like:
> > > 

Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation]

2020-06-26 Thread Roger Pau Monné
On Thu, Jun 25, 2020 at 06:36:59PM +, Anchal Agarwal wrote:
> On Tue, Jun 23, 2020 at 10:19:03AM +0200, Roger Pau Monné wrote:
> > CAUTION: This email originated from outside of the organization. Do not 
> > click links or open attachments unless you can confirm the sender and know 
> > the content is safe.
> > 
> > 
> > 
> > On Tue, Jun 23, 2020 at 12:43:14AM +, Anchal Agarwal wrote:
> > > On Mon, Jun 22, 2020 at 10:38:46AM +0200, Roger Pau Monné wrote:
> > > > CAUTION: This email originated from outside of the organization. Do not 
> > > > click links or open attachments unless you can confirm the sender and 
> > > > know the content is safe.
> > > >
> > > >
> > > >
> > > > On Fri, Jun 19, 2020 at 11:43:12PM +, Anchal Agarwal wrote:
> > > > > On Wed, Jun 17, 2020 at 10:35:28AM +0200, Roger Pau Monné wrote:
> > > > > > CAUTION: This email originated from outside of the organization. Do 
> > > > > > not click links or open attachments unless you can confirm the 
> > > > > > sender and know the content is safe.
> > > > > >
> > > > > >
> > > > > >
> > > > > > On Tue, Jun 16, 2020 at 09:49:25PM +, Anchal Agarwal wrote:
> > > > > > > On Thu, Jun 04, 2020 at 09:05:48AM +0200, Roger Pau Monné wrote:
> > > > > > > > CAUTION: This email originated from outside of the 
> > > > > > > > organization. Do not click links or open attachments unless you 
> > > > > > > > can confirm the sender and know the content is safe.
> > > > > > > > On Wed, Jun 03, 2020 at 11:33:52PM +, Agarwal, Anchal wrote:
> > > > > > > > >  CAUTION: This email originated from outside of the 
> > > > > > > > > organization. Do not click links or open attachments unless 
> > > > > > > > > you can confirm the sender and know the content is safe.
> > > > > > > > > > + xenbus_dev_error(dev, err, "Freezing 
> > > > > > > > > timed out;"
> > > > > > > > > > +  "the device may become 
> > > > > > > > > inconsistent state");
> > > > > > > > >
> > > > > > > > > Leaving the device in this state is quite bad, as it's in 
> > > > > > > > > a closed
> > > > > > > > > state and with the queues frozen. You should make an 
> > > > > > > > > attempt to
> > > > > > > > > restore things to a working state.
> > > > > > > > >
> > > > > > > > > You mean if backend closed after timeout? Is there a way to 
> > > > > > > > > know that? I understand it's not good to
> > > > > > > > > leave it in this state however, I am still trying to find if 
> > > > > > > > > there is a good way to know if backend is still connected 
> > > > > > > > > after timeout.
> > > > > > > > > Hence the message " the device may become inconsistent 
> > > > > > > > > state".  I didn't see a timeout not even once on my end so 
> > > > > > > > > that's why
> > > > > > > > > I may be looking for an alternate perspective here. may be 
> > > > > > > > > need to thaw everything back intentionally is one thing I 
> > > > > > > > > could think of.
> > > > > > > >
> > > > > > > > You can manually force this state, and then check that it will 
> > > > > > > > behave
> > > > > > > > correctly. I would expect that on a failure to disconnect from 
> > > > > > > > the
> > > > > > > > backend you should switch the frontend to the 'Init' state in 
> > > > > > > > order to
> > > > > > > > try to reconnect to the backend when possible.
> > > > > > > >
> > > > > > > From what I understand forcing manually is, failing the freeze 
> > > > > > > without
> > > > > > > disconnect and try to revive the connection by unfreezing the
> > > > > > > queues->reconnecting to backend [which never got diconnected]. 
> > > > > > > May be even
> > > > > > > tearing down things manually because I am not sure what state 
> > > > > > > will frontend
> > > > > > > see if backend fails to to disconnect at any point in time. I 
> > > > > > > assumed connected.
> > > > > > > Then again if its "CONNECTED" I may not need to tear down 
> > > > > > > everything and start
> > > > > > > from Initialising state because that may not work.
> > > > > > >
> > > > > > > So I am not so sure about backend's state so much, lets say if  
> > > > > > > xen_blkif_disconnect fail,
> > > > > > > I don't see it getting handled in the backend then what will be 
> > > > > > > backend's state?
> > > > > > > Will it still switch xenbus state to 'Closed'? If not what will 
> > > > > > > frontend see,
> > > > > > > if it tries to read backend's state through 
> > > > > > > xenbus_read_driver_state ?
> > > > > > >
> > > > > > > So the flow be like:
> > > > > > > Front end marks XenbusStateClosing
> > > > > > > Backend marks its state as XenbusStateClosing
> > > > > > > Frontend marks XenbusStateClosed
> > > > > > > Backend disconnects calls xen_blkif_disconnect
> > > > > > >Backend fails to disconnect, the above function returns 
> > > > > > > EBUSY
> > > > > > >What will be state of backend here?
> > > > > >
> > > > > > Backend should stay in state 'Closing' 

Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation]

2020-06-25 Thread Anchal Agarwal
On Tue, Jun 23, 2020 at 10:19:03AM +0200, Roger Pau Monné wrote:
> CAUTION: This email originated from outside of the organization. Do not click 
> links or open attachments unless you can confirm the sender and know the 
> content is safe.
> 
> 
> 
> On Tue, Jun 23, 2020 at 12:43:14AM +, Anchal Agarwal wrote:
> > On Mon, Jun 22, 2020 at 10:38:46AM +0200, Roger Pau Monné wrote:
> > > CAUTION: This email originated from outside of the organization. Do not 
> > > click links or open attachments unless you can confirm the sender and 
> > > know the content is safe.
> > >
> > >
> > >
> > > On Fri, Jun 19, 2020 at 11:43:12PM +, Anchal Agarwal wrote:
> > > > On Wed, Jun 17, 2020 at 10:35:28AM +0200, Roger Pau Monné wrote:
> > > > > CAUTION: This email originated from outside of the organization. Do 
> > > > > not click links or open attachments unless you can confirm the sender 
> > > > > and know the content is safe.
> > > > >
> > > > >
> > > > >
> > > > > On Tue, Jun 16, 2020 at 09:49:25PM +, Anchal Agarwal wrote:
> > > > > > On Thu, Jun 04, 2020 at 09:05:48AM +0200, Roger Pau Monné wrote:
> > > > > > > CAUTION: This email originated from outside of the organization. 
> > > > > > > Do not click links or open attachments unless you can confirm the 
> > > > > > > sender and know the content is safe.
> > > > > > > On Wed, Jun 03, 2020 at 11:33:52PM +, Agarwal, Anchal wrote:
> > > > > > > >  CAUTION: This email originated from outside of the 
> > > > > > > > organization. Do not click links or open attachments unless you 
> > > > > > > > can confirm the sender and know the content is safe.
> > > > > > > > > + xenbus_dev_error(dev, err, "Freezing timed 
> > > > > > > > out;"
> > > > > > > > > +  "the device may become 
> > > > > > > > inconsistent state");
> > > > > > > >
> > > > > > > > Leaving the device in this state is quite bad, as it's in a 
> > > > > > > > closed
> > > > > > > > state and with the queues frozen. You should make an 
> > > > > > > > attempt to
> > > > > > > > restore things to a working state.
> > > > > > > >
> > > > > > > > You mean if backend closed after timeout? Is there a way to 
> > > > > > > > know that? I understand it's not good to
> > > > > > > > leave it in this state however, I am still trying to find if 
> > > > > > > > there is a good way to know if backend is still connected after 
> > > > > > > > timeout.
> > > > > > > > Hence the message " the device may become inconsistent state".  
> > > > > > > > I didn't see a timeout not even once on my end so that's why
> > > > > > > > I may be looking for an alternate perspective here. may be need 
> > > > > > > > to thaw everything back intentionally is one thing I could 
> > > > > > > > think of.
> > > > > > >
> > > > > > > You can manually force this state, and then check that it will 
> > > > > > > behave
> > > > > > > correctly. I would expect that on a failure to disconnect from the
> > > > > > > backend you should switch the frontend to the 'Init' state in 
> > > > > > > order to
> > > > > > > try to reconnect to the backend when possible.
> > > > > > >
> > > > > > From what I understand forcing manually is, failing the freeze 
> > > > > > without
> > > > > > disconnect and try to revive the connection by unfreezing the
> > > > > > queues->reconnecting to backend [which never got diconnected]. May 
> > > > > > be even
> > > > > > tearing down things manually because I am not sure what state will 
> > > > > > frontend
> > > > > > see if backend fails to to disconnect at any point in time. I 
> > > > > > assumed connected.
> > > > > > Then again if its "CONNECTED" I may not need to tear down 
> > > > > > everything and start
> > > > > > from Initialising state because that may not work.
> > > > > >
> > > > > > So I am not so sure about backend's state so much, lets say if  
> > > > > > xen_blkif_disconnect fail,
> > > > > > I don't see it getting handled in the backend then what will be 
> > > > > > backend's state?
> > > > > > Will it still switch xenbus state to 'Closed'? If not what will 
> > > > > > frontend see,
> > > > > > if it tries to read backend's state through 
> > > > > > xenbus_read_driver_state ?
> > > > > >
> > > > > > So the flow be like:
> > > > > > Front end marks XenbusStateClosing
> > > > > > Backend marks its state as XenbusStateClosing
> > > > > > Frontend marks XenbusStateClosed
> > > > > > Backend disconnects calls xen_blkif_disconnect
> > > > > >Backend fails to disconnect, the above function returns EBUSY
> > > > > >What will be state of backend here?
> > > > >
> > > > > Backend should stay in state 'Closing' then, until it can finish
> > > > > tearing down.
> > > > >
> > > > It disconnects the ring after switching to connected state too.
> > > > > >Frontend did not tear down the rings if backend does not 
> > > > > > switches the
> > > > > >state to 'Closed' in case of failure.
> > > > > >

Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation]

2020-06-23 Thread Roger Pau Monné
On Tue, Jun 23, 2020 at 12:43:14AM +, Anchal Agarwal wrote:
> On Mon, Jun 22, 2020 at 10:38:46AM +0200, Roger Pau Monné wrote:
> > CAUTION: This email originated from outside of the organization. Do not 
> > click links or open attachments unless you can confirm the sender and know 
> > the content is safe.
> > 
> > 
> > 
> > On Fri, Jun 19, 2020 at 11:43:12PM +, Anchal Agarwal wrote:
> > > On Wed, Jun 17, 2020 at 10:35:28AM +0200, Roger Pau Monné wrote:
> > > > CAUTION: This email originated from outside of the organization. Do not 
> > > > click links or open attachments unless you can confirm the sender and 
> > > > know the content is safe.
> > > >
> > > >
> > > >
> > > > On Tue, Jun 16, 2020 at 09:49:25PM +, Anchal Agarwal wrote:
> > > > > On Thu, Jun 04, 2020 at 09:05:48AM +0200, Roger Pau Monné wrote:
> > > > > > CAUTION: This email originated from outside of the organization. Do 
> > > > > > not click links or open attachments unless you can confirm the 
> > > > > > sender and know the content is safe.
> > > > > > On Wed, Jun 03, 2020 at 11:33:52PM +, Agarwal, Anchal wrote:
> > > > > > >  CAUTION: This email originated from outside of the organization. 
> > > > > > > Do not click links or open attachments unless you can confirm the 
> > > > > > > sender and know the content is safe.
> > > > > > > > + xenbus_dev_error(dev, err, "Freezing timed 
> > > > > > > out;"
> > > > > > > > +  "the device may become 
> > > > > > > inconsistent state");
> > > > > > >
> > > > > > > Leaving the device in this state is quite bad, as it's in a 
> > > > > > > closed
> > > > > > > state and with the queues frozen. You should make an attempt 
> > > > > > > to
> > > > > > > restore things to a working state.
> > > > > > >
> > > > > > > You mean if backend closed after timeout? Is there a way to know 
> > > > > > > that? I understand it's not good to
> > > > > > > leave it in this state however, I am still trying to find if 
> > > > > > > there is a good way to know if backend is still connected after 
> > > > > > > timeout.
> > > > > > > Hence the message " the device may become inconsistent state".  I 
> > > > > > > didn't see a timeout not even once on my end so that's why
> > > > > > > I may be looking for an alternate perspective here. may be need 
> > > > > > > to thaw everything back intentionally is one thing I could think 
> > > > > > > of.
> > > > > >
> > > > > > You can manually force this state, and then check that it will 
> > > > > > behave
> > > > > > correctly. I would expect that on a failure to disconnect from the
> > > > > > backend you should switch the frontend to the 'Init' state in order 
> > > > > > to
> > > > > > try to reconnect to the backend when possible.
> > > > > >
> > > > > From what I understand forcing manually is, failing the freeze without
> > > > > disconnect and try to revive the connection by unfreezing the
> > > > > queues->reconnecting to backend [which never got diconnected]. May be 
> > > > > even
> > > > > tearing down things manually because I am not sure what state will 
> > > > > frontend
> > > > > see if backend fails to to disconnect at any point in time. I assumed 
> > > > > connected.
> > > > > Then again if its "CONNECTED" I may not need to tear down everything 
> > > > > and start
> > > > > from Initialising state because that may not work.
> > > > >
> > > > > So I am not so sure about backend's state so much, lets say if  
> > > > > xen_blkif_disconnect fail,
> > > > > I don't see it getting handled in the backend then what will be 
> > > > > backend's state?
> > > > > Will it still switch xenbus state to 'Closed'? If not what will 
> > > > > frontend see,
> > > > > if it tries to read backend's state through xenbus_read_driver_state ?
> > > > >
> > > > > So the flow be like:
> > > > > Front end marks XenbusStateClosing
> > > > > Backend marks its state as XenbusStateClosing
> > > > > Frontend marks XenbusStateClosed
> > > > > Backend disconnects calls xen_blkif_disconnect
> > > > >Backend fails to disconnect, the above function returns EBUSY
> > > > >What will be state of backend here?
> > > >
> > > > Backend should stay in state 'Closing' then, until it can finish
> > > > tearing down.
> > > >
> > > It disconnects the ring after switching to connected state too.
> > > > >Frontend did not tear down the rings if backend does not 
> > > > > switches the
> > > > >state to 'Closed' in case of failure.
> > > > >
> > > > > If backend stays in CONNECTED state, then even if we mark it 
> > > > > Initialised in frontend, backend
> > > >
> > > > Backend will stay in state 'Closing' I think.
> > > >
> > > > > won't be calling connect(). {From reading code in frontend_changed}
> > > > > IMU, Initialising will fail since backend dev->state != 
> > > > > XenbusStateClosed plus
> > > > > we did not tear down anything so calling talk_to_blkback may not be 
> > > > > 

Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation]

2020-06-22 Thread Anchal Agarwal
On Mon, Jun 22, 2020 at 10:38:46AM +0200, Roger Pau Monné wrote:
> CAUTION: This email originated from outside of the organization. Do not click 
> links or open attachments unless you can confirm the sender and know the 
> content is safe.
> 
> 
> 
> On Fri, Jun 19, 2020 at 11:43:12PM +, Anchal Agarwal wrote:
> > On Wed, Jun 17, 2020 at 10:35:28AM +0200, Roger Pau Monné wrote:
> > > CAUTION: This email originated from outside of the organization. Do not 
> > > click links or open attachments unless you can confirm the sender and 
> > > know the content is safe.
> > >
> > >
> > >
> > > On Tue, Jun 16, 2020 at 09:49:25PM +, Anchal Agarwal wrote:
> > > > On Thu, Jun 04, 2020 at 09:05:48AM +0200, Roger Pau Monné wrote:
> > > > > CAUTION: This email originated from outside of the organization. Do 
> > > > > not click links or open attachments unless you can confirm the sender 
> > > > > and know the content is safe.
> > > > > On Wed, Jun 03, 2020 at 11:33:52PM +, Agarwal, Anchal wrote:
> > > > > >  CAUTION: This email originated from outside of the organization. 
> > > > > > Do not click links or open attachments unless you can confirm the 
> > > > > > sender and know the content is safe.
> > > > > > > + xenbus_dev_error(dev, err, "Freezing timed out;"
> > > > > > > +  "the device may become 
> > > > > > inconsistent state");
> > > > > >
> > > > > > Leaving the device in this state is quite bad, as it's in a 
> > > > > > closed
> > > > > > state and with the queues frozen. You should make an attempt to
> > > > > > restore things to a working state.
> > > > > >
> > > > > > You mean if backend closed after timeout? Is there a way to know 
> > > > > > that? I understand it's not good to
> > > > > > leave it in this state however, I am still trying to find if there 
> > > > > > is a good way to know if backend is still connected after timeout.
> > > > > > Hence the message " the device may become inconsistent state".  I 
> > > > > > didn't see a timeout not even once on my end so that's why
> > > > > > I may be looking for an alternate perspective here. may be need to 
> > > > > > thaw everything back intentionally is one thing I could think of.
> > > > >
> > > > > You can manually force this state, and then check that it will behave
> > > > > correctly. I would expect that on a failure to disconnect from the
> > > > > backend you should switch the frontend to the 'Init' state in order to
> > > > > try to reconnect to the backend when possible.
> > > > >
> > > > From what I understand forcing manually is, failing the freeze without
> > > > disconnect and try to revive the connection by unfreezing the
> > > > queues->reconnecting to backend [which never got diconnected]. May be 
> > > > even
> > > > tearing down things manually because I am not sure what state will 
> > > > frontend
> > > > see if backend fails to to disconnect at any point in time. I assumed 
> > > > connected.
> > > > Then again if its "CONNECTED" I may not need to tear down everything 
> > > > and start
> > > > from Initialising state because that may not work.
> > > >
> > > > So I am not so sure about backend's state so much, lets say if  
> > > > xen_blkif_disconnect fail,
> > > > I don't see it getting handled in the backend then what will be 
> > > > backend's state?
> > > > Will it still switch xenbus state to 'Closed'? If not what will 
> > > > frontend see,
> > > > if it tries to read backend's state through xenbus_read_driver_state ?
> > > >
> > > > So the flow be like:
> > > > Front end marks XenbusStateClosing
> > > > Backend marks its state as XenbusStateClosing
> > > > Frontend marks XenbusStateClosed
> > > > Backend disconnects calls xen_blkif_disconnect
> > > >Backend fails to disconnect, the above function returns EBUSY
> > > >What will be state of backend here?
> > >
> > > Backend should stay in state 'Closing' then, until it can finish
> > > tearing down.
> > >
> > It disconnects the ring after switching to connected state too.
> > > >Frontend did not tear down the rings if backend does not 
> > > > switches the
> > > >state to 'Closed' in case of failure.
> > > >
> > > > If backend stays in CONNECTED state, then even if we mark it 
> > > > Initialised in frontend, backend
> > >
> > > Backend will stay in state 'Closing' I think.
> > >
> > > > won't be calling connect(). {From reading code in frontend_changed}
> > > > IMU, Initialising will fail since backend dev->state != 
> > > > XenbusStateClosed plus
> > > > we did not tear down anything so calling talk_to_blkback may not be 
> > > > needed
> > > >
> > > > Does that sound correct?
> > >
> > > I think switching to the initial state in order to try to attempt a
> > > reconnection would be our best bet here.
> > >
> > It does not seems to work correctly, I get hung tasks all over and all the
> > requests to filesystem gets stuck. Backend does shows the state as 

Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation]

2020-06-22 Thread Roger Pau Monné
On Fri, Jun 19, 2020 at 11:43:12PM +, Anchal Agarwal wrote:
> On Wed, Jun 17, 2020 at 10:35:28AM +0200, Roger Pau Monné wrote:
> > CAUTION: This email originated from outside of the organization. Do not 
> > click links or open attachments unless you can confirm the sender and know 
> > the content is safe.
> > 
> > 
> > 
> > On Tue, Jun 16, 2020 at 09:49:25PM +, Anchal Agarwal wrote:
> > > On Thu, Jun 04, 2020 at 09:05:48AM +0200, Roger Pau Monné wrote:
> > > > CAUTION: This email originated from outside of the organization. Do not 
> > > > click links or open attachments unless you can confirm the sender and 
> > > > know the content is safe.
> > > > On Wed, Jun 03, 2020 at 11:33:52PM +, Agarwal, Anchal wrote:
> > > > >  CAUTION: This email originated from outside of the organization. Do 
> > > > > not click links or open attachments unless you can confirm the sender 
> > > > > and know the content is safe.
> > > > > > + xenbus_dev_error(dev, err, "Freezing timed out;"
> > > > > > +  "the device may become 
> > > > > inconsistent state");
> > > > >
> > > > > Leaving the device in this state is quite bad, as it's in a closed
> > > > > state and with the queues frozen. You should make an attempt to
> > > > > restore things to a working state.
> > > > >
> > > > > You mean if backend closed after timeout? Is there a way to know 
> > > > > that? I understand it's not good to
> > > > > leave it in this state however, I am still trying to find if there is 
> > > > > a good way to know if backend is still connected after timeout.
> > > > > Hence the message " the device may become inconsistent state".  I 
> > > > > didn't see a timeout not even once on my end so that's why
> > > > > I may be looking for an alternate perspective here. may be need to 
> > > > > thaw everything back intentionally is one thing I could think of.
> > > >
> > > > You can manually force this state, and then check that it will behave
> > > > correctly. I would expect that on a failure to disconnect from the
> > > > backend you should switch the frontend to the 'Init' state in order to
> > > > try to reconnect to the backend when possible.
> > > >
> > > From what I understand forcing manually is, failing the freeze without
> > > disconnect and try to revive the connection by unfreezing the
> > > queues->reconnecting to backend [which never got diconnected]. May be even
> > > tearing down things manually because I am not sure what state will 
> > > frontend
> > > see if backend fails to to disconnect at any point in time. I assumed 
> > > connected.
> > > Then again if its "CONNECTED" I may not need to tear down everything and 
> > > start
> > > from Initialising state because that may not work.
> > >
> > > So I am not so sure about backend's state so much, lets say if  
> > > xen_blkif_disconnect fail,
> > > I don't see it getting handled in the backend then what will be backend's 
> > > state?
> > > Will it still switch xenbus state to 'Closed'? If not what will frontend 
> > > see,
> > > if it tries to read backend's state through xenbus_read_driver_state ?
> > >
> > > So the flow be like:
> > > Front end marks XenbusStateClosing
> > > Backend marks its state as XenbusStateClosing
> > > Frontend marks XenbusStateClosed
> > > Backend disconnects calls xen_blkif_disconnect
> > >Backend fails to disconnect, the above function returns EBUSY
> > >What will be state of backend here?
> > 
> > Backend should stay in state 'Closing' then, until it can finish
> > tearing down.
> > 
> It disconnects the ring after switching to connected state too. 
> > >Frontend did not tear down the rings if backend does not switches 
> > > the
> > >state to 'Closed' in case of failure.
> > >
> > > If backend stays in CONNECTED state, then even if we mark it Initialised 
> > > in frontend, backend
> > 
> > Backend will stay in state 'Closing' I think.
> > 
> > > won't be calling connect(). {From reading code in frontend_changed}
> > > IMU, Initialising will fail since backend dev->state != XenbusStateClosed 
> > > plus
> > > we did not tear down anything so calling talk_to_blkback may not be needed
> > >
> > > Does that sound correct?
> > 
> > I think switching to the initial state in order to try to attempt a
> > reconnection would be our best bet here.
> >
> It does not seems to work correctly, I get hung tasks all over and all the
> requests to filesystem gets stuck. Backend does shows the state as connected
> after xenbus_dev_suspend fails but I think there may be something missing.
> I don't seem to get IO interrupts thereafter i.e hitting the function 
> blkif_interrupts.
> I think just marking it initialised may not be the only thing.
> Here is a short description of what I am trying to do:
> So, on timeout:
> Switch XenBusState to "Initialized"
> unquiesce/unfreeze the queues and return
> mark info->connected = BLKIF_STATE_CONNECTED

Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation]

2020-06-19 Thread Anchal Agarwal
On Wed, Jun 17, 2020 at 10:35:28AM +0200, Roger Pau Monné wrote:
> CAUTION: This email originated from outside of the organization. Do not click 
> links or open attachments unless you can confirm the sender and know the 
> content is safe.
> 
> 
> 
> On Tue, Jun 16, 2020 at 09:49:25PM +, Anchal Agarwal wrote:
> > On Thu, Jun 04, 2020 at 09:05:48AM +0200, Roger Pau Monné wrote:
> > > CAUTION: This email originated from outside of the organization. Do not 
> > > click links or open attachments unless you can confirm the sender and 
> > > know the content is safe.
> > > On Wed, Jun 03, 2020 at 11:33:52PM +, Agarwal, Anchal wrote:
> > > >  CAUTION: This email originated from outside of the organization. Do 
> > > > not click links or open attachments unless you can confirm the sender 
> > > > and know the content is safe.
> > > > > + xenbus_dev_error(dev, err, "Freezing timed out;"
> > > > > +  "the device may become 
> > > > inconsistent state");
> > > >
> > > > Leaving the device in this state is quite bad, as it's in a closed
> > > > state and with the queues frozen. You should make an attempt to
> > > > restore things to a working state.
> > > >
> > > > You mean if backend closed after timeout? Is there a way to know that? 
> > > > I understand it's not good to
> > > > leave it in this state however, I am still trying to find if there is a 
> > > > good way to know if backend is still connected after timeout.
> > > > Hence the message " the device may become inconsistent state".  I 
> > > > didn't see a timeout not even once on my end so that's why
> > > > I may be looking for an alternate perspective here. may be need to thaw 
> > > > everything back intentionally is one thing I could think of.
> > >
> > > You can manually force this state, and then check that it will behave
> > > correctly. I would expect that on a failure to disconnect from the
> > > backend you should switch the frontend to the 'Init' state in order to
> > > try to reconnect to the backend when possible.
> > >
> > From what I understand forcing manually is, failing the freeze without
> > disconnect and try to revive the connection by unfreezing the
> > queues->reconnecting to backend [which never got diconnected]. May be even
> > tearing down things manually because I am not sure what state will frontend
> > see if backend fails to to disconnect at any point in time. I assumed 
> > connected.
> > Then again if its "CONNECTED" I may not need to tear down everything and 
> > start
> > from Initialising state because that may not work.
> >
> > So I am not so sure about backend's state so much, lets say if  
> > xen_blkif_disconnect fail,
> > I don't see it getting handled in the backend then what will be backend's 
> > state?
> > Will it still switch xenbus state to 'Closed'? If not what will frontend 
> > see,
> > if it tries to read backend's state through xenbus_read_driver_state ?
> >
> > So the flow be like:
> > Front end marks XenbusStateClosing
> > Backend marks its state as XenbusStateClosing
> > Frontend marks XenbusStateClosed
> > Backend disconnects calls xen_blkif_disconnect
> >Backend fails to disconnect, the above function returns EBUSY
> >What will be state of backend here?
> 
> Backend should stay in state 'Closing' then, until it can finish
> tearing down.
> 
It disconnects the ring after switching to connected state too. 
> >Frontend did not tear down the rings if backend does not switches the
> >state to 'Closed' in case of failure.
> >
> > If backend stays in CONNECTED state, then even if we mark it Initialised in 
> > frontend, backend
> 
> Backend will stay in state 'Closing' I think.
> 
> > won't be calling connect(). {From reading code in frontend_changed}
> > IMU, Initialising will fail since backend dev->state != XenbusStateClosed 
> > plus
> > we did not tear down anything so calling talk_to_blkback may not be needed
> >
> > Does that sound correct?
> 
> I think switching to the initial state in order to try to attempt a
> reconnection would be our best bet here.
>
It does not seems to work correctly, I get hung tasks all over and all the
requests to filesystem gets stuck. Backend does shows the state as connected
after xenbus_dev_suspend fails but I think there may be something missing.
I don't seem to get IO interrupts thereafter i.e hitting the function 
blkif_interrupts.
I think just marking it initialised may not be the only thing.
Here is a short description of what I am trying to do:
So, on timeout:
Switch XenBusState to "Initialized"
unquiesce/unfreeze the queues and return
mark info->connected = BLKIF_STATE_CONNECTED
return EBUSY

I even allowed blkfront_connect to switch state to "CONNECTED" rather me doing
it explicitly as mentioned above without re-allocating/re-registering the device
just to make sure bklfront_info object has all the right values.
Do you see anythign missing 

Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation]

2020-06-17 Thread Roger Pau Monné
On Tue, Jun 16, 2020 at 10:30:03PM +, Anchal Agarwal wrote:
> On Tue, Jun 16, 2020 at 09:49:25PM +, Anchal Agarwal wrote:
> > On Thu, Jun 04, 2020 at 09:05:48AM +0200, Roger Pau Monné wrote:
> > > On Wed, Jun 03, 2020 at 11:33:52PM +, Agarwal, Anchal wrote:
> > > > On Tue, May 19, 2020 at 11:27:50PM +, Anchal Agarwal wrote:
> > > > > From: Munehisa Kamata 
> > > > > + xenbus_dev_error(dev, err, "Freezing timed out;"
> > > > > +  "the device may become 
> > > > inconsistent state");
> > > >
> > > > Leaving the device in this state is quite bad, as it's in a closed
> > > > state and with the queues frozen. You should make an attempt to
> > > > restore things to a working state.
> > > >
> > > > You mean if backend closed after timeout? Is there a way to know that? 
> > > > I understand it's not good to
> > > > leave it in this state however, I am still trying to find if there is a 
> > > > good way to know if backend is still connected after timeout.
> > > > Hence the message " the device may become inconsistent state".  I 
> > > > didn't see a timeout not even once on my end so that's why
> > > > I may be looking for an alternate perspective here. may be need to thaw 
> > > > everything back intentionally is one thing I could think of.
> > > 
> > > You can manually force this state, and then check that it will behave
> > > correctly. I would expect that on a failure to disconnect from the
> > > backend you should switch the frontend to the 'Init' state in order to
> > > try to reconnect to the backend when possible.
> > > 
> > From what I understand forcing manually is, failing the freeze without
> > disconnect and try to revive the connection by unfreezing the
> > queues->reconnecting to backend [which never got diconnected]. May be even
> > tearing down things manually because I am not sure what state will frontend
> > see if backend fails to to disconnect at any point in time. I assumed 
> > connected.
> > Then again if its "CONNECTED" I may not need to tear down everything and 
> > start
> > from Initialising state because that may not work.
> > 
> > So I am not so sure about backend's state so much, lets say if  
> > xen_blkif_disconnect fail,
> > I don't see it getting handled in the backend then what will be backend's 
> > state?
> > Will it still switch xenbus state to 'Closed'? If not what will frontend 
> > see, 
> > if it tries to read backend's state through xenbus_read_driver_state ?
> > 
> > So the flow be like:
> > Front end marks XenbusStateClosing
> > Backend marks its state as XenbusStateClosing
> > Frontend marks XenbusStateClosed
> > Backend disconnects calls xen_blkif_disconnect
> >Backend fails to disconnect, the above function returns EBUSY
> >What will be state of backend here? 
> >Frontend did not tear down the rings if backend does not switches the
> >state to 'Closed' in case of failure.
> > 
> > If backend stays in CONNECTED state, then even if we mark it Initialised in 
> > frontend, backend
> > won't be calling connect(). {From reading code in frontend_changed}
> > IMU, Initialising will fail since backend dev->state != XenbusStateClosed 
> > plus
> > we did not tear down anything so calling talk_to_blkback may not be needed
> > 
> > Does that sound correct?
> Send that too quickly, I also meant to add XenBusIntialised state should be ok
> only if we expect backend will stay in "Connected" state. Also, I experimented
> with that notion. I am little worried about the correctness here. 
> Can the backend  come to an Unknown state somehow?

Not really, there's no such thing as an Unknown state.

There are no guarantees about what a backend can do really, so it
could indeed switch to a not recognized state, but that would be a
bug in the backend.

Roger.


Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation]

2020-06-17 Thread Roger Pau Monné
On Tue, Jun 16, 2020 at 09:49:25PM +, Anchal Agarwal wrote:
> On Thu, Jun 04, 2020 at 09:05:48AM +0200, Roger Pau Monné wrote:
> > CAUTION: This email originated from outside of the organization. Do not 
> > click links or open attachments unless you can confirm the sender and know 
> > the content is safe.
> > On Wed, Jun 03, 2020 at 11:33:52PM +, Agarwal, Anchal wrote:
> > >  CAUTION: This email originated from outside of the organization. Do not 
> > > click links or open attachments unless you can confirm the sender and 
> > > know the content is safe.
> > > > + xenbus_dev_error(dev, err, "Freezing timed out;"
> > > > +  "the device may become inconsistent 
> > > state");
> > >
> > > Leaving the device in this state is quite bad, as it's in a closed
> > > state and with the queues frozen. You should make an attempt to
> > > restore things to a working state.
> > >
> > > You mean if backend closed after timeout? Is there a way to know that? I 
> > > understand it's not good to
> > > leave it in this state however, I am still trying to find if there is a 
> > > good way to know if backend is still connected after timeout.
> > > Hence the message " the device may become inconsistent state".  I didn't 
> > > see a timeout not even once on my end so that's why
> > > I may be looking for an alternate perspective here. may be need to thaw 
> > > everything back intentionally is one thing I could think of.
> > 
> > You can manually force this state, and then check that it will behave
> > correctly. I would expect that on a failure to disconnect from the
> > backend you should switch the frontend to the 'Init' state in order to
> > try to reconnect to the backend when possible.
> > 
> From what I understand forcing manually is, failing the freeze without
> disconnect and try to revive the connection by unfreezing the
> queues->reconnecting to backend [which never got diconnected]. May be even
> tearing down things manually because I am not sure what state will frontend
> see if backend fails to to disconnect at any point in time. I assumed 
> connected.
> Then again if its "CONNECTED" I may not need to tear down everything and start
> from Initialising state because that may not work.
> 
> So I am not so sure about backend's state so much, lets say if  
> xen_blkif_disconnect fail,
> I don't see it getting handled in the backend then what will be backend's 
> state?
> Will it still switch xenbus state to 'Closed'? If not what will frontend see, 
> if it tries to read backend's state through xenbus_read_driver_state ?
> 
> So the flow be like:
> Front end marks XenbusStateClosing
> Backend marks its state as XenbusStateClosing
> Frontend marks XenbusStateClosed
> Backend disconnects calls xen_blkif_disconnect
>Backend fails to disconnect, the above function returns EBUSY
>What will be state of backend here?

Backend should stay in state 'Closing' then, until it can finish
tearing down.

>Frontend did not tear down the rings if backend does not switches the
>state to 'Closed' in case of failure.
> 
> If backend stays in CONNECTED state, then even if we mark it Initialised in 
> frontend, backend

Backend will stay in state 'Closing' I think.

> won't be calling connect(). {From reading code in frontend_changed}
> IMU, Initialising will fail since backend dev->state != XenbusStateClosed plus
> we did not tear down anything so calling talk_to_blkback may not be needed
> 
> Does that sound correct?

I think switching to the initial state in order to try to attempt a
reconnection would be our best bet here.

Thanks, Roger.


Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation]

2020-06-16 Thread Anchal Agarwal
On Tue, Jun 16, 2020 at 09:49:25PM +, Anchal Agarwal wrote:
> On Thu, Jun 04, 2020 at 09:05:48AM +0200, Roger Pau Monné wrote:
> > CAUTION: This email originated from outside of the organization. Do not 
> > click links or open attachments unless you can confirm the sender and know 
> > the content is safe.
> > 
> > 
> > 
> > Hello,
> > 
> > On Wed, Jun 03, 2020 at 11:33:52PM +, Agarwal, Anchal wrote:
> > >  CAUTION: This email originated from outside of the organization. Do not 
> > > click links or open attachments unless you can confirm the sender and 
> > > know the content is safe.
> > >
> > >
> > >
> > > On Tue, May 19, 2020 at 11:27:50PM +, Anchal Agarwal wrote:
> > > > From: Munehisa Kamata 
> > > >
> > > > S4 power transition states are much different than xen
> > > > suspend/resume. Former is visible to the guest and frontend drivers 
> > > should
> > > > be aware of the state transitions and should be able to take 
> > > appropriate
> > > > actions when needed. In transition to S4 we need to make sure that 
> > > at least
> > > > all the in-flight blkif requests get completed, since they probably 
> > > contain
> > > > bits of the guest's memory image and that's not going to get saved 
> > > any
> > > > other way. Hence, re-issuing of in-flight requests as in case of 
> > > xen resume
> > > > will not work here. This is in contrast to xen-suspend where we 
> > > need to
> > > > freeze with as little processing as possible to avoid dirtying RAM 
> > > late in
> > > > the migration cycle and we know that in-flight data can wait.
> > > >
> > > > Add freeze, thaw and restore callbacks for PM suspend and 
> > > hibernation
> > > > support. All frontend drivers that needs to use 
> > > PM_HIBERNATION/PM_SUSPEND
> > > > events, need to implement these xenbus_driver callbacks. The freeze 
> > > handler
> > > > stops block-layer queue and disconnect the frontend from the 
> > > backend while
> > > > freeing ring_info and associated resources. Before disconnecting 
> > > from the
> > > > backend, we need to prevent any new IO from being queued and wait 
> > > for existing
> > > > IO to complete. Freeze/unfreeze of the queues will guarantee that 
> > > there are no
> > > > requests in use on the shared ring. However, for sanity we should 
> > > check
> > > > state of the ring before disconnecting to make sure that there are 
> > > no
> > > > outstanding requests to be processed on the ring. The restore 
> > > handler
> > > > re-allocates ring_info, unquiesces and unfreezes the queue and 
> > > re-connect to
> > > > the backend, so that rest of the kernel can continue to use the 
> > > block device
> > > > transparently.
> > > >
> > > > Note:For older backends,if a backend doesn't have 
> > > commit'12ea729645ace'
> > > > xen/blkback: unmap all persistent grants when frontend gets 
> > > disconnected,
> > > > the frontend may see massive amount of grant table warning when 
> > > freeing
> > > > resources.
> > > > [   36.852659] deferring g.e. 0xf9 (pfn 0x)
> > > > [   36.855089] xen:grant_table: WARNING:e.g. 0x112 still in use!
> > > >
> > > > In this case, persistent grants would need to be disabled.
> > > >
> > > > [Anchal Changelog: Removed timeout/request during blkfront freeze.
> > > > Reworked the whole patch to work with blk-mq and incorporate 
> > > upstream's
> > > > comments]
> > >
> > > Please tag versions using vX and it would be helpful if you could list
> > > the specific changes that you performed between versions. There where
> > > 3 RFC versions IIRC, and there's no log of the changes between them.
> > >
> > > I will elaborate on "upstream's comments" in my changelog in my next 
> > > round of patches.
> > 
> > Sorry for being picky, but can you please make sure your email client
> > properly quotes previous emails on reply. Note the lack of '>' added
> > to the quoted parts of your reply.
> That was just my outlook probably. Note taken.
> > 
> > > > + }
> > > > +
> > > >   break;
> > > > + }
> > > > +
> > > > + /*
> > > > +  * We may somehow receive backend's Closed again 
> > > while thawing
> > > > +  * or restoring and it causes thawing or restoring to 
> > > fail.
> > > > +  * Ignore such unexpected state regardless of the 
> > > backend state.
> > > > +  */
> > > > + if (info->connected == BLKIF_STATE_FROZEN) {
> > >
> > > I think you can join this with the previous dev->state == 
> > > XenbusStateClosed?
> > >
> > > Also, won't the device be in the Closed state already if it's in state
> > > frozen?
> > > Yes but I think this mostly due to a hypothetical case if during thawing 
> > > backend switches to Closed 

Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation]

2020-06-16 Thread Anchal Agarwal
On Thu, Jun 04, 2020 at 09:05:48AM +0200, Roger Pau Monné wrote:
> CAUTION: This email originated from outside of the organization. Do not click 
> links or open attachments unless you can confirm the sender and know the 
> content is safe.
> 
> 
> 
> Hello,
> 
> On Wed, Jun 03, 2020 at 11:33:52PM +, Agarwal, Anchal wrote:
> >  CAUTION: This email originated from outside of the organization. Do not 
> > click links or open attachments unless you can confirm the sender and know 
> > the content is safe.
> >
> >
> >
> > On Tue, May 19, 2020 at 11:27:50PM +, Anchal Agarwal wrote:
> > > From: Munehisa Kamata 
> > >
> > > S4 power transition states are much different than xen
> > > suspend/resume. Former is visible to the guest and frontend drivers 
> > should
> > > be aware of the state transitions and should be able to take 
> > appropriate
> > > actions when needed. In transition to S4 we need to make sure that at 
> > least
> > > all the in-flight blkif requests get completed, since they probably 
> > contain
> > > bits of the guest's memory image and that's not going to get saved any
> > > other way. Hence, re-issuing of in-flight requests as in case of xen 
> > resume
> > > will not work here. This is in contrast to xen-suspend where we need 
> > to
> > > freeze with as little processing as possible to avoid dirtying RAM 
> > late in
> > > the migration cycle and we know that in-flight data can wait.
> > >
> > > Add freeze, thaw and restore callbacks for PM suspend and hibernation
> > > support. All frontend drivers that needs to use 
> > PM_HIBERNATION/PM_SUSPEND
> > > events, need to implement these xenbus_driver callbacks. The freeze 
> > handler
> > > stops block-layer queue and disconnect the frontend from the backend 
> > while
> > > freeing ring_info and associated resources. Before disconnecting from 
> > the
> > > backend, we need to prevent any new IO from being queued and wait for 
> > existing
> > > IO to complete. Freeze/unfreeze of the queues will guarantee that 
> > there are no
> > > requests in use on the shared ring. However, for sanity we should 
> > check
> > > state of the ring before disconnecting to make sure that there are no
> > > outstanding requests to be processed on the ring. The restore handler
> > > re-allocates ring_info, unquiesces and unfreezes the queue and 
> > re-connect to
> > > the backend, so that rest of the kernel can continue to use the block 
> > device
> > > transparently.
> > >
> > > Note:For older backends,if a backend doesn't have 
> > commit'12ea729645ace'
> > > xen/blkback: unmap all persistent grants when frontend gets 
> > disconnected,
> > > the frontend may see massive amount of grant table warning when 
> > freeing
> > > resources.
> > > [   36.852659] deferring g.e. 0xf9 (pfn 0x)
> > > [   36.855089] xen:grant_table: WARNING:e.g. 0x112 still in use!
> > >
> > > In this case, persistent grants would need to be disabled.
> > >
> > > [Anchal Changelog: Removed timeout/request during blkfront freeze.
> > > Reworked the whole patch to work with blk-mq and incorporate 
> > upstream's
> > > comments]
> >
> > Please tag versions using vX and it would be helpful if you could list
> > the specific changes that you performed between versions. There where
> > 3 RFC versions IIRC, and there's no log of the changes between them.
> >
> > I will elaborate on "upstream's comments" in my changelog in my next round 
> > of patches.
> 
> Sorry for being picky, but can you please make sure your email client
> properly quotes previous emails on reply. Note the lack of '>' added
> to the quoted parts of your reply.
That was just my outlook probably. Note taken.
> 
> > > + }
> > > +
> > >   break;
> > > + }
> > > +
> > > + /*
> > > +  * We may somehow receive backend's Closed again while 
> > thawing
> > > +  * or restoring and it causes thawing or restoring to 
> > fail.
> > > +  * Ignore such unexpected state regardless of the 
> > backend state.
> > > +  */
> > > + if (info->connected == BLKIF_STATE_FROZEN) {
> >
> > I think you can join this with the previous dev->state == 
> > XenbusStateClosed?
> >
> > Also, won't the device be in the Closed state already if it's in state
> > frozen?
> > Yes but I think this mostly due to a hypothetical case if during thawing 
> > backend switches to Closed state.
> > I am not entirely sure if that could happen. Could use some expertise here.
> 
> I think the frontend seeing the backend in the closed state during
> restore would be a bug that should prevent the frontend from
> resuming.
> 
> > > + /* Kick the backend to disconnect */
> > > + 

Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation]

2020-06-04 Thread Roger Pau Monné
Hello,

On Wed, Jun 03, 2020 at 11:33:52PM +, Agarwal, Anchal wrote:
>  CAUTION: This email originated from outside of the organization. Do not 
> click links or open attachments unless you can confirm the sender and know 
> the content is safe.
> 
> 
> 
> On Tue, May 19, 2020 at 11:27:50PM +, Anchal Agarwal wrote:
> > From: Munehisa Kamata 
> > 
> > S4 power transition states are much different than xen
> > suspend/resume. Former is visible to the guest and frontend drivers 
> should
> > be aware of the state transitions and should be able to take appropriate
> > actions when needed. In transition to S4 we need to make sure that at 
> least
> > all the in-flight blkif requests get completed, since they probably 
> contain
> > bits of the guest's memory image and that's not going to get saved any
> > other way. Hence, re-issuing of in-flight requests as in case of xen 
> resume
> > will not work here. This is in contrast to xen-suspend where we need to
> > freeze with as little processing as possible to avoid dirtying RAM late 
> in
> > the migration cycle and we know that in-flight data can wait.
> > 
> > Add freeze, thaw and restore callbacks for PM suspend and hibernation
> > support. All frontend drivers that needs to use 
> PM_HIBERNATION/PM_SUSPEND
> > events, need to implement these xenbus_driver callbacks. The freeze 
> handler
> > stops block-layer queue and disconnect the frontend from the backend 
> while
> > freeing ring_info and associated resources. Before disconnecting from 
> the
> > backend, we need to prevent any new IO from being queued and wait for 
> existing
> > IO to complete. Freeze/unfreeze of the queues will guarantee that there 
> are no
> > requests in use on the shared ring. However, for sanity we should check
> > state of the ring before disconnecting to make sure that there are no
> > outstanding requests to be processed on the ring. The restore handler
> > re-allocates ring_info, unquiesces and unfreezes the queue and 
> re-connect to
> > the backend, so that rest of the kernel can continue to use the block 
> device
> > transparently.
> > 
> > Note:For older backends,if a backend doesn't have commit'12ea729645ace'
> > xen/blkback: unmap all persistent grants when frontend gets 
> disconnected,
> > the frontend may see massive amount of grant table warning when freeing
> > resources.
> > [   36.852659] deferring g.e. 0xf9 (pfn 0x)
> > [   36.855089] xen:grant_table: WARNING:e.g. 0x112 still in use!
> > 
> > In this case, persistent grants would need to be disabled.
> > 
> > [Anchal Changelog: Removed timeout/request during blkfront freeze.
> > Reworked the whole patch to work with blk-mq and incorporate upstream's
> > comments]
> 
> Please tag versions using vX and it would be helpful if you could list
> the specific changes that you performed between versions. There where
> 3 RFC versions IIRC, and there's no log of the changes between them.
> 
> I will elaborate on "upstream's comments" in my changelog in my next round of 
> patches.

Sorry for being picky, but can you please make sure your email client
properly quotes previous emails on reply. Note the lack of '>' added
to the quoted parts of your reply.

> > + }
> > +
> >   break;
> > + }
> > +
> > + /*
> > +  * We may somehow receive backend's Closed again while 
> thawing
> > +  * or restoring and it causes thawing or restoring to 
> fail.
> > +  * Ignore such unexpected state regardless of the backend 
> state.
> > +  */
> > + if (info->connected == BLKIF_STATE_FROZEN) {
> 
> I think you can join this with the previous dev->state == 
> XenbusStateClosed?
> 
> Also, won't the device be in the Closed state already if it's in state
> frozen?
> Yes but I think this mostly due to a hypothetical case if during thawing 
> backend switches to Closed state.
> I am not entirely sure if that could happen. Could use some expertise here.

I think the frontend seeing the backend in the closed state during
restore would be a bug that should prevent the frontend from
resuming.

> > + /* Kick the backend to disconnect */
> > + xenbus_switch_state(dev, XenbusStateClosing);
> > +
> > + /*
> > +  * We don't want to move forward before the frontend is 
> diconnected
> > +  * from the backend cleanly.
> > +  */
> > + timeout = 
> wait_for_completion_timeout(>wait_backend_disconnected,
> > +   timeout);
> > + if (!timeout) {
> > + err = -EBUSY;
> 
> Note err is only used here, and I think could just be dropped.
> 
> This err is what's being 

Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation]

2020-06-03 Thread Agarwal, Anchal
 CAUTION: This email originated from outside of the organization. Do not click 
links or open attachments unless you can confirm the sender and know the 
content is safe.



On Tue, May 19, 2020 at 11:27:50PM +, Anchal Agarwal wrote:
> From: Munehisa Kamata 
> 
> S4 power transition states are much different than xen
> suspend/resume. Former is visible to the guest and frontend drivers should
> be aware of the state transitions and should be able to take appropriate
> actions when needed. In transition to S4 we need to make sure that at 
least
> all the in-flight blkif requests get completed, since they probably 
contain
> bits of the guest's memory image and that's not going to get saved any
> other way. Hence, re-issuing of in-flight requests as in case of xen 
resume
> will not work here. This is in contrast to xen-suspend where we need to
> freeze with as little processing as possible to avoid dirtying RAM late in
> the migration cycle and we know that in-flight data can wait.
> 
> Add freeze, thaw and restore callbacks for PM suspend and hibernation
> support. All frontend drivers that needs to use PM_HIBERNATION/PM_SUSPEND
> events, need to implement these xenbus_driver callbacks. The freeze 
handler
> stops block-layer queue and disconnect the frontend from the backend while
> freeing ring_info and associated resources. Before disconnecting from the
> backend, we need to prevent any new IO from being queued and wait for 
existing
> IO to complete. Freeze/unfreeze of the queues will guarantee that there 
are no
> requests in use on the shared ring. However, for sanity we should check
> state of the ring before disconnecting to make sure that there are no
> outstanding requests to be processed on the ring. The restore handler
> re-allocates ring_info, unquiesces and unfreezes the queue and re-connect 
to
> the backend, so that rest of the kernel can continue to use the block 
device
> transparently.
> 
> Note:For older backends,if a backend doesn't have commit'12ea729645ace'
> xen/blkback: unmap all persistent grants when frontend gets disconnected,
> the frontend may see massive amount of grant table warning when freeing
> resources.
> [   36.852659] deferring g.e. 0xf9 (pfn 0x)
> [   36.855089] xen:grant_table: WARNING:e.g. 0x112 still in use!
> 
> In this case, persistent grants would need to be disabled.
> 
> [Anchal Changelog: Removed timeout/request during blkfront freeze.
> Reworked the whole patch to work with blk-mq and incorporate upstream's
> comments]

Please tag versions using vX and it would be helpful if you could list
the specific changes that you performed between versions. There where
3 RFC versions IIRC, and there's no log of the changes between them.

I will elaborate on "upstream's comments" in my changelog in my next round of 
patches.
> 
> Signed-off-by: Anchal Agarwal 
> Signed-off-by: Munehisa Kamata 
> ---
>  drivers/block/xen-blkfront.c | 122 +--
>  1 file changed, 115 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
> index 3b889ea950c2..464863ed7093 100644
> --- a/drivers/block/xen-blkfront.c
> +++ b/drivers/block/xen-blkfront.c
> @@ -48,6 +48,8 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
> 
>  #include 
>  #include 
> @@ -80,6 +82,8 @@ enum blkif_state {
>   BLKIF_STATE_DISCONNECTED,
>   BLKIF_STATE_CONNECTED,
>   BLKIF_STATE_SUSPENDED,
> + BLKIF_STATE_FREEZING,
> + BLKIF_STATE_FROZEN

Nit: adding a terminating ',' would prevent further additions from
having to modify this line.
ACK.
>  };
> 
>  struct grant {
> @@ -219,6 +223,7 @@ struct blkfront_info
>   struct list_head requests;
>   struct bio_list bio_list;
>   struct list_head info_list;
> + struct completion wait_backend_disconnected;
>  };
> 
>  static unsigned int nr_minors;
> @@ -1005,6 +1010,7 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, 
u16 sector_size,
>   info->sector_size = sector_size;
>   info->physical_sector_size = physical_sector_size;
>   blkif_set_queue_limits(info);
> + init_completion(>wait_backend_disconnected);
> 
>   return 0;
>  }
> @@ -1057,7 +1063,7 @@ static int xen_translate_vdev(int vdevice, int 
*minor, unsigned int *offset)
>   case XEN_SCSI_DISK5_MAJOR:
>   case XEN_SCSI_DISK6_MAJOR:
>   case XEN_SCSI_DISK7_MAJOR:
> - *offset = (*minor / PARTS_PER_DISK) +
> + *offset = (*minor / PARTS_PER_DISK) +
>   

Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation

2020-05-28 Thread Roger Pau Monné
On Tue, May 19, 2020 at 11:27:50PM +, Anchal Agarwal wrote:
> From: Munehisa Kamata 
> 
> S4 power transition states are much different than xen
> suspend/resume. Former is visible to the guest and frontend drivers should
> be aware of the state transitions and should be able to take appropriate
> actions when needed. In transition to S4 we need to make sure that at least
> all the in-flight blkif requests get completed, since they probably contain
> bits of the guest's memory image and that's not going to get saved any
> other way. Hence, re-issuing of in-flight requests as in case of xen resume
> will not work here. This is in contrast to xen-suspend where we need to
> freeze with as little processing as possible to avoid dirtying RAM late in
> the migration cycle and we know that in-flight data can wait.
> 
> Add freeze, thaw and restore callbacks for PM suspend and hibernation
> support. All frontend drivers that needs to use PM_HIBERNATION/PM_SUSPEND
> events, need to implement these xenbus_driver callbacks. The freeze handler
> stops block-layer queue and disconnect the frontend from the backend while
> freeing ring_info and associated resources. Before disconnecting from the
> backend, we need to prevent any new IO from being queued and wait for existing
> IO to complete. Freeze/unfreeze of the queues will guarantee that there are no
> requests in use on the shared ring. However, for sanity we should check
> state of the ring before disconnecting to make sure that there are no
> outstanding requests to be processed on the ring. The restore handler
> re-allocates ring_info, unquiesces and unfreezes the queue and re-connect to
> the backend, so that rest of the kernel can continue to use the block device
> transparently.
> 
> Note:For older backends,if a backend doesn't have commit'12ea729645ace'
> xen/blkback: unmap all persistent grants when frontend gets disconnected,
> the frontend may see massive amount of grant table warning when freeing
> resources.
> [   36.852659] deferring g.e. 0xf9 (pfn 0x)
> [   36.855089] xen:grant_table: WARNING:e.g. 0x112 still in use!
> 
> In this case, persistent grants would need to be disabled.
> 
> [Anchal Changelog: Removed timeout/request during blkfront freeze.
> Reworked the whole patch to work with blk-mq and incorporate upstream's
> comments]

Please tag versions using vX and it would be helpful if you could list
the specific changes that you performed between versions. There where
3 RFC versions IIRC, and there's no log of the changes between them.

> 
> Signed-off-by: Anchal Agarwal 
> Signed-off-by: Munehisa Kamata 
> ---
>  drivers/block/xen-blkfront.c | 122 +--
>  1 file changed, 115 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
> index 3b889ea950c2..464863ed7093 100644
> --- a/drivers/block/xen-blkfront.c
> +++ b/drivers/block/xen-blkfront.c
> @@ -48,6 +48,8 @@
>  #include 
>  #include 
>  #include 
> +#include 
> +#include 
>  
>  #include 
>  #include 
> @@ -80,6 +82,8 @@ enum blkif_state {
>   BLKIF_STATE_DISCONNECTED,
>   BLKIF_STATE_CONNECTED,
>   BLKIF_STATE_SUSPENDED,
> + BLKIF_STATE_FREEZING,
> + BLKIF_STATE_FROZEN

Nit: adding a terminating ',' would prevent further additions from
having to modify this line.

>  };
>  
>  struct grant {
> @@ -219,6 +223,7 @@ struct blkfront_info
>   struct list_head requests;
>   struct bio_list bio_list;
>   struct list_head info_list;
> + struct completion wait_backend_disconnected;
>  };
>  
>  static unsigned int nr_minors;
> @@ -1005,6 +1010,7 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 
> sector_size,
>   info->sector_size = sector_size;
>   info->physical_sector_size = physical_sector_size;
>   blkif_set_queue_limits(info);
> + init_completion(>wait_backend_disconnected);
>  
>   return 0;
>  }
> @@ -1057,7 +1063,7 @@ static int xen_translate_vdev(int vdevice, int *minor, 
> unsigned int *offset)
>   case XEN_SCSI_DISK5_MAJOR:
>   case XEN_SCSI_DISK6_MAJOR:
>   case XEN_SCSI_DISK7_MAJOR:
> - *offset = (*minor / PARTS_PER_DISK) + 
> + *offset = (*minor / PARTS_PER_DISK) +
>   ((major - XEN_SCSI_DISK1_MAJOR + 1) * 16) +
>   EMULATED_SD_DISK_NAME_OFFSET;
>   *minor = *minor +
> @@ -1072,7 +1078,7 @@ static int xen_translate_vdev(int vdevice, int *minor, 
> unsigned int *offset)
>   case XEN_SCSI_DISK13_MAJOR:
>   case XEN_SCSI_DISK14_MAJOR:
>   case XEN_SCSI_DISK15_MAJOR:
> - *offset = (*minor / PARTS_PER_DISK) + 
> + *offset = (*minor / PARTS_PER_DISK) +

Unrelated changes, please split to a pre-patch.

>   ((major - XEN_SCSI_DISK8_MAJOR + 8) * 16) +
>  

Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation

2020-05-23 Thread kbuild test robot
Hi Anchal,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on linus/master]
[also build test WARNING on v5.7-rc6]
[cannot apply to xen-tip/linux-next tip/irq/core tip/auto-latest next-20200519]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:
https://github.com/0day-ci/linux/commits/Anchal-Agarwal/Fix-PM-hibernation-in-Xen-guests/20200520-073211
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
03fb3acae4be8a6b680ffedb220a8b6c07260b40
config: x86_64-allmodconfig (attached as .config)
reproduce:
# apt-get install sparse
# sparse version: v0.6.1-193-gb8fad4bc-dirty
# save the attached .config to linux build tree
make C=1 ARCH=x86_64 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__'
:: branch date: 11 hours ago
:: commit date: 11 hours ago

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot 


sparse warnings: (new ones prefixed by >>)

>> drivers/block/xen-blkfront.c:2700:0: sparse: sparse: missing terminating " 
>> character
   drivers/block/xen-blkfront.c:2701:0: sparse: sparse: missing terminating " 
character
   drivers/block/xen-blkfront.c:2700:25: sparse: sparse: Expected ) in function 
call
   drivers/block/xen-blkfront.c:2700:25: sparse: sparse: got The

# 
https://github.com/0day-ci/linux/commit/1997467d18e784a64ee0fe00875492e9605f6147
git remote add linux-review https://github.com/0day-ci/linux
git remote update linux-review
git checkout 1997467d18e784a64ee0fe00875492e9605f6147
vim +2700 drivers/block/xen-blkfront.c

9f27ee59503865 Jeremy Fitzhardinge 2007-07-17  2672  
1997467d18e784 Munehisa Kamata 2020-05-19  2673  static int 
blkfront_freeze(struct xenbus_device *dev)
1997467d18e784 Munehisa Kamata 2020-05-19  2674  {
1997467d18e784 Munehisa Kamata 2020-05-19  2675 unsigned int i;
1997467d18e784 Munehisa Kamata 2020-05-19  2676 struct blkfront_info 
*info = dev_get_drvdata(>dev);
1997467d18e784 Munehisa Kamata 2020-05-19  2677 struct 
blkfront_ring_info *rinfo;
1997467d18e784 Munehisa Kamata 2020-05-19  2678 /* This would be 
reasonable timeout as used in xenbus_dev_shutdown() */
1997467d18e784 Munehisa Kamata 2020-05-19  2679 unsigned int timeout = 
5 * HZ;
1997467d18e784 Munehisa Kamata 2020-05-19  2680 unsigned long flags;
1997467d18e784 Munehisa Kamata 2020-05-19  2681 int err = 0;
1997467d18e784 Munehisa Kamata 2020-05-19  2682  
1997467d18e784 Munehisa Kamata 2020-05-19  2683 info->connected = 
BLKIF_STATE_FREEZING;
1997467d18e784 Munehisa Kamata 2020-05-19  2684  
1997467d18e784 Munehisa Kamata 2020-05-19  2685 
blk_mq_freeze_queue(info->rq);
1997467d18e784 Munehisa Kamata 2020-05-19  2686 
blk_mq_quiesce_queue(info->rq);
1997467d18e784 Munehisa Kamata 2020-05-19  2687  
1997467d18e784 Munehisa Kamata 2020-05-19  2688 for_each_rinfo(info, 
rinfo, i) {
1997467d18e784 Munehisa Kamata 2020-05-19  2689 /* No more gnttab 
callback work. */
1997467d18e784 Munehisa Kamata 2020-05-19  2690 
gnttab_cancel_free_callback(>callback);
1997467d18e784 Munehisa Kamata 2020-05-19  2691 /* Flush gnttab 
callback work. Must be done with no locks held. */
1997467d18e784 Munehisa Kamata 2020-05-19  2692 
flush_work(>work);
1997467d18e784 Munehisa Kamata 2020-05-19  2693 }
1997467d18e784 Munehisa Kamata 2020-05-19  2694  
1997467d18e784 Munehisa Kamata 2020-05-19  2695 for_each_rinfo(info, 
rinfo, i) {
1997467d18e784 Munehisa Kamata 2020-05-19  2696 
spin_lock_irqsave(>ring_lock, flags);
1997467d18e784 Munehisa Kamata 2020-05-19  2697 if 
(RING_FULL(>ring)
1997467d18e784 Munehisa Kamata 2020-05-19  2698 || 
RING_HAS_UNCONSUMED_RESPONSES(>ring)) {
1997467d18e784 Munehisa Kamata 2020-05-19  2699 
xenbus_dev_error(dev, err, "Hibernation Failed.
1997467d18e784 Munehisa Kamata 2020-05-19 @2700 The 
ring is still busy");
1997467d18e784 Munehisa Kamata 2020-05-19  2701 info->connected 
= BLKIF_STATE_CONNECTED;
1997467d18e784 Munehisa Kamata 2020-05-19  2702 
spin_unlock_irqrestore(>ring_lock, flags);
1997467d18e784 Munehisa Kamata 2020-05-19  2703 return -EBUSY;
1997467d18e784 Munehisa Kamata 2020-05-19  2704 }
1997467d18e784 Munehisa Kamata 2020-05-19  2705 
spin_unlock_irqrestore(>ring_lock, flags);
1997467d18e784 Munehisa Kamata 2020-05-19  2706 }
1997467d18e784 Munehisa Kamata 2020-05-19  2707 /* Kick the backend to 
disconnect */
1997467d18e784 Munehisa Kamata 2020-05-19  2708 
xenbus_switch_state(dev, XenbusStateClosing);

Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation

2020-05-21 Thread Singh, Balbir
> @@ -1057,7 +1063,7 @@ static int xen_translate_vdev(int vdevice, int *minor, 
> unsigned int *offset)
>   case XEN_SCSI_DISK5_MAJOR:
>   case XEN_SCSI_DISK6_MAJOR:
>   case XEN_SCSI_DISK7_MAJOR:
> - *offset = (*minor / PARTS_PER_DISK) + 
> + *offset = (*minor / PARTS_PER_DISK) +
>   ((major - XEN_SCSI_DISK1_MAJOR + 1) * 16) +
>   EMULATED_SD_DISK_NAME_OFFSET;
>   *minor = *minor +
> @@ -1072,7 +1078,7 @@ static int xen_translate_vdev(int vdevice, int *minor, 
> unsigned int *offset)
>   case XEN_SCSI_DISK13_MAJOR:
>   case XEN_SCSI_DISK14_MAJOR:
>   case XEN_SCSI_DISK15_MAJOR:
> - *offset = (*minor / PARTS_PER_DISK) + 
> + *offset = (*minor / PARTS_PER_DISK) +
>   ((major - XEN_SCSI_DISK8_MAJOR + 8) * 16) +
>   EMULATED_SD_DISK_NAME_OFFSET;
>   *minor = *minor +

These seem like whitespace fixes? If so, they should be in a separate patch

Balbir



[PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation

2020-05-21 Thread Anchal Agarwal
From: Munehisa Kamata 

S4 power transisiton states are much different than xen
suspend/resume. Former is visible to the guest and frontend drivers should
be aware of the state transistions and should be able to take appropriate
actions when needed. In transition to S4 we need to make sure that at least
all the in-flight blkif requests get completed, since they probably contain
bits of the guest's memory image and that's not going to get saved any
other way. Hence, re-issuing of in-flight requests as in case of xen resume
will not work here. This is in contrast to xen-suspend where we need to
freeze with as little processing as possible to avoid dirtying RAM late in
the migration cycle and we know that in-flight data can wait.

Add freeze, thaw and restore callbacks for PM suspend and hibernation
support. All frontend drivers that needs to use PM_HIBERNATION/PM_SUSPEND
events, need to implement these xenbus_driver callbacks. The freeze handler
stops block-layer queue and disconnect the frontend from the backend while
freeing ring_info and associated resources. Before disconnecting from the
backend, we need to prevent any new IO from being queued and wait for
existing IO to complete. Freeze/unfreeze of the queues will guarantee that
there are no requests in use on the shared ring. However, for sanity we
should check state of the ring before disconnecting to make sure that there
are no outstanding requests to be processed on the ring. The restore
handler re-allocates ring_info, unquiesces and unfreezes the queue
and re-connect to the backend, so that rest of the kernel can continue
to use the block device transparently.

Note:For older backends,if a backend doesn't have commit'12ea729645ace'
xen/blkback: unmap all persistent grants when frontend gets disconnected,
the frontend may see massive amount of grant table warning when freeing
resources.
[   36.852659] deferring g.e. 0xf9 (pfn 0x)
[   36.855089] xen:grant_table: WARNING:e.g. 0x112 still in use!

In this case, persistent grants would need to be disabled.

[Anchal Changelog: Removed timeout/request during blkfront freeze.
Reworked the whole patch to work with blk-mq and incorporate upstream's
comments]

Fixes: Build errors reported by kbuild due to linebreak
Reported-by: kbuild test robot 

Signed-off-by: Anchal Agarwal 
Signed-off-by: Munehisa Kamata 
---
 drivers/block/xen-blkfront.c | 118 +--
 1 file changed, 112 insertions(+), 6 deletions(-)

diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 3b889ea950c2..34b0e51697b6 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -48,6 +48,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 #include 
@@ -80,6 +82,8 @@ enum blkif_state {
BLKIF_STATE_DISCONNECTED,
BLKIF_STATE_CONNECTED,
BLKIF_STATE_SUSPENDED,
+   BLKIF_STATE_FREEZING,
+   BLKIF_STATE_FROZEN
 };
 
 struct grant {
@@ -219,6 +223,7 @@ struct blkfront_info
struct list_head requests;
struct bio_list bio_list;
struct list_head info_list;
+   struct completion wait_backend_disconnected;
 };
 
 static unsigned int nr_minors;
@@ -1005,6 +1010,7 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 
sector_size,
info->sector_size = sector_size;
info->physical_sector_size = physical_sector_size;
blkif_set_queue_limits(info);
+   init_completion(>wait_backend_disconnected);
 
return 0;
 }
@@ -1057,7 +1063,7 @@ static int xen_translate_vdev(int vdevice, int *minor, 
unsigned int *offset)
case XEN_SCSI_DISK5_MAJOR:
case XEN_SCSI_DISK6_MAJOR:
case XEN_SCSI_DISK7_MAJOR:
-   *offset = (*minor / PARTS_PER_DISK) + 
+   *offset = (*minor / PARTS_PER_DISK) +
((major - XEN_SCSI_DISK1_MAJOR + 1) * 16) +
EMULATED_SD_DISK_NAME_OFFSET;
*minor = *minor +
@@ -1072,7 +1078,7 @@ static int xen_translate_vdev(int vdevice, int *minor, 
unsigned int *offset)
case XEN_SCSI_DISK13_MAJOR:
case XEN_SCSI_DISK14_MAJOR:
case XEN_SCSI_DISK15_MAJOR:
-   *offset = (*minor / PARTS_PER_DISK) + 
+   *offset = (*minor / PARTS_PER_DISK) +
((major - XEN_SCSI_DISK8_MAJOR + 8) * 16) +
EMULATED_SD_DISK_NAME_OFFSET;
*minor = *minor +
@@ -1353,6 +1359,8 @@ static void blkif_free(struct blkfront_info *info, int 
suspend)
unsigned int i;
struct blkfront_ring_info *rinfo;
 
+   if (info->connected == BLKIF_STATE_FREEZING)
+   goto free_rings;
/* Prevent new requests being issued until we fix things up. */
info->connected = suspend ?
BLKIF_STATE_SUSPENDED : 

Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation

2020-05-19 Thread kbuild test robot
Hi Anchal,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.7-rc6]
[cannot apply to xen-tip/linux-next tip/irq/core tip/auto-latest next-20200519]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:
https://github.com/0day-ci/linux/commits/Anchal-Agarwal/Fix-PM-hibernation-in-Xen-guests/20200520-073211
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
03fb3acae4be8a6b680ffedb220a8b6c07260b40
config: x86_64-rhel (attached as .config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot 

All error/warnings (new ones prefixed by >>, old ones prefixed by <<):

drivers/block/xen-blkfront.c: In function 'blkfront_freeze':
>> drivers/block/xen-blkfront.c:2699:30: warning: missing terminating " 
>> character
xenbus_dev_error(dev, err, "Hibernation Failed.
^
>> drivers/block/xen-blkfront.c:2699:30: error: missing terminating " character
xenbus_dev_error(dev, err, "Hibernation Failed.
^~~~
>> drivers/block/xen-blkfront.c:2700:4: error: 'The' undeclared (first use in 
>> this function)
The ring is still busy");
^~~
drivers/block/xen-blkfront.c:2700:4: note: each undeclared identifier is 
reported only once for each function it appears in
>> drivers/block/xen-blkfront.c:2700:8: error: expected ')' before 'ring'
The ring is still busy");
^~~~
drivers/block/xen-blkfront.c:2700:26: warning: missing terminating " character
The ring is still busy");
^
drivers/block/xen-blkfront.c:2700:26: error: missing terminating " character
The ring is still busy");
^~~
>> drivers/block/xen-blkfront.c:2704:2: error: expected ';' before '}' token
}
^

vim +2699 drivers/block/xen-blkfront.c

  2672  
  2673  static int blkfront_freeze(struct xenbus_device *dev)
  2674  {
  2675  unsigned int i;
  2676  struct blkfront_info *info = dev_get_drvdata(>dev);
  2677  struct blkfront_ring_info *rinfo;
  2678  /* This would be reasonable timeout as used in 
xenbus_dev_shutdown() */
  2679  unsigned int timeout = 5 * HZ;
  2680  unsigned long flags;
  2681  int err = 0;
  2682  
  2683  info->connected = BLKIF_STATE_FREEZING;
  2684  
  2685  blk_mq_freeze_queue(info->rq);
  2686  blk_mq_quiesce_queue(info->rq);
  2687  
  2688  for_each_rinfo(info, rinfo, i) {
  2689  /* No more gnttab callback work. */
  2690  gnttab_cancel_free_callback(>callback);
  2691  /* Flush gnttab callback work. Must be done with no locks 
held. */
  2692  flush_work(>work);
  2693  }
  2694  
  2695  for_each_rinfo(info, rinfo, i) {
  2696  spin_lock_irqsave(>ring_lock, flags);
  2697  if (RING_FULL(>ring)
  2698  || RING_HAS_UNCONSUMED_RESPONSES(>ring)) {
> 2699  xenbus_dev_error(dev, err, "Hibernation Failed.
> 2700  The ring is still busy");
  2701  info->connected = BLKIF_STATE_CONNECTED;
  2702  spin_unlock_irqrestore(>ring_lock, flags);
  2703  return -EBUSY;
> 2704  }
  2705  spin_unlock_irqrestore(>ring_lock, flags);
  2706  }
  2707  /* Kick the backend to disconnect */
  2708  xenbus_switch_state(dev, XenbusStateClosing);
  2709  
  2710  /*
  2711   * We don't want to move forward before the frontend is 
diconnected
  2712   * from the backend cleanly.
  2713   */
  2714  timeout = 
wait_for_completion_timeout(>wait_backend_disconnected,
  2715timeout);
  2716  if (!timeout) {
  2717  err = -EBUSY;
  2718  xenbus_dev_error(dev, err, "Freezing timed out;"
  2719   "the device may become inconsistent 
state");
  2720  }
  2721  
  2722  return err;
  2723  }
  2724  

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-...@lists.01.org


.config.gz
Description: application/gzip


Re: [PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation

2020-05-19 Thread kbuild test robot
Hi Anchal,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v5.7-rc6]
[cannot apply to xen-tip/linux-next tip/irq/core tip/auto-latest next-20200519]
[if your patch is applied to the wrong git tree, please drop us a note to help
improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:
https://github.com/0day-ci/linux/commits/Anchal-Agarwal/Fix-PM-hibernation-in-Xen-guests/20200520-073211
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 
03fb3acae4be8a6b680ffedb220a8b6c07260b40
config: x86_64-randconfig-a016-20200519 (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 
e6658079aca6d971b4e9d7137a3a2ecbc9c34aec)
reproduce:
wget 
https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O 
~/bin/make.cross
chmod +x ~/bin/make.cross
# install x86_64 cross compiling tool for clang build
# apt-get install binutils-x86-64-linux-gnu
# save the attached .config to linux build tree
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=x86_64 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kbuild test robot 

All error/warnings (new ones prefixed by >>, old ones prefixed by <<):

>> drivers/block/xen-blkfront.c:2699:30: warning: missing terminating '"' 
>> character [-Winvalid-pp-token]
xenbus_dev_error(dev, err, "Hibernation Failed.
^
>> drivers/block/xen-blkfront.c:2699:30: error: expected expression
drivers/block/xen-blkfront.c:2700:26: warning: missing terminating '"' 
character [-Winvalid-pp-token]
The ring is still busy");
^
>> drivers/block/xen-blkfront.c:2726:1: error: function definition is not 
>> allowed here
{
^
>> drivers/block/xen-blkfront.c:2762:10: error: use of undeclared identifier 
>> 'blkfront_restore'
.thaw = blkfront_restore,
^
drivers/block/xen-blkfront.c:2763:13: error: use of undeclared identifier 
'blkfront_restore'
.restore = blkfront_restore
^
drivers/block/xen-blkfront.c:2767:1: error: function definition is not allowed 
here
{
^
drivers/block/xen-blkfront.c:2800:1: error: function definition is not allowed 
here
{
^
drivers/block/xen-blkfront.c:2822:1: error: function definition is not allowed 
here
{
^
>> drivers/block/xen-blkfront.c:2863:13: error: use of undeclared identifier 
>> 'xlblk_init'
module_init(xlblk_init);
^
drivers/block/xen-blkfront.c:2867:1: error: function definition is not allowed 
here
{
^
>> drivers/block/xen-blkfront.c:2874:13: error: use of undeclared identifier 
>> 'xlblk_exit'
module_exit(xlblk_exit);
^
>> drivers/block/xen-blkfront.c:2880:24: error: expected '}'
MODULE_ALIAS("xenblk");
^
drivers/block/xen-blkfront.c:2674:1: note: to match this '{'
{
^
>> drivers/block/xen-blkfront.c:2738:45: warning: ISO C90 forbids mixing 
>> declarations and code [-Wdeclaration-after-statement]
static const struct block_device_operations xlvbd_block_fops =
^
3 warnings and 11 errors generated.

vim +2699 drivers/block/xen-blkfront.c

  2672  
  2673  static int blkfront_freeze(struct xenbus_device *dev)
  2674  {
  2675  unsigned int i;
  2676  struct blkfront_info *info = dev_get_drvdata(>dev);
  2677  struct blkfront_ring_info *rinfo;
  2678  /* This would be reasonable timeout as used in 
xenbus_dev_shutdown() */
  2679  unsigned int timeout = 5 * HZ;
  2680  unsigned long flags;
  2681  int err = 0;
  2682  
  2683  info->connected = BLKIF_STATE_FREEZING;
  2684  
  2685  blk_mq_freeze_queue(info->rq);
  2686  blk_mq_quiesce_queue(info->rq);
  2687  
  2688  for_each_rinfo(info, rinfo, i) {
  2689  /* No more gnttab callback work. */
  2690  gnttab_cancel_free_callback(>callback);
  2691  /* Flush gnttab callback work. Must be done with no locks 
held. */
  2692  flush_work(>work);
  2693  }
  2694  
  2695  for_each_rinfo(info, rinfo, i) {
  2696  spin_lock_irqsave(>ring_lock, flags);
  2697  if (RING_FULL(>ring)
  2698  || RING_HAS_UNCONSUMED_RESPONSES(>ring)) {
> 2699  xenbus_dev_error(dev, err, "Hibernation Failed.
  2700  The ring is still busy");
  2701  info->connected = BLKIF_STATE_CONNECTED;
  2702  spin_unlock_irqrestore(>ring_lock, flags);
  2703  return -EBUSY;
  2704  }
  2705  spin_unlock_irqrestore(>ring_lock, flags);
  2706  }
  2707  /* Kick the backend to disconnect */
  2708  xenbus_switch_state(dev, XenbusStateClosing);
  2709  
  2710  /*
  2711   * We don't want to move forward before the frontend is 
diconnected
  2712   * from the backend cleanly.
  2713

[PATCH 06/12] xen-blkfront: add callbacks for PM suspend and hibernation

2020-05-19 Thread Anchal Agarwal
From: Munehisa Kamata 

S4 power transition states are much different than xen
suspend/resume. Former is visible to the guest and frontend drivers should
be aware of the state transitions and should be able to take appropriate
actions when needed. In transition to S4 we need to make sure that at least
all the in-flight blkif requests get completed, since they probably contain
bits of the guest's memory image and that's not going to get saved any
other way. Hence, re-issuing of in-flight requests as in case of xen resume
will not work here. This is in contrast to xen-suspend where we need to
freeze with as little processing as possible to avoid dirtying RAM late in
the migration cycle and we know that in-flight data can wait.

Add freeze, thaw and restore callbacks for PM suspend and hibernation
support. All frontend drivers that needs to use PM_HIBERNATION/PM_SUSPEND
events, need to implement these xenbus_driver callbacks. The freeze handler
stops block-layer queue and disconnect the frontend from the backend while
freeing ring_info and associated resources. Before disconnecting from the
backend, we need to prevent any new IO from being queued and wait for existing
IO to complete. Freeze/unfreeze of the queues will guarantee that there are no
requests in use on the shared ring. However, for sanity we should check
state of the ring before disconnecting to make sure that there are no
outstanding requests to be processed on the ring. The restore handler
re-allocates ring_info, unquiesces and unfreezes the queue and re-connect to
the backend, so that rest of the kernel can continue to use the block device
transparently.

Note:For older backends,if a backend doesn't have commit'12ea729645ace'
xen/blkback: unmap all persistent grants when frontend gets disconnected,
the frontend may see massive amount of grant table warning when freeing
resources.
[   36.852659] deferring g.e. 0xf9 (pfn 0x)
[   36.855089] xen:grant_table: WARNING:e.g. 0x112 still in use!

In this case, persistent grants would need to be disabled.

[Anchal Changelog: Removed timeout/request during blkfront freeze.
Reworked the whole patch to work with blk-mq and incorporate upstream's
comments]

Signed-off-by: Anchal Agarwal 
Signed-off-by: Munehisa Kamata 
---
 drivers/block/xen-blkfront.c | 122 +--
 1 file changed, 115 insertions(+), 7 deletions(-)

diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c
index 3b889ea950c2..464863ed7093 100644
--- a/drivers/block/xen-blkfront.c
+++ b/drivers/block/xen-blkfront.c
@@ -48,6 +48,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include 
 #include 
@@ -80,6 +82,8 @@ enum blkif_state {
BLKIF_STATE_DISCONNECTED,
BLKIF_STATE_CONNECTED,
BLKIF_STATE_SUSPENDED,
+   BLKIF_STATE_FREEZING,
+   BLKIF_STATE_FROZEN
 };
 
 struct grant {
@@ -219,6 +223,7 @@ struct blkfront_info
struct list_head requests;
struct bio_list bio_list;
struct list_head info_list;
+   struct completion wait_backend_disconnected;
 };
 
 static unsigned int nr_minors;
@@ -1005,6 +1010,7 @@ static int xlvbd_init_blk_queue(struct gendisk *gd, u16 
sector_size,
info->sector_size = sector_size;
info->physical_sector_size = physical_sector_size;
blkif_set_queue_limits(info);
+   init_completion(>wait_backend_disconnected);
 
return 0;
 }
@@ -1057,7 +1063,7 @@ static int xen_translate_vdev(int vdevice, int *minor, 
unsigned int *offset)
case XEN_SCSI_DISK5_MAJOR:
case XEN_SCSI_DISK6_MAJOR:
case XEN_SCSI_DISK7_MAJOR:
-   *offset = (*minor / PARTS_PER_DISK) + 
+   *offset = (*minor / PARTS_PER_DISK) +
((major - XEN_SCSI_DISK1_MAJOR + 1) * 16) +
EMULATED_SD_DISK_NAME_OFFSET;
*minor = *minor +
@@ -1072,7 +1078,7 @@ static int xen_translate_vdev(int vdevice, int *minor, 
unsigned int *offset)
case XEN_SCSI_DISK13_MAJOR:
case XEN_SCSI_DISK14_MAJOR:
case XEN_SCSI_DISK15_MAJOR:
-   *offset = (*minor / PARTS_PER_DISK) + 
+   *offset = (*minor / PARTS_PER_DISK) +
((major - XEN_SCSI_DISK8_MAJOR + 8) * 16) +
EMULATED_SD_DISK_NAME_OFFSET;
*minor = *minor +
@@ -1353,6 +1359,8 @@ static void blkif_free(struct blkfront_info *info, int 
suspend)
unsigned int i;
struct blkfront_ring_info *rinfo;
 
+   if (info->connected == BLKIF_STATE_FREEZING)
+   goto free_rings;
/* Prevent new requests being issued until we fix things up. */
info->connected = suspend ?
BLKIF_STATE_SUSPENDED : BLKIF_STATE_DISCONNECTED;
@@ -1360,6 +1368,7 @@ static void blkif_free(struct blkfront_info *info, int