From mboxrd@z Thu Jan 1 00:00:00 1970 From: Konrad Rzeszutek Wilk Subject: Re: [Xen-devel] [PATCH 2/3] xen/ring: Add a new macro to detect whether there is an overflow in requests and response. Date: Fri, 25 Jan 2013 13:41:35 -0500 Message-ID: <20130125184135.GB1384@phenom.dumpdata.com> References: <1359135152-30688-1-git-send-email-konrad.wilk@oracle.com> <1359135152-30688-3-git-send-email-konrad.wilk@oracle.com> <5102C4B9.8050801@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Return-path: Content-Disposition: inline In-Reply-To: <5102C4B9.8050801@citrix.com> Sender: stable-owner@vger.kernel.org To: Roger Pau =?iso-8859-1?Q?Monn=E9?= Cc: "linux-kernel@vger.kernel.org" , "xen-devel@lists.xensource.com" , Konrad Rzeszutek Wilk , "stable@vger.kernel.org" List-Id: xen-devel@lists.xenproject.org On Fri, Jan 25, 2013 at 06:45:29PM +0100, Roger Pau Monn=E9 wrote: > On 25/01/13 18:32, Konrad Rzeszutek Wilk wrote: > > We want to be able to exit if the difference between the request > > produced (what the frontend tells us) and the requests consumed > > (what we have so far processed) is greater than the ring size. > >=20 > > If so, we should terminate the loop as the request produced > > is not trusted and it means it is bogus. > >=20 > > Cc: stable@vger.kernel.org > > Signed-off-by: Konrad Rzeszutek Wilk > > --- > > include/xen/interface/io/ring.h | 6 ++++++ > > 1 file changed, 6 insertions(+) > >=20 > > diff --git a/include/xen/interface/io/ring.h b/include/xen/interfac= e/io/ring.h > > index 75271b9..1114dde 100644 > > --- a/include/xen/interface/io/ring.h > > +++ b/include/xen/interface/io/ring.h > > @@ -188,6 +188,12 @@ struct __name##_back_ring { \ > > #define RING_REQUEST_CONS_OVERFLOW(_r, _cons) \ > > (((_cons) - (_r)->rsp_prod_pvt) >=3D RING_SIZE(_r)) > > =20 > > +/* Loop termination condition: Is the difference between request p= roduced > > + * and request consumed greater than the ring size. If so, termina= te the > > + * loop. */ > > +#define RING_REQUEST_PROD_OVERFLOW(_r, _cons, _prod) = \ > > + (((_prod) - (_prod)) > RING_SIZE(_r)) >=20 > Shouldn't the second _prod be _cons? >=20 > > + > > #define RING_PUSH_REQUESTS(_r) do { \ > > wmb(); /* back sees requests /before/ updated producer index *= / \ > > (_r)->sring->req_prod =3D (_r)->req_prod_pvt; \ > >=20 >=20 Here is an update of it: =46rom a84ea207716486515f083a6d708414dd3ad3aaf6 Mon Sep 17 00:00:00 200= 1 =46rom: Konrad Rzeszutek Wilk Date: Fri, 25 Jan 2013 12:29:51 -0500 Subject: [PATCH] ring/macro: Add a new macro to detect whether there is= an overflow in requests and response. We want to be able to exit if the difference between the request produced (what the frontend tells us) and the requests consumed (what we have so far processed) is greater than the ring size. If so, we should terminate the loop as the request produced is not trusted and it means it is bogus. [v1: Make the macro do the ring thing, swap arguments around to match the comment] Signed-off-by: Konrad Rzeszutek Wilk --- xen/include/public/io/ring.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xen/include/public/io/ring.h b/xen/include/public/io/ring.= h index 38b7051..440ef9a 100644 --- a/xen/include/public/io/ring.h +++ b/xen/include/public/io/ring.h @@ -234,6 +234,12 @@ typedef struct __name##_back_ring __name##_back_ri= ng_t #define RING_REQUEST_CONS_OVERFLOW(_r, _cons) = \ (((_cons) - (_r)->rsp_prod_pvt) >=3D RING_SIZE(_r)) =20 +/* Loop termination condition: Is the difference between request produ= ced + * and request consumed greater than the ring size. If so, terminate t= he + * loop. */ +#define RING_REQUEST_PROD_OVERFLOW(_r, _prod, _cons) = \ + (((_prod) - (_cons)) > RING_SIZE(_r)) + #define RING_PUSH_REQUESTS(_r) do { = \ xen_wmb(); /* back sees requests /before/ updated producer index *= / \ (_r)->sring->req_prod =3D (_r)->req_prod_pvt; = \ --=20 1.8.0.2