Received: from eggs.gnu.org ([2001:4830:134:3::10]:49774) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjlm3-0005Sc-0i for qemu-devel@nongnu.org; Tue, 13 Sep 2016 07:21:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bjllx-0006H0-UB for qemu-devel@nongnu.org; Tue, 13 Sep 2016 07:21:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:47406) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bjllx-0006Go-Oa for qemu-devel@nongnu.org; Tue, 13 Sep 2016 07:21:05 -0400 Date: Tue, 13 Sep 2016 16:50:58 +0530 (IST) From: P J P In-Reply-To: <7D125827-164E-43FF-A80F-8B8908D9B2EE@daynix.com> Message-ID: References: <1473184397-27900-1-git-send-email-ppandit@redhat.com> <7D125827-164E-43FF-A80F-8B8908D9B2EE@daynix.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3] scsi: pvscsi: avoid infinite loop while building SG list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Dmitry Fleytman Cc: Paolo Bonzini , Qemu Developers , Li Qiang Hello Dmitry, +-- On Tue, 13 Sep 2016, Dmitry Fleytman wrote --+ | Better put here: |=20 | if(elemcnt++ >=3D PVSCSI_MAX_SG_ELEM) { | return; | } | | And ditch additional conditions from while clauses. | This way you=E2=80=99ll have less compare operations and avoid | adding the same element twice when leaving because of too long SG list. Okay. | Also this is not a good idea to send truncated requests | when SG list becomes too long. I=E2=80=99d prefer to return error | code from pvscsi_convert_sglist() and handle it as appropriate. This could be a separate patch. Should pvscsi_build_sglist() destroy th= e=20 sglist on error?=20 @@ -656,7 +660,9 @@ pvscsi_build_sglist(PVSCSIState *s, PVSCSIRequest *r) =20 pci_dma_sglist_init(&r->sgl, d, 1); if (r->req.flags & PVSCSI_FLAG_CMD_WITH_SG_LIST) { - pvscsi_convert_sglist(r); + if (pvscsi_convert_sglist(r) < 0) { + qemu_sglist_destroy(&r->sgl); + } } else { qemu_sglist_add(&r->sgl, r->req.dataAddr, r->req.dataLen); } I'll send both patches together once you confirm. Thank you. -- Prasad J Pandit / Red Hat Product Security Team 47AF CE69 3A90 54AA 9045 1053 DD13 3D32 FE5B 041F