Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1664262 > unrolled thread
| Started by | Boris Ostrovsky <boris.ostrovsky@oracle.com> |
|---|---|
| First post | 2017-06-13 00:10 +0200 |
| Last post | 2017-06-15 21:00 +0200 |
| Articles | 4 — 2 participants |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: [PATCH v3 06/18] xen/pvcalls: handle commands from the frontend Boris Ostrovsky <boris.ostrovsky@oracle.com> - 2017-06-13 00:10 +0200
Re: [PATCH v3 06/18] xen/pvcalls: handle commands from the frontend Stefano Stabellini <sstabellini@kernel.org> - 2017-06-14 23:10 +0200
Re: [PATCH v3 06/18] xen/pvcalls: handle commands from the frontend Boris Ostrovsky <boris.ostrovsky@oracle.com> - 2017-06-15 16:40 +0200
Re: [PATCH v3 06/18] xen/pvcalls: handle commands from the frontend Stefano Stabellini <sstabellini@kernel.org> - 2017-06-15 21:00 +0200
| From | Boris Ostrovsky <boris.ostrovsky@oracle.com> |
|---|---|
| Date | 2017-06-13 00:10 +0200 |
| Subject | Re: [PATCH v3 06/18] xen/pvcalls: handle commands from the frontend |
| Message-ID | <tRFH3-800-7@gated-at.bofh.it> |
> +
> static void pvcalls_back_work(struct work_struct *work)
> {
> + struct pvcalls_fedata *priv = container_of(work,
> + struct pvcalls_fedata, register_work);
> + int notify, notify_all = 0, more = 1;
> + struct xen_pvcalls_request req;
> + struct xenbus_device *dev = priv->dev;
> +
> + while (more) {
> + while (RING_HAS_UNCONSUMED_REQUESTS(&priv->ring)) {
> + RING_COPY_REQUEST(&priv->ring,
> + priv->ring.req_cons++,
> + &req);
> +
> + if (!pvcalls_back_handle_cmd(dev, &req)) {
> + RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(
> + &priv->ring, notify);
> + notify_all += notify;
> + }
> + }
> +
> + if (notify_all)
> + notify_remote_via_irq(priv->irq);
> +
> + RING_FINAL_CHECK_FOR_REQUESTS(&priv->ring, more);
> + }
> }
>
> static irqreturn_t pvcalls_back_event(int irq, void *dev_id)
> {
> + struct xenbus_device *dev = dev_id;
> + struct pvcalls_fedata *priv = NULL;
> +
> + if (dev == NULL)
> + return IRQ_HANDLED;
> +
> + priv = dev_get_drvdata(&dev->dev);
> + if (priv == NULL)
> + return IRQ_HANDLED;
> +
> + /*
> + * TODO: a small theoretical race exists if we try to queue work
> + * after pvcalls_back_work checked for final requests and before
> + * it returns. The queuing will fail, and pvcalls_back_work
> + * won't do the work because it is about to return. In that
> + * case, we lose the notification.
> + */
> + queue_work(priv->wq, &priv->register_work);
Would queuing delayed work (if queue_work() failed) help? And canceling
it on next invocation of pvcalls_back_event()?
-boris
[toc] | [next] | [standalone]
| From | Stefano Stabellini <sstabellini@kernel.org> |
|---|---|
| Date | 2017-06-14 23:10 +0200 |
| Subject | Re: [PATCH v3 06/18] xen/pvcalls: handle commands from the frontend |
| Message-ID | <tSnI5-1Q7-3@gated-at.bofh.it> |
| In reply to | #1664262 |
On Mon, 12 Jun 2017, Boris Ostrovsky wrote:
> > +
> > static void pvcalls_back_work(struct work_struct *work)
> > {
> > + struct pvcalls_fedata *priv = container_of(work,
> > + struct pvcalls_fedata, register_work);
> > + int notify, notify_all = 0, more = 1;
> > + struct xen_pvcalls_request req;
> > + struct xenbus_device *dev = priv->dev;
> > +
> > + while (more) {
> > + while (RING_HAS_UNCONSUMED_REQUESTS(&priv->ring)) {
> > + RING_COPY_REQUEST(&priv->ring,
> > + priv->ring.req_cons++,
> > + &req);
> > +
> > + if (!pvcalls_back_handle_cmd(dev, &req)) {
> > + RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(
> > + &priv->ring, notify);
> > + notify_all += notify;
> > + }
> > + }
> > +
> > + if (notify_all)
> > + notify_remote_via_irq(priv->irq);
> > +
> > + RING_FINAL_CHECK_FOR_REQUESTS(&priv->ring, more);
> > + }
> > }
> >
> > static irqreturn_t pvcalls_back_event(int irq, void *dev_id)
> > {
> > + struct xenbus_device *dev = dev_id;
> > + struct pvcalls_fedata *priv = NULL;
> > +
> > + if (dev == NULL)
> > + return IRQ_HANDLED;
> > +
> > + priv = dev_get_drvdata(&dev->dev);
> > + if (priv == NULL)
> > + return IRQ_HANDLED;
> > +
> > + /*
> > + * TODO: a small theoretical race exists if we try to queue work
> > + * after pvcalls_back_work checked for final requests and before
> > + * it returns. The queuing will fail, and pvcalls_back_work
> > + * won't do the work because it is about to return. In that
> > + * case, we lose the notification.
> > + */
> > + queue_work(priv->wq, &priv->register_work);
>
> Would queuing delayed work (if queue_work() failed) help? And canceling
> it on next invocation of pvcalls_back_event()?
Looking at the implementation of queue_delayed_work_on and
queue_work_on, it looks like that if queue_work fails then also
queue_delayed_work would fail: they both test on
WORK_STRUCT_PENDING_BIT.
[toc] | [prev] | [next] | [standalone]
| From | Boris Ostrovsky <boris.ostrovsky@oracle.com> |
|---|---|
| Date | 2017-06-15 16:40 +0200 |
| Message-ID | <tSE6d-3E5-1@gated-at.bofh.it> |
| In reply to | #1666229 |
On 06/14/2017 05:03 PM, Stefano Stabellini wrote:
> On Mon, 12 Jun 2017, Boris Ostrovsky wrote:
>>> +
>>> static void pvcalls_back_work(struct work_struct *work)
>>> {
>>> + struct pvcalls_fedata *priv = container_of(work,
>>> + struct pvcalls_fedata, register_work);
>>> + int notify, notify_all = 0, more = 1;
>>> + struct xen_pvcalls_request req;
>>> + struct xenbus_device *dev = priv->dev;
>>> +
>>> + while (more) {
>>> + while (RING_HAS_UNCONSUMED_REQUESTS(&priv->ring)) {
>>> + RING_COPY_REQUEST(&priv->ring,
>>> + priv->ring.req_cons++,
>>> + &req);
>>> +
>>> + if (!pvcalls_back_handle_cmd(dev, &req)) {
>>> + RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(
>>> + &priv->ring, notify);
>>> + notify_all += notify;
>>> + }
>>> + }
>>> +
>>> + if (notify_all)
>>> + notify_remote_via_irq(priv->irq);
>>> +
>>> + RING_FINAL_CHECK_FOR_REQUESTS(&priv->ring, more);
>>> + }
>>> }
>>>
>>> static irqreturn_t pvcalls_back_event(int irq, void *dev_id)
>>> {
>>> + struct xenbus_device *dev = dev_id;
>>> + struct pvcalls_fedata *priv = NULL;
>>> +
>>> + if (dev == NULL)
>>> + return IRQ_HANDLED;
>>> +
>>> + priv = dev_get_drvdata(&dev->dev);
>>> + if (priv == NULL)
>>> + return IRQ_HANDLED;
>>> +
>>> + /*
>>> + * TODO: a small theoretical race exists if we try to queue work
>>> + * after pvcalls_back_work checked for final requests and before
>>> + * it returns. The queuing will fail, and pvcalls_back_work
>>> + * won't do the work because it is about to return. In that
>>> + * case, we lose the notification.
>>> + */
>>> + queue_work(priv->wq, &priv->register_work);
>> Would queuing delayed work (if queue_work() failed) help? And canceling
>> it on next invocation of pvcalls_back_event()?
> Looking at the implementation of queue_delayed_work_on and
> queue_work_on, it looks like that if queue_work fails then also
> queue_delayed_work would fail: they both test on
> WORK_STRUCT_PENDING_BIT.
Right, I should have looked at this myself. And flush_work() I suppose
cannot be used here since it may sleep?
Then I also can't think of anything else.
-boris
[toc] | [prev] | [next] | [standalone]
| From | Stefano Stabellini <sstabellini@kernel.org> |
|---|---|
| Date | 2017-06-15 21:00 +0200 |
| Subject | Re: [PATCH v3 06/18] xen/pvcalls: handle commands from the frontend |
| Message-ID | <tSI9R-68f-33@gated-at.bofh.it> |
| In reply to | #1666759 |
On Thu, 15 Jun 2017, Boris Ostrovsky wrote:
> On 06/14/2017 05:03 PM, Stefano Stabellini wrote:
> > On Mon, 12 Jun 2017, Boris Ostrovsky wrote:
> >>> +
> >>> static void pvcalls_back_work(struct work_struct *work)
> >>> {
> >>> + struct pvcalls_fedata *priv = container_of(work,
> >>> + struct pvcalls_fedata, register_work);
> >>> + int notify, notify_all = 0, more = 1;
> >>> + struct xen_pvcalls_request req;
> >>> + struct xenbus_device *dev = priv->dev;
> >>> +
> >>> + while (more) {
> >>> + while (RING_HAS_UNCONSUMED_REQUESTS(&priv->ring)) {
> >>> + RING_COPY_REQUEST(&priv->ring,
> >>> + priv->ring.req_cons++,
> >>> + &req);
> >>> +
> >>> + if (!pvcalls_back_handle_cmd(dev, &req)) {
> >>> + RING_PUSH_RESPONSES_AND_CHECK_NOTIFY(
> >>> + &priv->ring, notify);
> >>> + notify_all += notify;
> >>> + }
> >>> + }
> >>> +
> >>> + if (notify_all)
> >>> + notify_remote_via_irq(priv->irq);
> >>> +
> >>> + RING_FINAL_CHECK_FOR_REQUESTS(&priv->ring, more);
> >>> + }
> >>> }
> >>>
> >>> static irqreturn_t pvcalls_back_event(int irq, void *dev_id)
> >>> {
> >>> + struct xenbus_device *dev = dev_id;
> >>> + struct pvcalls_fedata *priv = NULL;
> >>> +
> >>> + if (dev == NULL)
> >>> + return IRQ_HANDLED;
> >>> +
> >>> + priv = dev_get_drvdata(&dev->dev);
> >>> + if (priv == NULL)
> >>> + return IRQ_HANDLED;
> >>> +
> >>> + /*
> >>> + * TODO: a small theoretical race exists if we try to queue work
> >>> + * after pvcalls_back_work checked for final requests and before
> >>> + * it returns. The queuing will fail, and pvcalls_back_work
> >>> + * won't do the work because it is about to return. In that
> >>> + * case, we lose the notification.
> >>> + */
> >>> + queue_work(priv->wq, &priv->register_work);
> >> Would queuing delayed work (if queue_work() failed) help? And canceling
> >> it on next invocation of pvcalls_back_event()?
> > Looking at the implementation of queue_delayed_work_on and
> > queue_work_on, it looks like that if queue_work fails then also
> > queue_delayed_work would fail: they both test on
> > WORK_STRUCT_PENDING_BIT.
>
> Right, I should have looked at this myself. And flush_work() I suppose
> cannot be used here since it may sleep?
>
> Then I also can't think of anything else.
I guess one way to work around the issue would be to use multiple work
items, and queue a new (different) work item at each pvcalls_back_event.
But that approach would use more memory and would need a new lock
in pvcalls_back_work.
Given that the race is only theoretical (I am running nginx inside a
VM and hitting it with as many multiple requests as I can and still I
cannot reproduce it), I am tempted to leave it as-is with a comment. We
can revisit it in the future if we find any real issues.
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web