All of lore.kernel.org
 help / color / mirror / Atom feed
* barriers before {req/rsp}_cons = cons?
@ 2008-07-18 18:52 Samuel Thibault
  2008-07-18 19:31 ` Keir Fraser
  0 siblings, 1 reply; 6+ messages in thread
From: Samuel Thibault @ 2008-07-18 18:52 UTC (permalink / raw)
  To: xen-devel

Hello,

In a bunch of places, one can read code like

cons = netif->tx.req_cons;
rmb(); /* Ensure that we see the request before we copy it. */
memcpy(&txreq, RING_GET_REQUEST(&netif->tx, i), sizeof(txreq));
some checks
netif->tx.req_cons = ++cons;

Shouldn't there be a full barrier just before the req_cons assignation?
I guess we are currently not seeing bugs at least because the req will
not be overwriten until we loop in the ring, but it seems to me there
may be a bug here.

Samuel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: barriers before {req/rsp}_cons = cons?
  2008-07-18 18:52 barriers before {req/rsp}_cons = cons? Samuel Thibault
@ 2008-07-18 19:31 ` Keir Fraser
  2008-07-18 19:33   ` Samuel Thibault
  0 siblings, 1 reply; 6+ messages in thread
From: Keir Fraser @ 2008-07-18 19:31 UTC (permalink / raw)
  To: Samuel Thibault, xen-devel

Could you describe the race you believe is made possible by the absence of
the barrier?

 -- Keir

On 18/7/08 19:52, "Samuel Thibault" <samuel.thibault@eu.citrix.com> wrote:

> Hello,
> 
> In a bunch of places, one can read code like
> 
> cons = netif->tx.req_cons;
> rmb(); /* Ensure that we see the request before we copy it. */
> memcpy(&txreq, RING_GET_REQUEST(&netif->tx, i), sizeof(txreq));
> some checks
> netif->tx.req_cons = ++cons;
> 
> Shouldn't there be a full barrier just before the req_cons assignation?
> I guess we are currently not seeing bugs at least because the req will
> not be overwriten until we loop in the ring, but it seems to me there
> may be a bug here.
> 
> Samuel
> 
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xensource.com
> http://lists.xensource.com/xen-devel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: barriers before {req/rsp}_cons = cons?
  2008-07-18 19:31 ` Keir Fraser
@ 2008-07-18 19:33   ` Samuel Thibault
  2008-07-18 19:34     ` Samuel Thibault
  2008-07-21  8:28     ` Keir Fraser
  0 siblings, 2 replies; 6+ messages in thread
From: Samuel Thibault @ 2008-07-18 19:33 UTC (permalink / raw)
  To: Keir Fraser; +Cc: xen-devel

Keir Fraser, le Fri 18 Jul 2008 20:31:13 +0100, a écrit :
> > cons = netif->tx.req_cons;
> > rmb(); /* Ensure that we see the request before we copy it. */
> > memcpy(&txreq, RING_GET_REQUEST(&netif->tx, i), sizeof(txreq));
> > some checks
> > netif->tx.req_cons = ++cons;
> 
> Could you describe the race you believe is made possible by the absence of
> the barrier?

It is very unlikely, but the write into req_cons could happen before
actually doing the memcpy, and so another processor could try to reuse
the same request slot.

Samuel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: barriers before {req/rsp}_cons = cons?
  2008-07-18 19:33   ` Samuel Thibault
@ 2008-07-18 19:34     ` Samuel Thibault
  2008-07-21  8:28     ` Keir Fraser
  1 sibling, 0 replies; 6+ messages in thread
From: Samuel Thibault @ 2008-07-18 19:34 UTC (permalink / raw)
  To: Keir Fraser, xen-devel

Samuel Thibault, le Fri 18 Jul 2008 20:33:04 +0100, a écrit :
> Keir Fraser, le Fri 18 Jul 2008 20:31:13 +0100, a écrit :
> > > cons = netif->tx.req_cons;
> > > rmb(); /* Ensure that we see the request before we copy it. */
> > > memcpy(&txreq, RING_GET_REQUEST(&netif->tx, i), sizeof(txreq));
> > > some checks
> > > netif->tx.req_cons = ++cons;
> > 
> > Could you describe the race you believe is made possible by the absence of
> > the barrier?
> 
> It is very unlikely, but the write into req_cons could happen before
> actually doing the memcpy,

(more precisely, the read, of course).

> and so another processor could try to reuse
> the same request slot.

Samuel

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: barriers before {req/rsp}_cons = cons?
  2008-07-18 19:33   ` Samuel Thibault
  2008-07-18 19:34     ` Samuel Thibault
@ 2008-07-21  8:28     ` Keir Fraser
  2008-07-21 10:08       ` Samuel Thibault
  1 sibling, 1 reply; 6+ messages in thread
From: Keir Fraser @ 2008-07-21  8:28 UTC (permalink / raw)
  To: Samuel Thibault; +Cc: xen-devel

On 18/7/08 20:33, "Samuel Thibault" <samuel.thibault@eu.citrix.com> wrote:

>> Could you describe the race you believe is made possible by the absence of
>> the barrier?
> 
> It is very unlikely, but the write into req_cons could happen before
> actually doing the memcpy, and so another processor could try to reuse
> the same request slot.

req_cons is not shared with the frontend driver, and most accesses within
the backend are serialised within the transmit tasklet.

 -- Keir

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: barriers before {req/rsp}_cons = cons?
  2008-07-21  8:28     ` Keir Fraser
@ 2008-07-21 10:08       ` Samuel Thibault
  0 siblings, 0 replies; 6+ messages in thread
From: Samuel Thibault @ 2008-07-21 10:08 UTC (permalink / raw)
  To: Keir Fraser; +Cc: xen-devel

Keir Fraser, le Mon 21 Jul 2008 09:28:38 +0100, a écrit :
> On 18/7/08 20:33, "Samuel Thibault" <samuel.thibault@eu.citrix.com> wrote:
> 
> >> Could you describe the race you believe is made possible by the absence of
> >> the barrier?
> > 
> > It is very unlikely, but the write into req_cons could happen before
> > actually doing the memcpy, and so another processor could try to reuse
> > the same request slot.
> 
> req_cons is not shared with the frontend driver,

Aow, right, I had forgotten that on the frontend side we are using the
rsp index, so that there is no more in-flight requests than ring slots.

Samuel

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2008-07-21 10:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-18 18:52 barriers before {req/rsp}_cons = cons? Samuel Thibault
2008-07-18 19:31 ` Keir Fraser
2008-07-18 19:33   ` Samuel Thibault
2008-07-18 19:34     ` Samuel Thibault
2008-07-21  8:28     ` Keir Fraser
2008-07-21 10:08       ` Samuel Thibault

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.