Skip to contentSkip to conversation

barriers before {req/rsp}_cons = cons?

DISCUSSION Samuel Thibault 2 participants 6 messages Jul 18, 2008 – Jul 21, 2008

lore
Share & tools
lore
#0 lore raw

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

#1 lore raw

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

-- Keir

Quoted 21 lines · Samuel Thibault

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
[email protected]
http://lists.xensource.com/xen-devel

#2 lore raw
Quoted 8 lines · Keir Fraser, le Fri 18 Jul 2008 20:31:13 +0100, a écrit :
Quoted 5 lines

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

#3 lore raw
Quoted 7 lines · Samuel Thibault, le Fri 18 Jul 2008 20:33:04 +0100, a écrit :
Quoted 6 lines · Keir Fraser, le Fri 18 Jul 2008 20:31:13 +0100, a écrit :
Quoted 5 lines

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;

Quoted 5 lines
Quoted 2 lines

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).

Quoted 2 lines

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

Samuel

#4 lore raw
In reply to Samuel Thibault
Quoted 6 lines · Samuel Thibault
Quoted 2 lines

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

#5 lore raw
Quoted 10 lines · Keir Fraser, le Mon 21 Jul 2008 09:28:38 +0100, a écrit :
Quoted 6 lines · Samuel Thibault
Quoted 2 lines

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