From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36933) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X33b5-0002al-6l for qemu-devel@nongnu.org; Fri, 04 Jul 2014 09:32:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X33au-00077i-Nd for qemu-devel@nongnu.org; Fri, 04 Jul 2014 09:32:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46572) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X33au-00077B-FM for qemu-devel@nongnu.org; Fri, 04 Jul 2014 09:32:04 -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 s64DW3mg022690 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 4 Jul 2014 09:32:03 -0400 From: Markus Armbruster Date: Fri, 4 Jul 2014 15:31:59 +0200 Message-Id: <1404480720-7485-4-git-send-email-armbru@redhat.com> In-Reply-To: <1404480720-7485-1-git-send-email-armbru@redhat.com> References: <1404480720-7485-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PATCH v2 2.1 3/4] virtio-blk: Treat read/write beyond end as invalid List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, famz@redhat.com, uobergfe@redhat.com, stefanha@redhat.com 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 Reviewed-by: Fam Zheng --- 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 c8952c0..5ec8469 100644 --- a/hw/block/virtio-blk.c +++ b/hw/block/virtio-blk.c @@ -291,12 +291,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