Received: from eggs.gnu.org ([2001:4830:134:3::10]:35494) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmfVO-00007c-1o for qemu-devel@nongnu.org; Wed, 21 Sep 2016 07:15:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bmfVH-0001GX-Vv for qemu-devel@nongnu.org; Wed, 21 Sep 2016 07:15:56 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:58932) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bmfVH-0001G9-OM for qemu-devel@nongnu.org; Wed, 21 Sep 2016 07:15:51 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id u8LBCaqY094903 for ; Wed, 21 Sep 2016 07:15:49 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0a-001b2d01.pphosted.com with ESMTP id 25k6ckuske-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 21 Sep 2016 07:15:48 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 21 Sep 2016 12:15:45 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp02.portsmouth.uk.ibm.com (Postfix) with ESMTP id CA6FD2190023 for ; Wed, 21 Sep 2016 12:15:03 +0100 (BST) Received: from d06av09.portsmouth.uk.ibm.com (d06av09.portsmouth.uk.ibm.com [9.149.37.250]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id u8LBFhOl15335822 for ; Wed, 21 Sep 2016 11:15:43 GMT Received: from d06av09.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av09.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id u8LBFhhw029134 for ; Wed, 21 Sep 2016 05:15:43 -0600 Date: Wed, 21 Sep 2016 13:15:41 +0200 From: Cornelia Huck In-Reply-To: <20160921090235.593dd32c@bahia.lab.toulouse-stg.fr.ibm.com> References: <1474382978-26310-1-git-send-email-stefanha@redhat.com> <1474382978-26310-5-git-send-email-stefanha@redhat.com> <20160921090235.593dd32c@bahia.lab.toulouse-stg.fr.ibm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-Id: <20160921131541.0e68e46f.cornelia.huck@de.ibm.com> Subject: Re: [Qemu-devel] [PATCH v4 4/9] virtio: handle virtqueue_map_desc() errors List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Greg Kurz Cc: Stefan Hajnoczi , qemu-devel@nongnu.org, Fam Zheng , "Michael S. Tsirkin" On Wed, 21 Sep 2016 09:02:35 +0200 Greg Kurz wrote: > On Tue, 20 Sep 2016 15:49:33 +0100 > Stefan Hajnoczi wrote: > > > Errors can occur during virtqueue_pop(), especially in > > virtqueue_map_desc(). In order to handle this we must unmap iov[] > > before returning NULL. The caller will consider the virtqueue empty and > > the virtio_error() call will have marked the device broken. > > > > Signed-off-by: Stefan Hajnoczi > > --- > > Hi Stefan, > > FWIW, Prasad's "virtio: add check for descriptor's mapped address" is already > in Michael's tree: > > https://git.kernel.org/cgit/virt/kvm/mst/qemu.git/commit/?h=pci&id=13c9ed60de6faaed325804620d13e7be37ea8183 > > I guess this patch should take it into account (as already suggested by Laszlo). Agreed. (...) > > +/* Only used by error code paths before we have a VirtQueueElement (therefore > > + * virtqueue_unmap_sg() can't be used). Assumes buffers weren't written to > > + * yet. > > + */ > > +static void virtqueue_undo_map_desc(unsigned out_num, unsigned in_num, Should the arguments use 'unsigned int' as well, for consistency's sake? > > + struct iovec *iov) > > +{ > > + unsigned int i; > > + > > + for (i = 0; i < out_num + in_num; i++) { > > + int is_write = i >= out_num; > > + > > + cpu_physical_memory_unmap(iov->iov_base, iov->iov_len, is_write, 0); > > + iov++; > > + } > > }