Received: from eggs.gnu.org ([2001:4830:134:3::10]:41066) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WskiC-0003Zo-Gf for qemu-devel@nongnu.org; Thu, 05 Jun 2014 23:21:06 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Wski6-0007Sb-Bm for qemu-devel@nongnu.org; Thu, 05 Jun 2014 23:21:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:38487) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Wski6-0007SX-2B for qemu-devel@nongnu.org; Thu, 05 Jun 2014 23:20:54 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s563KrIR025434 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 5 Jun 2014 23:20:53 -0400 Date: Fri, 6 Jun 2014 11:21:05 +0800 From: Fam Zheng Message-ID: <20140606032105.GC11403@T430.nay.redhat.com> References: <1401970536-18019-1-git-send-email-armbru@redhat.com> <1401970536-18019-4-git-send-email-armbru@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1401970536-18019-4-git-send-email-armbru@redhat.com> Subject: Re: [Qemu-devel] [PATCH 3/3] virtio-blk: Treat read/write beyond end as invalid List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, uobergfe@redhat.com On Thu, 06/05 14:15, Markus Armbruster wrote: > The block layer fails such reads and writes just fine. However, they > then get treated like valid operations that fail: the error action > gets executed. Unwanted; reporting the error to the guest is the only > sensible action. > > Reject them before passing them to the block layer. This bypasses the > error action and I/O accounting. > > Signed-off-by: Markus Armbruster > --- > hw/block/virtio-blk.c | 7 +++++++ > 1 file changed, 7 insertions(+) > > diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c > index 2c68d0d..0b38049 100644 > --- a/hw/block/virtio-blk.c > +++ b/hw/block/virtio-blk.c > @@ -284,12 +284,19 @@ static void virtio_blk_handle_flush(VirtIOBlockReq *req, MultiReqBuffer *mrb) > static bool virtio_blk_sect_range_ok(VirtIOBlock *dev, > uint64_t sector, size_t size) > { > + uint64_t nb_sectors = size >> BDRV_SECTOR_BITS; > + uint64_t total_sectors; > + > if (sector & dev->sector_mask) { > return false; > } > if (size % dev->conf->logical_block_size) { > return false; > } > + bdrv_get_geometry(dev->bs, &total_sectors); > + if (sector > total_sectors || nb_sectors > total_sectors - sector) { > + return false; > + } > return true; > } > > -- > 1.9.3 > > Reviewed-by: Fam Zheng