From: "Jan Beulich" Subject: Re: [PATCH] x86/HVM: avoid pointer wraparound in bufioreq handling Date: Tue, 16 Jun 2015 10:54:57 +0100 Message-ID: <55800E91020000780008565A@mail.emea.novell.com> References: <557EFDA10200007800084F23@mail.emea.novell.com> <557FE1DB0200007800085388@mail.emea.novell.com> <1434442808.13744.39.camel@citrix.com> <557FFC6302000078000854F9@mail.emea.novell.com> <1434445183.13744.61.camel@citrix.com> <9AAE0902D5BC7E449B7C8E4E778ABCD02594F62B@AMSPEX01CL01.citrite.net> <558008A902000078000855E7@mail.emea.novell.com> <9AAE0902D5BC7E449B7C8E4E778ABCD02594FB59@AMSPEX01CL01.citrite.net> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1Z4naB-0003NX-TQ for xen-devel@lists.xenproject.org; Tue, 16 Jun 2015 09:55:04 +0000 In-Reply-To: <9AAE0902D5BC7E449B7C8E4E778ABCD02594FB59@AMSPEX01CL01.citrite.net> Content-Disposition: inline List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: Paul Durrant Cc: Wei Liu , Ian Campbell , Andrew Cooper , StefanoStabellini , Ian Jackson , xen-devel , "Keir (Xen.org)" List-Id: xen-devel@lists.xenproject.org >>> On 16.06.15 at 11:45, wrote: >> From: Jan Beulich [mailto:JBeulich@suse.com] >> Sent: 16 June 2015 10:30 >> >>> On 16.06.15 at 11:15, wrote: >> > From my reading, both QEMU upstream and trad are safe. They use a loop >> of >> > the form: >> > >> > while (read_ptr != write_ptr) >> > { >> > do stuff >> > >> > read_ptr += (handled a qword) ? 2 : 1; >> > } >> > >> > So, since the only test is for equality I think overflow should be handled >> > correctly. So, does anything actually need to be fixed? >> >> Of course this needs to be fixed: When either pointer crosses the >> 2^32 boundary, the slot referenced goes from 0x1f to 0 (due to the >> "modulo 511" operation determining the slot to be used), introducing >> a discontinuity and potentially corrupting data in slots not consumed >> yet. >> > > Ah yes. I thought you were worried about inequality checks going wrong. > > The way that QEMU processes buffered requests means that a synchronous ioreq > is a barrier to buffered ring processing. So I guess it should be possible to > send a synchronous request and then zero the buffered ring counters before > they reach overflow. Or, following Ian's most recent reply, simply assume default servers to work atomically here (once a qemu-trad fix went in of course). Jan